Search in sources :

Example 6 with NumberToken

use of com.googlecode.aviator.lexer.token.NumberToken in project aviatorscript by killme2008.

the class ASMCodeGeneratorUnitTest method testOnConstant_Long.

@Test
public void testOnConstant_Long() throws Exception {
    this.codeGenerator.onConstant(new NumberToken(3L, "3"));
    Expression exp = this.codeGenerator.getResult(true);
    Object result = exp.execute();
    assertEquals(3L, result);
}
Also used : Expression(com.googlecode.aviator.Expression) NumberToken(com.googlecode.aviator.lexer.token.NumberToken) Test(org.junit.Test)

Example 7 with NumberToken

use of com.googlecode.aviator.lexer.token.NumberToken in project aviatorscript by killme2008.

the class ASMCodeGeneratorUnitTest method testOnMethod_withTwoArguments.

@Test
public void testOnMethod_withTwoArguments() throws Exception {
    this.codeGenerator.onMethodName(new Variable("string.substring", 0, -1));
    this.codeGenerator.onConstant(new StringToken("hello", 0, -1));
    this.codeGenerator.onMethodParameter(null);
    this.codeGenerator.onConstant(new NumberToken(2L, "2"));
    this.codeGenerator.onMethodParameter(null);
    this.codeGenerator.onConstant(new NumberToken(5L, "5"));
    this.codeGenerator.onMethodParameter(null);
    this.codeGenerator.onMethodInvoke(null);
    Object result = eval(new HashMap<String, Object>());
    assertEquals("llo", result);
}
Also used : Variable(com.googlecode.aviator.lexer.token.Variable) NumberToken(com.googlecode.aviator.lexer.token.NumberToken) StringToken(com.googlecode.aviator.lexer.token.StringToken) Test(org.junit.Test)

Example 8 with NumberToken

use of com.googlecode.aviator.lexer.token.NumberToken in project aviatorscript by killme2008.

the class ASMCodeGeneratorUnitTest method testOnNeg_Double.

@Test
public void testOnNeg_Double() throws Exception {
    this.codeGenerator.onConstant(new NumberToken(-3.3d, "-3.3"));
    this.codeGenerator.onNeg(null);
    Object result = eval(new HashMap<String, Object>());
    assertEquals(3.3, result);
}
Also used : NumberToken(com.googlecode.aviator.lexer.token.NumberToken) Test(org.junit.Test)

Example 9 with NumberToken

use of com.googlecode.aviator.lexer.token.NumberToken in project aviatorscript by killme2008.

the class ASMCodeGeneratorUnitTest method testOnNeg_Long.

@Test
public void testOnNeg_Long() throws Exception {
    this.codeGenerator.onConstant(new NumberToken(3L, "3"));
    this.codeGenerator.onNeg(null);
    Object result = eval(new HashMap<String, Object>());
    assertEquals(-3L, result);
}
Also used : NumberToken(com.googlecode.aviator.lexer.token.NumberToken) Test(org.junit.Test)

Example 10 with NumberToken

use of com.googlecode.aviator.lexer.token.NumberToken in project aviatorscript by killme2008.

the class ASMCodeGeneratorUnitTest method doBitOpTests.

public void doBitOpTests(final OperatorType operatorType) throws Exception {
    NumberToken a = new NumberToken(99L, "3");
    NumberToken b = new NumberToken(2, "2");
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("c", 9L);
    this.codeGenerator.onConstant(new Variable("c", 0, 7));
    this.codeGenerator.onConstant(a);
    this.codeGenerator.onConstant(b);
    switch(operatorType) {
        case BIT_OR:
            this.codeGenerator.onBitOr(null);
            this.codeGenerator.onBitOr(null);
            Object result = eval(env);
            assertEquals(7 | 3 | 2, result);
            break;
        case BIT_AND:
            this.codeGenerator.onBitAnd(null);
            this.codeGenerator.onBitAnd(null);
            result = eval(env);
            assertEquals(7 & 3 & 2, result);
            break;
        case BIT_XOR:
            this.codeGenerator.onBitXor(null);
            this.codeGenerator.onBitXor(null);
            result = eval(env);
            assertEquals(7 ^ 3 ^ 2, result);
            break;
        case SHIFT_LEFT:
            this.codeGenerator.onShiftLeft(null);
            this.codeGenerator.onShiftLeft(null);
            result = eval(env);
            assertEquals(7 << 3 << 2, result);
            break;
        case SHIFT_RIGHT:
            this.codeGenerator.onShiftRight(null);
            this.codeGenerator.onShiftRight(null);
            result = eval(env);
            assertEquals(7 >> 3 >> 2, result);
            break;
        case U_SHIFT_RIGHT:
            this.codeGenerator.onUnsignedShiftRight(null);
            this.codeGenerator.onUnsignedShiftRight(null);
            result = eval(env);
            assertEquals(7 >>> 3 >>> 2, result);
            break;
    }
}
Also used : Variable(com.googlecode.aviator.lexer.token.Variable) HashMap(java.util.HashMap) NumberToken(com.googlecode.aviator.lexer.token.NumberToken)

Aggregations

NumberToken (com.googlecode.aviator.lexer.token.NumberToken)15 Test (org.junit.Test)7 Variable (com.googlecode.aviator.lexer.token.Variable)6 StringToken (com.googlecode.aviator.lexer.token.StringToken)3 AviatorObject (com.googlecode.aviator.runtime.type.AviatorObject)3 AviatorPattern (com.googlecode.aviator.runtime.type.AviatorPattern)3 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)3 HashMap (java.util.HashMap)3 Expression (com.googlecode.aviator.Expression)2 CompileExpressionErrorException (com.googlecode.aviator.exception.CompileExpressionErrorException)2 AviatorNumber (com.googlecode.aviator.runtime.type.AviatorNumber)2 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)1 ExpressionSyntaxErrorException (com.googlecode.aviator.exception.ExpressionSyntaxErrorException)1 CharToken (com.googlecode.aviator.lexer.token.CharToken)1 PatternToken (com.googlecode.aviator.lexer.token.PatternToken)1 AviatorBoolean (com.googlecode.aviator.runtime.type.AviatorBoolean)1 AviatorJavaType (com.googlecode.aviator.runtime.type.AviatorJavaType)1 AviatorRuntimeJavaType (com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1