use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class CoreConfidenceTests method testContextObjMethodCall.
public void testContextObjMethodCall() {
String str = "getName() == \"bob\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Bar ctx = new Bar();
ctx.setName("bob");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects.
// interpreted
public void testThisReferenceMapVirtualObjects() {
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
assertEquals(true, eval("this.foo == 'bar'", map, factory));
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects2.
// compiled - asm
public void testThisReferenceMapVirtualObjects2() {
// Create our root Map object
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
if (!Boolean.getBoolean("mvel2.disable.jit"))
OptimizerFactory.setDefaultOptimizer("ASM");
// Run test
assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class IntegrationTests method testIndexedVariableFactory.
public void testIndexedVariableFactory() {
ParserContext ctx = ParserContext.create();
String[] vars = { "a", "b" };
Object[] vals = { "foo", "bar" };
ctx.setIndexAllocation(true);
ctx.addIndexedInput(vars);
String expr = "def myfunc(z) { a + b + z }; myfunc('poop');";
SharedVariableSpaceModel model = VariableSpaceCompiler.compileShared(expr, ctx, vals);
Serializable s = MVEL.compileExpression(expr, ctx);
// VariableResolverFactory locals = new CachingMapVariableResolverFactory(new HashMap<String, Object>());
// VariableResolverFactory injected = new IndexedVariableResolverFactory(vars, vals, locals);
assertEquals("foobarpoop", MVEL.executeExpression(s, model.createFactory()));
}
use of org.mvel2.tests.core.res.Bar 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