aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-20 23:31:59 -0500
committerCraig Jennings <c@cjennings.net>2026-07-20 23:31:59 -0500
commit3ea207c1c7588fbc122a766e5d8381815cd44711 (patch)
treea52cc9bf88f4248254e4b133200fda4fd3e27336 /tests
parent4c06b26b6b4f399e3d45f00c281f24a33a15cc66 (diff)
downloaddotemacs-3ea207c1c7588fbc122a766e5d8381815cd44711.tar.gz
dotemacs-3ea207c1c7588fbc122a766e5d8381815cd44711.zip
fix(jumper): handle empty completing-read input without crashing
An unmatched choice made the assoc lookup nil, which crashed the index arithmetic with wrong-type-argument. The jump prompt now gives a user-error and the remove prompt cancels.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-jumper.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test-jumper.el b/tests/test-jumper.el
index fa65d3f4..638f2aa2 100644
--- a/tests/test-jumper.el
+++ b/tests/test-jumper.el
@@ -348,5 +348,30 @@
(should (string-match-p "test line" formatted))))
(test-jumper-teardown))
+;;; Empty completing-read input (vertico-less UI can return "")
+
+(ert-deftest test-jumper-jump-empty-choice-signals-user-error ()
+ "Error: empty input at the jump prompt gives a user-error, not a crash.
+An unmatched choice makes (cdr (assoc ...)) nil, which used to flow into
+the index arithmetic and signal wrong-type-argument."
+ (let ((jumper--next-index 2))
+ (cl-letf (((symbol-function 'jumper--location-candidates)
+ (lambda () '(("[0] here" . 0) ("[1] there" . 1))))
+ ((symbol-function 'get-register) (lambda (_r) nil))
+ ((symbol-function 'completing-read) (lambda (&rest _) "")))
+ (should-error (jumper-jump-to-location) :type 'user-error))))
+
+(ert-deftest test-jumper-remove-empty-choice-cancels ()
+ "Boundary: empty input at the remove prompt cancels instead of crashing."
+ (let ((jumper--next-index 2)
+ removed)
+ (cl-letf (((symbol-function 'jumper--location-candidates)
+ (lambda () '(("[0] here" . 0) ("[1] there" . 1))))
+ ((symbol-function 'completing-read) (lambda (&rest _) ""))
+ ((symbol-function 'jumper--reorder-registers)
+ (lambda (_i) (setq removed t))))
+ (jumper-remove-location)
+ (should-not removed))))
+
(provide 'test-jumper)
;;; test-jumper.el ends here