]> code.delx.au - gnu-emacs-elpa/commitdiff
Fix string literals in parser.el test harness.
authorStephen Hicks <sdh@google.com>
Tue, 11 Nov 2014 02:13:42 +0000 (18:13 -0800)
committerStephen Hicks <sdh@google.com>
Sat, 15 Nov 2014 09:02:32 +0000 (01:02 -0800)
Previously all string literals in tests would fail, because they referred to a temporary buffer that no longer exists.  This fix works around this by extending the life of the temporary input buffer.

tests/parser.el

index 8d2cf706182bd4d020ec5a1f55e8e79c5f6efbe8..d986ffc34c9651a25d6ba54d1cff8a3cab5072c9 100644 (file)
 (put 'js2-deftest 'lisp-indent-function 'defun)
 
 (defun js2-test-string-to-ast (s)
-  (ert-with-test-buffer (:name 'origin)
-    (insert s)
-    (js2-mode)
-    (should (null js2-mode-buffer-dirty-p))
-    js2-mode-ast))
+  (insert s)
+  (js2-mode)
+  (should (null js2-mode-buffer-dirty-p))
+  js2-mode-ast)
 
 (defun* js2-test-parse-string (code-string &key syntax-error errors-count
                                                 reference)
-  (let ((ast (js2-test-string-to-ast code-string)))
-    (if syntax-error
-        (let ((errors (js2-ast-root-errors ast)))
-          (should (= (or errors-count 1) (length errors)))
-          (destructuring-bind (_ pos len) (first errors)
-            (should (string= syntax-error (substring code-string
-                                                     (1- pos) (+ pos len -1))))))
-      (should (= 0 (length (js2-ast-root-errors ast))))
-      (ert-with-test-buffer (:name 'copy)
-        (js2-print-tree ast)
-        (skip-chars-backward " \t\n")
-        (should (string= (or reference code-string)
-                         (buffer-substring-no-properties
-                          (point-min) (point))))))))
+  (ert-with-test-buffer (:name 'origin)
+    (let ((ast (js2-test-string-to-ast code-string)))
+      (if syntax-error
+          (let ((errors (js2-ast-root-errors ast)))
+            (should (= (or errors-count 1) (length errors)))
+            (destructuring-bind (_ pos len) (first errors)
+              (should (string= syntax-error (substring code-string
+                                                       (1- pos) (+ pos len -1))))))
+        (should (= 0 (length (js2-ast-root-errors ast))))
+        (ert-with-test-buffer (:name 'copy)
+          (js2-print-tree ast)
+          (skip-chars-backward " \t\n")
+          (should (string= (or reference code-string)
+                           (buffer-substring-no-properties
+                            (point-min) (point)))))))))
 
 (defmacro* js2-deftest-parse (name code-string &key bind syntax-error errors-count
                                                     reference)
@@ -332,6 +332,14 @@ the test."
 (js2-deftest-parse octal-number-broken "0o812;"
   :syntax-error "0o8" :errors-count 2)
 
+;;; Strings
+
+(js2-deftest-parse string-literal
+  "var x = 'y';")
+
+(js2-deftest-parse object-get-string-literal
+  "var x = {y: 5};\nvar z = x[\"y\"];")
+
 ;;; Classes
 
 (js2-deftest-parse parse-harmony-class-statement