Search in sources :

Example 31 with AviatorObject

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

the class StringJoinFunction method join.

private AviatorObject join(final Map<String, Object> env, final AviatorObject arg1, final Object target, final String split) {
    Class<?> clazz = target.getClass();
    StringBuilder sb = new StringBuilder(50);
    if (Collection.class.isAssignableFrom(clazz)) {
        boolean wasFirst = true;
        for (Object obj : (Collection<?>) target) {
            wasFirst = append(sb, split, wasFirst, obj);
        }
    } else if (clazz.isArray()) {
        int length = ArrayUtils.getLength(target);
        boolean wasFirst = true;
        for (int i = 0; i < length; i++) {
            Object obj = ArrayUtils.get(target, i);
            wasFirst = append(sb, split, wasFirst, obj);
        }
    } else {
        throw new IllegalArgumentException(arg1.desc(env) + " is not a seq");
    }
    return new AviatorString(sb.toString());
}
Also used : AviatorString(com.googlecode.aviator.runtime.type.AviatorString) Collection(java.util.Collection) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Example 32 with AviatorObject

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

the class RandomFunctionUnitTest method testCallWithOneArg.

public void testCallWithOneArg() {
    RandomFunction rand = new RandomFunction();
    AviatorObject result = rand.call(null, AviatorRuntimeJavaType.valueOf(1));
    assertTrue(((Integer) result.getValue(null)) < 1);
    assertTrue(((Integer) result.getValue(null)) >= 0);
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Example 33 with AviatorObject

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

the class RandomFunctionUnitTest method testCallIllegalArgument.

@Test(expected = IllegalArgumentException.class)
public void testCallIllegalArgument() {
    RandomFunction rand = new RandomFunction();
    AviatorObject result = rand.call(null, AviatorRuntimeJavaType.valueOf(1), AviatorRuntimeJavaType.valueOf(2));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 34 with AviatorObject

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

the class BinaryFunctionUnitTest method testModFunction.

@Test
public void testModFunction() {
    BinaryFunction fun = new BinaryFunction(OperatorType.MOD);
    AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
    assertEquals(10L, (Long) result.getValue(null), 0L);
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 35 with AviatorObject

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

the class BinaryFunctionUnitTest method testAddFunction.

@Test
public void testAddFunction() {
    BinaryFunction fun = new BinaryFunction(OperatorType.ADD);
    AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
    assertEquals(21L, (Long) result.getValue(null), 0L);
}
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