use of org.mvel2.integration.impl.IndexedVariableResolverFactory in project mvel by mvel.
the class CoreConfidenceTests method testNullCollection.
public void testNullCollection() throws CompileException {
boolean allowCompilerOverride = MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING;
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
String[] names = { "missing" };
String[] values = { null };
try {
MVEL.executeExpression((CompiledExpression) MVEL.compileExpression("1; missing[3]"), new IndexedVariableResolverFactory(names, values));
fail("Should throw a NullPointerExcption");
} catch (Exception e) {
} finally {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = allowCompilerOverride;
}
}
use of org.mvel2.integration.impl.IndexedVariableResolverFactory in project mvel by mvel.
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.integration.impl.IndexedVariableResolverFactory 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()));
}
Aggregations