33#include < boost/foreach.hpp>
44#include < boost/range/combine.hpp>
55#include < catch2/catch.hpp>
6+ #include < string_utils/constants.hpp>
67#include < string_utils/string_utils.hpp>
78
89using clp::string_utils::clean_up_wildcard_search_string;
910using clp::string_utils::convert_string_to_int;
11+ using clp::string_utils::cSingleCharWildcard;
12+ using clp::string_utils::cWildcardEscapeChar;
13+ using clp::string_utils::cZeroOrMoreCharsWildcard;
14+ using clp::string_utils::replace_unescaped_char;
1015using clp::string_utils::wildcard_match_unsafe;
1116using clp::string_utils::wildcard_match_unsafe_case_sensitive;
1217using std::chrono::duration;
@@ -22,6 +27,57 @@ TEST_CASE("to_lower", "[to_lower]") {
2227 REQUIRE (str == " test123test" );
2328}
2429
30+ TEST_CASE (" replace_unescaped_char" , " [replace_unescaped_char]" ) {
31+ auto check = [](char escape_char,
32+ char from_char,
33+ char to_char,
34+ std::string in,
35+ std::string const & expected) {
36+ replace_unescaped_char (escape_char, from_char, to_char, in);
37+ REQUIRE ((in == expected));
38+ };
39+
40+ SECTION (" Conventional escape and wildcard characters" ) {
41+ auto [str, expected] = GENERATE (
42+ as<std::pair<string, string>>{},
43+
44+ // Replacements with no escape chars present
45+ std::pair{R"( a?b)" , R"( a*b)" },
46+ std::pair{R"( ?leading)" , R"( *leading)" },
47+ std::pair{R"( trailing?)" , R"( trailing*)" },
48+ std::pair{R"( multiple??q)" , R"( multiple**q)" },
49+
50+ // Replacements with escape chars present
51+ std::pair{R"( a\\?b)" , R"( a\\*b)" },
52+ std::pair{R"( \\?abc)" , R"( \\*abc)" },
53+ std::pair{R"( abc\\?)" , R"( abc\\*)" },
54+
55+ // No replacements with escape chars present
56+ std::pair{R"( a\?b)" , R"( a\?b)" },
57+ std::pair{R"( \?abc)" , R"( \?abc)" },
58+ std::pair{R"( abc\?)" , R"( abc\?)" },
59+
60+ // Mixed
61+ std::pair{R"( a\\?b a\?b a?b)" , R"( a\\*b a\?b a*b)" },
62+ std::pair{R"( \\?abc \?abc a?b)" , R"( \\*abc \?abc a*b)" },
63+ std::pair{R"( abc\\? abc\? a?b)" , R"( abc\\* abc\? a*b)" },
64+
65+ // Additional edge cases
66+ std::pair{R"( no change)" , R"( no change)" },
67+ std::pair{R"( )" , R"( )" },
68+ std::pair{R"( \)" , R"( \)" },
69+ std::pair{R"( \\)" , R"( \\)" },
70+ std::pair{R"( ?\)" , R"( *\)" }
71+ );
72+
73+ check (cWildcardEscapeChar, cSingleCharWildcard, cZeroOrMoreCharsWildcard, str, expected);
74+ }
75+
76+ SECTION (" Unconventional escape and wildcard characters" ) {
77+ check (' q' , ' w' , ' e' , R"( aqqwb aqwb awb)" , R"( aqqeb aqwb aeb)" );
78+ }
79+ }
80+
2581TEST_CASE (" clean_up_wildcard_search_string" , " [clean_up_wildcard_search_string]" ) {
2682 string str;
2783
0 commit comments