Search in sources :

Example 41 with AviatorObject

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

the class SeqIncludeFunctionUnitTest method testInclude_Array.

@Test
public void testInclude_Array() {
    Integer[] a = new Integer[3];
    a[0] = 1;
    a[1] = -100;
    SeqIncludeFunction fun = new SeqIncludeFunction();
    final AviatorObject arg1 = AviatorRuntimeJavaType.valueOf(a);
    AviatorObject result = fun.call(null, arg1, AviatorRuntimeJavaType.valueOf(-100));
    assertTrue(result.booleanValue(null));
    // contains null Object
    result = fun.call(null, arg1, AviatorNil.NIL);
    assertTrue(result.booleanValue(null));
    // not match
    result = fun.call(null, arg1, AviatorRuntimeJavaType.valueOf(1000));
    assertFalse(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 42 with AviatorObject

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

the class SeqMakePredicateFunctionUnitTest method testMakePredicate.

@Test
public void testMakePredicate() {
    SeqMakePredicateFunFunction fun = new SeqMakePredicateFunFunction("eq", OperatorType.EQ);
    Map<String, Object> env = new HashMap<String, Object>();
    AviatorObject predicateName = fun.call(env, AviatorRuntimeJavaType.valueOf("hello"));
    assertNotNull(predicateName);
    AviatorFunction predicate = (AviatorFunction) predicateName.getValue(env);
    assertNotNull(predicate);
    AviatorObject result = predicate.call(null, AviatorRuntimeJavaType.valueOf("hello"));
    // equals self
    assertTrue(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) HashMap(java.util.HashMap) AviatorFunction(com.googlecode.aviator.runtime.type.AviatorFunction) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 43 with AviatorObject

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

the class SeqPredicateFunctionUnitTest method testPredicate_gt.

@Test
public void testPredicate_gt() {
    SeqPredicateFunction fun = new SeqPredicateFunction("gt", OperatorType.GT, AviatorRuntimeJavaType.valueOf("hello"));
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"));
    assertFalse(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("iello"));
    assertTrue(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 44 with AviatorObject

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

the class SeqPredicateFunctionUnitTest method testPredicate_lt.

@Test
public void testPredicate_lt() {
    SeqPredicateFunction fun = new SeqPredicateFunction("lt", OperatorType.LT, AviatorRuntimeJavaType.valueOf("hello"));
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"));
    assertFalse(result.booleanValue(null));
    result = fun.call(null, AviatorRuntimeJavaType.valueOf("ae1lo"));
    assertTrue(result.booleanValue(null));
}
Also used : AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject) Test(org.junit.Test)

Example 45 with AviatorObject

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

the class SeqPredicateFunctionUnitTest method testPredicate_IllegalArguments.

@Test(expected = IllegalArgumentException.class)
public void testPredicate_IllegalArguments() {
    SeqPredicateFunction fun = new SeqPredicateFunction("le", OperatorType.LE, AviatorRuntimeJavaType.valueOf("hello"));
    AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf("hello"), null);
}
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