Search in sources :

Example 1 with Expression

use of com.dexels.navajo.parser.Expression in project navajo by Dexels.

the class TestCompiledExpression method testNamedExpression.

@Test
public void testNamedExpression() throws ParseException {
    String expression = "aap=1+1";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    cp.KeyValue();
    ASTKeyValueNode atn = (ASTKeyValueNode) cp.getJJTree().rootNode();
    List<String> problems = new ArrayList<>();
    NamedExpression ne = (NamedExpression) atn.interpretToLambda(problems, expression, fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
    Assert.assertEquals(0, problems.size());
    Assert.assertEquals("aap", ne.name);
    Assert.assertEquals(2, ne.apply().value);
}
Also used : FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) ParameterNamesFunction(com.dexels.navajo.expression.compiled.ParameterNamesFunction) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) Before(org.junit.Before) FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) ExpressionCache(com.dexels.navajo.parser.compiled.api.ExpressionCache) FunctionFactoryFactory(com.dexels.navajo.functions.util.FunctionFactoryFactory) Message(com.dexels.navajo.document.Message) Test(org.junit.Test) Expression(com.dexels.navajo.parser.Expression) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) NavajoFactory(com.dexels.navajo.document.NavajoFactory) List(java.util.List) StringReader(java.io.StringReader) Ignore(org.junit.Ignore) FunctionClassification(com.dexels.navajo.expression.api.FunctionClassification) NamedExpression(com.dexels.navajo.parser.NamedExpression) SystemException(com.dexels.navajo.script.api.SystemException) Optional(java.util.Optional) Property(com.dexels.navajo.document.Property) Assert(org.junit.Assert) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) NamedExpression(com.dexels.navajo.parser.NamedExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Message (com.dexels.navajo.document.Message)1 Navajo (com.dexels.navajo.document.Navajo)1 NavajoFactory (com.dexels.navajo.document.NavajoFactory)1 Operand (com.dexels.navajo.document.Operand)1 Property (com.dexels.navajo.document.Property)1 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)1 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)1 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)1 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)1 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)1 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)1 ParameterNamesFunction (com.dexels.navajo.expression.compiled.ParameterNamesFunction)1 FunctionFactoryFactory (com.dexels.navajo.functions.util.FunctionFactoryFactory)1 Expression (com.dexels.navajo.parser.Expression)1 NamedExpression (com.dexels.navajo.parser.NamedExpression)1 ExpressionCache (com.dexels.navajo.parser.compiled.api.ExpressionCache)1 SystemException (com.dexels.navajo.script.api.SystemException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1