1 7 8 package org.netbeans.modules.languages.parser; 9 10 import org.netbeans.api.languages.ASTToken; 11 import java.io.IOException ; 12 import java.io.InputStream ; 13 import java.io.PrintWriter ; 14 import java.net.URL ; 15 import junit.framework.TestCase; 16 import java.util.ArrayList ; 17 import java.util.Arrays ; 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 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 31 public class PetraTest extends TestCase { 32 33 public PetraTest (String testName) { 34 super (testName); 35 } 36 37 38 public void testFirst1 () { 39 List rules = new ArrayList (); 40 rules.add (Rule.create ("S", new ArrayList (Arrays.asList (new Object [] { 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 (Arrays.asList (new Object [] { 46 })))); 47 rules.add (Rule.create ("A", new ArrayList (Arrays.asList (new Object [] { 48 ASTToken.create ("text", "a", null, 0), 49 ASTToken.create ("text", "c", null, 0) 50 })))); 51 Map m = Petra.first (rules); 52 AnalyserAnalyser.printF (m, null); 53 } 54 55 public void testFirst2 () { 56 List rules = new ArrayList (); 57 rules.add (Rule.create ("S", new ArrayList (Arrays.asList (new Object [] { 58 "A", 59 ASTToken.create ("text", "b", null, 0) 60 })))); 61 rules.add (Rule.create ("S", new ArrayList (Arrays.asList (new Object [] { 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 (Arrays.asList (new Object [] { 67 "B", 68 ASTToken.create ("text", "c", null, 0) 69 })))); 70 rules.add (Rule.create ("S", new ArrayList (Arrays.asList (new Object [] { 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 (Arrays.asList (new Object [] { 76 ASTToken.create ("text", "d", null, 0) 77 })))); 78 rules.add (Rule.create ("B", new ArrayList (Arrays.asList (new Object [] { 79 ASTToken.create ("text", "d", null, 0) 80 })))); 81 Map m = Petra.first (rules); 82 AnalyserAnalyser.printF (m, null); 83 assertEquals (1, m.size ()); 84 assert (m.containsKey ("text")); 85 m = (Map ) 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 m1 = (Map ) m.get ("S"); 91 assertEquals (3, m1.size ()); 92 assert (m1.containsKey (Arrays.asList (new Object [] {"b", null}))); 93 assert (m1.containsKey (Arrays.asList (new Object [] {"d", null}))); 94 assert (m1.containsKey ("&")); 95 assert (m1.get ("&").equals (new HashSet (Arrays.asList (new Object [] {new Integer (0), new Integer (1), new Integer (2), new Integer (3)})))); 96 97 m1 = (Map ) m1.get (Arrays.asList (new Object [] {"b", null})); 98 assertEquals (2, m1.size ()); 99 assert (m1.containsKey (Arrays.asList (new Object [] {"d", null}))); 100 assert (m1.containsKey ("&")); 101 assert (m1.get ("&").equals (new HashSet (Arrays.asList (new Object [] {new Integer (1), new Integer (3)})))); 102 103 m1 = (Map ) m1.get (Arrays.asList (new Object [] {"d", null})); 104 assertEquals (3, m1.size ()); 105 assert (m1.containsKey ("&")); 106 assert (m1.get ("&").equals (new HashSet (Arrays.asList (new Object [] {new Integer (1), new Integer (3)})))); 107 } 108 } 109 | Popular Tags |