lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / testing / lisp / test-org-list.el
blobc3864caa4a5fe81656ddaa7e604ae443a3684fe5
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/>.
20 ;;; Code:
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"
26 (goto-line 4)
27 (should-not (org-in-item-p)))
28 ;; With text less indented than top items.
29 (org-test-with-temp-text "- item\nText"
30 (goto-line 2)
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"
35 (goto-line 7)
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 "
41 - item A
42 - item B
45 - item 1
46 - item 1.1
47 - item 1.2
48 - item 1.3
49 - item 2
52 - item X
53 - item Y"
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'
59 ;; is non-nil.
60 (goto-line 9)
61 (should-error (org-next-item))
62 (let ((org-list-use-circular-motion t))
63 (should (progn (org-next-item) t)))
64 (goto-line 14)
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.
69 (goto-line 6)
70 (org-next-item)
71 (should (looking-at "- item 2"))
72 ;; 1.3. Shouldn't move to another list.
73 (goto-line 3)
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))
79 (goto-line 10)
80 (org-next-item)
81 (should (looking-at "- item 1"))
82 (goto-line 9)
83 (org-next-item)
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
89 ;; non-nil.
90 (goto-line 7)
91 (should-error (org-previous-item))
92 (let ((org-list-use-circular-motion t))
93 (should (progn (org-previous-item) t)))
94 (goto-line 13)
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.
99 (goto-line 10)
100 (org-previous-item)
101 (should (looking-at "- item 1"))
102 ;; 2.3. Shouldn't move to another list.
103 (goto-line 6)
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))
109 (goto-line 6)
110 (org-previous-item)
111 (should (looking-at "- item 2"))
112 (goto-line 7)
113 (org-previous-item)
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.
119 (should-error
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.
135 (should
136 (equal "1. item"
137 (org-test-with-temp-text "- item"
138 (let ((org-plain-list-ordered-item-terminator t))
139 (org-cycle-list-bullet "1.")
140 (buffer-string)))))
141 ;; Argument is an integer N: cycle to the Nth allowed bullet.
142 (should
143 (equal "+ item"
144 (org-test-with-temp-text "1. item"
145 (let ((org-plain-list-ordered-item-terminator t))
146 (org-cycle-list-bullet 1)
147 (buffer-string)))))
148 ;; Argument is `previous': cycle backwards.
149 (should
150 (equal "- item"
151 (org-test-with-temp-text "+ item"
152 (let ((org-plain-list-ordered-item-terminator t))
153 (org-cycle-list-bullet 'previous)
154 (buffer-string)))))
155 ;; Do not cycle to "*" bullets when item is at column 0.
156 (should
157 (equal "1. item"
158 (org-test-with-temp-text "+ item"
159 (let ((org-plain-list-ordered-item-terminator t))
160 (org-cycle-list-bullet)
161 (buffer-string)))))
162 ;; Do not cycle to numbered bullets in a description list.
163 (should-not
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)
168 (buffer-string)))))
169 ;; Do not cycle to ordered item terminators if they are not allowed
170 ;; in `org-plain-list-ordered-item-terminator'.
171 (should
172 (equal " 1) item"
173 (org-test-with-temp-text " * item"
174 (let ((org-plain-list-ordered-item-terminator 41))
175 (org-cycle-list-bullet)
176 (buffer-string)))))
177 ;; When `org-list-allow-alphabetical' is non-nil, cycle to alpha bullets.
178 (should
179 (equal "a. item"
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)
184 (buffer-string)))))
185 ;; Do not cycle to alpha bullets when list has more than 26
186 ;; elements.
187 (should-not
188 (equal "a. item 1"
189 (org-test-with-temp-text "1) item 1
190 2) item 2
191 3) item 3
192 4) item 4
193 5) item 5
194 6) item 6
195 7) item 7
196 8) item 8
197 9) item 9
198 10) item 10
199 11) item 11
200 12) item 12
201 13) item 13
202 14) item 14
203 15) item 15
204 16) item 16
205 17) item 17
206 18) item 18
207 19) item 19
208 20) item 20
209 21) item 21
210 22) item 22
211 23) item 23
212 24) item 24
213 25) item 25
214 26) item 26
215 27) item 27"
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.
227 (should-error
228 (org-test-with-temp-text "
229 - Item 1
230 - Item 2"
231 (forward-line)
232 (org-indent-item)))
233 (should-error
234 (org-test-with-temp-text "
235 - Item 1
236 - Item 2"
237 (forward-line)
238 (let ((org-list-automatic-rules nil)) (org-indent-item))))
239 ;; Indent a single item, not its children.
240 (should
241 (equal "
242 - Item 1
243 - Item 2
244 - Item 2.1"
245 (org-test-with-temp-text "
246 - Item 1
247 - Item 2<point>
248 - Item 2.1"
249 (let (org-list-demote-modify-bullet) (org-indent-item))
250 (buffer-string))))
251 ;; Follow `org-list-demote-modify-bullet' specifications.
252 (should
253 (equal "
254 - Item 1
255 + Item 2"
256 (org-test-with-temp-text "
257 - Item 1
258 - Item 2<point>"
259 (let ((org-list-demote-modify-bullet '(("-" . "+"))))
260 (org-indent-item))
261 (buffer-string))))
262 (should
263 (equal "
264 1. Item 1
265 + Item 2"
266 (org-test-with-temp-text "
267 1. Item 1
268 2. Item 2<point>"
269 (let ((org-plain-list-ordered-item-terminator t)
270 (org-list-demote-modify-bullet '(("1." . "+"))))
271 (org-indent-item))
272 (buffer-string))))
273 (should
274 (equal "
275 a. Item 1
276 - Item 2"
277 (org-test-with-temp-text "
278 a. Item 1
279 b. Item 2<point>"
280 (let ((org-plain-list-ordered-item-terminator t)
281 (org-list-allow-alphabetical t)
282 (org-list-demote-modify-bullet '(("A." . "a.") ("a." . "-"))))
283 (org-indent-item))
284 (buffer-string))))
285 ;; When a region is selected, indent every item within.
286 (should
287 (equal "
288 - Item 1
289 - Item 2
290 - Item 3
292 (org-test-with-temp-text "
293 - Item 1
294 <point>- Item 2
295 - Item 3
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))
301 (buffer-string)))))
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 "
310 - Item 1
311 - Item 2
312 - Item 2.1"
313 (search-forward "- Item 2")
314 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
315 (should (equal (buffer-string)
317 - Item 1
318 - Item 2
319 - Item 2.1")))
320 ;; 3. Special case: When indenting top item, move the whole list.
321 (org-test-with-temp-text "
322 - Item 1
323 - Item 2"
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)
329 - Item 1
330 - Item 2")))
331 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
333 ;; 4.1. With unordered lists.
334 (org-test-with-temp-text "
335 - Item 1
336 - Item 2
337 + Item 2.1"
338 (search-forward "- Item 2")
339 (let ((org-list-demote-modify-bullet '(("-" . "+") ("+" . "-"))))
340 (org-indent-item-tree))
341 (should (equal (buffer-string)
343 - Item 1
344 + Item 2
345 - Item 2.1")))
346 ;; 4.2. and ordered lists.
347 (org-test-with-temp-text "
348 1. Item 1
349 2. Item 2
350 + Item 2.1"
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)
357 1. Item 1
358 + Item 2
359 1. Item 2.1")))
360 ;; 5. When a region is selected, indent every item within.
361 (org-test-with-temp-text "
362 - Item 1
363 - Item 2
364 - Item 2.1
365 - Item 3
366 - Item 3.1
368 (search-forward "- Item 2")
369 (beginning-of-line)
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)
376 - Item 1
377 - Item 2
378 - Item 2.1
379 - Item 3
380 - Item 3.1
381 "))))
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 "
390 - Item 1
391 - Item 2"
392 (forward-line)
393 (should-error (org-outdent-item)))
394 ;; 3. Error when trying to outdent an item without its children.
395 (org-test-with-temp-text "
396 - Item 1
397 - Item 1.1
398 - Item 1.1.1"
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 "
403 - Item 1
404 - Item 2"
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 "
409 - Item 1
410 - Item 2
411 - Item 3
413 (search-forward "- Item 2")
414 (beginning-of-line)
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)
421 - Item 1
422 - Item 2
423 - Item 3
424 "))))
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 "
433 - Item 1
434 - Item 2"
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 "
439 - Item 1
440 - Item 2
441 - Item 2.1"
442 (search-forward "- Item 2")
443 (org-outdent-item-tree)
444 (should (equal (buffer-string)
446 - Item 1
447 - Item 2
448 - Item 2.1")))
449 ;; 3. Special case: When outdenting top item, move the whole list.
450 (org-test-with-temp-text "
451 - Item 1
452 - Item 2"
453 (search-forward "- Item 1")
454 (let (org-odd-levels-only) (org-outdent-item-tree))
455 (should (equal (buffer-string)
457 - Item 1
458 - Item 2")))
459 ;; 5. When a region is selected, outdent every item within.
460 (org-test-with-temp-text "
461 - Item 1
462 - Item 2
463 - Item 2.1
464 - Item 3
465 - Item 3.1
467 (search-forward "- Item 2")
468 (beginning-of-line)
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)
475 - Item 1
476 - Item 2
477 - Item 2.1
478 - Item 3
479 - Item 3.1
480 "))))
482 (ert-deftest test-org-list/move-item-down ()
483 "Test `org-move-item-down' specifications."
484 ;; Standard test.
485 (org-test-with-temp-text "- item 1\n- item 2"
486 (org-move-item-down)
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"
491 (forward-char 4)
492 (org-move-item-down)
493 (should (looking-at "em 1")))
494 ;; Move sub-items.
495 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
496 (org-move-item-down)
497 (should (equal (buffer-string)
498 "- item 2\n- item 1\n - sub-item 1")))
499 ;; Preserve blank lines.
500 (should
501 (equal
502 "- item 2\n\n- item 1"
503 (org-test-with-temp-text "- item 1\n\n- item 2"
504 (org-move-item-down)
505 (buffer-string))))
506 ;; Error when trying to move the last item...
507 (org-test-with-temp-text "- item 1\n- item 2"
508 (forward-line)
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"
513 (forward-line 2)
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")
520 (org-cycle)
521 (search-forward "- item 2")
522 (org-cycle))
523 (search-backward "- item 1")
524 (org-move-item-down)
525 (forward-line)
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
531 - item 1
532 - sub-item 1
533 sub-body 1
534 - item 2
535 - sub-item 2
536 sub-body 2"
537 (let ((org-cycle-include-plain-lists t))
538 (search-forward "- sub-item 1")
539 (org-cycle)
540 (search-forward "- sub-item 2")
541 (org-cycle))
542 (search-backward "- item 1")
543 (org-move-item-down)
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 "
552 - item 1
553 #+BEGIN_CENTER
554 Text1
555 #+END_CENTER
556 - item 2
557 #+BEGIN_CENTER
558 Text2
559 #+END_CENTER"
560 (org-hide-block-all)
561 (let ((invisible-property-1
562 (progn
563 (search-forward "Text1")
564 (get-char-property (point) 'invisible)))
565 (invisible-property-2
566 (progn
567 (search-forward "Text2")
568 (get-char-property (point) 'invisible))))
569 (goto-char (point-min))
570 (search-forward "- item 1")
571 (org-move-item-down)
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."
579 ;; Standard test.
580 (org-test-with-temp-text "- item 1\n- item 2"
581 (forward-line)
582 (org-move-item-up)
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"
587 (forward-line)
588 (forward-char 4)
589 (org-move-item-up)
590 (should (looking-at "em 2")))
591 ;; Move sub-items.
592 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
593 (forward-line)
594 (org-move-item-up)
595 (should (equal (buffer-string)
596 "- item 2\n - sub-item 2\n- item 1")))
597 ;; Preserve blank lines.
598 (should
599 (equal
600 "- item 2\n\n- item 1"
601 (org-test-with-temp-text "- item 1\n\n- item 2"
602 (search-forward "- item 2")
603 (org-move-item-up)
604 (buffer-string))))
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")
617 (org-cycle)
618 (search-forward "- item 2")
619 (org-cycle))
620 (org-move-item-up)
621 (forward-line)
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
627 - item 1
628 - sub-item 1
629 sub-body 1
630 - item 2
631 - sub-item 2
632 sub-body 2"
633 (let ((org-cycle-include-plain-lists t))
634 (search-forward "- sub-item 1")
635 (org-cycle)
636 (search-forward "- sub-item 2")
637 (org-cycle))
638 (search-backward "- item 2")
639 (org-move-item-up)
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 "
647 - item 1
648 #+BEGIN_CENTER
649 Text1
650 #+END_CENTER
651 - item 2
652 #+BEGIN_CENTER
653 Text2
654 #+END_CENTER"
655 (org-hide-block-all)
656 (let ((invisible-property-1
657 (progn
658 (search-forward "Text1")
659 (get-char-property (point) 'invisible)))
660 (invisible-property-2
661 (progn
662 (search-forward "Text2")
663 (get-char-property (point) 'invisible))))
664 (goto-char (point-min))
665 (search-forward "- item 2")
666 (org-move-item-up)
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.
677 (should
678 (org-test-with-temp-text "- a"
679 (let ((org-blank-before-new-entry '((plain-list-item . t))))
680 (end-of-line)
681 (org-insert-item)
682 (forward-line -1)
683 (looking-at "$"))))
684 ;; Nil `org-blank-before-new-entry': do not insert a blank line.
685 (should-not
686 (org-test-with-temp-text "- a"
687 (let ((org-blank-before-new-entry '((plain-list-item . nil))))
688 (end-of-line)
689 (org-insert-item)
690 (forward-line -1)
691 (looking-at "$"))))
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.
694 (should-not
695 (org-test-with-temp-text "- a"
696 (let ((org-blank-before-new-entry '((plain-list-item . auto))))
697 (end-of-line)
698 (org-insert-item)
699 (forward-line -1)
700 (looking-at "$"))))
701 ;; `org-blank-before-new-entry' set to `auto': if there's a blank
702 ;; line in the sole item, insert another one.
703 (should
704 (org-test-with-temp-text "- a\n\n b<point>"
705 (let ((org-blank-before-new-entry '((plain-list-item . auto))))
706 (org-insert-item)
707 (forward-line -1)
708 (looking-at "$"))))
709 ;; `org-blank-before-new-entry' set to `auto': if the user specified
710 ;; a blank line, preserve it.
711 (should
712 (org-test-with-temp-text "- a\n\n<point>"
713 (let ((org-blank-before-new-entry '((plain-list-item . auto))))
714 (org-insert-item)
715 (forward-line -1)
716 (looking-at "$"))))
717 ;; `org-blank-before-new-entry' set to `auto': if some items in list
718 ;; are already separated by blank lines, insert one.
719 (should
720 (org-test-with-temp-text "- a\n\n- b<point>"
721 (let ((org-blank-before-new-entry '((plain-list-item . auto))))
722 (org-insert-item)
723 (forward-line -1)
724 (looking-at "$"))))
725 (should
726 (org-test-with-temp-text "- a\n\n- b"
727 (let ((org-blank-before-new-entry '((plain-list-item . auto))))
728 (org-insert-item)
729 (forward-line)
730 (looking-at "$"))))
731 (should
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))))
735 (org-insert-item)
736 (forward-line -1)
737 (looking-at "$"))))
738 ;; When called before or on the bullet, insert new item before
739 ;; current one.
740 (should
741 (equal "- \n- item"
742 (org-test-with-temp-text "- item"
743 (org-insert-item)
744 (buffer-string))))
745 (should
746 (equal "- \n- item"
747 (org-test-with-temp-text "- <point>item"
748 (org-insert-item)
749 (buffer-string))))
750 ;; When called on tag in a descriptive list, insert new item before
751 ;; current one too.
752 (should
753 (equal "- :: \n- tag :: item"
754 (org-test-with-temp-text "- tag <point>:: item"
755 (org-insert-item)
756 (buffer-string))))
757 (should
758 (equal "- :: \n- tag :: item"
759 (org-test-with-temp-text "- ta<point>g :: item"
760 (org-insert-item)
761 (buffer-string))))
762 ;; Further, it splits the line or add a blank new item after it,
763 ;; according to `org-M-RET-may-split-line'.
764 (should
765 (equal "- it\n- em"
766 (org-test-with-temp-text "- it<point>em"
767 (let ((org-M-RET-may-split-line '((default . t))))
768 (org-insert-item))
769 (buffer-string))))
770 (should
771 (equal "- item\n- "
772 (org-test-with-temp-text "- it<point>em"
773 (let ((org-M-RET-may-split-line '((default . nil))))
774 (org-insert-item))
775 (buffer-string))))
776 ;; Preserve list visibility when inserting an item.
777 (should
778 (equal
779 '(outline outline)
780 (org-test-with-temp-text "- A\n - B\n- C\n - D"
781 (let ((org-cycle-include-plain-lists t))
782 (org-cycle)
783 (forward-line 2)
784 (org-cycle)
785 (org-insert-item)
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.
792 (should
793 (equal "- item\n - child"
794 (org-test-with-temp-text "- item\n - child"
795 (let ((org-list-indent-offset 0)) (org-list-repair))
796 (buffer-string))))
797 ;; Repair bullets and numbering.
798 (should
799 (equal "- a\n- b"
800 (org-test-with-temp-text "- a\n+ b"
801 (let ((org-list-indent-offset 0))
802 (org-list-repair))
803 (buffer-string))))
804 (should
805 (equal "1. a\n2. b"
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))
809 (org-list-repair))
810 (buffer-string))))
811 ;; Repair check-boxes.
812 (should
813 (equal "- [X] item\n - [X] child"
814 (org-test-with-temp-text "- [ ] item\n - [X] child"
815 (let ((org-list-indent-offset 0))
816 (org-list-repair))
817 (buffer-string))))
818 ;; Special case: do not move contents of an item within its child.
819 ;; Yet, preserve indentation differences within contents.
820 (should
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))
824 (buffer-string))))
825 (should
826 (equal
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))
831 (buffer-string)))))
833 (ert-deftest test-org-list/update-checkbox-count ()
834 "Test `org-update-checkbox-count' specifications."
835 ;; From a headline.
836 (should
837 (string-match "\\[0/1\\]"
838 (org-test-with-temp-text "* [/]\n- [ ] item"
839 (org-update-checkbox-count)
840 (buffer-string))))
841 (should
842 (string-match "\\[1/1\\]"
843 (org-test-with-temp-text "* [/]\n- [X] item"
844 (org-update-checkbox-count)
845 (buffer-string))))
846 (should
847 (string-match "\\[100%\\]"
848 (org-test-with-temp-text "* [%]\n- [X] item"
849 (org-update-checkbox-count)
850 (buffer-string))))
851 ;; From a list or a sub-list.
852 (should
853 (string-match "\\[0/1\\]"
854 (org-test-with-temp-text "- [/]\n - [ ] item"
855 (org-update-checkbox-count)
856 (buffer-string))))
857 (should
858 (string-match "\\[1/1\\]"
859 (org-test-with-temp-text "- [/]\n - [X] item"
860 (org-update-checkbox-count)
861 (buffer-string))))
862 (should
863 (string-match "\\[100%\\]"
864 (org-test-with-temp-text "- [%]\n - [X] item"
865 (org-update-checkbox-count)
866 (buffer-string))))
867 (should
868 (string-match
869 "\\[1/1\\]"
870 (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
871 (org-update-checkbox-count)
872 (buffer-string))))
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
875 ;; "recursive".
876 (should
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))
881 (buffer-string))))
882 (should
883 (string-match "\\[1/1\\]"
884 (org-test-with-temp-text "
885 <point>* H
886 :PROPERTIES:
887 :COOKIE_DATA: recursive
888 :END:
889 - [/]
890 - item
891 - [X] sub-item"
892 (org-update-checkbox-count)
893 (buffer-string))))
894 (should
895 (string-match "\\[0/0\\]"
896 (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
897 (org-update-checkbox-count)
898 (buffer-string))))
899 ;; With optional argument ALL, update all buffer.
900 (should
901 (= 2
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
906 ;; outside.
907 (should
908 (string-match "\\[2/2\\]"
909 (org-test-with-temp-text "
910 - [/]
911 - [X] item1
912 :DRAWER:
913 - [X] item
914 :END:
915 - [X] item2"
916 (let ((org-checkbox-hierarchical-statistics nil))
917 (org-update-checkbox-count))
918 (buffer-string)))))
922 ;;; Miscellaneous
924 (ert-deftest test-org-list/toggle-item ()
925 "Test `org-toggle-item' specifications."
926 ;; Convert normal lines to items.
927 (should
928 (equal "- line"
929 (org-test-with-temp-text "line"
930 (org-toggle-item nil)
931 (buffer-string))))
932 ;; Convert items to normal lines.
933 (should
934 (equal "line"
935 (org-test-with-temp-text "- line"
936 (org-toggle-item nil)
937 (buffer-string))))
938 ;; Convert headlines to items.
939 (should
940 (equal "- line"
941 (org-test-with-temp-text "* line"
942 (org-toggle-item nil)
943 (buffer-string))))
944 ;; When converting a headline to a list item, TODO keywords become
945 ;; checkboxes.
946 (should
947 (equal "- [X] line"
948 (org-test-with-temp-text "* DONE line"
949 (org-toggle-item nil)
950 (buffer-string))))
951 (should
952 (equal "- [ ] line"
953 (org-test-with-temp-text "* TODO line"
954 (org-toggle-item nil)
955 (buffer-string))))
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.
959 (should
960 (equal "- H\n"
961 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29 Thu>"
962 (org-toggle-item nil)
963 (buffer-string))))
964 (should
965 (equal "- H\n"
966 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
967 (org-toggle-item nil)
968 (buffer-string))))
969 (should
970 (equal "- H\nText"
971 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n\nText"
972 (org-toggle-item nil)
973 (buffer-string))))
974 ;; When a region is marked and first line is a headline, all
975 ;; headlines are turned into items.
976 (should
977 (equal "- H1\n - H2"
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)
983 (buffer-string))))
984 (should
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)
991 (buffer-string))))
992 ;; When turning headlines into items, make sure headings contents
993 ;; are kept within items.
994 (should
995 (equal "- H1\n Text"
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)
1001 (buffer-string))))
1002 ;; When a region is marked and first line is an item, all items are
1003 ;; turned into normal lines.
1004 (should
1005 (equal "1\n 2"
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)
1011 (buffer-string))))
1012 (should
1013 (equal "1\n2"
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)
1019 (buffer-string))))
1020 ;; When a region is marked and first line is an item, all normal
1021 ;; lines are turned into items.
1022 (should
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)
1029 (buffer-string))))
1030 (should
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)
1037 (buffer-string))))
1038 ;; When argument ARG is non-nil, change the whole region into
1039 ;; a single item.
1040 (should
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))
1046 (org-toggle-item t)
1047 (buffer-string)))))
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))))
1057 (should
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)
1061 (buffer-string))))
1062 (should
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)
1066 (buffer-string))))
1067 ;; Sort alphabetically (with case).
1068 (should
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)
1072 (buffer-string))))
1073 (should
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.
1079 (should
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)
1083 (buffer-string))))
1084 (should
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)
1088 (buffer-string))))
1089 ;; Sort by checked status.
1090 (should
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)
1094 (buffer-string))))
1095 (should
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)
1099 (buffer-string))))
1100 ;; Sort by time stamp.
1101 (should
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)
1106 (buffer-string))))
1107 (should
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)
1112 (buffer-string))))
1113 ;; Sort by custom function.
1114 (should
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
1118 (lambda ()
1119 (length (buffer-substring (point-at-bol)
1120 (point-at-eol))))
1121 #'<)
1122 (buffer-string))))
1123 (should
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
1127 (lambda ()
1128 (length (buffer-substring (point-at-bol)
1129 (point-at-eol))))
1130 #'<)
1131 (buffer-string)))))
1134 ;;; List transformations
1136 (ert-deftest test-org-list/to-generic ()
1137 "Test `org-list-to-generic' specifications."
1138 ;; Test `:ustart' and `:uend' parameters.
1139 (should
1140 (equal
1141 "begin\na"
1142 (org-test-with-temp-text "- a"
1143 (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
1144 (should-not
1145 (equal
1146 "begin\na"
1147 (org-test-with-temp-text "1. a"
1148 (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
1149 (should
1150 (equal
1151 "a\nend"
1152 (org-test-with-temp-text "- a"
1153 (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
1154 (should-not
1155 (equal
1156 "a\nend"
1157 (org-test-with-temp-text "1. a"
1158 (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
1159 (should
1160 (equal
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
1164 (org-list-to-lisp)
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.
1168 (should
1169 (equal
1170 "begin\na"
1171 (org-test-with-temp-text "1. a"
1172 (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
1173 (should-not
1174 (equal
1175 "begin\na"
1176 (org-test-with-temp-text "- a"
1177 (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
1178 (should
1179 (equal
1180 "a\nend"
1181 (org-test-with-temp-text "1. a"
1182 (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
1183 (should-not
1184 (equal
1185 "a\nend"
1186 (org-test-with-temp-text "- a"
1187 (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
1188 (should
1189 (equal
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
1193 (org-list-to-lisp)
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.
1197 (should
1198 (equal
1199 "begin\ntaga"
1200 (org-test-with-temp-text "- tag :: a"
1201 (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
1202 (should-not
1203 (equal
1204 "begin\na"
1205 (org-test-with-temp-text "- a"
1206 (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
1207 (should
1208 (equal
1209 "taga\nend"
1210 (org-test-with-temp-text "- tag :: a"
1211 (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
1212 (should-not
1213 (equal
1214 "a\nend"
1215 (org-test-with-temp-text "- a"
1216 (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
1217 (should
1218 (equal
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
1222 (org-list-to-lisp)
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.
1226 (should
1227 (equal
1228 ">tag<a"
1229 (org-test-with-temp-text "- tag :: a"
1230 (org-list-to-generic (org-list-to-lisp) '(:dtstart ">" :dtend "<")))))
1231 (should
1232 (equal
1233 "tag>a<"
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.
1237 (should
1238 (equal
1239 "starta"
1240 (org-test-with-temp-text "- a"
1241 (org-list-to-generic (org-list-to-lisp) '(:istart "start")))))
1242 (should
1243 (equal
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)))))))
1248 (should
1249 (equal
1250 "a\nblevel2level1"
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.
1255 (should
1256 (equal
1257 "counta"
1258 (org-test-with-temp-text "1. [@3] a"
1259 (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
1260 (should-not
1261 (equal
1262 "counta"
1263 (org-test-with-temp-text "1. a"
1264 (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
1265 (should
1266 (equal
1267 "counta"
1268 (org-test-with-temp-text "1. [@3] a"
1269 (org-list-to-generic (org-list-to-lisp)
1270 '(:icount "count" :istart "start")))))
1271 (should
1272 (equal
1273 "level:1, counter:3 a"
1274 (org-test-with-temp-text "1. [@3] a"
1275 (org-list-to-generic
1276 (org-list-to-lisp)
1277 '(:icount (lambda (type l c) (format "level:%d, counter:%d " l c)))))))
1278 ;; Test `:isep' parameter.
1279 (should
1280 (equal
1281 "a\n--\nb"
1282 (org-test-with-temp-text "- a\n- b"
1283 (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
1284 (should-not
1285 (equal
1286 "a\n--\nb"
1287 (org-test-with-temp-text "- a\n - b"
1288 (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
1289 (should
1290 (equal
1291 "a\n- 1 -\nb"
1292 (org-test-with-temp-text "- a\n- b"
1293 (org-list-to-generic
1294 (org-list-to-lisp)
1295 '(:isep (lambda (type depth) (format "- %d -" depth)))))))
1296 ;; Test `:ifmt' parameter.
1297 (should
1298 (equal
1299 ">> a <<"
1300 (org-test-with-temp-text "1. [@3] a"
1301 (org-list-to-generic
1302 (org-list-to-lisp)
1303 '(:ifmt (lambda (type c) (format ">> %s <<" c)))))))
1304 ;; Test `:cbon', `:cboff', `:cbtrans'
1305 (should
1306 (equal
1307 "!a"
1308 (org-test-with-temp-text "- [X] a"
1309 (org-list-to-generic (org-list-to-lisp) '(:cbon "!")))))
1310 (should-not
1311 (equal
1312 "!a"
1313 (org-test-with-temp-text "- [X] a"
1314 (org-list-to-generic (org-list-to-lisp) '(:cboff "!" :cbtrans "!")))))
1315 (should
1316 (equal
1317 "!a"
1318 (org-test-with-temp-text "- [ ] a"
1319 (org-list-to-generic (org-list-to-lisp) '(:cboff "!")))))
1320 (should-not
1321 (equal
1322 "!a"
1323 (org-test-with-temp-text "- [ ] a"
1324 (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cbtrans "!")))))
1325 (should
1326 (equal
1327 "!a"
1328 (org-test-with-temp-text "- [-] a"
1329 (org-list-to-generic (org-list-to-lisp) '(:cbtrans "!")))))
1330 (should-not
1331 (equal
1332 "!a"
1333 (org-test-with-temp-text "- [-] a"
1334 (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cboff "!")))))
1335 ;; Test `:splice' parameter.
1336 (should
1337 (equal
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.
1343 (should
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."
1348 (should
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."
1355 (should
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."
1362 (should
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."
1369 ;; Un-ordered list.
1370 (should
1371 (equal "- a"
1372 (org-test-with-temp-text "- a"
1373 (org-list-to-org (org-list-to-lisp) nil))))
1374 ;; Ordered list.
1375 (should
1376 (equal "1. a"
1377 (org-test-with-temp-text "1. a"
1378 (org-list-to-org (org-list-to-lisp) nil))))
1379 ;; Descriptive list.
1380 (should
1381 (equal "- a :: b"
1382 (org-test-with-temp-text "- a :: b"
1383 (org-list-to-org (org-list-to-lisp) nil))))
1384 ;; Nested list.
1385 (should
1386 (equal "- a\n - b"
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.
1390 (should
1391 (equal "- a\n b"
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.
1395 (should
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