Commits

Anonymous committed df72038

span tests

Comments (0)

Files changed (1)

tests/samples/test_js_semantic.py

         result,error = g.apply("comments")
         assert result == ['\n',["mlcomment", {}, " hello "],'\n',["comment", {}, " hello"], '\n', '    ']
 
+    def test_spans(self):
+        g = JavaScriptGrammar(u" \t\xA0")
+        result,error = g.apply("opt_hspan")
+        assert result == [u" ",u"\t",u"\xA0"]
+        
+        g = JavaScriptGrammar(u" \t\n")
+        result,error = g.apply("opt_vspan")
+        assert result == [u" ",u"\t",u"\n"]
+        
+        g = JavaScriptGrammar(u" \n\r\n \t")
+        result,error = g.apply("opt_vspan")
+        assert result == [u" ",u"\n",u"\r\n",u" ", u"\t"]
+        
+        g = JavaScriptGrammar(u" /*!*/\r\n/* abc */")
+        result,error = g.apply("opt_vspan")
+        assert result == [u" ", ["mlcomment",{},"!"] ,u"\r\n", ["mlcomment",{}," abc "]]
+        
+        g = JavaScriptGrammar(u"""\
+/* */
+// -
+  //
+""")
+        result,error = g.apply("opt_vspan")
+        assert result == [
+            ["mlcomment",{}," "], "\n",
+            ["comment",{}," -"], "\n",
+            " "," ", ["comment",{},""], "\n"
+        ]
+        
     def test_simple(self):
         
         self.checkLiteral("true", "boolean", "true", value=True)