use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class ControlFlowTests method testQualifiedForLoop.
public void testQualifiedForLoop() {
ParserContext pCtx = new ParserContext();
pCtx.setStrongTyping(true);
pCtx.addImport(Foo.class);
pCtx.addInput("l", ArrayList.class, new Class[] { Foo.class });
List l = new ArrayList();
l.add(new Foo());
l.add(new Foo());
l.add(new Foo());
Map vars = new HashMap();
vars.put("l", l);
Serializable s = MVEL.compileExpression("String s = ''; for (Foo f : l) { s += f.name }; s", pCtx);
String r = (String) MVEL.executeExpression(s, vars);
assertEquals("dogdogdog", r);
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class CoreConfidenceTests method testJIRA156c.
public void testJIRA156c() throws Throwable {
ClassProvider provider = new ClassProvider();
provider.getPublic().foo();
PublicClass.class.getMethod("foo").invoke(provider.getPublic());
String script = "provider.getPublic().foo()";
Serializable s = MVEL.compileExpression(script);
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("provider", provider);
MVEL.eval(script, vars);
OptimizerFactory.setDefaultOptimizer("reflective");
executeExpression(s, vars);
OptimizerFactory.setDefaultOptimizer("ASM");
executeExpression(s, vars);
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class IndexedVariablesTests method testVariableInjection2.
public void testVariableInjection2() {
String[] varNames = { "x", "y", "z" };
Object[] values = { 10, 20, 30 };
String expr = "foo = -1; res = x + y + z;\n" + "if (x > 9) {\n" + " res = z - y - x;\n" + " int k = 5;\n" + " foo = k;" + "}; \n" + "for (i = 0; i < 100000; i++) { foo++; }; foo;";
ParserContext ctx = ParserContext.create();
ctx.addIndexedInput(varNames);
ctx.setIndexAllocation(true);
SimpleVariableSpaceModel model = VariableSpaceCompiler.compile(expr, ctx);
Serializable indexCompile = MVEL.compileExpression(expr, ctx);
Serializable dynamicCompile = MVEL.compileExpression(expr, ParserContext.create());
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", 10);
map.put("y", 20);
map.put("z", 30);
assertEquals(MVEL.executeExpression(dynamicCompile, map), MVEL.executeExpression(indexCompile, model.createFactory(values)));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class CoreConfidenceTests method testSetAccessorOverloadedEqualsStrictMode.
public void testSetAccessorOverloadedEqualsStrictMode() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
try {
CompiledExpression expr = new ExpressionCompiler("foo.bar = 0").compile(ctx);
} catch (CompileException e) {
// should fail.
e.printStackTrace();
return;
}
assertTrue(false);
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class DebuggerTests method testBreakpoints5.
public void testBreakpoints5() {
OptimizerFactory.setDefaultOptimizer("ASM");
String expression = "System.out.println('foo');\r\n" + "a = new Foo244();\r\n" + "a.name = 'bar';\r\n" + "foo.happy();\r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "System.out.println( 'name:' + a.name ); \r\n" + "return a.name;";
Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
Map<String, Macro> macros = new HashMap<String, Macro>();
expression = parseMacros(expression, macros);
ExpressionCompiler compiler = new ExpressionCompiler(expression);
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
ctx.addImport("Foo244", Foo.class);
ctx.setInterceptors(interceptors);
CompiledExpression compiled = compiler.compile(ctx);
System.out.println("\nExpression:------------");
System.out.println(expression);
System.out.println("------------");
System.out.println(DebugTools.decompile(compiled));
MVELRuntime.registerBreakpoint("test2.mv", 1);
final Set<Integer> breaked = new HashSet<Integer>();
Debugger testDebugger = new Debugger() {
public int onBreak(Frame frame) {
System.out.println("Breakpoint [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
breaked.add(frame.getLineNumber());
return Debugger.STEP_OVER;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
System.out.println("\n==RUN==\n");
assertEquals("bar", MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertTrue("did not break at line 1", breaked.contains(1));
}
Aggregations