]> code.delx.au - gnu-emacs/blobdiff - test/automated/char-fold-tests.el
* lisp/char-fold.el: Rename from character-fold.el.
[gnu-emacs] / test / automated / char-fold-tests.el
similarity index 53%
rename from test/automated/character-fold-tests.el
rename to test/automated/char-fold-tests.el
index c611217712ef0e3b9b9844b56bff0f13e20e1c77..485254aa6cfa2bd848cc2417684f00d0b9d61128 100644 (file)
@@ -1,4 +1,4 @@
-;;; character-fold-tests.el --- Tests for character-fold.el  -*- lexical-binding: t; -*-
+;;; char-fold-tests.el --- Tests for char-fold.el  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
 
 ;;; Code:
 
 (require 'ert)
-(require 'character-fold)
+(require 'char-fold)
 
-(defun character-fold--random-word (n)
+(defun char-fold--random-word (n)
   (mapconcat (lambda (_) (string (+ 9 (random 117))))
              (make-list n nil) ""))
 
-(defun character-fold--test-search-with-contents (contents string)
+(defun char-fold--test-search-with-contents (contents string)
   (with-temp-buffer
     (insert contents)
     (goto-char (point-min))
-    (should (search-forward-regexp (character-fold-to-regexp string) nil 'noerror))
+    (should (search-forward-regexp (char-fold-to-regexp string) nil 'noerror))
     (goto-char (point-min))
-    (should (character-fold-search-forward string nil 'noerror))
-    (should (character-fold-search-backward string nil 'noerror))))
+    (should (char-fold-search-forward string nil 'noerror))
+    (should (char-fold-search-backward string nil 'noerror))))
 
 \f
-(ert-deftest character-fold--test-consistency ()
+(ert-deftest char-fold--test-consistency ()
   (dotimes (n 30)
-    (let ((w (character-fold--random-word n)))
+    (let ((w (char-fold--random-word n)))
       ;; A folded string should always match the original string.
-      (character-fold--test-search-with-contents w w))))
+      (char-fold--test-search-with-contents w w))))
 
-(ert-deftest character-fold--test-lax-whitespace ()
+(ert-deftest char-fold--test-lax-whitespace ()
   (dotimes (n 40)
-    (let ((w1 (character-fold--random-word n))
-          (w2 (character-fold--random-word n))
+    (let ((w1 (char-fold--random-word n))
+          (w2 (char-fold--random-word n))
           (search-spaces-regexp "\\s-+"))
-      (character-fold--test-search-with-contents
+      (char-fold--test-search-with-contents
        (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
        (concat w1 " " w2))
-      (character-fold--test-search-with-contents
+      (char-fold--test-search-with-contents
        (concat w1 "\s\n\s\t\f\t\n\r\t" 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) "\\'")))
+(defun char-fold--test-match-exactly (string &rest strings-to-match)
+  (let ((re (concat "\\`" (char-fold-to-regexp string) "\\'")))
     (dolist (it strings-to-match)
       (should (string-match re it)))
     ;; Case folding
         (should (string-match (upcase re) (downcase it)))
         (should (string-match (downcase re) (upcase it)))))))
 
-(ert-deftest character-fold--test-some-defaults ()
+(ert-deftest char-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))
-        (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 "-!-")
-    (character-fold--test-match-exactly "a1a1" "xx44xx44")
-    (character-fold--test-match-exactly "a1  a 1" "xx44-!--!-xx-!-44")
+    (char-fold--test-search-with-contents (cdr it) (car it))
+    (let ((multi (char-table-extra-slot char-fold-table 0))
+          (char-fold-table (make-char-table 'char-fold-table)))
+      (set-char-table-extra-slot char-fold-table 0 multi)
+      (char-fold--test-match-exactly (car it) (cdr it)))))
+
+(ert-deftest char-fold--test-fold-to-regexp ()
+  (let ((char-fold-table (make-char-table 'char-fold-table))
+        (multi  (make-char-table 'char-fold-table)))
+    (set-char-table-extra-slot char-fold-table 0 multi)
+    (aset char-fold-table ?a "xx")
+    (aset char-fold-table ?1 "44")
+    (aset char-fold-table ?\s "-!-")
+    (char-fold--test-match-exactly "a1a1" "xx44xx44")
+    (char-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")
+    (char-fold--test-match-exactly "a" "xx")
+    (char-fold--test-match-exactly "a1" "xx44" "99")
+    (char-fold--test-match-exactly "a12" "77" "xx442" "992")
+    (char-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")
+    (char-fold--test-match-exactly "a1" "xx44" "99")
+    (char-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")
+    ;; (char-fold--test-match-exactly "a12" "xxyy")
     ))
 
-(ert-deftest character-fold--speed-test ()
+(ert-deftest char-fold--speed-test ()
   (dolist (string (append '("tty-set-up-initial-frame-face"
                             "tty-set-up-initial-frame-face-frame-faceframe-faceframe-faceframe-face")
-                          (mapcar #'character-fold--random-word '(10 50 100
+                          (mapcar #'char-fold--random-word '(10 50 100
                                                                      50 100))))
     (message "Testing %s" string)
     ;; Make sure we didn't just fallback on the trivial search.
     (should-not (string= (regexp-quote string)
-                         (character-fold-to-regexp string)))
+                         (char-fold-to-regexp string)))
     (with-temp-buffer
       (save-excursion (insert string))
       (let ((time (time-to-seconds (current-time))))
         ;; created a lot of redundant paths in the regexp. Because of
         ;; that, if a really long string "almost" matches, the regexp
         ;; engine took a long time to realize that it doesn't match.
-        (should-not (character-fold-search-forward (concat string "c") nil 'noerror))
+        (should-not (char-fold-search-forward (concat string "c") nil 'noerror))
         ;; Ensure it took less than a second.
         (should (< (- (time-to-seconds (current-time))
                       time)
                    1))))))
 
-(provide 'character-fold-tests)
-;;; character-fold-tests.el ends here
+(provide 'char-fold-tests)
+;;; char-fold-tests.el ends here