|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 | import static org.assertj.core.api.Assertions.fail; |
5 | 5 |
|
| 6 | +import com.hubspot.jinjava.lib.exptest.IsEvenExpTest; |
| 7 | +import com.hubspot.jinjava.lib.exptest.IsFalseExpTest; |
| 8 | +import com.hubspot.jinjava.lib.exptest.IsTrueExpTest; |
6 | 9 | import de.odysseus.el.tree.impl.Builder; |
| 10 | +import de.odysseus.el.tree.impl.Builder.Feature; |
7 | 11 | import de.odysseus.el.tree.impl.ast.AstBinary; |
| 12 | +import de.odysseus.el.tree.impl.ast.AstDot; |
8 | 13 | import de.odysseus.el.tree.impl.ast.AstIdentifier; |
9 | 14 | import de.odysseus.el.tree.impl.ast.AstMethod; |
10 | 15 | import de.odysseus.el.tree.impl.ast.AstNested; |
@@ -127,6 +132,39 @@ public void itParsesExpTestLikeDictionary() { |
127 | 132 | assertThat(astNode).isInstanceOf(AstDict.class); |
128 | 133 | } |
129 | 134 |
|
| 135 | + @Test |
| 136 | + public void itResolvesAlternateExpTestSyntax() { |
| 137 | + AstNode regularSyntax = buildExpressionNodes("#{2 is even}"); |
| 138 | + |
| 139 | + assertThat(regularSyntax).isInstanceOf(AstMethod.class); |
| 140 | + assertThat(regularSyntax.getChild(0)).isInstanceOf(AstDot.class); |
| 141 | + assertThat(regularSyntax.getChild(1)).isInstanceOf(AstParameters.class); |
| 142 | + AstNode alternateSyntax = buildExpressionNodes( |
| 143 | + "#{exptest:even.evaluate(2, ____int3rpr3t3r____)}" |
| 144 | + ); |
| 145 | + |
| 146 | + assertThat(alternateSyntax).isInstanceOf(AstMethod.class); |
| 147 | + assertThat(alternateSyntax.getChild(0)).isInstanceOf(AstDot.class); |
| 148 | + assertThat(alternateSyntax.getChild(1)).isInstanceOf(AstParameters.class); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void itResolvesAlternateExpTestSyntaxForTrueAndFalseExpTests() { |
| 153 | + AstNode falseExpTest = buildExpressionNodes( |
| 154 | + "#{exptest:false.evaluate(2, ____int3rpr3t3r____)}" |
| 155 | + ); |
| 156 | + assertThat(falseExpTest).isInstanceOf(AstMethod.class); |
| 157 | + assertThat(falseExpTest.getChild(0)).isInstanceOf(AstDot.class); |
| 158 | + assertThat(falseExpTest.getChild(1)).isInstanceOf(AstParameters.class); |
| 159 | + |
| 160 | + AstNode trueExpTest = buildExpressionNodes( |
| 161 | + "#{exptest:true.evaluate(2, ____int3rpr3t3r____)}" |
| 162 | + ); |
| 163 | + assertThat(trueExpTest).isInstanceOf(AstMethod.class); |
| 164 | + assertThat(trueExpTest.getChild(0)).isInstanceOf(AstDot.class); |
| 165 | + assertThat(trueExpTest.getChild(1)).isInstanceOf(AstParameters.class); |
| 166 | + } |
| 167 | + |
130 | 168 | private void assertForExpression( |
131 | 169 | AstNode astNode, |
132 | 170 | String leftExpected, |
@@ -164,7 +202,10 @@ private void assertLeftAndRightByOperator( |
164 | 202 | } |
165 | 203 |
|
166 | 204 | private AstNode buildExpressionNodes(String input) { |
167 | | - ExtendedCustomParser extendedParser = new ExtendedCustomParser(new Builder(), input); |
| 205 | + ExtendedCustomParser extendedParser = new ExtendedCustomParser( |
| 206 | + new Builder(Feature.METHOD_INVOCATIONS), |
| 207 | + input |
| 208 | + ); |
168 | 209 | extendedParser.consumeTokenExpose(); |
169 | 210 | extendedParser.consumeTokenExpose(); |
170 | 211 |
|
|
0 commit comments