public void testInfiniteLoop() { String str = ""; str += "int insuranceAmt = caseRate + (charges * pctDiscount / 100);\n"; str += "update (estimate); \n"; Map<String, Macro> macros = new HashMap<String, Macro>(); macros.put("update", new Macro() { public String doMacro() { return "drools.update"; } }); String result = parseMacros(str, macros); str = ""; str += "int insuranceAmt = caseRate + (charges * pctDiscount / 100);\n"; str += "drools.update (estimate);"; assertEquals(str, result); }
return parseMacros(raw, macros);
@SuppressWarnings({"unchecked"}) public void testInterfaceMethodCallWithMacro() { Map macros = new HashMap(1); macros.put("retract", new Macro() { public String doMacro() { return "drools.retract"; } }); Map map = new HashMap(); DefaultKnowledgeHelper helper = new DefaultKnowledgeHelper(); map.put("drools", helper); Cheese cheese = new Cheese("stilton", 15); map.put("cheese", cheese); executeExpression(compileExpression(parseMacros("retract(cheese)", macros)), map); assertSame(cheese, helper.retracted.get(0)); }
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 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)); }
parseMacros( "System.out.println('hello');\n" + "System.out.println('bye');\n" +
Map<String, Macro> macros = new HashMap<String, Macro>(); expression = parseMacros(expression, macros);
expression = parseMacros(expression, macros);