Search in sources :

Example 1 with ExpressionCache

use of com.dexels.navajo.parser.compiled.api.ExpressionCache 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 2 with ExpressionCache

use of com.dexels.navajo.parser.compiled.api.ExpressionCache 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)

Example 3 with ExpressionCache

use of com.dexels.navajo.parser.compiled.api.ExpressionCache in project navajo by Dexels.

the class TestTypeCheckCompiledExpressionEvaluator method testUnknown.

@Test
public void testUnknown() {
    // test unknowable type
    ExpressionCache ce = ExpressionCache.getInstance();
    List<String> problems = new ArrayList<>();
    ContextExpression cx = ce.parse(problems, "[bla]", fn -> FunctionClassification.DEFAULT);
    Assert.assertFalse(cx.returnType().isPresent());
}
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 4 with ExpressionCache

use of com.dexels.navajo.parser.compiled.api.ExpressionCache in project navajo by Dexels.

the class TestTypeCheckCompiledExpressionEvaluator method testBadType.

@Test
public void testBadType() {
    // test unknowable type
    ExpressionCache ce = ExpressionCache.getInstance();
    List<String> problems = new ArrayList<>();
    // the [] expression has been added to prevent the expression to be pre-evaluated (as all other params are literals
    ContextExpression cx = ce.parse(problems, "1 AND 'monkey' AND [whoop]", fn -> FunctionClassification.DEFAULT);
    System.err.println("Problems: " + problems);
    Assert.assertEquals(2, problems.size());
    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)

Example 5 with ExpressionCache

use of com.dexels.navajo.parser.compiled.api.ExpressionCache in project navajo by Dexels.

the class TestTypeCheckCompiledExpressionEvaluator method testBasicTypes.

@Test
public void testBasicTypes() {
    ExpressionCache ce = ExpressionCache.getInstance();
    List<String> problems = new ArrayList<>();
    ContextExpression cx = ce.parse(problems, "1", fn -> FunctionClassification.DEFAULT);
    Assert.assertEquals(Property.INTEGER_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)7 ExpressionCache (com.dexels.navajo.parser.compiled.api.ExpressionCache)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Operand (com.dexels.navajo.document.Operand)2