Search in sources :

Example 91 with Operand

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

the class ToMoney method main.

public static void main(String[] args) throws Exception {
    java.util.Locale.setDefault(new java.util.Locale("nl", "NL"));
    // Tests.
    ToMoney tm = new ToMoney();
    tm.reset();
    tm.insertFloatOperand(Double.valueOf(1024.4990));
    System.out.println("result = " + ((Money) tm.evaluate()).formattedString());
    // Using expressions.
    String expression = "ToMoney(1024.50) + 500 - 5.7 + ToMoney(1)/2";
    Operand o = Expression.evaluate(expression, null);
    System.out.println("o = " + o.value);
    System.out.println("type = " + o.type);
    System.err.println("ToMoney('') = " + Expression.evaluate("ToMoney('')", null).value);
}
Also used : Money(com.dexels.navajo.document.types.Money) Operand(com.dexels.navajo.document.Operand)

Example 92 with Operand

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

the class TestCompiledExpression method testFunctionEvaluation.

@Test
public void testFunctionEvaluation() {
    List<String> problems = new ArrayList<>();
    ExpressionCache ce = ExpressionCache.getInstance();
    String embeddedExpression = "StringFunction('matches','aaa', '.*[-]+7[0-9][A-z]*$' ))";
    ContextExpression cemb = ce.parse(problems, embeddedExpression, name -> FunctionClassification.DEFAULT);
    System.err.println("Problems: " + problems);
    Assert.assertEquals(0, problems.size());
    Operand result = cemb.apply(input, Optional.empty(), Optional.empty());
    System.err.println("Result: " + result.type + " value: " + result.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) ExpressionCache(com.dexels.navajo.parser.compiled.api.ExpressionCache) Test(org.junit.Test)

Example 93 with Operand

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

the class Switch method testUnicodeExpressionFunction.

@Test
public void testUnicodeExpressionFunction() throws Exception {
    Operand result = Expression.evaluate("Unicode('0x20AC')", null, null, null);
    System.err.println("Result:" + result.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) Test(org.junit.Test)

Example 94 with Operand

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

the class StandardFunctionsTest method testCheckUniquenessExtended.

@Test
public void testCheckUniquenessExtended() throws SystemException {
    String expression = "Hallo \n Hoe is het nou?";
    CreateExpression ce = new CreateExpression();
    ce.reset();
    ce.insertStringOperand(expression);
    String result = (String) ce.evaluate();
    System.err.println("result:");
    System.err.println(result);
    Operand o = Expression.evaluate(result, null);
    System.err.println("Evaluated to: ");
    System.err.println(o.value);
    assertEquals(2, ((String) o.value).split("\n").length);
}
Also used : Operand(com.dexels.navajo.document.Operand) CapString(com.dexels.navajo.functions.CapString) CreateExpression(com.dexels.navajo.functions.CreateExpression) Test(org.junit.Test)

Example 95 with Operand

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

the class TestCompiledExpression method testForall.

@Test
public void testForall() throws TMLExpressionException {
    List<String> problems = new ArrayList<>();
    ExpressionCache ce = ExpressionCache.getInstance();
    // String extBackup ="FORALL( '/TestArrayMessageMessage', `! ?[Delete] OR ! [Delete] OR [/__globals__/ApplicationInstance] != 'TENANT' OR ! StringFunction( 'matches', [ChargeCodeId], '.*[-]+7[0-9][A-z]*$' )` )";
    String ext = "FORALL( '/Msg', `!StringFunction( 'matches', [ChargeCodeId], '.*[-]+7[0-9][A-z]*$' )` )";
    // String expression = "FORALL( '/Charges' , `! ?[Delete] OR ! [Delete]  OR [/__globals__/ApplicationInstance] != 'SOMETENANT' OR [SomeProperty] == 'SOMESTRING' `)";
    // ce.parse(problems, expression, mode, allowLiteralResolve)
    ContextExpression cx = ce.parse(problems, ext, name -> FunctionClassification.DEFAULT);
    System.err.println("Problems: " + problems);
    Assert.assertEquals(0, problems.size());
    Operand result = cx.apply(input, Optional.empty(), Optional.empty());
    System.err.println("Result: " + result.type + " value: " + result.value);
// Operand result = Expression.evaluate(expression, testDoc,null,topMessage);
}
Also used : Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) ExpressionCache(com.dexels.navajo.parser.compiled.api.ExpressionCache) 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