use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testFunctionType.
@Test
public void testFunctionType() {
ExpressionCache ce = ExpressionCache.getInstance();
List<String> problems = new ArrayList<>();
ContextExpression cx = ce.parse(problems, "ToUpper([whatever])", name -> FunctionClassification.DEFAULT);
Assert.assertEquals(Property.STRING_PROPERTY, cx.returnType().get());
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testImmutablilityPropagation.
@Test
public void testImmutablilityPropagation() throws TMLExpressionException {
List<String> problems = new ArrayList<>();
ContextExpression o = ExpressionCache.getInstance().parse(problems, "ToUpper(ToLower('Bob'))", name -> FunctionClassification.DEFAULT);
System.err.println("problems: " + problems);
System.err.println("immutable: " + o.isLiteral());
Assert.assertTrue(o.isLiteral());
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method parseIntAddition.
@Test
public void parseIntAddition() throws ParseException, TMLExpressionException {
List<String> problems = new ArrayList<>();
String expression = "1+1";
ContextExpression ss = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
ContextExpression ss2 = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
if (!problems.isEmpty()) {
throw new TMLExpressionException(problems, expression);
}
Assert.assertEquals(2, ss.apply().value);
Assert.assertEquals(2, ss2.apply().value);
Assert.assertTrue(ss.isLiteral());
Assert.assertTrue(ss2.isLiteral());
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testParseTmlConditionalComplex.
@Test
@Ignore
public void testParseTmlConditionalComplex() throws ParseException, TMLExpressionException {
String expression = "{request@.:!?[/NewMemberFunction/FromUnion]} AND {response@.:!?[/ExistingClubFunction/PersonId]}";
StringReader sr = new StringReader(expression);
CompiledParser cp = new CompiledParser(sr);
cp.Expression();
List<String> problems = new ArrayList<>();
ContextExpression ss = cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
if (!problems.isEmpty()) {
throw new TMLExpressionException(problems, expression);
}
ss.apply();
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestTypeCheckCompiledExpressionEvaluator method testEquals.
@Test
public void testEquals() {
ExpressionCache ce = ExpressionCache.getInstance();
List<String> problems = new ArrayList<>();
ContextExpression cx = ce.parse(problems, "1==1", fn -> FunctionClassification.DEFAULT);
Assert.assertEquals(Property.BOOLEAN_PROPERTY, cx.returnType().get());
}
Aggregations