Skip to content

Commit 96cf5a7

Browse files
committed
Unit tests for normal completion
1 parent 2721fd8 commit 96cf5a7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

js-comint-test.el

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,61 @@ Array.valueOf
240240
(should (string-empty-p res)))
241241
;; the output should not be accumulated
242242
(should (string-empty-p js-comint--completion-output))))
243+
244+
(ert-deftest js-comint--completion-filter/test-no-completion ()
245+
"Output should be saved until string match, then fail."
246+
(with-mock
247+
(mock (ignore nil)) ;; must be called
248+
(mock (js-comint--clear-repl-input))
249+
(with-temp-buffer
250+
(js-comint--reset-completion-state)
251+
(setq js-comint--post-completion-cb #'ignore
252+
js-comint--completion-prefix "foo")
253+
254+
;; each should be empty
255+
(dolist (res (list (js-comint--completion-filter "f")
256+
(js-comint--completion-filter "oo")))
257+
(should (string-empty-p res)))
258+
;; callback should be called with nil
259+
;; clear should be called
260+
;; then the the flag should be cleared
261+
(should-not js-comint--post-completion-cb))))
262+
263+
(ert-deftest js-comint--completion-filter/test-list-completion ()
264+
"Output should be saved until control char, then list returned."
265+
(with-mock
266+
;; callback should be called with completions
267+
(mock (ignore '("foobar" "foobaz")))
268+
(mock (js-comint--clear-repl-input))
269+
(with-temp-buffer
270+
(js-comint--reset-completion-state)
271+
(setq js-comint--post-completion-cb #'ignore
272+
js-comint--completion-prefix "foo")
273+
274+
;; each should be empty
275+
(dolist (res (list (js-comint--completion-filter "foobar foobaz")
276+
(js-comint--completion-filter "> foo")))
277+
(should (string-empty-p res)))
278+
279+
;; clear should be called
280+
;; then the the flag should be cleared
281+
(should-not js-comint--post-completion-cb))))
282+
283+
(ert-deftest js-comint--completion-filter/test-double-tab ()
284+
"When completing object properties, send another tab to get completion."
285+
(with-mock
286+
(stub js-comint-get-process)
287+
(mock (comint-send-string * "\t"))
288+
(with-temp-buffer
289+
(js-comint--reset-completion-state)
290+
(setq js-comint--post-completion-cb #'ignore
291+
js-comint--completion-prefix "foo.")
292+
293+
;; each should be empty
294+
(dolist (res (list (js-comint--completion-filter "f")
295+
(js-comint--completion-filter "oo.")))
296+
(should (string-empty-p res)))
297+
;; after sending tab should be ready to recieve completion
298+
(should js-comint--post-completion-cb)
299+
(should (equal js-comint--completion-prefix "foo."))
300+
(should (equal js-comint--completion-output "foo.")))))

0 commit comments

Comments
 (0)