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
)
91 ;;; Date and time analysis
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")))))
108 (ert-deftest test-org
/org-parse-time-string
()
109 "Test `org-parse-time-string'."
110 (should (equal (org-parse-time-string "2012-03-29 16:40")
111 '(0 40 16 29 3 2012 nil nil nil
)))
112 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
113 '(0 40 16 29 3 2012 nil nil nil
)))
114 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
115 '(0 40 16 29 3 2012 nil nil nil
)))
116 (should (equal (org-parse-time-string "<2012-03-29>")
117 '(0 0 0 29 3 2012 nil nil nil
)))
118 (should (equal (org-parse-time-string "<2012-03-29>" t
)
119 '(0 nil nil
29 3 2012 nil nil nil
))))
124 (ert-deftest test-org
/fill-paragraph
()
125 "Test `org-fill-paragraph' specifications."
126 ;; At an Org table, align it.
127 (org-test-with-temp-text "|a|"
129 (should (equal (buffer-string) "| a |\n")))
130 ;; At a paragraph, preserve line breaks.
131 (org-test-with-temp-text "some \\\\\nlong\ntext"
132 (let ((fill-column 20))
134 (should (equal (buffer-string) "some \\\\\nlong text"))))
135 ;; Correctly fill a paragraph when point is at its very end.
138 (org-test-with-temp-text "A\nB"
139 (let ((fill-column 20))
140 (goto-char (point-max))
143 ;; Correctly fill the last paragraph of a greater element.
145 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
146 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
147 (let ((fill-column 8))
152 ;; Correctly fill an element in a narrowed buffer.
155 (org-test-with-temp-text "01234 6789"
156 (let ((fill-column 5))
157 (narrow-to-region 1 8)
160 ;; Special case: Fill first paragraph when point is at an item or
161 ;; a plain-list or a footnote reference.
164 (org-test-with-temp-text "- A\n B"
165 (let ((fill-column 20))
170 (org-test-with-temp-text "[fn:1] A\nB"
171 (let ((fill-column 20))
174 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
175 (let ((fill-column 20))
177 (should (equal (buffer-string)
178 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
179 ;; Fill contents of `comment-block' elements.
182 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
183 (let ((fill-column 20))
187 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
188 ;; Fill `comment' elements.
191 (org-test-with-temp-text " # A\n # B"
192 (let ((fill-column 20))
195 ;; Do nothing at affiliated keywords.
196 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
197 (let ((fill-column 20))
199 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
201 (ert-deftest test-org
/auto-fill-function
()
202 "Test auto-filling features."
203 ;; Auto fill paragraph.
206 (org-test-with-temp-text "12345 7890"
207 (let ((fill-column 5))
209 (org-auto-fill-function)
211 ;; Auto fill first paragraph in an item.
213 (equal "- 12345\n 7890"
214 (org-test-with-temp-text "- 12345 7890"
215 (let ((fill-column 7))
217 (org-auto-fill-function)
219 ;; Auto fill comments.
221 (equal " # 12345\n # 7890"
222 (org-test-with-temp-text " # 12345 7890"
223 (let ((fill-column 10))
225 (org-auto-fill-function)
227 ;; A hash within a line isn't a comment.
229 (equal "12345 # 7890\n# 1"
230 (org-test-with-temp-text "12345 # 7890 1"
231 (let ((fill-column 12))
233 (org-auto-fill-function)
235 ;; Correctly interpret empty prefix.
237 (equal "# a\n# b\nRegular\n# paragraph"
238 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
239 (let ((fill-column 12))
241 (org-auto-fill-function)
243 ;; Comment block: auto fill contents.
245 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
246 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
247 (let ((fill-column 5))
250 (org-auto-fill-function)
253 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
254 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
255 (let ((fill-column 5))
258 (org-auto-fill-function)
260 ;; Do not fill if a new item could be created.
263 (org-test-with-temp-text "12345 - 90"
264 (let ((fill-column 5))
266 (org-auto-fill-function)
268 ;; Do not fill if a line break could be introduced.
270 (equal "123\\\\\n7890"
271 (org-test-with-temp-text "123\\\\ 7890"
272 (let ((fill-column 6))
274 (org-auto-fill-function)
276 ;; Do not fill affiliated keywords.
278 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
279 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
280 (let ((fill-column 20))
282 (org-auto-fill-function)
291 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
292 ;; a target keyword (aka an invisible target: #+TARGET: text), to
293 ;; a named element (#+name: text) and to headlines (* Text).
295 (ert-deftest test-org
/fuzzy-links
()
296 "Test fuzzy links specifications."
297 ;; 1. Fuzzy link goes in priority to a matching target.
298 (org-test-with-temp-text
299 "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
302 (should (looking-at "<<Test>>")))
303 ;; 2. Fuzzy link should then go to a matching target keyword.
304 (org-test-with-temp-text
305 "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
308 (should (looking-at "#\\+TARGET: Test")))
309 ;; 3. Then fuzzy link points to an element with a given name.
310 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
313 (should (looking-at "#\\+NAME: Test")))
314 ;; 4. A target still lead to a matching headline otherwise.
315 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
318 (should (looking-at "\\* Head2")))
319 ;; 5. With a leading star in link, enforce heading match.
320 (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
323 (should (looking-at "\\* Test"))))
328 (ert-deftest test-org
/org-link-escape-ascii-character
()
329 "Escape an ascii character."
333 (org-link-escape "["))))
335 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
336 "Escape an ascii control character."
340 (org-link-escape "\t"))))
342 (ert-deftest test-org
/org-link-escape-multibyte-character
()
343 "Escape an unicode multibyte character."
347 (org-link-escape "€"))))
349 (ert-deftest test-org
/org-link-escape-custom-table
()
350 "Escape string with custom character table."
354 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
356 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
357 "Escape string with custom table merged with default table."
360 "%5BF%6F%6F%3A%42ar%0A%5D"
361 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
363 (ert-deftest test-org
/org-link-unescape-ascii-character
()
364 "Unescape an ascii character."
368 (org-link-unescape "%5B"))))
370 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
371 "Unescpae an ascii control character."
375 (org-link-unescape "%0A"))))
377 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
378 "Unescape unicode multibyte character."
382 (org-link-unescape "%E2%82%AC"))))
384 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
385 "Unescape old style percent escaped character."
388 "à âçèéêîôùû"
389 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
391 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
392 "Escape and unscape a URL that includes an escaped char.
393 http://article.gmane.org/gmane.emacs.orgmode/21459/"
396 "http://some.host.com/form?&id=blah%2Bblah25"
397 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
403 (ert-deftest test-org
/macro-replace-all
()
404 "Test `org-macro-replace-all' specifications."
408 "#+MACRO: A B\n1 B 3"
409 (org-test-with-temp-text "#+MACRO: A B\n1 {{{A}}} 3"
410 (progn (org-macro-initialize-templates)
411 (org-macro-replace-all org-macro-templates
)
413 ;; Macro with arguments.
416 "#+MACRO: macro $1 $2\nsome text"
417 (org-test-with-temp-text "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
418 (progn (org-macro-initialize-templates)
419 (org-macro-replace-all org-macro-templates
)
421 ;; Macro with "eval".
424 "#+MACRO: add (eval (+ $1 $2))\n3"
425 (org-test-with-temp-text "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
426 (progn (org-macro-initialize-templates)
427 (org-macro-replace-all org-macro-templates
)
432 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\ninner outer"
433 (org-test-with-temp-text
434 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
435 (progn (org-macro-initialize-templates)
436 (org-macro-replace-all org-macro-templates
)
438 ;; Error out when macro expansion is circular.
440 (org-test-with-temp-text
441 "#+MACRO: mac1 {{{mac2}}}\n#+MACRO: mac2 {{{mac1}}}\n{{{mac1}}}"
442 (org-macro-initialize-templates)
443 (org-macro-replace-all org-macro-templates
))))
449 (ert-deftest test-org
/accumulated-properties-in-drawers
()
450 "Ensure properties accumulate in subtree drawers."
451 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
452 (org-babel-next-src-block)
453 (should (equal '(2 1) (org-babel-execute-src-block)))))
459 (ert-deftest test-org
/mark-subtree
()
460 "Test `org-mark-subtree' specifications."
461 ;; Error when point is before first headline.
463 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
464 (progn (transient-mark-mode 1)
465 (org-mark-subtree))))
466 ;; Without argument, mark current subtree.
470 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
471 (progn (transient-mark-mode 1)
474 (list (region-beginning) (region-end))))))
475 ;; With an argument, move ARG up.
479 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
480 (progn (transient-mark-mode 1)
483 (list (region-beginning) (region-end))))))
484 ;; Do not get fooled by inlinetasks.
485 (when (featurep 'org-inlinetask
)
488 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
489 (progn (transient-mark-mode 1)
491 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
492 (region-beginning)))))))
498 (ert-deftest test-org
/beginning-of-line
()
499 "Test `org-beginning-of-line' specifications."
502 (org-test-with-temp-text "Some text\nSome other text"
503 (progn (org-beginning-of-line) (bolp))))
504 ;; Standard test with `visual-line-mode'.
506 (org-test-with-temp-text "A long line of text\nSome other text"
507 (progn (visual-line-mode)
509 (dotimes (i 1000) (insert "very "))
510 (org-beginning-of-line)
512 ;; At an headline with special movement.
514 (org-test-with-temp-text "* TODO Headline"
515 (let ((org-special-ctrl-a/e t
))
517 (and (progn (org-beginning-of-line) (looking-at "Headline"))
518 (progn (org-beginning-of-line) (bolp))
519 (progn (org-beginning-of-line) (looking-at "Headline")))))))
521 (ert-deftest test-org
/end-of-line
()
522 "Test `org-end-of-line' specifications."
525 (org-test-with-temp-text "Some text\nSome other text"
526 (progn (org-end-of-line) (eolp))))
527 ;; Standard test with `visual-line-mode'.
529 (org-test-with-temp-text "A long line of text\nSome other text"
530 (progn (visual-line-mode)
532 (dotimes (i 1000) (insert "very "))
533 (goto-char (point-min))
536 ;; At an headline with special movement.
538 (org-test-with-temp-text "* Headline1 :tag:\n"
539 (let ((org-special-ctrl-a/e t
))
540 (and (progn (org-end-of-line) (looking-at " :tag:"))
541 (progn (org-end-of-line) (eolp))
542 (progn (org-end-of-line) (looking-at " :tag:"))))))
543 ;; At an headline without special movement.
545 (org-test-with-temp-text "* Headline2 :tag:\n"
546 (let ((org-special-ctrl-a/e nil
))
547 (and (progn (org-end-of-line) (eolp))
548 (progn (org-end-of-line) (eolp))))))
549 ;; At an headline, with reversed movement.
551 (org-test-with-temp-text "* Headline3 :tag:\n"
552 (let ((org-special-ctrl-a/e
'reversed
)
553 (this-command last-command
))
554 (and (progn (org-end-of-line) (eolp))
555 (progn (org-end-of-line) (looking-at " :tag:"))))))
556 ;; At a block without hidden contents.
558 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
559 (progn (org-end-of-line) (eolp))))
560 ;; At a block with hidden contents.
562 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
563 (let ((org-special-ctrl-a/e t
))
564 (org-hide-block-toggle)
568 (ert-deftest test-org
/forward-element
()
569 "Test `org-forward-element' specifications."
570 ;; 1. At EOB: should error.
571 (org-test-with-temp-text "Some text\n"
572 (goto-char (point-max))
573 (should-error (org-forward-element)))
574 ;; 2. Standard move: expected to ignore blank lines.
575 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
576 (org-forward-element)
577 (should (looking-at "Second paragraph.")))
578 ;; 3. Headline tests.
579 (org-test-with-temp-text "
584 ;; 3.1. At an headline beginning: move to next headline at the
587 (org-forward-element)
588 (should (looking-at "** Head 1.2"))
589 ;; 3.2. At an headline beginning: move to parent headline if no
590 ;; headline at the same level.
592 (org-forward-element)
593 (should (looking-at "** Head 1.2")))
594 ;; 4. Greater element tests.
595 (org-test-with-temp-text
596 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
597 ;; 4.1. At a greater element: expected to skip contents.
598 (org-forward-element)
599 (should (looking-at "Outside."))
600 ;; 4.2. At the end of greater element contents: expected to skip
601 ;; to the end of the greater element.
603 (org-forward-element)
604 (should (looking-at "Outside.")))
606 (org-test-with-temp-text "
620 ;; 5.1. At list top point: expected to move to the element after
623 (org-forward-element)
624 (should (looking-at "Outside."))
625 ;; 5.2. Special case: at the first line of a sub-list, but not at
626 ;; beginning of line, move to next item.
629 (org-forward-element)
630 (should (looking-at "- item2"))
633 (org-forward-element)
634 (should (looking-at " - sub2"))
635 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
637 (org-forward-element)
638 (should (looking-at " Inner paragraph."))
639 ;; 5.4. At sub-list end: expected to move outside the sub-list.
641 (org-forward-element)
642 (should (looking-at " Inner paragraph."))
643 ;; 5.5. At an item: expected to move to next item, if any.
645 (org-forward-element)
646 (should (looking-at " - sub3"))))
648 (ert-deftest test-org
/backward-element
()
649 "Test `org-backward-element' specifications."
650 ;; 1. Should error at BOB.
651 (org-test-with-temp-text " \nParagraph."
652 (should-error (org-backward-element)))
653 ;; 2. Should move at BOB when called on the first element in buffer.
655 (org-test-with-temp-text "\n#+TITLE: test"
656 (progn (forward-line)
657 (org-backward-element)
659 ;; 3. Not at the beginning of an element: move at its beginning.
660 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
663 (org-backward-element)
664 (should (looking-at "Paragraph2.")))
665 ;; 4. Headline tests.
666 (org-test-with-temp-text "
671 ;; 4.1. At an headline beginning: move to previous headline at the
674 (org-backward-element)
675 (should (looking-at "** Head 1.1"))
676 ;; 4.2. At an headline beginning: move to parent headline if no
677 ;; headline at the same level.
679 (org-backward-element)
680 (should (looking-at "* Head 1"))
681 ;; 4.3. At the first top-level headline: should error.
683 (should-error (org-backward-element)))
684 ;; 5. At beginning of first element inside a greater element:
685 ;; expected to move to greater element's beginning.
686 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
688 (org-backward-element)
689 (should (looking-at "#\\+BEGIN_CENTER")))
690 ;; 6. At the beginning of the first element in a section: should
691 ;; move back to headline, if any.
693 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
694 (progn (goto-char (point-max))
696 (org-backward-element)
697 (org-at-heading-p))))
699 (org-test-with-temp-text "
714 ;; 7.1. At beginning of sub-list: expected to move to the
715 ;; paragraph before it.
717 (org-backward-element)
718 (should (looking-at "item1"))
719 ;; 7.2. At an item in a list: expected to move at previous item.
721 (org-backward-element)
722 (should (looking-at " - sub2"))
724 (org-backward-element)
725 (should (looking-at "- item1"))
726 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
729 (org-backward-element)
730 (should (looking-at " - sub1"))
732 (org-backward-element)
733 (should (looking-at "- item1"))
734 ;; 7.4. At blank-lines before list end: expected to move to top
737 (org-backward-element)
738 (should (looking-at "- item1"))))
740 (ert-deftest test-org
/up-element
()
741 "Test `org-up-element' specifications."
742 ;; 1. At BOB or with no surrounding element: should error.
743 (org-test-with-temp-text "Paragraph."
744 (should-error (org-up-element)))
745 (org-test-with-temp-text "* Head1\n* Head2"
747 (should-error (org-up-element)))
748 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
750 (should-error (org-up-element)))
751 ;; 2. At an headline: move to parent headline.
752 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
755 (should (looking-at "\\* Head1")))
756 ;; 3. Inside a greater element: move to greater element beginning.
757 (org-test-with-temp-text
758 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
761 (should (looking-at "#\\+BEGIN_CENTER")))
763 (org-test-with-temp-text "* Top
770 Paragraph within sub2.
773 ;; 4.1. Within an item: move to the item beginning.
776 (should (looking-at " - sub2"))
777 ;; 4.2. At an item in a sub-list: move to parent item.
780 (should (looking-at "- item1"))
781 ;; 4.3. At an item in top list: move to beginning of whole list.
784 (should (looking-at "- item1"))
785 ;; 4.4. Special case. At very top point: should move to parent of
789 (should (looking-at "\\* Top"))))
791 (ert-deftest test-org
/down-element
()
792 "Test `org-down-element' specifications."
793 ;; Error when the element hasn't got a recursive type.
794 (org-test-with-temp-text "Paragraph."
795 (should-error (org-down-element)))
796 ;; Error when the element has no contents
797 (org-test-with-temp-text "* Headline"
798 (should-error (org-down-element)))
799 ;; When at a plain-list, move to first item.
800 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
803 (should (looking-at " - Item 1.1")))
804 (org-test-with-temp-text "#+NAME: list\n- Item 1"
806 (should (looking-at " Item 1")))
807 ;; When at a table, move to first row
808 (org-test-with-temp-text "#+NAME: table\n| a | b |"
810 (should (looking-at " a | b |")))
811 ;; Otherwise, move inside the greater element.
812 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
814 (should (looking-at "Paragraph"))))
816 (ert-deftest test-org
/drag-element-backward
()
817 "Test `org-drag-element-backward' specifications."
818 ;; 1. Error when trying to move first element of buffer.
819 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
820 (should-error (org-drag-element-backward)))
821 ;; 2. Error when trying to swap nested elements.
822 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
824 (should-error (org-drag-element-backward)))
825 ;; 3. Error when trying to swap an headline element and
826 ;; a non-headline element.
827 (org-test-with-temp-text "Test.\n* Head 1"
829 (should-error (org-drag-element-backward)))
830 ;; 4. Otherwise, swap elements, preserving column and blank lines
832 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
833 (search-forward "graph")
834 (org-drag-element-backward)
835 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
836 (should (looking-at " 2")))
837 ;; 5. Preserve visibility of elements and their contents.
838 (org-test-with-temp-text "
846 (while (search-forward "BEGIN_" nil t
) (org-cycle))
847 (search-backward "- item 1")
848 (org-drag-element-backward)
851 '((63 .
82) (26 .
48))
852 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
853 (overlays-in (point-min) (point-max)))))))
855 (ert-deftest test-org
/drag-element-forward
()
856 "Test `org-drag-element-forward' specifications."
857 ;; 1. Error when trying to move first element of buffer.
858 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
860 (should-error (org-drag-element-forward)))
861 ;; 2. Error when trying to swap nested elements.
862 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
864 (should-error (org-drag-element-forward)))
865 ;; 3. Error when trying to swap a non-headline element and an
867 (org-test-with-temp-text "Test.\n* Head 1"
868 (should-error (org-drag-element-forward)))
869 ;; 4. Otherwise, swap elements, preserving column and blank lines
871 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
872 (search-forward "graph")
873 (org-drag-element-forward)
874 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
875 (should (looking-at " 1")))
876 ;; 5. Preserve visibility of elements and their contents.
877 (org-test-with-temp-text "
885 (while (search-forward "BEGIN_" nil t
) (org-cycle))
886 (search-backward "#+BEGIN_CENTER")
887 (org-drag-element-forward)
890 '((63 .
82) (26 .
48))
891 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
892 (overlays-in (point-min) (point-max)))))))
896 ;;; Targets and Radio Targets
898 (ert-deftest test-org
/all-targets
()
899 "Test `org-all-targets' specifications."
900 ;; Without an argument.
902 (equal '("radio-target" "target")
903 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
906 (equal '("radio-target")
907 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
910 (equal '("radio-target")
911 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
912 (org-all-targets t
)))))
917 ;;; test-org.el ends here