use of org.mule.mvel2.ParserConfiguration in project mvel by mikebrock.
the class ArithmeticTests method testModExpr.
public void testModExpr() {
String str = "$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0 ";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("$y", int.class);
Map<String, Object> vars = new HashMap<String, Object>();
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
for (int i = 0; i < 500; i++) {
int y = i;
boolean expected = y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
vars.put("$y", y);
assertEquals(expected, MVEL.eval(str, vars));
assertEquals(expected, ((Boolean) MVEL.executeExpression(stmt, null, vars)).booleanValue());
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testArrays.
public void testArrays() {
String str = "Object[] a = new Object[3]; a[0] = \"a\"; a[1] = \"b\"; a[2] = \"c\"; System.out.println(java.util.Arrays.toString(a));";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new HashMap());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnaryNegativeWithSpace.
public void testUnaryNegativeWithSpace() {
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.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInvokeVarargConstructor.
public void testInvokeVarargConstructor() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(Thingy.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("name", String.class);
Map vars = new HashMap() {
{
put("name", "test");
}
};
Thingy result = (Thingy) MVEL.executeExpression(MVEL.compileExpression("new Thingy(name)", pctx), vars);
assertEquals("test", result.getName());
}
Aggregations