-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
smartparens-delayed-hook-test.el
70 lines (67 loc) · 2.79 KB
/
smartparens-delayed-hook-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
65
66
67
68
69
70
(ert-deftest sp-test-delayed-hook-should-trigger-on-RET ()
(cl-letf (((symbol-function 'sp-test-insert-space)
(lambda (&rest _)
(insert " "))))
(let ((sp-pairs '((emacs-lisp-mode
(:open "(" :close ")" :actions (insert wrap autoskip navigate)
:post-handlers ((sp-test-insert-space "RET")))))))
(sp-test-with-temp-elisp-buffer ""
(execute-kbd-macro "(")
(execute-kbd-macro (kbd "RET"))
(insert "|")
(should (equal (buffer-string) "(
|)"))))))
(ert-deftest sp-test-delayed-hook-should-not-trigger-on-a ()
(cl-letf (((symbol-function 'sp-test-insert-space)
(lambda (&rest _)
(insert " "))))
(let ((sp-pairs '((emacs-lisp-mode
(:open "(" :close ")" :actions (insert wrap autoskip navigate)
:post-handlers ((sp-test-insert-space "RET")))))))
(sp-test-with-temp-elisp-buffer ""
(execute-kbd-macro "(")
(execute-kbd-macro (kbd "a"))
(insert "|")
(should (equal (buffer-string) "(a|)"))))))
(ert-deftest sp-test-delayed-hook-should-trigger-on-my/newline ()
(cl-letf (((symbol-function 'my/test-newline)
(lambda (&rest _)
(interactive)
(insert "\n")))
((symbol-function 'sp-test-insert-space)
(lambda (&rest _)
(insert " "))))
(let ((sp-pairs '((emacs-lisp-mode
(:open "(" :close ")" :actions (insert wrap autoskip navigate)
:post-handlers ((sp-test-insert-space my/test-newline)))))))
(sp-test-with-temp-elisp-buffer ""
(execute-kbd-macro "(")
(setq this-command 'my/test-newline)
(call-interactively 'my/test-newline)
(run-hooks 'post-command-hook)
(insert "|")
(should (equal (buffer-string) "(
|)"))))))
(ert-deftest sp-test-delayed-hook-should-not-trigger-on-newline ()
(cl-letf (((symbol-function 'my/test-newline)
(lambda (&rest _)
(interactive)
(insert "\n")))
((symbol-function 'newline)
(lambda (&rest _)
(interactive)
(insert "\n")))
((symbol-function 'sp-test-insert-space)
(lambda (&rest _)
(insert " "))))
(let ((sp-pairs '((emacs-lisp-mode
(:open "(" :close ")" :actions (insert wrap autoskip navigate)
:post-handlers ((sp-test-insert-space my/test-newline)))))))
(sp-test-with-temp-elisp-buffer ""
(execute-kbd-macro "(")
(setq this-command 'newline)
(call-interactively 'newline)
(run-hooks 'post-command-hook)
(insert "|")
(should (equal (buffer-string) "(
|)"))))))