aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-13 09:06:45 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-13 09:06:45 +0100
commit05654c33acb16dcfdf1da0d2fd5d5763907bc2a1 (patch)
tree9a784453794fd62cc87571b520789b080863c856
parent69a69fa23ea01406f8b5b43adf3de885e668cced (diff)
compat-29: Add tests for keymap-lookup functions
-rw-r--r--compat-29.el6
-rw-r--r--compat-tests.el45
2 files changed, 46 insertions, 5 deletions
diff --git a/compat-29.el b/compat-29.el
index 819988b..d44a5ec 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -726,7 +726,7 @@ a menu, so this function is not useful for non-menu keymaps."
(define-key-after keymap (key-parse key) definition
(and after (key-parse after))))
-(compat-defun keymap-lookup ;; <UNTESTED>
+(compat-defun keymap-lookup ;; <OK>
(keymap key &optional accept-default no-remap position)
"Return the binding for command KEY.
KEY is a string that satisfies `key-valid-p'.
@@ -770,7 +770,7 @@ specified buffer position instead of point are used."
value))
(key-binding (kbd key) accept-default no-remap position)))
-(compat-defun keymap-local-lookup (keys &optional accept-default) ;; <UNTESTED>
+(compat-defun keymap-local-lookup (keys &optional accept-default) ;; <OK>
"Return the binding for command KEYS in current local keymap only.
KEY is a string that satisfies `key-valid-p'.
@@ -782,7 +782,7 @@ about this."
(when-let ((map (current-local-map)))
(keymap-lookup map keys accept-default)))
-(compat-defun keymap-global-lookup (keys &optional accept-default _message) ;; <UNTESTED>
+(compat-defun keymap-global-lookup (keys &optional accept-default _message) ;; <OK>
"Return the binding for command KEYS in current global keymap only.
KEY is a string that satisfies `key-valid-p'.
diff --git a/compat-tests.el b/compat-tests.el
index 854903c..3773e1d 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -270,27 +270,39 @@
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-x C-f") #'find-file)
(define-key map (kbd "SPC") #'minibuffer-complete-word)
+ (define-key map (kbd "RET") #'exit-minibuffer)
+ (define-key map [remap exit-minibuffer] #'minibuffer-force-complete-and-exit)
(define-key map (kbd "C-c") mode-specific-map)
(define-key map (kbd "s-c") [?\C-c ?\C-c])
+ (define-key map [t] 'compat-default-command)
map))
(defvar compat-tests--map-2
(let ((map (make-sparse-keymap)))
(keymap-set map "C-x C-f" #'find-file)
(keymap-set map "SPC" #'minibuffer-complete-word)
+ (keymap-set map "RET" #'exit-minibuffer)
+ (keymap-set map "<remap> <exit-minibuffer>" #'minibuffer-force-complete-and-exit)
(keymap-set map "C-c" mode-specific-map)
(keymap-set map "s-c" "C-c C-c")
+ (keymap-set map "<t>" 'compat-default-command)
map))
(defvar-keymap compat-tests--map-3
"C-x C-f" #'find-file
"SPC" #'minibuffer-complete-word
+ "RET" #'exit-minibuffer
+ "<remap> <exit-minibuffer>" #'minibuffer-force-complete-and-exit
"C-c" mode-specific-map
- "s-c" "C-c C-c")
+ "s-c" "C-c C-c"
+ "<t>" 'compat-default-command)
(defvar compat-tests--map-4
(define-keymap
"C-x C-f" #'find-file
"SPC" #'minibuffer-complete-word
+ "RET" #'exit-minibuffer
+ "<remap> <exit-minibuffer>" #'minibuffer-force-complete-and-exit
"C-c" mode-specific-map
- "s-c" "C-c C-c"))
+ "s-c" "C-c C-c"
+ "<t>" 'compat-default-command))
(ert-deftest defvar-keymap ()
(should-equal compat-tests--map-1 compat-tests--map-2)
(should-equal compat-tests--map-1 compat-tests--map-3)
@@ -510,6 +522,35 @@
(should-not (key-valid-p "M-xx"))
(should-not (key-valid-p "M-x<TAB>")))
+(ert-deftest keymap-lookup ()
+ (should-not (keymap-lookup compat-tests--map-1 "C-x b"))
+ (should-equal (keymap-lookup compat-tests--map-1 "C-x C-f") #'find-file)
+ (should-equal (keymap-lookup compat-tests--map-1 "RET") #'exit-minibuffer)
+ (should-equal (keymap-lookup compat-tests--map-1 "C-c") mode-specific-map)
+ (should-equal (keymap-lookup compat-tests--map-1 "s-c") [?\C-c ?\C-c])
+ (should-not (keymap-lookup compat-tests--map-1 "x"))
+ (should-equal (keymap-lookup compat-tests--map-1 "x" t) 'compat-default-command))
+
+(ert-deftest keymap-local-lookup ()
+ (let ((orig (current-local-map)))
+ (unwind-protect
+ (progn
+ (use-local-map compat-tests--map-1)
+ (should-not (keymap-local-lookup "C-x b"))
+ (should-equal (keymap-local-lookup "C-x C-f") #'find-file)
+ (should-equal (keymap-lookup compat-tests--map-1 "RET" nil t) #'exit-minibuffer)
+ (should-equal (keymap-local-lookup "RET") #'minibuffer-force-complete-and-exit)
+ (should-equal (keymap-local-lookup "C-c") mode-specific-map)
+ (should-equal (keymap-local-lookup "s-c") [?\C-c ?\C-c])
+ (should-not (keymap-local-lookup "x"))
+ (should-equal (keymap-local-lookup "x" t) 'compat-default-command))
+ (use-local-map orig))))
+
+(ert-deftest keymap-global-lookup ()
+ (should-equal (keymap-global-lookup "C-x b") #'switch-to-buffer)
+ (should-equal (keymap-global-lookup "C-x C-f") #'find-file)
+ (should-equal (keymap-global-lookup "C-c") #'mode-specific-command-prefix))
+
(defun compat-tests--function-put ())
(ert-deftest function-put ()
(function-put #'compat-tests--function-put 'compat-test 42)