Search in sources :

Example 21 with AviatorString

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

the class StringSubStringFunction method call.

@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
    String target = FunctionUtils.getStringValue(arg1, env);
    Number beginIndex = FunctionUtils.getNumberValue(arg2, env);
    return new AviatorString(target.substring(beginIndex.intValue()));
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorString(com.googlecode.aviator.runtime.type.AviatorString)

Example 22 with AviatorString

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

the class AviatorEvaluatorInstanceUnitTest method testFunctionMissing.

@Test
public void testFunctionMissing() {
    this.instance.setFunctionMissing(new FunctionMissing() {

        @Override
        public AviatorObject onFunctionMissing(final String name, final Map<String, Object> env, final AviatorObject... args) {
            // Returns the missing function name.
            return new AviatorString(name);
        }
    });
    assertEquals("test", this.instance.execute("test()"));
    assertEquals("abc", this.instance.execute("abc(1,2)"));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Example 23 with AviatorString

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

the class SeqFilterFunctionUnitTest method testFilter_String.

@Test
public void testFilter_String() {
    SeqFilterFunction fun = new SeqFilterFunction();
    SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("l"));
    Map<String, Object> env = new HashMap<String, Object>();
    env.putAll(AviatorEvaluator.FUNC_MAP);
    env.put("eq_temp_1", predicate);
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf("hello"), new AviatorJavaType("eq_temp_1"));
    List list = (List) result.getValue(null);
    assertEquals(2, list.size());
    for (Object i : list) {
        assertEquals("l", i);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) List(java.util.List) LinkedList(java.util.LinkedList) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Example 24 with AviatorString

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

the class SeqFilterFunctionUnitTest method testFilter_Collection.

@Test
public void testFilter_Collection() {
    final List<String> strs = new LinkedList<String>();
    for (int i = 0; i < 10; i++) {
        strs.add("hello" + i);
    }
    SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("hello1"));
    Map<String, Object> env = new HashMap<String, Object>();
    env.putAll(AviatorEvaluator.FUNC_MAP);
    env.put("eq_temp_1", predicate);
    SeqFilterFunction fun = new SeqFilterFunction();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(strs), new AviatorJavaType("eq_temp_1"));
    LinkedList list = (LinkedList) result.getValue(null);
    assertEquals(1, list.size());
    for (Object i : list) {
        assertEquals("hello1", i);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with AviatorString

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

the class SeqFilterFunctionUnitTest method testFilter_Array.

@Test
public void testFilter_Array() {
    final String[] strs = new String[10];
    for (int i = 0; i < strs.length; i++) {
        strs[i] = "hello" + i;
    }
    SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("hello1"));
    Map<String, Object> env = new HashMap<String, Object>();
    env.putAll(AviatorEvaluator.FUNC_MAP);
    env.put("eq_temp_1", predicate);
    SeqFilterFunction fun = new SeqFilterFunction();
    AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(strs), new AviatorJavaType("eq_temp_1"));
    Object[] array = (Object[]) result.getValue(null);
    assertEquals(1, array.length);
    for (Object i : array) {
        assertEquals("hello1", i);
    }
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) AviatorJavaType(com.googlecode.aviator.runtime.type.AviatorJavaType) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Test(org.junit.Test)

Aggregations

AviatorString (com.googlecode.aviator.runtime.type.AviatorString)33 Test (org.junit.Test)19 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)14 HashMap (java.util.HashMap)11 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AbstractFunction (com.googlecode.aviator.runtime.function.AbstractFunction)3 Date (java.util.Date)3 List (java.util.List)3 Map (java.util.Map)3 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)2 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)2 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)2 PrintStream (java.io.PrintStream)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 ID (cn.devezhao.persist4j.engine.ID)1 AviatorEvaluator (com.googlecode.aviator.AviatorEvaluator)1 AviatorNil (com.googlecode.aviator.runtime.type.AviatorNil)1 AviatorNumber (com.googlecode.aviator.runtime.type.AviatorNumber)1