1 ;;; tests/indent.el --- Some tests for js2-mode.
3 ;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 (defun js2-test-indent (content keep-indent)
27 (let ((s (replace-regexp-in-string "^ *|" "" content)))
32 (replace-regexp-in-string "^ *" "" s)))
34 (indent-region (point-min) (point-max))
35 (should (string= s (buffer-substring-no-properties
36 (point-min) (point)))))))
38 (cl-defmacro js2-deftest-indent (name content &key bind keep-indent)
39 `(ert-deftest ,(intern (format "js2-%s" name)) ()
40 (let ,(append '((js2-basic-offset 2)
41 (js2-pretty-multiline-declarations t)
42 (inhibit-point-motion-hooks t))
44 (js2-test-indent ,content ,keep-indent))))
46 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
48 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
52 (js2-deftest-indent multiline-decl-indent-after-comma
56 (js2-deftest-indent no-multiline-decl-when-disabled
59 :bind ((js2-pretty-multiline-declarations nil)))
61 (js2-deftest-indent multiline-decl-with-continued-expr
65 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
69 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
70 "var foo = bar('/protocols/')
73 (js2-deftest-indent no-multiline-decl-implicit-semicolon
77 (js2-deftest-indent multiline-decl-sees-keyword-width
81 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
89 (js2-deftest-indent multiline-decl-first-arg-function-normal
90 "var foo = function() {
95 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
96 "var foo = function() {
100 :bind ((js2-pretty-multiline-declarations 'all)))
102 (js2-deftest-indent default-keyword-as-property
109 (js2-deftest-indent multiline-string-noop
116 (js2-deftest-indent no-multiline-decl-first-arg-function-dynamic
117 "var foo = function() {
120 :bind ((js2-pretty-multiline-declarations 'dynamic)))
122 (js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic
123 "var foo = function() {
127 :bind ((js2-pretty-multiline-declarations 'dynamic)))
129 (js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic-comment
130 "var foo = function() {
132 | }/* MUAHAHAHA, ah ha! */,
134 :bind ((js2-pretty-multiline-declarations 'dynamic)))
136 (js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic-scan-error
137 "var foo = function() {
141 :bind ((js2-pretty-multiline-declarations 'dynamic)))