Search in sources :

Example 1 with AddTestFunction

use of com.dexels.navajo.expression.compiled.AddTestFunction in project navajo by Dexels.

the class TestCompiledExpression method testMultiArgFunction.

@Test
public void testMultiArgFunction() throws Exception {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("SingleValueQuery", fd);
    String expression = "SingleValueQuery( 'aap','noot' )";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    List<String> problems = new ArrayList<>();
    cp.Expression();
    cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Example 2 with AddTestFunction

use of com.dexels.navajo.expression.compiled.AddTestFunction in project navajo by Dexels.

the class TestCompiledExpression method testEmptyFunctionCall.

@Test
public void testEmptyFunctionCall() throws ParseException {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("addtest", fd);
    String expression = "addtest()";
    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());
    Operand o = ss.apply();
    Assert.assertEquals("monkey", o.value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Example 3 with AddTestFunction

use of com.dexels.navajo.expression.compiled.AddTestFunction in project navajo by Dexels.

the class TestCompiledExpression method testNestedNamedFunction.

@Test
public void testNestedNamedFunction() throws Exception {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("MysteryFunction", fd);
    String expression = "MysteryFunction(eep=MysteryFunction('blib','blob'), 'aap','noot' )";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    List<String> problems = new ArrayList<>();
    cp.Expression();
    cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Example 4 with AddTestFunction

use of com.dexels.navajo.expression.compiled.AddTestFunction in project navajo by Dexels.

the class TestCompiledExpression method testFunctionCallWithNamedParams.

@Test
public void testFunctionCallWithNamedParams() throws ParseException {
    FunctionInterface testFunction = new AddTestFunction();
    FunctionDefinition fd = new FunctionDefinition(testFunction.getClass().getName(), "blib", "bleb", "blab");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("addtest", fd);
    String expression = "addtest(aap='blub',3+5,4)";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    cp.Expression();
    SimpleNode atn = (SimpleNode) cp.getJJTree().rootNode();
    List<String> problems = new ArrayList<>();
    ContextExpression ne = atn.interpretToLambda(problems, expression, fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
    Operand result = ne.apply();
    Assert.assertEquals("monkey", result.value);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) AddTestFunction(com.dexels.navajo.expression.compiled.AddTestFunction) Test(org.junit.Test)

Aggregations

FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)4 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)4 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Operand (com.dexels.navajo.document.Operand)2 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)2