aboutsummaryrefslogtreecommitdiff
path: root/tests/test-selection-framework--consult-line-or-repeat.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-12 17:09:46 -0500
committerCraig Jennings <c@cjennings.net>2026-05-12 17:09:46 -0500
commit2c5d1c518addd736f618e0441930062d97152760 (patch)
tree553530480b6b203f5e45f3547a2105d8d83fd4a0 /tests/test-selection-framework--consult-line-or-repeat.el
parentfad6f3288ba7c9451bd0b2e0d38c67d267b7fc19 (diff)
downloaddotemacs-2c5d1c518addd736f618e0441930062d97152760.tar.gz
dotemacs-2c5d1c518addd736f618e0441930062d97152760.zip
test(selection-framework): cover both branches of the C-s dispatch
`cj/consult-line-or-repeat` had only a keybinding test. I added `tests/test-selection-framework--consult-line-or-repeat.el` — 4 ERT tests covering the fresh-search branch, the repeat-on-second-call branch, the nil `last-command` boundary, and `commandp`, with `consult-line` and `vertico-repeat` stubbed. It reuses the `use-package`-shadow trick from the keybindings test, so the module loads without dragging in the vertico/consult/embark/company/prescient stack.
Diffstat (limited to 'tests/test-selection-framework--consult-line-or-repeat.el')
-rw-r--r--tests/test-selection-framework--consult-line-or-repeat.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/test-selection-framework--consult-line-or-repeat.el b/tests/test-selection-framework--consult-line-or-repeat.el
new file mode 100644
index 00000000..fcaddcfd
--- /dev/null
+++ b/tests/test-selection-framework--consult-line-or-repeat.el
@@ -0,0 +1,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