]> code.delx.au - gnu-emacs-elpa/blobdiff - tests/parser.el
Make a new release
[gnu-emacs-elpa] / tests / parser.el
index c672c664b4ef0e509574041289ee087216a09ef1..b4aa68337b5a94dfed74a284c0dc968f6bde7fb6 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tests/parser.el --- Some tests for js2-mode.
 
-;; Copyright (C) 2009, 2011-2013  Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011-2016  Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
@@ -46,7 +46,7 @@
   js2-mode-ast)
 
 (cl-defun js2-test-parse-string (code-string &key syntax-error errors-count
-                                             reference)
+                                             reference warnings-count)
   (ert-with-test-buffer (:name 'origin)
     (let ((ast (js2-test-string-to-ast code-string)))
       (if syntax-error
           (skip-chars-backward " \t\n")
           (should (string= (or reference code-string)
                            (buffer-substring-no-properties
-                            (point-min) (point)))))))))
+                            (point-min) (point)))))
+        (when warnings-count
+          (should (= warnings-count
+                     (length (js2-ast-root-warnings ast)))))))))
 
 (cl-defmacro js2-deftest-parse (name code-string &key bind syntax-error errors-count
-                                     reference)
+                                     reference warnings-count)
   "Parse CODE-STRING.  If SYNTAX-ERROR is nil, print syntax tree
 with `js2-print-tree' and assert the result to be equal to
 REFERENCE, if present, or the original string.  If SYNTAX-ERROR
@@ -77,6 +80,7 @@ the test."
        (js2-test-parse-string ,code-string
                               :syntax-error ,syntax-error
                               :errors-count ,errors-count
+                              :warnings-count ,warnings-count
                               :reference ,reference))))
 
 ;;; Basics
@@ -180,22 +184,27 @@ the test."
 ;;; Destructuring binding
 
 (js2-deftest-parse destruct-in-declaration
-  "var {a, b} = {a: 1, b: 2};")
+  "var {a, b} = {a: 1, b: 2};"
+  :warnings-count 0)
 
 (js2-deftest-parse destruct-in-arguments
-  "function f({a: aa, b: bb}) {\n}")
+  "function f({a: aa, b: bb}) {\n}"
+  :warnings-count 0)
 
 (js2-deftest-parse destruct-in-array-comp-loop
   "[a + b for ([a, b] in [[0, 1], [1, 2]])];")
 
 (js2-deftest-parse destruct-in-catch-clause
-  "try {\n} catch ({a, b}) {\n  a + b;\n}")
+  "try {\n} catch ({a, b}) {\n  a + b;\n}"
+  :warnings-count 0)
 
 (js2-deftest-parse destruct-with-initializer-in-object
-  "var {a, b = 2, c} = {};")
+  "var {a, b = 2, c} = {};\nb;"
+  :warnings-count 0)
 
 (js2-deftest-parse destruct-with-initializer-in-array
-  "var [a, b = 2, c] = [];")
+  "var [a, b = 2, c] = [];\nb;"
+  :warnings-count 0)
 
 (js2-deftest-parse destruct-non-name-target-is-error
   "var {1=1} = {};" :syntax-error "1" :errors-count 1)
@@ -251,7 +260,7 @@ the test."
   "var x = {get [foo + bar]() {  return 42;\n}};")
 
 (js2-deftest-parse object-literal-generator
-  "var x = {*foo() {  yield 42;\n}};")
+  "var x = {*foo() {  yield* 42;\n}};")
 
 (js2-deftest-parse object-literal-computed-generator-key
   "var x = {*[foo + bar]() {  yield 42;\n}};")
@@ -381,6 +390,12 @@ the test."
 (js2-deftest-parse array-destructure-expr-default
   "let [[x] = [3]] = y;")
 
+(js2-deftest-parse spread-in-object-literal
+  "f({x, y, ...z});")
+
+(js2-deftest-parse rest-in-object-literal
+  "const {x, y, ...z} = f();")
+
 ;;; Arrow functions
 
 (js2-deftest-parse arrow-function-with-empty-args-and-no-curlies
@@ -953,22 +968,12 @@ the test."
   (js2-mode--and-parse)
   (js2-test-scope-of-nth-variable-satisifies-predicate "i" 0 #'js2-for-node-p))
 
-(js2-deftest const-scope-sloppy-script "{const a;} a;"
-  (js2-mode--and-parse)
-  (js2-test-scope-of-nth-variable-satisifies-predicate "a" 0 #'js2-script-node-p)
-  (js2-test-scope-of-nth-variable-satisifies-predicate "a" 1 #'js2-script-node-p))
-
-(js2-deftest const-scope-strict-script "'use strict'; { const a; } a;"
+(js2-deftest const-scope-inside-script "{ const a; } a;"
   (js2-mode--and-parse)
   (js2-test-scope-of-nth-variable-satisifies-predicate "a" 0 #'js2-block-node-p)
   (js2-test-scope-of-nth-variable-satisifies-predicate "a" 1 #'null))
 
-(js2-deftest const-scope-sloppy-function "function f() { { const a; } a; }"
-  (js2-mode--and-parse)
-  (js2-test-scope-of-nth-variable-satisifies-predicate "a" 0 #'js2-function-node-p)
-  (js2-test-scope-of-nth-variable-satisifies-predicate "a" 1 #'js2-function-node-p))
-
-(js2-deftest const-scope-strict-function "function f() { 'use strict'; { const a; } a; }"
+(js2-deftest const-scope-inside-function "function f() { { const a; } a; }"
   (js2-mode--and-parse)
   (js2-test-scope-of-nth-variable-satisifies-predicate "a" 0 #'js2-block-node-p)
   (js2-test-scope-of-nth-variable-satisifies-predicate "a" 1 #'null))