MCPcopy Create free account
hub / github.com/boostorg/json / testComments

Function testComments

test/basic_parser.cpp:1023–1128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1021 };
1022
1023 void
1024 testComments()
1025 {
1026 parse_options disabled;
1027 parse_options enabled;
1028 enabled.allow_comments = true;
1029
1030 const auto replace_and_test =
1031 [&](string_view s)
1032 {
1033 static std::vector<string_view> comments =
1034 {
1035 "//\n",
1036 "// \n",
1037 "//aaaa\n",
1038 "// aaaa\n",
1039 "// /* \n",
1040 "// /**/ \n",
1041 "/**/",
1042 "/*//*/",
1043 "/*/*/",
1044 "/******/",
1045 "/*** ***/",
1046 "/**aaaa***/",
1047 "/*** aaaa***/"
1048 };
1049
1050 std::string formatted = "";
1051 std::string just_comments = "";
1052 std::size_t guess = std::count(
1053 s.begin(), s.end(), '@') * 12;
1054 formatted.reserve(guess + s.size());
1055 just_comments.reserve(guess);
1056 std::size_t n = 0;
1057 for (char c : s)
1058 {
1059 if (c == '@')
1060 {
1061 string_view com =
1062 comments[((formatted.size() + n) % s.size()) % comments.size()];
1063 formatted.append(com.data(), n = com.size());
1064 just_comments.append(com.data(), com.size());
1065 continue;
1066 }
1067 formatted += c;
1068 }
1069 TEST_BAD_EXT(formatted, disabled);
1070 TEST_GOOD_EXT(formatted, enabled);
1071
1072 {
1073 // test the handler
1074 comment_parser p;
1075 system::error_code ec;
1076 p.write( formatted.data(), formatted.size(), ec );
1077 BOOST_TEST(! ec);
1078 BOOST_TEST(p.captured() == just_comments);
1079 }
1080 };

Callers 2

runFunction · 0.85
runMethod · 0.85

Calls 8

beginMethod · 0.45
endMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45
writeMethod · 0.45
capturedMethod · 0.45

Tested by

no test coverage detected