Add some more tests for keymap.c

* test/src/keymap-tests.el (keymap-make-keymap)
(keymap-make-sparse-keymap, keymap-keymapp)
(keymap-keymap-parent, keymap-keymap-set-parent/returns-parent)
(keymap-copy-keymap/is-equal, keymap-copy-keymap/is-not-eq)
(keymap-lookup-key, keymap-apropos-internal)
(keymap-apropos-internal/predicate): New tests.
(keymap-tests--make-keymap-test): New defun.
This commit is contained in:
Stefan Kangas 2020-11-07 07:55:50 +01:00
parent b7b9bbb93d
commit 6df06148e5

View file

@ -24,6 +24,45 @@
(require 'ert)
(defun keymap-tests--make-keymap-test (fun)
(should (eq (car (funcall fun)) 'keymap))
(should (proper-list-p (funcall fun)))
(should (equal (car (last (funcall fun "foo"))) "foo")))
(ert-deftest keymap-make-keymap ()
(keymap-tests--make-keymap-test #'make-keymap)
(should (char-table-p (cadr (make-keymap)))))
(ert-deftest keymap-make-sparse-keymap ()
(keymap-tests--make-keymap-test #'make-sparse-keymap))
(ert-deftest keymap-keymapp ()
(should (keymapp (make-keymap)))
(should (keymapp (make-sparse-keymap)))
(should-not (keymapp '(foo bar))))
(ert-deftest keymap-keymap-parent ()
(should-not (keymap-parent (make-keymap)))
(should-not (keymap-parent (make-sparse-keymap)))
(let ((map (make-keymap)))
(set-keymap-parent map help-mode-map)
(should (equal (keymap-parent map) help-mode-map))))
(ert-deftest keymap-keymap-set-parent/returns-parent ()
(let ((map (make-keymap)))
(should (equal (set-keymap-parent map help-mode-map) help-mode-map))))
(ert-deftest keymap-copy-keymap/is-equal ()
(should (equal (copy-keymap help-mode-map) help-mode-map)))
(ert-deftest keymap-copy-keymap/is-not-eq ()
(should-not (eq (copy-keymap help-mode-map) help-mode-map)))
(ert-deftest keymap-lookup-key ()
(let ((map (make-keymap)))
(define-key map [?a] 'foo)
(should (eq (lookup-key map [?a]) 'foo))))
(ert-deftest describe-buffer-bindings/header-in-current-buffer ()
"Header should be inserted into the current buffer.
https://debbugs.gnu.org/39149#31"
@ -135,6 +174,16 @@ commit 86c19714b097aa477d339ed99ffb5136c755a046."
(where-is-internal 'execute-extended-command global-map t))
[#x8000078])))
(ert-deftest keymap-apropos-internal ()
(should (equal (apropos-internal "^next-line$") '(next-line)))
(should (>= (length (apropos-internal "^help")) 100))
(should-not (apropos-internal "^test-a-missing-symbol-foo-bar-zut$")))
(ert-deftest keymap-apropos-internal/predicate ()
(should (equal (apropos-internal "^next-line$" #'commandp) '(next-line)))
(should (>= (length (apropos-internal "^help" #'commandp)) 15))
(should-not (apropos-internal "^next-line$" #'keymapp)))
(provide 'keymap-tests)
;;; keymap-tests.el ends here