1 ;;; test-org-list.el --- Tests for org-list.el
3 ;; Copyright (C) 2012, 2013, 2014, 2018, 2019 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
/cycle-bullet
()
117 "Test `org-cycle-list-bullet' specifications."
118 ;; Error when not at an item.
120 (org-test-with-temp-text "Paragraph"
121 (org-cycle-list-bullet)))
122 ;; Cycle through "-", "+", "*", "1.", "1)".
123 (org-test-with-temp-text " - item"
124 (org-cycle-list-bullet)
125 (should (looking-at "[ \t]+\\+"))
126 (org-cycle-list-bullet)
127 (should (looking-at "[ \t]+\\*"))
128 (let ((org-plain-list-ordered-item-terminator t
))
129 (org-cycle-list-bullet))
130 (should (looking-at "[ \t]+1\\."))
131 (let ((org-plain-list-ordered-item-terminator t
))
132 (org-cycle-list-bullet))
133 (should (looking-at "[ \t]+1)")))
134 ;; Argument is a valid bullet: cycle to that bullet directly.
137 (org-test-with-temp-text "- item"
138 (let ((org-plain-list-ordered-item-terminator t
))
139 (org-cycle-list-bullet "1.")
141 ;; Argument is an integer N: cycle to the Nth allowed bullet.
144 (org-test-with-temp-text "1. item"
145 (let ((org-plain-list-ordered-item-terminator t
))
146 (org-cycle-list-bullet 1)
148 ;; Argument is `previous': cycle backwards.
151 (org-test-with-temp-text "+ item"
152 (let ((org-plain-list-ordered-item-terminator t
))
153 (org-cycle-list-bullet 'previous
)
155 ;; Do not cycle to "*" bullets when item is at column 0.
158 (org-test-with-temp-text "+ item"
159 (let ((org-plain-list-ordered-item-terminator t
))
160 (org-cycle-list-bullet)
162 ;; Do not cycle to numbered bullets in a description list.
164 (equal "1. tag :: item"
165 (org-test-with-temp-text "+ tag :: item"
166 (let ((org-plain-list-ordered-item-terminator t
))
167 (org-cycle-list-bullet)
169 ;; Do not cycle to ordered item terminators if they are not allowed
170 ;; in `org-plain-list-ordered-item-terminator'.
173 (org-test-with-temp-text " * item"
174 (let ((org-plain-list-ordered-item-terminator 41))
175 (org-cycle-list-bullet)
177 ;; When `org-list-allow-alphabetical' is non-nil, cycle to alpha bullets.
180 (org-test-with-temp-text "1) item"
181 (let ((org-plain-list-ordered-item-terminator t
)
182 (org-list-allow-alphabetical t
))
183 (org-cycle-list-bullet)
185 ;; Do not cycle to alpha bullets when list has more than 26
189 (org-test-with-temp-text "1) item 1
216 (let ((org-plain-list-ordered-item-terminator t
)
217 (org-list-allow-alphabetical t
))
218 (org-cycle-list-bullet)
219 (buffer-substring (point) (line-end-position)))))))
221 (ert-deftest test-org-list
/indent-item
()
222 "Test `org-indent-item' specifications."
223 ;; Error when not at an item.
224 (org-test-with-temp-text "Paragraph."
225 (should-error (org-indent-item)))
226 ;; Error when trying to move first item of a list.
228 (org-test-with-temp-text "
234 (org-test-with-temp-text "
238 (let ((org-list-automatic-rules nil
)) (org-indent-item))))
239 ;; Indent a single item, not its children.
245 (org-test-with-temp-text "
249 (let (org-list-demote-modify-bullet) (org-indent-item))
251 ;; Follow `org-list-demote-modify-bullet' specifications.
256 (org-test-with-temp-text "
259 (let ((org-list-demote-modify-bullet '(("-" .
"+"))))
266 (org-test-with-temp-text "
269 (let ((org-plain-list-ordered-item-terminator t
)
270 (org-list-demote-modify-bullet '(("1." .
"+"))))
277 (org-test-with-temp-text "
280 (let ((org-plain-list-ordered-item-terminator t
)
281 (org-list-allow-alphabetical t
)
282 (org-list-demote-modify-bullet '(("A." .
"a.") ("a." .
"-"))))
285 ;; When a region is selected, indent every item within.
292 (org-test-with-temp-text "
297 (transient-mark-mode 1)
298 (push-mark (point) t t
)
299 (goto-char (point-max))
300 (let (org-list-demote-modify-bullet) (org-indent-item))
303 (ert-deftest test-org-list
/indent-item-tree
()
304 "Test `org-indent-item-tree' specifications."
305 ;; 1. Error when not at an item.
306 (org-test-with-temp-text "Paragraph."
307 (should-error (org-indent-item-tree)))
308 ;; 2. Indent item along with its children.
309 (org-test-with-temp-text "
313 (search-forward "- Item 2")
314 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
315 (should (equal (buffer-string)
320 ;; 3. Special case: When indenting top item, move the whole list.
321 (org-test-with-temp-text "
324 (search-forward "- Item 1")
325 (let (org-list-demote-modify-bullet org-odd-levels-only
)
326 (org-indent-item-tree))
327 (should (equal (buffer-string)
331 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
333 ;; 4.1. With unordered lists.
334 (org-test-with-temp-text "
338 (search-forward "- Item 2")
339 (let ((org-list-demote-modify-bullet '(("-" .
"+") ("+" .
"-"))))
340 (org-indent-item-tree))
341 (should (equal (buffer-string)
346 ;; 4.2. and ordered lists.
347 (org-test-with-temp-text "
351 (search-forward "2. Item 2")
352 (let ((org-plain-list-ordered-item-terminator t
)
353 (org-list-demote-modify-bullet '(("1." .
"+") ("+" .
"1."))))
354 (org-indent-item-tree))
355 (should (equal (buffer-string)
360 ;; 5. When a region is selected, indent every item within.
361 (org-test-with-temp-text "
368 (search-forward "- Item 2")
370 (transient-mark-mode 1)
371 (push-mark (point) t t
)
372 (goto-char (point-max))
373 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
374 (should (equal (buffer-string)
383 (ert-deftest test-org-list
/outdent-item
()
384 "Test `org-outdent-item' specifications."
385 ;; 1. Error when not at an item.
386 (org-test-with-temp-text "Paragraph."
387 (should-error (org-outdent-item)))
388 ;; 2. Error when trying to move first item of a list.
389 (org-test-with-temp-text "
393 (should-error (org-outdent-item)))
394 ;; 3. Error when trying to outdent an item without its children.
395 (org-test-with-temp-text "
399 (search-forward "- Item 1.1")
400 (should-error (org-outdent-item)))
401 ;; 4. Error when trying to outdent before top item.
402 (org-test-with-temp-text "
405 (search-forward "- Item 2")
406 (should-error (org-outdent-item)))
407 ;; 5. When a region is selected, outdent every item within.
408 (org-test-with-temp-text "
413 (search-forward "- Item 2")
415 (transient-mark-mode 1)
416 (push-mark (point) t t
)
417 (goto-char (point-max))
418 (let (org-list-demote-modify-bullet) (org-outdent-item))
419 (should (equal (buffer-string)
426 (ert-deftest test-org-list
/outdent-item-tree
()
427 "Test `org-outdent-item-tree' specifications."
428 ;; 1. Error when not at an item.
429 (org-test-with-temp-text "Paragraph."
430 (should-error (org-outdent-item-tree)))
431 ;; 2. Error when trying to outdent before top item.
432 (org-test-with-temp-text "
435 (search-forward "- Item 2")
436 (should-error (org-outdent-item-tree)))
437 ;; 3. Outdent item along with its children.
438 (org-test-with-temp-text "
442 (search-forward "- Item 2")
443 (org-outdent-item-tree)
444 (should (equal (buffer-string)
449 ;; 3. Special case: When outdenting top item, move the whole list.
450 (org-test-with-temp-text "
453 (search-forward "- Item 1")
454 (let (org-odd-levels-only) (org-outdent-item-tree))
455 (should (equal (buffer-string)
459 ;; 5. When a region is selected, outdent every item within.
460 (org-test-with-temp-text "
467 (search-forward "- Item 2")
469 (transient-mark-mode 1)
470 (push-mark (point) t t
)
471 (goto-char (point-max))
472 (org-outdent-item-tree)
473 (should (equal (buffer-string)
482 (ert-deftest test-org-list
/move-item-down
()
483 "Test `org-move-item-down' specifications."
485 (org-test-with-temp-text "- item 1\n- item 2"
487 (should (equal (buffer-string)
488 "- item 2\n- item 1")))
489 ;; Keep same column in item.
490 (org-test-with-temp-text "- item 1\n- item 2"
493 (should (looking-at "em 1")))
495 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
497 (should (equal (buffer-string)
498 "- item 2\n- item 1\n - sub-item 1")))
499 ;; Preserve blank lines.
502 "- item 2\n\n- item 1"
503 (org-test-with-temp-text "- item 1\n\n- item 2"
506 ;; Error when trying to move the last item...
507 (org-test-with-temp-text "- item 1\n- item 2"
509 (should-error (org-move-item-down)))
510 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
511 ;; case, move to the first item.
512 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
514 (let ((org-list-use-circular-motion t
)) (org-move-item-down))
515 (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
516 ;; Preserve item visibility.
517 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
518 (let ((org-cycle-include-plain-lists t
))
519 (search-forward "- item 1")
521 (search-forward "- item 2")
523 (search-backward "- item 1")
526 (should (org-invisible-p2))
527 (search-backward " body 2")
528 (should (org-invisible-p2)))
529 ;; Preserve children visibility.
530 (org-test-with-temp-text "* Headline
537 (let ((org-cycle-include-plain-lists t
))
538 (search-forward "- sub-item 1")
540 (search-forward "- sub-item 2")
542 (search-backward "- item 1")
544 (search-forward "sub-body 1")
545 (should (org-invisible-p2))
546 (search-backward "sub-body 2")
547 (should (org-invisible-p2))))
549 (ert-deftest test-org-list
/move-item-down-contents-visibility
()
550 "Preserve contents visibility."
551 (org-test-with-temp-text "
561 (let ((invisible-property-1
563 (search-forward "Text1")
564 (get-char-property (point) 'invisible
)))
565 (invisible-property-2
567 (search-forward "Text2")
568 (get-char-property (point) 'invisible
))))
569 (goto-char (point-min))
570 (search-forward "- item 1")
572 (search-forward "Text1")
573 (should (eq invisible-property-1
(get-char-property (point) 'invisible
)))
574 (search-backward "Text2")
575 (should (eq invisible-property-2
(get-char-property (point) 'invisible
))))))
577 (ert-deftest test-org-list
/move-item-up
()
578 "Test `org-move-item-up' specifications."
580 (org-test-with-temp-text "- item 1\n- item 2"
583 (should (equal (buffer-string)
584 "- item 2\n- item 1")))
585 ;; Keep same column in item.
586 (org-test-with-temp-text "- item 1\n- item 2"
590 (should (looking-at "em 2")))
592 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
595 (should (equal (buffer-string)
596 "- item 2\n - sub-item 2\n- item 1")))
597 ;; Preserve blank lines.
600 "- item 2\n\n- item 1"
601 (org-test-with-temp-text "- item 1\n\n- item 2"
602 (search-forward "- item 2")
605 ;; Error when trying to move the first item...
606 (org-test-with-temp-text "- item 1\n- item 2"
607 (should-error (org-move-item-up)))
608 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
609 ;; case, move to the first item.
610 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
611 (let ((org-list-use-circular-motion t
)) (org-move-item-up))
612 (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
613 ;; Preserve item visibility.
614 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
615 (let ((org-cycle-include-plain-lists t
))
616 (search-forward "- item 1")
618 (search-forward "- item 2")
622 (should (org-invisible-p2))
623 (search-forward " body 1")
624 (should (org-invisible-p2)))
625 ;; Preserve children visibility.
626 (org-test-with-temp-text "* Headline
633 (let ((org-cycle-include-plain-lists t
))
634 (search-forward "- sub-item 1")
636 (search-forward "- sub-item 2")
638 (search-backward "- item 2")
640 (search-forward "sub-body 2")
641 (should (org-invisible-p2))
642 (search-forward "sub-body 1")
643 (should (org-invisible-p2))))
645 (ert-deftest test-org-list
/move-item-up-contents-visibility
()
646 (org-test-with-temp-text "
656 (let ((invisible-property-1
658 (search-forward "Text1")
659 (get-char-property (point) 'invisible
)))
660 (invisible-property-2
662 (search-forward "Text2")
663 (get-char-property (point) 'invisible
))))
664 (goto-char (point-min))
665 (search-forward "- item 2")
667 (search-forward "Text2")
668 (should (eq invisible-property-2
(get-char-property (point) 'invisible
)))
669 (search-forward "Text1")
670 (should (eq invisible-property-1
(get-char-property (point) 'invisible
))))))
672 (ert-deftest test-org-list
/insert-item
()
673 "Test item insertion."
674 ;; Blank lines specifications.
676 ;; Non-nil `org-blank-before-new-entry': insert a blank line.
678 (org-test-with-temp-text "- a"
679 (let ((org-blank-before-new-entry '((plain-list-item . t
))))
684 ;; Nil `org-blank-before-new-entry': do not insert a blank line.
686 (org-test-with-temp-text "- a"
687 (let ((org-blank-before-new-entry '((plain-list-item . nil
))))
692 ;; `org-blank-before-new-entry' set to auto: if there's no blank
693 ;; line already in the sole item, do not insert one.
695 (org-test-with-temp-text "- a"
696 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
701 ;; `org-blank-before-new-entry' set to `auto': if there's a blank
702 ;; line in the sole item, insert another one.
704 (org-test-with-temp-text "- a\n\n b<point>"
705 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
709 ;; `org-blank-before-new-entry' set to `auto': if the user specified
710 ;; a blank line, preserve it.
712 (org-test-with-temp-text "- a\n\n<point>"
713 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
717 ;; `org-blank-before-new-entry' set to `auto': if some items in list
718 ;; are already separated by blank lines, insert one.
720 (org-test-with-temp-text "- a\n\n- b<point>"
721 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
726 (org-test-with-temp-text "- a\n\n- b"
727 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
732 (org-test-with-temp-text
733 "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE<point>"
734 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
738 ;; When called before or on the bullet, insert new item before
742 (org-test-with-temp-text "- item"
747 (org-test-with-temp-text "- <point>item"
750 ;; When called on tag in a descriptive list, insert new item before
753 (equal "- :: \n- tag :: item"
754 (org-test-with-temp-text "- tag <point>:: item"
758 (equal "- :: \n- tag :: item"
759 (org-test-with-temp-text "- ta<point>g :: item"
762 ;; Further, it splits the line or add a blank new item after it,
763 ;; according to `org-M-RET-may-split-line'.
766 (org-test-with-temp-text "- it<point>em"
767 (let ((org-M-RET-may-split-line '((default . t
))))
772 (org-test-with-temp-text "- it<point>em"
773 (let ((org-M-RET-may-split-line '((default . nil
))))
776 ;; Preserve list visibility when inserting an item.
780 (org-test-with-temp-text "- A\n - B\n- C\n - D"
781 (let ((org-cycle-include-plain-lists t
))
786 (list (get-char-property (line-beginning-position 0) 'invisible
)
787 (get-char-property (line-end-position 2) 'invisible
)))))))
789 (ert-deftest test-org-list
/repair
()
790 "Test `org-list-repair' specifications."
791 ;; Repair indentation.
793 (equal "- item\n - child"
794 (org-test-with-temp-text "- item\n - child"
795 (let ((org-list-indent-offset 0)) (org-list-repair))
797 ;; Repair bullets and numbering.
800 (org-test-with-temp-text "- a\n+ b"
801 (let ((org-list-indent-offset 0))
806 (org-test-with-temp-text "1. a\n1. b"
807 (let ((org-list-indent-offset 0)
808 (org-plain-list-ordered-item-terminator t
))
811 ;; Repair check-boxes.
813 (equal "- [X] item\n - [X] child"
814 (org-test-with-temp-text "- [ ] item\n - [X] child"
815 (let ((org-list-indent-offset 0))
818 ;; Special case: do not move contents of an item within its child.
819 ;; Yet, preserve indentation differences within contents.
821 (equal "- item\n - child\n within item"
822 (org-test-with-temp-text "- item\n - child\n within item"
823 (let ((org-list-indent-offset 0)) (org-list-repair))
827 "- item\n - child\n within item\n indented"
828 (org-test-with-temp-text
829 "- item\n - child\n within item\n indented"
830 (let ((org-list-indent-offset 0)) (org-list-repair))
833 (ert-deftest test-org-list
/update-checkbox-count
()
834 "Test `org-update-checkbox-count' specifications."
837 (string-match "\\[0/1\\]"
838 (org-test-with-temp-text "* [/]\n- [ ] item"
839 (org-update-checkbox-count)
842 (string-match "\\[1/1\\]"
843 (org-test-with-temp-text "* [/]\n- [X] item"
844 (org-update-checkbox-count)
847 (string-match "\\[100%\\]"
848 (org-test-with-temp-text "* [%]\n- [X] item"
849 (org-update-checkbox-count)
851 ;; From a list or a sub-list.
853 (string-match "\\[0/1\\]"
854 (org-test-with-temp-text "- [/]\n - [ ] item"
855 (org-update-checkbox-count)
858 (string-match "\\[1/1\\]"
859 (org-test-with-temp-text "- [/]\n - [X] item"
860 (org-update-checkbox-count)
863 (string-match "\\[100%\\]"
864 (org-test-with-temp-text "- [%]\n - [X] item"
865 (org-update-checkbox-count)
870 (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
871 (org-update-checkbox-count)
873 ;; Count do not apply to sub-lists unless count is not hierarchical.
874 ;; This state can be achieved with COOKIE_DATA node property set to
877 (string-match "\\[1/1\\]"
878 (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
879 (let ((org-checkbox-hierarchical-statistics nil
))
880 (org-update-checkbox-count))
883 (string-match "\\[1/1\\]"
884 (org-test-with-temp-text "
887 :COOKIE_DATA: recursive
892 (org-update-checkbox-count)
895 (string-match "\\[0/0\\]"
896 (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
897 (org-update-checkbox-count)
899 ;; With optional argument ALL, update all buffer.
902 (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
903 (org-update-checkbox-count t
)
904 (count-matches "\\[1/1\\]"))))
905 ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
908 (string-match "\\[2/2\\]"
909 (org-test-with-temp-text "
916 (let ((org-checkbox-hierarchical-statistics nil
))
917 (org-update-checkbox-count))
924 (ert-deftest test-org-list
/toggle-item
()
925 "Test `org-toggle-item' specifications."
926 ;; Convert normal lines to items.
929 (org-test-with-temp-text "line"
930 (org-toggle-item nil
)
932 ;; Convert items to normal lines.
935 (org-test-with-temp-text "- line"
936 (org-toggle-item nil
)
938 ;; Convert headlines to items.
941 (org-test-with-temp-text "* line"
942 (org-toggle-item nil
)
944 ;; When converting a headline to a list item, TODO keywords become
948 (org-test-with-temp-text "* DONE line"
949 (org-toggle-item nil
)
953 (org-test-with-temp-text "* TODO line"
954 (org-toggle-item nil
)
956 ;; When turning headlines into items, make sure planning info line
957 ;; and properties drawers are removed. This also includes empty
958 ;; lines following them.
961 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29 Thu>"
962 (org-toggle-item nil
)
966 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
967 (org-toggle-item nil
)
971 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n\nText"
972 (org-toggle-item nil
)
974 ;; When a region is marked and first line is a headline, all
975 ;; headlines are turned into items.
978 (org-test-with-temp-text "* H1\n** H2"
979 (transient-mark-mode 1)
980 (push-mark (point) t t
)
981 (goto-char (point-max))
982 (org-toggle-item nil
)
985 (equal "- [ ] H1\n - [ ] H2"
986 (org-test-with-temp-text "* TODO H1\n** TODO H2"
987 (transient-mark-mode 1)
988 (push-mark (point) t t
)
989 (goto-char (point-max))
990 (org-toggle-item nil
)
992 ;; When turning headlines into items, make sure headings contents
993 ;; are kept within items.
996 (org-test-with-temp-text "* H1\nText"
997 (transient-mark-mode 1)
998 (push-mark (point) t t
)
999 (goto-char (point-max))
1000 (org-toggle-item nil
)
1002 ;; When a region is marked and first line is an item, all items are
1003 ;; turned into normal lines.
1006 (org-test-with-temp-text "- 1\n - 2"
1007 (transient-mark-mode 1)
1008 (push-mark (point) t t
)
1009 (goto-char (point-max))
1010 (org-toggle-item nil
)
1014 (org-test-with-temp-text "- 1\n2"
1015 (transient-mark-mode 1)
1016 (push-mark (point) t t
)
1017 (goto-char (point-max))
1018 (org-toggle-item nil
)
1020 ;; When a region is marked and first line is an item, all normal
1021 ;; lines are turned into items.
1023 (equal "- line 1\n- line 2"
1024 (org-test-with-temp-text "line 1\nline 2"
1025 (transient-mark-mode 1)
1026 (push-mark (point) t t
)
1027 (goto-char (point-max))
1028 (org-toggle-item nil
)
1031 (equal "- line 1\n- line 2"
1032 (org-test-with-temp-text "line 1\n- line 2"
1033 (transient-mark-mode 1)
1034 (push-mark (point) t t
)
1035 (goto-char (point-max))
1036 (org-toggle-item nil
)
1038 ;; When argument ARG is non-nil, change the whole region into
1041 (equal "- line 1\n line 2"
1042 (org-test-with-temp-text "line 1\nline 2"
1043 (transient-mark-mode 1)
1044 (push-mark (point) t t
)
1045 (goto-char (point-max))
1049 (ert-deftest test-org-list
/sort
()
1050 "Test `org-sort-list'."
1051 ;; Sort alphabetically.
1052 (let ((original-string-collate-lessp (symbol-function 'string-collate-lessp
)))
1053 (cl-letf (((symbol-function 'string-collate-lessp
)
1054 (lambda (s1 s2
&optional locale ignore-case
)
1055 (funcall original-string-collate-lessp
1056 s1 s2
"C" ignore-case
))))
1058 (equal "- abc\n- def\n- XYZ\n"
1059 (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
1060 (org-sort-list nil ?a
)
1063 (equal "- XYZ\n- def\n- abc\n"
1064 (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
1065 (org-sort-list nil ?A
)
1067 ;; Sort alphabetically (with case).
1069 (equal "- C\n- a\n- b\n"
1070 (org-test-with-temp-text "- b\n- C\n- a\n"
1071 (org-sort-list t ?a
)
1074 (equal "- b\n- a\n- C\n"
1075 (org-test-with-temp-text "- b\n- C\n- a\n"
1076 (org-sort-list t ?A
)
1077 (buffer-string))))))
1078 ;; Sort numerically.
1080 (equal "- 1\n- 2\n- 10\n"
1081 (org-test-with-temp-text "- 10\n- 1\n- 2\n"
1082 (org-sort-list nil ?n
)
1085 (equal "- 10\n- 2\n- 1\n"
1086 (org-test-with-temp-text "- 10\n- 1\n- 2\n"
1087 (org-sort-list nil ?N
)
1089 ;; Sort by checked status.
1091 (equal "- [ ] xyz\n- [ ] def\n- [X] abc\n"
1092 (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1093 (org-sort-list nil ?x
)
1096 (equal "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1097 (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1098 (org-sort-list nil ?X
)
1100 ;; Sort by time stamp.
1102 (equal "- <2017-05-08 Mon>\n- <2017-05-09 Tue>\n- <2018-05-09 Wed>\n"
1103 (org-test-with-temp-text
1104 "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1105 (org-sort-list nil ?t
)
1108 (equal "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1109 (org-test-with-temp-text
1110 "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1111 (org-sort-list nil ?T
)
1113 ;; Sort by custom function.
1115 (equal "- b\n- aa\n- ccc\n"
1116 (org-test-with-temp-text "- ccc\n- b\n- aa\n"
1117 (org-sort-list nil ?f
1119 (length (buffer-substring (point-at-bol)
1124 (equal "- ccc\n- aa\n- b\n"
1125 (org-test-with-temp-text "- ccc\n- b\n- aa\n"
1126 (org-sort-list nil ?F
1128 (length (buffer-substring (point-at-bol)
1134 ;;; List transformations
1136 (ert-deftest test-org-list
/to-generic
()
1137 "Test `org-list-to-generic' specifications."
1138 ;; Test `:ustart' and `:uend' parameters.
1142 (org-test-with-temp-text "- a"
1143 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1147 (org-test-with-temp-text "1. a"
1148 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1152 (org-test-with-temp-text "- a"
1153 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1157 (org-test-with-temp-text "1. a"
1158 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1161 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1162 (org-test-with-temp-text "- a\n - b"
1163 (org-list-to-generic
1165 (list :ustart
(lambda (l) (format "begin l%d" l
))
1166 :uend
(lambda (l) (format "end l%d" l
)))))))
1167 ;; Test `:ostart' and `:oend' parameters.
1171 (org-test-with-temp-text "1. a"
1172 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1176 (org-test-with-temp-text "- a"
1177 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1181 (org-test-with-temp-text "1. a"
1182 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1186 (org-test-with-temp-text "- a"
1187 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1190 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1191 (org-test-with-temp-text "1. a\n 1. b"
1192 (org-list-to-generic
1194 (list :ostart
(lambda (l) (format "begin l%d" l
))
1195 :oend
(lambda (l) (format "end l%d" l
)))))))
1196 ;; Test `:dstart' and `:dend' parameters.
1200 (org-test-with-temp-text "- tag :: a"
1201 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1205 (org-test-with-temp-text "- a"
1206 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1210 (org-test-with-temp-text "- tag :: a"
1211 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1215 (org-test-with-temp-text "- a"
1216 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1219 "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
1220 (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
1221 (org-list-to-generic
1223 (list :dstart
(lambda (l) (format "begin l%d" l
))
1224 :dend
(lambda (l) (format "end l%d" l
)))))))
1225 ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
1229 (org-test-with-temp-text "- tag :: a"
1230 (org-list-to-generic (org-list-to-lisp) '(:dtstart
">" :dtend
"<")))))
1234 (org-test-with-temp-text "- tag :: a"
1235 (org-list-to-generic (org-list-to-lisp) '(:ddstart
">" :ddend
"<")))))
1236 ;; Test `:istart' and `:iend' parameters.
1240 (org-test-with-temp-text "- a"
1241 (org-list-to-generic (org-list-to-lisp) '(:istart
"start")))))
1244 "level1 a\nlevel2 b"
1245 (org-test-with-temp-text "- a\n - b"
1246 (org-list-to-generic (org-list-to-lisp)
1247 '(:istart
(lambda (type l
) (format "level%d "l
)))))))
1251 (org-test-with-temp-text "- a\n - b"
1252 (org-list-to-generic (org-list-to-lisp)
1253 '(:iend
(lambda (type l
) (format "level%d" l
)))))))
1254 ;; Test `:icount' parameter.
1258 (org-test-with-temp-text "1. [@3] a"
1259 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1263 (org-test-with-temp-text "1. a"
1264 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1268 (org-test-with-temp-text "1. [@3] a"
1269 (org-list-to-generic (org-list-to-lisp)
1270 '(:icount
"count" :istart
"start")))))
1273 "level:1, counter:3 a"
1274 (org-test-with-temp-text "1. [@3] a"
1275 (org-list-to-generic
1277 '(:icount
(lambda (type l c
) (format "level:%d, counter:%d " l c
)))))))
1278 ;; Test `:isep' parameter.
1282 (org-test-with-temp-text "- a\n- b"
1283 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1287 (org-test-with-temp-text "- a\n - b"
1288 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1292 (org-test-with-temp-text "- a\n- b"
1293 (org-list-to-generic
1295 '(:isep
(lambda (type depth
) (format "- %d -" depth
)))))))
1296 ;; Test `:ifmt' parameter.
1300 (org-test-with-temp-text "1. [@3] a"
1301 (org-list-to-generic
1303 '(:ifmt
(lambda (type c
) (format ">> %s <<" c
)))))))
1304 ;; Test `:cbon', `:cboff', `:cbtrans'
1308 (org-test-with-temp-text "- [X] a"
1309 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!")))))
1313 (org-test-with-temp-text "- [X] a"
1314 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!" :cbtrans
"!")))))
1318 (org-test-with-temp-text "- [ ] a"
1319 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!")))))
1323 (org-test-with-temp-text "- [ ] a"
1324 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cbtrans
"!")))))
1328 (org-test-with-temp-text "- [-] a"
1329 (org-list-to-generic (org-list-to-lisp) '(:cbtrans
"!")))))
1333 (org-test-with-temp-text "- [-] a"
1334 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cboff
"!")))))
1335 ;; Test `:splice' parameter.
1339 (org-test-with-temp-text "- a"
1340 (org-list-to-generic (org-list-to-lisp)
1341 '(:ustart
"begin" :uend
"end" :splice t
)))))
1342 ;; No error on empty lists.
1344 (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil
))))
1346 (ert-deftest test-org-list
/to-html
()
1347 "Test `org-list-to-html' specifications."
1349 (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
1350 (org-test-with-temp-text "- a"
1351 (org-list-to-html (org-list-to-lisp) nil
)))))
1353 (ert-deftest test-org-list
/to-latex
()
1354 "Test `org-list-to-latex' specifications."
1356 (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
1357 (org-test-with-temp-text "- a"
1358 (org-list-to-latex (org-list-to-lisp) nil
)))))
1360 (ert-deftest test-org-list
/to-texinfo
()
1361 "Test `org-list-to-texinfo' specifications."
1363 (equal "@itemize\n@item\na\n@end itemize"
1364 (org-test-with-temp-text "- a"
1365 (org-list-to-texinfo (org-list-to-lisp) nil
)))))
1367 (ert-deftest test-org-list
/to-org
()
1368 "Test `org-list-to-org' specifications."
1372 (org-test-with-temp-text "- a"
1373 (org-list-to-org (org-list-to-lisp) nil
))))
1377 (org-test-with-temp-text "1. a"
1378 (org-list-to-org (org-list-to-lisp) nil
))))
1379 ;; Descriptive list.
1382 (org-test-with-temp-text "- a :: b"
1383 (org-list-to-org (org-list-to-lisp) nil
))))
1387 (org-test-with-temp-text "- a\n - b"
1388 (org-list-to-org (org-list-to-lisp) nil
))))
1389 ;; Item spanning over multiple lines.
1392 (org-test-with-temp-text "- a\n b"
1393 (org-list-to-org (org-list-to-lisp) nil
))))
1394 ;; Item with continuation text after a sub-list.
1396 (equal "- a\n - b\n c"
1397 (org-test-with-temp-text "- a\n - b\n c"
1398 (org-list-to-org (org-list-to-lisp) nil
)))))
1401 (provide 'test-org-list
)
1402 ;;; test-org-list.el ends here