use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class TemplateTests method testMVEL244.
public void testMVEL244() {
Foo244 foo = new Foo244("plop");
String template = "@foreach{val : foo.liste[0].liste} plop @end{}";
CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template);
Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", foo);
System.out.println(TemplateRuntime.execute(compiledTemplate, new ParserContext(), new MapVariableResolverFactory(model)));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class TemplateTests method setupVarsMVEL219.
private Map<String, Object> setupVarsMVEL219() {
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("bal", new BigDecimal("999.99"));
vars.put("word", "ball");
vars.put("object", new CoreConfidenceTests.Dog());
Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", "bar");
map.put("fu", new CoreConfidenceTests.Dog());
map.put("trueValue", true);
map.put("falseValue", false);
map.put("one", 1);
map.put("zero", 0);
vars.put("map", map);
return vars;
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class IndexedVariablesTests method testVariableInjection3.
public void testVariableInjection3() {
String[] varNames = { "x", "y", "z" };
Object[] values = { 10, 20, 30 };
String expr = "def add(a,b) { a + b }; foo = -1; res = x + y + z;\n" + "if (x > 9) {\n" + " res = z - y - x;\n" + " int k = 5;\n" + " foo = add(5,10);" + "}; \n" + "for (i = 0; i < 100000; i++) { foo++; }; foo;";
ParserContext ctx = ParserContext.create();
ctx.addIndexedInput(varNames);
ctx.setIndexAllocation(true);
SimpleVariableSpaceModel model = VariableSpaceCompiler.compile(expr, ctx);
Serializable indexCompile = MVEL.compileExpression(expr, ctx);
Serializable dynamicCompile = MVEL.compileExpression(expr, ParserContext.create());
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", 10);
map.put("y", 20);
map.put("z", 30);
assertEquals(MVEL.executeExpression(dynamicCompile, map), MVEL.executeExpression(indexCompile, model.createFactory(values)));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
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);
List list = (List) executeExpression(compiler.compile(ctx), 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.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class TypesAndInferenceTests method testCompileTimeCoercion.
public void testCompileTimeCoercion() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
assertEquals(true, executeExpression(new ExpressionCompiler("foo.bar.woof == 'true'").compile(ctx), createTestMap()));
}
Aggregations