aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-30 12:18:46 +0000
committerArtur Malabarba2015-10-30 12:20:07 +0000
commit3fb3af1d2a62e9a0a7bda7a296b621312919f922 (patch)
tree8eac5a6ac811260f91da0a2929351870e07cca72 /test
parent8c443c55d8c3346ccd093b7d7434b5779ba94a09 (diff)
downloademacs-3fb3af1d2a62e9a0a7bda7a296b621312919f922.tar.gz
emacs-3fb3af1d2a62e9a0a7bda7a296b621312919f922.zip
* test/automated/character-fold-tests.el: New file
Diffstat (limited to 'test')
-rw-r--r--test/automated/character-fold-tests.el58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/automated/character-fold-tests.el b/test/automated/character-fold-tests.el
new file mode 100644
index 00000000000..2b1a15c9e76
--- /dev/null
+++ b/test/automated/character-fold-tests.el
@@ -0,0 +1,58 @@
1;;; character-fold-tests.el --- Tests for character-fold.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
4
5;; Author: Artur Malabarba <bruce.connor.am@gmail.com>
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(require 'character-fold)
24
25(defun character-fold--random-word (n)
26 (mapconcat (lambda (_) (string (+ 9 (random 117))))
27 (make-list n nil) ""))
28
29(defun character-fold--test-search-with-contents (contents string)
30 (with-temp-buffer
31 (insert contents)
32 (goto-char (point-min))
33 (should (search-forward-regexp (character-fold-to-regexp string) nil 'noerror))
34 (goto-char (point-min))
35 (should (character-fold-search-forward string nil 'noerror))
36 (should (character-fold-search-backward string nil 'noerror))))
37
38
39(ert-deftest character-fold--test-consistency ()
40 (dotimes (n 100)
41 (let ((w (character-fold--random-word n)))
42 ;; A folded string should always match the original string.
43 (character-fold--test-search-with-contents w w))))
44
45(ert-deftest character-fold--test-lax-whitespace ()
46 (dotimes (n 100)
47 (let ((w1 (character-fold--random-word n))
48 (w2 (character-fold--random-word n))
49 (search-spaces-regexp "\\s-+"))
50 (character-fold--test-search-with-contents
51 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
52 (concat w1 " " w2))
53 (character-fold--test-search-with-contents
54 (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
55 (concat w1 (make-string 90 ?\s) w2)))))
56
57(provide 'character-fold-tests)
58;;; character-fold-tests.el ends here