aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorStefan Kangas2020-11-15 00:53:32 +0100
committerStefan Kangas2020-11-15 00:54:07 +0100
commitf08e6538dca6d9cd1457ba1129afe1e56ee286f4 (patch)
treebec221923340ab807ab8791238d3818ff03a5950 /test/src
parentab417cf64d15fb6f6620b45e31c249baec49f3a8 (diff)
downloademacs-f08e6538dca6d9cd1457ba1129afe1e56ee286f4.tar.gz
emacs-f08e6538dca6d9cd1457ba1129afe1e56ee286f4.zip
Run menu-item :filter function before showing binding
* lisp/help.el (describe-map): Fix running `menu-item' :filter functions. This fixes a mistake in the previous conversion of this defun from the old C function describe_map. See the discussion in Bug#39149. * test/src/keymap-tests.el (keymap---get-keyelt/runs-menu-item-filter) (describe-buffer-bindings/menu-item-filter-show-binding) (describe-buffer-bindings/menu-item-filter-hide-binding): New tests. (keymap-tests--test-menu-item-filter): New defun.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/keymap-tests.el30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el
index e3dd8420d7b..610234c5a13 100644
--- a/test/src/keymap-tests.el
+++ b/test/src/keymap-tests.el
@@ -54,6 +54,16 @@
54(ert-deftest keymap-copy-keymap/is-not-eq () 54(ert-deftest keymap-copy-keymap/is-not-eq ()
55 (should-not (eq (copy-keymap help-mode-map) help-mode-map))) 55 (should-not (eq (copy-keymap help-mode-map) help-mode-map)))
56 56
57(ert-deftest keymap---get-keyelt/runs-menu-item-filter ()
58 (let* (menu-item-filter-ran
59 (object `(menu-item "2" identity
60 :filter ,(lambda (cmd)
61 (message "foo")
62 (setq menu-item-filter-ran t)
63 cmd))))
64 (keymap--get-keyelt object t)
65 (should menu-item-filter-ran)))
66
57(ert-deftest keymap-lookup-key () 67(ert-deftest keymap-lookup-key ()
58 (let ((map (make-keymap))) 68 (let ((map (make-keymap)))
59 (define-key map [?a] 'foo) 69 (define-key map [?a] 'foo)
@@ -72,6 +82,26 @@ https://debbugs.gnu.org/39149#31"
72 (with-temp-buffer 82 (with-temp-buffer
73 (should (eq (describe-buffer-bindings (current-buffer)) nil)))) 83 (should (eq (describe-buffer-bindings (current-buffer)) nil))))
74 84
85(defun keymap-tests--test-menu-item-filter (show filter-fun)
86 (unwind-protect
87 (progn
88 (define-key global-map (kbd "C-c C-l r")
89 `(menu-item "2" identity :filter ,filter-fun))
90 (with-temp-buffer
91 (describe-buffer-bindings (current-buffer))
92 (goto-char (point-min))
93 (if (eq show 'show)
94 (should (search-forward "C-c C-l r" nil t))
95 (should-not (search-forward "C-c C-l r" nil t)))))
96 (define-key global-map (kbd "C-c C-l r") nil)
97 (define-key global-map (kbd "C-c C-l") nil)))
98
99(ert-deftest describe-buffer-bindings/menu-item-filter-show-binding ()
100 (keymap-tests--test-menu-item-filter 'show (lambda (cmd) cmd)))
101
102(ert-deftest describe-buffer-bindings/menu-item-filter-hide-binding ()
103 (keymap-tests--test-menu-item-filter 'hide (lambda (_) nil)))
104
75(ert-deftest keymap-store_in_keymap-XFASTINT-on-non-characters () 105(ert-deftest keymap-store_in_keymap-XFASTINT-on-non-characters ()
76 "Check for bug fixed in \"Fix assertion violation in define-key\", 106 "Check for bug fixed in \"Fix assertion violation in define-key\",
77commit 86c19714b097aa477d339ed99ffb5136c755a046." 107commit 86c19714b097aa477d339ed99ffb5136c755a046."