This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathwhich-key-tests.el
101 lines (89 loc) · 3.62 KB
/
which-key-tests.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; which-key-tests.el --- Tests for which-key.el -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Justin Burkett
;; Author: Justin Burkett <[email protected]>
;; URL: https://github.com/justbur/emacs-which-key
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Tests for which-key.el
;;; Code:
(require 'which-key)
(require 'ert)
(ert-deftest which-key-test-prefix-declaration ()
"Test `which-key-declare-prefixes' and
`which-key-declare-prefixes-for-mode'. See Bug #109."
(let* ((major-mode 'test-mode)
which-key-replacement-alist)
(which-key-add-key-based-replacements
"SPC C-c" '("complete" . "complete title")
"SPC C-k" "cancel")
(which-key-add-major-mode-key-based-replacements 'test-mode
"C-c C-c" '("complete" . "complete title")
"C-c C-k" "cancel")
(should (equal
(which-key--maybe-replace '("SPC C-k" . ""))
'("SPC C-k" . "cancel")))
(should (equal
(which-key--maybe-replace '("C-c C-c" . ""))
'("C-c C-c" . "complete")))))
(ert-deftest which-key-test--maybe-replace ()
"Test `which-key--maybe-replace'. See #154"
(let ((which-key-replacement-alist
'((("C-c [a-d]" . nil) . ("C-c a" . "c-c a"))
(("C-c .+" . nil) . ("C-c *" . "c-c *"))))
(test-mode-1 t)
(test-mode-2 nil))
(which-key-add-key-based-replacements
"C-c ." "test ."
"SPC ." "SPC ."
"C-c \\" "regexp quoting"
"C-c [" "bad regexp"
"SPC t1" (lambda (kb)
(cons (car kb)
(if test-mode-1
"[x] test mode"
"[ ] test mode")))
"SPC t2" (lambda (kb)
(cons (car kb)
(if test-mode-2
"[x] test mode"
"[ ] test mode"))))
(should (equal
(which-key--maybe-replace '("C-c g" . "test"))
'("C-c *" . "c-c *")))
(should (equal
(which-key--maybe-replace '("C-c b" . "test"))
'("C-c a" . "c-c a")))
(should (equal
(which-key--maybe-replace '("C-c ." . "not test ."))
'("C-c ." . "test .")))
(should (not
(equal
(which-key--maybe-replace '("C-c +" . "not test ."))
'("C-c ." . "test ."))))
(should (equal
(which-key--maybe-replace '("C-c [" . "orig bad regexp"))
'("C-c [" . "bad regexp")))
(should (equal
(which-key--maybe-replace '("C-c \\" . "pre quoting"))
'("C-c \\" . "regexp quoting")))
;; see #155
(should (equal
(which-key--maybe-replace '("SPC . ." . "don't replace"))
'("SPC . ." . "don't replace")))
(should (equal
(which-key--maybe-replace '("SPC t 1" . "test mode"))
'("SPC t 1" . "[x] test mode")))
(should (equal
(which-key--maybe-replace '("SPC t 2" . "test mode"))
'("SPC t 2" . "[ ] test mode")))))
(provide 'which-key-tests)
;;; which-key-tests.el ends here