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);
}
}
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);
}
}
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"));
}
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));
}
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));
}
Aggregations