use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArithmeticTests method testMathCeil.
public void testMathCeil() {
String str = "Math.ceil( x/3 ) == 2";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport("Math", Math.class);
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);
Boolean result = (Boolean) MVEL.executeExpression(stmt, vars);
assertTrue(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArraysTests method testAssignmentOnTwoDimensionalArrayUsingIndexedInput.
public void testAssignmentOnTwoDimensionalArrayUsingIndexedInput() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setIndexAllocation(true);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("array", Double[][].class);
pctx.addIndexedInput("array");
Map vars = new HashMap() {
{
put("array", new Double[2][2]);
}
};
assertEquals(42.0, MVEL.executeExpression(MVEL.compileExpression("array[1][1] = 42.0;\narray[1][1]", pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testPackageImportEnum.
// public void testSysoutNullVariable() {
// // Create our root Map object
// Map<String, String> map = new HashMap<String, String>();
// map.put("foo", null);
//
// VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
// factory.createVariable("this", map);
//
// org.mvel2.MVEL.executeExpression(org.mvel2.MVEL.compileExpression("System.out.println(foo);"), map, factory);
// }
public void testPackageImportEnum() {
String str = "new Status( START )";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addPackageImport("org.mvel2.tests.core.res");
pconf.addPackageImport("org.mvel2.tests.core.res.Status");
ParserContext context = new ParserContext(pconf);
context.setStrongTyping(true);
Serializable s = MVEL.compileExpression(str.trim(), context);
assertEquals(new Status(Status.START), MVEL.executeExpression(s));
assertFalse(new Status(Status.STOP).equals(MVEL.executeExpression(s)));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInstanceofWithPackageImportAndInnerClass.
public void testInstanceofWithPackageImportAndInnerClass() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("org.mvel2.tests.core.CoreConfidenceTests");
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", Object.class);
Map vars = new HashMap() {
{
put("value", new ARef());
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof ARef", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + ARef.class.getCanonicalName(), pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMinusOperatorWithoutSpace.
public void testMinusOperatorWithoutSpace() {
String str = "length == $c.length -1";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Column col1 = new Column("x", 0);
Column col2 = new Column("x", 0);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", col2);
Boolean result = (Boolean) MVEL.executeExpression(stmt, col1, vars);
assertFalse(result);
}
Aggregations