KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > parser > PetraTest


1 /*
2  * PetraTest.java
3  * JUnit based test
4  *
5  * Created on August 18, 2006, 8:32 AM
6  */

7
8 package org.netbeans.modules.languages.parser;
9
10 import org.netbeans.api.languages.ASTToken;
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14 import java.net.URL JavaDoc;
15 import junit.framework.TestCase;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Arrays JavaDoc;
18 import java.util.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import org.netbeans.modules.languages.Language;
23 import org.netbeans.modules.languages.NBSLanguageReader;
24 import org.netbeans.modules.languages.parser.LLSyntaxAnalyser.Rule;
25
26
27 /**
28  *
29  * @author Jan Jancura
30  */

31 public class PetraTest extends TestCase {
32     
33     public PetraTest (String JavaDoc testName) {
34         super (testName);
35     }
36
37     
38     public void testFirst1 () {
39         List JavaDoc rules = new ArrayList JavaDoc ();
40         rules.add (Rule.create ("S", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
41             "A",
42             ASTToken.create ("text", "a", null, 0),
43             ASTToken.create ("text", "b", null, 0)
44         }))));
45         rules.add (Rule.create ("A", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
46         }))));
47         rules.add (Rule.create ("A", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
48             ASTToken.create ("text", "a", null, 0),
49             ASTToken.create ("text", "c", null, 0)
50         }))));
51         Map JavaDoc m = Petra.first (rules);
52         AnalyserAnalyser.printF (m, null);
53     }
54     
55     public void testFirst2 () {
56         List JavaDoc rules = new ArrayList JavaDoc ();
57         rules.add (Rule.create ("S", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
58             "A",
59             ASTToken.create ("text", "b", null, 0)
60         }))));
61         rules.add (Rule.create ("S", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
62             ASTToken.create ("text", "b", null, 0),
63             "A",
64             ASTToken.create ("text", "c", null, 0)
65         }))));
66         rules.add (Rule.create ("S", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
67             "B",
68             ASTToken.create ("text", "c", null, 0)
69         }))));
70         rules.add (Rule.create ("S", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
71             ASTToken.create ("text", "b", null, 0),
72             ASTToken.create ("text", "d", null, 0),
73             ASTToken.create ("text", "a", null, 0)
74         }))));
75         rules.add (Rule.create ("A", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
76             ASTToken.create ("text", "d", null, 0)
77         }))));
78         rules.add (Rule.create ("B", new ArrayList JavaDoc (Arrays.asList (new Object JavaDoc[] {
79             ASTToken.create ("text", "d", null, 0)
80         }))));
81         Map JavaDoc m = Petra.first (rules);
82         AnalyserAnalyser.printF (m, null);
83         assertEquals (1, m.size ());
84         assert (m.containsKey ("text"));
85         m = (Map JavaDoc) m.get ("text");
86         assertEquals (3, m.size ());
87         assert (m.containsKey ("S"));
88         assert (m.containsKey ("A"));
89         assert (m.containsKey ("B"));
90         Map JavaDoc m1 = (Map JavaDoc) m.get ("S");
91         assertEquals (3, m1.size ());
92         assert (m1.containsKey (Arrays.asList (new Object JavaDoc[] {"b", null})));
93         assert (m1.containsKey (Arrays.asList (new Object JavaDoc[] {"d", null})));
94         assert (m1.containsKey ("&"));
95         assert (m1.get ("&").equals (new HashSet JavaDoc (Arrays.asList (new Object JavaDoc[] {new Integer JavaDoc (0), new Integer JavaDoc (1), new Integer JavaDoc (2), new Integer JavaDoc (3)}))));
96         
97         m1 = (Map JavaDoc) m1.get (Arrays.asList (new Object JavaDoc[] {"b", null}));
98         assertEquals (2, m1.size ());
99         assert (m1.containsKey (Arrays.asList (new Object JavaDoc[] {"d", null})));
100         assert (m1.containsKey ("&"));
101         assert (m1.get ("&").equals (new HashSet JavaDoc (Arrays.asList (new Object JavaDoc[] {new Integer JavaDoc (1), new Integer JavaDoc (3)}))));
102         
103         m1 = (Map JavaDoc) m1.get (Arrays.asList (new Object JavaDoc[] {"d", null}));
104         assertEquals (3, m1.size ());
105         assert (m1.containsKey ("&"));
106         assert (m1.get ("&").equals (new HashSet JavaDoc (Arrays.asList (new Object JavaDoc[] {new Integer JavaDoc (1), new Integer JavaDoc (3)}))));
107     }
108 }
109
Popular Tags