use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrongTyping3.
public void testStrongTyping3() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
new ExpressionCompiler("foo.toUC(100.5").compile(ctx);
} catch (Exception e) {
// should fail.
return;
}
assertTrue(false);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testMultiTypeVarDeclr3.
public void testMultiTypeVarDeclr3() {
String ex = "int a = 52 * 3, b = 8, c = 16;";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex);
Serializable s = compiler.compile(ctx);
assertNotNull(ctx.getVariables());
assertEquals(3, ctx.getVariables().entrySet().size());
for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
assertEquals(Integer.class, entry.getValue());
}
Map vars = new HashMap();
executeExpression(s, vars);
assertEquals(52 * 3, vars.get("a"));
assertEquals(8, vars.get("b"));
assertEquals(16, vars.get("c"));
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testDataConverterStrictMode.
public void testDataConverterStrictMode() throws Exception {
OptimizerFactory.setDefaultOptimizer("ASM");
DataConversion.addConversionHandler(Date.class, new MVELDateCoercion());
ParserContext ctx = new ParserContext();
ctx.addImport("Cheese", Cheese.class);
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
Locale.setDefault(Locale.US);
Cheese expectedCheese = new Cheese();
expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c");
Cheese actualCheese = (Cheese) executeExpression(compiler.compile(ctx), createTestMap());
assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy());
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testMapWithStrictTyping.
public void testMapWithStrictTyping() {
ExpressionCompiler compiler = new ExpressionCompiler("map['KEY1'] == $msg");
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setStrongTyping(true);
ctx.addInput("$msg", String.class);
ctx.addInput("map", Map.class);
Serializable expr = compiler.compile(ctx);
Map map = new HashMap();
map.put("KEY1", "MSGONE");
Map vars = new HashMap();
vars.put("$msg", "MSGONE");
vars.put("map", map);
Boolean bool = (Boolean) executeExpression(expr, map, vars);
assertEquals(Boolean.TRUE, bool);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class WithTests method testInlineWith3.
public void testInlineWith3() {
CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}, toUC('doopy')}").compile();
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
assertEquals("foobie", f.getBar().getName());
assertEquals("doopy", f.register);
}
Aggregations