all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 3a288b9071cd7c713899a80bfefee07165efbb13 4165 bytes (raw)
name: test/automated/character-fold-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
 
;;; character-fold-tests.el --- Tests for character-fold.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2013-2015 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 'character-fold)

(defun character-fold--random-word (n)
  (mapconcat (lambda (_) (string (+ 9 (random 117))))
             (make-list n nil) ""))

(defun character-fold--test-search-with-contents (contents string)
  (with-temp-buffer
    (insert contents)
    (goto-char (point-min))
    (should (search-forward-regexp (character-fold-to-regexp string) nil 'noerror))
    (goto-char (point-min))
    (should (character-fold-search-forward string nil 'noerror))
    (should (character-fold-search-backward string nil 'noerror))))

\f
(ert-deftest character-fold--test-consistency ()
  (dotimes (n 50)
    (let ((w (character-fold--random-word n)))
      ;; A folded string should always match the original string.
      (character-fold--test-search-with-contents w w))))

(ert-deftest character-fold--test-lax-whitespace ()
  (dotimes (n 50)
    (let ((w1 (character-fold--random-word n))
          (w2 (character-fold--random-word n))
          (search-spaces-regexp "\\s-+"))
      (character-fold--test-search-with-contents
       (concat w1 "\s\n\s\t\f\t\n\r\t" w2)
       (concat w1 " " w2))
      (character-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 character-fold--test-match-exactly (string &rest strings-to-match)
  (let ((re (concat "\\`" (character-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 character-fold--test-some-defaults ()
  (dolist (it '(("ffl" . "ffl") ("ffi" . "ffi")
                ("fi" . "fi") ("ff" . "ff")
                ("ä" . "ä")))
    (character-fold--test-search-with-contents (cdr it) (car it))
    (let ((multi (char-table-extra-slot character-fold-table 0))
          (character-fold-table (make-char-table 'character-fold-table)))
      (set-char-table-extra-slot character-fold-table 0 multi)
      (character-fold--test-match-exactly (car it) (cdr it)))))

(ert-deftest character-fold--test-fold-to-regexp ()
  (let ((character-fold-table (make-char-table 'character-fold-table))
        (multi  (make-char-table 'character-fold-table)))
    (set-char-table-extra-slot character-fold-table 0 multi)
    (aset character-fold-table ?a "xx")
    (aset character-fold-table ?1 "44")
    (aset character-fold-table ?\s "-!-")
    (character-fold--test-match-exactly "a1a1" "xx44xx44")
    (character-fold--test-match-exactly "a1  a 1" "xx44-!--!-xx-!-44")
    (aset multi ?a '(("1" . "99")
                     ("2" . "88")
                     ("12" . "77")))
    (character-fold--test-match-exactly "a" "xx")
    (character-fold--test-match-exactly "a1" "xx44" "99")
    (character-fold--test-match-exactly "a12" "77" "xx442" "992")
    (character-fold--test-match-exactly "a2" "88")
    (aset multi ?1 '(("2" . "yy")))
    (character-fold--test-match-exactly "a1" "xx44" "99")
    (character-fold--test-match-exactly "a12" "77" "xx442" "992")
    (character-fold--test-match-exactly "a12" "xxyy")))


(provide 'character-fold-tests)
;;; character-fold-tests.el ends here

debug log:

solving 3a288b9 ...
found 3a288b9 in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.