diff options
| author | Juri Linkov | 2020-04-14 02:33:52 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-04-14 02:33:52 +0300 |
| commit | 7a9fb5d55c9bf612a38348d59e769ee915175e28 (patch) | |
| tree | 45b38be9f4d13d8a5a0069d20f940a8410b4350c /test | |
| parent | 086faceb1c395d24487c20bcb32ca710291bee41 (diff) | |
| download | emacs-7a9fb5d55c9bf612a38348d59e769ee915175e28.tar.gz emacs-7a9fb5d55c9bf612a38348d59e769ee915175e28.zip | |
Fix hi-lock test and add new test for unhighlight (bug#40337)
* lisp/hi-lock.el (hi-lock-unface-buffer): Use hi-lock--hashcons
only on strings, not lists.
* test/lisp/hi-lock-tests.el (hi-lock-bug26666): Revert previous change,
use "a" instead of "b".
(hi-lock-unhighlight): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/hi-lock-tests.el | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el index 252caaa2650..59f3e73b17d 100644 --- a/test/lisp/hi-lock-tests.el +++ b/test/lisp/hi-lock-tests.el | |||
| @@ -33,9 +33,7 @@ | |||
| 33 | (car defaults)))) | 33 | (car defaults)))) |
| 34 | (dotimes (_ 2) | 34 | (dotimes (_ 2) |
| 35 | (let ((face (hi-lock-read-face-name))) | 35 | (let ((face (hi-lock-read-face-name))) |
| 36 | ;; This test should use regexp "b" different from "a" | 36 | (hi-lock-set-pattern "a" face)))) |
| 37 | ;; used in another test because hi-lock--hashcons is global. | ||
| 38 | (hi-lock-set-pattern "b" face)))) | ||
| 39 | (should (equal hi-lock--unused-faces (cdr faces)))))) | 37 | (should (equal hi-lock--unused-faces (cdr faces)))))) |
| 40 | 38 | ||
| 41 | (ert-deftest hi-lock-test-set-pattern () | 39 | (ert-deftest hi-lock-test-set-pattern () |
| @@ -148,5 +146,63 @@ | |||
| 148 | (call-interactively 'unhighlight-regexp)) | 146 | (call-interactively 'unhighlight-regexp)) |
| 149 | (should (null (get-text-property 1 'face)))))) | 147 | (should (null (get-text-property 1 'face)))))) |
| 150 | 148 | ||
| 149 | (ert-deftest hi-lock-unhighlight () | ||
| 150 | "Test for unhighlighting and `hi-lock--regexps-at-point'." | ||
| 151 | (let ((hi-lock-auto-select-face t)) | ||
| 152 | (with-temp-buffer | ||
| 153 | (insert "aAbB\n") | ||
| 154 | |||
| 155 | (cl-letf (((symbol-function 'completing-read) | ||
| 156 | (lambda (_prompt _coll _x _y _z _hist defaults) | ||
| 157 | (car defaults)))) | ||
| 158 | |||
| 159 | (highlight-regexp "a") | ||
| 160 | (highlight-regexp "b") | ||
| 161 | (should (= (length (overlays-in (point-min) (point-max))) 4)) | ||
| 162 | ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, | ||
| 163 | ;; not the last regexp "b" | ||
| 164 | (goto-char 1) | ||
| 165 | (call-interactively 'unhighlight-regexp) | ||
| 166 | (should (= (length (overlays-in 1 3)) 0)) | ||
| 167 | (should (= (length (overlays-in 3 5)) 2)) | ||
| 168 | ;; Next call should unhighlight remaining regepxs | ||
| 169 | (call-interactively 'unhighlight-regexp) | ||
| 170 | (should (= (length (overlays-in 3 5)) 0)) | ||
| 171 | |||
| 172 | ;; Test unhighlight all | ||
| 173 | (highlight-regexp "a") | ||
| 174 | (highlight-regexp "b") | ||
| 175 | (should (= (length (overlays-in (point-min) (point-max))) 4)) | ||
| 176 | (unhighlight-regexp t) | ||
| 177 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 178 | |||
| 179 | (emacs-lisp-mode) | ||
| 180 | (setq font-lock-mode t) | ||
| 181 | |||
| 182 | (highlight-regexp "a") | ||
| 183 | (highlight-regexp "b") | ||
| 184 | (font-lock-ensure) | ||
| 185 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 186 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 187 | ;; `hi-lock--regexps-at-point' should take regexp "a" at point 1, | ||
| 188 | ;; not the last regexp "b" | ||
| 189 | (goto-char 1) | ||
| 190 | (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) | ||
| 191 | (should (null (get-text-property 1 'face))) | ||
| 192 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 193 | ;; Next call should unhighlight remaining regepxs | ||
| 194 | (let ((font-lock-fontified t)) (call-interactively 'unhighlight-regexp)) | ||
| 195 | (should (null (get-text-property 3 'face))) | ||
| 196 | |||
| 197 | ;; Test unhighlight all | ||
| 198 | (highlight-regexp "a") | ||
| 199 | (highlight-regexp "b") | ||
| 200 | (font-lock-ensure) | ||
| 201 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 202 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 203 | (let ((font-lock-fontified t)) (unhighlight-regexp t)) | ||
| 204 | (should (null (get-text-property 1 'face))) | ||
| 205 | (should (null (get-text-property 3 'face))))))) | ||
| 206 | |||
| 151 | (provide 'hi-lock-tests) | 207 | (provide 'hi-lock-tests) |
| 152 | ;;; hi-lock-tests.el ends here | 208 | ;;; hi-lock-tests.el ends here |