summaryrefslogtreecommitdiff
path: root/test/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/utils.cpp')
-rw-r--r--test/utils.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/utils.cpp b/test/utils.cpp
index e9c8c587..97f7b0b6 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -219,6 +219,64 @@ TEST_CASE(
}
}
+TEST_CASE("strip_comments ignores # characters inside double quotes",
+ "[utils][issue652]")
+{
+ SECTION("Real-world cases from issue 652") {
+ const auto expected1 =
+ std::string(R"#(highlight article "[-=+#_*~]{3,}.*" green default)#");
+ const auto input1 = expected1 + "# this is a comment";
+ REQUIRE(utils::strip_comments(input1) == expected1);
+
+ const auto expected2 =
+ std::string(R"#(highlight all "(https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+" blue default bold)#");
+ const auto input2 = expected2 + "#heresacomment";
+ REQUIRE(utils::strip_comments(input2) == expected2);
+ }
+
+ SECTION("Escaped double quote inside double quotes is not treated "
+ "as closing quote")
+ {
+ const auto expected =
+ std::string(R"#(test "here \"goes # nothing\" etc" hehe)#");
+ const auto input = expected + "# and here is a comment";
+ REQUIRE(utils::strip_comments(input) == expected);
+ }
+}
+
+TEST_CASE("strip_comments ignores # characters inside backticks", "[utils]")
+{
+ SECTION("Simple case") {
+ const auto expected = std::string(R"#(one `two # three` four)#");
+ const auto input = expected + "# and a comment, of course";
+ REQUIRE(utils::strip_comments(input) == expected);
+ }
+
+ SECTION("Escaped backtick inside backticks is not treated as closing")
+ {
+ const auto expected =
+ std::string(R"#(some `other \` tricky # test` hehe)#");
+ const auto input = expected + "#here goescomment";
+ REQUIRE(utils::strip_comments(input) == expected);
+ }
+}
+
+TEST_CASE("strip_comments is not confused by nested double quotes and backticks",
+ "[utils]")
+{
+ {
+ const auto expected = std::string(R"#("`" ... ` )#");
+ const auto input = expected + "#comment";
+ REQUIRE(utils::strip_comments(input) == expected);
+ }
+
+ {
+ const auto expected = std::string(R"#(aaa ` bbb "ccc ddd" e` dd)#");
+ const auto input = expected + "# a comment string";
+ REQUIRE(utils::strip_comments(input) == expected);
+ }
+}
+
TEST_CASE(
"consolidate_whitespace replaces multiple consecutive"
"whitespace with a single space",