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 lines if
73 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
75 (equal "# Comment 1\n\n# Comment 2"
76 (org-test-with-temp-text "Comment 1\n\nComment 2"
78 (transient-mark-mode 1)
79 (push-mark (point) t t
)
80 (goto-char (point-max))
81 (let ((comment-empty-lines nil
))
82 (call-interactively 'comment-dwim
))
85 (equal "# Comment 1\n# \n# Comment 2"
86 (org-test-with-temp-text "Comment 1\n\nComment 2"
88 (transient-mark-mode 1)
89 (push-mark (point) t t
)
90 (goto-char (point-max))
91 (let ((comment-empty-lines t
))
92 (call-interactively 'comment-dwim
))
94 ;; In front of a keyword without region, insert a new comment.
96 (equal "# \n#+KEYWORD: value"
97 (org-test-with-temp-text "#+KEYWORD: value"
98 (progn (call-interactively 'comment-dwim
)
103 ;;; Date and time analysis
105 (ert-deftest test-org
/org-read-date
()
106 "Test `org-read-date' specifications."
107 ;; Parse ISO date with abbreviated year and month.
108 (should (equal "2012-03-29 16:40"
109 (let ((org-time-was-given t
))
110 (org-read-date t nil
"12-3-29 16:40"))))
111 ;; Parse Europeans dates.
112 (should (equal "2012-03-29 16:40"
113 (let ((org-time-was-given t
))
114 (org-read-date t nil
"29.03.2012 16:40"))))
115 ;; Parse Europeans dates without year.
116 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
117 (let ((org-time-was-given t
))
118 (org-read-date t nil
"29.03. 16:40")))))
120 (ert-deftest test-org
/org-parse-time-string
()
121 "Test `org-parse-time-string'."
122 (should (equal (org-parse-time-string "2012-03-29 16:40")
123 '(0 40 16 29 3 2012 nil nil nil
)))
124 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
125 '(0 40 16 29 3 2012 nil nil nil
)))
126 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
127 '(0 40 16 29 3 2012 nil nil nil
)))
128 (should (equal (org-parse-time-string "<2012-03-29>")
129 '(0 0 0 29 3 2012 nil nil nil
)))
130 (should (equal (org-parse-time-string "<2012-03-29>" t
)
131 '(0 nil nil
29 3 2012 nil nil nil
))))
136 (ert-deftest test-org
/fill-paragraph
()
137 "Test `org-fill-paragraph' specifications."
138 ;; At an Org table, align it.
141 (org-test-with-temp-text "|a|"
145 (equal "#+name: table\n| a |\n"
146 (org-test-with-temp-text "#+name: table\n| a |"
149 ;; At a paragraph, preserve line breaks.
150 (org-test-with-temp-text "some \\\\\nlong\ntext"
151 (let ((fill-column 20))
153 (should (equal (buffer-string) "some \\\\\nlong text"))))
154 ;; Correctly fill a paragraph when point is at its very end.
157 (org-test-with-temp-text "A\nB"
158 (let ((fill-column 20))
159 (goto-char (point-max))
162 ;; Correctly fill the last paragraph of a greater element.
164 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
165 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
166 (let ((fill-column 8))
171 ;; Correctly fill an element in a narrowed buffer.
174 (org-test-with-temp-text "01234 6789"
175 (let ((fill-column 5))
176 (narrow-to-region 1 8)
179 ;; Special case: Fill first paragraph when point is at an item or
180 ;; a plain-list or a footnote reference.
183 (org-test-with-temp-text "- A\n B"
184 (let ((fill-column 20))
189 (org-test-with-temp-text "[fn:1] A\nB"
190 (let ((fill-column 20))
193 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
194 (let ((fill-column 20))
196 (should (equal (buffer-string)
197 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
198 ;; Fill contents of `comment-block' elements.
201 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
202 (let ((fill-column 20))
206 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
207 ;; Fill `comment' elements.
210 (org-test-with-temp-text " # A\n # B"
211 (let ((fill-column 20))
214 ;; Do not mix consecutive comments when filling one of them.
216 (equal "# A B\n\n# C"
217 (org-test-with-temp-text "# A\n# B\n\n# C"
218 (let ((fill-column 20))
221 ;; Use commented empty lines as separators when filling comments.
223 (equal "# A B\n#\n# C"
224 (org-test-with-temp-text "# A\n# B\n#\n# C"
225 (let ((fill-column 20))
228 ;; Do nothing at affiliated keywords.
229 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
230 (let ((fill-column 20))
232 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
233 ;; Do not move point after table when filling a table.
235 (org-test-with-temp-text "| a | b |\n| c | d |\n"
240 (ert-deftest test-org
/auto-fill-function
()
241 "Test auto-filling features."
242 ;; Auto fill paragraph.
245 (org-test-with-temp-text "12345 7890"
246 (let ((fill-column 5))
248 (org-auto-fill-function)
250 ;; Auto fill first paragraph in an item.
252 (equal "- 12345\n 7890"
253 (org-test-with-temp-text "- 12345 7890"
254 (let ((fill-column 7))
256 (org-auto-fill-function)
258 ;; Auto fill comments.
260 (equal " # 12345\n # 7890"
261 (org-test-with-temp-text " # 12345 7890"
262 (let ((fill-column 10))
264 (org-auto-fill-function)
266 ;; A hash within a line isn't a comment.
268 (equal "12345 # 7890\n# 1"
269 (org-test-with-temp-text "12345 # 7890 1"
270 (let ((fill-column 12))
272 (org-auto-fill-function)
274 ;; Correctly interpret empty prefix.
276 (equal "# a\n# b\nRegular\n# paragraph"
277 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
278 (let ((fill-column 12))
280 (org-auto-fill-function)
282 ;; Comment block: auto fill contents.
284 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
285 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
286 (let ((fill-column 5))
289 (org-auto-fill-function)
292 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
293 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
294 (let ((fill-column 5))
297 (org-auto-fill-function)
299 ;; Do not fill if a new item could be created.
302 (org-test-with-temp-text "12345 - 90"
303 (let ((fill-column 5))
305 (org-auto-fill-function)
307 ;; Do not fill if a line break could be introduced.
309 (equal "123\\\\\n7890"
310 (org-test-with-temp-text "123\\\\ 7890"
311 (let ((fill-column 6))
313 (org-auto-fill-function)
315 ;; Do not fill affiliated keywords.
317 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
318 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
319 (let ((fill-column 20))
321 (org-auto-fill-function)
330 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
331 ;; a named element (#+name: text) and to headlines (* Text).
333 (ert-deftest test-org
/fuzzy-links
()
334 "Test fuzzy links specifications."
335 ;; 1. Fuzzy link goes in priority to a matching target.
337 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
340 (looking-at "<<Test>>")))
341 ;; 2. Then fuzzy link points to an element with a given name.
343 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
346 (looking-at "#\\+NAME: Test")))
347 ;; 3. A target still lead to a matching headline otherwise.
349 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
352 (looking-at "\\* Head2")))
353 ;; 4. With a leading star in link, enforce heading match.
355 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
358 (looking-at "\\* Test"))))
363 (ert-deftest test-org
/org-link-escape-ascii-character
()
364 "Escape an ascii character."
368 (org-link-escape "["))))
370 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
371 "Escape an ascii control character."
375 (org-link-escape "\t"))))
377 (ert-deftest test-org
/org-link-escape-multibyte-character
()
378 "Escape an unicode multibyte character."
382 (org-link-escape "€"))))
384 (ert-deftest test-org
/org-link-escape-custom-table
()
385 "Escape string with custom character table."
389 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
391 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
392 "Escape string with custom table merged with default table."
395 "%5BF%6F%6F%3A%42ar%0A%5D"
396 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
398 (ert-deftest test-org
/org-link-unescape-ascii-character
()
399 "Unescape an ascii character."
403 (org-link-unescape "%5B"))))
405 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
406 "Unescpae an ascii control character."
410 (org-link-unescape "%0A"))))
412 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
413 "Unescape unicode multibyte character."
417 (org-link-unescape "%E2%82%AC"))))
419 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
420 "Unescape old style percent escaped character."
423 "à âçèéêîôùû"
424 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
426 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
427 "Escape and unscape a URL that includes an escaped char.
428 http://article.gmane.org/gmane.emacs.orgmode/21459/"
431 "http://some.host.com/form?&id=blah%2Bblah25"
432 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
438 (ert-deftest test-org
/accumulated-properties-in-drawers
()
439 "Ensure properties accumulate in subtree drawers."
440 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
441 (org-babel-next-src-block)
442 (should (equal '(2 1) (org-babel-execute-src-block)))))
448 (ert-deftest test-org
/mark-subtree
()
449 "Test `org-mark-subtree' specifications."
450 ;; Error when point is before first headline.
452 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
453 (progn (transient-mark-mode 1)
454 (org-mark-subtree))))
455 ;; Without argument, mark current subtree.
459 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
460 (progn (transient-mark-mode 1)
463 (list (region-beginning) (region-end))))))
464 ;; With an argument, move ARG up.
468 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
469 (progn (transient-mark-mode 1)
472 (list (region-beginning) (region-end))))))
473 ;; Do not get fooled by inlinetasks.
474 (when (featurep 'org-inlinetask
)
477 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
478 (progn (transient-mark-mode 1)
480 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
481 (region-beginning)))))))
487 (ert-deftest test-org
/beginning-of-line
()
488 "Test `org-beginning-of-line' specifications."
491 (org-test-with-temp-text "Some text\nSome other text"
492 (progn (org-beginning-of-line) (bolp))))
493 ;; Standard test with `visual-line-mode'.
495 (org-test-with-temp-text "A long line of text\nSome other text"
496 (progn (visual-line-mode)
498 (dotimes (i 1000) (insert "very "))
499 (org-beginning-of-line)
501 ;; At an headline with special movement.
503 (org-test-with-temp-text "* TODO Headline"
504 (let ((org-special-ctrl-a/e t
))
506 (and (progn (org-beginning-of-line) (looking-at "Headline"))
507 (progn (org-beginning-of-line) (bolp))
508 (progn (org-beginning-of-line) (looking-at "Headline")))))))
510 (ert-deftest test-org
/end-of-line
()
511 "Test `org-end-of-line' specifications."
514 (org-test-with-temp-text "Some text\nSome other text"
515 (progn (org-end-of-line) (eolp))))
516 ;; Standard test with `visual-line-mode'.
518 (org-test-with-temp-text "A long line of text\nSome other text"
519 (progn (visual-line-mode)
521 (dotimes (i 1000) (insert "very "))
522 (goto-char (point-min))
525 ;; At an headline with special movement.
527 (org-test-with-temp-text "* Headline1 :tag:\n"
528 (let ((org-special-ctrl-a/e t
))
529 (and (progn (org-end-of-line) (looking-at " :tag:"))
530 (progn (org-end-of-line) (eolp))
531 (progn (org-end-of-line) (looking-at " :tag:"))))))
532 ;; At an headline without special movement.
534 (org-test-with-temp-text "* Headline2 :tag:\n"
535 (let ((org-special-ctrl-a/e nil
))
536 (and (progn (org-end-of-line) (eolp))
537 (progn (org-end-of-line) (eolp))))))
538 ;; At an headline, with reversed movement.
540 (org-test-with-temp-text "* Headline3 :tag:\n"
541 (let ((org-special-ctrl-a/e
'reversed
)
542 (this-command last-command
))
543 (and (progn (org-end-of-line) (eolp))
544 (progn (org-end-of-line) (looking-at " :tag:"))))))
545 ;; At a block without hidden contents.
547 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
548 (progn (org-end-of-line) (eolp))))
549 ;; At a block with hidden contents.
551 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
552 (let ((org-special-ctrl-a/e t
))
553 (org-hide-block-toggle)
557 (ert-deftest test-org
/forward-element
()
558 "Test `org-forward-element' specifications."
559 ;; 1. At EOB: should error.
560 (org-test-with-temp-text "Some text\n"
561 (goto-char (point-max))
562 (should-error (org-forward-element)))
563 ;; 2. Standard move: expected to ignore blank lines.
564 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
565 (org-forward-element)
566 (should (looking-at (regexp-quote "Second paragraph."))))
567 ;; 3. Headline tests.
568 (org-test-with-temp-text "
573 ;; 3.1. At an headline beginning: move to next headline at the
576 (org-forward-element)
577 (should (looking-at (regexp-quote "** Head 1.2")))
578 ;; 3.2. At an headline beginning: move to parent headline if no
579 ;; headline at the same level.
581 (org-forward-element)
582 (should (looking-at (regexp-quote "** Head 1.2"))))
583 ;; 4. Greater element tests.
584 (org-test-with-temp-text
585 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
586 ;; 4.1. At a greater element: expected to skip contents.
587 (org-forward-element)
588 (should (looking-at (regexp-quote "Outside.")))
589 ;; 4.2. At the end of greater element contents: expected to skip
590 ;; to the end of the greater element.
592 (org-forward-element)
593 (should (looking-at (regexp-quote "Outside."))))
595 (org-test-with-temp-text "
609 ;; 5.1. At list top point: expected to move to the element after
612 (org-forward-element)
613 (should (looking-at (regexp-quote "Outside.")))
614 ;; 5.2. Special case: at the first line of a sub-list, but not at
615 ;; beginning of line, move to next item.
618 (org-forward-element)
619 (should (looking-at "- item2"))
622 (org-forward-element)
623 (should (looking-at " - sub2"))
624 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
626 (org-forward-element)
627 (should (looking-at (regexp-quote " Inner paragraph.")))
628 ;; 5.4. At sub-list end: expected to move outside the sub-list.
630 (org-forward-element)
631 (should (looking-at (regexp-quote " Inner paragraph.")))
632 ;; 5.5. At an item: expected to move to next item, if any.
634 (org-forward-element)
635 (should (looking-at " - sub3"))))
637 (ert-deftest test-org
/backward-element
()
638 "Test `org-backward-element' specifications."
639 ;; 1. Should error at BOB.
640 (org-test-with-temp-text " \nParagraph."
641 (should-error (org-backward-element)))
642 ;; 2. Should move at BOB when called on the first element in buffer.
644 (org-test-with-temp-text "\n#+TITLE: test"
645 (progn (forward-line)
646 (org-backward-element)
648 ;; 3. Not at the beginning of an element: move at its beginning.
649 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
652 (org-backward-element)
653 (should (looking-at (regexp-quote "Paragraph2."))))
654 ;; 4. Headline tests.
655 (org-test-with-temp-text "
660 ;; 4.1. At an headline beginning: move to previous headline at the
663 (org-backward-element)
664 (should (looking-at (regexp-quote "** Head 1.1")))
665 ;; 4.2. At an headline beginning: move to parent headline if no
666 ;; headline at the same level.
668 (org-backward-element)
669 (should (looking-at (regexp-quote "* Head 1")))
670 ;; 4.3. At the first top-level headline: should error.
672 (should-error (org-backward-element)))
673 ;; 5. At beginning of first element inside a greater element:
674 ;; expected to move to greater element's beginning.
675 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
677 (org-backward-element)
678 (should (looking-at "#\\+BEGIN_CENTER")))
679 ;; 6. At the beginning of the first element in a section: should
680 ;; move back to headline, if any.
682 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
683 (progn (goto-char (point-max))
685 (org-backward-element)
686 (org-at-heading-p))))
688 (org-test-with-temp-text "
703 ;; 7.1. At beginning of sub-list: expected to move to the
704 ;; paragraph before it.
706 (org-backward-element)
707 (should (looking-at "item1"))
708 ;; 7.2. At an item in a list: expected to move at previous item.
710 (org-backward-element)
711 (should (looking-at " - sub2"))
713 (org-backward-element)
714 (should (looking-at "- item1"))
715 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
718 (org-backward-element)
719 (should (looking-at " - sub1"))
721 (org-backward-element)
722 (should (looking-at "- item1"))
723 ;; 7.4. At blank-lines before list end: expected to move to top
726 (org-backward-element)
727 (should (looking-at "- item1"))))
729 (ert-deftest test-org
/up-element
()
730 "Test `org-up-element' specifications."
731 ;; 1. At BOB or with no surrounding element: should error.
732 (org-test-with-temp-text "Paragraph."
733 (should-error (org-up-element)))
734 (org-test-with-temp-text "* Head1\n* Head2"
736 (should-error (org-up-element)))
737 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
739 (should-error (org-up-element)))
740 ;; 2. At an headline: move to parent headline.
741 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
744 (should (looking-at "\\* Head1")))
745 ;; 3. Inside a greater element: move to greater element beginning.
746 (org-test-with-temp-text
747 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
750 (should (looking-at "#\\+BEGIN_CENTER")))
752 (org-test-with-temp-text "* Top
759 Paragraph within sub2.
762 ;; 4.1. Within an item: move to the item beginning.
765 (should (looking-at " - sub2"))
766 ;; 4.2. At an item in a sub-list: move to parent item.
769 (should (looking-at "- item1"))
770 ;; 4.3. At an item in top list: move to beginning of whole list.
773 (should (looking-at "- item1"))
774 ;; 4.4. Special case. At very top point: should move to parent of
778 (should (looking-at "\\* Top"))))
780 (ert-deftest test-org
/down-element
()
781 "Test `org-down-element' specifications."
782 ;; Error when the element hasn't got a recursive type.
783 (org-test-with-temp-text "Paragraph."
784 (should-error (org-down-element)))
785 ;; Error when the element has no contents
786 (org-test-with-temp-text "* Headline"
787 (should-error (org-down-element)))
788 ;; When at a plain-list, move to first item.
789 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
792 (should (looking-at " - Item 1.1")))
793 (org-test-with-temp-text "#+NAME: list\n- Item 1"
795 (should (looking-at " Item 1")))
796 ;; When at a table, move to first row
797 (org-test-with-temp-text "#+NAME: table\n| a | b |"
799 (should (looking-at " a | b |")))
800 ;; Otherwise, move inside the greater element.
801 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
803 (should (looking-at "Paragraph"))))
805 (ert-deftest test-org
/drag-element-backward
()
806 "Test `org-drag-element-backward' specifications."
807 ;; 1. Error when trying to move first element of buffer.
808 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
809 (should-error (org-drag-element-backward)))
810 ;; 2. Error when trying to swap nested elements.
811 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
813 (should-error (org-drag-element-backward)))
814 ;; 3. Error when trying to swap an headline element and
815 ;; a non-headline element.
816 (org-test-with-temp-text "Test.\n* Head 1"
818 (should-error (org-drag-element-backward)))
819 ;; 4. Otherwise, swap elements, preserving column and blank lines
821 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
822 (search-forward "graph")
823 (org-drag-element-backward)
824 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
825 (should (looking-at " 2")))
826 ;; 5. Preserve visibility of elements and their contents.
827 (org-test-with-temp-text "
835 (while (search-forward "BEGIN_" nil t
) (org-cycle))
836 (search-backward "- item 1")
837 (org-drag-element-backward)
840 '((63 .
82) (26 .
48))
841 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
842 (overlays-in (point-min) (point-max)))))))
844 (ert-deftest test-org
/drag-element-forward
()
845 "Test `org-drag-element-forward' specifications."
846 ;; 1. Error when trying to move first element of buffer.
847 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
849 (should-error (org-drag-element-forward)))
850 ;; 2. Error when trying to swap nested elements.
851 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
853 (should-error (org-drag-element-forward)))
854 ;; 3. Error when trying to swap a non-headline element and an
856 (org-test-with-temp-text "Test.\n* Head 1"
857 (should-error (org-drag-element-forward)))
858 ;; 4. Otherwise, swap elements, preserving column and blank lines
860 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
861 (search-forward "graph")
862 (org-drag-element-forward)
863 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
864 (should (looking-at " 1")))
865 ;; 5. Preserve visibility of elements and their contents.
866 (org-test-with-temp-text "
874 (while (search-forward "BEGIN_" nil t
) (org-cycle))
875 (search-backward "#+BEGIN_CENTER")
876 (org-drag-element-forward)
879 '((63 .
82) (26 .
48))
880 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
881 (overlays-in (point-min) (point-max)))))))
887 (ert-deftest test-org
/timestamp-has-time-p
()
888 "Test `org-timestamp-has-time-p' specifications."
891 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
892 (org-timestamp-has-time-p (org-element-context))))
895 (org-test-with-temp-text "<2012-03-29 Thu>"
896 (org-timestamp-has-time-p (org-element-context)))))
898 (ert-deftest test-org
/timestamp-format
()
899 "Test `org-timestamp-format' specifications."
904 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
905 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
910 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
911 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
913 (ert-deftest test-org
/timestamp-split-range
()
914 "Test `org-timestamp-split-range' specifications."
915 ;; Extract range start (active).
918 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
919 (let ((ts (org-timestamp-split-range (org-element-context))))
920 (mapcar (lambda (p) (org-element-property p ts
))
921 '(:year-end
:month-end
:day-end
))))))
922 ;; Extract range start (inactive)
925 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
926 (let ((ts (org-timestamp-split-range (org-element-context))))
927 (mapcar (lambda (p) (org-element-property p ts
))
928 '(:year-end
:month-end
:day-end
))))))
929 ;; Extract range end (active).
932 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
933 (let ((ts (org-timestamp-split-range
934 (org-element-context) t
)))
935 (mapcar (lambda (p) (org-element-property p ts
))
936 '(:year-end
:month-end
:day-end
))))))
937 ;; Extract range end (inactive)
940 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
941 (let ((ts (org-timestamp-split-range
942 (org-element-context) t
)))
943 (mapcar (lambda (p) (org-element-property p ts
))
944 '(:year-end
:month-end
:day-end
))))))
945 ;; Return the timestamp if not a range.
947 (org-test-with-temp-text "[2012-03-29 Thu]"
948 (let* ((ts-orig (org-element-context))
949 (ts-copy (org-timestamp-split-range ts-orig
)))
950 (eq ts-orig ts-copy
))))
952 (org-test-with-temp-text "<%%(org-float t 4 2)>"
953 (let* ((ts-orig (org-element-context))
954 (ts-copy (org-timestamp-split-range ts-orig
)))
955 (eq ts-orig ts-copy
))))
956 ;; Check that parent is the same when a range was split.
958 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
959 (let* ((ts-orig (org-element-context))
960 (ts-copy (org-timestamp-split-range ts-orig
)))
961 (eq (org-element-property :parent ts-orig
)
962 (org-element-property :parent ts-copy
))))))
964 (ert-deftest test-org
/timestamp-translate
()
965 "Test `org-timestamp-translate' specifications."
966 ;; Translate whole date range.
969 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
970 (let ((org-display-custom-times t
)
971 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
972 (org-timestamp-translate (org-element-context))))))
973 ;; Translate date range start.
976 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
977 (let ((org-display-custom-times t
)
978 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
979 (org-timestamp-translate (org-element-context) 'start
)))))
980 ;; Translate date range end.
983 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
984 (let ((org-display-custom-times t
)
985 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
986 (org-timestamp-translate (org-element-context) 'end
)))))
987 ;; Translate time range.
990 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
991 (let ((org-display-custom-times t
)
992 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
993 (org-timestamp-translate (org-element-context))))))
994 ;; Translate non-range timestamp.
997 (org-test-with-temp-text "<2012-03-29 Thu>"
998 (let ((org-display-custom-times t
)
999 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1000 (org-timestamp-translate (org-element-context))))))
1001 ;; Do not change `diary' timestamps.
1003 (equal "<%%(org-float t 4 2)>"
1004 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1005 (let ((org-display-custom-times t
)
1006 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1007 (org-timestamp-translate (org-element-context)))))))
1011 ;;; Targets and Radio Targets
1013 (ert-deftest test-org
/all-targets
()
1014 "Test `org-all-targets' specifications."
1015 ;; Without an argument.
1017 (equal '("radio-target" "target")
1018 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
1019 (org-all-targets))))
1021 (equal '("radio-target")
1022 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
1025 (equal '("radio-target")
1026 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
1027 (org-all-targets t
)))))
1032 ;;; test-org.el ends here