KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > language > css > 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.language.css;
11
12 import java.io.BufferedReader JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.io.InputStreamReader JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18 import junit.framework.TestCase;
19
20 import org.netbeans.api.languages.ASTNode;
21 import org.netbeans.api.languages.ParseException;
22 import org.netbeans.api.languages.TokenInput;
23 import org.netbeans.modules.languages.Language;
24 import org.netbeans.modules.languages.NBSLanguageReader;
25 import org.netbeans.modules.languages.parser.AnalyserAnalyser;
26 import org.netbeans.modules.languages.parser.Petra;
27 import org.netbeans.modules.languages.parser.StringInput;
28
29
30 /**
31  *
32  * @author Jan Jancura
33  */

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