aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJuri Linkov2016-05-17 23:55:38 +0300
committerJuri Linkov2016-05-17 23:55:38 +0300
commit1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56 (patch)
tree4e53bb771b1c81d7a4c79c2323c33b7c37a40274 /test
parenta35826dbd44122b97e93d0c67bf658ced0a07ec6 (diff)
downloademacs-1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56.tar.gz
emacs-1fe1e0a8e7e3863d36c1a87ca38d2fa39bc25a56.zip
* lisp/char-fold.el: Rename from character-fold.el.
* lisp/replace.el (replace-char-fold): Rename from replace-character-fold. * test/automated/char-fold-tests.el: Rename from character-fold-tests.el. http://lists.gnu.org/archive/html/emacs-devel/2015-12/msg00529.html
Diffstat (limited to 'test')
-rw-r--r--test/automated/char-fold-tests.el (renamed from test/automated/character-fold-tests.el)92
1 files changed, 46 insertions, 46 deletions
diff --git a/test/automated/character-fold-tests.el b/test/automated/char-fold-tests.el
index c611217712e..485254aa6cf 100644
--- a/test/automated/character-fold-tests.el
+++ b/test/automated/char-fold-tests.el
@@ -1,4 +1,4 @@
1;;; character-fold-tests.el --- Tests for character-fold.el -*- lexical-binding: t; -*- 1;;; char-fold-tests.el --- Tests for char-fold.el -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2013-2016 Free Software Foundation, Inc. 3;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
4 4
@@ -20,42 +20,42 @@
20;;; Code: 20;;; Code:
21 21
22(require 'ert) 22(require 'ert)
23(require 'character-fold) 23(require 'char-fold)
24 24
25(defun character-fold--random-word (n) 25(defun char-fold--random-word (n)
26 (mapconcat (lambda (_) (string (+ 9 (random 117)))) 26 (mapconcat (lambda (_) (string (+ 9 (random 117))))
27 (make-list n nil) "")) 27 (make-list n nil) ""))
28 28
29(defun character-fold--test-search-with-contents (contents string) 29(defun char-fold--test-search-with-contents (contents string)
30 (with-temp-buffer 30 (with-temp-buffer
31 (insert contents) 31 (insert contents)
32 (goto-char (point-min)) 32 (goto-char (point-min))
33 (should (search-forward-regexp (character-fold-to-regexp string) nil 'noerror)) 33 (should (search-forward-regexp (char-fold-to-regexp string) nil 'noerror))
34 (goto-char (point-min)) 34 (goto-char (point-min))
35 (should (character-fold-search-forward string nil 'noerror)) 35 (should (char-fold-search-forward string nil 'noerror))
36 (should (character-fold-search-backward string nil 'noerror)))) 36 (should (char-fold-search-backward string nil 'noerror))))
37 37
38 38
39(ert-deftest character-fold--test-consistency () 39(ert-deftest char-fold--test-consistency ()
40 (dotimes (n 30) 40 (dotimes (n 30)
41 (let ((w (character-fold--random-word n))) 41 (let ((w (char-fold--random-word n)))
42 ;; A folded string should always match the original string. 42 ;; A folded string should always match the original string.
43 (character-fold--test-search-with-contents w w)))) 43 (char-fold--test-search-with-contents w w))))
44 44
45(ert-deftest character-fold--test-lax-whitespace () 45(ert-deftest char-fold--test-lax-whitespace ()
46 (dotimes (n 40) 46 (dotimes (n 40)
47 (let ((w1 (character-fold--random-word n)) 47 (let ((w1 (char-fold--random-word n))
48 (w2 (character-fold--random-word n)) 48 (w2 (char-fold--random-word n))
49 (search-spaces-regexp "\\s-+")) 49 (search-spaces-regexp "\\s-+"))
50 (character-fold--test-search-with-contents 50 (char-fold--test-search-with-contents
51 (concat w1 "\s\n\s\t\f\t\n\r\t" w2) 51 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
52 (concat w1 " " w2)) 52 (concat w1 " " w2))
53 (character-fold--test-search-with-contents 53 (char-fold--test-search-with-contents
54 (concat w1 "\s\n\s\t\f\t\n\r\t" w2) 54 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
55 (concat w1 (make-string 10 ?\s) w2))))) 55 (concat w1 (make-string 10 ?\s) w2)))))
56 56
57(defun character-fold--test-match-exactly (string &rest strings-to-match) 57(defun char-fold--test-match-exactly (string &rest strings-to-match)
58 (let ((re (concat "\\`" (character-fold-to-regexp string) "\\'"))) 58 (let ((re (concat "\\`" (char-fold-to-regexp string) "\\'")))
59 (dolist (it strings-to-match) 59 (dolist (it strings-to-match)
60 (should (string-match re it))) 60 (should (string-match re it)))
61 ;; Case folding 61 ;; Case folding
@@ -64,49 +64,49 @@
64 (should (string-match (upcase re) (downcase it))) 64 (should (string-match (upcase re) (downcase it)))
65 (should (string-match (downcase re) (upcase it))))))) 65 (should (string-match (downcase re) (upcase it)))))))
66 66
67(ert-deftest character-fold--test-some-defaults () 67(ert-deftest char-fold--test-some-defaults ()
68 (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi") 68 (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
69 ("fi" . "fi") ("ff" . "ff") 69 ("fi" . "fi") ("ff" . "ff")
70 ("ä" . "ä"))) 70 ("ä" . "ä")))
71 (character-fold--test-search-with-contents (cdr it) (car it)) 71 (char-fold--test-search-with-contents (cdr it) (car it))
72 (let ((multi (char-table-extra-slot character-fold-table 0)) 72 (let ((multi (char-table-extra-slot char-fold-table 0))
73 (character-fold-table (make-char-table 'character-fold-table))) 73 (char-fold-table (make-char-table 'char-fold-table)))
74 (set-char-table-extra-slot character-fold-table 0 multi) 74 (set-char-table-extra-slot char-fold-table 0 multi)
75 (character-fold--test-match-exactly (car it) (cdr it))))) 75 (char-fold--test-match-exactly (car it) (cdr it)))))
76 76
77(ert-deftest character-fold--test-fold-to-regexp () 77(ert-deftest char-fold--test-fold-to-regexp ()
78 (let ((character-fold-table (make-char-table 'character-fold-table)) 78 (let ((char-fold-table (make-char-table 'char-fold-table))
79 (multi (make-char-table 'character-fold-table))) 79 (multi (make-char-table 'char-fold-table)))
80 (set-char-table-extra-slot character-fold-table 0 multi) 80 (set-char-table-extra-slot char-fold-table 0 multi)
81 (aset character-fold-table ?a "xx") 81 (aset char-fold-table ?a "xx")
82 (aset character-fold-table ?1 "44") 82 (aset char-fold-table ?1 "44")
83 (aset character-fold-table ?\s "-!-") 83 (aset char-fold-table ?\s "-!-")
84 (character-fold--test-match-exactly "a1a1" "xx44xx44") 84 (char-fold--test-match-exactly "a1a1" "xx44xx44")
85 (character-fold--test-match-exactly "a1 a 1" "xx44-!--!-xx-!-44") 85 (char-fold--test-match-exactly "a1 a 1" "xx44-!--!-xx-!-44")
86 (aset multi ?a '(("1" . "99") 86 (aset multi ?a '(("1" . "99")
87 ("2" . "88") 87 ("2" . "88")
88 ("12" . "77"))) 88 ("12" . "77")))
89 (character-fold--test-match-exactly "a" "xx") 89 (char-fold--test-match-exactly "a" "xx")
90 (character-fold--test-match-exactly "a1" "xx44" "99") 90 (char-fold--test-match-exactly "a1" "xx44" "99")
91 (character-fold--test-match-exactly "a12" "77" "xx442" "992") 91 (char-fold--test-match-exactly "a12" "77" "xx442" "992")
92 (character-fold--test-match-exactly "a2" "88") 92 (char-fold--test-match-exactly "a2" "88")
93 (aset multi ?1 '(("2" . "yy"))) 93 (aset multi ?1 '(("2" . "yy")))
94 (character-fold--test-match-exactly "a1" "xx44" "99") 94 (char-fold--test-match-exactly "a1" "xx44" "99")
95 (character-fold--test-match-exactly "a12" "77" "xx442" "992") 95 (char-fold--test-match-exactly "a12" "77" "xx442" "992")
96 ;; Support for this case is disabled. See function definition or: 96 ;; Support for this case is disabled. See function definition or:
97 ;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02562.html 97 ;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg02562.html
98 ;; (character-fold--test-match-exactly "a12" "xxyy") 98 ;; (char-fold--test-match-exactly "a12" "xxyy")
99 )) 99 ))
100 100
101(ert-deftest character-fold--speed-test () 101(ert-deftest char-fold--speed-test ()
102 (dolist (string (append '("tty-set-up-initial-frame-face" 102 (dolist (string (append '("tty-set-up-initial-frame-face"
103 "tty-set-up-initial-frame-face-frame-faceframe-faceframe-faceframe-face") 103 "tty-set-up-initial-frame-face-frame-faceframe-faceframe-faceframe-face")
104 (mapcar #'character-fold--random-word '(10 50 100 104 (mapcar #'char-fold--random-word '(10 50 100
105 50 100)))) 105 50 100))))
106 (message "Testing %s" string) 106 (message "Testing %s" string)
107 ;; Make sure we didn't just fallback on the trivial search. 107 ;; Make sure we didn't just fallback on the trivial search.
108 (should-not (string= (regexp-quote string) 108 (should-not (string= (regexp-quote string)
109 (character-fold-to-regexp string))) 109 (char-fold-to-regexp string)))
110 (with-temp-buffer 110 (with-temp-buffer
111 (save-excursion (insert string)) 111 (save-excursion (insert string))
112 (let ((time (time-to-seconds (current-time)))) 112 (let ((time (time-to-seconds (current-time))))
@@ -114,11 +114,11 @@
114 ;; created a lot of redundant paths in the regexp. Because of 114 ;; created a lot of redundant paths in the regexp. Because of
115 ;; that, if a really long string "almost" matches, the regexp 115 ;; that, if a really long string "almost" matches, the regexp
116 ;; engine took a long time to realize that it doesn't match. 116 ;; engine took a long time to realize that it doesn't match.
117 (should-not (character-fold-search-forward (concat string "c") nil 'noerror)) 117 (should-not (char-fold-search-forward (concat string "c") nil 'noerror))
118 ;; Ensure it took less than a second. 118 ;; Ensure it took less than a second.
119 (should (< (- (time-to-seconds (current-time)) 119 (should (< (- (time-to-seconds (current-time))
120 time) 120 time)
121 1)))))) 121 1))))))
122 122
123(provide 'character-fold-tests) 123(provide 'char-fold-tests)
124;;; character-fold-tests.el ends here 124;;; char-fold-tests.el ends here