use of com.googlecode.aviator.runtime.type.AviatorString 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.AviatorString 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.AviatorString in project aviatorscript by killme2008.
the class OperatorFunctionTest method testCustomBinOperatorFunction.
@Test
public void testCustomBinOperatorFunction() {
try {
assertEquals("hello world", this.instance.execute("'hello' & ' world'"));
fail();
} catch (Exception e) {
}
this.instance.addOpFunction(OperatorType.BIT_AND, new AbstractFunction() {
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
return new AviatorString(arg1.getValue(env).toString() + arg2.getValue(env).toString());
}
@Override
public String getName() {
return "&";
}
});
assertEquals("43", this.instance.exec("a&3", 4));
assertEquals("43", this.instance.exec("4&3", 4));
assertEquals("hello world", this.instance.execute("'hello' & ' world'"));
assertEquals("hello world", this.instance.exec("a&' world'", "hello"));
assertEquals("hello3 world", this.instance.exec("a & 3 & ' world'", "hello"));
Map<String, Object> env = new HashMap<>();
env.put("list", Arrays.asList(1, 2, 3));
assertEquals("123", this.instance.execute("reduce(list, &, '')", env));
}
Aggregations