mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-01 09:51:22 -08:00
c3489d0* lisp/w32-fns.el (set-message-beep, w32-get-locale-info) (w3...a4d882cCorrect old cell name unbinding when renaming cell.6c12c53Merge branch 'emacs-25' of git.sv.gnu.org:/srv/git/emacs into...0be6725Document problem: slow screen refresh on missing font.853b9b9* admin/admin.el (add-release-logs): Basic check of existing ...5fa80cf* build-aux/gitlog-to-emacslog: Handle empty generated Change...3c79e51* admin/admin.el (add-release-logs): Generate ChangeLog if ne...42275df* doc/misc/texinfo.tex: Revert previous change (Bug#23611).3f4a9d9* admin/authors.el (authors): First update the ChangeLog.897fb6f; 'Changes from the pre-25.1 API' copyedits825ca25Rename vc-stay-local back to vc-cvs-stay-local4efb3e8* doc/emacs/files.texi (Comparing Files): * doc/emacs/trouble...b995d1e* doc/misc/eww.texi (Advanced): Fix xref.2e589c0Fix cross-references between manualsf3d2ded* doc/misc/vhdl-mode.texi (Sample Init File): Rename node to ...906c810; * admin/release-process: Move etc/HISTORY from here... ; * ...bea1b65* admin/admin.el (add-release-logs): Also update etc/HISTORY.503e752; * CONTRIBUTE: Fix a typo.fbfd478Avoid aborting due to errors in arguments of 'set-face-attrib...bdfbe6d; * admin/release-process: Copyedits.44a6aed; * test/automated/data-tests.el: Standardize license notice.c33ed39; * test/automated/viper-tests.el: Standardize license notice.df4a14bAdd automated test for viper-tests.elc0139e3Fix viper undo breakage from undo-boundary changes920d76cFix reference to obsolete fn ps-eval-switch18a9bc1Do not trash symlinks to init file2671179Don't print the "decomposition" line for control chars in wha...869092cBring back xterm pasting with middle mouse5ab0830Provide workaround for xftfont rendering problemc9f7ec7* lisp/desktop.el: Disable restore frameset if in non-graphic...30989a0Mention GTK+ problems in etc/PROBLEMS421e3c4* lisp/emacs-lisp/package.el (package-refresh-contents):dadfc30Revert "epg: Add a way to detect gpg1 executable for tests"e41a5cbAvoid errors with Czech and Slovak input methodsd4ae6d7epg: Add a way to detect gpg1 executable for testsebc3a94* lisp/emacs-lisp/package.el: Fix free variable warnings.6e71295* lisp/emacs-lisp/package.el (package--with-response-buffer):c45d9f6Improve documentation of 'server-name'3b5e38cModernize ASLR advice in etc/PROBLEMS1fe1e0a* lisp/char-fold.el: Rename from character-fold.el.
124 lines
5.2 KiB
EmacsLisp
124 lines
5.2 KiB
EmacsLisp
;;; char-fold-tests.el --- Tests for char-fold.el -*- lexical-binding: t; -*-
|
||
|
||
;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
|
||
|
||
;; Author: Artur Malabarba <bruce.connor.am@gmail.com>
|
||
|
||
;; This program is free software; you can redistribute it and/or modify
|
||
;; it under the terms of the GNU General Public License as published by
|
||
;; the Free Software Foundation, either version 3 of the License, or
|
||
;; (at your option) any later version.
|
||
|
||
;; This program is distributed in the hope that it will be useful,
|
||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;; GNU General Public License for more details.
|
||
|
||
;; You should have received a copy of the GNU General Public License
|
||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
||
;;; Code:
|
||
|
||
(require 'ert)
|
||
(require 'char-fold)
|
||
|
||
(defun char-fold--random-word (n)
|
||
(mapconcat (lambda (_) (string (+ 9 (random 117))))
|
||
(make-list n nil) ""))
|
||
|
||
(defun char-fold--test-search-with-contents (contents string)
|
||
(with-temp-buffer
|
||
(insert contents)
|
||
(goto-char (point-min))
|
||
(should (search-forward-regexp (char-fold-to-regexp string) nil 'noerror))
|
||
(goto-char (point-min))
|
||
(should (char-fold-search-forward string nil 'noerror))
|
||
(should (char-fold-search-backward string nil 'noerror))))
|
||
|
||
|
||
(ert-deftest char-fold--test-consistency ()
|
||
(dotimes (n 30)
|
||
(let ((w (char-fold--random-word n)))
|
||
;; A folded string should always match the original string.
|
||
(char-fold--test-search-with-contents w w))))
|
||
|
||
(ert-deftest char-fold--test-lax-whitespace ()
|
||
(dotimes (n 40)
|
||
(let ((w1 (char-fold--random-word n))
|
||
(w2 (char-fold--random-word n))
|
||
(search-spaces-regexp "\\s-+"))
|
||
(char-fold--test-search-with-contents
|
||
(concat w1 "\s\n\s\t\f\t\n\r\t" w2)
|
||
(concat w1 " " w2))
|
||
(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 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 (upcase re) (downcase it)))
|
||
(should (string-match (downcase re) (upcase it)))))))
|
||
|
||
(ert-deftest char-fold--test-some-defaults ()
|
||
(dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
|
||
("fi" . "fi") ("ff" . "ff")
|
||
("ä" . "ä")))
|
||
(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")))
|
||
(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")))
|
||
(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
|
||
;; (char-fold--test-match-exactly "a12" "xxyy")
|
||
))
|
||
|
||
(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)
|
||
;; Make sure we didn't just fallback on the trivial search.
|
||
(should-not (string= (regexp-quote string)
|
||
(char-fold-to-regexp string)))
|
||
(with-temp-buffer
|
||
(save-excursion (insert string))
|
||
(let ((time (time-to-seconds (current-time))))
|
||
;; Our initial implementation of case-folding in char-folding
|
||
;; 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 (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 'char-fold-tests)
|
||
;;; char-fold-tests.el ends here
|