use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArithmeticTests method testStaticMathCeilWithJavaClassStyleLiterals.
public void testStaticMathCeilWithJavaClassStyleLiterals() {
MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;
try {
String str = "java.lang.Math.ceil( x/3 )";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("x", int.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map vars = new HashMap();
vars.put("x", 4);
assertEquals(Math.ceil((double) 4 / 3), MVEL.executeExpression(stmt, vars));
} finally {
MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = false;
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArithmeticTests method testStaticMathCeil.
public void testStaticMathCeil() {
int x = 4;
// demonstrating it's perfectly valid java
int m = (int) java.lang.Math.ceil(x / 3);
String str = "int m = (int) java.lang.Math.ceil( x/3 ); return m;";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("x", int.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map vars = new HashMap();
vars.put("x", 4);
assertEquals(new Integer(2), MVEL.executeExpression(stmt, vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
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 ArithmeticTests method testIntsWithDivision.
public void testIntsWithDivision() {
String str = "0 == x - (y/2)";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("x", int.class);
pctx.addInput("y", int.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map vars = new HashMap();
vars.put("x", 50);
vars.put("y", 100);
Boolean result = (Boolean) MVEL.executeExpression(stmt, vars);
assertTrue(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArraysTests method testMultiDimensionalArrayType.
public void testMultiDimensionalArrayType() {
String str = "$c.cheeses[0][0] = new Cheese('brie', 15)";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport(Cheese.class);
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("$c", Column.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map<String, Object> vars = new HashMap<String, Object>();
Column c = new Column("x", 1);
c.setCheeses(new Cheese[5][5]);
vars.put("$c", c);
MVEL.executeExpression(stmt, null, vars);
assertEquals(new Cheese("brie", 15), c.getCheeses()[0][0]);
}
Aggregations