Skip to content

Commit

Permalink
test Attributes comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Nov 1, 2024
1 parent 68f9e42 commit c98ff41
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/snl/snl/kernel/SNLAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SNLAttribute>;
Attributes attributes1(
Expand Down
35 changes: 35 additions & 0 deletions test/snl/snl/kernel/SNLAttributesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit c98ff41

Please sign in to comment.