blob: 1ae0d3d2c3426eac4af3277bc7c7acb461629b0e (
plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
;;; test-pearl-keymap.el --- Tests for the prefix keymap and minor mode -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Craig Jennings
;; Author: Craig Jennings <c@cjennings.net>
;; 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 `pearl-prefix-map' and `pearl-mode'. Hot-path commands bind
;; directly under the prefix; the rest live in category sub-maps (fetch / edit
;; / new / delete / url). The common commands appear in both places.
;; `pearl-mode' makes the map live inside Pearl buffers under
;; `pearl-keymap-prefix'.
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
(defun test-pearl-keymap--label-of (map command)
"Return the menu-item label bound to COMMAND in MAP, or nil.
Walks MAP looking for a labeled binding (\"label\" . COMMAND)."
(let (found)
(map-keymap
(lambda (_ev binding)
(when (and (consp binding) (stringp (car binding))
(eq (cdr binding) command))
(setq found (car binding))))
map)
found))
(ert-deftest test-pearl-prefix-map-is-a-keymap ()
"`pearl-prefix-map' is defined as a keymap."
(should (keymapp pearl-prefix-map)))
(ert-deftest test-pearl-prefix-map-direct-hot-keys ()
"The hot-path commands resolve in one key under the prefix.
The lowercase `c' is no longer a direct command -- it is the create prefix."
(should (eq 'pearl-list-issues (lookup-key pearl-prefix-map (kbd "l"))))
(should (eq 'pearl-refresh-current-view (lookup-key pearl-prefix-map (kbd "g"))))
(should (eq 'pearl-refresh-current-issue (lookup-key pearl-prefix-map (kbd "r"))))
(should (eq 'pearl-save-issue (lookup-key pearl-prefix-map (kbd "s"))))
(should (eq 'pearl-save-all (lookup-key pearl-prefix-map (kbd "S"))))
(should (eq 'pearl-edit-description (lookup-key pearl-prefix-map (kbd "d"))))
(should (eq 'pearl-menu (lookup-key pearl-prefix-map (kbd "m")))))
(ert-deftest test-pearl-prefix-map-sub-prefixes-are-verbs ()
"Each category key is a sub-prefix keymap named for an action verb."
(should (keymapp (lookup-key pearl-prefix-map (kbd "f")))) ; fetch
(should (keymapp (lookup-key pearl-prefix-map (kbd "e")))) ; edit
(should (keymapp (lookup-key pearl-prefix-map (kbd "c")))) ; create
(should (keymapp (lookup-key pearl-prefix-map (kbd "k")))) ; delete
(should (keymapp (lookup-key pearl-prefix-map (kbd "o")))) ; open
(should (keymapp (lookup-key pearl-prefix-map (kbd "y"))))) ; copy
(ert-deftest test-pearl-prefix-map-fetch-group ()
"The fetch group resolves each source command, including the unified pick-source."
(should (eq 'pearl-pick-source (lookup-key pearl-prefix-map (kbd "f s"))))
(should (eq 'pearl-list-issues (lookup-key pearl-prefix-map (kbd "f o"))))
(should (eq 'pearl-list-issues-by-project (lookup-key pearl-prefix-map (kbd "f p"))))
(should (eq 'pearl-list-issues-filtered (lookup-key pearl-prefix-map (kbd "f f"))))
(should (eq 'pearl-run-view (lookup-key pearl-prefix-map (kbd "f v"))))
(should (eq 'pearl-run-saved-query (lookup-key pearl-prefix-map (kbd "f q"))))
(should (eq 'pearl-sync-saved-query-to-linear
(lookup-key pearl-prefix-map (kbd "f S"))))
(should (eq 'pearl-publish-current-source
(lookup-key pearl-prefix-map (kbd "f P")))))
(ert-deftest test-pearl-prefix-map-edit-group ()
"The edit group resolves each field-edit command."
(should (eq 'pearl-edit-description (lookup-key pearl-prefix-map (kbd "e d"))))
(should (eq 'pearl-edit-state (lookup-key pearl-prefix-map (kbd "e s"))))
(should (eq 'pearl-edit-assignee (lookup-key pearl-prefix-map (kbd "e a"))))
(should (eq 'pearl-edit-labels (lookup-key pearl-prefix-map (kbd "e l"))))
(should (eq 'pearl-edit-current-comment (lookup-key pearl-prefix-map (kbd "e c"))))
;; priority has no edit command (org-native cookie); e p is unbound
(should-not (lookup-key pearl-prefix-map (kbd "e p"))))
(ert-deftest test-pearl-prefix-map-create-and-delete-groups ()
"Create and delete groups resolve issue/comment under c and k."
(should (eq 'pearl-create-issue (lookup-key pearl-prefix-map (kbd "c t"))))
(should (eq 'pearl-create-comment (lookup-key pearl-prefix-map (kbd "c c"))))
(should (eq 'pearl-delete-current-issue (lookup-key pearl-prefix-map (kbd "k t"))))
(should (eq 'pearl-delete-current-comment (lookup-key pearl-prefix-map (kbd "k c"))))
(should (eq 'pearl-delete-saved-query (lookup-key pearl-prefix-map (kbd "k q")))))
(ert-deftest test-pearl-prefix-map-open-and-copy-groups ()
"The open group resolves the two open actions; copy resolves copy-url."
(should (eq 'pearl-open-current-issue (lookup-key pearl-prefix-map (kbd "o i"))))
(should (eq 'pearl-open-current-view-in-linear (lookup-key pearl-prefix-map (kbd "o v"))))
(should (eq 'pearl-copy-issue-url (lookup-key pearl-prefix-map (kbd "y u")))))
(ert-deftest test-pearl-prefix-map-common-commands-bound-twice ()
"The most common commands resolve both directly and inside their group."
;; edit-description: direct d and e d
(should (eq (lookup-key pearl-prefix-map (kbd "d"))
(lookup-key pearl-prefix-map (kbd "e d"))))
;; list issues: direct l and f o
(should (eq (lookup-key pearl-prefix-map (kbd "l"))
(lookup-key pearl-prefix-map (kbd "f o")))))
(ert-deftest test-pearl-prefix-map-which-key-labels ()
"Leaf bindings carry verb labels; sub-prefixes carry +labels."
(should (string= "edit state"
(test-pearl-keymap--label-of pearl-edit-map 'pearl-edit-state)))
(should (string= "create issue"
(test-pearl-keymap--label-of pearl-create-map 'pearl-create-issue)))
(should (string= "open issue in browser"
(test-pearl-keymap--label-of pearl-open-map 'pearl-open-current-issue)))
(should (string= "copy issue URL"
(test-pearl-keymap--label-of pearl-copy-map 'pearl-copy-issue-url)))
(should (string= "+edit" (test-pearl-keymap--label-of pearl-prefix-map pearl-edit-map)))
(should (string= "+open" (test-pearl-keymap--label-of pearl-prefix-map pearl-open-map))))
(ert-deftest test-pearl-prefix-map-not-bound-at-load ()
"Loading pearl binds nothing globally; the keys are live only via pearl-mode."
(should-not (where-is-internal 'pearl-save-issue (current-global-map)))
(should-not (where-is-internal 'pearl-list-issues (current-global-map))))
;;; minor mode
(ert-deftest test-pearl-mode-is-a-minor-mode ()
"`pearl-mode' is defined as a command."
(should (fboundp 'pearl-mode))
(should (commandp 'pearl-mode)))
(ert-deftest test-pearl-mode-map-binds-the-prefix ()
"`pearl-mode-map' binds `pearl-keymap-prefix' to the command map."
(should (eq pearl-prefix-map
(lookup-key pearl-mode-map (kbd pearl-keymap-prefix)))))
(ert-deftest test-pearl-buffer-is-pearl-p-detects-source-header ()
"A buffer with a #+LINEAR-SOURCE header reads as a Pearl buffer; one without does not."
(with-temp-buffer
(insert "#+title: x\n#+LINEAR-SOURCE: (:type filter)\n")
(should (pearl--buffer-is-pearl-p)))
(with-temp-buffer
(insert "#+title: notes\n* a heading\n")
(should-not (pearl--buffer-is-pearl-p))))
(ert-deftest test-pearl-maybe-enable-mode-only-in-pearl-org-buffers ()
"`pearl--maybe-enable-mode' turns the mode on in a Pearl org buffer, not elsewhere."
;; Pearl org buffer -> enabled. `delay-mode-hooks' keeps `org-mode-hook'
;; (which itself carries the auto-enable) from firing, so the explicit call
;; is what flips the mode.
(with-temp-buffer
(delay-mode-hooks (org-mode))
(insert "#+title: x\n#+LINEAR-SOURCE: (:type filter)\n")
(pearl--maybe-enable-mode)
(should pearl-mode))
;; Plain org buffer -> left off.
(with-temp-buffer
(delay-mode-hooks (org-mode))
(insert "#+title: notes\n* a heading\n")
(pearl--maybe-enable-mode)
(should-not pearl-mode))
;; Non-org buffer with the header -> left off (org-mode gate).
(with-temp-buffer
(fundamental-mode)
(insert "#+LINEAR-SOURCE: (:type filter)\n")
(pearl--maybe-enable-mode)
(should-not pearl-mode)))
(provide 'test-pearl-keymap)
;;; test-pearl-keymap.el ends here
|