aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSimen Heggestøyl2020-05-09 19:58:46 +0200
committerSimen Heggestøyl2020-05-09 20:01:37 +0200
commit9d8fc3a598090da518fcdd5c0503ed0f7faa41a9 (patch)
tree05dc66186dba5bf6e954552d60d4947bfa67d641 /test
parent94224c4addc999ad798cc690051498bcce199555 (diff)
downloademacs-9d8fc3a598090da518fcdd5c0503ed0f7faa41a9.tar.gz
emacs-9d8fc3a598090da518fcdd5c0503ed0f7faa41a9.zip
Use lexical-binding in help-mode.el and add tests
* lisp/help-mode.el: Use lexical-binding. (help-mode-map, help-mode-menu, help-mode-setup) (help-mode-finish): Make spelling of "Help mode" consistent throughout the doc strings (also making it consistent with the spelling of "Help mode" used in the Elisp manual). (help-do-xref): Re-indent to make the else-branch easier to see. * test/lisp/help-mode-tests.el: New file with tests for help-mode.el.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/help-mode-tests.el169
1 files changed, 169 insertions, 0 deletions
diff --git a/test/lisp/help-mode-tests.el b/test/lisp/help-mode-tests.el
new file mode 100644
index 00000000000..2b9552a8d81
--- /dev/null
+++ b/test/lisp/help-mode-tests.el
@@ -0,0 +1,169 @@
1;;; help-mode-tests.el --- Tests for help-mode.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; Author: Simen Heggestøyl <simenheg@gmail.com>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'ert)
30(require 'help-mode)
31(require 'pp)
32
33(ert-deftest help-mode-tests-help-buffer ()
34 (let ((help-xref-following nil))
35 (should (equal "*Help*" (help-buffer)))))
36
37(ert-deftest help-mode-tests-help-buffer-current-buffer ()
38 (with-temp-buffer
39 (help-mode)
40 (let ((help-xref-following t))
41 (should (equal (buffer-name (current-buffer))
42 (help-buffer))))))
43
44(ert-deftest help-mode-tests-help-buffer-current-buffer-error ()
45 (with-temp-buffer
46 (let ((help-xref-following t))
47 (should-error (help-buffer)))))
48
49(ert-deftest help-mode-tests-make-xrefs ()
50 (with-temp-buffer
51 (insert "car is a built-in function in ‘C source code’.
52
53(car LIST)
54
55 Probably introduced at or before Emacs version 1.2.
56 This function does not change global state, including the match data.
57
58Return the car of LIST. If arg is nil, return nil.
59Error if arg is not nil and not a cons cell. See also ‘car-safe’.
60
61See Info node ‘(elisp)Cons Cells’ for a discussion of related basic
62Lisp concepts such as car, cdr, cons cell and list.")
63 (help-mode)
64 (help-make-xrefs)
65 (let ((car-safe-button (button-at 298)))
66 (should (eq (button-type car-safe-button) 'help-symbol))
67 (should (eq (button-get car-safe-button 'help-function)
68 #'describe-symbol)))
69 (let ((cons-cells-info-button (button-at 333)))
70 (should (eq (button-type cons-cells-info-button) 'help-info))
71 (should (eq (button-get cons-cells-info-button 'help-function)
72 #'info)))))
73
74(ert-deftest help-mode-tests-xref-button ()
75 (with-temp-buffer
76 (insert "See also the function ‘interactive’.")
77 (string-match help-xref-symbol-regexp (buffer-string))
78 (help-xref-button 8 'help-function)
79 (should-not (button-at 22))
80 (should-not (button-at 35))
81 (let ((button (button-at 30)))
82 (should (eq (button-type button) 'help-function)))))
83
84(ert-deftest help-mode-tests-insert-xref-button ()
85 (with-temp-buffer
86 (help-insert-xref-button "[back]" 'help-back)
87 (goto-char (point-min))
88 (should (eq (button-type (button-at (point))) 'help-back))
89 (help-insert-xref-button "[forward]" 'help-forward)
90 ;; The back button should stay unchanged.
91 (should (eq (button-type (button-at (point))) 'help-back))))
92
93(ert-deftest help-mode-tests-xref-on-pp ()
94 (with-temp-buffer
95 (insert (pp '(cons fill-column)))
96 (help-xref-on-pp (point-min) (point-max))
97 (goto-char (point-min))
98 (search-forward "co")
99 (should (eq (button-type (button-at (point))) 'help-function))
100 (search-forward "-")
101 (should (eq (button-type (button-at (point))) 'help-variable))))
102
103(ert-deftest help-mode-tests-xref-go-back ()
104 (let ((help-xref-stack
105 `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
106 (with-temp-buffer
107 (insert "foo")
108 (help-xref-go-back (current-buffer))
109 (should (= (point) 2))
110 (should (equal (buffer-string) "bar")))))
111
112(ert-deftest help-mode-tests-xref-go-forward ()
113 (let ((help-xref-forward-stack
114 `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
115 (with-temp-buffer
116 (insert "foo")
117 (help-xref-go-forward (current-buffer))
118 (should (= (point) 2))
119 (should (equal (buffer-string) "bar")))))
120
121(ert-deftest help-mode-tests-go-back ()
122 (let ((help-xref-stack
123 `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
124 (with-temp-buffer
125 (insert "foo")
126 (help-go-back)
127 (should (= (point) 2))
128 (should (equal (buffer-string) "bar")))))
129
130(ert-deftest help-mode-tests-go-back-no-stack ()
131 (let ((help-xref-stack '()))
132 (should-error (help-go-back))))
133
134(ert-deftest help-mode-tests-go-forward ()
135 (let ((help-xref-forward-stack
136 `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
137 (with-temp-buffer
138 (insert "foo")
139 (help-go-forward)
140 (should (= (point) 2))
141 (should (equal (buffer-string) "bar")))))
142
143(ert-deftest help-mode-tests-go-forward-no-stack ()
144 (let ((help-xref-forward-stack '()))
145 (should-error (help-go-forward))))
146
147(ert-deftest help-mode-tests-do-xref ()
148 (with-temp-buffer
149 (help-mode)
150 (help-do-xref 0 #'describe-symbol '(car))
151 (should (looking-at-p "car is a"))
152 (should (string-match-p "[back]" (buffer-string)))))
153
154(ert-deftest help-mode-tests-follow-symbol ()
155 (with-temp-buffer
156 (insert "car")
157 (help-mode)
158 (help-follow-symbol 0)
159 (should (looking-at-p "car is a"))
160 (should (string-match-p "[back]" (buffer-string)))))
161
162(ert-deftest help-mode-tests-follow-symbol-no-symbol ()
163 (with-temp-buffer
164 (insert "fXYEWnRHI0B9w6VJqQIw")
165 (help-mode)
166 (should-error (help-follow-symbol 0))))
167
168(provide 'help-mode-tests)
169;;; help-mode-tests.el ends here