Search in sources :

Example 36 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class BinaryFunctionUnitTest method testNotFunction.

@Test
public void testNotFunction() {
    BinaryFunction fun = new BinaryFunction(OperatorType.NOT);
    AviatorObject result = fun.call(env, AviatorBoolean.FALSE);
    assertTrue((Boolean) result.getValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 37 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class BinaryFunctionUnitTest method testSubFunction.

@Test
public void testSubFunction() {
    BinaryFunction fun = new BinaryFunction(OperatorType.SUB);
    AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
    assertEquals(-1L, (Long) result.getValue(null), 0L);
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 38 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class BinaryFunctionUnitTest method testDivFunction.

@Test
public void testDivFunction() {
    BinaryFunction fun = new BinaryFunction(OperatorType.DIV);
    AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
    assertEquals(0, (Long) result.getValue(null), 0.00);
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 39 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class SeqFilterFunctionUnitTest method testFilter_map.

@Test
public void testFilter_map() {
    Map<Integer, String> data = new HashMap<>();
    for (int i = 0; i < 5; i++) {
        data.put(i, "a" + i);
    }
    Map<String, Object> env = new HashMap<>();
    SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("a1"), new AviatorString("value"));
    env.putAll(AviatorEvaluator.FUNC_MAP);
    env.put("eq_temp_1", predicate);
    SeqFilterFunction fun = new SeqFilterFunction();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(data), new AviatorJavaType("eq_temp_1"));
    Map map = ((Map) result.getValue(null));
    assertEquals(1, map.size());
    for (Object value : map.values()) {
        assertEquals("a1", value.toString());
    }
}
Also used : HashMap(java.util.HashMap) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 40 with AviatorObject

use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.

the class SeqIncludeFunctionUnitTest method testInclude_String.

public void testInclude_String() {
    SeqIncludeFunction fun = new SeqIncludeFunction();
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"), AviatorRuntimeJavaType.valueOf("h"));
    assertTrue(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Aggregations

AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)110 Test (org.junit.Test)51 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)25 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)22 AviatorFunction (com.googlecode.aviator.runtime.type.AviatorFunction)16 HashMap (java.util.HashMap)12 Map (java.util.Map)11 List (java.util.List)10 AbstractFunction (com.googlecode.aviator.runtime.function.AbstractFunction)9 FunctionNotFoundException (com.googlecode.aviator.exception.FunctionNotFoundException)7 Env (com.googlecode.aviator.utils.Env)6 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)5 LinkedList (java.util.LinkedList)5 Collection (java.util.Collection)4 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)3 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)3 AviatorRuntimeJavaType (com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType)3 Sequence (com.googlecode.aviator.runtime.type.Sequence)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3