01: package org.drools.lang;
02:
03: import junit.framework.TestCase;
04:
05: import org.antlr.runtime.ANTLRStringStream;
06: import org.antlr.runtime.CharStream;
07: import org.antlr.runtime.CommonTokenStream;
08: import org.antlr.runtime.Lexer;
09: import org.antlr.runtime.TokenStream;
10: import org.drools.lang.descr.AndDescr;
11: import org.drools.lang.descr.FieldConstraintDescr;
12: import org.drools.lang.descr.PatternDescr;
13:
14: public class MVELDumperTest extends TestCase {
15:
16: private MVELDumper dumper;
17:
18: protected void setUp() throws Exception {
19: super .setUp();
20: dumper = new MVELDumper();
21: }
22:
23: protected void tearDown() throws Exception {
24: super .tearDown();
25: }
26:
27: public void testDump() throws Exception {
28: String input = "Cheese( price > 10 && < 20 || == $val || == 30 )";
29: String expected = "( ( price > 10 && price < 20 ) || price == $val || price == 30 )";
30: DRLParser parser = parse(input);
31: PatternDescr pattern = (PatternDescr) parser.fact(null);
32:
33: FieldConstraintDescr fieldDescr = (FieldConstraintDescr) pattern
34: .getConstraint().getDescrs().get(0);
35: String result = dumper.dump(fieldDescr);
36:
37: assertEquals(expected, result);
38: }
39:
40: private DRLParser parse(final String text) throws Exception {
41: return newParser(newTokenStream(newLexer(newCharStream(text))));
42: }
43:
44: private CharStream newCharStream(final String text) {
45: return new ANTLRStringStream(text);
46: }
47:
48: private DRLLexer newLexer(final CharStream charStream) {
49: return new DRLLexer(charStream);
50: }
51:
52: private TokenStream newTokenStream(final Lexer lexer) {
53: return new CommonTokenStream(lexer);
54: }
55:
56: private DRLParser newParser(final TokenStream tokenStream) {
57: final DRLParser p = new DRLParser(tokenStream);
58: //p.setParserDebug( true );
59: return p;
60: }
61:
62: }
|