blob: fcaddcfd00ff5f0042c1e9144060007c3a4d9c53 (
plain)
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
|
;;; test-selection-framework--consult-line-or-repeat.el --- Tests for the C-s dispatch -*- lexical-binding: t; -*-
;;; Commentary:
;; `cj/consult-line-or-repeat' (bound to `C-s') runs `consult-line', or
;; `vertico-repeat' when it was also the previous command -- so a second press
;; in a row repeats the last search instead of starting a fresh one. These
;; tests exercise both branches with `consult-line' / `vertico-repeat' stubbed.
;;
;; Like `test-selection-framework-keybindings.el', this shadows `use-package'
;; with a no-op so the module loads without pulling in vertico/consult/embark/
;; company/prescient and their load-time side effects.
;;; Code:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(defmacro use-package (&rest _args)
"Ignore package configuration while loading selection-framework in tests."
nil)
(defun consult-line (&rest _args)
"Test stub for `consult-line'.")
(defun vertico-repeat (&rest _args)
"Test stub for `vertico-repeat'.")
(require 'selection-framework)
(defmacro test-sf--with-spies (&rest body)
"Run BODY with `consult-line' and `vertico-repeat' recording into
`consulted' and `repeated', both bound to nil first."
`(let (consulted repeated)
(cl-letf (((symbol-function 'consult-line) (lambda (&rest _) (setq consulted t)))
((symbol-function 'vertico-repeat) (lambda (&rest _) (setq repeated t))))
,@body)))
(ert-deftest test-selection-framework-consult-line-or-repeat-fresh-search ()
"Normal: when the previous command was something else, do a fresh `consult-line'."
(test-sf--with-spies
(let ((last-command 'some-other-command))
(cj/consult-line-or-repeat))
(should consulted)
(should-not repeated)))
(ert-deftest test-selection-framework-consult-line-or-repeat-repeats-on-second-call ()
"Normal: a second invocation in a row repeats the last search."
(test-sf--with-spies
(let ((last-command 'cj/consult-line-or-repeat))
(cj/consult-line-or-repeat))
(should repeated)
(should-not consulted)))
(ert-deftest test-selection-framework-consult-line-or-repeat-nil-last-command ()
"Boundary: nil `last-command' is not a repeat -> fresh search."
(test-sf--with-spies
(let ((last-command nil))
(cj/consult-line-or-repeat))
(should consulted)
(should-not repeated)))
(ert-deftest test-selection-framework-consult-line-or-repeat-is-a-command ()
"Normal: `cj/consult-line-or-repeat' is an interactive command."
(should (commandp #'cj/consult-line-or-repeat)))
(provide 'test-selection-framework--consult-line-or-repeat)
;;; test-selection-framework--consult-line-or-repeat.el ends here
|