Skip to content

Commit

Permalink
Fix resolution for build "is" expression
Browse files Browse the repository at this point in the history
  • Loading branch information
samukce committed Jun 12, 2020
1 parent d3a3f27 commit 8cb5142
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ protected AstNode value() throws ScanException, ParseException {
List<AstNode> exptestParams = Lists.newArrayList(v, interpreter());

// optional exptest arg
AstNode arg = expr(false);
AstNode arg = value();
if (arg != null) {
exptestParams.add(arg);
}
Expand Down
26 changes: 22 additions & 4 deletions src/test/java/com/hubspot/jinjava/el/ext/ExtendedParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void itParseSingleBinaryEqualCondition() {

@Test
public void itParseBinaryOrEqualCondition() {
AstNode astNode = buildExpressionNodes("#{'a' == 'b' or 'c' == 'c'}");
AstNode astNode = buildExpressionNodes("#{'a' == 'b' or 'c' == 'd'}");

assertThat(astNode).isInstanceOf(AstBinary.class);

Expand All @@ -38,7 +38,7 @@ public void itParseBinaryOrEqualCondition() {
assertThat(right).isInstanceOf(AstBinary.class);

assertLeftAndRightByOperator((AstBinary) left, "a", "b", AstBinary.EQ);
assertLeftAndRightByOperator((AstBinary) right, "c", "c", AstBinary.EQ);
assertLeftAndRightByOperator((AstBinary) right, "c", "d", AstBinary.EQ);
}

@Test
Expand All @@ -51,7 +51,7 @@ public void itParseSingleBinaryWithExpressionCondition() {

@Test
public void itParseBinaryOrWithEqualSymbolAndExpressionCondition() {
AstNode astNode = buildExpressionNodes("#{'a' == 'b' or 'c' is equalto 'c'}");
AstNode astNode = buildExpressionNodes("#{'a' == 'b' or 'c' is equalto 'd'}");

assertThat(astNode).isInstanceOf(AstBinary.class);

Expand All @@ -64,7 +64,25 @@ public void itParseBinaryOrWithEqualSymbolAndExpressionCondition() {
assertThat(right).isInstanceOf(AstMethod.class);

assertLeftAndRightByOperator((AstBinary) left, "a", "b", AstBinary.EQ);
assertForExpression(right, "c", "c", "exptest:equalto");
assertForExpression(right, "c", "d", "exptest:equalto");
}

@Test
public void itParseBinaryOrWithExpressionsCondition() {
AstNode astNode = buildExpressionNodes("#{'a' is equalto 'b' or 'c' is equalto 'd'}");

assertThat(astNode).isInstanceOf(AstBinary.class);

AstBinary astBinary = (AstBinary) astNode;
AstNode left = astBinary.getChild(0);
AstNode right = astBinary.getChild(1);

assertThat(astBinary.getOperator()).isEqualTo(OrOperator.OP);
assertThat(left).isInstanceOf(AstMethod.class);
assertThat(right).isInstanceOf(AstMethod.class);

assertForExpression(left, "a", "b", "exptest:equalto");
assertForExpression(right, "c", "d", "exptest:equalto");
}

private void assertForExpression(AstNode astNode, String leftExpected, String rightExpected, String expression) {
Expand Down

0 comments on commit 8cb5142

Please sign in to comment.