use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testParseTml.
@Test
public void testParseTml() throws ParseException, TMLExpressionException {
String expression = "[/TestMessage/TestProperty]";
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);
}
Assert.assertEquals("TestValue", ss.apply(input, Optional.empty(), Optional.empty()).value);
Assert.assertFalse(ss.isLiteral());
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testNestedFunctionType.
@Test
public void testNestedFunctionType() 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("returntype: " + o.returnType().orElse("<unknown>"));
Assert.assertTrue("Expected a return type here", o.returnType().isPresent());
Assert.assertEquals("string", o.returnType().get());
System.err.println("immutable: " + o.isLiteral());
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testFunctionEvaluation.
@Test
public void testFunctionEvaluation() {
List<String> problems = new ArrayList<>();
ExpressionCache ce = ExpressionCache.getInstance();
String embeddedExpression = "StringFunction('matches','aaa', '.*[-]+7[0-9][A-z]*$' ))";
ContextExpression cemb = ce.parse(problems, embeddedExpression, name -> FunctionClassification.DEFAULT);
System.err.println("Problems: " + problems);
Assert.assertEquals(0, problems.size());
Operand result = cemb.apply(input, Optional.empty(), Optional.empty());
System.err.println("Result: " + result.type + " value: " + result.value);
}
use of com.dexels.navajo.expression.api.ContextExpression in project navajo by Dexels.
the class TestCompiledExpression method testImmutablilityPropagationPerformance.
@Test
public void testImmutablilityPropagationPerformance() throws TMLExpressionException {
CacheSubexpression.setCacheSubExpression(true);
;
List<String> problems = new ArrayList<>();
ContextExpression o = ExpressionCache.getInstance().parse(problems, "ToUpper(ToLower('Bob'))", name -> FunctionClassification.DEFAULT);
long now = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
o.apply();
// .value;
// System.err.println("tr:" +tr);
}
System.err.println("Now: " + (System.currentTimeMillis() - now));
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 testForall.
@Test
public void testForall() throws TMLExpressionException {
List<String> problems = new ArrayList<>();
ExpressionCache ce = ExpressionCache.getInstance();
// String extBackup ="FORALL( '/TestArrayMessageMessage', `! ?[Delete] OR ! [Delete] OR [/__globals__/ApplicationInstance] != 'TENANT' OR ! StringFunction( 'matches', [ChargeCodeId], '.*[-]+7[0-9][A-z]*$' )` )";
String ext = "FORALL( '/Msg', `!StringFunction( 'matches', [ChargeCodeId], '.*[-]+7[0-9][A-z]*$' )` )";
// String expression = "FORALL( '/Charges' , `! ?[Delete] OR ! [Delete] OR [/__globals__/ApplicationInstance] != 'SOMETENANT' OR [SomeProperty] == 'SOMESTRING' `)";
// ce.parse(problems, expression, mode, allowLiteralResolve)
ContextExpression cx = ce.parse(problems, ext, name -> FunctionClassification.DEFAULT);
System.err.println("Problems: " + problems);
Assert.assertEquals(0, problems.size());
Operand result = cx.apply(input, Optional.empty(), Optional.empty());
System.err.println("Result: " + result.type + " value: " + result.value);
// Operand result = Expression.evaluate(expression, testDoc,null,topMessage);
}
Aggregations