diff --git a/src/snl/snl/kernel/SNLAttributes.cpp b/src/snl/snl/kernel/SNLAttributes.cpp index 48c7cf2a..dd7ceb0e 100644 --- a/src/snl/snl/kernel/SNLAttributes.cpp +++ b/src/snl/snl/kernel/SNLAttributes.cpp @@ -129,6 +129,11 @@ bool SNLAttributes::compareAttributes( std::string& reason) { auto prop1 = SNLAttributesPrivateProperty::get(object1); auto prop2 = SNLAttributesPrivateProperty::get(object2); + //xor + if ((prop1 and not prop2) or (not prop1 and prop2)) { + reason = "attributes property mismatch"; + return false; + } if (prop1 and prop2) { using Attributes = std::vector; Attributes attributes1( diff --git a/test/snl/snl/kernel/SNLAttributesTest.cpp b/test/snl/snl/kernel/SNLAttributesTest.cpp index dafff097..09bc1d39 100644 --- a/test/snl/snl/kernel/SNLAttributesTest.cpp +++ b/test/snl/snl/kernel/SNLAttributesTest.cpp @@ -91,4 +91,39 @@ TEST_F(SNLAttributesTest, testCreationOnDesignObject) { SNLAttributes::clearAttributes(term); EXPECT_TRUE(SNLAttributes::getAttributes(term).empty()); +} + +TEST_F(SNLAttributesTest, testCompare) { + auto design1 = SNLDesign::create(library_, SNLName("DESIGN1")); + auto design2 = SNLDesign::create(library_, SNLName("DESIGN2")); + std::string reason; + EXPECT_TRUE(SNLAttributes::compareAttributes(design1, design2, reason)); + EXPECT_TRUE(reason.empty()); + + SNLAttributes::addAttribute(design1, + SNLAttributes::SNLAttribute( + SNLName("PRAGMA1"), + SNLAttributes::SNLAttribute::Value("value1"))); + EXPECT_FALSE(SNLAttributes::compareAttributes(design1, design2, reason)); + EXPECT_FALSE(reason.empty()); + + SNLAttributes::addAttribute(design2, + SNLAttributes::SNLAttribute( + SNLName("PRAGMA1"), + SNLAttributes::SNLAttribute::Value("value1"))); + reason = std::string(); + EXPECT_TRUE(SNLAttributes::compareAttributes(design1, design2, reason)); + EXPECT_TRUE(reason.empty()); + + SNLAttributes::addAttribute(design1, + SNLAttributes::SNLAttribute( + SNLName("PRAGMA2"), + SNLAttributes::SNLAttribute::Value("value2"))); + SNLAttributes::addAttribute(design2, + SNLAttributes::SNLAttribute( + SNLName("PRAGMA2"), + SNLAttributes::SNLAttribute::Value("value3"))); + reason = std::string(); + EXPECT_FALSE(SNLAttributes::compareAttributes(design1, design2, reason)); + EXPECT_FALSE(reason.empty()); } \ No newline at end of file