Skip to content

Commit 8175e9a

Browse files
committed
Fixed test file, and added regression test cases
Fixes bug#653. * lispy-test.el (lispy-simulate-key) (lispy-simulate-keys) (lispy-simulate-expect): Added facilities to assert results after a given set of keypresses. (lispy-read-unsafe-chars): added regression tests for bug#648.
1 parent fe44efd commit 8175e9a

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

lispy-test.el

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,92 @@
9595
(with-syntax-table table
9696
(split-string str "\\b" t)))))
9797

98+
(defun lispy-simulate-key (key)
99+
"Simulate key press KEY.
100+
This is used rather than `execute-kbd-macro' because apparently
101+
that function somehow fails to run within `ert-deftest'."
102+
(should (numberp key))
103+
(let ((cmd (keymap-lookup nil (key-description (vector key)))))
104+
(setq last-command-event key)
105+
(call-interactively cmd)
106+
(setq last-command cmd)))
107+
108+
(defun lispy-simulate-keys (keys)
109+
"Simulate a sequence of KEYS.
110+
See `lispy-simulate-key'."
111+
(seq-do #'lispy-simulate-key keys))
112+
113+
(cl-defun lispy-simulate-expect
114+
(keys &key buffer point (mode #'lisp-mode))
115+
"Simulate key sequence KEYS and check the result.
116+
If KEYS is a sequence of sequence, simulate each element of KEYS
117+
instead.
118+
119+
MODE is the major mode in effect.
120+
121+
BUFFER, if non-nil, is the buffer string to match after the keys
122+
are simulated.
123+
124+
POINT, if non-nil, is the point to match after the keys are
125+
pressed."
126+
(declare (indent 1))
127+
(if (seqp (seq-first keys))
128+
(seq-do (lambda (keys)
129+
(lispy-simulate-expect keys
130+
:buffer buffer
131+
:point point
132+
:mode mode))
133+
keys)
134+
(with-temp-buffer
135+
(funcall mode)
136+
(lispy-mode)
137+
(lispy-simulate-keys keys)
138+
(when buffer
139+
(should (thread-last (buffer-substring-no-properties
140+
(point-min) (point-max))
141+
(string= buffer))))
142+
(let ((point (cl-case point
143+
(max (point-max))
144+
(min (point-min))
145+
(t point))))
146+
(when point
147+
(should (= (point) point)))))))
148+
149+
(ert-deftest lispy-read-unsafe-chars ()
150+
"See #648."
151+
;; Expect: (de|)
152+
;; Recipe: ( d e
153+
(lispy-simulate-expect '(?\( ?d ?e)
154+
:buffer "(de)"
155+
:point 4)
156+
;; Expect: (.)|
157+
;; Recipes:
158+
;; 1: ( . ) i
159+
;; 2. ( . SPC C-b C-t ) i
160+
;; 3. ( . SPC ) i
161+
;; 4. ( . SPC C-b C-t SPC ) i
162+
(lispy-simulate-expect
163+
'((?\( ?. ?\) ?i) ; format "(.)"
164+
(?\( ?. ? ?\C-b ?\C-t ?\) ?i) ; format "( .)"
165+
(?\( ?. ? ?\) ?i) ; format "(. )"
166+
(?\( ?. ? ?\C-b ?\C-t ? ?\) ?i)) ; format "( . )"
167+
:buffer "(.)"
168+
:point 'max)
169+
;; Expect: (f .)|
170+
;; Recipes:
171+
;; 1. ( f SPC . ) i
172+
;; 2. ( f SPC . SPC ) i
173+
(lispy-simulate-expect
174+
'((?\( ?f ? ?. ?\) ?i) ; format "(f .)"
175+
(?\( ?f ? ?. ? ?\) ?i)) ; format "(f . )"
176+
:buffer "(f .)"
177+
:point 'max)
178+
;; Expect: (. f)|
179+
;; Recipe: ( . SPC f ) i
180+
(lispy-simulate-expect '(?\( ?. ? ?f ?\) ?i)
181+
:buffer "(. f)"
182+
:point 'max))
183+
98184
(ert-deftest lispy-decode-keysequence ()
99185
(should (equal (lispy-decode-keysequence "23ab50c")
100186
'(23 "a" "b" 50 "c")))
@@ -2388,7 +2474,7 @@ Insert KEY if there's no command."
23882474
(should (string= (lispy-with "|;;* Intro" "a")
23892475
";;* Intro\n;;* |")))
23902476

2391-
(ert-deftest lispy-outline-add ()
2477+
(ert-deftest lispy-outline-add-2 () ; FIXME: duplicate name
23922478
(should (string= (lispy-with "(quote ~foo|)" "~")
23932479
"(quote ~~foo|)"))
23942480
(should (string= (lispy-with "(quote ~~foo|)" "~")
@@ -2594,7 +2680,7 @@ Insert KEY if there's no command."
25942680
(execute-kbd-macro (kbd "aa")))
25952681
"(progn (setq type 'norwegian-blue)\n (~setq| plumage-type 'lovely))"))))
25962682

2597-
(ert-deftest lispy-ace-subword ()
2683+
(ert-deftest lispy-ace-subword-2 () ; FIXME: duplicate name
25982684
(should (string= (lispy-with "|(progn (setq type 'norwegian-blue)\n (setq plumage-type 'lovely))"
25992685
(execute-kbd-macro (kbd "-g")))
26002686
"(progn (setq type 'norwegian-blue)\n (setq |plumage~-type 'lovely))"))

0 commit comments

Comments
 (0)