use of com.googlecode.aviator.parser.Parser in project aviatorscript by killme2008.
the class ASMCodeGeneratorUnitTest method testOnLambdaDefine.
@Test
public void testOnLambdaDefine() throws Exception {
this.codeGenerator.setParser(new Parser() {
@Override
public void setCodeGenerator(final CodeGenerator codeGenerator) {
}
@Override
public void restoreScope(final ScopeInfo info) {
}
@Override
public SymbolTable getSymbolTable() {
return null;
}
@Override
public CodeGenerator getCodeGenerator() {
return ASMCodeGeneratorUnitTest.this.codeGenerator;
}
@Override
public ScopeInfo enterScope(final boolean inForLoop) {
return null;
}
});
assertNull(this.codeGenerator.getLambdaGenerator());
this.codeGenerator.onLambdaDefineStart(new Variable("lambda", 0, 0));
LambdaGenerator lambdaGenerator = this.codeGenerator.getLambdaGenerator();
assertNotNull(lambdaGenerator);
this.codeGenerator.onLambdaArgument(new Variable("x", 0, 1), new FunctionParam(0, "x", false));
this.codeGenerator.onLambdaArgument(new Variable("y", 0, 2), new FunctionParam(1, "y", false));
this.codeGenerator.onLambdaBodyStart(new Variable(">", 0, 3));
lambdaGenerator.onConstant(new Variable("x", 0, 4));
lambdaGenerator.onConstant(new Variable("y", 0, 5));
lambdaGenerator.onAdd(null);
this.codeGenerator.onLambdaBodyEnd(new Variable("end", 0, 7));
HashMap<String, Object> env = new HashMap<String, Object>();
env.put("x", 2);
env.put("y", 3);
Object result = eval(env);
assertTrue(result instanceof LambdaFunction);
assertEquals(5, ((LambdaFunction) result).call(env, new AviatorJavaType("x"), new AviatorJavaType("y")).getValue(env));
assertNull(this.codeGenerator.getLambdaGenerator());
}
Aggregations