use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMethodCallWithSpaces.
public void testMethodCallWithSpaces() {
String[] str = new String[] { "Foo f = new Foo(); f.setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f . setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f. setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f .setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f.boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f . boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f. boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f .boolTest = true ; f.isBoolTest()" };
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
pctx.addImport(Foo.class);
List<String> errors = new ArrayList<String>();
for (String s : str) {
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(s, pctx);
Bar ctx = new Bar();
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx, new HashMap());
assertTrue(result);
} catch (Exception e) {
e.printStackTrace();
errors.add("**** Error on expression: " + s + "\n" + e.getMessage());
}
}
assertTrue(errors.toString(), errors.isEmpty());
}
use of org.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.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testContextFieldNotFound.
public void testContextFieldNotFound() {
String str = "'stilton'.equals( type );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Cheese.class);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessWithNestedPropertyAO_ASM.
public void testMapAccessWithNestedPropertyAO_ASM() {
OptimizerFactory.setDefaultOptimizer("ASM");
boolean allowCompilerOverride = MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING;
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
try {
String str = "map[key] == \"one\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", POJO.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
POJO ctx = new POJO();
ctx.getMap().put("1", "one");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
} finally {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = allowCompilerOverride;
}
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnwantedImport.
public void testUnwantedImport() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("java.util");
conf.addPackageImport("org.mvel2.tests.core.res");
ParserContext pctx = new ParserContext(conf);
MVEL.analysisCompile("ScenarioType.Set.ADD", pctx);
assertNull(conf.getImports().get("Set"));
}
Aggregations