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)
361 (ert-deftest test-org-list
/move-item-down
()
362 "Test `org-move-item-down' specifications."
364 (org-test-with-temp-text "- item 1\n- item 2"
366 (should (equal (buffer-string)
367 "- item 2\n- item 1")))
368 ;; Keep same column in item.
369 (org-test-with-temp-text "- item 1\n- item 2"
372 (should (looking-at "em 1")))
374 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
376 (should (equal (buffer-string)
377 "- item 2\n- item 1\n - sub-item 1")))
378 ;; Preserve blank lines.
379 (org-test-with-temp-text "- item 1\n\n- item 2"
380 (let ((org-empty-line-terminates-plain-lists nil
)) (org-move-item-down))
381 (should (equal (buffer-string) "- item 2\n\n- item 1")))
382 ;; Error when trying to move the last item...
383 (org-test-with-temp-text "- item 1\n- item 2"
385 (should-error (org-move-item-down)))
386 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
387 ;; case, move to the first item.
388 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
390 (let ((org-list-use-circular-motion t
)) (org-move-item-down))
391 (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
392 ;; Preserve item visibility.
393 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
394 (let ((org-cycle-include-plain-lists t
))
395 (search-forward "- item 1")
397 (search-forward "- item 2")
399 (search-backward "- item 1")
402 (should (org-invisible-p2))
403 (search-backward " body 2")
404 (should (org-invisible-p2)))
405 ;; Preserve children visibility.
406 (org-test-with-temp-text "* Headline
413 (let ((org-cycle-include-plain-lists t
))
414 (search-forward "- sub-item 1")
416 (search-forward "- sub-item 2")
418 (search-backward "- item 1")
420 (search-forward "sub-body 1")
421 (should (org-invisible-p2))
422 (search-backward "sub-body 2")
423 (should (org-invisible-p2)))
424 ;; Preserve contents visibility.
425 (org-test-with-temp-text "
435 (search-forward "- item 1")
437 (search-forward "Text1")
438 (should (org-invisible-p2))
439 (search-backward "Text2")
440 (should (org-invisible-p2))))
442 (ert-deftest test-org-list
/move-item-up
()
443 "Test `org-move-item-up' specifications."
445 (org-test-with-temp-text "- item 1\n- item 2"
448 (should (equal (buffer-string)
449 "- item 2\n- item 1")))
450 ;; Keep same column in item.
451 (org-test-with-temp-text "- item 1\n- item 2"
455 (should (looking-at "em 2")))
457 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
460 (should (equal (buffer-string)
461 "- item 2\n - sub-item 2\n- item 1")))
462 ;; Preserve blank lines.
463 (org-test-with-temp-text "- item 1\n\n- item 2"
464 (search-forward "- item 2")
465 (let ((org-empty-line-terminates-plain-lists nil
)) (org-move-item-up))
466 (should (equal (buffer-string) "- item 2\n\n- item 1")))
467 ;; Error when trying to move the first item...
468 (org-test-with-temp-text "- item 1\n- item 2"
469 (should-error (org-move-item-up)))
470 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
471 ;; case, move to the first item.
472 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
473 (let ((org-list-use-circular-motion t
)) (org-move-item-up))
474 (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
475 ;; Preserve item visibility.
476 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
477 (let ((org-cycle-include-plain-lists t
))
478 (search-forward "- item 1")
480 (search-forward "- item 2")
484 (should (org-invisible-p2))
485 (search-forward " body 1")
486 (should (org-invisible-p2)))
487 ;; Preserve children visibility.
488 (org-test-with-temp-text "* Headline
495 (let ((org-cycle-include-plain-lists t
))
496 (search-forward "- sub-item 1")
498 (search-forward "- sub-item 2")
500 (search-backward "- item 2")
502 (search-forward "sub-body 2")
503 (should (org-invisible-p2))
504 (search-forward "sub-body 1")
505 (should (org-invisible-p2)))
506 ;; Preserve contents visibility.
507 (org-test-with-temp-text "
517 (search-forward "- item 2")
519 (search-forward "Text2")
520 (should (org-invisible-p2))
521 (search-forward "Text1")
522 (should (org-invisible-p2))))
525 (provide 'test-org-list
)
526 ;;; test-org-list.el ends here