]> code.delx.au - gnu-emacs-elpa/blob - tests/indent.el
Replace usage of 'cl with 'cl-lib
[gnu-emacs-elpa] / tests / indent.el
1 ;;; tests/indent.el --- Some tests for js2-mode.
2
3 ;; Copyright (C) 2009, 2011-2013 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
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.
11
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.
16
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/>.
19
20 ;;; Code:
21
22 (require 'ert)
23 (require 'js2-mode)
24 (require 'cl-lib)
25
26 (defun js2-test-indent (content)
27 (let ((s (replace-regexp-in-string "^ *|" "" content)))
28 (with-temp-buffer
29 (insert (replace-regexp-in-string "^ *" "" s))
30 (js2-mode)
31 (indent-region (point-min) (point-max))
32 (should (string= s (buffer-substring-no-properties
33 (point-min) (point)))))))
34
35 (cl-defmacro js2-deftest-indent (name content &key bind)
36 `(ert-deftest ,(intern (format "js2-%s" name)) ()
37 (let ,(append '((js2-basic-offset 2)
38 (js2-pretty-multiline-declarations t)
39 (inhibit-point-motion-hooks t))
40 bind)
41 (js2-test-indent ,content))))
42
43 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
44
45 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
46 "var foo = 1;
47 |bar = 2")
48
49 (js2-deftest-indent multiline-decl-indent-after-comma
50 "let foo = 1,
51 | bar = 2")
52
53 (js2-deftest-indent no-multiline-decl-when-disabled
54 "let foo = 1,
55 |bar = 2"
56 :bind ((js2-pretty-multiline-declarations nil)))
57
58 (js2-deftest-indent multiline-decl-with-continued-expr
59 "var foo = 100500
60 | + 1")
61
62 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
63 "var foo = 100500 /
64 | 16;")
65
66 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
67 "var foo = bar('/protocols/')
68 |baz()")
69
70 (js2-deftest-indent no-multiline-decl-implicit-semicolon
71 "var foo = 100500
72 |1")
73
74 (js2-deftest-indent multiline-decl-sees-keyword-width
75 "const foo = 1,
76 | bar = 2;")
77
78 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
79 "var foo = 1,
80 | bar = [
81 | 1, 2,
82 | 3, 4
83 | ],
84 | baz = 5;")
85
86 (js2-deftest-indent multiline-decl-first-arg-function-normal
87 "var foo = function() {
88 | return 7;
89 |},
90 | bar = 8;")
91
92 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
93 "var foo = function() {
94 | return 7;
95 | },
96 | bar = 8;"
97 :bind ((js2-pretty-multiline-declarations 'all)))
98
99 (js2-deftest-indent default-keyword-as-property
100 "var foo = {
101 | case: 'zzzz',
102 | default: 'donkey',
103 | tee: 'ornery'
104 |};")