11#include < unistd.h>
22
3+ #include < string>
4+ #include < string_view>
5+ #include < vector>
6+
37#include < catch2/catch_test_macros.hpp>
48
59#include " ../src/clp/EncodedVariableInterpreter.hpp"
@@ -15,6 +19,7 @@ using clp::EncodedVariableInterpreter;
1519using clp::enum_to_underlying_type;
1620using clp::ir::VariablePlaceholder;
1721using std::string;
22+ using std::string_view;
1823using std::to_string;
1924using std::vector;
2025
@@ -439,14 +444,15 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
439444
440445 string large_val_str = to_string (cVariableDictionaryIdMax) + " 0" ;
441446 vector<string> var_strs
442- = {" 4938" , large_val_str, " -25.5196868642755" , " -00.00" , " python2.7.3" };
447+ = {" 4938" , large_val_str, " -25.5196868642755" , " -00.00" , " python2.7.3" , " \\ a1 " };
443448 // clang-format off
444449 msg = " here is a string with a small int " + var_strs[0 ]
445450 + " and a very large int " + var_strs[1 ]
446451 + " and a double " + var_strs[2 ]
447452 + " and a weird double " + var_strs[3 ]
448- + " and a str with numbers "
449- + var_strs[4 ] + " and an escape "
453+ + " and a str with numbers " + var_strs[4 ]
454+ + " and a str with a backslash and numbers " + var_strs[5 ]
455+ + " and an escape "
450456 + enum_to_underlying_type (VariablePlaceholder::Escape)
451457 + " and an int placeholder "
452458 + enum_to_underlying_type (VariablePlaceholder::Integer)
@@ -530,6 +536,30 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
530536 search_logtype,
531537 sub_query
532538 ));
539+ auto escape_handler = [](std::string_view str) -> std::string {
540+ std::string escaped_string;
541+ for (auto const c : str) {
542+ if (' *' == c || ' ?' == c
543+ || enum_to_underlying_type (VariablePlaceholder::Escape) == c
544+ || enum_to_underlying_type (VariablePlaceholder::Integer) == c
545+ || enum_to_underlying_type (VariablePlaceholder::Float) == c
546+ || enum_to_underlying_type (VariablePlaceholder::Dictionary) == c)
547+ {
548+ escaped_string.push_back (enum_to_underlying_type (VariablePlaceholder::Escape));
549+ }
550+ escaped_string.push_back (c);
551+ }
552+ return escaped_string;
553+ };
554+ search_logtype += " and a str with a backslash and numbers " ;
555+ REQUIRE (EncodedVariableInterpreter::encode_and_search_dictionary (
556+ escape_handler (var_strs[5 ]),
557+ var_dict_reader,
558+ false ,
559+ search_logtype,
560+ sub_query
561+ ));
562+
533563 search_logtype += " and an escape " ;
534564 search_logtype += enum_to_underlying_type (VariablePlaceholder::Escape);
535565 search_logtype += enum_to_underlying_type (VariablePlaceholder::Escape);
0 commit comments