@Test public void testDebugSymbolCount() { String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n"; ParserContext context = new ParserContext(); context.setDebugSymbols( true ); context.addImport( "System", System.class ); context.setStrictTypeEnforcement( true ); //context.setDebugSymbols( true ); context.setSourceFile( "mysource" ); ExpressionCompiler compiler = new ExpressionCompiler( expr, context ); Serializable compiledExpression = compiler.compile(); String s = DebugTools.decompile( compiledExpression ); System.out.println( "s " + s ); int fromIndex = 0; int count = 0; while ( (fromIndex = s.indexOf( "DEBUG_SYMBOL", fromIndex + 1 )) > -1 ) { count++; } assertEquals( 4, count ); }
public void testExecuteCoercionTwice() { OptimizerFactory.setDefaultOptimizer("reflective"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("foo", new Foo()); vars.put("$value", new Long(5)); ParserContext ctx = new ParserContext(); ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true); ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };", ctx); CompiledExpression compiled = compiler.compile(); executeExpression(compiled, null, vars); executeExpression(compiled, null, vars); }
public void testBreakpoints2() { ParserContext ctx = new ParserContext(); ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true); ExpressionCompiler compiler = new ExpressionCompiler("System.out.println('test the debugger');\n a = 0;", ctx); CompiledExpression compiled = compiler.compile(); }
public void testMacroSupport() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("foo", new Foo()); Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>(); Map<String, Macro> macros = new HashMap<String, Macro>(); interceptors.put("Modify", new Interceptor() { public int doBefore(ASTNode node, VariableResolverFactory factory) { ((WithNode) node).getNestedStatement().getValue(null, factory); factory.createVariable("mod", "FOOBAR!"); return 0; } public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) { return 0; } }); macros.put("modify", new Macro() { public String doMacro() { return "@Modify with"; } }); ParserContext ctx = new ParserContext(null, interceptors, null); ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true); ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("modify (foo) { aValue = 'poo = poo', bValue = 'poo, poo' }; mod", macros), ctx); assertEquals("FOOBAR!", executeExpression(compiler.compile(), null, vars)); }
public void testExecuteCoercionTwice2() { OptimizerFactory.setDefaultOptimizer("ASM"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("foo", new Foo()); vars.put("$value", new Long(5)); ParserContext ctx = new ParserContext(); ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true); ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };", ctx); CompiledExpression compiled = compiler.compile(); executeExpression(compiled, null, vars); executeExpression(compiled, null, vars); }
parserContext.setSourceFile( name );
public void testMacroSupportWithStrings() { Map<String, Object> vars = new HashMap<String, Object>(); Foo foo = new Foo(); vars.put("foo", foo); Map<String, Macro> macros = new HashMap<String, Macro>(); macros.put("modify", new Macro() { public String doMacro() { return "drools.modify"; } }); assertEquals("", foo.aValue); ParserContext ctx = new ParserContext(null, null, null); ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true); ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("\"This is an modify()\"", macros), ctx); assertEquals("This is an modify()", executeExpression(compiler.compile(), null, vars)); }
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"; 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); }
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); }
public void testBreakpoints3() { String expr = "System.out.println( \"a1\" );\n" + "System.out.println( \"a2\" );\n" + "System.out.println( \"a3\" );\n" + "System.out.println( \"a4\" );\n"; ParserContext context = new ParserContext(); context.addImport("System", System.class); context.setStrictTypeEnforcement(true); context.setDebugSymbols(true); context.setSourceFile("mysource"); ExpressionCompiler compiler = new ExpressionCompiler(expr, context); String s = org.mvel2.debug.DebugTools.decompile(compiler.compile()); System.out.println("output: " + s); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(4, count); }
ctx.setSourceFile("test.mv"); ctx.setDebugSymbols(true);
ctx.setSourceFile("test2.mv"); ctx.setDebugSymbols(true); ctx.addImport("Foo244", Foo.class);
public void testConcatWithLineBreaks() { ParserContext ctx = new ParserContext(); ctx.setDebugSymbols(true); ctx.setSourceFile("source.mv"); ExpressionCompiler parser = new ExpressionCompiler("\"foo\"+\n\"bar\"", ctx); assertEquals("foobar", executeExpression(parser.compile())); }
public void testBreakpointsAcrossWith() { String line1 = "System.out.println( \"a1\" );\n"; String line2 = "c = new Cheese();\n"; String line3 = "with ( c ) { type = 'cheddar',\n" + " price = 10 };\n"; String line4 = "System.out.println( \"a1\" );\n"; String expr = line1 + line2 + line3 + line4; System.out.println(expr); ParserContext context = new ParserContext(); context.addImport("System", System.class); context.addImport("Cheese", Cheese.class); context.setStrictTypeEnforcement(true); context.setDebugSymbols(true); context.setSourceFile("mysource"); ExpressionCompiler compiler = new ExpressionCompiler(expr, context); String s = org.mvel2.debug.DebugTools.decompile(compiler.compile()); System.out.println("output: " + s); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(5, count); }
ctx.setSourceFile("test2.mv"); ctx.setDebugSymbols( true );
public void testDebugSymbolsWithUnixLinedEndings() throws Exception { String expr = " System.out.println( \"a1\" );\n" + " System.out.println( \"a2\" );\n" + " System.out.println( \"a3\" );\n" + " System.out.println( \"a4\" );\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()); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(4, count); }
public void testBreakpoints() { ParserContext ctx = new ParserContext(); ctx.setSourceFile( "test.mv" ); ctx.setDebugSymbols( true ); ExpressionCompiler compiler = new ExpressionCompiler("a = 5;\nb = 5;\n\nif (a == b) {\n\nSystem.out.println('Good');\nreturn a + b;\n}\n", ctx); System.out.println("-------\n" + compiler.getExpression() + "\n-------\n"); CompiledExpression compiled = compiler.compile(); MVELRuntime.registerBreakpoint("test.mv", 7); 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(10, MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(createTestMap()))); assertTrue("did not break at line 7", breaked.contains(7)); }
ctx.setSourceFile("mysource"); ctx.setDebugSymbols(true); ExpressionCompiler c = new ExpressionCompiler(src, ctx);
public void testDebuggerInvoke2() { count = 0; MVELRuntime.resetDebugger(); MVELRuntime.setThreadDebugger(new Debugger() { public int onBreak(Frame frame) { count++; return 0; } }); String src = "a1=7;\na2=8;\nSystem.out.println(\"h\");\nac=23;\nde=23;\nge=23;\ngef=34;"; ParserContext ctx = new ParserContext(); ctx.setSourceFile("mysource"); ctx.setDebugSymbols(true); ExpressionCompiler c = new ExpressionCompiler(src, ctx); CompiledExpression compexpr = c.compile(); System.out.println(decompile(compexpr)); MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 1); MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 2); MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 3); MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 4); MVELRuntime.registerBreakpoint(ctx.getSourceFile(), 5); VariableResolverFactory factory = new DefaultLocalVariableResolverFactory(); MVEL.executeDebugger(compexpr, null, factory); System.out.println(count); assertEquals(5, count); }
public void testBreakpointsAcrossComments2() { ParserContext ctx = new ParserContext(); ctx.setSourceFile("test2.mv"); ctx.setDebugSymbols(true);