Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OR condition in scoped attribute selector #1618

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ private boolean compareWithScope(AttributeValue scope) {
// Ensure that each assertion matches, and provide them the scope.
for (Assertion assertion : assertions) {
AttributeValue lhs = assertion.lhs.create(scope);
boolean matchedOneRhs = false;
for (ScopedFactory factory : assertion.rhs) {
AttributeValue rhs = factory.create(scope);
if (!assertion.comparator.compare(lhs, rhs, assertion.caseInsensitive)) {
return false;
if (assertion.comparator.compare(lhs, rhs, assertion.caseInsensitive)) {
matchedOneRhs = true;
break;
}
}

if (!matchedOneRhs) {
return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,24 @@ public void evaluatesScopedAttributes() {
assertThat(shapes2, equalTo(shapes1));
}

@Test
public void evaluatesScopedAttributesWithOr() {
final Model enumModel = Model.assembler()
.addImport(SelectorTest.class.getResource("enums.smithy"))
.assemble()
.unwrap();

Set<String> shapes = ids(
enumModel, "[@trait|enum|(values): @{name} ^= DIA, CLU]");

assertThat(shapes, containsInAnyOrder("smithy.example#Suit"));

shapes = ids(
enumModel, "[@trait|enum|(values): @{name} ^= DIA, BLA]");

assertThat(shapes, containsInAnyOrder("smithy.example#Color", "smithy.example#Suit"));
}

@Test
public void evaluatesScopedAttributesWithProjections() {
// Note that the projection can be on either side.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$version: "1.0"

namespace smithy.example

@enum([
{ name: "DIAMOND", value: "diamond"},
{ name: "CLUB", value: "club"},
{ name: "HEART", value: "heart"},
{ name: "SPADE", value: "spade"},
])
string Suit

@enum([
{ name: "RED", value: "red"}
{ name: "BLACK", value: "black"}
])
string Color