use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testAssertKeyword.
public void testAssertKeyword() {
ExpressionCompiler compiler = new ExpressionCompiler("assert 1 == 2;");
Serializable s = compiler.compile();
try {
executeExpression(s);
} catch (AssertionError e) {
return;
}
assertTrue(false);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testDynamicImports3.
public void testDynamicImports3() {
String expression = "import java.util.*; HashMap map = new HashMap(); map.size()";
ExpressionCompiler compiler = new ExpressionCompiler(expression);
Serializable s = compiler.compile();
assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory()));
assertEquals(0, MVEL.eval(expression, new HashMap()));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testStrictTypingCompilation.
public void testStrictTypingCompilation() {
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
ExpressionCompiler compiler = new ExpressionCompiler("a.foo;\nb.foo;\n x = 5");
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
try {
compiler.compile(ctx);
} catch (CompileException e) {
e.printStackTrace();
return;
}
assertTrue(false);
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class MacroProcessorTest method testMacroSupportWithDebugging.
public void testMacroSupportWithDebugging() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("foo", new Foo());
Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
Map<String, Macro> macros = new HashMap<String, Macro>();
interceptors.put("Modify", new Interceptor() {
public int doBefore(ASTNode node, VariableResolverFactory factory) {
((WithNode) node).getNestedStatement().getValue(null, factory);
factory.createVariable("mod", "FOOBAR!");
return 0;
}
public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) {
return 0;
}
});
macros.put("modify", new Macro() {
public String doMacro() {
return "@Modify with";
}
});
ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("System.out.println('hello');\n" + "System.out.println('bye');\n" + "modify (foo) { aValue = 'poo', \n" + " aValue = 'poo' };\n mod", macros));
// compiler.setDebugSymbols(true);
ParserContext ctx = new ParserContext(null, interceptors, null);
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
MVELRuntime.setThreadDebugger(new Debugger() {
public int onBreak(Frame frame) {
System.out.println(frame.getSourceName() + ":" + frame.getLineNumber());
return Debugger.STEP;
}
});
MVELRuntime.registerBreakpoint("test.mv", 3);
System.out.println(DebugTools.decompile(compiled));
Assert.assertEquals("FOOBAR!", MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(vars)));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testPropertyVerfierShoudldNotLoopIndefinately.
/**
* Provided by: Aadi Deshpande
*/
public void testPropertyVerfierShoudldNotLoopIndefinately() {
String expr = "\t\tmodel.latestHeadlines = $list;\n" + "model.latestHeadlines.add( 0, (model.latestHeadlines[2]) );";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
compiler.setVerifying(true);
ParserContext pCtx = new ParserContext();
pCtx.addInput("$list", List.class);
pCtx.addInput("model", Model.class);
compiler.compile(pCtx);
}
Aggregations