From 3ba9ca370b85f704cfa763738600931d41681369 Mon Sep 17 00:00:00 2001 From: DanilaKn Date: Thu, 9 Nov 2023 23:42:12 +0300 Subject: [PATCH] =?UTF-8?q?(#290)=20Fix=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=B8=20unit=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=86=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/UnitTestsApp/src/UnitTests.cpp | 8 ++++++++ libs/Objects/src/AlgExpression.cpp | 2 +- libs/Objects/src/BackRefRegex.cpp | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) 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;