diff --git a/apps/UnitTestsApp/src/UnitTests.cpp b/apps/UnitTestsApp/src/UnitTests.cpp index 54f9d24b..dc1baa55 100644 --- a/apps/UnitTestsApp/src/UnitTests.cpp +++ b/apps/UnitTestsApp/src/UnitTests.cpp @@ -10,6 +10,14 @@ #include "gtest/gtest.h" #include +TEST(TestCaseName, Test_regex_minus) { + string str = "^(c^(a^(b)d))e"; + Regex r1(str); + string r1_str = r1.to_txt(); + Regex r2(r1_str); + ASSERT_EQ(true, Regex::equivalent(r1, r2)); +} + TEST(TestCaseName, Test_random_regex_parsing) { RegexGenerator rg(15, 10, 5, 3); for (int i = 0; i < 30; i++) { diff --git a/libs/Objects/src/AlgExpression.cpp b/libs/Objects/src/AlgExpression.cpp index c1d57cf0..e10b0bb9 100644 --- a/libs/Objects/src/AlgExpression.cpp +++ b/libs/Objects/src/AlgExpression.cpp @@ -92,7 +92,7 @@ string AlgExpression::to_txt() const { if (term_l && term_l->type == Type::alt) { str1 = "(" + str1 + ")"; } - if (term_r && term_l->type == Type::alt) { + if (term_r && term_r->type == Type::alt) { str2 = "(" + str2 + ")"; } break; diff --git a/libs/Objects/src/BackRefRegex.cpp b/libs/Objects/src/BackRefRegex.cpp index 2799b80b..8761b82e 100644 --- a/libs/Objects/src/BackRefRegex.cpp +++ b/libs/Objects/src/BackRefRegex.cpp @@ -58,7 +58,7 @@ template const BackRefRegex* BackRefRegex::cast(const T* ptr) { } string BackRefRegex::to_txt() const { - BackRefRegex* br_term_l; + BackRefRegex* br_term_l, *br_term_r; string str1, str2; if (term_l) { str1 = term_l->to_txt(); @@ -66,6 +66,7 @@ string BackRefRegex::to_txt() const { } if (term_r) { str2 = term_r->to_txt(); + br_term_r = cast(term_r); } string symb; switch (type) { @@ -73,7 +74,7 @@ string BackRefRegex::to_txt() const { if (term_l && br_term_l->type == Type::alt) { str1 = "(" + str1 + ")"; } - if (term_r && br_term_l->type == Type::alt) { + if (term_r && br_term_r->type == Type::alt) { str2 = "(" + str2 + ")"; } break;