1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00

Add some new tests for keymap.c

* test/src/keymap-tests.el (keymap-define-key/undefined)
(keymap-define-key/keyboard-macro, keymap-define-key/lambda)
(keymap-define-key/keymap, keymap-define-key/menu-item)
(keymap-lookup-key/list-of-keymaps, keymap-lookup-key/too-long):
New tests.
(keymap-lookup-key): Extend test slightly.
This commit is contained in:
Stefan Kangas 2021-03-06 03:17:23 +01:00
parent 0f85f2c0e5
commit 106e6f48bf

View File

@ -63,10 +63,66 @@
(keymap--get-keyelt object t)
(should menu-item-filter-ran)))
(ert-deftest keymap-define-key/undefined ()
;; nil (means key is undefined in this keymap),
(let ((map (make-keymap)))
(define-key map [?a] nil)
(should-not (lookup-key map [?a]))))
(ert-deftest keymap-define-key/keyboard-macro ()
;; a string (treated as a keyboard macro),
(let ((map (make-keymap)))
(define-key map [?a] "abc")
(should (equal (lookup-key map [?a]) "abc"))))
(ert-deftest keymap-define-key/lambda ()
(let ((map (make-keymap)))
(define-key map [?a] (lambda () (interactive) nil))
(should (functionp (lookup-key map [?a])))))
(ert-deftest keymap-define-key/keymap ()
;; a keymap (to define a prefix key),
(let ((map (make-keymap))
(map2 (make-keymap)))
(define-key map [?a] map2)
(define-key map2 [?b] 'foo)
(should (eq (lookup-key map [?a ?b]) 'foo))))
(ert-deftest keymap-define-key/menu-item ()
;; or an extended menu item definition.
;; (See info node (elisp)Extended Menu Items.)
(let ((map (make-sparse-keymap))
(menu (make-sparse-keymap)))
(define-key menu [new-file]
'(menu-item "Visit New File..." find-file
:enable (menu-bar-non-minibuffer-window-p)
:help "Specify a new file's name, to edit the file"))
(define-key map [menu-bar file] (cons "File" menu))
(should (eq (lookup-key map [menu-bar file new-file]) 'find-file))))
(ert-deftest keymap-lookup-key ()
(let ((map (make-keymap)))
(define-key map [?a] 'foo)
(should (eq (lookup-key map [?a]) 'foo))))
(should (eq (lookup-key map [?a]) 'foo))
(should-not (lookup-key map [?b]))))
(ert-deftest keymap-lookup-key/list-of-keymaps ()
(let ((map1 (make-keymap))
(map2 (make-keymap)))
(define-key map1 [?a] 'foo)
(define-key map2 [?b] 'bar)
(should (eq (lookup-key (list map1 map2) [?a]) 'foo))
(should (eq (lookup-key (list map1 map2) [?b]) 'bar))
(should-not (lookup-key (list map1 map2) [?c]))))
(ert-deftest keymap-lookup-key/too-long ()
(let ((map (make-keymap)))
(define-key map (kbd "C-c f") 'foo)
(should (= (lookup-key map (kbd "C-c f x")) 2))))
;; TODO: Write test for the ACCEPT-DEFAULT argument.
;; (ert-deftest keymap-lookup-key/accept-default ()
;; ...)
(ert-deftest describe-buffer-bindings/header-in-current-buffer ()
"Header should be inserted into the current buffer.