[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 05654c33ac: compat-29: Add tests for keymap-look
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 05654c33ac: compat-29: Add tests for keymap-lookup functions |
Date: |
Fri, 13 Jan 2023 03:57:26 -0500 (EST) |
branch: externals/compat
commit 05654c33acb16dcfdf1da0d2fd5d5763907bc2a1
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
compat-29: Add tests for keymap-lookup functions
---
compat-29.el | 6 +++---
compat-tests.el | 45 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/compat-29.el b/compat-29.el
index 819988b3a9..d44a5ec674 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 854903cd72..3773e1da50 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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/compat 05654c33ac: compat-29: Add tests for keymap-lookup functions,
ELPA Syncer <=