Search in sources :

Example 76 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class ExpressionTest method testExpressionWithinSelection.

@Test
public void testExpressionWithinSelection() throws Exception {
    Expression.compileExpressions = true;
    Operand o = Expression.evaluate("[name]", testDoc, null, topMessage, testSelection, null);
    assertEquals("option1", o.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 77 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class ExpressionTest method testTrailingTMLPath.

@Test
public void testTrailingTMLPath() throws Exception {
    Expression.compileExpressions = true;
    ImmutableMessage outer = ImmutableFactory.empty().with("outerint", 1, "integer");
    ImmutableMessage inner = ImmutableFactory.empty().with("innerint", 3, "integer");
    ImmutableMessage combined = outer.withSubMessage("sub", inner);
    Operand o = Expression.evaluateImmutable("[sub/]", null, Optional.of(combined), Optional.empty());
    ImmutableMessage s = o.immutableMessageValue();
    assertEquals(3, s.value("innerint").get());
}
Also used : Operand(com.dexels.navajo.document.Operand) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Test(org.junit.Test)

Example 78 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class ExpressionTest method testTrailingTMLPathParam.

@Test
public void testTrailingTMLPathParam() throws Exception {
    Expression.compileExpressions = true;
    ImmutableMessage outer = ImmutableFactory.empty().with("outerint", 1, "integer");
    ImmutableMessage inner = ImmutableFactory.empty().with("innerint", 3, "integer");
    ImmutableMessage combined = outer.withSubMessage("sub", inner);
    Operand o = Expression.evaluateImmutable("[@sub/]", null, Optional.empty(), Optional.of(combined));
    ImmutableMessage s = o.immutableMessageValue();
    assertEquals(3, s.value("innerint").get());
}
Also used : Operand(com.dexels.navajo.document.Operand) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Test(org.junit.Test)

Example 79 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class TestCompiledExpression method testIntegerDoubleComparison.

@Test
public void testIntegerDoubleComparison() {
    Operand result;
    result = Expression.evaluate(" 1 < 1.1 ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" 1 < 1.0 ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" 1 <= 1.1 ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" 1 <= 1.0 ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" 1 > 1.1 ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" 1 > 1.0 ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" 1 >= 1.1 ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" 1 >= 1.0 ", null, null, null);
    Assert.assertTrue((boolean) result.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 80 with Operand

use of com.dexels.navajo.document.Operand 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)

Aggregations

Operand (com.dexels.navajo.document.Operand)95 Test (org.junit.Test)57 Message (com.dexels.navajo.document.Message)22 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)20 Navajo (com.dexels.navajo.document.Navajo)20 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)14 ArrayList (java.util.ArrayList)12 Selection (com.dexels.navajo.document.Selection)11 Property (com.dexels.navajo.document.Property)10 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)10 Access (com.dexels.navajo.script.api.Access)10 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)10 NavajoException (com.dexels.navajo.document.NavajoException)9 TipiLink (com.dexels.navajo.expression.api.TipiLink)9 Optional (java.util.Optional)9 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)8 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)6 SystemException (com.dexels.navajo.script.api.SystemException)6 List (java.util.List)6