use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testOverloading.
public void testOverloading() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrictTypeEnforcement(true);
parserContext.setStrongTyping(true);
parserContext.addInput("this", Overloaded.class);
Overloaded overloaded = new Overloaded();
assertEquals(15, MVEL.executeExpression(MVEL.compileExpression("method(5, 9, \"x\")", parserContext), overloaded));
assertEquals(-3, MVEL.executeExpression(MVEL.compileExpression("method(5, \"x\", 9)", parserContext), overloaded));
assertEquals(-13, MVEL.executeExpression(MVEL.compileExpression("method(\"x\", 5, 9)", parserContext), overloaded));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImportsWithIdentifierSameAsClassWithDiffCase.
public void testDynamicImportsWithIdentifierSameAsClassWithDiffCase() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("org.mvel2.tests.core.res");
ctx.setStrictTypeEnforcement(false);
ExpressionCompiler compiler = new ExpressionCompiler("bar.add(\"hello\")", ctx);
compiler.compile();
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImports.
public void testDynamicImports() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("java.util");
ExpressionCompiler compiler = new ExpressionCompiler("HashMap", ctx);
Serializable s = compiler.compile();
assertEquals(HashMap.class, executeExpression(s));
compiler = new ExpressionCompiler("map = new HashMap(); map.size()", ctx);
s = compiler.compile();
assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory()));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testGenericsWithOr.
public void testGenericsWithOr() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrictTypeEnforcement(true);
parserContext.setStrongTyping(true);
parserContext.addInput("o", OrderLine.class);
parserContext.addInput("p", Product.class);
Class<?> clazz = MVEL.analyze("p.id == o.product.id || p.category == o.product.category", parserContext);
assertEquals(Boolean.class, clazz);
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class DebuggerTests method testDebugSymbolsWithWindowsLinedEndings.
public void testDebugSymbolsWithWindowsLinedEndings() throws Exception {
String expr = " System.out.println( \"a1\" );\r\n" + " System.out.println( \"a2\" );\r\n" + " System.out.println( \"a3\" );\r\n" + " System.out.println( \"a4\" );\r\n";
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setDebugSymbols(true);
ctx.setSourceFile("mysource");
ExpressionCompiler compiler = new ExpressionCompiler(expr, ctx);
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile());
System.out.println(s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
Aggregations