use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testEmptyOperatorOnBoolean.
public void testEmptyOperatorOnBoolean() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("bNull", Boolean.class);
pctx.addInput("bTrue", Boolean.class);
pctx.addInput("bFalse", Boolean.class);
Map vars = new HashMap() {
{
put("bNull", null);
put("bTrue", true);
put("bFalse", false);
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("bNull == empty", pctx), vars));
assertEquals(false, MVEL.executeExpression(MVEL.compileExpression("bTrue == empty", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("bFalse == empty", pctx), vars));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testForLoopWithSpaces.
public void testForLoopWithSpaces() {
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("strings", Arrays.asList("test"));
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("strings", List.class);
String expression = "for ( String s : strings ) {\n" + " return s;\n" + "}";
Serializable compiledExpr = MVEL.compileExpression(expression, pctx);
assertEquals("test", MVEL.executeExpression(compiledExpr, null, factory));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class PrimitiveTypesTest method testFloat.
public void testFloat() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(FactWithFloat.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("this", FactWithFloat.class);
boolean result = (Boolean) MVEL.executeExpression(MVEL.compileExpression("floatObjectValue == 15.1", pctx), new FactWithFloat(15.1f));
assertTrue(result);
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testEmptyOperatorOnStrings.
public void testEmptyOperatorOnStrings() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("nullString", String.class);
pctx.addInput("emptyString", String.class);
pctx.addInput("blankString", String.class);
pctx.addInput("nonEmptyString", String.class);
Map vars = new HashMap() {
{
put("nullString", null);
put("emptyString", "");
put("blankString", " ");
put("nonEmptyString", "abc");
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("nullString == empty", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("emptyString == empty", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("blankString == empty", pctx), vars));
assertEquals(false, MVEL.executeExpression(MVEL.compileExpression("nonEmptyString == empty", pctx), vars));
}
use of org.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));
}
Aggregations