diff options
| author | Juri Linkov | 2020-04-13 02:40:56 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-04-13 02:40:56 +0300 |
| commit | 91e4acf7c736dfdb2673dc33c9303b5284e925df (patch) | |
| tree | e72ce8d84512ee75701424fdac26560c94ee88f7 /test | |
| parent | 68ffe4a3c9a001db528b057109d11de71471e4ff (diff) | |
| download | emacs-91e4acf7c736dfdb2673dc33c9303b5284e925df.tar.gz emacs-91e4acf7c736dfdb2673dc33c9303b5284e925df.zip | |
Fix hi-lock test and add new test for case-fold (bug#40337)
* lisp/hi-lock.el (hi-lock--regexps-at-point): Handle font-lock faces.
(hi-lock-unface-buffer): Simplify default value handling.
(hi-lock-set-pattern): Add either lighter or regexp to
hi-lock-interactive-lighters.
(hi-lock-set-pattern): Put overlay prop hi-lock-overlay-regexp to
either lighter or regexp.
* test/lisp/hi-lock-tests.el (hi-lock-bug26666): Use "b" instead of "a".
(hi-lock-case-fold): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/hi-lock-tests.el | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el index dd2c28053a0..252caaa2650 100644 --- a/test/lisp/hi-lock-tests.el +++ b/test/lisp/hi-lock-tests.el | |||
| @@ -33,7 +33,9 @@ | |||
| 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 | (hi-lock-set-pattern "a" face)))) | 36 | ;; This test should use regexp "b" different from "a" |
| 37 | ;; used in another test because hi-lock--hashcons is global. | ||
| 38 | (hi-lock-set-pattern "b" face)))) | ||
| 37 | (should (equal hi-lock--unused-faces (cdr faces)))))) | 39 | (should (equal hi-lock--unused-faces (cdr faces)))))) |
| 38 | 40 | ||
| 39 | (ert-deftest hi-lock-test-set-pattern () | 41 | (ert-deftest hi-lock-test-set-pattern () |
| @@ -48,5 +50,103 @@ | |||
| 48 | ;; Only one match, then we have used just 1 face | 50 | ;; Only one match, then we have used just 1 face |
| 49 | (should (equal hi-lock--unused-faces (cdr faces)))))) | 51 | (should (equal hi-lock--unused-faces (cdr faces)))))) |
| 50 | 52 | ||
| 53 | (ert-deftest hi-lock-case-fold () | ||
| 54 | "Test for case-sensitivity." | ||
| 55 | (let ((hi-lock-auto-select-face t)) | ||
| 56 | (with-temp-buffer | ||
| 57 | (insert "a A b B\n") | ||
| 58 | |||
| 59 | (dotimes (_ 2) (highlight-regexp "[a]")) | ||
| 60 | (should (= (length (overlays-in (point-min) (point-max))) 2)) | ||
| 61 | (unhighlight-regexp "[a]") | ||
| 62 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 63 | |||
| 64 | (dotimes (_ 2) (highlight-regexp "[a]" nil nil "a")) | ||
| 65 | (should (= (length (overlays-in (point-min) (point-max))) 2)) | ||
| 66 | (unhighlight-regexp "a") | ||
| 67 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 68 | |||
| 69 | (dotimes (_ 2) (highlight-regexp "[A]" )) | ||
| 70 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 71 | (unhighlight-regexp "[A]") | ||
| 72 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 73 | |||
| 74 | (dotimes (_ 2) (highlight-regexp "[A]" nil nil "A")) | ||
| 75 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 76 | (unhighlight-regexp "A") | ||
| 77 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 78 | |||
| 79 | (let ((case-fold-search nil)) (dotimes (_ 2) (highlight-regexp "[a]"))) | ||
| 80 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 81 | (unhighlight-regexp "[a]") | ||
| 82 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 83 | |||
| 84 | (dotimes (_ 2) (highlight-phrase "a a")) | ||
| 85 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 86 | (unhighlight-regexp "a a") | ||
| 87 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 88 | |||
| 89 | (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) | ||
| 90 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 91 | (cl-letf (((symbol-function 'completing-read) | ||
| 92 | (lambda (_prompt _coll _x _y _z _hist defaults) | ||
| 93 | (car defaults)))) | ||
| 94 | (call-interactively 'unhighlight-regexp)) | ||
| 95 | (should (= (length (overlays-in (point-min) (point-max))) 0)) | ||
| 96 | |||
| 97 | (emacs-lisp-mode) | ||
| 98 | (setq font-lock-mode t) | ||
| 99 | |||
| 100 | (dotimes (_ 2) (highlight-regexp "[a]")) | ||
| 101 | (font-lock-ensure) | ||
| 102 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 103 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 104 | (let ((font-lock-fontified t)) (unhighlight-regexp "[a]")) | ||
| 105 | (should (null (get-text-property 3 'face))) | ||
| 106 | |||
| 107 | (dotimes (_ 2) (highlight-regexp "[a]" nil nil "a")) | ||
| 108 | (font-lock-ensure) | ||
| 109 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 110 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 111 | (let ((font-lock-fontified t)) (unhighlight-regexp "a")) | ||
| 112 | (should (null (get-text-property 3 'face))) | ||
| 113 | |||
| 114 | (dotimes (_ 2) (highlight-regexp "[A]" )) | ||
| 115 | (font-lock-ensure) | ||
| 116 | (should (null (get-text-property 1 'face))) | ||
| 117 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 118 | (let ((font-lock-fontified t)) (unhighlight-regexp "[A]")) | ||
| 119 | (should (null (get-text-property 3 'face))) | ||
| 120 | |||
| 121 | (dotimes (_ 2) (highlight-regexp "[A]" nil nil "A")) | ||
| 122 | (font-lock-ensure) | ||
| 123 | (should (null (get-text-property 1 'face))) | ||
| 124 | (should (memq 'hi-yellow (get-text-property 3 'face))) | ||
| 125 | (let ((font-lock-fontified t)) (unhighlight-regexp "A")) | ||
| 126 | (should (null (get-text-property 3 'face))) | ||
| 127 | |||
| 128 | (let ((case-fold-search nil)) (dotimes (_ 2) (highlight-regexp "[a]"))) | ||
| 129 | (font-lock-ensure) | ||
| 130 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 131 | (should (null (get-text-property 3 'face))) | ||
| 132 | (let ((font-lock-fontified t)) (unhighlight-regexp "[a]")) | ||
| 133 | (should (null (get-text-property 1 'face))) | ||
| 134 | |||
| 135 | (dotimes (_ 2) (highlight-phrase "a a")) | ||
| 136 | (font-lock-ensure) | ||
| 137 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 138 | (let ((font-lock-fontified t)) (unhighlight-regexp "a a")) | ||
| 139 | (should (null (get-text-property 1 'face))) | ||
| 140 | |||
| 141 | (let ((search-spaces-regexp search-whitespace-regexp)) (highlight-regexp "a a")) | ||
| 142 | (font-lock-ensure) | ||
| 143 | (should (memq 'hi-yellow (get-text-property 1 'face))) | ||
| 144 | (cl-letf (((symbol-function 'completing-read) | ||
| 145 | (lambda (_prompt _coll _x _y _z _hist defaults) | ||
| 146 | (car defaults))) | ||
| 147 | (font-lock-fontified t)) | ||
| 148 | (call-interactively 'unhighlight-regexp)) | ||
| 149 | (should (null (get-text-property 1 'face)))))) | ||
| 150 | |||
| 51 | (provide 'hi-lock-tests) | 151 | (provide 'hi-lock-tests) |
| 52 | ;;; hi-lock-tests.el ends here | 152 | ;;; hi-lock-tests.el ends here |