ox-texinfo: Fix generated label
[org-mode.git] / testing / lisp / test-org-list.el
blob241dafe1cbd941cf18d59e5bc815cbb27970b472
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/>.
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 ;; 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 "
228 - Item 1
229 - Item 2"
230 (forward-line)
231 (should-error (org-indent-item)))
232 ;; 3. Indent a single item, not its children.
233 (org-test-with-temp-text "
234 - Item 1
235 - Item 2
236 - Item 2.1"
237 (search-forward "- Item 2")
238 (let (org-list-demote-modify-bullet) (org-indent-item))
239 (should (equal (buffer-string)
241 - Item 1
242 - Item 2
243 - Item 2.1")))
244 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
246 ;; 4.1. With unordered lists.
247 (org-test-with-temp-text "
248 - Item 1
249 - Item 2"
250 (search-forward "- Item 2")
251 (let ((org-list-demote-modify-bullet '(("-" . "+")))) (org-indent-item))
252 (should (equal (buffer-string)
254 - Item 1
255 + Item 2")))
256 ;; 4.2. and ordered lists.
257 (org-test-with-temp-text "
258 1. Item 1
259 2. Item 2"
260 (search-forward "2. Item 2")
261 (let ((org-plain-list-ordered-item-terminator t)
262 (org-list-demote-modify-bullet '(("1." . "+"))))
263 (org-indent-item))
264 (should (equal (buffer-string)
266 1. Item 1
267 + Item 2")))
268 ;; 5. When a region is selected, indent every item within.
269 (org-test-with-temp-text "
270 - Item 1
271 - Item 2
272 - Item 3
274 (search-forward "- Item 2")
275 (beginning-of-line)
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)
282 - Item 1
283 - Item 2
284 - Item 3
285 "))))
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 "
294 - Item 1
295 - Item 2
296 - Item 2.1"
297 (search-forward "- Item 2")
298 (let (org-list-demote-modify-bullet) (org-indent-item-tree))
299 (should (equal (buffer-string)
301 - Item 1
302 - Item 2
303 - Item 2.1")))
304 ;; 3. Special case: When indenting top item, move the whole list.
305 (org-test-with-temp-text "
306 - Item 1
307 - Item 2"
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)
313 - Item 1
314 - Item 2")))
315 ;; 4. Follow `org-list-demote-modify-bullet' specifications.
317 ;; 4.1. With unordered lists.
318 (org-test-with-temp-text "
319 - Item 1
320 - Item 2
321 + Item 2.1"
322 (search-forward "- Item 2")
323 (let ((org-list-demote-modify-bullet '(("-" . "+") ("+" . "-"))))
324 (org-indent-item-tree))
325 (should (equal (buffer-string)
327 - Item 1
328 + Item 2
329 - Item 2.1")))
330 ;; 4.2. and ordered lists.
331 (org-test-with-temp-text "
332 1. Item 1
333 2. Item 2
334 + Item 2.1"
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)
341 1. Item 1
342 + Item 2
343 1. Item 2.1")))
344 ;; 5. When a region is selected, indent every item within.
345 (org-test-with-temp-text "
346 - Item 1
347 - Item 2
348 - Item 2.1
349 - Item 3
350 - Item 3.1
352 (search-forward "- Item 2")
353 (beginning-of-line)
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)
360 - Item 1
361 - Item 2
362 - Item 2.1
363 - Item 3
364 - Item 3.1
365 "))))
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 "
374 - Item 1
375 - Item 2"
376 (forward-line)
377 (should-error (org-outdent-item)))
378 ;; 3. Error when trying to outdent an item without its children.
379 (org-test-with-temp-text "
380 - Item 1
381 - Item 1.1
382 - Item 1.1.1"
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 "
387 - Item 1
388 - Item 2"
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 "
393 - Item 1
394 - Item 2
395 - Item 3
397 (search-forward "- Item 2")
398 (beginning-of-line)
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)
405 - Item 1
406 - Item 2
407 - Item 3
408 "))))
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 "
417 - Item 1
418 - Item 2"
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 "
423 - Item 1
424 - Item 2
425 - Item 2.1"
426 (search-forward "- Item 2")
427 (org-outdent-item-tree)
428 (should (equal (buffer-string)
430 - Item 1
431 - Item 2
432 - Item 2.1")))
433 ;; 3. Special case: When outdenting top item, move the whole list.
434 (org-test-with-temp-text "
435 - Item 1
436 - Item 2"
437 (search-forward "- Item 1")
438 (let (org-odd-levels-only) (org-outdent-item-tree))
439 (should (equal (buffer-string)
441 - Item 1
442 - Item 2")))
443 ;; 5. When a region is selected, outdent every item within.
444 (org-test-with-temp-text "
445 - Item 1
446 - Item 2
447 - Item 2.1
448 - Item 3
449 - Item 3.1
451 (search-forward "- Item 2")
452 (beginning-of-line)
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)
459 - Item 1
460 - Item 2
461 - Item 2.1
462 - Item 3
463 - Item 3.1
464 "))))
466 (ert-deftest test-org-list/move-item-down ()
467 "Test `org-move-item-down' specifications."
468 ;; Standard test.
469 (org-test-with-temp-text "- item 1\n- item 2"
470 (org-move-item-down)
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"
475 (forward-char 4)
476 (org-move-item-down)
477 (should (looking-at "em 1")))
478 ;; Move sub-items.
479 (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
480 (org-move-item-down)
481 (should (equal (buffer-string)
482 "- item 2\n- item 1\n - sub-item 1")))
483 ;; Preserve blank lines.
484 (org-test-with-temp-text "- item 1\n\n- item 2"
485 (let ((org-list-empty-line-terminates-plain-lists nil)) (org-move-item-down))
486 (should (equal (buffer-string) "- item 2\n\n- item 1")))
487 ;; Error when trying to move the last item...
488 (org-test-with-temp-text "- item 1\n- item 2"
489 (forward-line)
490 (should-error (org-move-item-down)))
491 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
492 ;; case, move to the first item.
493 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
494 (forward-line 2)
495 (let ((org-list-use-circular-motion t)) (org-move-item-down))
496 (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
497 ;; Preserve item visibility.
498 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
499 (let ((org-cycle-include-plain-lists t))
500 (search-forward "- item 1")
501 (org-cycle)
502 (search-forward "- item 2")
503 (org-cycle))
504 (search-backward "- item 1")
505 (org-move-item-down)
506 (forward-line)
507 (should (org-invisible-p2))
508 (search-backward " body 2")
509 (should (org-invisible-p2)))
510 ;; Preserve children visibility.
511 (org-test-with-temp-text "* Headline
512 - item 1
513 - sub-item 1
514 sub-body 1
515 - item 2
516 - sub-item 2
517 sub-body 2"
518 (let ((org-cycle-include-plain-lists t))
519 (search-forward "- sub-item 1")
520 (org-cycle)
521 (search-forward "- sub-item 2")
522 (org-cycle))
523 (search-backward "- item 1")
524 (org-move-item-down)
525 (search-forward "sub-body 1")
526 (should (org-invisible-p2))
527 (search-backward "sub-body 2")
528 (should (org-invisible-p2)))
529 ;; Preserve contents visibility.
530 (org-test-with-temp-text "
531 - item 1
532 #+BEGIN_CENTER
533 Text1
534 #+END_CENTER
535 - item 2
536 #+BEGIN_CENTER
537 Text2
538 #+END_CENTER"
539 (org-hide-block-all)
540 (search-forward "- item 1")
541 (org-move-item-down)
542 (search-forward "Text1")
543 (should (org-invisible-p2))
544 (search-backward "Text2")
545 (should (org-invisible-p2))))
547 (ert-deftest test-org-list/move-item-up ()
548 "Test `org-move-item-up' specifications."
549 ;; Standard test.
550 (org-test-with-temp-text "- item 1\n- item 2"
551 (forward-line)
552 (org-move-item-up)
553 (should (equal (buffer-string)
554 "- item 2\n- item 1")))
555 ;; Keep same column in item.
556 (org-test-with-temp-text "- item 1\n- item 2"
557 (forward-line)
558 (forward-char 4)
559 (org-move-item-up)
560 (should (looking-at "em 2")))
561 ;; Move sub-items.
562 (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
563 (forward-line)
564 (org-move-item-up)
565 (should (equal (buffer-string)
566 "- item 2\n - sub-item 2\n- item 1")))
567 ;; Preserve blank lines.
568 (org-test-with-temp-text "- item 1\n\n- item 2"
569 (search-forward "- item 2")
570 (let ((org-list-empty-line-terminates-plain-lists nil)) (org-move-item-up))
571 (should (equal (buffer-string) "- item 2\n\n- item 1")))
572 ;; Error when trying to move the first item...
573 (org-test-with-temp-text "- item 1\n- item 2"
574 (should-error (org-move-item-up)))
575 ;; ... unless `org-list-use-circular-motion' is non-nil. In this
576 ;; case, move to the first item.
577 (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
578 (let ((org-list-use-circular-motion t)) (org-move-item-up))
579 (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
580 ;; Preserve item visibility.
581 (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
582 (let ((org-cycle-include-plain-lists t))
583 (search-forward "- item 1")
584 (org-cycle)
585 (search-forward "- item 2")
586 (org-cycle))
587 (org-move-item-up)
588 (forward-line)
589 (should (org-invisible-p2))
590 (search-forward " body 1")
591 (should (org-invisible-p2)))
592 ;; Preserve children visibility.
593 (org-test-with-temp-text "* Headline
594 - item 1
595 - sub-item 1
596 sub-body 1
597 - item 2
598 - sub-item 2
599 sub-body 2"
600 (let ((org-cycle-include-plain-lists t))
601 (search-forward "- sub-item 1")
602 (org-cycle)
603 (search-forward "- sub-item 2")
604 (org-cycle))
605 (search-backward "- item 2")
606 (org-move-item-up)
607 (search-forward "sub-body 2")
608 (should (org-invisible-p2))
609 (search-forward "sub-body 1")
610 (should (org-invisible-p2)))
611 ;; Preserve contents visibility.
612 (org-test-with-temp-text "
613 - item 1
614 #+BEGIN_CENTER
615 Text1
616 #+END_CENTER
617 - item 2
618 #+BEGIN_CENTER
619 Text2
620 #+END_CENTER"
621 (org-hide-block-all)
622 (search-forward "- item 2")
623 (org-move-item-up)
624 (search-forward "Text2")
625 (should (org-invisible-p2))
626 (search-forward "Text1")
627 (should (org-invisible-p2))))
629 (ert-deftest test-org-list/insert-item ()
630 "Test item insertion."
631 ;; Blank lines specifications.
633 ;; Non-nil `org-blank-before-new-entry': insert a blank line, unless
634 ;; `org-list-empty-line-terminates-plain-lists' is non-nil.
635 (should
636 (org-test-with-temp-text "- a"
637 (let ((org-list-empty-line-terminates-plain-lists nil)
638 (org-blank-before-new-entry '((plain-list-item . t))))
639 (end-of-line)
640 (org-insert-item)
641 (forward-line -1)
642 (looking-at "$"))))
643 (should-not
644 (org-test-with-temp-text "- a"
645 (let ((org-list-empty-line-terminates-plain-lists t)
646 (org-blank-before-new-entry '((plain-list-item . t))))
647 (end-of-line)
648 (org-insert-item)
649 (forward-line -1)
650 (looking-at "$"))))
651 ;; Nil `org-blank-before-new-entry': do not insert a blank line.
652 (should-not
653 (org-test-with-temp-text "- a"
654 (let ((org-list-empty-line-terminates-plain-lists nil)
655 (org-blank-before-new-entry '((plain-list-item . nil))))
656 (end-of-line)
657 (org-insert-item)
658 (forward-line -1)
659 (looking-at "$"))))
660 ;; `org-blank-before-new-entry' set to auto: if there's no blank
661 ;; line already in the sole item, do not insert one.
662 (should-not
663 (org-test-with-temp-text "- a"
664 (let ((org-list-empty-line-terminates-plain-lists nil)
665 (org-blank-before-new-entry '((plain-list-item . auto))))
666 (end-of-line)
667 (org-insert-item)
668 (forward-line -1)
669 (looking-at "$"))))
670 ;; `org-blank-before-new-entry' set to `auto': if there's a blank
671 ;; line in the sole item, insert another one.
672 (should
673 (org-test-with-temp-text "- a\n\n b"
674 (let ((org-list-empty-line-terminates-plain-lists nil)
675 (org-blank-before-new-entry '((plain-list-item . auto))))
676 (goto-char (point-max))
677 (org-insert-item)
678 (forward-line -1)
679 (looking-at "$"))))
680 ;; `org-blank-before-new-entry' set to `auto': if the user specified
681 ;; a blank line, preserve it.
682 (should
683 (org-test-with-temp-text "- a\n\n"
684 (let ((org-list-empty-line-terminates-plain-lists nil)
685 (org-blank-before-new-entry '((plain-list-item . auto))))
686 (goto-char (point-max))
687 (org-insert-item)
688 (forward-line -1)
689 (looking-at "$"))))
690 ;; `org-blank-before-new-entry' set to `auto': if some items in list
691 ;; are already separated by blank lines, insert one.
692 (should
693 (org-test-with-temp-text "- a\n\n- b"
694 (let ((org-list-empty-line-terminates-plain-lists nil)
695 (org-blank-before-new-entry '((plain-list-item . auto))))
696 (goto-char (point-max))
697 (org-insert-item)
698 (forward-line -1)
699 (looking-at "$"))))
700 (should
701 (org-test-with-temp-text "- a\n\n- b"
702 (let ((org-list-empty-line-terminates-plain-lists nil)
703 (org-blank-before-new-entry '((plain-list-item . auto))))
704 (org-insert-item)
705 (forward-line)
706 (looking-at "$"))))
707 (should
708 (org-test-with-temp-text "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE"
709 (let ((org-list-empty-line-terminates-plain-lists nil)
710 (org-blank-before-new-entry '((plain-list-item . auto))))
711 (goto-char (point-max))
712 (org-insert-item)
713 (forward-line -1)
714 (looking-at "$"))))
715 ;; When called before or on the bullet, insert new item before
716 ;; current one.
717 (should
718 (equal "- \n- item"
719 (org-test-with-temp-text "- item"
720 (org-insert-item)
721 (buffer-string))))
722 (should
723 (equal "- \n- item"
724 (org-test-with-temp-text "- <point>item"
725 (org-insert-item)
726 (buffer-string))))
727 ;; When called on tag in a descriptive list, insert new item before
728 ;; current one too.
729 (should
730 (equal "- :: \n- tag :: item"
731 (org-test-with-temp-text "- tag <point>:: item"
732 (org-insert-item)
733 (buffer-string))))
734 (should
735 (equal "- :: \n- tag :: item"
736 (org-test-with-temp-text "- ta<point>g :: item"
737 (org-insert-item)
738 (buffer-string))))
739 ;; Further, it splits the line or add a blank new item after it,
740 ;; according to `org-M-RET-may-split-line'.
741 (should
742 (equal "- it\n- em"
743 (org-test-with-temp-text "- it<point>em"
744 (let ((org-M-RET-may-split-line '((default . t))))
745 (org-insert-item))
746 (buffer-string))))
747 (should
748 (equal "- item\n- "
749 (org-test-with-temp-text "- it<point>em"
750 (let ((org-M-RET-may-split-line '((default . nil))))
751 (org-insert-item))
752 (buffer-string)))))
754 (ert-deftest test-org-list/repair ()
755 "Test `org-list-repair' specifications."
756 ;; Repair indentation.
757 (should
758 (equal "- item\n - child"
759 (org-test-with-temp-text "- item\n - child"
760 (let ((org-list-indent-offset 0)) (org-list-repair))
761 (buffer-string))))
762 ;; Repair bullets and numbering.
763 (should
764 (equal "- a\n- b"
765 (org-test-with-temp-text "- a\n+ b"
766 (let ((org-list-indent-offset 0))
767 (org-list-repair))
768 (buffer-string))))
769 (should
770 (equal "1. a\n2. b"
771 (org-test-with-temp-text "1. a\n1. b"
772 (let ((org-list-indent-offset 0)
773 (org-plain-list-ordered-item-terminator t))
774 (org-list-repair))
775 (buffer-string))))
776 ;; Repair check-boxes.
777 (should
778 (equal "- [X] item\n - [X] child"
779 (org-test-with-temp-text "- [ ] item\n - [X] child"
780 (let ((org-list-indent-offset 0))
781 (org-list-repair))
782 (buffer-string))))
783 ;; Special case: do not move contents of an item within its child.
784 ;; Yet, preserve indentation differences within contents.
785 (should
786 (equal "- item\n - child\n within item"
787 (org-test-with-temp-text "- item\n - child\n within item"
788 (let ((org-list-indent-offset 0)) (org-list-repair))
789 (buffer-string))))
790 (should
791 (equal
792 "- item\n - child\n within item\n indented"
793 (org-test-with-temp-text
794 "- item\n - child\n within item\n indented"
795 (let ((org-list-indent-offset 0)) (org-list-repair))
796 (buffer-string)))))
800 ;;; Radio Lists
802 (ert-deftest test-org-list/send-list ()
803 "Test various checks for `org-list-send-list'."
804 ;; Error when not at a list item.
805 (should-error
806 (org-test-with-temp-text "Not a list item"
807 (org-list-send-list)))
808 ;; Error when ORGLST line is not provided.
809 (should-error
810 (org-test-with-temp-text "- item"
811 (org-list-send-list)))
812 ;; Error when transformation function is unknown.
813 (should-error
814 (org-test-with-temp-text "@ignore
815 #+ORGLST: SEND list unknown-function
816 - item
817 @end ignore"
818 (forward-line 2)
819 (org-list-send-list)))
820 ;; Error when receiving location is not defined.
821 (should-error
822 (org-test-with-temp-text "@ignore
823 #+ORGLST: SEND list org-list-to-texinfo
824 - item
825 @end ignore"
826 (forward-line 2)
827 (org-list-send-list)))
828 ;; Error when insertion region is ill-formed.
829 (should-error
830 (org-test-with-temp-text "@c BEGIN RECEIVE ORGLST list
831 @ignore
832 #+ORGLST: SEND list org-list-to-texinfo
833 - item
834 @end ignore"
835 (forward-line 3)
836 (org-list-send-list))))
838 (ert-deftest test-org-list/to-html ()
839 "Test `org-list-to-html' specifications."
840 (should
841 (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
842 (let (org-html-indent)
843 (with-temp-buffer
844 (insert "<!-- BEGIN RECEIVE ORGLST name -->
845 <!-- END RECEIVE ORGLST name -->
846 <!--
847 #+ORGLST: SEND name org-list-to-html
849 -->")
850 (goto-char (point-min))
851 (re-search-forward "^- a" nil t)
852 (beginning-of-line)
853 (org-list-send-list)
854 (goto-line 2)
855 (buffer-substring-no-properties
856 (point)
857 (progn (re-search-forward "^<!-- END" nil t)
858 (beginning-of-line)
859 (skip-chars-backward " \r\t\n")
860 (point))))))))
862 (ert-deftest test-org-list/to-latex ()
863 "Test `org-list-to-latex' specifications."
864 (should
865 (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
866 (with-temp-buffer
867 (insert "% BEGIN RECEIVE ORGLST name
868 % END RECEIVE ORGLST name
869 \\begin{comment}
870 #+ORGLST: SEND name org-list-to-latex
872 \\end{comment}")
873 (goto-char (point-min))
874 (re-search-forward "^- a" nil t)
875 (beginning-of-line)
876 (org-list-send-list)
877 (goto-line 2)
878 (buffer-substring-no-properties
879 (point)
880 (progn (re-search-forward "^% END" nil t)
881 (beginning-of-line)
882 (skip-chars-backward " \r\t\n")
883 (point)))))))
885 (ert-deftest test-org-list/to-texinfo ()
886 "Test `org-list-to-texinfo' specifications."
887 (should
888 (equal "@itemize\n@item\na\n@end itemize"
889 (with-temp-buffer
890 (insert "@c BEGIN RECEIVE ORGLST name
891 @c END RECEIVE ORGLST name
892 @ignore
893 #+ORGLST: SEND name org-list-to-texinfo
895 @end ignore")
896 (goto-char (point-min))
897 (re-search-forward "^- a" nil t)
898 (beginning-of-line)
899 (org-list-send-list)
900 (goto-line 2)
901 (buffer-substring-no-properties
902 (point)
903 (progn (re-search-forward "^@c END" nil t)
904 (beginning-of-line)
905 (skip-chars-backward " \r\t\n")
906 (point)))))))
909 (provide 'test-org-list)
910 ;;; test-org-list.el ends here