use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqReduceFunctionUnitTest method testReduce_IllegalArguments.
@Test(expected = IllegalArgumentException.class)
public void testReduce_IllegalArguments() {
LinkedHashSet<Integer> a = new LinkedHashSet<Integer>();
for (int i = 0; i < 10; i++) {
a.add(i);
}
SeqReduceFunction fun = new SeqReduceFunction();
AviatorObject result = fun.call(this.env, AviatorRuntimeJavaType.valueOf(a), new AviatorJavaType("+"));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class StringIndexOfFunctionUnitTest method testCall.
@Test
public void testCall() {
Map<String, Object> env = new HashMap<String, Object>();
env.put("s1", "hello");
env.put("s2", "llo");
env.put("ch", 'l');
assertEquals(1L, this.function.call(null, new AviatorString("hello"), new AviatorString("ell")).getValue(null));
assertEquals(2L, this.function.call(env, new AviatorString("hello"), new AviatorJavaType("s2")).getValue(env));
assertEquals(2L, this.function.call(env, new AviatorString("hello"), new AviatorJavaType("ch")).getValue(env));
assertEquals(2L, this.function.call(env, new AviatorJavaType("s1"), new AviatorJavaType("s2")).getValue(env));
assertEquals(2L, this.function.call(env, new AviatorJavaType("s1"), new AviatorJavaType("ch")).getValue(env));
assertEquals(2L, this.function.call(env, new AviatorJavaType("s1"), new AviatorString("llo")).getValue(env));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class StringLengthFunctionUnitTest method testCall.
@Test
public void testCall() {
Map<String, Object> env = new HashMap<String, Object>();
env.put("s1", "hello");
env.put("s2", "hello world");
assertEquals(5, function.call(null, new AviatorString("hello")).getValue(null));
assertEquals(11, function.call(null, new AviatorString("hello world")).getValue(null));
assertEquals(5, function.call(env, new AviatorJavaType("s1")).getValue(null));
assertEquals(11, function.call(env, new AviatorJavaType("s2")).getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class MathCosFunctionUnitTest method testCall.
@Test
public void testCall() {
assertEquals(Math.cos(30), this.function.call(null, AviatorNumber.valueOf(30)).getValue(null));
assertEquals(Math.cos(1020.999), this.function.call(null, AviatorNumber.valueOf(1020.999)).getValue(null));
assertEquals(Math.cos(400), this.function.call(null, AviatorNumber.valueOf(400)).getValue(null));
Map<String, Object> env = new HashMap<String, Object>();
env.put("a", 10000);
env.put("b", 9.0);
assertEquals(Math.cos(10000), this.function.call(env, new AviatorJavaType("a")).getValue(null));
assertEquals(Math.cos(9.0), this.function.call(env, new AviatorJavaType("b")).getValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorJavaType in project aviatorscript by killme2008.
the class SeqArrayFunction method variadicCall.
@Override
public AviatorObject variadicCall(final Map<String, Object> env, final AviatorObject... args) {
if (args == null || args.length == 0) {
throw new IllegalArgumentException("Missing arguments for seq.array");
}
AviatorObject clazzVar = args[0];
if (clazzVar == null || clazzVar.getAviatorType() != AviatorType.JavaType) {
throw new IllegalArgumentException("Invalid class:" + (clazzVar == null ? "null" : clazzVar.desc(env)));
}
try {
String name = ((AviatorJavaType) clazzVar).getName();
Class<?> clazz = null;
if (TypeUtils.PRIMITIVE_TYPES.containsKey(name)) {
clazz = TypeUtils.PRIMITIVE_TYPES.get(name);
} else {
assert (env instanceof Env);
clazz = ((Env) env).resolveClassSymbol(name);
}
Object ret = Array.newInstance(clazz, args.length - 1);
for (int i = 1; i < args.length; i++) {
ArrayUtils.set(ret, i - 1, Reflector.boxArg(clazz, args[i].getValue(env)));
}
return AviatorRuntimeJavaType.valueOf(ret);
} catch (Throwable t) {
throw Reflector.sneakyThrow(t);
}
}
Aggregations