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);
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations