org-capture.el (org-capture): Fix bug introduced by commit 1737d3
[org-mode.git] / testing / lisp / test-org.el
blob9f59a7cdd8902d55887c0424a1d3e0b1d6989aea
1 ;;; test-org.el
3 ;; Copyright (c) ߚ David Maus
4 ;; Authors: David Maus
6 ;; Released under the GNU General Public License version 3
7 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
9 ;;;; Comments:
11 ;; Template test file for Org-mode tests
13 ;;; Code:
14 (ert-deftest test-org/org-link-escape-ascii-character ()
15 "Escape an ascii character."
16 (should
17 (string=
18 "%5B"
19 (org-link-escape "["))))
21 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
22 "Escape an ascii control character."
23 (should
24 (string=
25 "%09"
26 (org-link-escape "\t"))))
28 (ert-deftest test-org/org-link-escape-multibyte-character ()
29 "Escape an unicode multibyte character."
30 (should
31 (string=
32 "%E2%82%AC"
33 (org-link-escape "€"))))
35 (ert-deftest test-org/org-link-escape-custom-table ()
36 "Escape string with custom character table."
37 (should
38 (string=
39 "Foo%3A%42ar%0A"
40 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
42 (ert-deftest test-org/org-link-escape-custom-table-merge ()
43 "Escape string with custom table merged with default table."
44 (should
45 (string=
46 "%5BF%6F%6F%3A%42ar%0A%5D"
47 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
49 (ert-deftest test-org/org-link-unescape-ascii-character ()
50 "Unescape an ascii character."
51 (should
52 (string=
53 "["
54 (org-link-unescape "%5B"))))
56 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
57 "Unescpae an ascii control character."
58 (should
59 (string=
60 "\n"
61 (org-link-unescape "%0A"))))
63 (ert-deftest test-org/org-link-unescape-multibyte-character ()
64 "Unescape unicode multibyte character."
65 (should
66 (string=
67 "€"
68 (org-link-unescape "%E2%82%AC"))))
70 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
71 "Unescape old style percent escaped character."
72 (should
73 (string=
74 "àâçèéêîôùû"
75 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
77 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
78 "Escape and unscape a URL that includes an escaped char.
79 http://article.gmane.org/gmane.emacs.orgmode/21459/"
80 (should
81 (string=
82 "http://some.host.com/form?&id=blah%2Bblah25"
83 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
85 (ert-deftest test-org/accumulated-properties-in-drawers ()
86 "Ensure properties accumulate in subtree drawers."
87 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
88 (org-babel-next-src-block)
89 (should (equal '(2 1) (org-babel-execute-src-block)))))
93 ;;; Links
95 ;;;; Fuzzy links
97 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
98 ;; a target keyword (aka an invisible target: #+TARGET: text), to
99 ;; a named element (#+name: text) and to headlines (* Text).
101 (ert-deftest test-org/fuzzy-links ()
102 "Test fuzzy links specifications."
103 ;; 1. Fuzzy link goes in priority to a matching target.
104 (org-test-with-temp-text
105 "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
106 (goto-line 6)
107 (org-open-at-point)
108 (should (looking-at "<<Test>>")))
109 ;; 2. Fuzzy link should then go to a matching target keyword.
110 (org-test-with-temp-text
111 "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
112 (goto-line 5)
113 (org-open-at-point)
114 (should (looking-at "#\\+TARGET: Test")))
115 ;; 3. Then fuzzy link points to an element with a given name.
116 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
117 (goto-line 5)
118 (org-open-at-point)
119 (should (looking-at "#\\+NAME: Test")))
120 ;; 4. A target still lead to a matching headline otherwise.
121 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
122 (goto-line 4)
123 (org-open-at-point)
124 (should (looking-at "\\* Head2")))
125 ;; 5. With a leading star in link, enforce heading match.
126 (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
127 (goto-line 4)
128 (org-open-at-point)
129 (should (looking-at "\\* Test"))))
133 ;;; Filling
135 (ert-deftest test-org/fill-paragraph ()
136 "Test `org-fill-paragraph' specifications."
137 ;; At an Org table, align it.
138 (org-test-with-temp-text "|a|"
139 (org-fill-paragraph)
140 (should (equal (buffer-string) "| a |\n")))
141 ;; At a paragraph, preserve line breaks.
142 (org-test-with-temp-text "some \\\\\nlong\ntext"
143 (let ((fill-column 20))
144 (org-fill-paragraph)
145 (should (equal (buffer-string) "some \\\\\nlong text"))))
146 ;; Correctly fill a paragraph when point is at its very end.
147 (should
148 (equal "A B"
149 (org-test-with-temp-text "A\nB"
150 (let ((fill-column 20))
151 (goto-char (point-max))
152 (org-fill-paragraph)
153 (buffer-string)))))
154 ;; Correctly fill the last paragraph of a greater element.
155 (should
156 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
157 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
158 (let ((fill-column 8))
159 (forward-line)
160 (end-of-line)
161 (org-fill-paragraph)
162 (buffer-string)))))
163 ;; Special case: Fill first paragraph when point is at an item or
164 ;; a plain-list or a footnote reference.
165 (should
166 (equal "- A B"
167 (org-test-with-temp-text "- A\n B"
168 (let ((fill-column 20))
169 (org-fill-paragraph)
170 (buffer-string)))))
171 (should
172 (equal "[fn:1] A B"
173 (org-test-with-temp-text "[fn:1] A\nB"
174 (let ((fill-column 20))
175 (org-fill-paragraph)
176 (buffer-string)))))
177 ;; At a verse block, fill paragraph at point, also preserving line
178 ;; breaks. Though, do nothing when point is at the block
179 ;; boundaries.
180 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
181 (forward-line)
182 (let ((fill-column 20))
183 (org-fill-paragraph)
184 (should (equal (buffer-string)
185 "#+BEGIN_VERSE\nSome \\\\\nlong text\n#+END_VERSE"))))
186 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
187 (let ((fill-column 20))
188 (org-fill-paragraph)
189 (should (equal (buffer-string)
190 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
191 ;; Fill contents of `comment-block' elements.
192 (should
193 (equal
194 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
195 (let ((fill-column 20))
196 (forward-line)
197 (org-fill-paragraph)
198 (buffer-string)))
199 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
200 ;; Fill `comment' elements.
201 (should
202 (equal " # A B"
203 (org-test-with-temp-text " # A\n # B"
204 (let ((fill-column 20))
205 (org-fill-paragraph)
206 (buffer-string)))))
207 ;; Do nothing at affiliated keywords.
208 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
209 (let ((fill-column 20))
210 (org-fill-paragraph)
211 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
213 (ert-deftest test-org/auto-fill-function ()
214 "Test auto-filling features."
215 ;; Auto fill paragraph.
216 (should
217 (equal "12345\n7890"
218 (org-test-with-temp-text "12345 7890"
219 (let ((fill-column 5))
220 (end-of-line)
221 (org-auto-fill-function)
222 (buffer-string)))))
223 ;; Auto fill first paragraph in an item.
224 (should
225 (equal "- 12345\n 7890"
226 (org-test-with-temp-text "- 12345 7890"
227 (let ((fill-column 7))
228 (end-of-line)
229 (org-auto-fill-function)
230 (buffer-string)))))
231 ;; Auto fill comments.
232 (should
233 (equal " # 12345\n # 7890"
234 (org-test-with-temp-text " # 12345 7890"
235 (let ((fill-column 10))
236 (end-of-line)
237 (org-auto-fill-function)
238 (buffer-string)))))
239 ;; Verse and comment block: auto fill contents.
240 (should
241 (equal "#+BEGIN_VERSE\n12345\n7890\n#+END_VERSE"
242 (org-test-with-temp-text "#+BEGIN_VERSE\n12345 7890\n#+END_VERSE"
243 (let ((fill-column 5))
244 (forward-line)
245 (end-of-line)
246 (org-auto-fill-function)
247 (buffer-string)))))
248 (should
249 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
250 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
251 (let ((fill-column 5))
252 (forward-line)
253 (end-of-line)
254 (org-auto-fill-function)
255 (buffer-string)))))
256 ;; Do not fill if a new item could be created.
257 (should-not
258 (equal "12345\n- 90"
259 (org-test-with-temp-text "12345 - 90"
260 (let ((fill-column 5))
261 (end-of-line)
262 (org-auto-fill-function)
263 (buffer-string)))))
264 ;; Do not fill if a line break could be introduced.
265 (should-not
266 (equal "123\\\\\n7890"
267 (org-test-with-temp-text "123\\\\ 7890"
268 (let ((fill-column 6))
269 (end-of-line)
270 (org-auto-fill-function)
271 (buffer-string)))))
272 ;; Do not fill affiliated keywords.
273 (should-not
274 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
275 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
276 (let ((fill-column 20))
277 (end-of-line)
278 (org-auto-fill-function)
279 (buffer-string))))))
283 ;;; Comments
285 (ert-deftest test-org/comment-dwim ()
286 "Test `comment-dwim' behaviour in an Org buffer."
287 ;; No region selected, no comment on current line and line not
288 ;; empty: insert comment on line above.
289 (should
290 (equal "# \nComment"
291 (org-test-with-temp-text "Comment"
292 (progn (call-interactively 'comment-dwim)
293 (buffer-string)))))
294 ;; No region selected, no comment on current line and line empty:
295 ;; insert comment on this line.
296 (should
297 (equal "# \nParagraph"
298 (org-test-with-temp-text "\nParagraph"
299 (progn (call-interactively 'comment-dwim)
300 (buffer-string)))))
301 ;; No region selected, and a comment on this line: indent it.
302 (should
303 (equal "* Headline\n # Comment"
304 (org-test-with-temp-text "* Headline\n# Comment"
305 (progn (forward-line)
306 (let ((org-adapt-indentation t))
307 (call-interactively 'comment-dwim))
308 (buffer-string)))))
309 ;; Also recognize single # at column 0 as comments.
310 (should
311 (equal "# Comment"
312 (org-test-with-temp-text "# Comment"
313 (progn (forward-line)
314 (call-interactively 'comment-dwim)
315 (buffer-string)))))
316 ;; Region selected and only comments and blank lines within it:
317 ;; un-comment all commented lines.
318 (should
319 (equal "Comment 1\n\nComment 2"
320 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
321 (progn
322 (transient-mark-mode 1)
323 (push-mark (point) t t)
324 (goto-char (point-max))
325 (call-interactively 'comment-dwim)
326 (buffer-string)))))
327 ;; Region selected without comments: comment all non-blank lines.
328 (should
329 (equal "# Comment 1\n\n# Comment 2"
330 (org-test-with-temp-text "Comment 1\n\nComment 2"
331 (progn
332 (transient-mark-mode 1)
333 (push-mark (point) t t)
334 (goto-char (point-max))
335 (call-interactively 'comment-dwim)
336 (buffer-string))))))
340 ;;; Mark region
342 (ert-deftest test-org/mark-subtree ()
343 "Test `org-mark-subtree' specifications."
344 ;; Error when point is before first headline.
345 (should-error
346 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
347 (progn (transient-mark-mode 1)
348 (org-mark-subtree))))
349 ;; Without argument, mark current subtree.
350 (should
351 (equal
352 '(12 32)
353 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
354 (progn (transient-mark-mode 1)
355 (forward-line 2)
356 (org-mark-subtree)
357 (list (region-beginning) (region-end))))))
358 ;; With an argument, move ARG up.
359 (should
360 (equal
361 '(1 32)
362 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
363 (progn (transient-mark-mode 1)
364 (forward-line 2)
365 (org-mark-subtree 1)
366 (list (region-beginning) (region-end))))))
367 ;; Do not get fooled with inlinetasks.
368 (when (featurep 'org-inlinetask)
369 (should
370 (= 1
371 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
372 (progn (transient-mark-mode 1)
373 (forward-line 1)
374 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
375 (region-beginning)))))))
379 ;; Navigation
381 (ert-deftest test-org/forward-element ()
382 "Test `org-forward-element' specifications."
383 ;; 1. At EOB: should error.
384 (org-test-with-temp-text "Some text\n"
385 (goto-char (point-max))
386 (should-error (org-forward-element)))
387 ;; 2. Standard move: expected to ignore blank lines.
388 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
389 (org-forward-element)
390 (should (looking-at "Second paragraph.")))
391 ;; 3. Headline tests.
392 (org-test-with-temp-text "
393 * Head 1
394 ** Head 1.1
395 *** Head 1.1.1
396 ** Head 1.2"
397 ;; 3.1. At an headline beginning: move to next headline at the
398 ;; same level.
399 (goto-line 3)
400 (org-forward-element)
401 (should (looking-at "** Head 1.2"))
402 ;; 3.2. At an headline beginning: move to parent headline if no
403 ;; headline at the same level.
404 (goto-line 3)
405 (org-forward-element)
406 (should (looking-at "** Head 1.2")))
407 ;; 4. Greater element tests.
408 (org-test-with-temp-text
409 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
410 ;; 4.1. At a greater element: expected to skip contents.
411 (org-forward-element)
412 (should (looking-at "Outside."))
413 ;; 4.2. At the end of greater element contents: expected to skip
414 ;; to the end of the greater element.
415 (goto-line 2)
416 (org-forward-element)
417 (should (looking-at "Outside.")))
418 ;; 5. List tests.
419 (org-test-with-temp-text "
420 - item1
422 - sub1
424 - sub2
426 - sub3
428 Inner paragraph.
430 - item2
432 Outside."
433 ;; 5.1. At list top point: expected to move to the element after
434 ;; the list.
435 (goto-line 2)
436 (org-forward-element)
437 (should (looking-at "Outside."))
438 ;; 5.2. Special case: at the first line of a sub-list, but not at
439 ;; beginning of line, move to next item.
440 (goto-line 2)
441 (forward-char)
442 (org-forward-element)
443 (should (looking-at "- item2"))
444 (goto-line 4)
445 (forward-char)
446 (org-forward-element)
447 (should (looking-at " - sub2"))
448 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
449 (goto-line 4)
450 (org-forward-element)
451 (should (looking-at " Inner paragraph."))
452 ;; 5.4. At sub-list end: expected to move outside the sub-list.
453 (goto-line 8)
454 (org-forward-element)
455 (should (looking-at " Inner paragraph."))
456 ;; 5.5. At an item: expected to move to next item, if any.
457 (goto-line 6)
458 (org-forward-element)
459 (should (looking-at " - sub3"))))
461 (ert-deftest test-org/backward-element ()
462 "Test `org-backward-element' specifications."
463 ;; 1. At BOB (modulo some white spaces): should error.
464 (org-test-with-temp-text " \nParagraph."
465 (org-skip-whitespace)
466 (should-error (org-backward-element)))
467 ;; 2. Not at the beginning of an element: move at its beginning.
468 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
469 (goto-line 3)
470 (end-of-line)
471 (org-backward-element)
472 (should (looking-at "Paragraph2.")))
473 ;; 3. Headline tests.
474 (org-test-with-temp-text "
475 * Head 1
476 ** Head 1.1
477 *** Head 1.1.1
478 ** Head 1.2"
479 ;; 3.1. At an headline beginning: move to previous headline at the
480 ;; same level.
481 (goto-line 5)
482 (org-backward-element)
483 (should (looking-at "** Head 1.1"))
484 ;; 3.2. At an headline beginning: move to parent headline if no
485 ;; headline at the same level.
486 (goto-line 3)
487 (org-backward-element)
488 (should (looking-at "* Head 1"))
489 ;; 3.3. At the first top-level headline: should error.
490 (goto-line 2)
491 (should-error (org-backward-element)))
492 ;; 4. At beginning of first element inside a greater element:
493 ;; expected to move to greater element's beginning.
494 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER."
495 (goto-line 3)
496 (org-backward-element)
497 (should (looking-at "#\\+BEGIN_CENTER")))
498 ;; 5. List tests.
499 (org-test-with-temp-text "
500 - item1
502 - sub1
504 - sub2
506 - sub3
508 Inner paragraph.
510 - item2
513 Outside."
514 ;; 5.1. At beginning of sub-list: expected to move to the
515 ;; paragraph before it.
516 (goto-line 4)
517 (org-backward-element)
518 (should (looking-at "item1"))
519 ;; 5.2. At an item in a list: expected to move at previous item.
520 (goto-line 8)
521 (org-backward-element)
522 (should (looking-at " - sub2"))
523 (goto-line 12)
524 (org-backward-element)
525 (should (looking-at "- item1"))
526 ;; 5.3. At end of list/sub-list: expected to move to list/sub-list
527 ;; beginning.
528 (goto-line 10)
529 (org-backward-element)
530 (should (looking-at " - sub1"))
531 (goto-line 15)
532 (org-backward-element)
533 (should (looking-at "- item1"))
534 ;; 5.4. At blank-lines before list end: expected to move to top
535 ;; item.
536 (goto-line 14)
537 (org-backward-element)
538 (should (looking-at "- item1"))))
540 (ert-deftest test-org/up-element ()
541 "Test `org-up-element' specifications."
542 ;; 1. At BOB or with no surrounding element: should error.
543 (org-test-with-temp-text "Paragraph."
544 (should-error (org-up-element)))
545 (org-test-with-temp-text "* Head1\n* Head2"
546 (goto-line 2)
547 (should-error (org-up-element)))
548 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
549 (goto-line 3)
550 (should-error (org-up-element)))
551 ;; 2. At an headline: move to parent headline.
552 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
553 (goto-line 3)
554 (org-up-element)
555 (should (looking-at "\\* Head1")))
556 ;; 3. Inside a greater element: move to greater element beginning.
557 (org-test-with-temp-text
558 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
559 (goto-line 3)
560 (org-up-element)
561 (should (looking-at "#\\+BEGIN_CENTER")))
562 ;; 4. List tests.
563 (org-test-with-temp-text "* Top
564 - item1
566 - sub1
568 - sub2
570 Paragraph within sub2.
572 - item2"
573 ;; 4.1. Within an item: move to the item beginning.
574 (goto-line 8)
575 (org-up-element)
576 (should (looking-at " - sub2"))
577 ;; 4.2. At an item in a sub-list: move to parent item.
578 (goto-line 4)
579 (org-up-element)
580 (should (looking-at "- item1"))
581 ;; 4.3. At an item in top list: move to beginning of whole list.
582 (goto-line 10)
583 (org-up-element)
584 (should (looking-at "- item1"))
585 ;; 4.4. Special case. At very top point: should move to parent of
586 ;; list.
587 (goto-line 2)
588 (org-up-element)
589 (should (looking-at "\\* Top"))))
591 (ert-deftest test-org/down-element ()
592 "Test `org-down-element' specifications."
593 ;; Error when the element hasn't got a recursive type.
594 (org-test-with-temp-text "Paragraph."
595 (should-error (org-down-element)))
596 ;; Error when the element has no contents
597 (org-test-with-temp-text "* Headline"
598 (should-error (org-down-element)))
599 ;; When at a plain-list, move to first item.
600 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
601 (goto-line 2)
602 (org-down-element)
603 (should (looking-at " - Item 1.1")))
604 (org-test-with-temp-text "#+NAME: list\n- Item 1"
605 (org-down-element)
606 (should (looking-at " Item 1")))
607 ;; When at a table, move to first row
608 (org-test-with-temp-text "#+NAME: table\n| a | b |"
609 (org-down-element)
610 (should (looking-at " a | b |")))
611 ;; Otherwise, move inside the greater element.
612 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
613 (org-down-element)
614 (should (looking-at "Paragraph"))))
616 (ert-deftest test-org/drag-element-backward ()
617 "Test `org-drag-element-backward' specifications."
618 ;; 1. Error when trying to move first element of buffer.
619 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
620 (should-error (org-drag-element-backward)))
621 ;; 2. Error when trying to swap nested elements.
622 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
623 (forward-line)
624 (should-error (org-drag-element-backward)))
625 ;; 3. Error when trying to swap an headline element and
626 ;; a non-headline element.
627 (org-test-with-temp-text "Test.\n* Head 1"
628 (forward-line)
629 (should-error (org-drag-element-backward)))
630 ;; 4. Otherwise, swap elements, preserving column and blank lines
631 ;; between elements.
632 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
633 (search-forward "graph")
634 (org-drag-element-backward)
635 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
636 (should (looking-at " 2")))
637 ;; 5. Preserve visibility of elements and their contents.
638 (org-test-with-temp-text "
639 #+BEGIN_CENTER
640 Text.
641 #+END_CENTER
642 - item 1
643 #+BEGIN_QUOTE
644 Text.
645 #+END_QUOTE"
646 (while (search-forward "BEGIN_" nil t) (org-cycle))
647 (search-backward "- item 1")
648 (org-drag-element-backward)
649 (should
650 (equal
651 '((63 . 82) (26 . 48))
652 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
653 (overlays-in (point-min) (point-max)))))))
655 (ert-deftest test-org/drag-element-forward ()
656 "Test `org-drag-element-forward' specifications."
657 ;; 1. Error when trying to move first element of buffer.
658 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
659 (goto-line 3)
660 (should-error (org-drag-element-forward)))
661 ;; 2. Error when trying to swap nested elements.
662 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
663 (forward-line)
664 (should-error (org-drag-element-forward)))
665 ;; 3. Error when trying to swap a non-headline element and an
666 ;; headline.
667 (org-test-with-temp-text "Test.\n* Head 1"
668 (should-error (org-drag-element-forward)))
669 ;; 4. Otherwise, swap elements, preserving column and blank lines
670 ;; between elements.
671 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
672 (search-forward "graph")
673 (org-drag-element-forward)
674 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
675 (should (looking-at " 1")))
676 ;; 5. Preserve visibility of elements and their contents.
677 (org-test-with-temp-text "
678 #+BEGIN_CENTER
679 Text.
680 #+END_CENTER
681 - item 1
682 #+BEGIN_QUOTE
683 Text.
684 #+END_QUOTE"
685 (while (search-forward "BEGIN_" nil t) (org-cycle))
686 (search-backward "#+BEGIN_CENTER")
687 (org-drag-element-forward)
688 (should
689 (equal
690 '((63 . 82) (26 . 48))
691 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
692 (overlays-in (point-min) (point-max)))))))
695 (provide 'test-org)
697 ;;; test-org.el ends here