all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 278155006c2558db0aceddf1a11720b55b365f5f 5870 bytes (raw)
name: test/lisp/emacs-lisp/text-property-search-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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 
;;; text-property-search-tests.el --- Testing text-property-search  -*- lexical-binding:t -*-

;; Copyright (C) 2018-2020 Free Software Foundation, Inc.

;; Author: Lars Ingebrigtsen <larsi@gnus.org>
;; Keywords:

;; 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'ert)
(require 'text-property-search)
(require 'cl-lib)

(defun text-property-setup ()
  (insert "This is "
          (propertize "bold1" 'face 'bold)
          " and this is "
          (propertize "italic1" 'face 'italic)
          (propertize "bold2" 'face 'bold)
          (propertize "italic2" 'face 'italic)
          " at the end")
  (goto-char (point-min)))

(defmacro with-test (form result &optional point)
  `(with-temp-buffer
     (text-property-setup)
     (when ,point
       (goto-char ,point))
     (should
      (equal
       (cl-loop for match = ,form
                while match
                collect (buffer-substring (prop-match-beginning match)
                                          (prop-match-end match)))
       ,result))))

(ert-deftest text-property-search-forward-bold-t ()
  (with-test (text-property-search-forward 'face 'bold t)
             '("bold1" "bold2")))

(ert-deftest text-property-search-forward-bold-nil ()
  (with-test (text-property-search-forward 'face 'bold nil)
             '("This is " " and this is italic1" "italic2 at the end")))

(ert-deftest text-property-search-forward-nil-t ()
  (with-test (text-property-search-forward 'face nil t)
             '("This is " " and this is " " at the end")))

(ert-deftest text-property-search-forward-nil-nil ()
  (with-test (text-property-search-forward 'face nil nil)
             '("bold1" "italic1" "bold2" "italic2")))

(ert-deftest text-property-search-forward-partial-bold-t ()
  (with-test (text-property-search-forward 'face 'bold t)
             '("old1" "bold2")
             10))

(ert-deftest text-property-search-forward-partial-non-current-bold-t ()
  (with-test (text-property-search-forward 'face 'bold t t)
             '("bold2")
             10))


(ert-deftest text-property-search-backward-bold-t ()
  (with-test (text-property-search-backward 'face 'bold t)
             '("bold2" "bold1")
             (point-max)))

(ert-deftest text-property-search-backward-bold-nil ()
  (with-test (text-property-search-backward 'face 'bold nil)
             '( "italic2 at the end" " and this is italic1" "This is ")
             (point-max)))

(ert-deftest text-property-search-backward-nil-t ()
  (with-test (text-property-search-backward 'face nil t)
             '(" at the end" " and this is " "This is ")
             (point-max)))

(ert-deftest text-property-search-backward-nil-nil ()
  (with-test (text-property-search-backward 'face nil nil)
             '("italic2" "bold2" "italic1" "bold1")
             (point-max)))

(ert-deftest text-property-search-backward-partial-bold-t ()
  (with-test (text-property-search-backward 'face 'bold t)
             '("b" "bold1")
             35))

(ert-deftest text-property-search-backward-partial-non-current-bold-t ()
  (with-test (text-property-search-backward 'face 'bold t t)
             '("bold1")
             35))

(defmacro with-match-test (form beginning end value &optional point)
  `(with-temp-buffer
     (text-property-setup)
     (when ,point
       (goto-char ,point))
     (should (equal ,form
                    (make-prop-match :beginning ,beginning
                                     :end ,end
                                     :value ,value)))))

(ert-deftest text-property-search-forward-prop-match-match-face-nil-nil ()
  (with-match-test
   (text-property-search-forward 'face nil nil)
   9 14 'bold))

(ert-deftest text-property-search-forward-prop-match-match-face-bold-t ()
  (with-match-test
   (text-property-search-forward 'face 'bold t)
   9 14 'bold))

(ert-deftest text-property-search-forward-prop-match-match-face-bold-nil ()
  (with-match-test
   (text-property-search-forward 'face 'bold nil)
   1 9 nil))

(ert-deftest text-property-search-backward-prop-match-match-face-nil-nil ()
  (with-match-test
   (text-property-search-backward 'face nil nil)
   39 46 'italic
   (point-max)))

(ert-deftest text-property-search-backward-prop-match-match-face-italic-t ()
  (with-match-test
   (text-property-search-backward 'face 'italic t)
   39 46 'italic
   (point-max)))

(ert-deftest text-property-search-backward-prop-match-match-face-italic-nil ()
  (with-match-test
   (text-property-search-backward 'face 'italic nil)
   46 57 nil
   (point-max)))

\f
;;;; Position after search.

(defun text-property-search--pos-test (fun pos &optional reverse)
  (with-temp-buffer (:name "position")
    (insert (concat "foo "
                  (propertize "bar" 'x t)
                  " baz"))
    (goto-char (if reverse (point-max) (point-min)))
    (funcall fun 'x t)
    (should (= (point) pos))))

(ert-deftest text-property-search-forward-point-at-beginning ()
  (text-property-search--pos-test #'text-property-search-forward 5))

(ert-deftest text-property-search-backward-point-at-end ()
  (text-property-search--pos-test #'text-property-search-backward 8 t))

(provide 'text-property-search-tests)

;;; text-property-search-tests.el ends here

debug log:

solving 278155006c ...
found 278155006c 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.