Search in sources :

Example 6 with ContextExpression

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());
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) ExpressionCache(com.dexels.navajo.parser.compiled.api.ExpressionCache) Test(org.junit.Test)

Example 7 with ContextExpression

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());
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with ContextExpression

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());
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Test(org.junit.Test)

Example 9 with ContextExpression

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();
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with ContextExpression

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());
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) ExpressionCache(com.dexels.navajo.parser.compiled.api.ExpressionCache) Test(org.junit.Test)

Aggregations

ContextExpression (com.dexels.navajo.expression.api.ContextExpression)36 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)18 Operand (com.dexels.navajo.document.Operand)14 Message (com.dexels.navajo.document.Message)13 Navajo (com.dexels.navajo.document.Navajo)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)12 Selection (com.dexels.navajo.document.Selection)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 Access (com.dexels.navajo.script.api.Access)12 Optional (java.util.Optional)12 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)9 ExpressionCache (com.dexels.navajo.parser.compiled.api.ExpressionCache)7 StringReader (java.io.StringReader)7 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)4 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)4 NamedExpression (com.dexels.navajo.parser.NamedExpression)4 List (java.util.List)4 Function (java.util.function.Function)4