]> code.delx.au - gnu-emacs-elpa/blob - packages/js2-mode/tests/indent.el
Merge temp-buffer-browse as our subdirectory
[gnu-emacs-elpa] / packages / js2-mode / tests / indent.el
1 ;;; indent.el --- Tests of indentation for js2-mode
2
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>.
17
18 ;;; Code:
19
20 (require 'ert)
21 (require 'js2-mode)
22
23 (defun js2-test-indent (content)
24 (let ((s (replace-regexp-in-string "^ *|" "" content)))
25 (with-temp-buffer
26 (insert (replace-regexp-in-string "^ *" "" s))
27 (js2-mode)
28 (indent-region (point-min) (point-max))
29 (should (string= s (buffer-substring-no-properties
30 (point-min) (point)))))))
31
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))
37 bind)
38 (js2-test-indent ,content))))
39
40 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
41
42 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
43 "var foo = 1;
44 |bar = 2")
45
46 (js2-deftest-indent multiline-decl-indent-after-comma
47 "let foo = 1,
48 | bar = 2")
49
50 (js2-deftest-indent no-multiline-decl-when-disabled
51 "let foo = 1,
52 |bar = 2"
53 :bind ((js2-pretty-multiline-declarations nil)))
54
55 (js2-deftest-indent multiline-decl-with-continued-expr
56 "var foo = 100500
57 | + 1")
58
59 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
60 "var foo = 100500 /
61 | 16;")
62
63 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
64 "var foo = bar('/protocols/')
65 |baz()")
66
67 (js2-deftest-indent no-multiline-decl-implicit-semicolon
68 "var foo = 100500
69 |1")
70
71 (js2-deftest-indent multiline-decl-sees-keyword-width
72 "const foo = 1,
73 | bar = 2;")
74
75 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
76 "var foo = 1,
77 | bar = [
78 | 1, 2,
79 | 3, 4
80 | ],
81 | baz = 5;")
82
83 (js2-deftest-indent multiline-decl-first-arg-function-normal
84 "var foo = function() {
85 | return 7;
86 |},
87 | bar = 8;")
88
89 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
90 "var foo = function() {
91 | return 7;
92 | },
93 | bar = 8;"
94 :bind ((js2-pretty-multiline-declarations 'all)))