KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > javascript > JavaScriptTest


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.javascript;
11
12
13 import java.io.BufferedReader JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.io.InputStreamReader JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
19 import junit.framework.TestCase;
20
21 import org.netbeans.api.languages.ParseException;
22 import org.netbeans.modules.languages.parser.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 JavaScriptTest extends TestCase {
35     
36     public JavaScriptTest (String JavaDoc testName) {
37         super (testName);
38     }
39     
40     public void testConficts () {
41         InputStream JavaDoc is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/javascript/JavaScript.nbs");
42         try {
43             Language l = NBSLanguageReader.readLanguage ("test", is, "test/mimeType");
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 testTokens () throws ParseException, IOException JavaDoc {
60         InputStream JavaDoc is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/javascript/JavaScript.nbs");
61         Language l = NBSLanguageReader.readLanguage ("test", is, "test/x-nbs");
62
63         is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/javascript/tokens.js");
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 (), "NBS.nbs"),
74             l.getSkipTokenTypes ()
75         );
76         assertEquals ("identifier", ti.read ().getType ());
77         assertEquals ("keyword", ti.read ().getType ());
78         assertEquals ("operator", ti.read ().getType ());
79         assertEquals ("string", ti.read ().getType ());
80         assertEquals ("operator", ti.read ().getType ());
81         assertEquals ("string", ti.read ().getType ());
82         assertEquals ("operator", ti.read ().getType ());
83         assertEquals ("string", ti.read ().getType ());
84         assertEquals ("operator", ti.read ().getType ());
85         assertEquals ("string", ti.read ().getType ());
86         assertEquals ("operator", ti.read ().getType ());
87         assertEquals ("string", ti.read ().getType ());
88         assertEquals ("operator", ti.read ().getType ());
89         assertEquals ("string", ti.read ().getType ());
90         assertEquals ("separator", ti.read ().getType ());
91         assertTrue (ti.eof ());
92     }
93 }
94
Popular Tags