aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJustin Talbott2019-06-20 11:27:46 -0400
committerJustin Talbott2019-06-20 11:48:55 -0400
commit0d720a0f618fe2edfd7e7c547f422ae1d8b831c7 (patch)
tree0d663aa9d3bc78482b9f9c96c5b5d5ab58b1ccc2 /test
parent97f0287e1968d3ccd802fe52a4dbca707babd7fa (diff)
downloademacs-0d720a0f618fe2edfd7e7c547f422ae1d8b831c7.tar.gz
emacs-0d720a0f618fe2edfd7e7c547f422ae1d8b831c7.zip
update bind-chords to use of eval-after-load when maps declared
also improve :chord keyword syntax processing to more closely mimic bind-keys since the same binding normalizer is used. also add tests for use-package-chords to cover these test cases
Diffstat (limited to 'test')
-rw-r--r--test/lisp/use-package/use-package-chords-tests.el161
1 files changed, 161 insertions, 0 deletions
diff --git a/test/lisp/use-package/use-package-chords-tests.el b/test/lisp/use-package/use-package-chords-tests.el
new file mode 100644
index 00000000000..3c3dc4b4fe0
--- /dev/null
+++ b/test/lisp/use-package/use-package-chords-tests.el
@@ -0,0 +1,161 @@
1;;; use-package-chords-tests.el --- Tests for use-package-chords.el -*- lexical-binding: t; -*-
2
3;; This program is free software; you can redistribute it and/or
4;; modify it under the terms of the GNU General Public License as
5;; published by the Free Software Foundation; either version 3, or (at
6;; your option) any later version.
7
8;; This program is distributed in the hope that it will be useful, but
9;; WITHOUT ANY WARRANTY; without even the implied warranty of
10;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11;; General Public License for more details.
12
13;; You should have received a copy of the GNU General Public License
14;; along with GNU Emacs; see the file COPYING. If not, write to the
15;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16;; Boston, MA 02111-1307, USA.
17
18;;; Commentary:
19
20;;
21
22
23;;; Code:
24
25(require 'use-package)
26(require 'use-package-tests)
27(require 'use-package-chords)
28
29(defmacro match-expansion (form &rest value)
30 `(should (pcase (expand-minimally ,form)
31 ,@(mapcar #'(lambda (x) (list x t)) value))))
32
33(defun use-package-test-normalize-chord (&rest args)
34 (apply #'use-package-normalize-binder 'foo :chords args))
35
36(ert-deftest use-package-test-normalize/:chords-1 ()
37 (should (equal (use-package-test-normalize-chord
38 '(("C-a" . alpha)))
39 '(("C-a" . alpha)))))
40
41(ert-deftest use-package-test-normalize/:chords-2 ()
42 (should (equal (use-package-test-normalize-chord
43 '(("C-a" . alpha)
44 :map foo-map
45 ("C-b" . beta)))
46 '(("C-a" . alpha)
47 :map foo-map
48 ("C-b" . beta)))))
49
50(ert-deftest use-package-test-normalize/:chords-3 ()
51 (should (equal (use-package-test-normalize-chord
52 '(:map foo-map
53 ("C-a" . alpha)
54 ("C-b" . beta)))
55 '(:map foo-map
56 ("C-a" . alpha)
57 ("C-b" . beta)))))
58
59(ert-deftest use-package-test/:chords-1 ()
60 (match-expansion
61 (use-package foo :chords ("C-k" . key1) ("C-u" . key2))
62 `(progn
63 (unless
64 (fboundp 'key1)
65 (autoload #'key1 "foo" nil t))
66 (unless
67 (fboundp 'key2)
68 (autoload #'key2 "foo" nil t))
69 (bind-chord "C-k" #'key1 nil)
70 (bind-chord "C-u" #'key2 nil))))
71
72(ert-deftest use-package-test/:chords-2 ()
73 (match-expansion
74 (use-package foo :chords (("C-k" . key1) ("C-u" . key2)))
75 `(progn
76 (unless (fboundp 'key1)
77 (autoload #'key1 "foo" nil t))
78 (unless (fboundp 'key2)
79 (autoload #'key2 "foo" nil t))
80 (bind-chord "C-k" #'key1 nil)
81 (bind-chord "C-u" #'key2 nil))))
82
83(ert-deftest use-package-test/:chords-3 ()
84 (match-expansion
85 (use-package foo :chords (:map my-map ("C-k" . key1) ("C-u" . key2)))
86 `(progn
87 (unless
88 (fboundp 'key1)
89 (autoload #'key1 "foo" nil t))
90 (unless
91 (fboundp 'key2)
92 (autoload #'key2 "foo" nil t))
93 (if
94 (boundp 'my-map)
95 (progn
96 (bind-chord "C-k" #'key1 my-map)
97 (bind-chord "C-u" #'key2 my-map))
98 (eval-after-load 'foo
99 '(progn
100 (bind-chord "C-k" #'key1 my-map)
101 (bind-chord "C-u" #'key2 my-map)))))))
102
103(ert-deftest use-package-test/:chords-4 ()
104 (should-error
105 (match-expansion
106 (use-package foo :chords :map my-map ("C-k" . key1) ("C-u" . key2))
107 `(bind-chords :package foo))))
108
109(ert-deftest use-package-test/:chords-5 ()
110 (match-expansion
111 (use-package foo :chords ("C-k" . key1) (:map my-map ("C-u" . key2)))
112 `(progn
113 (unless (fboundp 'key1)
114 (autoload #'key1 "foo" nil t))
115 (unless (fboundp 'key2)
116 (autoload #'key2 "foo" nil t))
117 (progn
118 (bind-chord "C-k" #'key1 nil)
119 (if
120 (boundp 'my-map)
121 (bind-chord "C-u" #'key2 my-map)
122 (eval-after-load 'foo
123 '(bind-chord "C-u" #'key2 my-map)))))))
124
125(ert-deftest use-package-test/:chords-6 ()
126 (match-expansion
127 (use-package foo
128 :chords
129 ("C-k" . key1)
130 (:map my-map ("C-u" . key2))
131 (:map my-map2 ("C-u" . key3)))
132 `(progn
133 (unless
134 (fboundp 'key1)
135 (autoload #'key1 "foo" nil t))
136 (unless
137 (fboundp 'key2)
138 (autoload #'key2 "foo" nil t))
139 (unless
140 (fboundp 'key3)
141 (autoload #'key3 "foo" nil t))
142 (progn
143 (bind-chord "C-k" #'key1 nil)
144 (if
145 (boundp 'my-map)
146 (bind-chord "C-u" #'key2 my-map)
147 (eval-after-load 'foo
148 '(bind-chord "C-u" #'key2 my-map)))
149 (if
150 (boundp 'my-map2)
151 (bind-chord "C-u" #'key3 my-map2)
152 (eval-after-load 'foo
153 '(bind-chord "C-u" #'key3 my-map2)))))))
154
155;; Local Variables:
156;; indent-tabs-mode: nil
157;; no-byte-compile: t
158;; no-update-autoloads: t
159;; End:
160
161;;; use-package-tests.el ends here