KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * NBSTest.java
3  *
4  * Created on September 1, 2006, 2:46 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.languages.parser;
11
12 import org.netbeans.api.languages.ParseException;
13 import org.netbeans.modules.languages.parser.TokenInput;
14 import org.netbeans.api.languages.ASTNode;
15 import java.io.BufferedReader JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.InputStream JavaDoc;
18 import java.io.InputStreamReader JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21 import junit.framework.TestCase;
22 import org.netbeans.modules.languages.Language;
23 import org.netbeans.modules.languages.NBSLanguageReader;
24
25
26 /**
27  *
28  * @author Jan Jancura
29  */

30 public class NBSTest extends TestCase {
31     
32     public NBSTest (String JavaDoc testName) {
33         super (testName);
34     }
35     
36     public void testFirst () {
37         InputStream JavaDoc is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/resources/NBS.nbs");
38         try {
39             Language l = NBSLanguageReader.readLanguage ("test", is, "test/x-nbs");
40             List JavaDoc r = l.getAnalyser ().getRules ();
41 // AnalyserAnalyser.printRules (r, null);
42
// AnalyserAnalyser.printUndefinedNTs (r, null);
43
Map JavaDoc f = Petra.first2 (r);
44 // AnalyserAnalyser.printDepth (f, null);
45
// AnalyserAnalyser.printConflicts (f, null);
46
// AnalyserAnalyser.printF (f, null);
47
assertFalse (AnalyserAnalyser.hasConflicts (f));
48         } catch (ParseException ex) {
49             ex.printStackTrace();
50         } catch (IOException JavaDoc ex) {
51             ex.printStackTrace();
52         }
53     }
54     
55     public void test2 () throws ParseException, IOException JavaDoc {
56         InputStream JavaDoc is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/resources/NBS.nbs");
57         Language l = NBSLanguageReader.readLanguage ("test", is, "test/x-nbs");
58
59         is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/resources/NBS.nbs");
60         BufferedReader JavaDoc br = new BufferedReader JavaDoc (new InputStreamReader JavaDoc (is));
61         StringBuilder JavaDoc sb = new StringBuilder JavaDoc ();
62         String JavaDoc ln = br.readLine ();
63         while (ln != null) {
64             sb.append (ln).append ('\n');
65             ln = br.readLine ();
66         }
67         TokenInput ti = TokenInput.create (
68             "text/test",
69             l.getParser (),
70             new StringInput (sb.toString (), "NBS.nbs"),
71             l.getSkipTokenTypes ()
72         );
73         ASTNode n = l.getAnalyser ().read (ti, false);
74         assertNotNull (n);
75     }
76 }
77
Popular Tags