all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 00165ab05120be8283df12b46cd7fb257ed5295b 3828 bytes (raw)
name: test/src/regex-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
 
;;; regex-tests.el --- tests for regex.c functions -*- lexical-binding: t -*-

;; Copyright (C) 2015-2016 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)

(ert-deftest regex-word-cc-fallback-test ()
  "Test that ‘[[:cc:]]*x’ matches ‘x’ (bug#24020).

Test that a regex of the form \"[[:cc:]]*x\" where CC is
a character class which matches a multibyte character X, matches
string \"x\".

For example, ‘[[:word:]]*\u2620’ regex (note: \u2620 is a word
character) must match a string \"\u2420\"."
  (dolist (class '("[[:word:]]" "\\sw"))
    (dolist (repeat '("*" "+"))
      (dolist (suffix '("" "b" "bar" "\u2620"))
        (dolist (string '("" "foo"))
          (when (not (and (string-equal repeat "+")
                          (string-equal string "")))
            (should (string-match (concat "^" class repeat suffix "$")
                                  (concat string suffix)))))))))

(defun regex--test-cc (name matching not-matching)
  (should (string-match-p (concat "^[[:" name ":]]*$") matching))
  (should (string-match-p (concat "^[[:" name ":]]*?\u2622$")
                          (concat matching "\u2622")))
  (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching))
  (should (string-match-p (concat "^[^[:" name ":]]*\u2622$")
                          (concat not-matching "\u2622")))
  (with-temp-buffer
    (insert matching)
    (let ((p (point)))
      (insert not-matching)
      (goto-char (point-min))
      (skip-chars-forward (concat "[:" name ":]"))
      (should (equal (point) p))
      (skip-chars-forward (concat "^[:" name ":]"))
      (should (equal (point) (point-max)))
      (goto-char (point-min))
      (skip-chars-forward (concat "[:" name ":]\u2622"))
      (should (or (equal (point) p) (equal (point) (1+ p)))))))

(ert-deftest regex-character-classes ()
  "Perform sanity test of regexes using character classes.

Go over all the supported character classes and test whether the
classes and their inversions match what they are supposed to
match.  The test is done using `string-match-p' as well as
`skip-chars-forward'."
  (let (case-fold-search)
    (regex--test-cc "alnum" "abcABC012łąka" "-, \t\n")
    (regex--test-cc "alpha" "abcABCłąka" "-,012 \t\n")
    (regex--test-cc "digit" "012" "abcABCłąka-, \t\n")
    (regex--test-cc "xdigit" "0123aBc" "łąk-, \t\n")
    (regex--test-cc "upper" "ABCŁĄKA" "abc012-, \t\n")
    (regex--test-cc "lower" "abcłąka" "ABC012-, \t\n")

    (regex--test-cc "word" "abcABC012\u2620" "-, \t\n")

    (regex--test-cc "punct" ".,-" "abcABC012\u2620 \t\n")
    (regex--test-cc "cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
    (regex--test-cc "graph" "abcłąka\u2620-," " \t\n\1")
    (regex--test-cc "print" "abcłąka\u2620-, " "\t\n\1")

    (regex--test-cc "space" " \t\n\u2001" "abcABCł0123")
    (regex--test-cc "blank" " \t" "\n\u2001")

    (regex--test-cc "ascii" "abcABC012 \t\n\1" "łą\u2620")
    (regex--test-cc "nonascii" "łą\u2622" "abcABC012 \t\n\1")
    (regex--test-cc "unibyte" "abcABC012 \t\n\1" "łą\u2622")
    (regex--test-cc "multibyte" "łą\u2622" "abcABC012 \t\n\1")))

;;; regex-tests.el ends here

debug log:

solving 00165ab ...
found 00165ab 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.