-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug function endpoints fn construction
A copy-paste error in built in function construction functions meant that the JVM class was incorrect. This produces unexpected results when visitors are invoked because the wrong visitor branch will be called. This doesn't happen in general because `fromNode` produces the correct behavior.
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,4 +180,4 @@ public Value evaluateCondition(Condition condition) { | |
} | ||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ine/src/test/java/software/amazon/smithy/rulesengine/language/fn/FunctionOfExprsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package software.amazon.smithy.rulesengine.language.fn; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.rulesengine.language.syntax.expr.Expression; | ||
import software.amazon.smithy.rulesengine.language.syntax.fn.FunctionDefinition; | ||
import software.amazon.smithy.rulesengine.language.visit.ExpressionVisitor; | ||
|
||
public class FunctionOfExprsTest { | ||
|
||
@Test | ||
void boolEquals() { | ||
Expression boolEquals = Expression.of(true).equal(true); | ||
assertEquals(boolEquals.accept(new ExpectLibFunction()), false); | ||
assertEquals(boolEquals.accept(new ExpectBuiltInFunction()), "bool"); | ||
} | ||
|
||
|
||
@Test | ||
void stringEquals() { | ||
Expression stringEquals = Expression.of("asdf").equal("asdf"); | ||
assertEquals(stringEquals.accept(new ExpectLibFunction()), false); | ||
assertEquals(stringEquals.accept(new ExpectBuiltInFunction()), "string"); | ||
} | ||
|
||
@Test | ||
void not() { | ||
Expression not = Expression.of("asdf").equal("asdf").not(); | ||
assertEquals(not.accept(new ExpectLibFunction()), false); | ||
assertEquals(not.accept(new ExpectBuiltInFunction()), "not"); | ||
} | ||
|
||
static class ExpectLibFunction extends ExpressionVisitor.Default<Boolean> { | ||
@Override | ||
public Boolean visitLibraryFunction(FunctionDefinition fn, List<Expression> args) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Boolean getDefault() { | ||
return false; | ||
} | ||
} | ||
|
||
static class ExpectBuiltInFunction extends ExpressionVisitor.Default<String> { | ||
@Override | ||
public String getDefault() { | ||
return "other"; | ||
} | ||
|
||
@Override | ||
public String visitBoolEquals(Expression left, Expression right) { | ||
return "bool"; | ||
} | ||
|
||
|
||
@Override | ||
public String visitStringEquals(Expression left, Expression right) { | ||
return "string"; | ||
} | ||
|
||
@Override | ||
public String visitNot(Expression not) { | ||
return "not"; | ||
} | ||
} | ||
} |