1 9 10 package org.netbeans.modules.languages.javascript; 11 12 13 import java.io.BufferedReader ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.InputStreamReader ; 17 import java.util.List ; 18 import java.util.Map ; 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 34 public class JavaScriptTest extends TestCase { 35 36 public JavaScriptTest (String testName) { 37 super (testName); 38 } 39 40 public void testConficts () { 41 InputStream is = getClass ().getClassLoader ().getResourceAsStream ("org/netbeans/modules/languages/javascript/JavaScript.nbs"); 42 try { 43 Language l = NBSLanguageReader.readLanguage ("test", is, "test/mimeType"); 44 List r = l.getAnalyser ().getRules (); 45 Map f = Petra.first2 (r); 48 assertFalse (AnalyserAnalyser.hasConflicts (f)); 52 } catch (ParseException ex) { 53 ex.printStackTrace(); 54 } catch (IOException ex) { 55 ex.printStackTrace(); 56 } 57 } 58 59 public void testTokens () throws ParseException, IOException { 60 InputStream 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 br = new BufferedReader (new InputStreamReader (is)); 65 StringBuilder sb = new StringBuilder (); 66 String 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 |