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