From 6b62145a599144c9a938c8bfb0af69edaa9dddd3 Mon Sep 17 00:00:00 2001 From: Lovro Lugovic Date: Wed, 10 Apr 2019 10:48:13 +0200 Subject: [PATCH] Fix CypherMainVisitor tests relying on traversal order Summary: The tests `RelationshipPatternNoDetails` and `PatternPartBraces` in `memgraph__unit__cypher_main_visitor` checked for the names of the anonymous identifiers and therefore implicitly relied on the order of the traversal of the tree. This "bug" surfaced when Memgraph was compiled with GCC (tested on >= 6.3.0). Reviewers: mtomic, teon.banek, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1945 --- tests/unit/cypher_main_visitor.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 2d7514895..05c4aaee3 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -1076,11 +1076,20 @@ TEST_P(CypherMainVisitorTest, RelationshipPatternNoDetails) { ASSERT_TRUE(edge); auto *node2 = dynamic_cast(match->patterns_[0]->atoms_[2]); ASSERT_TRUE(node2); - EXPECT_EQ(edge->direction_, EdgeAtom::Direction::BOTH); + ASSERT_TRUE(node1->identifier_); ASSERT_TRUE(edge->identifier_); - EXPECT_THAT(edge->identifier_->name_, - CypherMainVisitor::kAnonPrefix + std::to_string(2)); + ASSERT_TRUE(node2->identifier_); + EXPECT_THAT( + std::vector({node1->identifier_->name_, + edge->identifier_->name_, + node2->identifier_->name_}), + UnorderedElementsAre(CypherMainVisitor::kAnonPrefix + std::to_string(1), + CypherMainVisitor::kAnonPrefix + std::to_string(2), + CypherMainVisitor::kAnonPrefix + std::to_string(3))); + EXPECT_FALSE(node1->identifier_->user_declared_); EXPECT_FALSE(edge->identifier_->user_declared_); + EXPECT_FALSE(node2->identifier_->user_declared_); + EXPECT_EQ(edge->direction_, EdgeAtom::Direction::BOTH); } // PatternPart in braces. @@ -1103,11 +1112,20 @@ TEST_P(CypherMainVisitorTest, PatternPartBraces) { ASSERT_TRUE(edge); auto *node2 = dynamic_cast(match->patterns_[0]->atoms_[2]); ASSERT_TRUE(node2); - EXPECT_EQ(edge->direction_, EdgeAtom::Direction::BOTH); + ASSERT_TRUE(node1->identifier_); ASSERT_TRUE(edge->identifier_); - EXPECT_THAT(edge->identifier_->name_, - CypherMainVisitor::kAnonPrefix + std::to_string(2)); + ASSERT_TRUE(node2->identifier_); + EXPECT_THAT( + std::vector({node1->identifier_->name_, + edge->identifier_->name_, + node2->identifier_->name_}), + UnorderedElementsAre(CypherMainVisitor::kAnonPrefix + std::to_string(1), + CypherMainVisitor::kAnonPrefix + std::to_string(2), + CypherMainVisitor::kAnonPrefix + std::to_string(3))); + EXPECT_FALSE(node1->identifier_->user_declared_); EXPECT_FALSE(edge->identifier_->user_declared_); + EXPECT_FALSE(node2->identifier_->user_declared_); + EXPECT_EQ(edge->direction_, EdgeAtom::Direction::BOTH); } TEST_P(CypherMainVisitorTest, RelationshipPatternDetails) {