@@ -81,7 +81,7 @@ struct submatch_t {
8181
8282struct submatch_test_t {
8383 std::string_view regex;
84- int capture_count;
84+ int32_t capture_count;
8585 std::vector<submatch_t > tests;
8686};
8787
@@ -129,7 +129,7 @@ TEST_CASE("Regex", "[libts][Regex]")
129129 for (auto &item : submatch_test_data) {
130130 Regex r;
131131 REQUIRE (r.compile (item.regex .data ()) == true );
132- REQUIRE (r.get_capture_count () == item.capture_count );
132+ REQUIRE (r.captureCount () == item.capture_count );
133133
134134 for (auto &test : item.tests ) {
135135 RegexMatches matches;
@@ -146,7 +146,7 @@ TEST_CASE("Regex", "[libts][Regex]")
146146 for (auto &item : submatch_test_data) {
147147 Regex r;
148148 REQUIRE (r.compile (item.regex .data ()) == true );
149- REQUIRE (r.get_capture_count () == item.capture_count );
149+ REQUIRE (r.captureCount () == item.capture_count );
150150
151151 for (auto &test : item.tests ) {
152152 RegexMatches matches;
@@ -489,3 +489,78 @@ TEST_CASE("Regex copy with RE_NOTEMPTY flag", "[libts][Regex][copy][flags]")
489489 CHECK (copy.exec (std::string_view (" " ), RE_NOTEMPTY) == false );
490490 }
491491}
492+
493+ struct backref_test_t {
494+ std::string_view regex;
495+ bool valid;
496+ int32_t backref_max;
497+ };
498+
499+ std::vector<backref_test_t > backref_test_data{
500+ {
501+ {" " },
502+ true , 0 ,
503+ },
504+ {
505+ {R"( \b(\w+)\s+\1\b)" },
506+ true , 1 ,
507+ },
508+ {
509+ {R"( (.)\1)" },
510+ true ,1 ,
511+ },
512+ {
513+ {R"( (.)(.).\2\1)" },
514+ true , 2 ,
515+ },
516+ {
517+ {R"( (.\2\1)" },
518+ false , -1 ,
519+ },
520+ };
521+
522+ TEST_CASE (" Regex back reference counting" , " [libts][Regex][backrefMax]" )
523+ {
524+ // case sensitive test
525+ for (auto &item : backref_test_data) {
526+ Regex r;
527+ REQUIRE (r.compile (item.regex ) == item.valid );
528+ REQUIRE (r.backrefMax () == item.backref_max );
529+ }
530+ }
531+
532+ struct match_context_test_t {
533+ std::string_view regex;
534+ std::string_view str;
535+ bool valid;
536+ int32_t rcode;
537+ };
538+
539+ std::vector<match_context_test_t > match_context_test_data{
540+ {
541+ {" abc" },
542+ {" abc" },
543+ true , 1 ,
544+ },
545+ {{" a+b" }, {" aaaaaab" }, true , 1 },
546+ {{" (a+)+b" }, {" aaaaab" }, true , -47 }, // PCRE2_ERROR_MATCHLIMIT
547+ {
548+ {" (." },
549+ {" a" },
550+ false , -1 ,
551+ },
552+ };
553+
554+ TEST_CASE (" RegexMatchContext" , " [libts][Regex][RegexMatchContext]" )
555+ {
556+ RegexMatchContext match_context;
557+ match_context.setMatchLimit (5 );
558+
559+ // case sensitive test
560+ for (auto &item : match_context_test_data) {
561+ Regex r;
562+ REQUIRE (r.compile (item.regex ) == item.valid );
563+ RegexMatches matches;
564+ REQUIRE (r.exec (item.str , matches, 0 , &match_context) == item.rcode );
565+ }
566+ }
0 commit comments