From 7b8cce38f2fbe0ccc24d052281f0efd14da105b7 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 17 Oct 2014 11:00:19 +0200
Subject: [PATCH] Fix relation and equal operators of FormalRegExp

---
 .../regexp/formal/FormalRegExpAlternation.cpp |  6 +-
 .../formal/FormalRegExpConcatenation.cpp      |  6 +-
 .../regexp/formal/FormalRegExpIteration.cpp   |  4 +-
 alib2data/test-src/regexp/RegExpTest.cpp      | 56 +++++++++++++------
 4 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp b/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp
index a7dbf0cfb7..d01a6a9508 100644
--- a/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp
+++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.cpp
@@ -142,12 +142,12 @@ bool FormalRegExpAlternation::operator>(const FormalRegExpElement& other) const
 
 
 bool FormalRegExpAlternation::operator<(const FormalRegExpAlternation& other) const {
-	if(this->left == other.left) return this->right < other.right;
-	return this->left < other.left;
+	if(*left == *other.left) return *right < *other.right;
+	return *left < *other.left;
 }
 
 bool FormalRegExpAlternation::operator==(const FormalRegExpAlternation& other) const {
-	return this->left == other.left && this->right == other.right;
+	return *left == *other.left && *right == *other.right;
 }
 
 void FormalRegExpAlternation::operator>>(std::ostream& out) const {
diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp b/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp
index 41154f6e3c..07c1b4327f 100644
--- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp
+++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.cpp
@@ -141,12 +141,12 @@ bool FormalRegExpConcatenation::operator>(const FormalRegExpElement& other) cons
 
 
 bool FormalRegExpConcatenation::operator<(const FormalRegExpConcatenation& other) const {
-	if(this->left == other.left) return this->right < other.right;
-	return this->left < other.left;
+	if(*left == *other.left) return *right < *other.right;
+	return *left < *other.left;
 }
 
 bool FormalRegExpConcatenation::operator==(const FormalRegExpConcatenation& other) const {
-	return this->left == other.left && this->right == other.right;
+	return *left == *other.left && *right == *other.right;
 }
 
 void FormalRegExpConcatenation::operator>>(std::ostream& out) const {
diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.cpp b/alib2data/src/regexp/formal/FormalRegExpIteration.cpp
index 6ee36586d2..ea044dc85c 100644
--- a/alib2data/src/regexp/formal/FormalRegExpIteration.cpp
+++ b/alib2data/src/regexp/formal/FormalRegExpIteration.cpp
@@ -106,11 +106,11 @@ bool FormalRegExpIteration::operator>(const FormalRegExpElement& other) const {
 }
 
 bool FormalRegExpIteration::operator<(const FormalRegExpIteration& other) const {
-	return *(this->element) < *(other.element);
+	return *element < *other.element;
 }
 
 bool FormalRegExpIteration::operator==(const FormalRegExpIteration& other) const {
-	return *(this->element) == *(other.element);
+	return *element == *other.element;
 }
 
 void FormalRegExpIteration::operator>>(std::ostream& out) const {
diff --git a/alib2data/test-src/regexp/RegExpTest.cpp b/alib2data/test-src/regexp/RegExpTest.cpp
index bcc8c4e2ea..3fafc00927 100644
--- a/alib2data/test-src/regexp/RegExpTest.cpp
+++ b/alib2data/test-src/regexp/RegExpTest.cpp
@@ -24,30 +24,54 @@ void RegExpTest::tearDown() {
 }
 
 void RegExpTest::testCopyConstruct() {
-	regexp::UnboundedRegExp regexp;
-	regexp.setAlphabet({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("3")});
-	regexp::UnboundedRegExpSymbol l1 = regexp::UnboundedRegExpSymbol("1");
-	regexp::UnboundedRegExpSymbol l2 = regexp::UnboundedRegExpSymbol("2");
+	{
+		regexp::UnboundedRegExp regexp;
+		regexp.setAlphabet({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("3")});
+		regexp::UnboundedRegExpSymbol l1 = regexp::UnboundedRegExpSymbol("1");
+		regexp::UnboundedRegExpSymbol l2 = regexp::UnboundedRegExpSymbol("2");
 
-	regexp::UnboundedRegExpConcatenation con = regexp::UnboundedRegExpConcatenation();
-	con.appendElement(l1);
-	con.appendElement(l2);
+		regexp::UnboundedRegExpConcatenation con = regexp::UnboundedRegExpConcatenation();
+		con.appendElement(l1);
+		con.appendElement(l2);
 
-	regexp::UnboundedRegExpIteration ite = regexp::UnboundedRegExpIteration(l1);
+		regexp::UnboundedRegExpIteration ite = regexp::UnboundedRegExpIteration(l1);
 
-	regexp::UnboundedRegExpAlternation alt = regexp::UnboundedRegExpAlternation();
-	alt.appendElement(con);
-	alt.appendElement(ite);
+		regexp::UnboundedRegExpAlternation alt = regexp::UnboundedRegExpAlternation();
+		alt.appendElement(con);
+		alt.appendElement(ite);
 
-	regexp.setRegExp(alt);
+		regexp.setRegExp(alt);
 
-	regexp::UnboundedRegExp regexp2(regexp);
+		regexp::UnboundedRegExp regexp2(regexp);
 
-	CPPUNIT_ASSERT( regexp == regexp2 );
+		CPPUNIT_ASSERT( regexp == regexp2 );
 
-	regexp::UnboundedRegExp regexp3(std::move(regexp));
+		regexp::UnboundedRegExp regexp3(std::move(regexp));
 
-	CPPUNIT_ASSERT( regexp2 == regexp3 );
+		CPPUNIT_ASSERT( regexp2 == regexp3 );
+	}
+	{
+		regexp::FormalRegExp regexp;
+		regexp.setAlphabet({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("3")});
+		regexp::FormalRegExpSymbol l1 = regexp::FormalRegExpSymbol("1");
+		regexp::FormalRegExpSymbol l2 = regexp::FormalRegExpSymbol("2");
+
+		regexp::FormalRegExpConcatenation con = regexp::FormalRegExpConcatenation(l1, l2);
+
+		regexp::FormalRegExpIteration ite = regexp::FormalRegExpIteration(l1);
+
+		regexp::FormalRegExpAlternation alt = regexp::FormalRegExpAlternation(con, ite);
+
+		regexp.setRegExp(alt);
+
+		regexp::FormalRegExp regexp2(regexp);
+
+		CPPUNIT_ASSERT( regexp == regexp2 );
+
+		regexp::FormalRegExp regexp3(std::move(regexp));
+
+		CPPUNIT_ASSERT( regexp2 == regexp3 );
+	}
 }
 
 void RegExpTest::testEqual() {
-- 
GitLab