1 ;;; test-org-list.el --- Tests for org-list.el
3 ;; Copyright (C) 2012, 2013, 2014 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 ;; 1. Error when not at an item.
224 (org-test-with-temp-text "Paragraph."
225 (should-error (org-indent-item)))
226 ;; 2. Error when trying to move first item of a list.
227 (org-test-with-temp-text "
231 (should-error (org-indent-item)))
232 ;; 3. Indent a single item, not its children.
233 (org-test-with-temp-text "
237 (search-forward "- Item 2")
238 (let (org-list-demote-modify-bullet) (org-indent-item))
239 (should (equal (buffer-string)
244 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
246 ;; 4.1. With unordered lists.
247 (org-test-with-temp-text "
250 (search-forward "- Item 2")
251 (let ((org-list-demote-modify-bullet '(("-" .
"+")))) (org-indent-item))
252 (should (equal (buffer-string)
256 ;; 4.2. and ordered lists.
257 (org-test-with-temp-text "
260 (search-forward "2. Item 2")
261 (let ((org-plain-list-ordered-item-terminator t
)
262 (org-list-demote-modify-bullet '(("1." .
"+"))))
264 (should (equal (buffer-string)
268 ;; 5. When a region is selected, indent every item within.
269 (org-test-with-temp-text "
274 (search-forward "- Item 2")
276 (transient-mark-mode 1)
277 (push-mark (point) t t
)
278 (goto-char (point-max))
279 (let (org-list-demote-modify-bullet) (org-indent-item))
280 (should (equal (buffer-string)
287 (ert-deftest test-org-list
/indent-item-tree
()
288 "Test `org-indent-item-tree' specifications."
289 ;; 1. Error when not at an item.
290 (org-test-with-temp-text "Paragraph."
291 (should-error (org-indent-item-tree)))
292 ;; 2. Indent item along with its children.
293 (org-test-with-temp-text "
297 (search-forward "- Item 2")
298 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
299 (should (equal (buffer-string)
304 ;; 3. Special case: When indenting top item, move the whole list.
305 (org-test-with-temp-text "
308 (search-forward "- Item 1")
309 (let (org-list-demote-modify-bullet org-odd-levels-only
)
310 (org-indent-item-tree))
311 (should (equal (buffer-string)
315 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
317 ;; 4.1. With unordered lists.
318 (org-test-with-temp-text "
322 (search-forward "- Item 2")
323 (let ((org-list-demote-modify-bullet '(("-" .
"+") ("+" .
"-"))))
324 (org-indent-item-tree))
325 (should (equal (buffer-string)
330 ;; 4.2. and ordered lists.
331 (org-test-with-temp-text "
335 (search-forward "2. Item 2")
336 (let ((org-plain-list-ordered-item-terminator t
)
337 (org-list-demote-modify-bullet '(("1." .
"+") ("+" .
"1."))))
338 (org-indent-item-tree))
339 (should (equal (buffer-string)
344 ;; 5. When a region is selected, indent every item within.
345 (org-test-with-temp-text "
352 (search-forward "- Item 2")
354 (transient-mark-mode 1)
355 (push-mark (point) t t
)
356 (goto-char (point-max))
357 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
358 (should (equal (buffer-string)
367 (ert-deftest test-org-list
/outdent-item
()
368 "Test `org-outdent-item' specifications."
369 ;; 1. Error when not at an item.
370 (org-test-with-temp-text "Paragraph."
371 (should-error (org-outdent-item)))
372 ;; 2. Error when trying to move first item of a list.
373 (org-test-with-temp-text "
377 (should-error (org-outdent-item)))
378 ;; 3. Error when trying to outdent an item without its children.
379 (org-test-with-temp-text "
383 (search-forward "- Item 1.1")
384 (should-error (org-outdent-item)))
385 ;; 4. Error when trying to outdent before top item.
386 (org-test-with-temp-text "
389 (search-forward "- Item 2")
390 (should-error (org-outdent-item)))
391 ;; 5. When a region is selected, outdent every item within.
392 (org-test-with-temp-text "
397 (search-forward "- Item 2")
399 (transient-mark-mode 1)
400 (push-mark (point) t t
)
401 (goto-char (point-max))
402 (let (org-list-demote-modify-bullet) (org-outdent-item))
403 (should (equal (buffer-string)
410 (ert-deftest test-org-list
/outdent-item-tree
()
411 "Test `org-outdent-item-tree' specifications."
412 ;; 1. Error when not at an item.
413 (org-test-with-temp-text "Paragraph."
414 (should-error (org-outdent-item-tree)))
415 ;; 2. Error when trying to outdent before top item.
416 (org-test-with-temp-text "
419 (search-forward "- Item 2")
420 (should-error (org-outdent-item-tree)))
421 ;; 3. Outdent item along with its children.
422 (org-test-with-temp-text "
426 (search-forward "- Item 2")
427 (org-outdent-item-tree)
428 (should (equal (buffer-string)
433 ;; 3. Special case: When outdenting top item, move the whole list.
434 (org-test-with-temp-text "
437 (search-forward "- Item 1")
438 (let (org-odd-levels-only) (org-outdent-item-tree))
439 (should (equal (buffer-string)
443 ;; 5. When a region is selected, outdent every item within.
444 (org-test-with-temp-text "
451 (search-forward "- Item 2")
453 (transient-mark-mode 1)
454 (push-mark (point) t t
)
455 (goto-char (point-max))
456 (org-outdent-item-tree)
457 (should (equal (buffer-string)
466 (ert-deftest test-org-list
/move-item-down
()
467 "Test `org-move-item-down' specifications."
469 (org-test-with-temp-text "- item 1\n- item 2"
471 (should (equal (buffer-string)
472 "- item 2\n- item 1")))
473 ;; Keep same column in item.
474 (org-test-with-temp-text "- item 1\n- item 2"
477 (should (looking-at "em 1")))
479 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
481 (should (equal (buffer-string)
482 "- item 2\n- item 1\n - sub-item 1")))
483 ;; Preserve blank lines.
486 "- item 2\n\n- item 1"
487 (org-test-with-temp-text "- item 1\n\n- item 2"
490 ;; Error when trying to move the last item...
491 (org-test-with-temp-text "- item 1\n- item 2"
493 (should-error (org-move-item-down)))
494 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
495 ;; case, move to the first item.
496 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
498 (let ((org-list-use-circular-motion t
)) (org-move-item-down))
499 (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
500 ;; Preserve item visibility.
501 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
502 (let ((org-cycle-include-plain-lists t
))
503 (search-forward "- item 1")
505 (search-forward "- item 2")
507 (search-backward "- item 1")
510 (should (org-invisible-p2))
511 (search-backward " body 2")
512 (should (org-invisible-p2)))
513 ;; Preserve children visibility.
514 (org-test-with-temp-text "* Headline
521 (let ((org-cycle-include-plain-lists t
))
522 (search-forward "- sub-item 1")
524 (search-forward "- sub-item 2")
526 (search-backward "- item 1")
528 (search-forward "sub-body 1")
529 (should (org-invisible-p2))
530 (search-backward "sub-body 2")
531 (should (org-invisible-p2))))
533 (ert-deftest test-org-list
/move-item-down-contents-visibility
()
534 "Preserve contents visibility."
535 (org-test-with-temp-text "
545 (let ((invisible-property-1
547 (search-forward "Text1")
548 (get-char-property (point) 'invisible
)))
549 (invisible-property-2
551 (search-forward "Text2")
552 (get-char-property (point) 'invisible
))))
553 (goto-char (point-min))
554 (search-forward "- item 1")
556 (search-forward "Text1")
557 (should (eq invisible-property-1
(get-char-property (point) 'invisible
)))
558 (search-backward "Text2")
559 (should (eq invisible-property-2
(get-char-property (point) 'invisible
))))))
561 (ert-deftest test-org-list
/move-item-up
()
562 "Test `org-move-item-up' specifications."
564 (org-test-with-temp-text "- item 1\n- item 2"
567 (should (equal (buffer-string)
568 "- item 2\n- item 1")))
569 ;; Keep same column in item.
570 (org-test-with-temp-text "- item 1\n- item 2"
574 (should (looking-at "em 2")))
576 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
579 (should (equal (buffer-string)
580 "- item 2\n - sub-item 2\n- item 1")))
581 ;; Preserve blank lines.
584 "- item 2\n\n- item 1"
585 (org-test-with-temp-text "- item 1\n\n- item 2"
586 (search-forward "- item 2")
589 ;; Error when trying to move the first item...
590 (org-test-with-temp-text "- item 1\n- item 2"
591 (should-error (org-move-item-up)))
592 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
593 ;; case, move to the first item.
594 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
595 (let ((org-list-use-circular-motion t
)) (org-move-item-up))
596 (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
597 ;; Preserve item visibility.
598 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
599 (let ((org-cycle-include-plain-lists t
))
600 (search-forward "- item 1")
602 (search-forward "- item 2")
606 (should (org-invisible-p2))
607 (search-forward " body 1")
608 (should (org-invisible-p2)))
609 ;; Preserve children visibility.
610 (org-test-with-temp-text "* Headline
617 (let ((org-cycle-include-plain-lists t
))
618 (search-forward "- sub-item 1")
620 (search-forward "- sub-item 2")
622 (search-backward "- item 2")
624 (search-forward "sub-body 2")
625 (should (org-invisible-p2))
626 (search-forward "sub-body 1")
627 (should (org-invisible-p2))))
629 (ert-deftest test-org-list
/move-item-up-contents-visibility
()
630 (org-test-with-temp-text "
640 (let ((invisible-property-1
642 (search-forward "Text1")
643 (get-char-property (point) 'invisible
)))
644 (invisible-property-2
646 (search-forward "Text2")
647 (get-char-property (point) 'invisible
))))
648 (goto-char (point-min))
649 (search-forward "- item 2")
651 (search-forward "Text2")
652 (should (eq invisible-property-2
(get-char-property (point) 'invisible
)))
653 (search-forward "Text1")
654 (should (eq invisible-property-1
(get-char-property (point) 'invisible
))))))
656 (ert-deftest test-org-list
/insert-item
()
657 "Test item insertion."
658 ;; Blank lines specifications.
660 ;; Non-nil `org-blank-before-new-entry': insert a blank line.
662 (org-test-with-temp-text "- a"
663 (let ((org-blank-before-new-entry '((plain-list-item . t
))))
668 ;; Nil `org-blank-before-new-entry': do not insert a blank line.
670 (org-test-with-temp-text "- a"
671 (let ((org-blank-before-new-entry '((plain-list-item . nil
))))
676 ;; `org-blank-before-new-entry' set to auto: if there's no blank
677 ;; line already in the sole item, do not insert one.
679 (org-test-with-temp-text "- a"
680 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
685 ;; `org-blank-before-new-entry' set to `auto': if there's a blank
686 ;; line in the sole item, insert another one.
688 (org-test-with-temp-text "- a\n\n b<point>"
689 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
693 ;; `org-blank-before-new-entry' set to `auto': if the user specified
694 ;; a blank line, preserve it.
696 (org-test-with-temp-text "- a\n\n<point>"
697 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
701 ;; `org-blank-before-new-entry' set to `auto': if some items in list
702 ;; are already separated by blank lines, insert one.
704 (org-test-with-temp-text "- a\n\n- b<point>"
705 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
710 (org-test-with-temp-text "- a\n\n- b"
711 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
716 (org-test-with-temp-text
717 "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE<point>"
718 (let ((org-blank-before-new-entry '((plain-list-item . auto
))))
722 ;; When called before or on the bullet, insert new item before
726 (org-test-with-temp-text "- item"
731 (org-test-with-temp-text "- <point>item"
734 ;; When called on tag in a descriptive list, insert new item before
737 (equal "- :: \n- tag :: item"
738 (org-test-with-temp-text "- tag <point>:: item"
742 (equal "- :: \n- tag :: item"
743 (org-test-with-temp-text "- ta<point>g :: item"
746 ;; Further, it splits the line or add a blank new item after it,
747 ;; according to `org-M-RET-may-split-line'.
750 (org-test-with-temp-text "- it<point>em"
751 (let ((org-M-RET-may-split-line '((default . t
))))
756 (org-test-with-temp-text "- it<point>em"
757 (let ((org-M-RET-may-split-line '((default . nil
))))
761 (ert-deftest test-org-list
/repair
()
762 "Test `org-list-repair' specifications."
763 ;; Repair indentation.
765 (equal "- item\n - child"
766 (org-test-with-temp-text "- item\n - child"
767 (let ((org-list-indent-offset 0)) (org-list-repair))
769 ;; Repair bullets and numbering.
772 (org-test-with-temp-text "- a\n+ b"
773 (let ((org-list-indent-offset 0))
778 (org-test-with-temp-text "1. a\n1. b"
779 (let ((org-list-indent-offset 0)
780 (org-plain-list-ordered-item-terminator t
))
783 ;; Repair check-boxes.
785 (equal "- [X] item\n - [X] child"
786 (org-test-with-temp-text "- [ ] item\n - [X] child"
787 (let ((org-list-indent-offset 0))
790 ;; Special case: do not move contents of an item within its child.
791 ;; Yet, preserve indentation differences within contents.
793 (equal "- item\n - child\n within item"
794 (org-test-with-temp-text "- item\n - child\n within item"
795 (let ((org-list-indent-offset 0)) (org-list-repair))
799 "- item\n - child\n within item\n indented"
800 (org-test-with-temp-text
801 "- item\n - child\n within item\n indented"
802 (let ((org-list-indent-offset 0)) (org-list-repair))
805 (ert-deftest test-org-list
/update-checkbox-count
()
806 "Test `org-update-checkbox-count' specifications."
809 (string-match "\\[0/1\\]"
810 (org-test-with-temp-text "* [/]\n- [ ] item"
811 (org-update-checkbox-count)
814 (string-match "\\[1/1\\]"
815 (org-test-with-temp-text "* [/]\n- [X] item"
816 (org-update-checkbox-count)
819 (string-match "\\[100%\\]"
820 (org-test-with-temp-text "* [%]\n- [X] item"
821 (org-update-checkbox-count)
823 ;; From a list or a sub-list.
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)
842 (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
843 (org-update-checkbox-count)
845 ;; Count do not apply to sub-lists unless count is not hierarchical.
846 ;; This state can be achieved with COOKIE_DATA node property set to
849 (string-match "\\[1/1\\]"
850 (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
851 (let ((org-checkbox-hierarchical-statistics nil
))
852 (org-update-checkbox-count))
855 (string-match "\\[1/1\\]"
856 (org-test-with-temp-text "
859 :COOKIE_DATA: recursive
864 (org-update-checkbox-count)
867 (string-match "\\[0/0\\]"
868 (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
869 (org-update-checkbox-count)
871 ;; With optional argument ALL, update all buffer.
874 (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
875 (org-update-checkbox-count t
)
876 (count-matches "\\[1/1\\]"))))
877 ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
880 (string-match "\\[2/2\\]"
881 (org-test-with-temp-text "
888 (let ((org-checkbox-hierarchical-statistics nil
))
889 (org-update-checkbox-count))
896 (ert-deftest test-org-list
/toggle-item
()
897 "Test `org-toggle-item' specifications."
898 ;; Convert normal lines to items.
901 (org-test-with-temp-text "line"
902 (org-toggle-item nil
)
904 ;; Convert items to normal lines.
907 (org-test-with-temp-text "- line"
908 (org-toggle-item nil
)
910 ;; Convert headlines to items.
913 (org-test-with-temp-text "* line"
914 (org-toggle-item nil
)
916 ;; When converting a headline to a list item, TODO keywords become
920 (org-test-with-temp-text "* DONE line"
921 (org-toggle-item nil
)
925 (org-test-with-temp-text "* TODO line"
926 (org-toggle-item nil
)
928 ;; When a region is marked and first line is a headline, all
929 ;; headlines are turned into items.
932 (org-test-with-temp-text "* H1\n** H2"
933 (transient-mark-mode 1)
934 (push-mark (point) t t
)
935 (goto-char (point-max))
936 (org-toggle-item nil
)
939 (equal "- [ ] H1\n - [ ] H2"
940 (org-test-with-temp-text "* TODO H1\n** TODO H2"
941 (transient-mark-mode 1)
942 (push-mark (point) t t
)
943 (goto-char (point-max))
944 (org-toggle-item nil
)
946 ;; When turning headlines into items, make sure headings contents
947 ;; are kept within items.
950 (org-test-with-temp-text "* H1\nText"
951 (transient-mark-mode 1)
952 (push-mark (point) t t
)
953 (goto-char (point-max))
954 (org-toggle-item nil
)
956 ;; When a region is marked and first line is an item, all items are
957 ;; turned into normal lines.
960 (org-test-with-temp-text "- 1\n - 2"
961 (transient-mark-mode 1)
962 (push-mark (point) t t
)
963 (goto-char (point-max))
964 (org-toggle-item nil
)
968 (org-test-with-temp-text "- 1\n2"
969 (transient-mark-mode 1)
970 (push-mark (point) t t
)
971 (goto-char (point-max))
972 (org-toggle-item nil
)
974 ;; When a region is marked and first line is an item, all normal
975 ;; lines are turned into items.
977 (equal "- line 1\n- line 2"
978 (org-test-with-temp-text "line 1\nline 2"
979 (transient-mark-mode 1)
980 (push-mark (point) t t
)
981 (goto-char (point-max))
982 (org-toggle-item nil
)
985 (equal "- line 1\n- line 2"
986 (org-test-with-temp-text "line 1\n- line 2"
987 (transient-mark-mode 1)
988 (push-mark (point) t t
)
989 (goto-char (point-max))
990 (org-toggle-item nil
)
992 ;; When argument ARG is non-nil, change the whole region into
995 (equal "- line 1\n line 2"
996 (org-test-with-temp-text "line 1\nline 2"
997 (transient-mark-mode 1)
998 (push-mark (point) t t
)
999 (goto-char (point-max))
1006 (ert-deftest test-org-list
/send-list
()
1007 "Test various checks for `org-list-send-list'."
1008 ;; Error when not at a list item.
1010 (org-test-with-temp-text "Not a list item"
1011 (org-list-send-list)))
1012 ;; Error when ORGLST line is not provided.
1014 (org-test-with-temp-text "- item"
1015 (org-list-send-list)))
1016 ;; Error when transformation function is unknown.
1018 (org-test-with-temp-text "@ignore
1019 #+ORGLST: SEND list unknown-function
1023 (org-list-send-list)))
1024 ;; Error when receiving location is not defined.
1026 (org-test-with-temp-text "@ignore
1027 #+ORGLST: SEND list org-list-to-texinfo
1031 (org-list-send-list)))
1032 ;; Error when insertion region is ill-formed.
1034 (org-test-with-temp-text "@c BEGIN RECEIVE ORGLST list
1036 #+ORGLST: SEND list org-list-to-texinfo
1040 (org-list-send-list)))
1041 ;; Allow multiple receiver locations.
1043 (org-test-with-temp-text "
1044 @c BEGIN RECEIVE ORGLST list
1045 @c END RECEIVE ORGLST list
1048 #+ORGLST: SEND list org-list-to-texinfo
1049 <point>- item contents
1052 @c BEGIN RECEIVE ORGLST list
1053 @c END RECEIVE ORGLST list"
1054 (org-list-send-list)
1055 (goto-char (point-min))
1056 (search-forward "item contents" nil t
3))))
1058 (ert-deftest test-org-list
/to-generic
()
1059 "Test `org-list-to-generic' specifications."
1060 ;; Test `:ustart' and `:uend' parameters.
1064 (org-test-with-temp-text "- a"
1065 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1069 (org-test-with-temp-text "1. a"
1070 (org-list-to-generic (org-list-to-lisp) '(:ustart
"begin")))))
1074 (org-test-with-temp-text "- a"
1075 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1079 (org-test-with-temp-text "1. a"
1080 (org-list-to-generic (org-list-to-lisp) '(:uend
"end")))))
1083 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1084 (org-test-with-temp-text "- a\n - b"
1085 (org-list-to-generic
1087 (list :ustart
(lambda (l) (format "begin l%d" l
))
1088 :uend
(lambda (l) (format "end l%d" l
)))))))
1089 ;; Test `:ostart' and `:oend' parameters.
1093 (org-test-with-temp-text "1. a"
1094 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1098 (org-test-with-temp-text "- a"
1099 (org-list-to-generic (org-list-to-lisp) '(:ostart
"begin")))))
1103 (org-test-with-temp-text "1. a"
1104 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1108 (org-test-with-temp-text "- a"
1109 (org-list-to-generic (org-list-to-lisp) '(:oend
"end")))))
1112 "begin l1\na\nbegin l2\nb\nend l2\nend l1"
1113 (org-test-with-temp-text "1. a\n 1. b"
1114 (org-list-to-generic
1116 (list :ostart
(lambda (l) (format "begin l%d" l
))
1117 :oend
(lambda (l) (format "end l%d" l
)))))))
1118 ;; Test `:dstart' and `:dend' parameters.
1122 (org-test-with-temp-text "- tag :: a"
1123 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1127 (org-test-with-temp-text "- a"
1128 (org-list-to-generic (org-list-to-lisp) '(:dstart
"begin")))))
1132 (org-test-with-temp-text "- tag :: a"
1133 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1137 (org-test-with-temp-text "- a"
1138 (org-list-to-generic (org-list-to-lisp) '(:dend
"end")))))
1141 "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
1142 (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
1143 (org-list-to-generic
1145 (list :dstart
(lambda (l) (format "begin l%d" l
))
1146 :dend
(lambda (l) (format "end l%d" l
)))))))
1147 ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
1151 (org-test-with-temp-text "- tag :: a"
1152 (org-list-to-generic (org-list-to-lisp) '(:dtstart
">" :dtend
"<")))))
1156 (org-test-with-temp-text "- tag :: a"
1157 (org-list-to-generic (org-list-to-lisp) '(:ddstart
">" :ddend
"<")))))
1158 ;; Test `:istart' and `:iend' parameters.
1162 (org-test-with-temp-text "- a"
1163 (org-list-to-generic (org-list-to-lisp) '(:istart
"start")))))
1166 "level1 a\nlevel2 b"
1167 (org-test-with-temp-text "- a\n - b"
1168 (org-list-to-generic (org-list-to-lisp)
1169 '(:istart
(lambda (l) (format "level%d "l
)))))))
1173 (org-test-with-temp-text "- a\n - b"
1174 (org-list-to-generic (org-list-to-lisp)
1175 '(:iend
(lambda (l) (format "level%d" l
)))))))
1176 ;; Test `:icount' parameter.
1180 (org-test-with-temp-text "1. [@3] a"
1181 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1185 (org-test-with-temp-text "1. a"
1186 (org-list-to-generic (org-list-to-lisp) '(:icount
"count")))))
1190 (org-test-with-temp-text "1. [@3] a"
1191 (org-list-to-generic (org-list-to-lisp)
1192 '(:icount
"count" :istart
"start")))))
1195 "level:1, counter:3 a"
1196 (org-test-with-temp-text "1. [@3] a"
1197 (org-list-to-generic
1199 '(:icount
(lambda (l c
) (format "level:%d, counter:%d " l c
)))))))
1200 ;; Test `:isep' parameter.
1204 (org-test-with-temp-text "- a\n- b"
1205 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1209 (org-test-with-temp-text "- a\n - b"
1210 (org-list-to-generic (org-list-to-lisp) '(:isep
"--")))))
1214 (org-test-with-temp-text "- a\n- b"
1215 (org-list-to-generic (org-list-to-lisp)
1216 '(:isep
(lambda (l) (format "- %d -" l
)))))))
1217 ;; Test `:cbon', `:cboff', `:cbtrans'
1221 (org-test-with-temp-text "- [X] a"
1222 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!")))))
1226 (org-test-with-temp-text "- [X] a"
1227 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!" :cbtrans
"!")))))
1231 (org-test-with-temp-text "- [ ] a"
1232 (org-list-to-generic (org-list-to-lisp) '(:cboff
"!")))))
1236 (org-test-with-temp-text "- [ ] a"
1237 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cbtrans
"!")))))
1241 (org-test-with-temp-text "- [-] a"
1242 (org-list-to-generic (org-list-to-lisp) '(:cbtrans
"!")))))
1246 (org-test-with-temp-text "- [-] a"
1247 (org-list-to-generic (org-list-to-lisp) '(:cbon
"!" :cboff
"!")))))
1248 ;; Test `:splice' parameter.
1252 (org-test-with-temp-text "- a"
1253 (org-list-to-generic (org-list-to-lisp)
1254 '(:ustart
"begin" :uend
"end" :splice t
)))))
1255 ;; No error on empty lists.
1257 (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil
))))
1259 (ert-deftest test-org-list
/to-html
()
1260 "Test `org-list-to-html' specifications."
1262 (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
1263 (let (org-html-indent)
1265 (insert "<!-- BEGIN RECEIVE ORGLST name -->
1266 <!-- END RECEIVE ORGLST name -->
1268 #+ORGLST: SEND name org-list-to-html
1271 (goto-char (point-min))
1272 (re-search-forward "^- a" nil t
)
1274 (org-list-send-list)
1276 (buffer-substring-no-properties
1278 (progn (re-search-forward "^<!-- END" nil t
)
1280 (skip-chars-backward " \r\t\n")
1283 (ert-deftest test-org-list
/to-latex
()
1284 "Test `org-list-to-latex' specifications."
1286 (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
1288 (insert "% BEGIN RECEIVE ORGLST name
1289 % END RECEIVE ORGLST name
1291 #+ORGLST: SEND name org-list-to-latex
1294 (goto-char (point-min))
1295 (re-search-forward "^- a" nil t
)
1297 (org-list-send-list)
1299 (buffer-substring-no-properties
1301 (progn (re-search-forward "^% END" nil t
)
1303 (skip-chars-backward " \r\t\n")
1306 (ert-deftest test-org-list
/to-texinfo
()
1307 "Test `org-list-to-texinfo' specifications."
1309 (equal "@itemize\n@item\na\n@end itemize"
1311 (insert "@c BEGIN RECEIVE ORGLST name
1312 @c END RECEIVE ORGLST name
1314 #+ORGLST: SEND name org-list-to-texinfo
1317 (goto-char (point-min))
1318 (re-search-forward "^- a" nil t
)
1320 (org-list-send-list)
1322 (buffer-substring-no-properties
1324 (progn (re-search-forward "^@c END" nil t
)
1326 (skip-chars-backward " \r\t\n")
1330 (provide 'test-org-list
)
1331 ;;; test-org-list.el ends here