-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
smartparens-javascript-test.el
64 lines (57 loc) · 1.75 KB
/
smartparens-javascript-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(require 'smartparens-javascript)
(require 'js2-mode)
(defun sp-test--javascript-mode ()
"Helper"
(shut-up (js-mode)))
(ert-deftest sp-test-javascript-slurp-whitespace ()
"Ensure we don't add unwanted whitespace when slurping."
(sp-test-with-temp-buffer "(|)foo.bar()"
(sp-test--javascript-mode)
(sp-forward-slurp-sexp)
(sp-forward-slurp-sexp)
(should (equal (buffer-string) "(foo.bar)()"))))
(ert-deftest sp-test-js2-reindent-after-kill ()
(sp-test-with-temp-buffer "function f () {
|
return 42; // 2 spaces of indentation
}
"
(shut-up (js2-mode))
(sp-kill-hybrid-sexp 1)
(sp-buffer-equals "function f () {
|return 42; // 2 spaces of indentation
}
")))
(ert-deftest sp-test-js2-jsx-html-element-as-sexp ()
(sp-test-with-temp-buffer "function render() {
return |<a href=\"/\">Top</a>;
}
"
(shut-up (js2-jsx-mode))
(sp-forward-sexp)
(sp-buffer-equals "function render() {
return <a href=\"/\">Top</a>|;
}
")
(sp-backward-sexp)
(sp-buffer-equals "function render() {
return |<a href=\"/\">Top</a>;
}
")))
(ert-deftest sp-test-javascript-skip-arrow-fn-bracket ()
"#872"
(sp-test-with-temp-buffer "|const test = () => {
console.log('test')
}M"
(sp-test--javascript-mode)
(call-interactively 'sp-kill-region)
(should (equal (buffer-string) ""))))
(ert-deftest sp-test-javascript-skip-arrow-fn-bracket-region-ok ()
"#872 The region should not be OK because it contains unclosed bracket.
Before, the > character caused it to skip into the `console'
token over the bracket and this made the region appear OK."
(sp-test-with-temp-buffer "|const test = () => {M
console.log('test')
}"
(sp-test--javascript-mode)
(should (not (sp-region-ok-p (region-beginning) (region-end))))))