1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Template test file for Org-mode tests
30 (ert-deftest test-org
/comment-dwim
()
31 "Test `comment-dwim' behaviour in an Org buffer."
32 ;; No region selected, no comment on current line and line not
33 ;; empty: insert comment on line above.
36 (org-test-with-temp-text "Comment"
37 (progn (call-interactively 'comment-dwim
)
39 ;; No region selected, no comment on current line and line empty:
40 ;; insert comment on this line.
42 (equal "# \nParagraph"
43 (org-test-with-temp-text "\nParagraph"
44 (progn (call-interactively 'comment-dwim
)
46 ;; No region selected, and a comment on this line: indent it.
48 (equal "* Headline\n # Comment"
49 (org-test-with-temp-text "* Headline\n# Comment"
51 (let ((org-adapt-indentation t
))
52 (call-interactively 'comment-dwim
))
54 ;; Also recognize single # at column 0 as comments.
57 (org-test-with-temp-text "# Comment"
59 (call-interactively 'comment-dwim
)
61 ;; Region selected and only comments and blank lines within it:
62 ;; un-comment all commented lines.
64 (equal "Comment 1\n\nComment 2"
65 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
67 (transient-mark-mode 1)
68 (push-mark (point) t t
)
69 (goto-char (point-max))
70 (call-interactively 'comment-dwim
)
72 ;; Region selected without comments: comment all non-blank lines.
74 (equal "# Comment 1\n\n# Comment 2"
75 (org-test-with-temp-text "Comment 1\n\nComment 2"
77 (transient-mark-mode 1)
78 (push-mark (point) t t
)
79 (goto-char (point-max))
80 (call-interactively 'comment-dwim
)
82 ;; In front of a keyword without region, insert a new comment.
84 (equal "# \n#+KEYWORD: value"
85 (org-test-with-temp-text "#+KEYWORD: value"
86 (progn (call-interactively 'comment-dwim
)
93 (ert-deftest test-org
/org-read-date
()
94 "Test `org-read-date' specifications."
95 ;; Parse ISO date with abbreviated year and month.
96 (should (equal "2012-03-29 16:40"
97 (let ((org-time-was-given t
))
98 (org-read-date t nil
"12-3-29 16:40"))))
99 ;; Parse Europeans dates.
100 (should (equal "2012-03-29 16:40"
101 (let ((org-time-was-given t
))
102 (org-read-date t nil
"29.03.2012 16:40"))))
103 ;; Parse Europeans dates without year.
104 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
105 (let ((org-time-was-given t
))
106 (org-read-date t nil
"29.03. 16:40")))))
112 (ert-deftest test-org
/fill-paragraph
()
113 "Test `org-fill-paragraph' specifications."
114 ;; At an Org table, align it.
115 (org-test-with-temp-text "|a|"
117 (should (equal (buffer-string) "| a |\n")))
118 ;; At a paragraph, preserve line breaks.
119 (org-test-with-temp-text "some \\\\\nlong\ntext"
120 (let ((fill-column 20))
122 (should (equal (buffer-string) "some \\\\\nlong text"))))
123 ;; Correctly fill a paragraph when point is at its very end.
126 (org-test-with-temp-text "A\nB"
127 (let ((fill-column 20))
128 (goto-char (point-max))
131 ;; Correctly fill the last paragraph of a greater element.
133 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
134 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
135 (let ((fill-column 8))
140 ;; Correctly fill an element in a narrowed buffer.
143 (org-test-with-temp-text "01234 6789"
144 (let ((fill-column 5))
145 (narrow-to-region 1 8)
148 ;; Special case: Fill first paragraph when point is at an item or
149 ;; a plain-list or a footnote reference.
152 (org-test-with-temp-text "- A\n B"
153 (let ((fill-column 20))
158 (org-test-with-temp-text "[fn:1] A\nB"
159 (let ((fill-column 20))
162 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
163 (let ((fill-column 20))
165 (should (equal (buffer-string)
166 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
167 ;; Fill contents of `comment-block' elements.
170 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
171 (let ((fill-column 20))
175 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
176 ;; Fill `comment' elements.
179 (org-test-with-temp-text " # A\n # B"
180 (let ((fill-column 20))
183 ;; Do nothing at affiliated keywords.
184 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
185 (let ((fill-column 20))
187 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
189 (ert-deftest test-org
/auto-fill-function
()
190 "Test auto-filling features."
191 ;; Auto fill paragraph.
194 (org-test-with-temp-text "12345 7890"
195 (let ((fill-column 5))
197 (org-auto-fill-function)
199 ;; Auto fill first paragraph in an item.
201 (equal "- 12345\n 7890"
202 (org-test-with-temp-text "- 12345 7890"
203 (let ((fill-column 7))
205 (org-auto-fill-function)
207 ;; Auto fill comments.
209 (equal " # 12345\n # 7890"
210 (org-test-with-temp-text " # 12345 7890"
211 (let ((fill-column 10))
213 (org-auto-fill-function)
215 ;; A hash within a line isn't a comment.
217 (equal "12345 # 7890\n# 1"
218 (org-test-with-temp-text "12345 # 7890 1"
219 (let ((fill-column 12))
221 (org-auto-fill-function)
223 ;; Correctly interpret empty prefix.
225 (equal "# a\n# b\nRegular\n# paragraph"
226 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
227 (let ((fill-column 12))
229 (org-auto-fill-function)
231 ;; Comment block: auto fill contents.
233 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
234 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
235 (let ((fill-column 5))
238 (org-auto-fill-function)
241 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
242 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
243 (let ((fill-column 5))
246 (org-auto-fill-function)
248 ;; Do not fill if a new item could be created.
251 (org-test-with-temp-text "12345 - 90"
252 (let ((fill-column 5))
254 (org-auto-fill-function)
256 ;; Do not fill if a line break could be introduced.
258 (equal "123\\\\\n7890"
259 (org-test-with-temp-text "123\\\\ 7890"
260 (let ((fill-column 6))
262 (org-auto-fill-function)
264 ;; Do not fill affiliated keywords.
266 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
267 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
268 (let ((fill-column 20))
270 (org-auto-fill-function)
279 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
280 ;; a target keyword (aka an invisible target: #+TARGET: text), to
281 ;; a named element (#+name: text) and to headlines (* Text).
283 (ert-deftest test-org
/fuzzy-links
()
284 "Test fuzzy links specifications."
285 ;; 1. Fuzzy link goes in priority to a matching target.
286 (org-test-with-temp-text
287 "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
290 (should (looking-at "<<Test>>")))
291 ;; 2. Fuzzy link should then go to a matching target keyword.
292 (org-test-with-temp-text
293 "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
296 (should (looking-at "#\\+TARGET: Test")))
297 ;; 3. Then fuzzy link points to an element with a given name.
298 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
301 (should (looking-at "#\\+NAME: Test")))
302 ;; 4. A target still lead to a matching headline otherwise.
303 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
306 (should (looking-at "\\* Head2")))
307 ;; 5. With a leading star in link, enforce heading match.
308 (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
311 (should (looking-at "\\* Test"))))
316 (ert-deftest test-org
/org-link-escape-ascii-character
()
317 "Escape an ascii character."
321 (org-link-escape "["))))
323 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
324 "Escape an ascii control character."
328 (org-link-escape "\t"))))
330 (ert-deftest test-org
/org-link-escape-multibyte-character
()
331 "Escape an unicode multibyte character."
335 (org-link-escape "€"))))
337 (ert-deftest test-org
/org-link-escape-custom-table
()
338 "Escape string with custom character table."
342 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
344 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
345 "Escape string with custom table merged with default table."
348 "%5BF%6F%6F%3A%42ar%0A%5D"
349 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
351 (ert-deftest test-org
/org-link-unescape-ascii-character
()
352 "Unescape an ascii character."
356 (org-link-unescape "%5B"))))
358 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
359 "Unescpae an ascii control character."
363 (org-link-unescape "%0A"))))
365 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
366 "Unescape unicode multibyte character."
370 (org-link-unescape "%E2%82%AC"))))
372 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
373 "Unescape old style percent escaped character."
376 "à âçèéêîôùû"
377 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
379 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
380 "Escape and unscape a URL that includes an escaped char.
381 http://article.gmane.org/gmane.emacs.orgmode/21459/"
384 "http://some.host.com/form?&id=blah%2Bblah25"
385 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
391 (ert-deftest test-org
/macro-replace-all
()
392 "Test `org-macro-replace-all' specifications."
396 "#+MACRO: A B\n1 B 3"
397 (org-test-with-temp-text "#+MACRO: A B\n1 {{{A}}} 3"
398 (progn (org-macro-initialize-templates)
399 (org-macro-replace-all org-macro-templates
)
401 ;; Macro with arguments.
404 "#+MACRO: macro $1 $2\nsome text"
405 (org-test-with-temp-text "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
406 (progn (org-macro-initialize-templates)
407 (org-macro-replace-all org-macro-templates
)
409 ;; Macro with "eval".
412 "#+MACRO: add (eval (+ $1 $2))\n3"
413 (org-test-with-temp-text "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
414 (progn (org-macro-initialize-templates)
415 (org-macro-replace-all org-macro-templates
)
420 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\ninner outer"
421 (org-test-with-temp-text
422 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
423 (progn (org-macro-initialize-templates)
424 (org-macro-replace-all org-macro-templates
)
426 ;; Error out when macro expansion is circular.
428 (org-test-with-temp-text
429 "#+MACRO: mac1 {{{mac2}}}\n#+MACRO: mac2 {{{mac1}}}\n{{{mac1}}}"
430 (org-macro-initialize-templates)
431 (org-macro-replace-all org-macro-templates
))))
437 (ert-deftest test-org
/accumulated-properties-in-drawers
()
438 "Ensure properties accumulate in subtree drawers."
439 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
440 (org-babel-next-src-block)
441 (should (equal '(2 1) (org-babel-execute-src-block)))))
447 (ert-deftest test-org
/mark-subtree
()
448 "Test `org-mark-subtree' specifications."
449 ;; Error when point is before first headline.
451 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
452 (progn (transient-mark-mode 1)
453 (org-mark-subtree))))
454 ;; Without argument, mark current subtree.
458 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
459 (progn (transient-mark-mode 1)
462 (list (region-beginning) (region-end))))))
463 ;; With an argument, move ARG up.
467 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
468 (progn (transient-mark-mode 1)
471 (list (region-beginning) (region-end))))))
472 ;; Do not get fooled by inlinetasks.
473 (when (featurep 'org-inlinetask
)
476 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
477 (progn (transient-mark-mode 1)
479 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
480 (region-beginning)))))))
486 (ert-deftest test-org
/beginning-of-line
()
487 "Test `org-beginning-of-line' specifications."
490 (org-test-with-temp-text "Some text\nSome other text"
491 (progn (org-beginning-of-line) (bolp))))
492 ;; Standard test with `visual-line-mode'.
494 (org-test-with-temp-text "A long line of text\nSome other text"
495 (progn (visual-line-mode)
497 (dotimes (i 1000) (insert "very "))
498 (org-beginning-of-line)
500 ;; At an headline with special movement.
502 (org-test-with-temp-text "* TODO Headline"
503 (let ((org-special-ctrl-a/e t
))
505 (and (progn (org-beginning-of-line) (looking-at "Headline"))
506 (progn (org-beginning-of-line) (bolp))
507 (progn (org-beginning-of-line) (looking-at "Headline")))))))
509 (ert-deftest test-org
/end-of-line
()
510 "Test `org-end-of-line' specifications."
513 (org-test-with-temp-text "Some text\nSome other text"
514 (progn (org-end-of-line) (eolp))))
515 ;; Standard test with `visual-line-mode'.
517 (org-test-with-temp-text "A long line of text\nSome other text"
518 (progn (visual-line-mode)
520 (dotimes (i 1000) (insert "very "))
521 (goto-char (point-min))
524 ;; At an headline with special movement.
526 (org-test-with-temp-text "* Headline1 :tag:\n"
527 (let ((org-special-ctrl-a/e t
))
528 (and (progn (org-end-of-line) (looking-at " :tag:"))
529 (progn (org-end-of-line) (eolp))
530 (progn (org-end-of-line) (looking-at " :tag:"))))))
531 ;; At an headline without special movement.
533 (org-test-with-temp-text "* Headline2 :tag:\n"
534 (let ((org-special-ctrl-a/e nil
))
535 (and (progn (org-end-of-line) (eolp))
536 (progn (org-end-of-line) (eolp))))))
537 ;; At an headline, with reversed movement.
539 (org-test-with-temp-text "* Headline3 :tag:\n"
540 (let ((org-special-ctrl-a/e
'reversed
)
541 (this-command last-command
))
542 (and (progn (org-end-of-line) (eolp))
543 (progn (org-end-of-line) (looking-at " :tag:"))))))
544 ;; At a block without hidden contents.
546 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
547 (progn (org-end-of-line) (eolp))))
548 ;; At a block with hidden contents.
550 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
551 (let ((org-special-ctrl-a/e t
))
552 (org-hide-block-toggle)
556 (ert-deftest test-org
/forward-element
()
557 "Test `org-forward-element' specifications."
558 ;; 1. At EOB: should error.
559 (org-test-with-temp-text "Some text\n"
560 (goto-char (point-max))
561 (should-error (org-forward-element)))
562 ;; 2. Standard move: expected to ignore blank lines.
563 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
564 (org-forward-element)
565 (should (looking-at "Second paragraph.")))
566 ;; 3. Headline tests.
567 (org-test-with-temp-text "
572 ;; 3.1. At an headline beginning: move to next headline at the
575 (org-forward-element)
576 (should (looking-at "** Head 1.2"))
577 ;; 3.2. At an headline beginning: move to parent headline if no
578 ;; headline at the same level.
580 (org-forward-element)
581 (should (looking-at "** Head 1.2")))
582 ;; 4. Greater element tests.
583 (org-test-with-temp-text
584 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
585 ;; 4.1. At a greater element: expected to skip contents.
586 (org-forward-element)
587 (should (looking-at "Outside."))
588 ;; 4.2. At the end of greater element contents: expected to skip
589 ;; to the end of the greater element.
591 (org-forward-element)
592 (should (looking-at "Outside.")))
594 (org-test-with-temp-text "
608 ;; 5.1. At list top point: expected to move to the element after
611 (org-forward-element)
612 (should (looking-at "Outside."))
613 ;; 5.2. Special case: at the first line of a sub-list, but not at
614 ;; beginning of line, move to next item.
617 (org-forward-element)
618 (should (looking-at "- item2"))
621 (org-forward-element)
622 (should (looking-at " - sub2"))
623 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
625 (org-forward-element)
626 (should (looking-at " Inner paragraph."))
627 ;; 5.4. At sub-list end: expected to move outside the sub-list.
629 (org-forward-element)
630 (should (looking-at " Inner paragraph."))
631 ;; 5.5. At an item: expected to move to next item, if any.
633 (org-forward-element)
634 (should (looking-at " - sub3"))))
636 (ert-deftest test-org
/backward-element
()
637 "Test `org-backward-element' specifications."
638 ;; 1. Should error at BOB.
639 (org-test-with-temp-text " \nParagraph."
640 (should-error (org-backward-element)))
641 ;; 2. Should move at BOB when called on the first element in buffer.
643 (org-test-with-temp-text "\n#+TITLE: test"
644 (progn (forward-line)
645 (org-backward-element)
647 ;; 3. Not at the beginning of an element: move at its beginning.
648 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
651 (org-backward-element)
652 (should (looking-at "Paragraph2.")))
653 ;; 4. Headline tests.
654 (org-test-with-temp-text "
659 ;; 4.1. At an headline beginning: move to previous headline at the
662 (org-backward-element)
663 (should (looking-at "** Head 1.1"))
664 ;; 4.2. At an headline beginning: move to parent headline if no
665 ;; headline at the same level.
667 (org-backward-element)
668 (should (looking-at "* Head 1"))
669 ;; 4.3. At the first top-level headline: should error.
671 (should-error (org-backward-element)))
672 ;; 5. At beginning of first element inside a greater element:
673 ;; expected to move to greater element's beginning.
674 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
676 (org-backward-element)
677 (should (looking-at "#\\+BEGIN_CENTER")))
678 ;; 6. At the beginning of the first element in a section: should
679 ;; move back to headline, if any.
681 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
682 (progn (goto-char (point-max))
684 (org-backward-element)
685 (org-at-heading-p))))
687 (org-test-with-temp-text "
702 ;; 7.1. At beginning of sub-list: expected to move to the
703 ;; paragraph before it.
705 (org-backward-element)
706 (should (looking-at "item1"))
707 ;; 7.2. At an item in a list: expected to move at previous item.
709 (org-backward-element)
710 (should (looking-at " - sub2"))
712 (org-backward-element)
713 (should (looking-at "- item1"))
714 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
717 (org-backward-element)
718 (should (looking-at " - sub1"))
720 (org-backward-element)
721 (should (looking-at "- item1"))
722 ;; 7.4. At blank-lines before list end: expected to move to top
725 (org-backward-element)
726 (should (looking-at "- item1"))))
728 (ert-deftest test-org
/up-element
()
729 "Test `org-up-element' specifications."
730 ;; 1. At BOB or with no surrounding element: should error.
731 (org-test-with-temp-text "Paragraph."
732 (should-error (org-up-element)))
733 (org-test-with-temp-text "* Head1\n* Head2"
735 (should-error (org-up-element)))
736 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
738 (should-error (org-up-element)))
739 ;; 2. At an headline: move to parent headline.
740 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
743 (should (looking-at "\\* Head1")))
744 ;; 3. Inside a greater element: move to greater element beginning.
745 (org-test-with-temp-text
746 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
749 (should (looking-at "#\\+BEGIN_CENTER")))
751 (org-test-with-temp-text "* Top
758 Paragraph within sub2.
761 ;; 4.1. Within an item: move to the item beginning.
764 (should (looking-at " - sub2"))
765 ;; 4.2. At an item in a sub-list: move to parent item.
768 (should (looking-at "- item1"))
769 ;; 4.3. At an item in top list: move to beginning of whole list.
772 (should (looking-at "- item1"))
773 ;; 4.4. Special case. At very top point: should move to parent of
777 (should (looking-at "\\* Top"))))
779 (ert-deftest test-org
/down-element
()
780 "Test `org-down-element' specifications."
781 ;; Error when the element hasn't got a recursive type.
782 (org-test-with-temp-text "Paragraph."
783 (should-error (org-down-element)))
784 ;; Error when the element has no contents
785 (org-test-with-temp-text "* Headline"
786 (should-error (org-down-element)))
787 ;; When at a plain-list, move to first item.
788 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
791 (should (looking-at " - Item 1.1")))
792 (org-test-with-temp-text "#+NAME: list\n- Item 1"
794 (should (looking-at " Item 1")))
795 ;; When at a table, move to first row
796 (org-test-with-temp-text "#+NAME: table\n| a | b |"
798 (should (looking-at " a | b |")))
799 ;; Otherwise, move inside the greater element.
800 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
802 (should (looking-at "Paragraph"))))
804 (ert-deftest test-org
/drag-element-backward
()
805 "Test `org-drag-element-backward' specifications."
806 ;; 1. Error when trying to move first element of buffer.
807 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
808 (should-error (org-drag-element-backward)))
809 ;; 2. Error when trying to swap nested elements.
810 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
812 (should-error (org-drag-element-backward)))
813 ;; 3. Error when trying to swap an headline element and
814 ;; a non-headline element.
815 (org-test-with-temp-text "Test.\n* Head 1"
817 (should-error (org-drag-element-backward)))
818 ;; 4. Otherwise, swap elements, preserving column and blank lines
820 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
821 (search-forward "graph")
822 (org-drag-element-backward)
823 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
824 (should (looking-at " 2")))
825 ;; 5. Preserve visibility of elements and their contents.
826 (org-test-with-temp-text "
834 (while (search-forward "BEGIN_" nil t
) (org-cycle))
835 (search-backward "- item 1")
836 (org-drag-element-backward)
839 '((63 .
82) (26 .
48))
840 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
841 (overlays-in (point-min) (point-max)))))))
843 (ert-deftest test-org
/drag-element-forward
()
844 "Test `org-drag-element-forward' specifications."
845 ;; 1. Error when trying to move first element of buffer.
846 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
848 (should-error (org-drag-element-forward)))
849 ;; 2. Error when trying to swap nested elements.
850 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
852 (should-error (org-drag-element-forward)))
853 ;; 3. Error when trying to swap a non-headline element and an
855 (org-test-with-temp-text "Test.\n* Head 1"
856 (should-error (org-drag-element-forward)))
857 ;; 4. Otherwise, swap elements, preserving column and blank lines
859 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
860 (search-forward "graph")
861 (org-drag-element-forward)
862 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
863 (should (looking-at " 1")))
864 ;; 5. Preserve visibility of elements and their contents.
865 (org-test-with-temp-text "
873 (while (search-forward "BEGIN_" nil t
) (org-cycle))
874 (search-backward "#+BEGIN_CENTER")
875 (org-drag-element-forward)
878 '((63 .
82) (26 .
48))
879 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
880 (overlays-in (point-min) (point-max)))))))
884 ;;; Targets and Radio Targets
886 (ert-deftest test-org
/all-targets
()
887 "Test `org-all-targets' specifications."
888 ;; Without an argument.
890 (equal '("radio-target" "target")
891 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
894 (equal '("radio-target")
895 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
898 (equal '("radio-target")
899 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
900 (org-all-targets t
)))))
905 ;;; test-org.el ends here