1 ;;; indent.el --- Tests of indentation for js2-mode
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program If not, see <http://www.gnu.org/licenses/>.
23 (defun js2-test-indent (content)
24 (let ((s (replace-regexp-in-string "^ *|" "" content)))
26 (insert (replace-regexp-in-string "^ *" "" s))
28 (indent-region (point-min) (point-max))
29 (should (string= s (buffer-substring-no-properties
30 (point-min) (point)))))))
32 (defmacro* js2-deftest-indent (name content &key bind)
33 `(ert-deftest ,(intern (format "js2-%s" name)) ()
34 (let ,(append '((js2-basic-offset 2)
35 (js2-pretty-multiline-declarations t)
36 (inhibit-point-motion-hooks t))
38 (js2-test-indent ,content))))
40 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
42 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
46 (js2-deftest-indent multiline-decl-indent-after-comma
50 (js2-deftest-indent no-multiline-decl-when-disabled
53 :bind ((js2-pretty-multiline-declarations nil)))
55 (js2-deftest-indent multiline-decl-with-continued-expr
59 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
63 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
64 "var foo = bar('/protocols/')
67 (js2-deftest-indent no-multiline-decl-implicit-semicolon
71 (js2-deftest-indent multiline-decl-sees-keyword-width
75 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
83 (js2-deftest-indent multiline-decl-first-arg-function-normal
84 "var foo = function() {
89 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
90 "var foo = function() {
94 :bind ((js2-pretty-multiline-declarations 'all)))