diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-30 08:19:07 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-30 08:19:07 -0500 |
| commit | f5b04084c238e3bb7b16ea8a9b6f6dbe0d0def40 (patch) | |
| tree | 31c1cc26ad29fd110e7897b5d6e56699f24bfd43 /tests/test-keybindings--jump-commands.el | |
| parent | be3e227f3aa75c018fa4f7486226d691765012b5 (diff) | |
| download | dotemacs-f5b04084c238e3bb7b16ea8a9b6f6dbe0d0def40.tar.gz dotemacs-f5b04084c238e3bb7b16ea8a9b6f6dbe0d0def40.zip | |
test(keybindings): cover cj/jump-open-var and the jump-commands wiring
Two test files for keybindings.el. cj/jump-open-var gets full N/B/E
coverage (6 tests): existing-file happy path, plus error paths for
unbound symbol, nil value, non-string value, empty string, and missing
file. The smoke file for the auto-generated cj/jump-to-NAME commands
asserts that each spec entry has an fbound command, that the command
is bound in cj/jump-map at the spec's key, that calling each command
invokes cj/jump-open-var with the spec's var, and that cj/jump-map is
mounted under cj/custom-keymap at "j".
The test fixture variable is declared at top level. If it were
let-bound inside a test under lexical-binding, the let would create a
lexical binding that shadows the dynamic one. The production code's
symbol-value would then miss what setq writes. find-file is mocked at
the boundary so the existing-file test doesn't actually open a buffer.
10 tests pass. No production change in keybindings.el.
Diffstat (limited to 'tests/test-keybindings--jump-commands.el')
| -rw-r--r-- | tests/test-keybindings--jump-commands.el | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test-keybindings--jump-commands.el b/tests/test-keybindings--jump-commands.el new file mode 100644 index 00000000..6fc01285 --- /dev/null +++ b/tests/test-keybindings--jump-commands.el @@ -0,0 +1,50 @@ +;;; test-keybindings--jump-commands.el --- Smoke tests for the auto-generated jump commands -*- lexical-binding: t; -*- + +;;; Commentary: +;; Smoke tests for the `cj/jump-to-NAME' commands that the `dolist' over +;; `cj/jump--specs' generates in keybindings.el. Each spec entry is +;; (KEY NAME-SYM VAR-SYM); the loop creates a defalias and binds it +;; under `cj/jump-map'. These tests assert the wiring without exercising +;; the underlying I/O. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'keybindings) + +(ert-deftest test-keybindings-jump-commands-each-spec-has-fbound-command () + "Smoke: each `cj/jump--specs' entry has an fbound `cj/jump-to-NAME'." + (dolist (spec cj/jump--specs) + (pcase-let ((`(,_key ,name ,_var) spec)) + (let ((fn (intern (format "cj/jump-to-%s" name)))) + (should (fboundp fn)))))) + +(ert-deftest test-keybindings-jump-commands-each-spec-bound-in-jump-map () + "Smoke: each `cj/jump--specs' entry's key is bound to its command in +`cj/jump-map'." + (dolist (spec cj/jump--specs) + (pcase-let ((`(,key ,name ,_var) spec)) + (let ((fn (intern (format "cj/jump-to-%s" name)))) + (should (eq fn (lookup-key cj/jump-map (kbd key)))))))) + +(ert-deftest test-keybindings-jump-commands-each-calls-jump-open-var-with-spec-var () + "Smoke: each `cj/jump-to-NAME' calls `cj/jump-open-var' with the var +from its spec entry, in spec order." + (let (calls) + (cl-letf (((symbol-function 'cj/jump-open-var) + (lambda (var) (push var calls)))) + (dolist (spec cj/jump--specs) + (pcase-let ((`(,_key ,name ,_var) spec)) + (funcall (intern (format "cj/jump-to-%s" name)))))) + (let ((expected-vars (mapcar (lambda (spec) (nth 2 spec)) cj/jump--specs))) + (should (equal (nreverse calls) expected-vars))))) + +(ert-deftest test-keybindings-jump-map-mounted-under-custom-keymap () + "Smoke: `cj/jump-map' is mounted at \"j\" under `cj/custom-keymap'." + (should (eq cj/jump-map (lookup-key cj/custom-keymap (kbd "j"))))) + +(provide 'test-keybindings--jump-commands) +;;; test-keybindings--jump-commands.el ends here |
