Give '$' punctuation syntax in make-mode (Bug#24477)
[emacs.git] / test / lisp / emacs-lisp / text-property-search-tests.el
blob5ea6b5372e10416be7598758430bcb57f6c7d368
1 ;;; text-property-search-tests.el --- Testing text-property-search
3 ;; Copyright (C) 2018 Free Software Foundation, Inc.
5 ;; Author: Lars Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords:
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
21 ;;; Commentary:
25 ;;; Code:
27 (require 'ert)
28 (require 'text-property-search)
29 (require 'cl-lib)
31 (defun text-property-setup ()
32 (insert "This is "
33 (propertize "bold1" 'face 'bold)
34 " and this is "
35 (propertize "italic1" 'face 'italic)
36 (propertize "bold2" 'face 'bold)
37 (propertize "italic2" 'face 'italic)
38 " at the end")
39 (goto-char (point-min)))
41 (defmacro with-test (form result &optional point)
42 `(with-temp-buffer
43 (text-property-setup)
44 (when ,point
45 (goto-char ,point))
46 (should
47 (equal
48 (cl-loop for match = ,form
49 while match
50 collect (buffer-substring (prop-match-beginning match)
51 (prop-match-end match)))
52 ,result))))
54 (ert-deftest text-property-search-forward-bold-t ()
55 (with-test (text-property-search-forward 'face 'bold t)
56 '("bold1" "bold2")))
58 (ert-deftest text-property-search-forward-bold-nil ()
59 (with-test (text-property-search-forward 'face 'bold nil)
60 '("This is " " and this is italic1" "italic2 at the end")))
62 (ert-deftest text-property-search-forward-nil-t ()
63 (with-test (text-property-search-forward 'face nil t)
64 '("This is " " and this is " " at the end")))
66 (ert-deftest text-property-search-forward-nil-nil ()
67 (with-test (text-property-search-forward 'face nil nil)
68 '("bold1" "italic1" "bold2" "italic2")))
70 (ert-deftest text-property-search-forward-partial-bold-t ()
71 (with-test (text-property-search-forward 'face 'bold t)
72 '("old1" "bold2")
73 10))
75 (ert-deftest text-property-search-forward-partial-non-current-bold-t ()
76 (with-test (text-property-search-forward 'face 'bold t t)
77 '("bold2")
78 10))
81 (ert-deftest text-property-search-backward-bold-t ()
82 (with-test (text-property-search-backward 'face 'bold t)
83 '("bold2" "bold1")
84 (point-max)))
86 (ert-deftest text-property-search-backward-bold-nil ()
87 (with-test (text-property-search-backward 'face 'bold nil)
88 '( "italic2 at the end" " and this is italic1" "This is ")
89 (point-max)))
91 (ert-deftest text-property-search-backward-nil-t ()
92 (with-test (text-property-search-backward 'face nil t)
93 '(" at the end" " and this is " "This is ")
94 (point-max)))
96 (ert-deftest text-property-search-backward-nil-nil ()
97 (with-test (text-property-search-backward 'face nil nil)
98 '("italic2" "bold2" "italic1" "bold1")
99 (point-max)))
101 (ert-deftest text-property-search-backward-partial-bold-t ()
102 (with-test (text-property-search-backward 'face 'bold t)
103 '("b" "bold1")
104 35))
106 (ert-deftest text-property-search-backward-partial-non-current-bold-t ()
107 (with-test (text-property-search-backward 'face 'bold t t)
108 '("bold1")
109 35))
111 (provide 'text-property-search-tests)
113 ;;; text-property-search-tests.el ends here