Search in sources :

Example 76 with AviatorObject

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

the class SeqMapFunctionUnitTest method testCount_Collection.

@Test
public void testCount_Collection() {
    final List<String> strs = new LinkedList<String>();
    for (int i = 0; i < 10; i++) {
        strs.add("hello");
    }
    SeqMapFunction fun = new SeqMapFunction();
    Env env = TestUtils.getTestEnv();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(strs), new AviatorJavaType("string.length"));
    LinkedList array = (LinkedList) result.getValue(env);
    for (Object i : array) {
        assertEquals(5, i);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Env(com.googlecode.aviator.utils.Env) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 77 with AviatorObject

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

the class SeqMapFunctionUnitTest method testMap_String.

@Test
public void testMap_String() {
    Env env = TestUtils.getTestEnv();
    SeqMapFunction fun = new SeqMapFunction();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf("hello"), new AviatorJavaType("string.length"));
    List list = (List) result.getValue(null);
    assertEquals(5, list.size());
    for (Object val : list) {
        assertEquals(val, 1);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) List(java.util.List) LinkedList(java.util.LinkedList) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Env(com.googlecode.aviator.utils.Env) Test(org.junit.Test)

Example 78 with AviatorObject

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

the class SeqMapFunctionUnitTest method testMap_Map.

@Test
public void testMap_Map() {
    final Map<String, String> m = new HashMap<String, String>();
    m.put("a", "1");
    m.put("b", "2");
    SeqMapFunction fun = new SeqMapFunction();
    AviatorObject result = fun.call(AviatorEvaluator.FUNC_MAP, AviatorRuntimeJavaType.valueOf(m), (AviatorObject) AviatorEvaluator.execute("lambda(x) -> x.value end"));
    List<Object> results = (List<Object>) result.getValue(null);
    assertEquals(2, results.size());
    assertTrue(results.contains("1"));
    assertTrue(results.contains("2"));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 79 with AviatorObject

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

the class SeqPredicateFunctionUnitTest method testPredicate_le.

@Test
public void testPredicate_le() {
    SeqPredicateFunction fun = new SeqPredicateFunction("le", OperatorType.LE, AviatorRuntimeJavaType.valueOf("hello"));
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"));
    assertTrue(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("ae1lo"));
    assertTrue(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("ie1lo"));
    assertFalse(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 80 with AviatorObject

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

the class SeqPredicateFunctionUnitTest method testPredicate_ge.

@Test
public void testPredicate_ge() {
    SeqPredicateFunction fun = new SeqPredicateFunction("ge", OperatorType.GE, AviatorRuntimeJavaType.valueOf("hello"));
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"));
    assertTrue(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("iello"));
    assertTrue(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("aello"));
    assertFalse(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

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