(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.
(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