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."))))
200 ;; Do not move point after table when filling a table.
202 (org-test-with-temp-text "| a | b |\n| c | d |\n"
207 (ert-deftest test-org
/auto-fill-function
()
208 "Test auto-filling features."
209 ;; Auto fill paragraph.
212 (org-test-with-temp-text "12345 7890"
213 (let ((fill-column 5))
215 (org-auto-fill-function)
217 ;; Auto fill first paragraph in an item.
219 (equal "- 12345\n 7890"
220 (org-test-with-temp-text "- 12345 7890"
221 (let ((fill-column 7))
223 (org-auto-fill-function)
225 ;; Auto fill comments.
227 (equal " # 12345\n # 7890"
228 (org-test-with-temp-text " # 12345 7890"
229 (let ((fill-column 10))
231 (org-auto-fill-function)
233 ;; A hash within a line isn't a comment.
235 (equal "12345 # 7890\n# 1"
236 (org-test-with-temp-text "12345 # 7890 1"
237 (let ((fill-column 12))
239 (org-auto-fill-function)
241 ;; Correctly interpret empty prefix.
243 (equal "# a\n# b\nRegular\n# paragraph"
244 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
245 (let ((fill-column 12))
247 (org-auto-fill-function)
249 ;; Comment block: auto fill contents.
251 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
252 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
253 (let ((fill-column 5))
256 (org-auto-fill-function)
259 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
260 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
261 (let ((fill-column 5))
264 (org-auto-fill-function)
266 ;; Do not fill if a new item could be created.
269 (org-test-with-temp-text "12345 - 90"
270 (let ((fill-column 5))
272 (org-auto-fill-function)
274 ;; Do not fill if a line break could be introduced.
276 (equal "123\\\\\n7890"
277 (org-test-with-temp-text "123\\\\ 7890"
278 (let ((fill-column 6))
280 (org-auto-fill-function)
282 ;; Do not fill affiliated keywords.
284 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
285 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
286 (let ((fill-column 20))
288 (org-auto-fill-function)
297 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
298 ;; a named element (#+name: text) and to headlines (* Text).
300 (ert-deftest test-org
/fuzzy-links
()
301 "Test fuzzy links specifications."
302 ;; 1. Fuzzy link goes in priority to a matching target.
304 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
307 (looking-at "<<Test>>")))
308 ;; 2. 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 (looking-at "#\\+NAME: Test")))
314 ;; 3. A target still lead to a matching headline otherwise.
316 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
319 (looking-at "\\* Head2")))
320 ;; 4. With a leading star in link, enforce heading match.
322 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
325 (looking-at "\\* Test"))))
330 (ert-deftest test-org
/org-link-escape-ascii-character
()
331 "Escape an ascii character."
335 (org-link-escape "["))))
337 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
338 "Escape an ascii control character."
342 (org-link-escape "\t"))))
344 (ert-deftest test-org
/org-link-escape-multibyte-character
()
345 "Escape an unicode multibyte character."
349 (org-link-escape "€"))))
351 (ert-deftest test-org
/org-link-escape-custom-table
()
352 "Escape string with custom character table."
356 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
358 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
359 "Escape string with custom table merged with default table."
362 "%5BF%6F%6F%3A%42ar%0A%5D"
363 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
365 (ert-deftest test-org
/org-link-unescape-ascii-character
()
366 "Unescape an ascii character."
370 (org-link-unescape "%5B"))))
372 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
373 "Unescpae an ascii control character."
377 (org-link-unescape "%0A"))))
379 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
380 "Unescape unicode multibyte character."
384 (org-link-unescape "%E2%82%AC"))))
386 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
387 "Unescape old style percent escaped character."
390 "à âçèéêîôùû"
391 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
393 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
394 "Escape and unscape a URL that includes an escaped char.
395 http://article.gmane.org/gmane.emacs.orgmode/21459/"
398 "http://some.host.com/form?&id=blah%2Bblah25"
399 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
405 (ert-deftest test-org
/accumulated-properties-in-drawers
()
406 "Ensure properties accumulate in subtree drawers."
407 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
408 (org-babel-next-src-block)
409 (should (equal '(2 1) (org-babel-execute-src-block)))))
415 (ert-deftest test-org
/mark-subtree
()
416 "Test `org-mark-subtree' specifications."
417 ;; Error when point is before first headline.
419 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
420 (progn (transient-mark-mode 1)
421 (org-mark-subtree))))
422 ;; Without argument, mark current subtree.
426 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
427 (progn (transient-mark-mode 1)
430 (list (region-beginning) (region-end))))))
431 ;; With an argument, move ARG up.
435 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
436 (progn (transient-mark-mode 1)
439 (list (region-beginning) (region-end))))))
440 ;; Do not get fooled by inlinetasks.
441 (when (featurep 'org-inlinetask
)
444 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
445 (progn (transient-mark-mode 1)
447 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
448 (region-beginning)))))))
454 (ert-deftest test-org
/beginning-of-line
()
455 "Test `org-beginning-of-line' specifications."
458 (org-test-with-temp-text "Some text\nSome other text"
459 (progn (org-beginning-of-line) (bolp))))
460 ;; Standard test with `visual-line-mode'.
462 (org-test-with-temp-text "A long line of text\nSome other text"
463 (progn (visual-line-mode)
465 (dotimes (i 1000) (insert "very "))
466 (org-beginning-of-line)
468 ;; At an headline with special movement.
470 (org-test-with-temp-text "* TODO Headline"
471 (let ((org-special-ctrl-a/e t
))
473 (and (progn (org-beginning-of-line) (looking-at "Headline"))
474 (progn (org-beginning-of-line) (bolp))
475 (progn (org-beginning-of-line) (looking-at "Headline")))))))
477 (ert-deftest test-org
/end-of-line
()
478 "Test `org-end-of-line' specifications."
481 (org-test-with-temp-text "Some text\nSome other text"
482 (progn (org-end-of-line) (eolp))))
483 ;; Standard test with `visual-line-mode'.
485 (org-test-with-temp-text "A long line of text\nSome other text"
486 (progn (visual-line-mode)
488 (dotimes (i 1000) (insert "very "))
489 (goto-char (point-min))
492 ;; At an headline with special movement.
494 (org-test-with-temp-text "* Headline1 :tag:\n"
495 (let ((org-special-ctrl-a/e t
))
496 (and (progn (org-end-of-line) (looking-at " :tag:"))
497 (progn (org-end-of-line) (eolp))
498 (progn (org-end-of-line) (looking-at " :tag:"))))))
499 ;; At an headline without special movement.
501 (org-test-with-temp-text "* Headline2 :tag:\n"
502 (let ((org-special-ctrl-a/e nil
))
503 (and (progn (org-end-of-line) (eolp))
504 (progn (org-end-of-line) (eolp))))))
505 ;; At an headline, with reversed movement.
507 (org-test-with-temp-text "* Headline3 :tag:\n"
508 (let ((org-special-ctrl-a/e
'reversed
)
509 (this-command last-command
))
510 (and (progn (org-end-of-line) (eolp))
511 (progn (org-end-of-line) (looking-at " :tag:"))))))
512 ;; At a block without hidden contents.
514 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
515 (progn (org-end-of-line) (eolp))))
516 ;; At a block with hidden contents.
518 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
519 (let ((org-special-ctrl-a/e t
))
520 (org-hide-block-toggle)
524 (ert-deftest test-org
/forward-element
()
525 "Test `org-forward-element' specifications."
526 ;; 1. At EOB: should error.
527 (org-test-with-temp-text "Some text\n"
528 (goto-char (point-max))
529 (should-error (org-forward-element)))
530 ;; 2. Standard move: expected to ignore blank lines.
531 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
532 (org-forward-element)
533 (should (looking-at (regexp-quote "Second paragraph."))))
534 ;; 3. Headline tests.
535 (org-test-with-temp-text "
540 ;; 3.1. At an headline beginning: move to next headline at the
543 (org-forward-element)
544 (should (looking-at (regexp-quote "** Head 1.2")))
545 ;; 3.2. At an headline beginning: move to parent headline if no
546 ;; headline at the same level.
548 (org-forward-element)
549 (should (looking-at (regexp-quote "** Head 1.2"))))
550 ;; 4. Greater element tests.
551 (org-test-with-temp-text
552 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
553 ;; 4.1. At a greater element: expected to skip contents.
554 (org-forward-element)
555 (should (looking-at (regexp-quote "Outside.")))
556 ;; 4.2. At the end of greater element contents: expected to skip
557 ;; to the end of the greater element.
559 (org-forward-element)
560 (should (looking-at (regexp-quote "Outside."))))
562 (org-test-with-temp-text "
576 ;; 5.1. At list top point: expected to move to the element after
579 (org-forward-element)
580 (should (looking-at (regexp-quote "Outside.")))
581 ;; 5.2. Special case: at the first line of a sub-list, but not at
582 ;; beginning of line, move to next item.
585 (org-forward-element)
586 (should (looking-at "- item2"))
589 (org-forward-element)
590 (should (looking-at " - sub2"))
591 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
593 (org-forward-element)
594 (should (looking-at (regexp-quote " Inner paragraph.")))
595 ;; 5.4. At sub-list end: expected to move outside the sub-list.
597 (org-forward-element)
598 (should (looking-at (regexp-quote " Inner paragraph.")))
599 ;; 5.5. At an item: expected to move to next item, if any.
601 (org-forward-element)
602 (should (looking-at " - sub3"))))
604 (ert-deftest test-org
/backward-element
()
605 "Test `org-backward-element' specifications."
606 ;; 1. Should error at BOB.
607 (org-test-with-temp-text " \nParagraph."
608 (should-error (org-backward-element)))
609 ;; 2. Should move at BOB when called on the first element in buffer.
611 (org-test-with-temp-text "\n#+TITLE: test"
612 (progn (forward-line)
613 (org-backward-element)
615 ;; 3. Not at the beginning of an element: move at its beginning.
616 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
619 (org-backward-element)
620 (should (looking-at (regexp-quote "Paragraph2."))))
621 ;; 4. Headline tests.
622 (org-test-with-temp-text "
627 ;; 4.1. At an headline beginning: move to previous headline at the
630 (org-backward-element)
631 (should (looking-at (regexp-quote "** Head 1.1")))
632 ;; 4.2. At an headline beginning: move to parent headline if no
633 ;; headline at the same level.
635 (org-backward-element)
636 (should (looking-at (regexp-quote "* Head 1")))
637 ;; 4.3. At the first top-level headline: should error.
639 (should-error (org-backward-element)))
640 ;; 5. At beginning of first element inside a greater element:
641 ;; expected to move to greater element's beginning.
642 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
644 (org-backward-element)
645 (should (looking-at "#\\+BEGIN_CENTER")))
646 ;; 6. At the beginning of the first element in a section: should
647 ;; move back to headline, if any.
649 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
650 (progn (goto-char (point-max))
652 (org-backward-element)
653 (org-at-heading-p))))
655 (org-test-with-temp-text "
670 ;; 7.1. At beginning of sub-list: expected to move to the
671 ;; paragraph before it.
673 (org-backward-element)
674 (should (looking-at "item1"))
675 ;; 7.2. At an item in a list: expected to move at previous item.
677 (org-backward-element)
678 (should (looking-at " - sub2"))
680 (org-backward-element)
681 (should (looking-at "- item1"))
682 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
685 (org-backward-element)
686 (should (looking-at " - sub1"))
688 (org-backward-element)
689 (should (looking-at "- item1"))
690 ;; 7.4. At blank-lines before list end: expected to move to top
693 (org-backward-element)
694 (should (looking-at "- item1"))))
696 (ert-deftest test-org
/up-element
()
697 "Test `org-up-element' specifications."
698 ;; 1. At BOB or with no surrounding element: should error.
699 (org-test-with-temp-text "Paragraph."
700 (should-error (org-up-element)))
701 (org-test-with-temp-text "* Head1\n* Head2"
703 (should-error (org-up-element)))
704 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
706 (should-error (org-up-element)))
707 ;; 2. At an headline: move to parent headline.
708 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
711 (should (looking-at "\\* Head1")))
712 ;; 3. Inside a greater element: move to greater element beginning.
713 (org-test-with-temp-text
714 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
717 (should (looking-at "#\\+BEGIN_CENTER")))
719 (org-test-with-temp-text "* Top
726 Paragraph within sub2.
729 ;; 4.1. Within an item: move to the item beginning.
732 (should (looking-at " - sub2"))
733 ;; 4.2. At an item in a sub-list: move to parent item.
736 (should (looking-at "- item1"))
737 ;; 4.3. At an item in top list: move to beginning of whole list.
740 (should (looking-at "- item1"))
741 ;; 4.4. Special case. At very top point: should move to parent of
745 (should (looking-at "\\* Top"))))
747 (ert-deftest test-org
/down-element
()
748 "Test `org-down-element' specifications."
749 ;; Error when the element hasn't got a recursive type.
750 (org-test-with-temp-text "Paragraph."
751 (should-error (org-down-element)))
752 ;; Error when the element has no contents
753 (org-test-with-temp-text "* Headline"
754 (should-error (org-down-element)))
755 ;; When at a plain-list, move to first item.
756 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
759 (should (looking-at " - Item 1.1")))
760 (org-test-with-temp-text "#+NAME: list\n- Item 1"
762 (should (looking-at " Item 1")))
763 ;; When at a table, move to first row
764 (org-test-with-temp-text "#+NAME: table\n| a | b |"
766 (should (looking-at " a | b |")))
767 ;; Otherwise, move inside the greater element.
768 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
770 (should (looking-at "Paragraph"))))
772 (ert-deftest test-org
/drag-element-backward
()
773 "Test `org-drag-element-backward' specifications."
774 ;; 1. Error when trying to move first element of buffer.
775 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
776 (should-error (org-drag-element-backward)))
777 ;; 2. Error when trying to swap nested elements.
778 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
780 (should-error (org-drag-element-backward)))
781 ;; 3. Error when trying to swap an headline element and
782 ;; a non-headline element.
783 (org-test-with-temp-text "Test.\n* Head 1"
785 (should-error (org-drag-element-backward)))
786 ;; 4. Otherwise, swap elements, preserving column and blank lines
788 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
789 (search-forward "graph")
790 (org-drag-element-backward)
791 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
792 (should (looking-at " 2")))
793 ;; 5. Preserve visibility of elements and their contents.
794 (org-test-with-temp-text "
802 (while (search-forward "BEGIN_" nil t
) (org-cycle))
803 (search-backward "- item 1")
804 (org-drag-element-backward)
807 '((63 .
82) (26 .
48))
808 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
809 (overlays-in (point-min) (point-max)))))))
811 (ert-deftest test-org
/drag-element-forward
()
812 "Test `org-drag-element-forward' specifications."
813 ;; 1. Error when trying to move first element of buffer.
814 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
816 (should-error (org-drag-element-forward)))
817 ;; 2. Error when trying to swap nested elements.
818 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
820 (should-error (org-drag-element-forward)))
821 ;; 3. Error when trying to swap a non-headline element and an
823 (org-test-with-temp-text "Test.\n* Head 1"
824 (should-error (org-drag-element-forward)))
825 ;; 4. Otherwise, swap elements, preserving column and blank lines
827 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
828 (search-forward "graph")
829 (org-drag-element-forward)
830 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
831 (should (looking-at " 1")))
832 ;; 5. Preserve visibility of elements and their contents.
833 (org-test-with-temp-text "
841 (while (search-forward "BEGIN_" nil t
) (org-cycle))
842 (search-backward "#+BEGIN_CENTER")
843 (org-drag-element-forward)
846 '((63 .
82) (26 .
48))
847 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
848 (overlays-in (point-min) (point-max)))))))
854 (ert-deftest test-org
/timestamp-has-time-p
()
855 "Test `org-timestamp-has-time-p' specifications."
858 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
859 (org-timestamp-has-time-p (org-element-context))))
862 (org-test-with-temp-text "<2012-03-29 Thu>"
863 (org-timestamp-has-time-p (org-element-context)))))
865 (ert-deftest test-org
/timestamp-format
()
866 "Test `org-timestamp-format' specifications."
871 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
872 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
877 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
878 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
880 (ert-deftest test-org
/timestamp-split-range
()
881 "Test `org-timestamp-split-range' specifications."
882 ;; Extract range start (active).
885 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
886 (let ((ts (org-timestamp-split-range (org-element-context))))
887 (mapcar (lambda (p) (org-element-property p ts
))
888 '(:year-end
:month-end
:day-end
))))))
889 ;; Extract range start (inactive)
892 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
893 (let ((ts (org-timestamp-split-range (org-element-context))))
894 (mapcar (lambda (p) (org-element-property p ts
))
895 '(:year-end
:month-end
:day-end
))))))
896 ;; Extract range end (active).
899 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
900 (let ((ts (org-timestamp-split-range
901 (org-element-context) t
)))
902 (mapcar (lambda (p) (org-element-property p ts
))
903 '(:year-end
:month-end
:day-end
))))))
904 ;; Extract range end (inactive)
907 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
908 (let ((ts (org-timestamp-split-range
909 (org-element-context) t
)))
910 (mapcar (lambda (p) (org-element-property p ts
))
911 '(:year-end
:month-end
:day-end
))))))
912 ;; Return the timestamp if not a range.
914 (org-test-with-temp-text "[2012-03-29 Thu]"
915 (let* ((ts-orig (org-element-context))
916 (ts-copy (org-timestamp-split-range ts-orig
)))
917 (eq ts-orig ts-copy
))))
919 (org-test-with-temp-text "<%%(org-float t 4 2)>"
920 (let* ((ts-orig (org-element-context))
921 (ts-copy (org-timestamp-split-range ts-orig
)))
922 (eq ts-orig ts-copy
))))
923 ;; Check that parent is the same when a range was split.
925 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
926 (let* ((ts-orig (org-element-context))
927 (ts-copy (org-timestamp-split-range ts-orig
)))
928 (eq (org-element-property :parent ts-orig
)
929 (org-element-property :parent ts-copy
))))))
931 (ert-deftest test-org
/timestamp-translate
()
932 "Test `org-timestamp-translate' specifications."
933 ;; Translate whole date range.
936 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
937 (let ((org-display-custom-times t
)
938 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
939 (org-timestamp-translate (org-element-context))))))
940 ;; Translate date range start.
943 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
944 (let ((org-display-custom-times t
)
945 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
946 (org-timestamp-translate (org-element-context) 'start
)))))
947 ;; Translate date range end.
950 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
951 (let ((org-display-custom-times t
)
952 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
953 (org-timestamp-translate (org-element-context) 'end
)))))
954 ;; Translate time range.
957 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
958 (let ((org-display-custom-times t
)
959 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
960 (org-timestamp-translate (org-element-context))))))
961 ;; Translate non-range timestamp.
964 (org-test-with-temp-text "<2012-03-29 Thu>"
965 (let ((org-display-custom-times t
)
966 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
967 (org-timestamp-translate (org-element-context))))))
968 ;; Do not change `diary' timestamps.
970 (equal "<%%(org-float t 4 2)>"
971 (org-test-with-temp-text "<%%(org-float t 4 2)>"
972 (let ((org-display-custom-times t
)
973 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
974 (org-timestamp-translate (org-element-context)))))))
978 ;;; Targets and Radio Targets
980 (ert-deftest test-org
/all-targets
()
981 "Test `org-all-targets' specifications."
982 ;; Without an argument.
984 (equal '("radio-target" "target")
985 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
988 (equal '("radio-target")
989 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
992 (equal '("radio-target")
993 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
994 (org-all-targets t
)))))
999 ;;; test-org.el ends here