]> code.delx.au - gnu-emacs/blobdiff - test/automated/character-fold-tests.el
* lisp/emacs-lisp/package.el (package-unpack): Load before compiling
[gnu-emacs] / test / automated / character-fold-tests.el
index 40f0aecf4494058e210828105023a1b062179538..40735e5df7fe09298037557c460d97ea449196a3 100644 (file)
 
 \f
 (ert-deftest character-fold--test-consistency ()
-  (dotimes (n 100)
+  (dotimes (n 30)
     (let ((w (character-fold--random-word n)))
       ;; A folded string should always match the original string.
       (character-fold--test-search-with-contents w w))))
 
 (ert-deftest character-fold--test-lax-whitespace ()
-  (dotimes (n 100)
+  (dotimes (n 40)
     (let ((w1 (character-fold--random-word n))
           (w2 (character-fold--random-word n))
           (search-spaces-regexp "\\s-+"))
        (concat w1 " " w2))
       (character-fold--test-search-with-contents
        (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
-       (concat w1 (make-string 90 ?\s) w2)))))
+       (concat w1 (make-string 10 ?\s) w2)))))
+
+(defun character-fold--test-match-exactly (string &rest strings-to-match)
+  (let ((re (concat "\\`" (character-fold-to-regexp string) "\\'")))
+    (dolist (it strings-to-match)
+      (should (string-match re it)))
+    ;; Case folding
+    (let ((case-fold-search t))
+      (dolist (it strings-to-match)
+        (should (string-match (upcase re) (downcase it)))
+        (should (string-match (downcase re) (upcase it)))))))
+
+(ert-deftest character-fold--test-some-defaults ()
+  (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
+                ("fi" . "fi") ("ff" . "ff")
+                ("ä" . "ä")))
+    (character-fold--test-search-with-contents (cdr it) (car it))
+    (let ((multi (char-table-extra-slot character-fold-table 0))
+          (character-fold-table (make-char-table 'character-fold-table)))
+      (set-char-table-extra-slot character-fold-table 0 multi)
+      (character-fold--test-match-exactly (car it) (cdr it)))))
 
 (ert-deftest character-fold--test-fold-to-regexp ()
-  (let ((character-fold-table (make-char-table 'character-fold-table)))
-    (aset character-fold-table ?a "abc")
-    (aset character-fold-table ?1 "123")
+  (let ((character-fold-table (make-char-table 'character-fold-table))
+        (multi  (make-char-table 'character-fold-table)))
+    (set-char-table-extra-slot character-fold-table 0 multi)
+    (aset character-fold-table ?a "xx")
+    (aset character-fold-table ?1 "44")
     (aset character-fold-table ?\s "-!-")
-    (should (equal (character-fold-to-regexp "a1a1")
-                   "abc123abc123"))
-    (should (equal (character-fold-to-regexp "a1  a 1")
-                   "abc123\\(?:  \\|-!--!-\\)abc\\(?: \\|-!-\\)123"))))
+    (character-fold--test-match-exactly "a1a1" "xx44xx44")
+    (character-fold--test-match-exactly "a1  a 1" "xx44-!--!-xx-!-44")
+    (aset multi ?a '(("1" . "99")
+                     ("2" . "88")
+                     ("12" . "77")))
+    (character-fold--test-match-exactly "a" "xx")
+    (character-fold--test-match-exactly "a1" "xx44" "99")
+    (character-fold--test-match-exactly "a12" "77" "xx442" "992")
+    (character-fold--test-match-exactly "a2" "88")
+    (aset multi ?1 '(("2" . "yy")))
+    (character-fold--test-match-exactly "a1" "xx44" "99")
+    (character-fold--test-match-exactly "a12" "77" "xx442" "992")
+    ;; Support for this case is disabled.  See function definition or:
+    ;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02562.html
+    ;; (character-fold--test-match-exactly "a12" "xxyy")
+    ))
+
 
 (provide 'character-fold-tests)
 ;;; character-fold-tests.el ends here