use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testUnaryNegative.
public void testUnaryNegative() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", int.class);
Map vars = new HashMap() {
{
put("value", 42);
}
};
assertEquals(-42, MVEL.executeExpression(MVEL.compileExpression("-value", pctx), vars));
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessWithNestedProperty.
public void testMapAccessWithNestedProperty() {
String str = "map[key] == \"one\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", POJO.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
POJO ctx = new POJO();
ctx.getMap().put("1", "one");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testJIRA155.
public void testJIRA155() {
ParserContext pctx = new ParserContext();
pctx.addImport("returnTrue", MVEL.getStaticMethod(CoreConfidenceTests.class, "returnTrue", new Class[0]));
assertEquals(true, executeExpression(MVEL.compileExpression("!true || returnTrue()", pctx)));
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testComaProblemStrikesBack.
public void testComaProblemStrikesBack() {
String ex = "a.explanation = \"There is a coma, in here\"";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
Serializable s = compiler.compile();
Base a = new Base();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("a", a);
executeExpression(s, variables);
assertEquals("There is a coma, in here", a.data);
}
use of org.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testArray.
public void testArray() {
String ex = " TestHelper.method(1, new String[]{\"a\", \"b\"});\n" + " TestHelper.method(2, new String[]{new String(\"a\"), new String(\"b\")});\n" + " TestHelper.method(3, new Fooz[]{new Fooz(\"a\"), new Fooz(\"b\")});";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport(TestHelper.class);
ctx.addImport(Fooz.class);
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
OptimizerFactory.setDefaultOptimizer("ASM");
CompiledExpression expr = compiler.compile();
executeExpression(expr);
OptimizerFactory.setDefaultOptimizer("reflective");
expr = compiler.compile();
executeExpression(expr);
}
Aggregations