1 ;;; test-org-list.el --- Tests for org-list.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 (ert-deftest test-org-list
/list-ending
()
23 "Test if lists end at the right place."
24 ;; With two blank lines.
25 (org-test-with-temp-text "- item\n\n\n Text"
27 (should-not (org-in-item-p)))
28 ;; With text less indented than top items.
29 (org-test-with-temp-text "- item\nText"
31 (should-not (org-in-item-p)))
32 ;; Though, blank lines and text indentation is ignored in blocks.
33 (org-test-with-temp-text
34 "- item\n #+begin_quote\n\n\nText at column 0\n #+end_quote\n Text"
36 (should (org-in-item-p))))
38 (ert-deftest test-org-list
/list-navigation
()
39 "Test list navigation specifications."
40 (org-test-with-temp-text "
54 (let ((org-list-use-circular-motion nil
))
55 ;; 1. Test `org-next-item'.
57 ;; 1.1. Should return an error if at last item in
58 ;; a list/sub-list, unless `org-list-use-circular-motion'
61 (should-error (org-next-item))
62 (let ((org-list-use-circular-motion t
))
63 (should (progn (org-next-item) t
)))
65 (should-error (org-next-item))
66 (let ((org-list-use-circular-motion t
))
67 (should (progn (org-next-item) t
)))
68 ;; 1.2. Should jump over sub-lists.
71 (should (looking-at "- item 2"))
72 ;; 1.3. Shouldn't move to another list.
74 (should-error (org-next-item))
75 (should-not (looking-at "- item 1"))
76 ;; 1.4. Should move to the list/sub-list first item when
77 ;; `org-list-use-circular-motion' is non-nil.
78 (let ((org-list-use-circular-motion t
))
81 (should (looking-at "- item 1"))
84 (should (looking-at " - item 1.1")))
85 ;; 2. Test `org-previous-item'.
87 ;; 2.1. Should return an error if at first item in
88 ;; a list/sub-list, unless `org-list-use-circular-motion is
91 (should-error (org-previous-item))
92 (let ((org-list-use-circular-motion t
))
93 (should (progn (org-previous-item) t
)))
95 (should-error (org-previous-item))
96 (let ((org-list-use-circular-motion t
))
97 (should (progn (org-previous-item) t
)))
98 ;; 2.2. Should ignore sub-lists.
101 (should (looking-at "- item 1"))
102 ;; 2.3. Shouldn't move to another list.
104 (should-error (org-previous-item))
105 (should-not (looking-at "- item B"))
106 ;; 2.4. Should move to the list/sub-list last item when
107 ;; `org-list-use-circular-motion' is non-nil.
108 (let ((org-list-use-circular-motion t
))
111 (should (looking-at "- item 2"))
114 (should (looking-at " - item 1.3"))))))
116 (ert-deftest test-org-list
/indent-item
()
117 "Test `org-indent-item' specifications."
118 ;; 1. Error when not at an item.
119 (org-test-with-temp-text "Paragraph."
120 (should-error (org-indent-item)))
121 ;; 2. Error when trying to move first item of a list.
122 (org-test-with-temp-text "
126 (should-error (org-indent-item)))
127 ;; 3. Indent a single item, not its children.
128 (org-test-with-temp-text "
132 (search-forward "- Item 2")
133 (let (org-list-demote-modify-bullet) (org-indent-item))
134 (should (equal (buffer-string)
139 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
141 ;; 4.1. With unordered lists.
142 (org-test-with-temp-text "
145 (search-forward "- Item 2")
146 (let ((org-list-demote-modify-bullet '(("-" .
"+")))) (org-indent-item))
147 (should (equal (buffer-string)
151 ;; 4.2. and ordered lists.
152 (org-test-with-temp-text "
155 (search-forward "2. Item 2")
156 (let ((org-plain-list-ordered-item-terminator t
)
157 (org-list-demote-modify-bullet '(("1." .
"+"))))
159 (should (equal (buffer-string)
163 ;; 5. When a region is selected, indent every item within.
164 (org-test-with-temp-text "
169 (search-forward "- Item 2")
171 (transient-mark-mode 1)
172 (push-mark (point) t t
)
173 (goto-char (point-max))
174 (let (org-list-demote-modify-bullet) (org-indent-item))
175 (should (equal (buffer-string)
182 (ert-deftest test-org-list
/indent-item-tree
()
183 "Test `org-indent-item-tree' specifications."
184 ;; 1. Error when not at an item.
185 (org-test-with-temp-text "Paragraph."
186 (should-error (org-indent-item-tree)))
187 ;; 2. Indent item along with its children.
188 (org-test-with-temp-text "
192 (search-forward "- Item 2")
193 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
194 (should (equal (buffer-string)
199 ;; 3. Special case: When indenting top item, move the whole list.
200 (org-test-with-temp-text "
203 (search-forward "- Item 1")
204 (let (org-list-demote-modify-bullet org-odd-levels-only
)
205 (org-indent-item-tree))
206 (should (equal (buffer-string)
210 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
212 ;; 4.1. With unordered lists.
213 (org-test-with-temp-text "
217 (search-forward "- Item 2")
218 (let ((org-list-demote-modify-bullet '(("-" .
"+") ("+" .
"-"))))
219 (org-indent-item-tree))
220 (should (equal (buffer-string)
225 ;; 4.2. and ordered lists.
226 (org-test-with-temp-text "
230 (search-forward "2. Item 2")
231 (let ((org-plain-list-ordered-item-terminator t
)
232 (org-list-demote-modify-bullet '(("1." .
"+") ("+" .
"1."))))
233 (org-indent-item-tree))
234 (should (equal (buffer-string)
239 ;; 5. When a region is selected, indent every item within.
240 (org-test-with-temp-text "
247 (search-forward "- Item 2")
249 (transient-mark-mode 1)
250 (push-mark (point) t t
)
251 (goto-char (point-max))
252 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
253 (should (equal (buffer-string)
262 (ert-deftest test-org-list
/outdent-item
()
263 "Test `org-outdent-item' specifications."
264 ;; 1. Error when not at an item.
265 (org-test-with-temp-text "Paragraph."
266 (should-error (org-outdent-item)))
267 ;; 2. Error when trying to move first item of a list.
268 (org-test-with-temp-text "
272 (should-error (org-outdent-item)))
273 ;; 3. Error when trying to outdent an item without its children.
274 (org-test-with-temp-text "
278 (search-forward "- Item 1.1")
279 (should-error (org-outdent-item)))
280 ;; 4. Error when trying to outdent before top item.
281 (org-test-with-temp-text "
284 (search-forward "- Item 2")
285 (should-error (org-outdent-item)))
286 ;; 5. When a region is selected, outdent every item within.
287 (org-test-with-temp-text "
292 (search-forward "- Item 2")
294 (transient-mark-mode 1)
295 (push-mark (point) t t
)
296 (goto-char (point-max))
297 (let (org-list-demote-modify-bullet) (org-outdent-item))
298 (should (equal (buffer-string)
305 (ert-deftest test-org-list
/outdent-item-tree
()
306 "Test `org-outdent-item-tree' specifications."
307 ;; 1. Error when not at an item.
308 (org-test-with-temp-text "Paragraph."
309 (should-error (org-outdent-item-tree)))
310 ;; 2. Error when trying to outdent before top item.
311 (org-test-with-temp-text "
314 (search-forward "- Item 2")
315 (should-error (org-outdent-item-tree)))
316 ;; 3. Outdent item along with its children.
317 (org-test-with-temp-text "
321 (search-forward "- Item 2")
322 (org-outdent-item-tree)
323 (should (equal (buffer-string)
328 ;; 3. Special case: When outdenting top item, move the whole list.
329 (org-test-with-temp-text "
332 (search-forward "- Item 1")
333 (let (org-odd-levels-only) (org-outdent-item-tree))
334 (should (equal (buffer-string)
338 ;; 5. When a region is selected, outdent every item within.
339 (org-test-with-temp-text "
346 (search-forward "- Item 2")
348 (transient-mark-mode 1)
349 (push-mark (point) t t
)
350 (goto-char (point-max))
351 (org-outdent-item-tree)
352 (should (equal (buffer-string)
362 (provide 'test-org-list
)
363 ;;; test-org-list.el ends here