]> code.delx.au - gnu-emacs-elpa/blob - tests/indent.el
Fix #89
[gnu-emacs-elpa] / tests / indent.el
1 (require 'ert)
2 (require 'js2-mode)
3
4 (defun js2-test-indent (content)
5 (let ((s (replace-regexp-in-string "^ *|" "" content)))
6 (with-temp-buffer
7 (insert (replace-regexp-in-string "^ *" "" s))
8 (js2-mode)
9 (indent-region (point-min) (point-max))
10 (should (string= s (buffer-substring-no-properties
11 (point-min) (point)))))))
12
13 (defmacro* js2-deftest-indent (name content &key bind)
14 `(ert-deftest ,name ()
15 (let ,(append '((js2-basic-offset 2)
16 (js2-pretty-multiline-declarations t))
17 bind)
18 (js2-test-indent ,content))))
19
20 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
21
22 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
23 "var foo = 1;
24 |bar = 2")
25
26 (js2-deftest-indent multiline-decl-indent-after-comma
27 "let foo = 1,
28 | bar = 2")
29
30 (js2-deftest-indent no-multiline-decl-when-disabled
31 "let foo = 1,
32 |bar = 2"
33 :bind ((js2-pretty-multiline-declarations nil)))
34
35 (js2-deftest-indent multiline-decl-with-continued-expr
36 "var foo = 100500
37 | + 1")
38
39 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
40 "var foo = 100500 /
41 | 16;")
42
43 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
44 "var foo = bar('/protocols/')
45 |baz()")
46
47 (js2-deftest-indent no-multiline-decl-implicit-semicolon
48 "var foo = 100500
49 |1")
50
51 (js2-deftest-indent multiline-decl-sees-keyword-width
52 "const foo = 1,
53 | bar = 2;")
54
55 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
56 "var foo = 1,
57 | bar = [
58 | 1, 2,
59 | 3, 4
60 | ],
61 | baz = 5;")
62
63 (js2-deftest-indent multiline-decl-first-arg-function-normal
64 "var foo = function() {
65 | return 7;
66 |},
67 | bar = 8;")
68
69 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
70 "var foo = function() {
71 | return 7;
72 | },
73 | bar = 8;"
74 :bind ((js2-pretty-multiline-declarations 'all)))