use of org.mvel2.tests.core.res.Foo 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.Foo in project mvel by mikebrock.
the class AbstractTest method createTestMap.
protected static Map createTestMap() {
Map map = new HashMap();
map.put("foo", new Foo());
map.put("a", null);
map.put("b", null);
map.put("c", "cat");
map.put("BWAH", "");
map.put("misc", new MiscTestClass());
map.put("pi", "3.14");
map.put("hour", 60);
map.put("zero", 0);
map.put("array", new String[] { "", "blip" });
map.put("order", new Order());
map.put("$id", 20);
map.put("five", 5);
map.put("testImpl", new TestInterface() {
public String getName() {
return "FOOBAR!";
}
public boolean isFoo() {
return true;
}
});
map.put("derived", new DerivedClass());
map.put("ipaddr", "10.1.1.2");
map.put("dt1", new Date(currentTimeMillis() - 100000));
map.put("dt2", new Date(currentTimeMillis()));
return map;
}
use of org.mvel2.tests.core.res.Foo 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.Foo 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.Foo in project mvel by mikebrock.
the class ComparisonTests method testIsDefOperator6.
public void testIsDefOperator6() {
Foo foo = new Foo();
assertEquals(true, MVEL.eval("isdef name", foo));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("isdef name"), foo));
}
Aggregations