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
/accumulated-properties-in-drawers
()
404 "Ensure properties accumulate in subtree drawers."
405 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
406 (org-babel-next-src-block)
407 (should (equal '(2 1) (org-babel-execute-src-block)))))
413 (ert-deftest test-org
/mark-subtree
()
414 "Test `org-mark-subtree' specifications."
415 ;; Error when point is before first headline.
417 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
418 (progn (transient-mark-mode 1)
419 (org-mark-subtree))))
420 ;; Without argument, mark current subtree.
424 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
425 (progn (transient-mark-mode 1)
428 (list (region-beginning) (region-end))))))
429 ;; With an argument, move ARG up.
433 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
434 (progn (transient-mark-mode 1)
437 (list (region-beginning) (region-end))))))
438 ;; Do not get fooled by inlinetasks.
439 (when (featurep 'org-inlinetask
)
442 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
443 (progn (transient-mark-mode 1)
445 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
446 (region-beginning)))))))
452 (ert-deftest test-org
/beginning-of-line
()
453 "Test `org-beginning-of-line' specifications."
456 (org-test-with-temp-text "Some text\nSome other text"
457 (progn (org-beginning-of-line) (bolp))))
458 ;; Standard test with `visual-line-mode'.
460 (org-test-with-temp-text "A long line of text\nSome other text"
461 (progn (visual-line-mode)
463 (dotimes (i 1000) (insert "very "))
464 (org-beginning-of-line)
466 ;; At an headline with special movement.
468 (org-test-with-temp-text "* TODO Headline"
469 (let ((org-special-ctrl-a/e t
))
471 (and (progn (org-beginning-of-line) (looking-at "Headline"))
472 (progn (org-beginning-of-line) (bolp))
473 (progn (org-beginning-of-line) (looking-at "Headline")))))))
475 (ert-deftest test-org
/end-of-line
()
476 "Test `org-end-of-line' specifications."
479 (org-test-with-temp-text "Some text\nSome other text"
480 (progn (org-end-of-line) (eolp))))
481 ;; Standard test with `visual-line-mode'.
483 (org-test-with-temp-text "A long line of text\nSome other text"
484 (progn (visual-line-mode)
486 (dotimes (i 1000) (insert "very "))
487 (goto-char (point-min))
490 ;; At an headline with special movement.
492 (org-test-with-temp-text "* Headline1 :tag:\n"
493 (let ((org-special-ctrl-a/e t
))
494 (and (progn (org-end-of-line) (looking-at " :tag:"))
495 (progn (org-end-of-line) (eolp))
496 (progn (org-end-of-line) (looking-at " :tag:"))))))
497 ;; At an headline without special movement.
499 (org-test-with-temp-text "* Headline2 :tag:\n"
500 (let ((org-special-ctrl-a/e nil
))
501 (and (progn (org-end-of-line) (eolp))
502 (progn (org-end-of-line) (eolp))))))
503 ;; At an headline, with reversed movement.
505 (org-test-with-temp-text "* Headline3 :tag:\n"
506 (let ((org-special-ctrl-a/e
'reversed
)
507 (this-command last-command
))
508 (and (progn (org-end-of-line) (eolp))
509 (progn (org-end-of-line) (looking-at " :tag:"))))))
510 ;; At a block without hidden contents.
512 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
513 (progn (org-end-of-line) (eolp))))
514 ;; At a block with hidden contents.
516 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
517 (let ((org-special-ctrl-a/e t
))
518 (org-hide-block-toggle)
522 (ert-deftest test-org
/forward-element
()
523 "Test `org-forward-element' specifications."
524 ;; 1. At EOB: should error.
525 (org-test-with-temp-text "Some text\n"
526 (goto-char (point-max))
527 (should-error (org-forward-element)))
528 ;; 2. Standard move: expected to ignore blank lines.
529 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
530 (org-forward-element)
531 (should (looking-at (regexp-quote "Second paragraph."))))
532 ;; 3. Headline tests.
533 (org-test-with-temp-text "
538 ;; 3.1. At an headline beginning: move to next headline at the
541 (org-forward-element)
542 (should (looking-at (regexp-quote "** Head 1.2")))
543 ;; 3.2. At an headline beginning: move to parent headline if no
544 ;; headline at the same level.
546 (org-forward-element)
547 (should (looking-at (regexp-quote "** Head 1.2"))))
548 ;; 4. Greater element tests.
549 (org-test-with-temp-text
550 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
551 ;; 4.1. At a greater element: expected to skip contents.
552 (org-forward-element)
553 (should (looking-at (regexp-quote "Outside.")))
554 ;; 4.2. At the end of greater element contents: expected to skip
555 ;; to the end of the greater element.
557 (org-forward-element)
558 (should (looking-at (regexp-quote "Outside."))))
560 (org-test-with-temp-text "
574 ;; 5.1. At list top point: expected to move to the element after
577 (org-forward-element)
578 (should (looking-at (regexp-quote "Outside.")))
579 ;; 5.2. Special case: at the first line of a sub-list, but not at
580 ;; beginning of line, move to next item.
583 (org-forward-element)
584 (should (looking-at "- item2"))
587 (org-forward-element)
588 (should (looking-at " - sub2"))
589 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
591 (org-forward-element)
592 (should (looking-at (regexp-quote " Inner paragraph.")))
593 ;; 5.4. At sub-list end: expected to move outside the sub-list.
595 (org-forward-element)
596 (should (looking-at (regexp-quote " Inner paragraph.")))
597 ;; 5.5. At an item: expected to move to next item, if any.
599 (org-forward-element)
600 (should (looking-at " - sub3"))))
602 (ert-deftest test-org
/backward-element
()
603 "Test `org-backward-element' specifications."
604 ;; 1. Should error at BOB.
605 (org-test-with-temp-text " \nParagraph."
606 (should-error (org-backward-element)))
607 ;; 2. Should move at BOB when called on the first element in buffer.
609 (org-test-with-temp-text "\n#+TITLE: test"
610 (progn (forward-line)
611 (org-backward-element)
613 ;; 3. Not at the beginning of an element: move at its beginning.
614 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
617 (org-backward-element)
618 (should (looking-at (regexp-quote "Paragraph2."))))
619 ;; 4. Headline tests.
620 (org-test-with-temp-text "
625 ;; 4.1. At an headline beginning: move to previous headline at the
628 (org-backward-element)
629 (should (looking-at (regexp-quote "** Head 1.1")))
630 ;; 4.2. At an headline beginning: move to parent headline if no
631 ;; headline at the same level.
633 (org-backward-element)
634 (should (looking-at (regexp-quote "* Head 1")))
635 ;; 4.3. At the first top-level headline: should error.
637 (should-error (org-backward-element)))
638 ;; 5. At beginning of first element inside a greater element:
639 ;; expected to move to greater element's beginning.
640 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
642 (org-backward-element)
643 (should (looking-at "#\\+BEGIN_CENTER")))
644 ;; 6. At the beginning of the first element in a section: should
645 ;; move back to headline, if any.
647 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
648 (progn (goto-char (point-max))
650 (org-backward-element)
651 (org-at-heading-p))))
653 (org-test-with-temp-text "
668 ;; 7.1. At beginning of sub-list: expected to move to the
669 ;; paragraph before it.
671 (org-backward-element)
672 (should (looking-at "item1"))
673 ;; 7.2. At an item in a list: expected to move at previous item.
675 (org-backward-element)
676 (should (looking-at " - sub2"))
678 (org-backward-element)
679 (should (looking-at "- item1"))
680 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
683 (org-backward-element)
684 (should (looking-at " - sub1"))
686 (org-backward-element)
687 (should (looking-at "- item1"))
688 ;; 7.4. At blank-lines before list end: expected to move to top
691 (org-backward-element)
692 (should (looking-at "- item1"))))
694 (ert-deftest test-org
/up-element
()
695 "Test `org-up-element' specifications."
696 ;; 1. At BOB or with no surrounding element: should error.
697 (org-test-with-temp-text "Paragraph."
698 (should-error (org-up-element)))
699 (org-test-with-temp-text "* Head1\n* Head2"
701 (should-error (org-up-element)))
702 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
704 (should-error (org-up-element)))
705 ;; 2. At an headline: move to parent headline.
706 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
709 (should (looking-at "\\* Head1")))
710 ;; 3. Inside a greater element: move to greater element beginning.
711 (org-test-with-temp-text
712 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
715 (should (looking-at "#\\+BEGIN_CENTER")))
717 (org-test-with-temp-text "* Top
724 Paragraph within sub2.
727 ;; 4.1. Within an item: move to the item beginning.
730 (should (looking-at " - sub2"))
731 ;; 4.2. At an item in a sub-list: move to parent item.
734 (should (looking-at "- item1"))
735 ;; 4.3. At an item in top list: move to beginning of whole list.
738 (should (looking-at "- item1"))
739 ;; 4.4. Special case. At very top point: should move to parent of
743 (should (looking-at "\\* Top"))))
745 (ert-deftest test-org
/down-element
()
746 "Test `org-down-element' specifications."
747 ;; Error when the element hasn't got a recursive type.
748 (org-test-with-temp-text "Paragraph."
749 (should-error (org-down-element)))
750 ;; Error when the element has no contents
751 (org-test-with-temp-text "* Headline"
752 (should-error (org-down-element)))
753 ;; When at a plain-list, move to first item.
754 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
757 (should (looking-at " - Item 1.1")))
758 (org-test-with-temp-text "#+NAME: list\n- Item 1"
760 (should (looking-at " Item 1")))
761 ;; When at a table, move to first row
762 (org-test-with-temp-text "#+NAME: table\n| a | b |"
764 (should (looking-at " a | b |")))
765 ;; Otherwise, move inside the greater element.
766 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
768 (should (looking-at "Paragraph"))))
770 (ert-deftest test-org
/drag-element-backward
()
771 "Test `org-drag-element-backward' specifications."
772 ;; 1. Error when trying to move first element of buffer.
773 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
774 (should-error (org-drag-element-backward)))
775 ;; 2. Error when trying to swap nested elements.
776 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
778 (should-error (org-drag-element-backward)))
779 ;; 3. Error when trying to swap an headline element and
780 ;; a non-headline element.
781 (org-test-with-temp-text "Test.\n* Head 1"
783 (should-error (org-drag-element-backward)))
784 ;; 4. Otherwise, swap elements, preserving column and blank lines
786 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
787 (search-forward "graph")
788 (org-drag-element-backward)
789 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
790 (should (looking-at " 2")))
791 ;; 5. Preserve visibility of elements and their contents.
792 (org-test-with-temp-text "
800 (while (search-forward "BEGIN_" nil t
) (org-cycle))
801 (search-backward "- item 1")
802 (org-drag-element-backward)
805 '((63 .
82) (26 .
48))
806 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
807 (overlays-in (point-min) (point-max)))))))
809 (ert-deftest test-org
/drag-element-forward
()
810 "Test `org-drag-element-forward' specifications."
811 ;; 1. Error when trying to move first element of buffer.
812 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
814 (should-error (org-drag-element-forward)))
815 ;; 2. Error when trying to swap nested elements.
816 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
818 (should-error (org-drag-element-forward)))
819 ;; 3. Error when trying to swap a non-headline element and an
821 (org-test-with-temp-text "Test.\n* Head 1"
822 (should-error (org-drag-element-forward)))
823 ;; 4. Otherwise, swap elements, preserving column and blank lines
825 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
826 (search-forward "graph")
827 (org-drag-element-forward)
828 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
829 (should (looking-at " 1")))
830 ;; 5. Preserve visibility of elements and their contents.
831 (org-test-with-temp-text "
839 (while (search-forward "BEGIN_" nil t
) (org-cycle))
840 (search-backward "#+BEGIN_CENTER")
841 (org-drag-element-forward)
844 '((63 .
82) (26 .
48))
845 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
846 (overlays-in (point-min) (point-max)))))))
852 (ert-deftest test-org
/timestamp-has-time-p
()
853 "Test `org-timestamp-has-time-p' specifications."
856 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
857 (org-timestamp-has-time-p (org-element-context))))
860 (org-test-with-temp-text "<2012-03-29 Thu>"
861 (org-timestamp-has-time-p (org-element-context)))))
863 (ert-deftest test-org
/timestamp-format
()
864 "Test `org-timestamp-format' specifications."
869 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
870 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
875 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
876 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
878 (ert-deftest test-org
/timestamp-split-range
()
879 "Test `org-timestamp-split-range' specifications."
880 ;; Extract range start (active).
883 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
884 (let ((ts (org-timestamp-split-range (org-element-context))))
885 (mapcar (lambda (p) (org-element-property p ts
))
886 '(:year-end
:month-end
:day-end
))))))
887 ;; Extract range start (inactive)
890 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
891 (let ((ts (org-timestamp-split-range (org-element-context))))
892 (mapcar (lambda (p) (org-element-property p ts
))
893 '(:year-end
:month-end
:day-end
))))))
894 ;; Extract range end (active).
897 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
898 (let ((ts (org-timestamp-split-range
899 (org-element-context) t
)))
900 (mapcar (lambda (p) (org-element-property p ts
))
901 '(:year-end
:month-end
:day-end
))))))
902 ;; Extract range end (inactive)
905 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
906 (let ((ts (org-timestamp-split-range
907 (org-element-context) t
)))
908 (mapcar (lambda (p) (org-element-property p ts
))
909 '(:year-end
:month-end
:day-end
))))))
910 ;; Return the timestamp if not a range.
912 (org-test-with-temp-text "[2012-03-29 Thu]"
913 (let* ((ts-orig (org-element-context))
914 (ts-copy (org-timestamp-split-range ts-orig
)))
915 (eq ts-orig ts-copy
))))
917 (org-test-with-temp-text "<%%(org-float t 4 2)>"
918 (let* ((ts-orig (org-element-context))
919 (ts-copy (org-timestamp-split-range ts-orig
)))
920 (eq ts-orig ts-copy
))))
921 ;; Check that parent is the same when a range was split.
923 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
924 (let* ((ts-orig (org-element-context))
925 (ts-copy (org-timestamp-split-range ts-orig
)))
926 (eq (org-element-property :parent ts-orig
)
927 (org-element-property :parent ts-copy
))))))
929 (ert-deftest test-org
/timestamp-translate
()
930 "Test `org-timestamp-translate' specifications."
931 ;; Translate whole date range.
934 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
935 (let ((org-display-custom-times t
)
936 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
937 (org-timestamp-translate (org-element-context))))))
938 ;; Translate date range start.
941 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
942 (let ((org-display-custom-times t
)
943 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
944 (org-timestamp-translate (org-element-context) 'start
)))))
945 ;; Translate date range end.
948 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
949 (let ((org-display-custom-times t
)
950 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
951 (org-timestamp-translate (org-element-context) 'end
)))))
952 ;; Translate time range.
955 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
956 (let ((org-display-custom-times t
)
957 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
958 (org-timestamp-translate (org-element-context))))))
959 ;; Translate non-range timestamp.
962 (org-test-with-temp-text "<2012-03-29 Thu>"
963 (let ((org-display-custom-times t
)
964 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
965 (org-timestamp-translate (org-element-context))))))
966 ;; Do not change `diary' timestamps.
968 (equal "<%%(org-float t 4 2)>"
969 (org-test-with-temp-text "<%%(org-float t 4 2)>"
970 (let ((org-display-custom-times t
)
971 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
972 (org-timestamp-translate (org-element-context)))))))
976 ;;; Targets and Radio Targets
978 (ert-deftest test-org
/all-targets
()
979 "Test `org-all-targets' specifications."
980 ;; Without an argument.
982 (equal '("radio-target" "target")
983 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
986 (equal '("radio-target")
987 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
990 (equal '("radio-target")
991 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
992 (org-all-targets t
)))))
997 ;;; test-org.el ends here