use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class FunctionsTest method testFunctionDefAndCall2.
public void testFunctionDefAndCall2() {
ExpressionCompiler compiler = new ExpressionCompiler("function heyFoo() { return 'Foobar'; };\n" + "return heyFoo() + heyFoo();");
Serializable s = compiler.compile();
Map<String, Function> m = extractAllDeclaredFunctions((CompiledExpression) s);
assertTrue(m.containsKey("heyFoo"));
OptimizerFactory.setDefaultOptimizer("reflective");
assertEquals("FoobarFoobar", executeExpression(s, new HashMap()));
assertEquals("FoobarFoobar", executeExpression(s, new HashMap()));
OptimizerFactory.setDefaultOptimizer("dynamic");
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class InlineCollectionsTests method testToListStrictMode.
@SuppressWarnings({ "UnnecessaryBoxing" })
public void testToListStrictMode() {
String text = "misc.toList(foo.bar.name, 'hello', 42, ['key1' : 'value1'," + " c : [ foo.bar.age, 'car', 42 ]], [42, [c : 'value1']] )";
ParserContext ctx = new ParserContext();
ctx.addInput("misc", MiscTestClass.class);
ctx.addInput("foo", Foo.class);
ctx.addInput("c", String.class);
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler(text, ctx);
List list = (List) executeExpression(compiler.compile(), createTestMap());
assertSame("dog", list.get(0));
assertEquals("hello", list.get(1));
assertEquals(new Integer(42), list.get(2));
Map map = (Map) list.get(3);
assertEquals("value1", map.get("key1"));
List nestedList = (List) map.get("cat");
assertEquals(14, nestedList.get(0));
assertEquals("car", nestedList.get(1));
assertEquals(42, nestedList.get(2));
nestedList = (List) list.get(4);
assertEquals(42, nestedList.get(0));
map = (Map) nestedList.get(1);
assertEquals("value1", map.get("cat"));
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testStrongTyping3.
public void testStrongTyping3() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
new ExpressionCompiler("foo.toUC(100.5", ctx).compile();
} catch (Exception e) {
// should fail.
return;
}
assertTrue(false);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testAnalysisCompile.
public void testAnalysisCompile() {
ParserContext pCtx = new ParserContext();
ExpressionCompiler e = new ExpressionCompiler("foo.aValue = 'bar'", pCtx);
e.setVerifyOnly(true);
e.compile();
assertTrue(pCtx.getInputs().keySet().contains("foo"));
assertEquals(1, pCtx.getInputs().size());
assertEquals(0, pCtx.getVariables().size());
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class TypesAndInferenceTests method testStrictTypingCompilation3.
public void testStrictTypingCompilation3() throws NoSuchMethodException {
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("message='Hello';b=7;\nSystem.out.println(message + ';' + b);\n" + "System.out.println(message + ';' + b); b", ctx);
assertEquals(7, executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory()));
}
Aggregations