aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLars Ingebrigtsen2018-04-22 16:57:16 +0200
committerLars Ingebrigtsen2018-04-22 16:57:16 +0200
commit214ca3b5857c3fc9f425bb1949cfc26f8c53da56 (patch)
treea84f48bddf21e1ce8c0fda5affec1dcd6e6914f0 /test
parent47d8e79960fe3ba98e360b201a6893812212880d (diff)
downloademacs-214ca3b5857c3fc9f425bb1949cfc26f8c53da56.tar.gz
emacs-214ca3b5857c3fc9f425bb1949cfc26f8c53da56.zip
Add a test suite for text-property-search
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/text-property-search-tests.el113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/text-property-search-tests.el b/test/lisp/emacs-lisp/text-property-search-tests.el
new file mode 100644
index 00000000000..5ea6b5372e1
--- /dev/null
+++ b/test/lisp/emacs-lisp/text-property-search-tests.el
@@ -0,0 +1,113 @@
1;;; text-property-search-tests.el --- Testing text-property-search
2
3;; Copyright (C) 2018 Free Software Foundation, Inc.
4
5;; Author: Lars Ingebrigtsen <larsi@gnus.org>
6;; Keywords:
7
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.
12
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.
17
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/>.
20
21;;; Commentary:
22
23;;
24
25;;; Code:
26
27(require 'ert)
28(require 'text-property-search)
29(require 'cl-lib)
30
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)))
40
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))))
53
54(ert-deftest text-property-search-forward-bold-t ()
55 (with-test (text-property-search-forward 'face 'bold t)
56 '("bold1" "bold2")))
57
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")))
61
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")))
65
66(ert-deftest text-property-search-forward-nil-nil ()
67 (with-test (text-property-search-forward 'face nil nil)
68 '("bold1" "italic1" "bold2" "italic2")))
69
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))
74
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))
79
80
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)))
85
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)))
90
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)))
95
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)))
100
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))
105
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))
110
111(provide 'text-property-search-tests)
112
113;;; text-property-search-tests.el ends here