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 target keyword (aka an invisible target: #+TARGET: text), to
299 ;; a named element (#+name: text) and to headlines (* Text).
301 (ert-deftest test-org
/fuzzy-links
()
302 "Test fuzzy links specifications."
303 ;; 1. Fuzzy link goes in priority to a matching target.
304 (org-test-with-temp-text
305 "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
308 (should (looking-at "<<Test>>")))
309 ;; 2. Fuzzy link should then go to a matching target keyword.
310 (org-test-with-temp-text
311 "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
314 (should (looking-at "#\\+TARGET: Test")))
315 ;; 3. Then fuzzy link points to an element with a given name.
316 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
319 (should (looking-at "#\\+NAME: Test")))
320 ;; 4. A target still lead to a matching headline otherwise.
321 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
324 (should (looking-at "\\* Head2")))
325 ;; 5. With a leading star in link, enforce heading match.
326 (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
329 (should (looking-at "\\* Test"))))
334 (ert-deftest test-org
/org-link-escape-ascii-character
()
335 "Escape an ascii character."
339 (org-link-escape "["))))
341 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
342 "Escape an ascii control character."
346 (org-link-escape "\t"))))
348 (ert-deftest test-org
/org-link-escape-multibyte-character
()
349 "Escape an unicode multibyte character."
353 (org-link-escape "€"))))
355 (ert-deftest test-org
/org-link-escape-custom-table
()
356 "Escape string with custom character table."
360 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
362 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
363 "Escape string with custom table merged with default table."
366 "%5BF%6F%6F%3A%42ar%0A%5D"
367 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
369 (ert-deftest test-org
/org-link-unescape-ascii-character
()
370 "Unescape an ascii character."
374 (org-link-unescape "%5B"))))
376 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
377 "Unescpae an ascii control character."
381 (org-link-unescape "%0A"))))
383 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
384 "Unescape unicode multibyte character."
388 (org-link-unescape "%E2%82%AC"))))
390 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
391 "Unescape old style percent escaped character."
394 "à âçèéêîôùû"
395 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
397 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
398 "Escape and unscape a URL that includes an escaped char.
399 http://article.gmane.org/gmane.emacs.orgmode/21459/"
402 "http://some.host.com/form?&id=blah%2Bblah25"
403 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
409 (ert-deftest test-org
/accumulated-properties-in-drawers
()
410 "Ensure properties accumulate in subtree drawers."
411 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
412 (org-babel-next-src-block)
413 (should (equal '(2 1) (org-babel-execute-src-block)))))
419 (ert-deftest test-org
/mark-subtree
()
420 "Test `org-mark-subtree' specifications."
421 ;; Error when point is before first headline.
423 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
424 (progn (transient-mark-mode 1)
425 (org-mark-subtree))))
426 ;; Without argument, mark current subtree.
430 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
431 (progn (transient-mark-mode 1)
434 (list (region-beginning) (region-end))))))
435 ;; With an argument, move ARG up.
439 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
440 (progn (transient-mark-mode 1)
443 (list (region-beginning) (region-end))))))
444 ;; Do not get fooled by inlinetasks.
445 (when (featurep 'org-inlinetask
)
448 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
449 (progn (transient-mark-mode 1)
451 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
452 (region-beginning)))))))
458 (ert-deftest test-org
/beginning-of-line
()
459 "Test `org-beginning-of-line' specifications."
462 (org-test-with-temp-text "Some text\nSome other text"
463 (progn (org-beginning-of-line) (bolp))))
464 ;; Standard test with `visual-line-mode'.
466 (org-test-with-temp-text "A long line of text\nSome other text"
467 (progn (visual-line-mode)
469 (dotimes (i 1000) (insert "very "))
470 (org-beginning-of-line)
472 ;; At an headline with special movement.
474 (org-test-with-temp-text "* TODO Headline"
475 (let ((org-special-ctrl-a/e t
))
477 (and (progn (org-beginning-of-line) (looking-at "Headline"))
478 (progn (org-beginning-of-line) (bolp))
479 (progn (org-beginning-of-line) (looking-at "Headline")))))))
481 (ert-deftest test-org
/end-of-line
()
482 "Test `org-end-of-line' specifications."
485 (org-test-with-temp-text "Some text\nSome other text"
486 (progn (org-end-of-line) (eolp))))
487 ;; Standard test with `visual-line-mode'.
489 (org-test-with-temp-text "A long line of text\nSome other text"
490 (progn (visual-line-mode)
492 (dotimes (i 1000) (insert "very "))
493 (goto-char (point-min))
496 ;; At an headline with special movement.
498 (org-test-with-temp-text "* Headline1 :tag:\n"
499 (let ((org-special-ctrl-a/e t
))
500 (and (progn (org-end-of-line) (looking-at " :tag:"))
501 (progn (org-end-of-line) (eolp))
502 (progn (org-end-of-line) (looking-at " :tag:"))))))
503 ;; At an headline without special movement.
505 (org-test-with-temp-text "* Headline2 :tag:\n"
506 (let ((org-special-ctrl-a/e nil
))
507 (and (progn (org-end-of-line) (eolp))
508 (progn (org-end-of-line) (eolp))))))
509 ;; At an headline, with reversed movement.
511 (org-test-with-temp-text "* Headline3 :tag:\n"
512 (let ((org-special-ctrl-a/e
'reversed
)
513 (this-command last-command
))
514 (and (progn (org-end-of-line) (eolp))
515 (progn (org-end-of-line) (looking-at " :tag:"))))))
516 ;; At a block without hidden contents.
518 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
519 (progn (org-end-of-line) (eolp))))
520 ;; At a block with hidden contents.
522 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
523 (let ((org-special-ctrl-a/e t
))
524 (org-hide-block-toggle)
528 (ert-deftest test-org
/forward-element
()
529 "Test `org-forward-element' specifications."
530 ;; 1. At EOB: should error.
531 (org-test-with-temp-text "Some text\n"
532 (goto-char (point-max))
533 (should-error (org-forward-element)))
534 ;; 2. Standard move: expected to ignore blank lines.
535 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
536 (org-forward-element)
537 (should (looking-at (regexp-quote "Second paragraph."))))
538 ;; 3. Headline tests.
539 (org-test-with-temp-text "
544 ;; 3.1. At an headline beginning: move to next headline at the
547 (org-forward-element)
548 (should (looking-at (regexp-quote "** Head 1.2")))
549 ;; 3.2. At an headline beginning: move to parent headline if no
550 ;; headline at the same level.
552 (org-forward-element)
553 (should (looking-at (regexp-quote "** Head 1.2"))))
554 ;; 4. Greater element tests.
555 (org-test-with-temp-text
556 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
557 ;; 4.1. At a greater element: expected to skip contents.
558 (org-forward-element)
559 (should (looking-at (regexp-quote "Outside.")))
560 ;; 4.2. At the end of greater element contents: expected to skip
561 ;; to the end of the greater element.
563 (org-forward-element)
564 (should (looking-at (regexp-quote "Outside."))))
566 (org-test-with-temp-text "
580 ;; 5.1. At list top point: expected to move to the element after
583 (org-forward-element)
584 (should (looking-at (regexp-quote "Outside.")))
585 ;; 5.2. Special case: at the first line of a sub-list, but not at
586 ;; beginning of line, move to next item.
589 (org-forward-element)
590 (should (looking-at "- item2"))
593 (org-forward-element)
594 (should (looking-at " - sub2"))
595 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
597 (org-forward-element)
598 (should (looking-at (regexp-quote " Inner paragraph.")))
599 ;; 5.4. At sub-list end: expected to move outside the sub-list.
601 (org-forward-element)
602 (should (looking-at (regexp-quote " Inner paragraph.")))
603 ;; 5.5. At an item: expected to move to next item, if any.
605 (org-forward-element)
606 (should (looking-at " - sub3"))))
608 (ert-deftest test-org
/backward-element
()
609 "Test `org-backward-element' specifications."
610 ;; 1. Should error at BOB.
611 (org-test-with-temp-text " \nParagraph."
612 (should-error (org-backward-element)))
613 ;; 2. Should move at BOB when called on the first element in buffer.
615 (org-test-with-temp-text "\n#+TITLE: test"
616 (progn (forward-line)
617 (org-backward-element)
619 ;; 3. Not at the beginning of an element: move at its beginning.
620 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
623 (org-backward-element)
624 (should (looking-at (regexp-quote "Paragraph2."))))
625 ;; 4. Headline tests.
626 (org-test-with-temp-text "
631 ;; 4.1. At an headline beginning: move to previous headline at the
634 (org-backward-element)
635 (should (looking-at (regexp-quote "** Head 1.1")))
636 ;; 4.2. At an headline beginning: move to parent headline if no
637 ;; headline at the same level.
639 (org-backward-element)
640 (should (looking-at (regexp-quote "* Head 1")))
641 ;; 4.3. At the first top-level headline: should error.
643 (should-error (org-backward-element)))
644 ;; 5. At beginning of first element inside a greater element:
645 ;; expected to move to greater element's beginning.
646 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
648 (org-backward-element)
649 (should (looking-at "#\\+BEGIN_CENTER")))
650 ;; 6. At the beginning of the first element in a section: should
651 ;; move back to headline, if any.
653 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
654 (progn (goto-char (point-max))
656 (org-backward-element)
657 (org-at-heading-p))))
659 (org-test-with-temp-text "
674 ;; 7.1. At beginning of sub-list: expected to move to the
675 ;; paragraph before it.
677 (org-backward-element)
678 (should (looking-at "item1"))
679 ;; 7.2. At an item in a list: expected to move at previous item.
681 (org-backward-element)
682 (should (looking-at " - sub2"))
684 (org-backward-element)
685 (should (looking-at "- item1"))
686 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
689 (org-backward-element)
690 (should (looking-at " - sub1"))
692 (org-backward-element)
693 (should (looking-at "- item1"))
694 ;; 7.4. At blank-lines before list end: expected to move to top
697 (org-backward-element)
698 (should (looking-at "- item1"))))
700 (ert-deftest test-org
/up-element
()
701 "Test `org-up-element' specifications."
702 ;; 1. At BOB or with no surrounding element: should error.
703 (org-test-with-temp-text "Paragraph."
704 (should-error (org-up-element)))
705 (org-test-with-temp-text "* Head1\n* Head2"
707 (should-error (org-up-element)))
708 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
710 (should-error (org-up-element)))
711 ;; 2. At an headline: move to parent headline.
712 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
715 (should (looking-at "\\* Head1")))
716 ;; 3. Inside a greater element: move to greater element beginning.
717 (org-test-with-temp-text
718 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
721 (should (looking-at "#\\+BEGIN_CENTER")))
723 (org-test-with-temp-text "* Top
730 Paragraph within sub2.
733 ;; 4.1. Within an item: move to the item beginning.
736 (should (looking-at " - sub2"))
737 ;; 4.2. At an item in a sub-list: move to parent item.
740 (should (looking-at "- item1"))
741 ;; 4.3. At an item in top list: move to beginning of whole list.
744 (should (looking-at "- item1"))
745 ;; 4.4. Special case. At very top point: should move to parent of
749 (should (looking-at "\\* Top"))))
751 (ert-deftest test-org
/down-element
()
752 "Test `org-down-element' specifications."
753 ;; Error when the element hasn't got a recursive type.
754 (org-test-with-temp-text "Paragraph."
755 (should-error (org-down-element)))
756 ;; Error when the element has no contents
757 (org-test-with-temp-text "* Headline"
758 (should-error (org-down-element)))
759 ;; When at a plain-list, move to first item.
760 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
763 (should (looking-at " - Item 1.1")))
764 (org-test-with-temp-text "#+NAME: list\n- Item 1"
766 (should (looking-at " Item 1")))
767 ;; When at a table, move to first row
768 (org-test-with-temp-text "#+NAME: table\n| a | b |"
770 (should (looking-at " a | b |")))
771 ;; Otherwise, move inside the greater element.
772 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
774 (should (looking-at "Paragraph"))))
776 (ert-deftest test-org
/drag-element-backward
()
777 "Test `org-drag-element-backward' specifications."
778 ;; 1. Error when trying to move first element of buffer.
779 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
780 (should-error (org-drag-element-backward)))
781 ;; 2. Error when trying to swap nested elements.
782 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
784 (should-error (org-drag-element-backward)))
785 ;; 3. Error when trying to swap an headline element and
786 ;; a non-headline element.
787 (org-test-with-temp-text "Test.\n* Head 1"
789 (should-error (org-drag-element-backward)))
790 ;; 4. Otherwise, swap elements, preserving column and blank lines
792 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
793 (search-forward "graph")
794 (org-drag-element-backward)
795 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
796 (should (looking-at " 2")))
797 ;; 5. Preserve visibility of elements and their contents.
798 (org-test-with-temp-text "
806 (while (search-forward "BEGIN_" nil t
) (org-cycle))
807 (search-backward "- item 1")
808 (org-drag-element-backward)
811 '((63 .
82) (26 .
48))
812 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
813 (overlays-in (point-min) (point-max)))))))
815 (ert-deftest test-org
/drag-element-forward
()
816 "Test `org-drag-element-forward' specifications."
817 ;; 1. Error when trying to move first element of buffer.
818 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
820 (should-error (org-drag-element-forward)))
821 ;; 2. Error when trying to swap nested elements.
822 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
824 (should-error (org-drag-element-forward)))
825 ;; 3. Error when trying to swap a non-headline element and an
827 (org-test-with-temp-text "Test.\n* Head 1"
828 (should-error (org-drag-element-forward)))
829 ;; 4. Otherwise, swap elements, preserving column and blank lines
831 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
832 (search-forward "graph")
833 (org-drag-element-forward)
834 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
835 (should (looking-at " 1")))
836 ;; 5. Preserve visibility of elements and their contents.
837 (org-test-with-temp-text "
845 (while (search-forward "BEGIN_" nil t
) (org-cycle))
846 (search-backward "#+BEGIN_CENTER")
847 (org-drag-element-forward)
850 '((63 .
82) (26 .
48))
851 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
852 (overlays-in (point-min) (point-max)))))))
858 (ert-deftest test-org
/timestamp-has-time-p
()
859 "Test `org-timestamp-has-time-p' specifications."
862 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
863 (org-timestamp-has-time-p (org-element-context))))
866 (org-test-with-temp-text "<2012-03-29 Thu>"
867 (org-timestamp-has-time-p (org-element-context)))))
869 (ert-deftest test-org
/timestamp-format
()
870 "Test `org-timestamp-format' specifications."
875 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
876 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
881 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
882 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
884 (ert-deftest test-org
/timestamp-split-range
()
885 "Test `org-timestamp-split-range' specifications."
886 ;; Extract range start (active).
889 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
890 (let ((ts (org-timestamp-split-range (org-element-context))))
891 (mapcar (lambda (p) (org-element-property p ts
))
892 '(:year-end
:month-end
:day-end
))))))
893 ;; Extract range start (inactive)
896 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
897 (let ((ts (org-timestamp-split-range (org-element-context))))
898 (mapcar (lambda (p) (org-element-property p ts
))
899 '(:year-end
:month-end
:day-end
))))))
900 ;; Extract range end (active).
903 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
904 (let ((ts (org-timestamp-split-range
905 (org-element-context) t
)))
906 (mapcar (lambda (p) (org-element-property p ts
))
907 '(:year-end
:month-end
:day-end
))))))
908 ;; Extract range end (inactive)
911 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
912 (let ((ts (org-timestamp-split-range
913 (org-element-context) t
)))
914 (mapcar (lambda (p) (org-element-property p ts
))
915 '(:year-end
:month-end
:day-end
))))))
916 ;; Return the timestamp if not a range.
918 (org-test-with-temp-text "[2012-03-29 Thu]"
919 (let* ((ts-orig (org-element-context))
920 (ts-copy (org-timestamp-split-range ts-orig
)))
921 (eq ts-orig ts-copy
))))
923 (org-test-with-temp-text "<%%(org-float t 4 2)>"
924 (let* ((ts-orig (org-element-context))
925 (ts-copy (org-timestamp-split-range ts-orig
)))
926 (eq ts-orig ts-copy
))))
927 ;; Check that parent is the same when a range was split.
929 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
930 (let* ((ts-orig (org-element-context))
931 (ts-copy (org-timestamp-split-range ts-orig
)))
932 (eq (org-element-property :parent ts-orig
)
933 (org-element-property :parent ts-copy
))))))
935 (ert-deftest test-org
/timestamp-translate
()
936 "Test `org-timestamp-translate' specifications."
937 ;; Translate whole date range.
940 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
941 (let ((org-display-custom-times t
)
942 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
943 (org-timestamp-translate (org-element-context))))))
944 ;; Translate date range start.
947 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
948 (let ((org-display-custom-times t
)
949 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
950 (org-timestamp-translate (org-element-context) 'start
)))))
951 ;; Translate date range end.
954 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
955 (let ((org-display-custom-times t
)
956 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
957 (org-timestamp-translate (org-element-context) 'end
)))))
958 ;; Translate time range.
961 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
962 (let ((org-display-custom-times t
)
963 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
964 (org-timestamp-translate (org-element-context))))))
965 ;; Translate non-range timestamp.
968 (org-test-with-temp-text "<2012-03-29 Thu>"
969 (let ((org-display-custom-times t
)
970 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
971 (org-timestamp-translate (org-element-context))))))
972 ;; Do not change `diary' timestamps.
974 (equal "<%%(org-float t 4 2)>"
975 (org-test-with-temp-text "<%%(org-float t 4 2)>"
976 (let ((org-display-custom-times t
)
977 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
978 (org-timestamp-translate (org-element-context)))))))
982 ;;; Targets and Radio Targets
984 (ert-deftest test-org
/all-targets
()
985 "Test `org-all-targets' specifications."
986 ;; Without an argument.
988 (equal '("radio-target" "target")
989 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
992 (equal '("radio-target")
993 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
996 (equal '("radio-target")
997 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
998 (org-all-targets t
)))))
1003 ;;; test-org.el ends here