]> code.delx.au - gnu-emacs-elpa/blob - tests/indent.el
Fix #116
[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 ,(intern (format "js2-%s" name)) ()
15 (let ,(append '((js2-basic-offset 2)
16 (js2-pretty-multiline-declarations t)
17 (inhibit-point-motion-hooks t))
18 bind)
19 (js2-test-indent ,content))))
20
21 (put 'js2-deftest-indent 'lisp-indent-function 'defun)
22
23 (js2-deftest-indent no-multiline-decl-indent-after-semicolon
24 "var foo = 1;
25 |bar = 2")
26
27 (js2-deftest-indent multiline-decl-indent-after-comma
28 "let foo = 1,
29 | bar = 2")
30
31 (js2-deftest-indent no-multiline-decl-when-disabled
32 "let foo = 1,
33 |bar = 2"
34 :bind ((js2-pretty-multiline-declarations nil)))
35
36 (js2-deftest-indent multiline-decl-with-continued-expr
37 "var foo = 100500
38 | + 1")
39
40 (js2-deftest-indent multiline-decl-with-continued-expr-same-line
41 "var foo = 100500 /
42 | 16;")
43
44 (js2-deftest-indent no-multiline-decl-with-operator-inside-string
45 "var foo = bar('/protocols/')
46 |baz()")
47
48 (js2-deftest-indent no-multiline-decl-implicit-semicolon
49 "var foo = 100500
50 |1")
51
52 (js2-deftest-indent multiline-decl-sees-keyword-width
53 "const foo = 1,
54 | bar = 2;")
55
56 (js2-deftest-indent multiline-decl-second-arg-value-parenthesised
57 "var foo = 1,
58 | bar = [
59 | 1, 2,
60 | 3, 4
61 | ],
62 | baz = 5;")
63
64 (js2-deftest-indent multiline-decl-first-arg-function-normal
65 "var foo = function() {
66 | return 7;
67 |},
68 | bar = 8;")
69
70 (js2-deftest-indent multiline-decl-first-arg-function-indent-all
71 "var foo = function() {
72 | return 7;
73 | },
74 | bar = 8;"
75 :bind ((js2-pretty-multiline-declarations 'all)))
76
77 (js2-deftest-indent default-keyword-as-property
78 "var foo = {
79 | case: 'zzzz',
80 | default: 'donkey',
81 | tee: 'ornery'
82 |};")