use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testDynamicImportsInList.
public void testDynamicImportsInList() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("[ new User('Bobba', 'Feta') ]");
List list = (List) executeExpression(compiler.compile(ctx));
User user = (User) list.get(0);
assertEquals("Bobba", user.getFirstName());
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
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\")");
compiler.compile(ctx);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testParserErrorHandling.
public void testParserErrorHandling() {
final ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler("a[");
try {
compiler.compile(ctx);
} catch (Exception e) {
return;
}
assertTrue(false);
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testStringConcatenation.
public void testStringConcatenation() {
// debugging MVEL code, it seems that MVEL 'thinks' that the result of the expression:
// "Drop +5%: "+$sb+" avg: $"+$av+" price: $"+$pr
// is a double, and as so, he looks for a method:
// Services.log( double );
// but finds only:
// Services.log( String );
// raising the error.
String ex = "services.log((String) \"Drop +5%: \"+$sb+\" avg: $\"+$av+\" price: $\"+$pr );";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("$sb", String.class);
ctx.addInput("$av", double.class);
ctx.addInput("$pr", double.class);
ctx.addInput("services", Services.class);
try {
ExpressionCompiler compiler = new ExpressionCompiler(ex);
compiler.compile(ctx);
} catch (Throwable e) {
e.printStackTrace();
fail("Should not raise exception: " + e.getMessage());
}
}
use of org.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testAssignmentRegression.
public void testAssignmentRegression() {
ExpressionCompiler compiler = new ExpressionCompiler("total = total + $cheese.price");
compiler.compile();
}
Aggregations