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.
129 (org-test-with-temp-text "|a|"
133 (equal "#+name: table\n| a |\n"
134 (org-test-with-temp-text "#+name: table\n| a |"
137 ;; At a paragraph, preserve line breaks.
138 (org-test-with-temp-text "some \\\\\nlong\ntext"
139 (let ((fill-column 20))
141 (should (equal (buffer-string) "some \\\\\nlong text"))))
142 ;; Correctly fill a paragraph when point is at its very end.
145 (org-test-with-temp-text "A\nB"
146 (let ((fill-column 20))
147 (goto-char (point-max))
150 ;; Correctly fill the last paragraph of a greater element.
152 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
153 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
154 (let ((fill-column 8))
159 ;; Correctly fill an element in a narrowed buffer.
162 (org-test-with-temp-text "01234 6789"
163 (let ((fill-column 5))
164 (narrow-to-region 1 8)
167 ;; Special case: Fill first paragraph when point is at an item or
168 ;; a plain-list or a footnote reference.
171 (org-test-with-temp-text "- A\n B"
172 (let ((fill-column 20))
177 (org-test-with-temp-text "[fn:1] A\nB"
178 (let ((fill-column 20))
181 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
182 (let ((fill-column 20))
184 (should (equal (buffer-string)
185 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
186 ;; Fill contents of `comment-block' elements.
189 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
190 (let ((fill-column 20))
194 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
195 ;; Fill `comment' elements.
198 (org-test-with-temp-text " # A\n # B"
199 (let ((fill-column 20))
202 ;; Do not mix consecutive comments when filling one of them.
204 (equal "# A B\n\n# C"
205 (org-test-with-temp-text "# A\n# B\n\n# C"
206 (let ((fill-column 20))
209 ;; Do nothing at affiliated keywords.
210 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
211 (let ((fill-column 20))
213 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
214 ;; Do not move point after table when filling a table.
216 (org-test-with-temp-text "| a | b |\n| c | d |\n"
221 (ert-deftest test-org
/auto-fill-function
()
222 "Test auto-filling features."
223 ;; Auto fill paragraph.
226 (org-test-with-temp-text "12345 7890"
227 (let ((fill-column 5))
229 (org-auto-fill-function)
231 ;; Auto fill first paragraph in an item.
233 (equal "- 12345\n 7890"
234 (org-test-with-temp-text "- 12345 7890"
235 (let ((fill-column 7))
237 (org-auto-fill-function)
239 ;; Auto fill comments.
241 (equal " # 12345\n # 7890"
242 (org-test-with-temp-text " # 12345 7890"
243 (let ((fill-column 10))
245 (org-auto-fill-function)
247 ;; A hash within a line isn't a comment.
249 (equal "12345 # 7890\n# 1"
250 (org-test-with-temp-text "12345 # 7890 1"
251 (let ((fill-column 12))
253 (org-auto-fill-function)
255 ;; Correctly interpret empty prefix.
257 (equal "# a\n# b\nRegular\n# paragraph"
258 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
259 (let ((fill-column 12))
261 (org-auto-fill-function)
263 ;; Comment block: auto fill contents.
265 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
266 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
267 (let ((fill-column 5))
270 (org-auto-fill-function)
273 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
274 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
275 (let ((fill-column 5))
278 (org-auto-fill-function)
280 ;; Do not fill if a new item could be created.
283 (org-test-with-temp-text "12345 - 90"
284 (let ((fill-column 5))
286 (org-auto-fill-function)
288 ;; Do not fill if a line break could be introduced.
290 (equal "123\\\\\n7890"
291 (org-test-with-temp-text "123\\\\ 7890"
292 (let ((fill-column 6))
294 (org-auto-fill-function)
296 ;; Do not fill affiliated keywords.
298 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
299 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
300 (let ((fill-column 20))
302 (org-auto-fill-function)
311 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
312 ;; a named element (#+name: text) and to headlines (* Text).
314 (ert-deftest test-org
/fuzzy-links
()
315 "Test fuzzy links specifications."
316 ;; 1. Fuzzy link goes in priority to a matching target.
318 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
321 (looking-at "<<Test>>")))
322 ;; 2. Then fuzzy link points to an element with a given name.
324 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
327 (looking-at "#\\+NAME: Test")))
328 ;; 3. A target still lead to a matching headline otherwise.
330 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
333 (looking-at "\\* Head2")))
334 ;; 4. With a leading star in link, enforce heading match.
336 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
339 (looking-at "\\* Test"))))
344 (ert-deftest test-org
/org-link-escape-ascii-character
()
345 "Escape an ascii character."
349 (org-link-escape "["))))
351 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
352 "Escape an ascii control character."
356 (org-link-escape "\t"))))
358 (ert-deftest test-org
/org-link-escape-multibyte-character
()
359 "Escape an unicode multibyte character."
363 (org-link-escape "€"))))
365 (ert-deftest test-org
/org-link-escape-custom-table
()
366 "Escape string with custom character table."
370 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
372 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
373 "Escape string with custom table merged with default table."
376 "%5BF%6F%6F%3A%42ar%0A%5D"
377 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
379 (ert-deftest test-org
/org-link-unescape-ascii-character
()
380 "Unescape an ascii character."
384 (org-link-unescape "%5B"))))
386 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
387 "Unescpae an ascii control character."
391 (org-link-unescape "%0A"))))
393 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
394 "Unescape unicode multibyte character."
398 (org-link-unescape "%E2%82%AC"))))
400 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
401 "Unescape old style percent escaped character."
404 "à âçèéêîôùû"
405 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
407 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
408 "Escape and unscape a URL that includes an escaped char.
409 http://article.gmane.org/gmane.emacs.orgmode/21459/"
412 "http://some.host.com/form?&id=blah%2Bblah25"
413 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
419 (ert-deftest test-org
/accumulated-properties-in-drawers
()
420 "Ensure properties accumulate in subtree drawers."
421 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
422 (org-babel-next-src-block)
423 (should (equal '(2 1) (org-babel-execute-src-block)))))
429 (ert-deftest test-org
/mark-subtree
()
430 "Test `org-mark-subtree' specifications."
431 ;; Error when point is before first headline.
433 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
434 (progn (transient-mark-mode 1)
435 (org-mark-subtree))))
436 ;; Without argument, mark current subtree.
440 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
441 (progn (transient-mark-mode 1)
444 (list (region-beginning) (region-end))))))
445 ;; With an argument, move ARG up.
449 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
450 (progn (transient-mark-mode 1)
453 (list (region-beginning) (region-end))))))
454 ;; Do not get fooled by inlinetasks.
455 (when (featurep 'org-inlinetask
)
458 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
459 (progn (transient-mark-mode 1)
461 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
462 (region-beginning)))))))
468 (ert-deftest test-org
/beginning-of-line
()
469 "Test `org-beginning-of-line' specifications."
472 (org-test-with-temp-text "Some text\nSome other text"
473 (progn (org-beginning-of-line) (bolp))))
474 ;; Standard test with `visual-line-mode'.
476 (org-test-with-temp-text "A long line of text\nSome other text"
477 (progn (visual-line-mode)
479 (dotimes (i 1000) (insert "very "))
480 (org-beginning-of-line)
482 ;; At an headline with special movement.
484 (org-test-with-temp-text "* TODO Headline"
485 (let ((org-special-ctrl-a/e t
))
487 (and (progn (org-beginning-of-line) (looking-at "Headline"))
488 (progn (org-beginning-of-line) (bolp))
489 (progn (org-beginning-of-line) (looking-at "Headline")))))))
491 (ert-deftest test-org
/end-of-line
()
492 "Test `org-end-of-line' specifications."
495 (org-test-with-temp-text "Some text\nSome other text"
496 (progn (org-end-of-line) (eolp))))
497 ;; Standard test with `visual-line-mode'.
499 (org-test-with-temp-text "A long line of text\nSome other text"
500 (progn (visual-line-mode)
502 (dotimes (i 1000) (insert "very "))
503 (goto-char (point-min))
506 ;; At an headline with special movement.
508 (org-test-with-temp-text "* Headline1 :tag:\n"
509 (let ((org-special-ctrl-a/e t
))
510 (and (progn (org-end-of-line) (looking-at " :tag:"))
511 (progn (org-end-of-line) (eolp))
512 (progn (org-end-of-line) (looking-at " :tag:"))))))
513 ;; At an headline without special movement.
515 (org-test-with-temp-text "* Headline2 :tag:\n"
516 (let ((org-special-ctrl-a/e nil
))
517 (and (progn (org-end-of-line) (eolp))
518 (progn (org-end-of-line) (eolp))))))
519 ;; At an headline, with reversed movement.
521 (org-test-with-temp-text "* Headline3 :tag:\n"
522 (let ((org-special-ctrl-a/e
'reversed
)
523 (this-command last-command
))
524 (and (progn (org-end-of-line) (eolp))
525 (progn (org-end-of-line) (looking-at " :tag:"))))))
526 ;; At a block without hidden contents.
528 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
529 (progn (org-end-of-line) (eolp))))
530 ;; At a block with hidden contents.
532 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
533 (let ((org-special-ctrl-a/e t
))
534 (org-hide-block-toggle)
538 (ert-deftest test-org
/forward-element
()
539 "Test `org-forward-element' specifications."
540 ;; 1. At EOB: should error.
541 (org-test-with-temp-text "Some text\n"
542 (goto-char (point-max))
543 (should-error (org-forward-element)))
544 ;; 2. Standard move: expected to ignore blank lines.
545 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
546 (org-forward-element)
547 (should (looking-at (regexp-quote "Second paragraph."))))
548 ;; 3. Headline tests.
549 (org-test-with-temp-text "
554 ;; 3.1. At an headline beginning: move to next headline at the
557 (org-forward-element)
558 (should (looking-at (regexp-quote "** Head 1.2")))
559 ;; 3.2. At an headline beginning: move to parent headline if no
560 ;; headline at the same level.
562 (org-forward-element)
563 (should (looking-at (regexp-quote "** Head 1.2"))))
564 ;; 4. Greater element tests.
565 (org-test-with-temp-text
566 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
567 ;; 4.1. At a greater element: expected to skip contents.
568 (org-forward-element)
569 (should (looking-at (regexp-quote "Outside.")))
570 ;; 4.2. At the end of greater element contents: expected to skip
571 ;; to the end of the greater element.
573 (org-forward-element)
574 (should (looking-at (regexp-quote "Outside."))))
576 (org-test-with-temp-text "
590 ;; 5.1. At list top point: expected to move to the element after
593 (org-forward-element)
594 (should (looking-at (regexp-quote "Outside.")))
595 ;; 5.2. Special case: at the first line of a sub-list, but not at
596 ;; beginning of line, move to next item.
599 (org-forward-element)
600 (should (looking-at "- item2"))
603 (org-forward-element)
604 (should (looking-at " - sub2"))
605 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
607 (org-forward-element)
608 (should (looking-at (regexp-quote " Inner paragraph.")))
609 ;; 5.4. At sub-list end: expected to move outside the sub-list.
611 (org-forward-element)
612 (should (looking-at (regexp-quote " Inner paragraph.")))
613 ;; 5.5. At an item: expected to move to next item, if any.
615 (org-forward-element)
616 (should (looking-at " - sub3"))))
618 (ert-deftest test-org
/backward-element
()
619 "Test `org-backward-element' specifications."
620 ;; 1. Should error at BOB.
621 (org-test-with-temp-text " \nParagraph."
622 (should-error (org-backward-element)))
623 ;; 2. Should move at BOB when called on the first element in buffer.
625 (org-test-with-temp-text "\n#+TITLE: test"
626 (progn (forward-line)
627 (org-backward-element)
629 ;; 3. Not at the beginning of an element: move at its beginning.
630 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
633 (org-backward-element)
634 (should (looking-at (regexp-quote "Paragraph2."))))
635 ;; 4. Headline tests.
636 (org-test-with-temp-text "
641 ;; 4.1. At an headline beginning: move to previous headline at the
644 (org-backward-element)
645 (should (looking-at (regexp-quote "** Head 1.1")))
646 ;; 4.2. At an headline beginning: move to parent headline if no
647 ;; headline at the same level.
649 (org-backward-element)
650 (should (looking-at (regexp-quote "* Head 1")))
651 ;; 4.3. At the first top-level headline: should error.
653 (should-error (org-backward-element)))
654 ;; 5. At beginning of first element inside a greater element:
655 ;; expected to move to greater element's beginning.
656 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
658 (org-backward-element)
659 (should (looking-at "#\\+BEGIN_CENTER")))
660 ;; 6. At the beginning of the first element in a section: should
661 ;; move back to headline, if any.
663 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
664 (progn (goto-char (point-max))
666 (org-backward-element)
667 (org-at-heading-p))))
669 (org-test-with-temp-text "
684 ;; 7.1. At beginning of sub-list: expected to move to the
685 ;; paragraph before it.
687 (org-backward-element)
688 (should (looking-at "item1"))
689 ;; 7.2. At an item in a list: expected to move at previous item.
691 (org-backward-element)
692 (should (looking-at " - sub2"))
694 (org-backward-element)
695 (should (looking-at "- item1"))
696 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
699 (org-backward-element)
700 (should (looking-at " - sub1"))
702 (org-backward-element)
703 (should (looking-at "- item1"))
704 ;; 7.4. At blank-lines before list end: expected to move to top
707 (org-backward-element)
708 (should (looking-at "- item1"))))
710 (ert-deftest test-org
/up-element
()
711 "Test `org-up-element' specifications."
712 ;; 1. At BOB or with no surrounding element: should error.
713 (org-test-with-temp-text "Paragraph."
714 (should-error (org-up-element)))
715 (org-test-with-temp-text "* Head1\n* Head2"
717 (should-error (org-up-element)))
718 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
720 (should-error (org-up-element)))
721 ;; 2. At an headline: move to parent headline.
722 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
725 (should (looking-at "\\* Head1")))
726 ;; 3. Inside a greater element: move to greater element beginning.
727 (org-test-with-temp-text
728 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
731 (should (looking-at "#\\+BEGIN_CENTER")))
733 (org-test-with-temp-text "* Top
740 Paragraph within sub2.
743 ;; 4.1. Within an item: move to the item beginning.
746 (should (looking-at " - sub2"))
747 ;; 4.2. At an item in a sub-list: move to parent item.
750 (should (looking-at "- item1"))
751 ;; 4.3. At an item in top list: move to beginning of whole list.
754 (should (looking-at "- item1"))
755 ;; 4.4. Special case. At very top point: should move to parent of
759 (should (looking-at "\\* Top"))))
761 (ert-deftest test-org
/down-element
()
762 "Test `org-down-element' specifications."
763 ;; Error when the element hasn't got a recursive type.
764 (org-test-with-temp-text "Paragraph."
765 (should-error (org-down-element)))
766 ;; Error when the element has no contents
767 (org-test-with-temp-text "* Headline"
768 (should-error (org-down-element)))
769 ;; When at a plain-list, move to first item.
770 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
773 (should (looking-at " - Item 1.1")))
774 (org-test-with-temp-text "#+NAME: list\n- Item 1"
776 (should (looking-at " Item 1")))
777 ;; When at a table, move to first row
778 (org-test-with-temp-text "#+NAME: table\n| a | b |"
780 (should (looking-at " a | b |")))
781 ;; Otherwise, move inside the greater element.
782 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
784 (should (looking-at "Paragraph"))))
786 (ert-deftest test-org
/drag-element-backward
()
787 "Test `org-drag-element-backward' specifications."
788 ;; 1. Error when trying to move first element of buffer.
789 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
790 (should-error (org-drag-element-backward)))
791 ;; 2. Error when trying to swap nested elements.
792 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
794 (should-error (org-drag-element-backward)))
795 ;; 3. Error when trying to swap an headline element and
796 ;; a non-headline element.
797 (org-test-with-temp-text "Test.\n* Head 1"
799 (should-error (org-drag-element-backward)))
800 ;; 4. Otherwise, swap elements, preserving column and blank lines
802 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
803 (search-forward "graph")
804 (org-drag-element-backward)
805 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
806 (should (looking-at " 2")))
807 ;; 5. Preserve visibility of elements and their contents.
808 (org-test-with-temp-text "
816 (while (search-forward "BEGIN_" nil t
) (org-cycle))
817 (search-backward "- item 1")
818 (org-drag-element-backward)
821 '((63 .
82) (26 .
48))
822 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
823 (overlays-in (point-min) (point-max)))))))
825 (ert-deftest test-org
/drag-element-forward
()
826 "Test `org-drag-element-forward' specifications."
827 ;; 1. Error when trying to move first element of buffer.
828 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
830 (should-error (org-drag-element-forward)))
831 ;; 2. Error when trying to swap nested elements.
832 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
834 (should-error (org-drag-element-forward)))
835 ;; 3. Error when trying to swap a non-headline element and an
837 (org-test-with-temp-text "Test.\n* Head 1"
838 (should-error (org-drag-element-forward)))
839 ;; 4. Otherwise, swap elements, preserving column and blank lines
841 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
842 (search-forward "graph")
843 (org-drag-element-forward)
844 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
845 (should (looking-at " 1")))
846 ;; 5. Preserve visibility of elements and their contents.
847 (org-test-with-temp-text "
855 (while (search-forward "BEGIN_" nil t
) (org-cycle))
856 (search-backward "#+BEGIN_CENTER")
857 (org-drag-element-forward)
860 '((63 .
82) (26 .
48))
861 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
862 (overlays-in (point-min) (point-max)))))))
868 (ert-deftest test-org
/timestamp-has-time-p
()
869 "Test `org-timestamp-has-time-p' specifications."
872 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
873 (org-timestamp-has-time-p (org-element-context))))
876 (org-test-with-temp-text "<2012-03-29 Thu>"
877 (org-timestamp-has-time-p (org-element-context)))))
879 (ert-deftest test-org
/timestamp-format
()
880 "Test `org-timestamp-format' specifications."
885 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
886 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
891 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
892 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
894 (ert-deftest test-org
/timestamp-split-range
()
895 "Test `org-timestamp-split-range' specifications."
896 ;; Extract range start (active).
899 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
900 (let ((ts (org-timestamp-split-range (org-element-context))))
901 (mapcar (lambda (p) (org-element-property p ts
))
902 '(:year-end
:month-end
:day-end
))))))
903 ;; Extract range start (inactive)
906 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
907 (let ((ts (org-timestamp-split-range (org-element-context))))
908 (mapcar (lambda (p) (org-element-property p ts
))
909 '(:year-end
:month-end
:day-end
))))))
910 ;; Extract range end (active).
913 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
914 (let ((ts (org-timestamp-split-range
915 (org-element-context) t
)))
916 (mapcar (lambda (p) (org-element-property p ts
))
917 '(:year-end
:month-end
:day-end
))))))
918 ;; Extract range end (inactive)
921 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
922 (let ((ts (org-timestamp-split-range
923 (org-element-context) t
)))
924 (mapcar (lambda (p) (org-element-property p ts
))
925 '(:year-end
:month-end
:day-end
))))))
926 ;; Return the timestamp if not a range.
928 (org-test-with-temp-text "[2012-03-29 Thu]"
929 (let* ((ts-orig (org-element-context))
930 (ts-copy (org-timestamp-split-range ts-orig
)))
931 (eq ts-orig ts-copy
))))
933 (org-test-with-temp-text "<%%(org-float t 4 2)>"
934 (let* ((ts-orig (org-element-context))
935 (ts-copy (org-timestamp-split-range ts-orig
)))
936 (eq ts-orig ts-copy
))))
937 ;; Check that parent is the same when a range was split.
939 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
940 (let* ((ts-orig (org-element-context))
941 (ts-copy (org-timestamp-split-range ts-orig
)))
942 (eq (org-element-property :parent ts-orig
)
943 (org-element-property :parent ts-copy
))))))
945 (ert-deftest test-org
/timestamp-translate
()
946 "Test `org-timestamp-translate' specifications."
947 ;; Translate whole date range.
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))))))
954 ;; Translate date range start.
957 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
958 (let ((org-display-custom-times t
)
959 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
960 (org-timestamp-translate (org-element-context) 'start
)))))
961 ;; Translate date range end.
964 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
965 (let ((org-display-custom-times t
)
966 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
967 (org-timestamp-translate (org-element-context) 'end
)))))
968 ;; Translate time range.
971 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
972 (let ((org-display-custom-times t
)
973 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
974 (org-timestamp-translate (org-element-context))))))
975 ;; Translate non-range timestamp.
978 (org-test-with-temp-text "<2012-03-29 Thu>"
979 (let ((org-display-custom-times t
)
980 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
981 (org-timestamp-translate (org-element-context))))))
982 ;; Do not change `diary' timestamps.
984 (equal "<%%(org-float t 4 2)>"
985 (org-test-with-temp-text "<%%(org-float t 4 2)>"
986 (let ((org-display-custom-times t
)
987 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
988 (org-timestamp-translate (org-element-context)))))))
992 ;;; Targets and Radio Targets
994 (ert-deftest test-org
/all-targets
()
995 "Test `org-all-targets' specifications."
996 ;; Without an argument.
998 (equal '("radio-target" "target")
999 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
1000 (org-all-targets))))
1002 (equal '("radio-target")
1003 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
1006 (equal '("radio-target")
1007 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
1008 (org-all-targets t
)))))
1013 ;;; test-org.el ends here