emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d4353da0ad: Use defvar-keymap in tests


From: Stefan Kangas
Subject: master d4353da0ad: Use defvar-keymap in tests
Date: Sun, 26 Dec 2021 15:55:13 -0500 (EST)

branch: master
commit d4353da0ad969a492c75bae130aed33ab204ed32
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Use defvar-keymap in tests
    
    * 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            |  8 +++---
 test/lisp/emacs-lisp/edebug-tests.el | 30 +++++++++++-----------
 test/lisp/help-tests.el              | 49 +++++++++++++++++-------------------
 test/lisp/kmacro-tests.el            | 49 +++++++++++++++++-------------------
 test/lisp/repeat-tests.el            | 24 ++++++++----------
 test/src/keymap-tests.el             | 12 +++------
 6 files changed, 77 insertions(+), 95 deletions(-)

diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el
index 2f5ad795df..a88387e025 100644
--- a/test/lisp/button-tests.el
+++ b/test/lisp/button-tests.el
@@ -21,11 +21,9 @@
 
 (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."
diff --git a/test/lisp/emacs-lisp/edebug-tests.el 
b/test/lisp/emacs-lisp/edebug-tests.el
index 210bf24880..3ab5ac6a9a 100644
--- a/test/lisp/emacs-lisp/edebug-tests.el
+++ b/test/lisp/emacs-lisp/edebug-tests.el
@@ -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:
 
diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el
index a1ae838239..65b329c1cd 100644
--- a/test/lisp/help-tests.el
+++ b/test/lisp/help-tests.el
@@ -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.")
diff --git a/test/lisp/kmacro-tests.el b/test/lisp/kmacro-tests.el
index ecd3d5fc22..49b4093538 100644
--- a/test/lisp/kmacro-tests.el
+++ b/test/lisp/kmacro-tests.el
@@ -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.")
diff --git a/test/lisp/repeat-tests.el b/test/lisp/repeat-tests.el
index 02d9ddbc96..84a4d722a8 100644
--- a/test/lisp/repeat-tests.el
+++ b/test/lisp/repeat-tests.el
@@ -34,20 +34,16 @@
   (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)
 
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el
index bee48351e1..71fd972429 100644
--- a/test/src/keymap-tests.el
+++ b/test/src/keymap-tests.el
@@ -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.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]