[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 9d72d6a: * lisp/char-fold.el (char-fold-make-table)
From: |
Juri Linkov |
Subject: |
[Emacs-diffs] master 9d72d6a: * lisp/char-fold.el (char-fold-make-table): New function |
Date: |
Mon, 3 Jun 2019 16:18:38 -0400 (EDT) |
branch: master
commit 9d72d6a3a2fb23c6f7123c5aba2457dee93d9454
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>
* lisp/char-fold.el (char-fold-make-table): New function
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 | 23 ++++++++++++--------
test/lisp/char-fold-tests.el | 50 +++++++++++++++++++++++++-------------------
2 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index e61bc3e..d2fa710 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -24,11 +24,12 @@
(eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1))
-(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.
@@ -107,13 +108,17 @@
;; 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.
diff --git a/test/lisp/char-fold-tests.el b/test/lisp/char-fold-tests.el
index 8a647bd..8a74140 100644
--- a/test/lisp/char-fold-tests.el
+++ b/test/lisp/char-fold-tests.el
@@ -26,6 +26,24 @@
(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)
@@ -54,25 +72,7 @@
(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")
("ä" . "ä")))
@@ -109,9 +109,7 @@
(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)))
@@ -126,5 +124,13 @@
;; 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 9d72d6a: * lisp/char-fold.el (char-fold-make-table): New function,
Juri Linkov <=