📄 example_test.cpp
字号:
"dll boost_filesystem\n"
" : ../src/$(SOURCES).cpp\n"
" : \n"
" [ common-names ] \n"
" <define>BOOST_FILESYSTEM_DYN_LINK=1 \n"
" <runtime-link>dynamic \n"
" <include>$(BOOST_ROOT) <sysinclude>$(BOOST_ROOT)\n"
" <no-warn>exception.cpp <no-warn>operations_posix_windows.cpp\n"
" : debug release \n"
" ;";
BOOST_CHECK(
io::test_input_filter( io::example::shell_comments_stdio_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::shell_comments_stdio_filter(),
input, output )
);
BOOST_CHECK(
io::test_input_filter( io::example::shell_comments_input_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::shell_comments_output_filter(),
input, output )
);
BOOST_CHECK(
io::test_input_filter( io::example::shell_comments_dual_use_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::shell_comments_dual_use_filter(),
input, output )
);
BOOST_CHECK(
io::test_input_filter( io::example::shell_comments_multichar_input_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::shell_comments_multichar_output_filter(),
input, output )
);
}
//------------------tab_expanding_filter test---------------------------------//
void tab_expanding_filter_test()
{
using namespace std;
const std::string input =
"class tab_expanding_stdio_filter : public stdio_filter {\n"
"public:\n"
"\texplicit tab_expanding_stdio_filter(int\ttab_size = 8)\n"
"\t\t: tab_size_(tab_size), col_no_(0)\n"
"\t{\n"
"\t\tassert(tab_size\t> 0);\n"
"\t}\n"
"private:\n"
"\tvoid do_filter()\n"
"\t{\n"
"\t\tint\tc;\n"
"\t\twhile ((c = std::cin.get()) != EOF) {\n"
"\t\t\tif (c == '\\t') {\n"
"\t\t\t\tint\tspaces = tab_size_ - (col_no_ %\ttab_size_);\n"
"\t\t\t\tfor\t(; spaces >\t0; --spaces)\n"
"\t\t\t\t\tput_char(' ');\n"
"\t\t\t} else {\n"
"\t\t\t\tput_char(c);\n"
"\t\t\t}\n"
"\t\t}\n"
"\t}\n"
"\tvoid do_close()\t{ col_no_ =\t0; }\n"
"\tvoid put_char(int c)\n"
"\t{\n"
"\t\tstd::cout.put(c);\n"
"\t\tif (c == '\\n') {\n"
"\t\t\tcol_no_\t= 0;\n"
"\t\t} else {\n"
"\t\t\t++col_no_;\n"
"\t\t}\n"
"\t}\n"
"\tint\t tab_size_;\n"
"\tint\t col_no_;\n"
"};";
const std::string output =
"class tab_expanding_stdio_filter : public stdio_filter {\n"
"public:\n"
" explicit tab_expanding_stdio_filter(int tab_size = 8)\n"
" : tab_size_(tab_size), col_no_(0)\n"
" {\n"
" assert(tab_size > 0);\n"
" }\n"
"private:\n"
" void do_filter()\n"
" {\n"
" int c;\n"
" while ((c = std::cin.get()) != EOF) {\n"
" if (c == '\\t') {\n"
" int spaces = tab_size_ - (col_no_ % tab_size_);\n"
" for (; spaces > 0; --spaces)\n"
" put_char(' ');\n"
" } else {\n"
" put_char(c);\n"
" }\n"
" }\n"
" }\n"
" void do_close() { col_no_ = 0; }\n"
" void put_char(int c)\n"
" {\n"
" std::cout.put(c);\n"
" if (c == '\\n') {\n"
" col_no_ = 0;\n"
" } else {\n"
" ++col_no_;\n"
" }\n"
" }\n"
" int tab_size_;\n"
" int col_no_;\n"
"};";
BOOST_CHECK(
io::test_input_filter( io::example::tab_expanding_stdio_filter(4),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::tab_expanding_stdio_filter(4),
input, output )
);
BOOST_CHECK(
io::test_input_filter( io::example::tab_expanding_input_filter(4),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::tab_expanding_output_filter(4),
input, output )
);
}
//------------------unix2dos_filter test--------------------------------------//
void unix2dos_filter_test()
{
using namespace std;
const std::string input =
"When I was one-and-twenty\n"
"I heard a wise man say,\n"
"'Give crowns and pounds and guineas\n"
"But not your heart away;\n"
"\n"
"Give pearls away and rubies\n"
"But keep your fancy free.'\n"
"But I was one-and-twenty,\n"
"No use to talk to me.\n"
"\n"
"When I was one-and-twenty\n"
"I heard him say again,\n"
"'The heart out of the bosom\n"
"Was never given in vain;\n"
"'Tis paid with sighs a plenty\n"
"And sold for endless rue.'\n"
"And I am two-and-twenty,\n"
"And oh, 'tis true, 'tis true.";
const std::string output =
"When I was one-and-twenty\r\n"
"I heard a wise man say,\r\n"
"'Give crowns and pounds and guineas\r\n"
"But not your heart away;\r\n"
"\r\n"
"Give pearls away and rubies\r\n"
"But keep your fancy free.'\r\n"
"But I was one-and-twenty,\r\n"
"No use to talk to me.\r\n"
"\r\n"
"When I was one-and-twenty\r\n"
"I heard him say again,\r\n"
"'The heart out of the bosom\r\n"
"Was never given in vain;\r\n"
"'Tis paid with sighs a plenty\r\n"
"And sold for endless rue.'\r\n"
"And I am two-and-twenty,\r\n"
"And oh, 'tis true, 'tis true.";
BOOST_CHECK(
io::test_input_filter( io::example::unix2dos_stdio_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::unix2dos_stdio_filter(),
input, output )
);
BOOST_CHECK(
io::test_input_filter( io::example::unix2dos_input_filter(),
input, output )
);
BOOST_CHECK(
io::test_output_filter( io::example::unix2dos_output_filter(),
input, output )
);
}
test_suite* init_unit_test_suite(int, char* [])
{
test_suite* test = BOOST_TEST_SUITE("example test");
test->add(BOOST_TEST_CASE(&container_device_test));
test->add(BOOST_TEST_CASE(&dictionary_filter_test));
test->add(BOOST_TEST_CASE(&tab_expanding_filter_test));
test->add(BOOST_TEST_CASE(&line_wrapping_filter_test));
test->add(BOOST_TEST_CASE(&shell_comments_filter_test));
test->add(BOOST_TEST_CASE(&unix2dos_filter_test));
return test;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -