use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class InlineCollectionsTests method testInlineListSensitivenessToSpaces.
public void testInlineListSensitivenessToSpaces() {
String ex = "([\"a\",\"b\", \"c\"])";
ParserContext ctx = new ParserContext();
Serializable s = compileExpression(ex, ctx);
List result = (List) executeExpression(s, new HashMap());
assertNotNull(result);
assertEquals("a", result.get(0));
assertEquals("b", result.get(1));
assertEquals("c", result.get(2));
}
use of org.mule.mvel2.ParserContext 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.mule.mvel2.ParserContext in project mvel by mikebrock.
the class DebuggerTests method testDebugSymbolsWithMixedLinedEndings.
public void testDebugSymbolsWithMixedLinedEndings() throws Exception {
String expr = " System.out.println( \"a1\" );\n" + " System.out.println( \"a2\" );\r\n" + " System.out.println( \"a3\" );\n" + " System.out.println( \"a4\" );\r\n";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setDebugSymbols(true);
ctx.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(ctx));
System.out.println(s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class DebuggerTests method testBreakpointsAcrossComments2.
public void testBreakpointsAcrossComments2() {
ExpressionCompiler compiler = new ExpressionCompiler(// 1
"// This is a comment\n" + // 2
"//Second comment line\n" + // 3
"//Third Comment Line\n" + // 4
"\n" + // 5
"//Test\n" + // 6
"System.out.println('4');\n" + // 7
"//System.out.println('5'); \n" + // 8
"a = 0;\n" + // 9
"b = 1;\n" + // 10
" a + b");
ParserContext ctx = new ParserContext();
ctx.setSourceFile("test2.mv");
ctx.setDebugSymbols(true);
CompiledExpression compiled = compiler.compile(ctx);
MVELRuntime.registerBreakpoint("test2.mv", 6);
MVELRuntime.registerBreakpoint("test2.mv", 8);
MVELRuntime.registerBreakpoint("test2.mv", 9);
MVELRuntime.registerBreakpoint("test2.mv", 10);
final Set<Integer> breaked = new HashSet<Integer>();
Debugger testDebugger = new Debugger() {
public int onBreak(Frame frame) {
System.out.println("Breakpoint [source:" + frame.getSourceName() + "; line:" + frame.getLineNumber() + "]");
breaked.add(frame.getLineNumber());
return 0;
}
};
MVELRuntime.setThreadDebugger(testDebugger);
assertEquals(1, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap())));
assertEquals("did not break at expected lines", Make.Set.<Integer>$()._(6)._(8)._(9)._(10)._(), breaked);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
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";
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ctx.setDebugSymbols(true);
ctx.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(ctx));
System.out.println(s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(4, count);
}
Aggregations