use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testJIRA168.
public void testJIRA168() {
boolean before = MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL;
try {
Map<String, Object> st = new HashMap<String, Object>();
st.put("__fact__", new ArrayList());
st.put("__expected__", 0);
String expressionNaked = "__fact__.size == __expected__";
String expressionNonNaked = "__fact__.size() == __expected__";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
// the following works fine
ParserContext ctx = new ParserContext();
for (Map.Entry<String, Object> entry : st.entrySet()) {
ctx.addInput(entry.getKey(), entry.getValue().getClass());
}
CompiledExpression expr = new ExpressionCompiler(expressionNaked, ctx).compile();
Boolean result = (Boolean) executeExpression(expr, st);
assertTrue(result);
// the following works fine
result = (Boolean) MVEL.eval(expressionNonNaked, st);
assertTrue(result);
// the following fails
result = (Boolean) MVEL.eval(expressionNaked, st);
assertTrue(result);
} finally {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = before;
}
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testStrictTypingCompilation.
public void testStrictTypingCompilation() {
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("a.foo;\nb.foo;\n x = 5", ctx);
try {
compiler.compile();
} catch (CompileException e) {
e.printStackTrace();
return;
}
assertTrue(false);
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testNestedClassWithNestedGenericsOnNakedMethod.
public void testNestedClassWithNestedGenericsOnNakedMethod() {
String str = "deliveries.size";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Triangle.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertEquals(Integer.valueOf(0), (Integer) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
str = "deliveries.size == 0";
stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertTrue((Boolean) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testInstanceofWithPackageImport.
public void testInstanceofWithPackageImport() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("org.mvel2.tests.core");
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", Object.class);
Map vars = new HashMap() {
{
put("value", new CoreConfidenceTests());
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof CoreConfidenceTests", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + CoreConfidenceTests.class.getCanonicalName(), pctx), vars));
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImportsWithNullConstructorParamWithStrongType.
public void testDynamicImportsWithNullConstructorParamWithStrongType() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", null)", ctx);
Cheesery p1 = new Cheesery("bobbo", null);
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
Aggregations