Search in sources :

Example 36 with Operand

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

the class ExpressionTest method testExpressionWithImmutableParamMessage.

@Test
public void testExpressionWithImmutableParamMessage() throws Exception {
    Expression.compileExpressions = true;
    Operand o = Expression.evaluate("[@SomeInteger]", testDoc, (MappableTreeNode) null, topMessage, (Message) null, (Selection) null, (TipiLink) null, Collections.emptyMap(), Optional.of(immutableMessage), Optional.of(paramMessage));
    assertEquals(4, o.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 37 with Operand

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

the class ExpressionTest method testExpressionWithImmutableMessage.

@Test
public void testExpressionWithImmutableMessage() throws Exception {
    Expression.compileExpressions = true;
    Operand o = Expression.evaluate("[SomeInteger]", testDoc, (MappableTreeNode) null, topMessage, (Message) null, (Selection) null, (TipiLink) null, Collections.emptyMap(), Optional.of(immutableMessage), Optional.of(paramMessage));
    assertEquals(3, o.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 38 with Operand

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

the class ExpressionTest method testExpression.

@Test
public void testExpression() throws Exception {
    ExpressionEvaluator ee = NavajoFactory.getInstance().getExpressionEvaluator();
    Operand o = ee.evaluate("1+1", null, null, null);
    assertEquals(2, o.value);
    o = ee.evaluate("TODAY + 0#0#2#0#0#0", null, null, null);
    System.err.println(o.value);
    Navajo testDoc = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(m);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    m.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@MyProp=noot1/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap1", o.value);
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@2/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap2", o.value);
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) ExpressionEvaluator(com.dexels.navajo.document.ExpressionEvaluator) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 39 with Operand

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

the class ExpressionTest method testEmptyTML.

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

Example 40 with Operand

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

the class TestCompiledExpression method testDateComparison.

// Missing date comparison where the right hand operand is not a date
@Test
public void testDateComparison() {
    Operand result;
    result = Expression.evaluate(" TODAY < ( TODAY + 0#0#1#0#0#0 ) ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" TODAY < TODAY ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" TODAY <= ( TODAY + 0#0#1#0#0#0 ) ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" TODAY <= TODAY ", null, null, null);
    Assert.assertTrue((boolean) result.value);
    result = Expression.evaluate(" TODAY > ( TODAY + 0#0#1#0#0#0 ) ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" TODAY > TODAY ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" TODAY >= ( TODAY + 0#0#1#0#0#0 ) ", null, null, null);
    Assert.assertFalse((boolean) result.value);
    result = Expression.evaluate(" TODAY >= TODAY ", null, null, null);
    Assert.assertTrue((boolean) result.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) 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