1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-25 07:28:20 +00:00

* 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.
This commit is contained in:
Juri Linkov 2019-06-03 23:18:31 +03:00
parent 4b87a032dc
commit 9d72d6a3a2
2 changed files with 42 additions and 31 deletions

View File

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

View File

@ -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" . "") ("ffi" . "")
("fi" . "") ("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