aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJuri Linkov2019-07-23 23:27:28 +0300
committerJuri Linkov2019-07-23 23:27:28 +0300
commit376f5df3cca0dbf186823e5b329d76b52019473d (patch)
treed13fed57ed0b5d306d27846e87ee1e21b2f9900a /test
parenta48726ebae2f44ed15b97cb72bc7eca199d8de47 (diff)
downloademacs-376f5df3cca0dbf186823e5b329d76b52019473d.tar.gz
emacs-376f5df3cca0dbf186823e5b329d76b52019473d.zip
Customizable char-fold with char-fold-symmetric, char-fold-include (bug#35689)
* doc/emacs/search.texi (Lax Search): Document char-fold-symmetric, char-fold-include, char-fold-exclude. * lisp/char-fold.el (char-fold--default-include) (char-fold--default-exclude, char-fold--default-symmetric) (char-fold--previous): New defconsts. (char-fold-include, char-fold-exclude, char-fold-symmetric): New defcustoms. (char-fold-make-table): Use them. (char-fold-update-table): New function called at top-level. * test/lisp/char-fold-tests.el (char-fold--test-no-match-exactly) (char-fold--permutation): New functions. (char-fold--test-without-customization) (char-fold--test-with-customization): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/char-fold-tests.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/lisp/char-fold-tests.el b/test/lisp/char-fold-tests.el
index e9dfd2b7336..e519435ef05 100644
--- a/test/lisp/char-fold-tests.el
+++ b/test/lisp/char-fold-tests.el
@@ -44,6 +44,16 @@
44 (should (string-match (char-fold--ascii-upcase re) (downcase it))) 44 (should (string-match (char-fold--ascii-upcase re) (downcase it)))
45 (should (string-match (char-fold--ascii-downcase re) (upcase it))))))) 45 (should (string-match (char-fold--ascii-downcase re) (upcase it)))))))
46 46
47(defun char-fold--test-no-match-exactly (string &rest strings-to-match)
48 (let ((re (concat "\\`" (char-fold-to-regexp string) "\\'")))
49 (dolist (it strings-to-match)
50 (should-not (string-match re it)))
51 ;; Case folding
52 (let ((case-fold-search t))
53 (dolist (it strings-to-match)
54 (should-not (string-match (char-fold--ascii-upcase re) (downcase it)))
55 (should-not (string-match (char-fold--ascii-downcase re) (upcase it)))))))
56
47(defun char-fold--test-search-with-contents (contents string) 57(defun char-fold--test-search-with-contents (contents string)
48 (with-temp-buffer 58 (with-temp-buffer
49 (insert contents) 59 (insert contents)
@@ -53,6 +63,11 @@
53 (should (char-fold-search-forward string nil 'noerror)) 63 (should (char-fold-search-forward string nil 'noerror))
54 (should (char-fold-search-backward string nil 'noerror)))) 64 (should (char-fold-search-backward string nil 'noerror))))
55 65
66(defun char-fold--permutation (strings)
67 (mapcar (lambda (string)
68 (cons string (remove string strings)))
69 strings))
70
56 71
57(ert-deftest char-fold--test-consistency () 72(ert-deftest char-fold--test-consistency ()
58 (dotimes (n 30) 73 (dotimes (n 30)
@@ -132,5 +147,65 @@
132 ;; Ensure it took less than a second. 147 ;; Ensure it took less than a second.
133 (should (< (- (time-to-seconds) time) 1)))))) 148 (should (< (- (time-to-seconds) time) 1))))))
134 149
150(ert-deftest char-fold--test-without-customization ()
151 (let* ((matches
152 '(
153 ("e" "ℯ" "ḗ" "ë" "ë")
154 ("ι"
155 "ί" ;; 1 level decomposition
156 "ί" ;; 2 level decomposition
157 ;; FIXME:
158 ;; "ΐ" ;; 3 level decomposition
159 )
160 )))
161 (dolist (strings matches)
162 (apply 'char-fold--test-match-exactly strings))))
163
164(ert-deftest char-fold--test-with-customization ()
165 :tags '(:expensive-test)
166 (let* ((char-fold-include
167 '(
168 (?ß "ss") ;; de
169 (?o "ø") ;; da no nb nn
170 (?l "ł") ;; pl
171 ))
172 ;; FIXME: move language-specific settings to defaults
173 (char-fold-exclude
174 '(
175 (?a "å") ;; sv da no nb nn
176 (?a "ä") ;; sv fi et
177 (?o "ö") ;; sv fi et
178 (?n "ñ") ;; es
179 (?и "й") ;; ru
180 ))
181 (char-fold-symmetric t)
182 (char-fold-table (char-fold-make-table))
183 (matches
184 '(
185 ("e" "ℯ" "ḗ" "ë" "ë")
186 ("е" "ё" "ё")
187 ("ι" "ί" "ί"
188 ;; FIXME: "ΐ"
189 )
190 ("ß" "ss")
191 ("o" "ø")
192 ("l" "ł")
193
194 ))
195 (no-matches
196 '(
197 ("a" "å")
198 ("a" "ä")
199 ("o" "ö")
200 ("n" "ñ")
201 ("и" "й")
202 )))
203 (dolist (strings matches)
204 (dolist (permutation (char-fold--permutation strings))
205 (apply 'char-fold--test-match-exactly permutation)))
206 (dolist (strings no-matches)
207 (dolist (permutation (char-fold--permutation strings))
208 (apply 'char-fold--test-no-match-exactly permutation)))))
209
135(provide 'char-fold-tests) 210(provide 'char-fold-tests)
136;;; char-fold-tests.el ends here 211;;; char-fold-tests.el ends here