use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ControlFlowTests method testForLoopWithVar.
public void testForLoopWithVar() {
String str = "int height = 100; int j = 0; for (i = 0; i < height; i++) {j++ }; return j;";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map vars = new HashMap();
assertEquals(new Integer(100), MVEL.executeExpression(stmt, vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testStrictModeAddAll.
public void testStrictModeAddAll() {
String str = "list.addAll( o );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("o", Object.class);
pctx.addInput("list", ArrayList.class);
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
fail("This should not compileShared, as o is not of a type Collection");
} catch (Exception e) {
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMultiplyIntByDouble.
public void testMultiplyIntByDouble() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("i", Integer.class);
pctx.addInput("d", Double.class);
Map vars = new HashMap() {
{
put("i", 10);
put("d", 0.3);
}
};
assertEquals(3.0, MVEL.executeExpression(MVEL.compileExpression("i*d", pctx), vars));
assertEquals(3.0, MVEL.executeExpression(MVEL.compileExpression("i*0.3", pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testCharToStringCoercionForComparison.
public void testCharToStringCoercionForComparison() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("ch", Character.class);
Map vars = new HashMap() {
{
put("ch", 'a');
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("ch == \"a\"", pctx), vars));
assertEquals(false, MVEL.executeExpression(MVEL.compileExpression("ch == \"b\"", pctx), vars));
// assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("\"a\" == ch", pctx), vars));
// assertEquals(false, MVEL.executeExpression(MVEL.compileExpression("\"b\" == ch", pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMethodScoring.
public void testMethodScoring() {
OptimizerFactory.setDefaultOptimizer("ASM");
ParserConfiguration pconf = new ParserConfiguration();
for (Method m : StaticMethods.class.getMethods()) {
if (Modifier.isStatic(m.getModifiers())) {
pconf.addImport(m.getName(), m);
}
}
pconf.addImport("TestCase", TestCase.class);
ParserContext pctx = new ParserContext(pconf);
Map<String, Object> vars = new HashMap<String, Object>();
// this is successful
TestCase.assertTrue(StaticMethods.is(StaticMethods.getList(java.util.Formatter.class)));
// this also should be fine
Serializable expr = MVEL.compileExpression("TestCase.assertTrue( is( getList( java.util.Formatter ) ) )", pctx);
executeExpression(expr, vars);
}
Aggregations