]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/char-fold.el (char-fold-make-table): New function
authorJuri Linkov <juri@linkov.net>
Mon, 3 Jun 2019 20:18:31 +0000 (23:18 +0300)
committerJuri Linkov <juri@linkov.net>
Mon, 3 Jun 2019 20:18:31 +0000 (23:18 +0300)
with body extracted from INITVALUE of defconst (bug#35689).
Bind search-spaces-regexp to nil (bug#35802).

* test/lisp/char-fold-tests.el: Relocate helpers to file beginning.
(char-fold--test-bug-35802): New test.

lisp/char-fold.el
test/lisp/char-fold-tests.el

index e61bc3edc6a440a690d54328cdbb5aa654c7962c..d2fa7108bbd5e251a7856b14b113e99d0913e333 100644 (file)
 
 (eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1))
 \f
-(defconst char-fold-table
-  (eval-when-compile
-    (let ((equiv (make-char-table 'char-fold-table))
-          (equiv-multi (make-char-table 'char-fold-table))
-          (table (unicode-property-table-internal 'decomposition)))
+(eval-and-compile
+  (defun char-fold-make-table ()
+    (let* ((equiv (make-char-table 'char-fold-table))
+           (equiv-multi (make-char-table 'char-fold-table))
+           (search-spaces-regexp nil)   ; workaround for bug#35802
+           (table (unicode-property-table-internal 'decomposition)))
       (set-char-table-extra-slot equiv 0 equiv-multi)
 
       ;; Ensure the table is populated.
 
       ;; Convert the lists of characters we compiled into regexps.
       (map-char-table
-       (lambda (char dec-list)
-         (let ((re (regexp-opt (cons (char-to-string char) dec-list))))
-           (if (consp char)
+       (lambda (char decomp-list)
+         (let ((re (regexp-opt (cons (char-to-string char) decomp-list))))
+           (if (consp char) ; FIXME: char never is consp?
                (set-char-table-range equiv char re)
              (aset equiv char re))))
        equiv)
-      equiv))
+      equiv)))
+
+(defconst char-fold-table
+  (eval-when-compile
+    (char-fold-make-table))
   "Used for folding characters of the same group during search.
 This is a char-table with the `char-fold-table' subtype.
 
index 8a647bd07654fe4e7b79527c1ab61e71110d20d0..8a7414084b0e72c2e4414e485f01f8be15732fae 100644 (file)
   (mapconcat (lambda (_) (string (+ 9 (random 117))))
              (make-list n nil) ""))
 
+(defun char-fold--ascii-upcase (string)
+  "Like `upcase' but acts on ASCII characters only."
+  (replace-regexp-in-string "[a-z]+" 'upcase string))
+
+(defun char-fold--ascii-downcase (string)
+  "Like `downcase' but acts on ASCII characters only."
+  (replace-regexp-in-string "[a-z]+" 'downcase 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
+    (let ((case-fold-search t))
+      (dolist (it strings-to-match)
+        (should (string-match (char-fold--ascii-upcase re) (downcase it)))
+        (should (string-match (char-fold--ascii-downcase re) (upcase it)))))))
+
 (defun char-fold--test-search-with-contents (contents string)
   (with-temp-buffer
     (insert contents)
        (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
        (concat w1 (make-string 10 ?\s) w2)))))
 
-(defun char-fold--ascii-upcase (string)
-  "Like `upcase' but acts on ASCII characters only."
-  (replace-regexp-in-string "[a-z]+" 'upcase string))
-
-(defun char-fold--ascii-downcase (string)
-  "Like `downcase' but acts on ASCII characters only."
-  (replace-regexp-in-string "[a-z]+" 'downcase 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
-    (let ((case-fold-search t))
-      (dolist (it strings-to-match)
-        (should (string-match (char-fold--ascii-upcase re) (downcase it)))
-        (should (string-match (char-fold--ascii-downcase re) (upcase it)))))))
-
-(ert-deftest char-fold--test-some-defaults ()
+(ert-deftest char-fold--test-multi-defaults ()
   (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
                 ("fi" . "fi") ("ff" . "ff")
                 ("ä" . "ä")))
 (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 #'char-fold--random-word '(10 50 100
-                                                                     50 100))))
-    (message "Testing %s" string)
+                          (mapcar #'char-fold--random-word '(10 50 100 50 100))))
     ;; Make sure we didn't just fallback on the trivial search.
     (should-not (string= (regexp-quote string)
                          (char-fold-to-regexp string)))
         ;; Ensure it took less than a second.
         (should (< (- (time-to-seconds) time) 1))))))
 
+(ert-deftest char-fold--test-bug-35802 ()
+  (let* ((char-code-property-alist      ; initial value
+          (cons '(decomposition . "uni-decomposition.el")
+                char-code-property-alist))
+         (search-spaces-regexp "\\(\\s-\\|\n\\)+")
+         (char-fold-table (char-fold-make-table)))
+    (char-fold--test-match-exactly "ä" "ä")))
+
 (provide 'char-fold-tests)
 ;;; char-fold-tests.el ends here