aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEli Zaretskii2023-02-18 10:45:12 +0200
committerEli Zaretskii2023-02-18 10:45:12 +0200
commitdeef41a82590658455bfd6468b2811147dd5f845 (patch)
tree8ebace3e64469f6e15f6f09ac5fd74858c32cef9 /test
parent5093a5349603390666681966442a21382287b4bd (diff)
downloademacs-deef41a82590658455bfd6468b2811147dd5f845.tar.gz
emacs-deef41a82590658455bfd6468b2811147dd5f845.zip
Fix hi-lock-tests when 'use-dialog-box' is non-nil
* test/lisp/hi-lock-tests.el (hi-lock-case-fold) (hi-lock-unhighlight): Bind 'use-dialog-box' to nil.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/hi-lock-tests.el143
1 files changed, 79 insertions, 64 deletions
diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el
index aeb08ecbb29..794a3b1d0c2 100644
--- a/test/lisp/hi-lock-tests.el
+++ b/test/lisp/hi-lock-tests.el
@@ -86,13 +86,18 @@
86 (unhighlight-regexp "a a") 86 (unhighlight-regexp "a a")
87 (should (= (length (overlays-in (point-min) (point-max))) 0)) 87 (should (= (length (overlays-in (point-min) (point-max))) 0))
88 88
89 (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) 89 (let ((search-spaces-regexp search-whitespace-regexp))
90 (highlight-regexp "a a"))
90 (should (= (length (overlays-in (point-min) (point-max))) 1)) 91 (should (= (length (overlays-in (point-min) (point-max))) 1))
91 (cl-letf (((symbol-function 'completing-read) 92 ;; We bind use-dialog-box to nil to prevent unhighlight-regexp
92 (lambda (_prompt _coll 93 ;; from using popup menus, since the replacement for
93 &optional _x _y _z _hist defaults _inherit) 94 ;; completing-read below is not ready for that calamity
94 (car defaults)))) 95 (let ((use-dialog-box nil))
95 (call-interactively 'unhighlight-regexp)) 96 (cl-letf (((symbol-function 'completing-read)
97 (lambda (_prompt _coll
98 &optional _x _y _z _hist defaults _inherit)
99 (car defaults))))
100 (call-interactively 'unhighlight-regexp)))
96 (should (= (length (overlays-in (point-min) (point-max))) 0)) 101 (should (= (length (overlays-in (point-min) (point-max))) 0))
97 102
98 (emacs-lisp-mode) 103 (emacs-lisp-mode)
@@ -142,12 +147,16 @@
142 (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) 147 (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a"))
143 (font-lock-ensure) 148 (font-lock-ensure)
144 (should (memq 'hi-yellow (get-text-property 1 'face))) 149 (should (memq 'hi-yellow (get-text-property 1 'face)))
145 (cl-letf (((symbol-function 'completing-read) 150 ;; We bind use-dialog-box to nil to prevent unhighlight-regexp
146 (lambda (_prompt _coll 151 ;; from using popup menus, since the replacement for
147 &optional _x _y _z _hist defaults _inherit) 152 ;; completing-read below is not ready for that calamity
148 (car defaults))) 153 (let ((use-dialog-box nil))
149 (font-lock-fontified t)) 154 (cl-letf (((symbol-function 'completing-read)
150 (call-interactively 'unhighlight-regexp)) 155 (lambda (_prompt _coll
156 &optional _x _y _z _hist defaults _inherit)
157 (car defaults)))
158 (font-lock-fontified t))
159 (call-interactively 'unhighlight-regexp)))
151 (should (null (get-text-property 1 'face)))))) 160 (should (null (get-text-property 1 'face))))))
152 161
153(ert-deftest hi-lock-unhighlight () 162(ert-deftest hi-lock-unhighlight ()
@@ -156,58 +165,64 @@
156 (with-temp-buffer 165 (with-temp-buffer
157 (insert "aAbB\n") 166 (insert "aAbB\n")
158 167
159 (cl-letf (((symbol-function 'completing-read) 168 ;; We bind use-dialog-box to nil to prevent unhighlight-regexp
160 (lambda (_prompt _coll 169 ;; from using popup menus, since the replacement for
161 &optional _x _y _z _hist defaults _inherit) 170 ;; completing-read below is not ready for that calamity
162 (car defaults)))) 171 (let ((use-dialog-box nil))
163 172 (cl-letf (((symbol-function 'completing-read)
164 (highlight-regexp "a") 173 (lambda (_prompt _coll
165 (highlight-regexp "b") 174 &optional _x _y _z _hist defaults _inherit)
166 (should (= (length (overlays-in (point-min) (point-max))) 4)) 175 (car defaults))))
167 ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, 176 (highlight-regexp "a")
168 ;; not the last regexp "b" 177 (highlight-regexp "b")
169 (goto-char 1) 178 (should (= (length (overlays-in (point-min) (point-max))) 4))
170 (call-interactively 'unhighlight-regexp) 179 ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1,
171 (should (= (length (overlays-in 1 3)) 0)) 180 ;; not the last regexp "b"
172 (should (= (length (overlays-in 3 5)) 2)) 181 (goto-char 1)
173 ;; Next call should unhighlight remaining regepxs 182 (call-interactively 'unhighlight-regexp)
174 (call-interactively 'unhighlight-regexp) 183 (should (= (length (overlays-in 1 3)) 0))
175 (should (= (length (overlays-in 3 5)) 0)) 184 (should (= (length (overlays-in 3 5)) 2))
176 185 ;; Next call should unhighlight remaining regepxs
177 ;; Test unhighlight all 186 (call-interactively 'unhighlight-regexp)
178 (highlight-regexp "a") 187 (should (= (length (overlays-in 3 5)) 0))
179 (highlight-regexp "b") 188
180 (should (= (length (overlays-in (point-min) (point-max))) 4)) 189 ;; Test unhighlight all
181 (unhighlight-regexp t) 190 (highlight-regexp "a")
182 (should (= (length (overlays-in (point-min) (point-max))) 0)) 191 (highlight-regexp "b")
183 192 (should (= (length (overlays-in (point-min) (point-max))) 4))
184 (emacs-lisp-mode) 193 (unhighlight-regexp t)
185 (setq font-lock-mode t) 194 (should (= (length (overlays-in (point-min) (point-max))) 0))
186 195
187 (highlight-regexp "a") 196 (emacs-lisp-mode)
188 (highlight-regexp "b") 197 (setq font-lock-mode t)
189 (font-lock-ensure) 198
190 (should (memq 'hi-yellow (get-text-property 1 'face))) 199 (highlight-regexp "a")
191 (should (memq 'hi-yellow (get-text-property 3 'face))) 200 (highlight-regexp "b")
192 ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, 201 (font-lock-ensure)
193 ;; not the last regexp "b" 202 (should (memq 'hi-yellow (get-text-property 1 'face)))
194 (goto-char 1) 203 (should (memq 'hi-yellow (get-text-property 3 'face)))
195 (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) 204 ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1,
196 (should (null (get-text-property 1 'face))) 205 ;; not the last regexp "b"
197 (should (memq 'hi-yellow (get-text-property 3 'face))) 206 (goto-char 1)
198 ;; Next call should unhighlight remaining regepxs 207 (let ((font-lock-fontified t))
199 (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) 208 (call-interactively 'unhighlight-regexp))
200 (should (null (get-text-property 3 'face))) 209 (should (null (get-text-property 1 'face)))
201 210 (should (memq 'hi-yellow (get-text-property 3 'face)))
202 ;; Test unhighlight all 211 ;; Next call should unhighlight remaining regepxs
203 (highlight-regexp "a") 212 (let ((font-lock-fontified t))
204 (highlight-regexp "b") 213 (call-interactively 'unhighlight-regexp))
205 (font-lock-ensure) 214 (should (null (get-text-property 3 'face)))
206 (should (memq 'hi-yellow (get-text-property 1 'face))) 215
207 (should (memq 'hi-yellow (get-text-property 3 'face))) 216 ;; Test unhighlight all
208 (let ((font-lock-fontified t)) (unhighlight-regexp t)) 217 (highlight-regexp "a")
209 (should (null (get-text-property 1 'face))) 218 (highlight-regexp "b")
210 (should (null (get-text-property 3 'face))))))) 219 (font-lock-ensure)
220 (should (memq 'hi-yellow (get-text-property 1 'face)))
221 (should (memq 'hi-yellow (get-text-property 3 'face)))
222 (let ((font-lock-fontified t))
223 (unhighlight-regexp t))
224 (should (null (get-text-property 1 'face)))
225 (should (null (get-text-property 3 'face))))))))
211 226
212(provide 'hi-lock-tests) 227(provide 'hi-lock-tests)
213;;; hi-lock-tests.el ends here 228;;; hi-lock-tests.el ends here