1 ;;; test-org-list.el --- Tests for org-list.el
3 ;; Copyright (C) 2012, 2013, 2014, 2018 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." .
"+"))))
273 ;; When a region is selected, indent every item within.
280 (org-test-with-temp-text "
285 (transient-mark-mode 1)
286 (push-mark (point) t t
)
287 (goto-char (point-max))
288 (let (org-list-demote-modify-bullet) (org-indent-item))
291 (ert-deftest test-org-list
/indent-item-tree
()
292 "Test `org-indent-item-tree' specifications."
293 ;; 1. Error when not at an item.
294 (org-test-with-temp-text "Paragraph."
295 (should-error (org-indent-item-tree)))
296 ;; 2. Indent item along with its children.
297 (org-test-with-temp-text "
301 (search-forward "- Item 2")
302 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
303 (should (equal (buffer-string)
308 ;; 3. Special case: When indenting top item, move the whole list.
309 (org-test-with-temp-text "
312 (search-forward "- Item 1")
313 (let (org-list-demote-modify-bullet org-odd-levels-only
)
314 (org-indent-item-tree))
315 (should (equal (buffer-string)
319 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
321 ;; 4.1. With unordered lists.
322 (org-test-with-temp-text "
326 (search-forward "- Item 2")
327 (let ((org-list-demote-modify-bullet '(("-" .
"+") ("+" .
"-"))))
328 (org-indent-item-tree))
329 (should (equal (buffer-string)
334 ;; 4.2. and ordered lists.
335 (org-test-with-temp-text "
339 (search-forward "2. Item 2")
340 (let ((org-plain-list-ordered-item-terminator t
)
341 (org-list-demote-modify-bullet '(("1." .
"+") ("+" .
"1."))))
342 (org-indent-item-tree))
343 (should (equal (buffer-string)
348 ;; 5. When a region is selected, indent every item within.
349 (org-test-with-temp-text "
356 (search-forward "- Item 2")
358 (transient-mark-mode 1)
359 (push-mark (point) t t
)
360 (goto-char (point-max))
361 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
362 (should (equal (buffer-string)
371 (ert-deftest test-org-list
/outdent-item
()
372 "Test `org-outdent-item' specifications."
373 ;; 1. Error when not at an item.
374 (org-test-with-temp-text "Paragraph."
375 (should-error (org-outdent-item)))
376 ;; 2. Error when trying to move first item of a list.
377 (org-test-with-temp-text "
381 (should-error (org-outdent-item)))
382 ;; 3. Error when trying to outdent an item without its children.
383 (org-test-with-temp-text "
387 (search-forward "- Item 1.1")
388 (should-error (org-outdent-item)))
389 ;; 4. Error when trying to outdent before top item.
390 (org-test-with-temp-text "
393 (search-forward "- Item 2")
394 (should-error (org-outdent-item)))
395 ;; 5. When a region is selected, outdent every item within.
396 (org-test-with-temp-text "
401 (search-forward "- Item 2")
403 (transient-mark-mode 1)
404 (push-mark (point) t t
)
405 (goto-char (point-max))
406 (let (org-list-demote-modify-bullet) (org-outdent-item))
407 (should (equal (buffer-string)
414 (ert-deftest test-org-list
/outdent-item-tree
()
415 "Test `org-outdent-item-tree' specifications."
416 ;; 1. Error when not at an item.
417 (org-test-with-temp-text "Paragraph."
418 (should-error (org-outdent-item-tree)))
419 ;; 2. Error when trying to outdent before top item.
420 (org-test-with-temp-text "
423 (search-forward "- Item 2")
424 (should-error (org-outdent-item-tree)))
425 ;; 3. Outdent item along with its children.
426 (org-test-with-temp-text "
430 (search-forward "- Item 2")
431 (org-outdent-item-tree)
432 (should (equal (buffer-string)
437 ;; 3. Special case: When outdenting top item, move the whole list.
438 (org-test-with-temp-text "
441 (search-forward "- Item 1")
442 (let (org-odd-levels-only) (org-outdent-item-tree))
443 (should (equal (buffer-string)
447 ;; 5. When a region is selected, outdent every item within.
448 (org-test-with-temp-text "
455 (search-forward "- Item 2")
457 (transient-mark-mode 1)
458 (push-mark (point) t t
)
459 (goto-char (point-max))
460 (org-outdent-item-tree)
461 (should (equal (buffer-string)
470 (ert-deftest test-org-list
/move-item-down
()
471 "Test `org-move-item-down' specifications."
473 (org-test-with-temp-text "- item 1\n- item 2"
475 (should (equal (buffer-string)
476 "- item 2\n- item 1")))
477 ;; Keep same column in item.
478 (org-test-with-temp-text "- item 1\n- item 2"
481 (should (looking-at "em 1")))
483 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
485 (should (equal (buffer-string)
486 "- item 2\n- item 1\n - sub-item 1")))
487 ;; Preserve blank lines.
490 "- item 2\n\n- item 1"
491 (org-test-with-temp-text "- item 1\n\n- item 2"
494 ;; Error when trying to move the last item...
495 (org-test-with-temp-text "- item 1\n- item 2"
497 (should-error (org-move-item-down)))
498 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
499 ;; case, move to the first item.
500 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
502 (let ((org-list-use-circular-motion t
)) (org-move-item-down))
503 (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
504 ;; Preserve item visibility.
505 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
506 (let ((org-cycle-include-plain-lists t
))
507 (search-forward "- item 1")
509 (search-forward "- item 2")
511 (search-backward "- item 1")
514 (should (org-invisible-p2))
515 (search-backward " body 2")
516 (should (org-invisible-p2)))
517 ;; Preserve children visibility.
518 (org-test-with-temp-text "* Headline
525 (let ((org-cycle-include-plain-lists t
))
526 (search-forward "- sub-item 1")
528 (search-forward "- sub-item 2")
530 (search-backward "- item 1")
532 (search-forward "sub-body 1")
533 (should (org-invisible-p2))
534 (search-backward "sub-body 2")
535 (should (org-invisible-p2))))
537 (ert-deftest test-org-list
/move-item-down-contents-visibility
()
538 "Preserve contents visibility."
539 (org-test-with-temp-text "
549 (let ((invisible-property-1
551 (search-forward "Text1")
552 (get-char-property (point) 'invisible
)))
553 (invisible-property-2
555 (search-forward "Text2")
556 (get-char-property (point) 'invisible
))))
557 (goto-char (point-min))
558 (search-forward "- item 1")
560 (search-forward "Text1")
561 (should (eq invisible-property-1
(get-char-property (point) 'invisible
)))
562 (search-backward "Text2")
563 (should (eq invisible-property-2
(get-char-property (point) 'invisible
))))))
565 (ert-deftest test-org-list
/move-item-up
()
566 "Test `org-move-item-up' specifications."
568 (org-test-with-temp-text "- item 1\n- item 2"
571 (should (equal (buffer-string)
572 "- item 2\n- item 1")))
573 ;; Keep same column in item.
574 (org-test-with-temp-text "- item 1\n- item 2"
578 (should (looking-at "em 2")))
580 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
583 (should (equal (buffer-string)
584 "- item 2\n - sub-item 2\n- item 1")))
585 ;; Preserve blank lines.
588 "- item 2\n\n- item 1"
589 (org-test-with-temp-text "- item 1\n\n- item 2"
590 (search-forward "- item 2")
593 ;; Error when trying to move the first item...
594 (org-test-with-temp-text "- item 1\n- item 2"
595 (should-error (org-move-item-up)))
596 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
597 ;; case, move to the first item.
598 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
599 (let ((org-list-use-circular-motion t
)) (org-move-item-up))
600 (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
601 ;; Preserve item visibility.
602 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
603 (let ((org-cycle-include-plain-lists t
))
604 (search-forward "- item 1")
606 (search-forward "- item 2")
610 (should (org-invisible-p2))
611 (search-forward " body 1")
612 (should (org-invisible-p2)))
613 ;; Preserve children visibility.
614 (org-test-with-temp-text "* Headline
621 (let ((org-cycle-include-plain-lists t
))
622 (search-forward "- sub-item 1")
624 (search-forward "- sub-item 2")
626 (search-backward "- item 2")
628 (search-forward "sub-body 2")
629 (should (org-invisible-p2))
630 (search-forward "sub-body 1")
631 (should (org-invisible-p2))))
633 (ert-deftest test-org-list
/move-item-up-contents-visibility
()
634 (org-test-with-temp-text "
644 (let ((invisible-property-1
646 (search-forward "Text1")
647 (get-char-property (point) 'invisible
)))
648 (invisible-property-2
650 (search-forward "Text2")
651 (get-char-property (point) 'invisible
))))
652 (goto-char (point-min))
653 (search-forward "- item 2")
655 (search-forward "Text2")
656 (should (eq invisible-property-2
(get-char-property (point) 'invisible
)))
657 (search-forward "Text1")
658 (should (eq invisible-property-1
(get-char-property (point) 'invisible
))))))
660 (ert-deftest test-org-list
/insert-item
()
661 "Test item insertion."
662 ;; Blank lines specifications.
664 ;; Non-nil `org-blank-before-new-entry': insert a blank line.
666 (org-test-with-temp-text "- a"
667 (let ((org-blank-before-new-entry '((plain-list-item . t
))))
672 ;; Nil `org-blank-before-new-entry': do not insert a blank line.
674 (org-test-with-temp-text "- a"
675 (let ((org-blank-before-new-entry '((plain-list-item . nil
))))
680 ;; `org-blank-before-new-entry' set to auto: if there's no blank
681 ;; line already in the sole item, do not insert one.
683 (org-test-with-temp-text "- a"
684 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
689 ;; `org-blank-before-new-entry' set to `auto': if there's a blank
690 ;; line in the sole item, insert another one.
692 (org-test-with-temp-text "- a\n\n b<point>"
693 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
697 ;; `org-blank-before-new-entry' set to `auto': if the user specified
698 ;; a blank line, preserve it.
700 (org-test-with-temp-text "- a\n\n<point>"
701 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
705 ;; `org-blank-before-new-entry' set to `auto': if some items in list
706 ;; are already separated by blank lines, insert one.
708 (org-test-with-temp-text "- a\n\n- b<point>"
709 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
714 (org-test-with-temp-text "- a\n\n- b"
715 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
720 (org-test-with-temp-text
721 "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE<point>"
722 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
726 ;; When called before or on the bullet, insert new item before
730 (org-test-with-temp-text "- item"
735 (org-test-with-temp-text "- <point>item"
738 ;; When called on tag in a descriptive list, insert new item before
741 (equal "- :: \n- tag :: item"
742 (org-test-with-temp-text "- tag <point>:: item"
746 (equal "- :: \n- tag :: item"
747 (org-test-with-temp-text "- ta<point>g :: item"
750 ;; Further, it splits the line or add a blank new item after it,
751 ;; according to `org-M-RET-may-split-line'.
754 (org-test-with-temp-text "- it<point>em"
755 (let ((org-M-RET-may-split-line '((default . t
))))
760 (org-test-with-temp-text "- it<point>em"
761 (let ((org-M-RET-may-split-line '((default . nil
))))
764 ;; Preserve list visibility when inserting an item.
768 (org-test-with-temp-text "- A\n - B\n- C\n - D"
769 (let ((org-cycle-include-plain-lists t
))
774 (list (get-char-property (line-beginning-position 0) 'invisible
)
775 (get-char-property (line-end-position 2) 'invisible
)))))))
777 (ert-deftest test-org-list
/repair
()
778 "Test `org-list-repair' specifications."
779 ;; Repair indentation.
781 (equal "- item\n - child"
782 (org-test-with-temp-text "- item\n - child"
783 (let ((org-list-indent-offset 0)) (org-list-repair))
785 ;; Repair bullets and numbering.
788 (org-test-with-temp-text "- a\n+ b"
789 (let ((org-list-indent-offset 0))
794 (org-test-with-temp-text "1. a\n1. b"
795 (let ((org-list-indent-offset 0)
796 (org-plain-list-ordered-item-terminator t
))
799 ;; Repair check-boxes.
801 (equal "- [X] item\n - [X] child"
802 (org-test-with-temp-text "- [ ] item\n - [X] child"
803 (let ((org-list-indent-offset 0))
806 ;; Special case: do not move contents of an item within its child.
807 ;; Yet, preserve indentation differences within contents.
809 (equal "- item\n - child\n within item"
810 (org-test-with-temp-text "- item\n - child\n within item"
811 (let ((org-list-indent-offset 0)) (org-list-repair))
815 "- item\n - child\n within item\n indented"
816 (org-test-with-temp-text
817 "- item\n - child\n within item\n indented"
818 (let ((org-list-indent-offset 0)) (org-list-repair))
821 (ert-deftest test-org-list
/update-checkbox-count
()
822 "Test `org-update-checkbox-count' specifications."
825 (string-match "\\[0/1\\]"
826 (org-test-with-temp-text "* [/]\n- [ ] item"
827 (org-update-checkbox-count)
830 (string-match "\\[1/1\\]"
831 (org-test-with-temp-text "* [/]\n- [X] item"
832 (org-update-checkbox-count)
835 (string-match "\\[100%\\]"
836 (org-test-with-temp-text "* [%]\n- [X] item"
837 (org-update-checkbox-count)
839 ;; From a list or a sub-list.
841 (string-match "\\[0/1\\]"
842 (org-test-with-temp-text "- [/]\n - [ ] item"
843 (org-update-checkbox-count)
846 (string-match "\\[1/1\\]"
847 (org-test-with-temp-text "- [/]\n - [X] item"
848 (org-update-checkbox-count)
851 (string-match "\\[100%\\]"
852 (org-test-with-temp-text "- [%]\n - [X] item"
853 (org-update-checkbox-count)
858 (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
859 (org-update-checkbox-count)
861 ;; Count do not apply to sub-lists unless count is not hierarchical.
862 ;; This state can be achieved with COOKIE_DATA node property set to
865 (string-match "\\[1/1\\]"
866 (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
867 (let ((org-checkbox-hierarchical-statistics nil
))
868 (org-update-checkbox-count))
871 (string-match "\\[1/1\\]"
872 (org-test-with-temp-text "
875 :COOKIE_DATA: recursive
880 (org-update-checkbox-count)
883 (string-match "\\[0/0\\]"
884 (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
885 (org-update-checkbox-count)
887 ;; With optional argument ALL, update all buffer.
890 (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
891 (org-update-checkbox-count t
)
892 (count-matches "\\[1/1\\]"))))
893 ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
896 (string-match "\\[2/2\\]"
897 (org-test-with-temp-text "
904 (let ((org-checkbox-hierarchical-statistics nil
))
905 (org-update-checkbox-count))
912 (ert-deftest test-org-list
/toggle-item
()
913 "Test `org-toggle-item' specifications."
914 ;; Convert normal lines to items.
917 (org-test-with-temp-text "line"
918 (org-toggle-item nil
)
920 ;; Convert items to normal lines.
923 (org-test-with-temp-text "- line"
924 (org-toggle-item nil
)
926 ;; Convert headlines to items.
929 (org-test-with-temp-text "* line"
930 (org-toggle-item nil
)
932 ;; When converting a headline to a list item, TODO keywords become
936 (org-test-with-temp-text "* DONE line"
937 (org-toggle-item nil
)
941 (org-test-with-temp-text "* TODO line"
942 (org-toggle-item nil
)
944 ;; When turning headlines into items, make sure planning info line
945 ;; and properties drawers are removed. This also includes empty
946 ;; lines following them.
949 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29 Thu>"
950 (org-toggle-item nil
)
954 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
955 (org-toggle-item nil
)
959 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n\nText"
960 (org-toggle-item nil
)
962 ;; When a region is marked and first line is a headline, all
963 ;; headlines are turned into items.
966 (org-test-with-temp-text "* H1\n** H2"
967 (transient-mark-mode 1)
968 (push-mark (point) t t
)
969 (goto-char (point-max))
970 (org-toggle-item nil
)
973 (equal "- [ ] H1\n - [ ] H2"
974 (org-test-with-temp-text "* TODO H1\n** TODO H2"
975 (transient-mark-mode 1)
976 (push-mark (point) t t
)
977 (goto-char (point-max))
978 (org-toggle-item nil
)
980 ;; When turning headlines into items, make sure headings contents
981 ;; are kept within items.
984 (org-test-with-temp-text "* H1\nText"
985 (transient-mark-mode 1)
986 (push-mark (point) t t
)
987 (goto-char (point-max))
988 (org-toggle-item nil
)
990 ;; When a region is marked and first line is an item, all items are
991 ;; turned into normal lines.
994 (org-test-with-temp-text "- 1\n - 2"
995 (transient-mark-mode 1)
996 (push-mark (point) t t
)
997 (goto-char (point-max))
998 (org-toggle-item nil
)
1002 (org-test-with-temp-text "- 1\n2"
1003 (transient-mark-mode 1)
1004 (push-mark (point) t t
)
1005 (goto-char (point-max))
1006 (org-toggle-item nil
)
1008 ;; When a region is marked and first line is an item, all normal
1009 ;; lines are turned into items.
1011 (equal "- line 1\n- line 2"
1012 (org-test-with-temp-text "line 1\nline 2"
1013 (transient-mark-mode 1)
1014 (push-mark (point) t t
)
1015 (goto-char (point-max))
1016 (org-toggle-item nil
)
1019 (equal "- line 1\n- line 2"
1020 (org-test-with-temp-text "line 1\n- line 2"
1021 (transient-mark-mode 1)
1022 (push-mark (point) t t
)
1023 (goto-char (point-max))
1024 (org-toggle-item nil
)
1026 ;; When argument ARG is non-nil, change the whole region into
1029 (equal "- line 1\n line 2"
1030 (org-test-with-temp-text "line 1\nline 2"
1031 (transient-mark-mode 1)
1032 (push-mark (point) t t
)
1033 (goto-char (point-max))
1037 (ert-deftest test-org-list
/sort
()
1038 "Test `org-sort-list'."
1039 ;; Sort alphabetically.
1040 (let ((original-string-collate-lessp (symbol-function 'string-collate-lessp
)))
1041 (cl-letf (((symbol-function 'string-collate-lessp
)
1042 (lambda (s1 s2
&optional locale ignore-case
)
1043 (funcall original-string-collate-lessp
1044 s1 s2
"C" ignore-case
))))
1046 (equal "- abc\n- def\n- XYZ\n"
1047 (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
1048 (org-sort-list nil ?a
)
1051 (equal "- XYZ\n- def\n- abc\n"
1052 (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
1053 (org-sort-list nil ?A
)
1055 ;; Sort alphabetically (with case).
1057 (equal "- C\n- a\n- b\n"
1058 (org-test-with-temp-text "- b\n- C\n- a\n"
1059 (org-sort-list t ?a
)
1062 (equal "- b\n- a\n- C\n"
1063 (org-test-with-temp-text "- b\n- C\n- a\n"
1064 (org-sort-list t ?A
)
1065 (buffer-string))))))
1066 ;; Sort numerically.
1068 (equal "- 1\n- 2\n- 10\n"
1069 (org-test-with-temp-text "- 10\n- 1\n- 2\n"
1070 (org-sort-list nil ?n
)
1073 (equal "- 10\n- 2\n- 1\n"
1074 (org-test-with-temp-text "- 10\n- 1\n- 2\n"
1075 (org-sort-list nil ?N
)
1077 ;; Sort by checked status.
1079 (equal "- [ ] xyz\n- [ ] def\n- [X] abc\n"
1080 (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1081 (org-sort-list nil ?x
)
1084 (equal "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1085 (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
1086 (org-sort-list nil ?X
)
1088 ;; Sort by time stamp.
1090 (equal "- <2017-05-08 Mon>\n- <2017-05-09 Tue>\n- <2018-05-09 Wed>\n"
1091 (org-test-with-temp-text
1092 "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1093 (org-sort-list nil ?t
)
1096 (equal "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1097 (org-test-with-temp-text
1098 "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
1099 (org-sort-list nil ?T
)
1101 ;; Sort by custom function.
1103 (equal "- b\n- aa\n- ccc\n"
1104 (org-test-with-temp-text "- ccc\n- b\n- aa\n"
1105 (org-sort-list nil ?f
1107 (length (buffer-substring (point-at-bol)
1112 (equal "- ccc\n- aa\n- b\n"
1113 (org-test-with-temp-text "- ccc\n- b\n- aa\n"
1114 (org-sort-list nil ?F
1116 (length (buffer-substring (point-at-bol)
1122 ;;; List transformations
1124 (ert-deftest test-org-list
/to-generic
()
1125 "Test `org-list-to-generic' specifications."
1126 ;; Test `:ustart' and `:uend' parameters.
1130 (org-test-with-temp-text "- a"
1131 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1135 (org-test-with-temp-text "1. a"
1136 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1140 (org-test-with-temp-text "- a"
1141 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1145 (org-test-with-temp-text "1. a"
1146 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1149 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1150 (org-test-with-temp-text "- a\n - b"
1151 (org-list-to-generic
1153 (list :ustart
(lambda (l) (format "begin l%d" l
))
1154 :uend
(lambda (l) (format "end l%d" l
)))))))
1155 ;; Test `:ostart' and `:oend' parameters.
1159 (org-test-with-temp-text "1. a"
1160 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1164 (org-test-with-temp-text "- a"
1165 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1169 (org-test-with-temp-text "1. a"
1170 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1174 (org-test-with-temp-text "- a"
1175 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1178 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1179 (org-test-with-temp-text "1. a\n 1. b"
1180 (org-list-to-generic
1182 (list :ostart
(lambda (l) (format "begin l%d" l
))
1183 :oend
(lambda (l) (format "end l%d" l
)))))))
1184 ;; Test `:dstart' and `:dend' parameters.
1188 (org-test-with-temp-text "- tag :: a"
1189 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1193 (org-test-with-temp-text "- a"
1194 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1198 (org-test-with-temp-text "- tag :: a"
1199 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1203 (org-test-with-temp-text "- a"
1204 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1207 "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
1208 (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
1209 (org-list-to-generic
1211 (list :dstart
(lambda (l) (format "begin l%d" l
))
1212 :dend
(lambda (l) (format "end l%d" l
)))))))
1213 ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
1217 (org-test-with-temp-text "- tag :: a"
1218 (org-list-to-generic (org-list-to-lisp) '(:dtstart
">" :dtend
"<")))))
1222 (org-test-with-temp-text "- tag :: a"
1223 (org-list-to-generic (org-list-to-lisp) '(:ddstart
">" :ddend
"<")))))
1224 ;; Test `:istart' and `:iend' parameters.
1228 (org-test-with-temp-text "- a"
1229 (org-list-to-generic (org-list-to-lisp) '(:istart
"start")))))
1232 "level1 a\nlevel2 b"
1233 (org-test-with-temp-text "- a\n - b"
1234 (org-list-to-generic (org-list-to-lisp)
1235 '(:istart
(lambda (type l
) (format "level%d "l
)))))))
1239 (org-test-with-temp-text "- a\n - b"
1240 (org-list-to-generic (org-list-to-lisp)
1241 '(:iend
(lambda (type l
) (format "level%d" l
)))))))
1242 ;; Test `:icount' parameter.
1246 (org-test-with-temp-text "1. [@3] a"
1247 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1251 (org-test-with-temp-text "1. a"
1252 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1256 (org-test-with-temp-text "1. [@3] a"
1257 (org-list-to-generic (org-list-to-lisp)
1258 '(:icount
"count" :istart
"start")))))
1261 "level:1, counter:3 a"
1262 (org-test-with-temp-text "1. [@3] a"
1263 (org-list-to-generic
1265 '(:icount
(lambda (type l c
) (format "level:%d, counter:%d " l c
)))))))
1266 ;; Test `:isep' parameter.
1270 (org-test-with-temp-text "- a\n- b"
1271 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1275 (org-test-with-temp-text "- a\n - b"
1276 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1280 (org-test-with-temp-text "- a\n- b"
1281 (org-list-to-generic
1283 '(:isep
(lambda (type depth
) (format "- %d -" depth
)))))))
1284 ;; Test `:ifmt' parameter.
1288 (org-test-with-temp-text "1. [@3] a"
1289 (org-list-to-generic
1291 '(:ifmt
(lambda (type c
) (format ">> %s <<" c
)))))))
1292 ;; Test `:cbon', `:cboff', `:cbtrans'
1296 (org-test-with-temp-text "- [X] a"
1297 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!")))))
1301 (org-test-with-temp-text "- [X] a"
1302 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!" :cbtrans
"!")))))
1306 (org-test-with-temp-text "- [ ] a"
1307 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!")))))
1311 (org-test-with-temp-text "- [ ] a"
1312 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cbtrans
"!")))))
1316 (org-test-with-temp-text "- [-] a"
1317 (org-list-to-generic (org-list-to-lisp) '(:cbtrans
"!")))))
1321 (org-test-with-temp-text "- [-] a"
1322 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cboff
"!")))))
1323 ;; Test `:splice' parameter.
1327 (org-test-with-temp-text "- a"
1328 (org-list-to-generic (org-list-to-lisp)
1329 '(:ustart
"begin" :uend
"end" :splice t
)))))
1330 ;; No error on empty lists.
1332 (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil
))))
1334 (ert-deftest test-org-list
/to-html
()
1335 "Test `org-list-to-html' specifications."
1337 (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
1338 (org-test-with-temp-text "- a"
1339 (org-list-to-html (org-list-to-lisp) nil
)))))
1341 (ert-deftest test-org-list
/to-latex
()
1342 "Test `org-list-to-latex' specifications."
1344 (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
1345 (org-test-with-temp-text "- a"
1346 (org-list-to-latex (org-list-to-lisp) nil
)))))
1348 (ert-deftest test-org-list
/to-texinfo
()
1349 "Test `org-list-to-texinfo' specifications."
1351 (equal "@itemize\n@item\na\n@end itemize"
1352 (org-test-with-temp-text "- a"
1353 (org-list-to-texinfo (org-list-to-lisp) nil
)))))
1355 (ert-deftest test-org-list
/to-org
()
1356 "Test `org-list-to-org' specifications."
1360 (org-test-with-temp-text "- a"
1361 (org-list-to-org (org-list-to-lisp) nil
))))
1365 (org-test-with-temp-text "1. a"
1366 (org-list-to-org (org-list-to-lisp) nil
))))
1367 ;; Descriptive list.
1370 (org-test-with-temp-text "- a :: b"
1371 (org-list-to-org (org-list-to-lisp) nil
))))
1375 (org-test-with-temp-text "- a\n - b"
1376 (org-list-to-org (org-list-to-lisp) nil
))))
1377 ;; Item spanning over multiple lines.
1380 (org-test-with-temp-text "- a\n b"
1381 (org-list-to-org (org-list-to-lisp) nil
))))
1382 ;; Item with continuation text after a sub-list.
1384 (equal "- a\n - b\n c"
1385 (org-test-with-temp-text "- a\n - b\n c"
1386 (org-list-to-org (org-list-to-lisp) nil
)))))
1389 (provide 'test-org-list
)
1390 ;;; test-org-list.el ends here