]> code.delx.au - gnu-emacs/blob - test/lisp/character-fold-tests.el
Rename all test files to reflect source layout.
[gnu-emacs] / test / lisp / character-fold-tests.el
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 \f
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