]> git.eshelyaron.com Git - emacs.git/commitdiff
Use defvar-keymap in tests
authorStefan Kangas <stefan@marxist.se>
Sun, 26 Dec 2021 20:52:56 +0000 (21:52 +0100)
committerStefan Kangas <stefan@marxist.se>
Sun, 26 Dec 2021 20:52:56 +0000 (21:52 +0100)
* test/lisp/button-tests.el (button-tests--map):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-keymap):
* test/lisp/help-tests.el (help-tests-remap-map)
(help-tests-major-mode-map, help-tests-minor-mode-map):
* test/lisp/kmacro-tests.el (kmacro-tests-keymap):
* test/lisp/repeat-tests.el (repeat-tests-map)
(repeat-tests-repeat-map):
* test/src/keymap-tests.el (keymap-tests-minor-mode-map)
(keymap-tests-major-mode-map): Use defvar-keymap.

test/lisp/button-tests.el
test/lisp/emacs-lisp/edebug-tests.el
test/lisp/help-tests.el
test/lisp/kmacro-tests.el
test/lisp/repeat-tests.el
test/src/keymap-tests.el

index 2f5ad795df2fece9796e77d53e75a5746ea0ee59..a88387e0259e2e9fe0ba862a9e2064eb84cadc5b 100644 (file)
 
 (require 'ert)
 
-(defvar button-tests--map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "x" #'ignore)
-    map)
-  "Keymap for testing command substitution.")
+(defvar-keymap button-tests--map
+  :doc "Keymap for testing command substitution."
+  "x" #'ignore)
 
 (ert-deftest button-at ()
   "Test `button-at' behavior."
index 210bf24880b6c1ee2866fc510ee5ee8d62188a26..3ab5ac6a9ad2a3881aaf51808c80d64ce3cc443b 100644 (file)
@@ -53,22 +53,20 @@ Since `should' failures which happen inside `post-command-hook' will
 be trapped by the command loop, this preserves them until we get
 back to the top level.")
 
-(defvar edebug-tests-keymap
-  (let ((map (make-sparse-keymap)))
-    (define-key map "@"     'edebug-tests-call-instrumented-func)
-    (define-key map "C-u"   'universal-argument)
-    (define-key map "C-p"   'previous-line)
-    (define-key map "C-n"   'next-line)
-    (define-key map "C-b"   'backward-char)
-    (define-key map "C-a"   'move-beginning-of-line)
-    (define-key map "C-e"   'move-end-of-line)
-    (define-key map "C-k"   'kill-line)
-    (define-key map "M-x"   'execute-extended-command)
-    (define-key map "C-M-x" 'eval-defun)
-    (define-key map "C-x X b" 'edebug-set-breakpoint)
-    (define-key map "C-x X w" 'edebug-where)
-    map)
-  "Keys used by the keyboard macros in Edebug's tests.")
+(defvar-keymap edebug-tests-keymap
+  :doc "Keys used by the keyboard macros in Edebug's tests."
+  "@"       'edebug-tests-call-instrumented-func
+  "C-u"     'universal-argument
+  "C-p"     'previous-line
+  "C-n"     'next-line
+  "C-b"     'backward-char
+  "C-a"     'move-beginning-of-line
+  "C-e"     'move-end-of-line
+  "C-k"     'kill-line
+  "M-x"     'execute-extended-command
+  "C-M-x"   'eval-defun
+  "C-x X b" 'edebug-set-breakpoint
+  "C-x X w" 'edebug-where)
 
 ;;; Macros for defining tests:
 
index a1ae838239c8f4cd6524e71f8e298743296e0f2f..65b329c1cd6c930cc161af0060d09ac86fa835eb 100644 (file)
@@ -166,12 +166,11 @@ M-g M-c           switch-to-completions
    (test "\\<minibuffer-local-must-match-map>\\[abort-recursive-edit]" "C-]")
    (test "\\<emacs-lisp-mode-map>\\[eval-defun]" "C-M-x")))
 
-(defvar help-tests-remap-map
-  (let ((map (make-keymap)))
-    (define-key map (kbd "x") 'foo)
-    (define-key map (kbd "y") 'bar)
-    (define-key map [remap foo] 'bar)
-    map))
+(defvar-keymap help-tests-remap-map
+  :full t
+  "x" 'foo
+  "y" 'bar
+  "<remap> <foo>" 'bar)
 
 (ert-deftest help-tests-substitute-command-keys/remap ()
   (should (equal (substitute-command-keys "\\<help-tests-remap-map>\\[foo]") "y"))
@@ -235,30 +234,28 @@ M-g M-c           switch-to-completions
     (goto-char (point-min))
     (should (looking-at "Type RET on"))))
 
-(defvar help-tests-major-mode-map
-  (let ((map (make-keymap)))
-    (define-key map "x" 'foo-original)
-    (define-key map "1" 'foo-range)
-    (define-key map "2" 'foo-range)
-    (define-key map "3" 'foo-range)
-    (define-key map "4" 'foo-range)
-    (define-key map (kbd "C-e") 'foo-something)
-    (define-key map '[F1] 'foo-function-key1)
-    (define-key map "(" 'short-range)
-    (define-key map ")" 'short-range)
-    (define-key map "a" 'foo-other-range)
-    (define-key map "b" 'foo-other-range)
-    (define-key map "c" 'foo-other-range)
-    map))
+(defvar-keymap help-tests-major-mode-map
+  :full t
+  "x"    'foo-original
+  "1"    'foo-range
+  "2"    'foo-range
+  "3"    'foo-range
+  "4"    'foo-range
+  "C-e"  'foo-something
+  "<f1>" 'foo-function-key1
+  "("    'short-range
+  ")"    'short-range
+  "a"    'foo-other-range
+  "b"    'foo-other-range
+  "c"    'foo-other-range)
 
 (define-derived-mode help-tests-major-mode nil
   "Major mode for testing shadowing.")
 
-(defvar help-tests-minor-mode-map
-  (let ((map (make-keymap)))
-    (define-key map "x" 'foo-shadow)
-    (define-key map (kbd "C-e") 'foo-shadow)
-    map))
+(defvar-keymap help-tests-minor-mode-map
+  :full t
+  "x"   'foo-shadow
+  "C-e" 'foo-shadow)
 
 (define-minor-mode help-tests-minor-mode
   "Minor mode for testing shadowing.")
index ecd3d5fc22b625a54732232117f6310254695db0..49b40935387d2158993fc44c09083d3ec064148c 100644 (file)
@@ -91,33 +91,30 @@ body in KEYS-AND-BODY."
        ,docstring ,@keys
        (kmacro-tests-with-kmacro-clean-slate ,@body))))
 
-(defvar kmacro-tests-keymap
-  (let ((map (make-sparse-keymap)))
-    (dotimes (i 26)
-      (define-key map (string (+ ?a i)) 'self-insert-command))
-    (dotimes (i 10)
-      (define-key map (string (+ ?0 i)) 'self-insert-command))
-    ;; Define a few key sequences of different lengths.
-    (dolist (item '(("\C-a"     . beginning-of-line)
-                    ("\C-b"     . backward-char)
-                    ("\C-e"     . end-of-line)
-                    ("\C-f"     . forward-char)
-                    ("\C-r"     . isearch-backward)
-                    ("\C-u"     . universal-argument)
-                    ("\C-w"     . kill-region)
-                    ("\C-SPC"   . set-mark-command)
-                    ("\M-w"     . kill-ring-save)
-                    ("\M-x"     . execute-extended-command)
-                    ("\C-cd"    . downcase-word)
-                    ("\C-cxu"   . upcase-word)
-                    ("\C-cxq"   . quoted-insert)
-                    ("\C-cxi"   . kmacro-insert-counter)
-                    ("\C-x\C-k" . kmacro-keymap)))
-      (define-key map (car item) (cdr item)))
-    map)
-  "Keymap to use for testing keyboard macros.
+(defvar-keymap kmacro-tests-keymap
+  :doc "Keymap to use for testing keyboard macros.
 This is used to obtain consistent results even if tests are run
-in an environment with rebound keys.")
+in an environment with rebound keys."
+  ;; Define a few key sequences of different lengths.
+  "C-a"     'beginning-of-line
+  "C-b"     'backward-char
+  "C-e"     'end-of-line
+  "C-f"     'forward-char
+  "C-r"     'isearch-backward
+  "C-u"     'universal-argument
+  "C-w"     'kill-region
+  "C-SPC"   'set-mark-command
+  "M-w"     'kill-ring-save
+  "M-x"     'execute-extended-command
+  "C-c d"   'downcase-word
+  "C-c x u" 'upcase-word
+  "C-c x q" 'quoted-insert
+  "C-c x i" 'kmacro-insert-counter
+  "C-x C-k" 'kmacro-keymap)
+(dotimes (i 26)
+  (keymap-set kmacro-tests-keymap (string (+ ?a i)) 'self-insert-command))
+(dotimes (i 10)
+  (keymap-set kmacro-tests-keymap (string (+ ?0 i)) 'self-insert-command))
 
 (defvar kmacro-tests-events nil
   "Input events used by the kmacro test in progress.")
index 02d9ddbc96ec4b11de63d9131f8ce6b9ea7c1977..84a4d722a83ace813cdcd658a811fc0cd8948750 100644 (file)
   (interactive "p")
   (push `(,arg b) repeat-tests-calls))
 
-(defvar repeat-tests-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "C-x w a") 'repeat-tests-call-a)
-    (define-key map (kbd "M-C-a") 'repeat-tests-call-a)
-    (define-key map (kbd "M-C-z") 'repeat-tests-call-a)
-    map)
-  "Keymap for keys that initiate repeating sequences.")
-
-(defvar repeat-tests-repeat-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "a" 'repeat-tests-call-a)
-    (define-key map "b" 'repeat-tests-call-b)
-    map)
-  "Keymap for repeating sequences.")
+(defvar-keymap repeat-tests-map
+  :doc "Keymap for keys that initiate repeating sequences."
+  "C-x w a" 'repeat-tests-call-a
+  "C-M-a"   'repeat-tests-call-a
+  "C-M-z"   'repeat-tests-call-a)
+
+(defvar-keymap repeat-tests-repeat-map
+  :doc "Keymap for repeating sequences."
+  "a" 'repeat-tests-call-a
+  "b" 'repeat-tests-call-b)
 (put 'repeat-tests-call-a 'repeat-map 'repeat-tests-repeat-map)
 (put 'repeat-tests-call-b 'repeat-map repeat-tests-repeat-map)
 
index bee48351e150cb8e84414f233851a56c794c3b01..71fd97242955cea11ed4bbd64f66f2126bb657aa 100644 (file)
@@ -276,15 +276,11 @@ commit 86c19714b097aa477d339ed99ffb5136c755a046."
     (should (equal (where-is-internal 'foo map t) [?y]))
     (should (equal (where-is-internal 'bar map t) [?y]))))
 
-(defvar keymap-tests-minor-mode-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "x" 'keymap-tests--command-2)
-    map))
+(defvar-keymap keymap-tests-minor-mode-map
+  "x" 'keymap-tests--command-2)
 
-(defvar keymap-tests-major-mode-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "x" 'keymap-tests--command-1)
-    map))
+(defvar-keymap keymap-tests-major-mode-map
+  "x" 'keymap-tests--command-1)
 
 (define-minor-mode keymap-tests-minor-mode "Test.")