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
/toggle-comment
()
31 "Test `org-toggle-comment' specifications."
35 (org-test-with-temp-text "* COMMENT Test"
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
43 ;; Headline with a regular keyword.
46 (org-test-with-temp-text "* TODO COMMENT Test"
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
57 (org-test-with-temp-text "* COMMENT"
62 (org-test-with-temp-text "* "
65 ;; Headline with a single keyword.
68 (org-test-with-temp-text "* TODO COMMENT"
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
76 ;; Headline with a keyword, a priority cookie and contents.
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
88 (ert-deftest test-org
/comment-dwim
()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim
)
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim
)
104 ;; No region selected, and a comment on this line: indent it.
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t
))
110 (call-interactively 'comment-dwim
))
112 ;; Also recognize single # at column 0 as comments.
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim
)
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
125 (transient-mark-mode 1)
126 (push-mark (point) t t
)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim
)
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
136 (transient-mark-mode 1)
137 (push-mark (point) t t
)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil
))
140 (call-interactively 'comment-dwim
))
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
146 (transient-mark-mode 1)
147 (push-mark (point) t t
)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t
))
150 (call-interactively 'comment-dwim
))
152 ;; In front of a keyword without region, insert a new comment.
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim
)
158 ;; In a source block, use appropriate syntax.
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim
))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
170 (transient-mark-mode 1)
171 (push-mark (point) t t
)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim
))
179 ;;; Date and time analysis
181 (ert-deftest test-org
/org-read-date
()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t
))
186 (org-read-date t nil
"12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t
))
190 (org-read-date t nil
"29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t
))
194 (org-read-date t nil
"29.03. 16:40")))))
196 (ert-deftest test-org
/org-parse-time-string
()
197 "Test `org-parse-time-string'."
198 (should (equal (org-parse-time-string "2012-03-29 16:40")
199 '(0 40 16 29 3 2012 nil nil nil
)))
200 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
201 '(0 40 16 29 3 2012 nil nil nil
)))
202 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
203 '(0 40 16 29 3 2012 nil nil nil
)))
204 (should (equal (org-parse-time-string "<2012-03-29>")
205 '(0 0 0 29 3 2012 nil nil nil
)))
206 (should (equal (org-parse-time-string "<2012-03-29>" t
)
207 '(0 nil nil
29 3 2012 nil nil nil
))))
212 (ert-deftest test-org
/fill-paragraph
()
213 "Test `org-fill-paragraph' specifications."
214 ;; At an Org table, align it.
217 (org-test-with-temp-text "|a|"
221 (equal "#+name: table\n| a |\n"
222 (org-test-with-temp-text "#+name: table\n| a |"
225 ;; At a paragraph, preserve line breaks.
226 (org-test-with-temp-text "some \\\\\nlong\ntext"
227 (let ((fill-column 20))
229 (should (equal (buffer-string) "some \\\\\nlong text"))))
230 ;; Correctly fill a paragraph when point is at its very end.
233 (org-test-with-temp-text "A\nB"
234 (let ((fill-column 20))
235 (goto-char (point-max))
238 ;; Correctly fill the last paragraph of a greater element.
240 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
241 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
242 (let ((fill-column 8))
247 ;; Correctly fill an element in a narrowed buffer.
250 (org-test-with-temp-text "01234 6789"
251 (let ((fill-column 5))
252 (narrow-to-region 1 8)
255 ;; Handle `adaptive-fill-regexp' in paragraphs.
258 (org-test-with-temp-text "> a\n> b"
259 (let ((fill-column 5)
260 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
263 ;; Special case: Fill first paragraph when point is at an item or
264 ;; a plain-list or a footnote reference.
267 (org-test-with-temp-text "- A\n B"
268 (let ((fill-column 20))
273 (org-test-with-temp-text "[fn:1] A\nB"
274 (let ((fill-column 20))
277 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
278 (let ((fill-column 20))
280 (should (equal (buffer-string)
281 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
282 ;; Fill contents of `comment-block' elements.
285 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
286 (let ((fill-column 20))
290 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
291 ;; Fill `comment' elements.
294 (org-test-with-temp-text " # A\n # B"
295 (let ((fill-column 20))
298 ;; Do not mix consecutive comments when filling one of them.
300 (equal "# A B\n\n# C"
301 (org-test-with-temp-text "# A\n# B\n\n# C"
302 (let ((fill-column 20))
305 ;; Use commented empty lines as separators when filling comments.
307 (equal "# A B\n#\n# C"
308 (org-test-with-temp-text "# A\n# B\n#\n# C"
309 (let ((fill-column 20))
312 ;; Handle `adaptive-fill-regexp' in comments.
315 (org-test-with-temp-text "# > a\n# > b"
316 (let ((fill-column 20)
317 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
320 ;; Do nothing at affiliated keywords.
321 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
322 (let ((fill-column 20))
324 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
325 ;; Do not move point after table when filling a table.
327 (org-test-with-temp-text "| a | b |\n| c | d |\n"
332 (ert-deftest test-org
/auto-fill-function
()
333 "Test auto-filling features."
334 ;; Auto fill paragraph.
337 (org-test-with-temp-text "12345 7890"
338 (let ((fill-column 5))
340 (org-auto-fill-function)
342 ;; Auto fill first paragraph in an item.
344 (equal "- 12345\n 7890"
345 (org-test-with-temp-text "- 12345 7890"
346 (let ((fill-column 7))
348 (org-auto-fill-function)
350 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
352 (equal "> 12345\n 7890"
353 (org-test-with-temp-text "> 12345 7890"
354 (let ((fill-column 10)
355 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
356 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
358 (org-auto-fill-function)
361 (equal "> 12345\n> 12345\n> 7890"
362 (org-test-with-temp-text "> 12345\n> 12345 7890"
363 (let ((fill-column 10)
364 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
365 (goto-char (point-max))
366 (org-auto-fill-function)
369 (equal " 12345\n *12345\n *12345"
370 (org-test-with-temp-text " 12345\n *12345 12345"
371 (let ((fill-column 10)
372 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
373 (goto-char (point-max))
374 (org-auto-fill-function)
376 ;; Auto fill comments.
378 (equal " # 12345\n # 7890"
379 (org-test-with-temp-text " # 12345 7890"
380 (let ((fill-column 10))
382 (org-auto-fill-function)
384 ;; A hash within a line isn't a comment.
386 (equal "12345 # 7890\n# 1"
387 (org-test-with-temp-text "12345 # 7890 1"
388 (let ((fill-column 12))
390 (org-auto-fill-function)
392 ;; Correctly interpret empty prefix.
394 (equal "# a\n# b\nRegular\n# paragraph"
395 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
396 (let ((fill-column 12))
398 (org-auto-fill-function)
400 ;; Comment block: auto fill contents.
402 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
403 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
404 (let ((fill-column 5))
407 (org-auto-fill-function)
410 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
411 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
412 (let ((fill-column 5))
415 (org-auto-fill-function)
417 ;; Do not fill if a new item could be created.
420 (org-test-with-temp-text "12345 - 90"
421 (let ((fill-column 5))
423 (org-auto-fill-function)
425 ;; Do not fill if a line break could be introduced.
427 (equal "123\\\\\n7890"
428 (org-test-with-temp-text "123\\\\ 7890"
429 (let ((fill-column 6))
431 (org-auto-fill-function)
433 ;; Do not fill affiliated keywords.
435 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
436 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
437 (let ((fill-column 20))
439 (org-auto-fill-function)
446 (ert-deftest test-org
/indent-line
()
447 "Test `org-indent-line' specifications."
448 ;; Do not indent footnote definitions or headlines.
451 (org-test-with-temp-text "* H"
453 (org-get-indentation))))
456 (org-test-with-temp-text "[fn:1] fn"
457 (let ((org-adapt-indentation t
)) (org-indent-line))
458 (org-get-indentation))))
459 ;; Do not indent before first headline.
462 (org-test-with-temp-text ""
464 (org-get-indentation))))
465 ;; Indent according to headline level otherwise, unless
466 ;; `org-adapt-indentation' is nil.
469 (org-test-with-temp-text "* H\nA"
471 (let ((org-adapt-indentation t
)) (org-indent-line))
472 (org-get-indentation))))
475 (org-test-with-temp-text "* H\n\nA"
477 (let ((org-adapt-indentation t
)) (org-indent-line))
478 (org-get-indentation))))
481 (org-test-with-temp-text "* H\nA"
483 (let ((org-adapt-indentation nil
)) (org-indent-line))
484 (org-get-indentation))))
485 ;; Indenting preserves point position.
487 (org-test-with-temp-text "* H\nAB"
490 (let ((org-adapt-indentation t
)) (org-indent-line))
492 ;; Do not change indentation at an item.
495 (org-test-with-temp-text "* H\n - A"
497 (let ((org-adapt-indentation t
)) (org-indent-line))
498 (org-get-indentation))))
499 ;; On blank lines at the end of a list, indent like last element
500 ;; within it if the line is still in the list. Otherwise, indent
501 ;; like the whole list.
504 (org-test-with-temp-text "* H\n- A\n - AA\n"
505 (goto-char (point-max))
506 (let ((org-adapt-indentation t
)) (org-indent-line))
507 (org-get-indentation))))
510 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
511 (goto-char (point-max))
512 (let ((org-adapt-indentation t
)) (org-indent-line))
513 (org-get-indentation))))
514 ;; Likewise, on a blank line at the end of a footnote definition,
515 ;; indent at column 0 if line belongs to the definition. Otherwise,
516 ;; indent like the definition itself.
519 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
520 (goto-char (point-max))
521 (let ((org-adapt-indentation t
)) (org-indent-line))
522 (org-get-indentation))))
525 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
526 (goto-char (point-max))
527 (let ((org-adapt-indentation t
)) (org-indent-line))
528 (org-get-indentation))))
529 ;; After the end of the contents of a greater element, indent like
530 ;; the beginning of the element.
533 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
536 (org-get-indentation))))
537 ;; At the first line of an element, indent like previous element's
538 ;; first line, ignoring footnotes definitions and inline tasks, or
539 ;; according to parent.
542 (org-test-with-temp-text "A\n\n B\n\nC"
543 (goto-char (point-max))
545 (org-get-indentation))))
548 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
549 (goto-char (point-max))
551 (org-get-indentation))))
554 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
557 (org-get-indentation))))
558 ;; Within code part of a source block, use language major mode if
559 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
560 ;; according to line above.
563 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
565 (let ((org-src-tab-acts-natively t
)
566 (org-edit-src-content-indentation 0))
568 (org-get-indentation))))
571 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
573 (let ((org-src-tab-acts-natively nil
)
574 (org-edit-src-content-indentation 0))
576 (org-get-indentation))))
577 ;; Otherwise, indent like the first non-blank line above.
580 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
583 (org-get-indentation))))
584 ;; Align node properties according to `org-property-format'. Handle
585 ;; nicely empty values.
587 (equal ":PROPERTIES:\n:key: value\n:END:"
588 (org-test-with-temp-text ":PROPERTIES:\n:key: value\n:END:"
590 (let ((org-property-format "%-10s %s"))
594 (equal ":PROPERTIES:\n:key:\n:END:"
595 (org-test-with-temp-text ":PROPERTIES:\n:key:\n:END:"
597 (let ((org-property-format "%-10s %s"))
601 (ert-deftest test-org
/indent-region
()
602 "Test `org-indent-region' specifications."
606 (org-test-with-temp-text " A\nB\n C"
607 (org-indent-region (point-min) (point-max))
609 ;; Indent greater elements along with their contents.
611 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
612 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
613 (org-indent-region (point-min) (point-max))
615 ;; Ignore contents of verse blocks and example blocks.
617 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
618 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
619 (org-indent-region (point-min) (point-max))
622 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
623 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
624 (org-indent-region (point-min) (point-max))
626 ;; Indent according to mode if `org-src-tab-acts-natively' is
627 ;; non-nil. Otherwise, do not indent code at all.
629 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
630 (org-test-with-temp-text
631 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
632 (let ((org-src-tab-acts-natively t
)
633 (org-edit-src-content-indentation 0))
634 (org-indent-region (point-min) (point-max)))
637 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
638 (org-test-with-temp-text
639 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
640 (let ((org-src-tab-acts-natively nil
)
641 (org-edit-src-content-indentation 0))
642 (org-indent-region (point-min) (point-max)))
644 ;; Align node properties according to `org-property-format'. Handle
645 ;; nicely empty values.
647 (equal ":PROPERTIES:\n:key: value\n:END:"
648 (org-test-with-temp-text ":PROPERTIES:\n:key: value\n:END:"
649 (let ((org-property-format "%-10s %s"))
650 (org-indent-region (point-min) (point-max)))
653 (equal ":PROPERTIES:\n:key:\n:END:"
654 (org-test-with-temp-text ":PROPERTIES:\n:key:\n:END:"
655 (let ((org-property-format "%-10s %s"))
656 (org-indent-region (point-min) (point-max)))
658 ;; Special case: plain lists and footnote definitions.
660 (equal "- A\n B\n - C\n\n D"
661 (org-test-with-temp-text "- A\n B\n - C\n\n D"
662 (org-indent-region (point-min) (point-max))
665 (equal "[fn:1] Definition\n\nDefinition"
666 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
667 (org-indent-region (point-min) (point-max))
676 (ert-deftest test-org
/meta-return
()
677 "Test M-RET (`org-meta-return')."
678 ;; In a table field insert a row above.
680 (org-test-with-temp-text "| a |"
684 (looking-at "| |$")))
685 ;; In a paragraph change current line into a header.
687 (org-test-with-temp-text "a"
690 (looking-at "\* a$")))
691 ;; In an item insert an item, in this case above.
693 (org-test-with-temp-text "- a"
697 ;; In a drawer and item insert an item, in this case above.
699 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
703 (looking-at "- $"))))
705 (ert-deftest test-org
/insert-heading
()
706 "Test `org-insert-heading' specifications."
707 ;; FIXME: Test coverage is incomplete yet.
709 ;; In an empty buffer, insert a new headline.
712 (org-test-with-temp-text ""
715 ;; At the beginning of a line, turn it into a headline
718 (org-test-with-temp-text "<point>P"
721 ;; In the middle of a line, split the line if allowed, otherwise,
722 ;; insert the headline at its end.
724 (equal "Para\n* graph"
725 (org-test-with-temp-text "Para<point>graph"
726 (let ((org-M-RET-may-split-line '((default . t
))))
727 (org-insert-heading))
730 (equal "Paragraph\n* "
731 (org-test-with-temp-text "Para<point>graph"
732 (let ((org-M-RET-may-split-line '((default . nil
))))
733 (org-insert-heading))
735 ;; Corner case: correctly insert a headline after an empty one.
738 (org-test-with-temp-text "* <point>"
742 (ert-deftest test-org
/insert-todo-heading-respect-content
()
743 "Test `org-insert-todo-heading-respect-content' specifications."
744 ;; Create a TODO heading.
746 (org-test-with-temp-text "* H1\n Body"
747 (org-insert-todo-heading-respect-content)
748 (nth 2 (org-heading-components))))
749 ;; Add headline at the end of the first subtree
751 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
752 (search-forward "H1Body")
753 (org-insert-todo-heading-respect-content)
754 (and (eobp) (org-at-heading-p))))
755 ;; In a list, do not create a new item.
757 (org-test-with-temp-text "* H\n- an item\n- another one"
758 (search-forward "an ")
759 (org-insert-todo-heading-respect-content)
760 (and (eobp) (org-at-heading-p)))))
764 ;;; Fixed-Width Areas
766 (ert-deftest test-org
/toggle-fixed-width
()
767 "Test `org-toggle-fixed-width' specifications."
768 ;; No region: Toggle on fixed-width marker in paragraphs.
771 (org-test-with-temp-text "A"
772 (org-toggle-fixed-width)
774 ;; No region: Toggle off fixed-width markers in fixed-width areas.
777 (org-test-with-temp-text ": A"
778 (org-toggle-fixed-width)
780 ;; No region: Toggle on marker in blank lines after elements or just
784 (org-test-with-temp-text "* H\n"
786 (org-toggle-fixed-width)
789 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
790 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
791 (goto-char (point-max))
792 (org-toggle-fixed-width)
794 ;; No region: Toggle on marker in front of one line elements (e.g.,
795 ;; headlines, clocks)
797 (equal ": * Headline"
798 (org-test-with-temp-text "* Headline"
799 (org-toggle-fixed-width)
802 (equal ": #+KEYWORD: value"
803 (org-test-with-temp-text "#+KEYWORD: value"
804 (org-toggle-fixed-width)
806 ;; No region: error in other situations.
808 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
810 (org-toggle-fixed-width)
812 ;; No region: Indentation is preserved.
815 (org-test-with-temp-text "- A\n B"
817 (org-toggle-fixed-width)
819 ;; Region: If it contains only fixed-width elements and blank lines,
820 ;; toggle off fixed-width markup.
823 (org-test-with-temp-text ": A\n\n: B"
824 (transient-mark-mode 1)
825 (push-mark (point) t t
)
826 (goto-char (point-max))
827 (org-toggle-fixed-width)
829 ;; Region: If it contains anything else, toggle on fixed-width but
830 ;; not on fixed-width areas.
832 (equal ": A\n: \n: B\n: \n: C"
833 (org-test-with-temp-text "A\n\n: B\n\nC"
834 (transient-mark-mode 1)
835 (push-mark (point) t t
)
836 (goto-char (point-max))
837 (org-toggle-fixed-width)
839 ;; Region: Ignore blank lines at its end, unless it contains only
843 (org-test-with-temp-text "A\n\n"
844 (transient-mark-mode 1)
845 (push-mark (point) t t
)
846 (goto-char (point-max))
847 (org-toggle-fixed-width)
851 (org-test-with-temp-text "\n\n"
852 (transient-mark-mode 1)
853 (push-mark (point) t t
)
854 (goto-char (point-max))
855 (org-toggle-fixed-width)
862 (ert-deftest test-org
/in-commented-heading-p
()
863 "Test `org-in-commented-heading-p' specifications."
864 ;; Commented headline.
866 (org-test-with-temp-text "* COMMENT Headline\nBody"
867 (goto-char (point-max))
868 (org-in-commented-heading-p)))
869 ;; Commented ancestor.
871 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
872 (goto-char (point-max))
873 (org-in-commented-heading-p)))
874 ;; Comment keyword is case-sensitive.
876 (org-test-with-temp-text "* Comment Headline\nBody"
877 (goto-char (point-max))
878 (org-in-commented-heading-p)))
879 ;; Keyword is standalone.
881 (org-test-with-temp-text "* COMMENTHeadline\nBody"
882 (goto-char (point-max))
883 (org-in-commented-heading-p)))
884 ;; Optional argument.
886 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
887 (goto-char (point-max))
888 (org-in-commented-heading-p t
))))
896 (ert-deftest test-org
/coderef
()
897 "Test coderef links specifications."
899 (org-test-with-temp-text "
900 #+BEGIN_SRC emacs-lisp
904 (goto-char (point-max))
906 (looking-at "(ref:sc)"))))
910 (ert-deftest test-org
/custom-id
()
911 "Test custom ID links specifications."
913 (org-test-with-temp-text
914 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
915 (goto-char (point-max))
917 (org-looking-at-p "\\* H1"))))
921 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
922 ;; a named element (#+name: text) and to headlines (* Text).
924 (ert-deftest test-org
/fuzzy-links
()
925 "Test fuzzy links specifications."
926 ;; Fuzzy link goes in priority to a matching target.
928 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
931 (looking-at "<<Test>>")))
932 ;; Then fuzzy link points to an element with a given name.
934 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
937 (looking-at "#\\+NAME: Test")))
938 ;; A target still lead to a matching headline otherwise.
940 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
943 (looking-at "\\* Head2")))
944 ;; With a leading star in link, enforce heading match.
946 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
949 (looking-at "\\* Test")))
950 ;; Correctly un-hexify fuzzy links.
952 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
953 (goto-char (point-max))
959 (ert-deftest test-org
/org-link-escape-ascii-character
()
960 "Escape an ascii character."
964 (org-link-escape "["))))
966 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
967 "Escape an ascii control character."
971 (org-link-escape "\t"))))
973 (ert-deftest test-org
/org-link-escape-multibyte-character
()
974 "Escape an unicode multibyte character."
978 (org-link-escape "€"))))
980 (ert-deftest test-org
/org-link-escape-custom-table
()
981 "Escape string with custom character table."
985 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
987 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
988 "Escape string with custom table merged with default table."
991 "%5BF%6F%6F%3A%42ar%0A%5D"
992 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
994 (ert-deftest test-org
/org-link-unescape-ascii-character
()
995 "Unescape an ascii character."
999 (org-link-unescape "%5B"))))
1001 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1002 "Unescpae an ascii control character."
1006 (org-link-unescape "%0A"))))
1008 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1009 "Unescape unicode multibyte character."
1013 (org-link-unescape "%E2%82%AC"))))
1015 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1016 "Unescape old style percent escaped character."
1019 "à âçèéêîôùû"
1020 (decode-coding-string
1021 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1023 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1024 "Escape and unescape a URL that includes an escaped char.
1025 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1028 "http://some.host.com/form?&id=blah%2Bblah25"
1030 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1032 (ert-deftest test-org
/org-link-escape-chars-browser
()
1033 "Test of the constant `org-link-escape-chars-browser'.
1034 See there why this test is a candidate to be removed once Org
1035 drops support for Emacs 24.1 and 24.2."
1038 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1039 "%22Release%208.2%22&idxname=emacs-orgmode")
1040 (org-link-escape-browser ; Do not replace with `url-encode-url',
1041 ; see docstring above.
1042 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1043 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1047 (ert-deftest test-org
/open-at-point-in-property
()
1048 "Does `org-open-at-point' open link in property drawer?"
1050 (org-test-with-temp-text
1053 :URL: <point>[[info:emacs#Top]]
1055 (org-open-at-point) t
)))
1057 (ert-deftest test-org
/open-at-point-in-comment
()
1058 "Does `org-open-at-point' open link in a commented line?"
1060 (org-test-with-temp-text
1061 "# <point>[[info:emacs#Top]]"
1062 (org-open-at-point) t
)))
1064 (ert-deftest test-org
/open-at-point
/info
()
1065 "Test `org-open-at-point' on info links."
1067 (org-test-with-temp-text
1068 "<point>[[info:emacs#Top]]"
1070 (and (switch-to-buffer "*info*")
1072 (looking-at "\nThe Emacs Editor")
1078 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1079 "Ensure properties accumulate in subtree drawers."
1080 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1081 (org-babel-next-src-block)
1082 (should (equal '(2 1) (org-babel-execute-src-block)))))
1088 (ert-deftest test-org
/mark-subtree
()
1089 "Test `org-mark-subtree' specifications."
1090 ;; Error when point is before first headline.
1092 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1093 (progn (transient-mark-mode 1)
1094 (org-mark-subtree))))
1095 ;; Without argument, mark current subtree.
1099 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1100 (progn (transient-mark-mode 1)
1103 (list (region-beginning) (region-end))))))
1104 ;; With an argument, move ARG up.
1108 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1109 (progn (transient-mark-mode 1)
1111 (org-mark-subtree 1)
1112 (list (region-beginning) (region-end))))))
1113 ;; Do not get fooled by inlinetasks.
1114 (when (featurep 'org-inlinetask
)
1117 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1118 (progn (transient-mark-mode 1)
1120 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1121 (region-beginning)))))))
1127 (ert-deftest test-org
/beginning-of-line
()
1128 "Test `org-beginning-of-line' specifications."
1131 (org-test-with-temp-text "Some text\nSome other text"
1132 (progn (org-beginning-of-line) (bolp))))
1133 ;; Standard test with `visual-line-mode'.
1135 (org-test-with-temp-text "A long line of text\nSome other text"
1136 (progn (visual-line-mode)
1138 (dotimes (i 1000) (insert "very "))
1139 (org-beginning-of-line)
1141 ;; At an headline with special movement.
1143 (org-test-with-temp-text "* TODO Headline"
1144 (let ((org-special-ctrl-a/e t
))
1146 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1147 (progn (org-beginning-of-line) (bolp))
1148 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1150 (ert-deftest test-org
/end-of-line
()
1151 "Test `org-end-of-line' specifications."
1154 (org-test-with-temp-text "Some text\nSome other text"
1155 (progn (org-end-of-line) (eolp))))
1156 ;; Standard test with `visual-line-mode'.
1158 (org-test-with-temp-text "A long line of text\nSome other text"
1159 (progn (visual-line-mode)
1161 (dotimes (i 1000) (insert "very "))
1162 (goto-char (point-min))
1165 ;; At an headline with special movement.
1167 (org-test-with-temp-text "* Headline1 :tag:\n"
1168 (let ((org-special-ctrl-a/e t
))
1169 (and (progn (org-end-of-line) (looking-at " :tag:"))
1170 (progn (org-end-of-line) (eolp))
1171 (progn (org-end-of-line) (looking-at " :tag:"))))))
1172 ;; At an headline without special movement.
1174 (org-test-with-temp-text "* Headline2 :tag:\n"
1175 (let ((org-special-ctrl-a/e nil
))
1176 (and (progn (org-end-of-line) (eolp))
1177 (progn (org-end-of-line) (eolp))))))
1178 ;; At an headline, with reversed movement.
1180 (org-test-with-temp-text "* Headline3 :tag:\n"
1181 (let ((org-special-ctrl-a/e
'reversed
)
1182 (this-command last-command
))
1183 (and (progn (org-end-of-line) (eolp))
1184 (progn (org-end-of-line) (looking-at " :tag:"))))))
1185 ;; At a block without hidden contents.
1187 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1188 (progn (org-end-of-line) (eolp))))
1189 ;; At a block with hidden contents.
1191 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1192 (let ((org-special-ctrl-a/e t
))
1193 (org-hide-block-toggle)
1197 (ert-deftest test-org
/forward-paragraph
()
1198 "Test `org-forward-paragraph' specifications."
1199 ;; At end of buffer, return an error.
1201 (org-test-with-temp-text "Paragraph"
1202 (goto-char (point-max))
1203 (org-forward-paragraph)))
1206 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1207 (org-forward-paragraph)
1211 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1212 (org-forward-paragraph)
1214 ;; Do not enter elements with invisible contents.
1216 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1217 (org-hide-block-toggle)
1218 (org-forward-paragraph)
1220 ;; On an affiliated keyword, jump to the beginning of the element.
1222 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1223 (org-forward-paragraph)
1224 (looking-at "Para")))
1225 ;; On an item or a footnote definition, move to the second element
1228 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1229 (org-forward-paragraph)
1230 (looking-at " Paragraph")))
1232 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1233 (org-forward-paragraph)
1234 (looking-at "Paragraph")))
1235 ;; On an item, or a footnote definition, when the first line is
1236 ;; empty, move to the first item.
1238 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1239 (org-forward-paragraph)
1240 (looking-at " Paragraph")))
1242 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1243 (org-forward-paragraph)
1244 (looking-at "Paragraph")))
1245 ;; On a table (resp. a property drawer) do not move through table
1246 ;; rows (resp. node properties).
1248 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1249 (org-forward-paragraph)
1250 (looking-at "Paragraph")))
1252 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nParagraph"
1253 (org-forward-paragraph)
1254 (looking-at "Paragraph")))
1255 ;; On a verse or source block, stop after blank lines.
1257 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1258 (org-forward-paragraph)
1261 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1262 (org-forward-paragraph)
1263 (looking-at "L2"))))
1265 (ert-deftest test-org
/backward-paragraph
()
1266 "Test `org-backward-paragraph' specifications."
1267 ;; Error at beginning of buffer.
1269 (org-test-with-temp-text "Paragraph"
1270 (org-backward-paragraph)))
1273 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1274 (goto-char (point-max))
1275 (org-backward-paragraph)
1278 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1279 (goto-char (point-max))
1281 (org-backward-paragraph)
1285 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1286 (goto-char (point-max))
1288 (org-backward-paragraph)
1290 ;; Ignore invisible elements.
1292 (org-test-with-temp-text "* H1\n P1\n* H2"
1294 (goto-char (point-max))
1296 (org-backward-paragraph)
1298 ;; On an affiliated keyword, jump to the first one.
1300 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1301 (search-forward "c2")
1302 (org-backward-paragraph)
1303 (looking-at "#\\+name")))
1304 ;; On the second element in an item or a footnote definition, jump
1305 ;; to item or the definition.
1307 (org-test-with-temp-text "- line1\n\n line2"
1308 (goto-char (point-max))
1310 (org-backward-paragraph)
1311 (looking-at "- line1")))
1313 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1314 (goto-char (point-max))
1316 (org-backward-paragraph)
1317 (looking-at "\\[fn:1\\] line1")))
1318 ;; On a table (resp. a property drawer), ignore table rows
1319 ;; (resp. node properties).
1321 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1322 (goto-char (point-max))
1324 (org-backward-paragraph)
1327 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nP1"
1328 (goto-char (point-max))
1330 (org-backward-paragraph)
1332 ;; On a source or verse block, stop before blank lines.
1334 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1335 (search-forward "L3")
1337 (org-backward-paragraph)
1340 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1341 (search-forward "L3")
1343 (org-backward-paragraph)
1344 (looking-at "L2"))))
1346 (ert-deftest test-org
/forward-element
()
1347 "Test `org-forward-element' specifications."
1348 ;; 1. At EOB: should error.
1349 (org-test-with-temp-text "Some text\n"
1350 (goto-char (point-max))
1351 (should-error (org-forward-element)))
1352 ;; 2. Standard move: expected to ignore blank lines.
1353 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1354 (org-forward-element)
1355 (should (looking-at (regexp-quote "Second paragraph."))))
1356 ;; 3. Headline tests.
1357 (org-test-with-temp-text "
1362 ;; 3.1. At an headline beginning: move to next headline at the
1365 (org-forward-element)
1366 (should (looking-at (regexp-quote "** Head 1.2")))
1367 ;; 3.2. At an headline beginning: move to parent headline if no
1368 ;; headline at the same level.
1370 (org-forward-element)
1371 (should (looking-at (regexp-quote "** Head 1.2"))))
1372 ;; 4. Greater element tests.
1373 (org-test-with-temp-text
1374 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1375 ;; 4.1. At a greater element: expected to skip contents.
1376 (org-forward-element)
1377 (should (looking-at (regexp-quote "Outside.")))
1378 ;; 4.2. At the end of greater element contents: expected to skip
1379 ;; to the end of the greater element.
1381 (org-forward-element)
1382 (should (looking-at (regexp-quote "Outside."))))
1384 (org-test-with-temp-text "
1398 ;; 5.1. At list top point: expected to move to the element after
1401 (org-forward-element)
1402 (should (looking-at (regexp-quote "Outside.")))
1403 ;; 5.2. Special case: at the first line of a sub-list, but not at
1404 ;; beginning of line, move to next item.
1407 (org-forward-element)
1408 (should (looking-at "- item2"))
1411 (org-forward-element)
1412 (should (looking-at " - sub2"))
1413 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1415 (org-forward-element)
1416 (should (looking-at (regexp-quote " Inner paragraph.")))
1417 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1419 (org-forward-element)
1420 (should (looking-at (regexp-quote " Inner paragraph.")))
1421 ;; 5.5. At an item: expected to move to next item, if any.
1423 (org-forward-element)
1424 (should (looking-at " - sub3"))))
1426 (ert-deftest test-org
/backward-element
()
1427 "Test `org-backward-element' specifications."
1428 ;; 1. Should error at BOB.
1429 (org-test-with-temp-text " \nParagraph."
1430 (should-error (org-backward-element)))
1431 ;; 2. Should move at BOB when called on the first element in buffer.
1433 (org-test-with-temp-text "\n#+TITLE: test"
1434 (progn (forward-line)
1435 (org-backward-element)
1437 ;; 3. Not at the beginning of an element: move at its beginning.
1438 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1441 (org-backward-element)
1442 (should (looking-at (regexp-quote "Paragraph2."))))
1443 ;; 4. Headline tests.
1444 (org-test-with-temp-text "
1449 ;; 4.1. At an headline beginning: move to previous headline at the
1452 (org-backward-element)
1453 (should (looking-at (regexp-quote "** Head 1.1")))
1454 ;; 4.2. At an headline beginning: move to parent headline if no
1455 ;; headline at the same level.
1457 (org-backward-element)
1458 (should (looking-at (regexp-quote "* Head 1")))
1459 ;; 4.3. At the first top-level headline: should error.
1461 (should-error (org-backward-element)))
1462 ;; 5. At beginning of first element inside a greater element:
1463 ;; expected to move to greater element's beginning.
1464 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1466 (org-backward-element)
1467 (should (looking-at "#\\+BEGIN_CENTER")))
1468 ;; 6. At the beginning of the first element in a section: should
1469 ;; move back to headline, if any.
1471 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1472 (progn (goto-char (point-max))
1474 (org-backward-element)
1475 (org-at-heading-p))))
1477 (org-test-with-temp-text "
1492 ;; 7.1. At beginning of sub-list: expected to move to the
1493 ;; paragraph before it.
1495 (org-backward-element)
1496 (should (looking-at "item1"))
1497 ;; 7.2. At an item in a list: expected to move at previous item.
1499 (org-backward-element)
1500 (should (looking-at " - sub2"))
1502 (org-backward-element)
1503 (should (looking-at "- item1"))
1504 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1507 (org-backward-element)
1508 (should (looking-at " - sub1"))
1510 (org-backward-element)
1511 (should (looking-at "- item1"))
1512 ;; 7.4. At blank-lines before list end: expected to move to top
1515 (org-backward-element)
1516 (should (looking-at "- item1"))))
1518 (ert-deftest test-org
/up-element
()
1519 "Test `org-up-element' specifications."
1520 ;; 1. At BOB or with no surrounding element: should error.
1521 (org-test-with-temp-text "Paragraph."
1522 (should-error (org-up-element)))
1523 (org-test-with-temp-text "* Head1\n* Head2"
1525 (should-error (org-up-element)))
1526 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1528 (should-error (org-up-element)))
1529 ;; 2. At an headline: move to parent headline.
1530 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1533 (should (looking-at "\\* Head1")))
1534 ;; 3. Inside a greater element: move to greater element beginning.
1535 (org-test-with-temp-text
1536 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1539 (should (looking-at "#\\+BEGIN_CENTER")))
1541 (org-test-with-temp-text "* Top
1548 Paragraph within sub2.
1551 ;; 4.1. Within an item: move to the item beginning.
1554 (should (looking-at " - sub2"))
1555 ;; 4.2. At an item in a sub-list: move to parent item.
1558 (should (looking-at "- item1"))
1559 ;; 4.3. At an item in top list: move to beginning of whole list.
1562 (should (looking-at "- item1"))
1563 ;; 4.4. Special case. At very top point: should move to parent of
1567 (should (looking-at "\\* Top"))))
1569 (ert-deftest test-org
/down-element
()
1570 "Test `org-down-element' specifications."
1571 ;; Error when the element hasn't got a recursive type.
1572 (org-test-with-temp-text "Paragraph."
1573 (should-error (org-down-element)))
1574 ;; Error when the element has no contents
1575 (org-test-with-temp-text "* Headline"
1576 (should-error (org-down-element)))
1577 ;; When at a plain-list, move to first item.
1578 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1581 (should (looking-at " - Item 1.1")))
1582 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1584 (should (looking-at " Item 1")))
1585 ;; When at a table, move to first row
1586 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1588 (should (looking-at " a | b |")))
1589 ;; Otherwise, move inside the greater element.
1590 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1592 (should (looking-at "Paragraph"))))
1594 (ert-deftest test-org
/drag-element-backward
()
1595 "Test `org-drag-element-backward' specifications."
1599 "#+key2: val2\n#+key1: val1\n#+key3: val3"
1600 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
1601 (org-drag-element-backward)
1605 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
1606 (org-test-with-temp-text
1607 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
1608 (org-drag-element-backward)
1610 ;; Preserve blank lines.
1612 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
1613 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
1614 (org-drag-element-backward)
1618 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
1619 (org-drag-element-backward)
1620 (org-looking-at-p "2")))
1621 ;; Error when trying to move first element of buffer.
1623 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1624 (org-drag-element-backward)))
1625 ;; Error when trying to swap nested elements.
1627 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1629 (org-drag-element-backward)))
1630 ;; Error when trying to swap an headline element and a non-headline
1633 (org-test-with-temp-text "Test.\n* Head 1"
1635 (org-drag-element-backward)))
1636 ;; Preserve visibility of elements and their contents.
1638 (equal '((63 .
82) (26 .
48))
1639 (org-test-with-temp-text "
1647 (while (search-forward "BEGIN_" nil t
) (org-cycle))
1648 (search-backward "- item 1")
1649 (org-drag-element-backward)
1650 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
1651 (overlays-in (point-min) (point-max)))))))
1653 (ert-deftest test-org
/drag-element-forward
()
1654 "Test `org-drag-element-forward' specifications."
1655 ;; 1. Error when trying to move first element of buffer.
1656 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1658 (should-error (org-drag-element-forward)))
1659 ;; 2. Error when trying to swap nested elements.
1660 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1662 (should-error (org-drag-element-forward)))
1663 ;; 3. Error when trying to swap a non-headline element and an
1665 (org-test-with-temp-text "Test.\n* Head 1"
1666 (should-error (org-drag-element-forward)))
1667 ;; 4. Otherwise, swap elements, preserving column and blank lines
1668 ;; between elements.
1669 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
1670 (search-forward "graph")
1671 (org-drag-element-forward)
1672 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
1673 (should (looking-at " 1")))
1674 ;; 5. Preserve visibility of elements and their contents.
1675 (org-test-with-temp-text "
1683 (while (search-forward "BEGIN_" nil t
) (org-cycle))
1684 (search-backward "#+BEGIN_CENTER")
1685 (org-drag-element-forward)
1688 '((63 .
82) (26 .
48))
1689 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
1690 (overlays-in (point-min) (point-max)))))))
1696 (ert-deftest test-org
/timestamp-has-time-p
()
1697 "Test `org-timestamp-has-time-p' specifications."
1700 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1701 (org-timestamp-has-time-p (org-element-context))))
1704 (org-test-with-temp-text "<2012-03-29 Thu>"
1705 (org-timestamp-has-time-p (org-element-context)))))
1707 (ert-deftest test-org
/timestamp-format
()
1708 "Test `org-timestamp-format' specifications."
1713 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1714 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
1719 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1720 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
1722 (ert-deftest test-org
/timestamp-split-range
()
1723 "Test `org-timestamp-split-range' specifications."
1724 ;; Extract range start (active).
1727 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1728 (let ((ts (org-timestamp-split-range (org-element-context))))
1729 (mapcar (lambda (p) (org-element-property p ts
))
1730 '(:year-end
:month-end
:day-end
))))))
1731 ;; Extract range start (inactive)
1734 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1735 (let ((ts (org-timestamp-split-range (org-element-context))))
1736 (mapcar (lambda (p) (org-element-property p ts
))
1737 '(:year-end
:month-end
:day-end
))))))
1738 ;; Extract range end (active).
1741 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1742 (let ((ts (org-timestamp-split-range
1743 (org-element-context) t
)))
1744 (mapcar (lambda (p) (org-element-property p ts
))
1745 '(:year-end
:month-end
:day-end
))))))
1746 ;; Extract range end (inactive)
1749 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1750 (let ((ts (org-timestamp-split-range
1751 (org-element-context) t
)))
1752 (mapcar (lambda (p) (org-element-property p ts
))
1753 '(:year-end
:month-end
:day-end
))))))
1754 ;; Return the timestamp if not a range.
1756 (org-test-with-temp-text "[2012-03-29 Thu]"
1757 (let* ((ts-orig (org-element-context))
1758 (ts-copy (org-timestamp-split-range ts-orig
)))
1759 (eq ts-orig ts-copy
))))
1761 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1762 (let* ((ts-orig (org-element-context))
1763 (ts-copy (org-timestamp-split-range ts-orig
)))
1764 (eq ts-orig ts-copy
))))
1765 ;; Check that parent is the same when a range was split.
1767 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1768 (let* ((ts-orig (org-element-context))
1769 (ts-copy (org-timestamp-split-range ts-orig
)))
1770 (eq (org-element-property :parent ts-orig
)
1771 (org-element-property :parent ts-copy
))))))
1773 (ert-deftest test-org
/timestamp-translate
()
1774 "Test `org-timestamp-translate' specifications."
1775 ;; Translate whole date range.
1778 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1779 (let ((org-display-custom-times t
)
1780 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1781 (org-timestamp-translate (org-element-context))))))
1782 ;; Translate date range start.
1785 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1786 (let ((org-display-custom-times t
)
1787 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1788 (org-timestamp-translate (org-element-context) 'start
)))))
1789 ;; Translate date range end.
1792 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1793 (let ((org-display-custom-times t
)
1794 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1795 (org-timestamp-translate (org-element-context) 'end
)))))
1796 ;; Translate time range.
1799 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
1800 (let ((org-display-custom-times t
)
1801 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
1802 (org-timestamp-translate (org-element-context))))))
1803 ;; Translate non-range timestamp.
1806 (org-test-with-temp-text "<2012-03-29 Thu>"
1807 (let ((org-display-custom-times t
)
1808 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1809 (org-timestamp-translate (org-element-context))))))
1810 ;; Do not change `diary' timestamps.
1812 (equal "<%%(org-float t 4 2)>"
1813 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1814 (let ((org-display-custom-times t
)
1815 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
1816 (org-timestamp-translate (org-element-context)))))))
1822 (ert-deftest test-org
/update-radio-target-regexp
()
1823 "Test `org-update-radio-target-regexp' specifications."
1824 ;; Properly update cache with no previous radio target regexp.
1827 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
1828 (save-excursion (goto-char (point-max)) (org-element-context))
1830 (search-forward "o")
1832 (org-update-radio-target-regexp)
1833 (goto-char (point-max))
1834 (org-element-type (org-element-context)))))
1835 ;; Properly update cache with previous radio target regexp.
1838 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
1839 (save-excursion (goto-char (point-max)) (org-element-context))
1841 (search-forward "o")
1843 (org-update-radio-target-regexp)
1844 (search-backward "r")
1847 (org-update-radio-target-regexp)
1848 (goto-char (point-max))
1849 (delete-region (line-beginning-position) (point))
1851 (org-element-type (org-element-context))))))
1857 (ert-deftest test-org
/flag-drawer
()
1858 "Test `org-flag-drawer' specifications."
1861 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
1863 (get-char-property (line-end-position) 'invisible
)))
1866 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
1868 (org-flag-drawer nil
)
1869 (get-char-property (line-end-position) 'invisible
)))
1870 ;; Test optional argument.
1872 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
1873 (let ((drawer (save-excursion (search-forward ":D2")
1874 (org-element-at-point))))
1875 (org-flag-drawer t drawer
)
1876 (get-char-property (progn (search-forward ":D2") (line-end-position))
1879 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
1880 (let ((drawer (save-excursion (search-forward ":D2")
1881 (org-element-at-point))))
1882 (org-flag-drawer t drawer
)
1883 (get-char-property (line-end-position) 'invisible
))))
1884 ;; Do not hide fake drawers.
1886 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
1889 (get-char-property (line-end-position) 'invisible
)))
1890 ;; Do not hide incomplete drawers.
1892 (org-test-with-temp-text ":D:\nparagraph"
1895 (get-char-property (line-end-position) 'invisible
)))
1896 ;; Do not hide drawers when called from final blank lines.
1898 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
1899 (goto-char (point-max))
1901 (goto-char (point-min))
1902 (get-char-property (line-end-position) 'invisible
)))
1903 ;; Don't leave point in an invisible part of the buffer when hiding
1906 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
1907 (goto-char (point-max))
1909 (get-char-property (point) 'invisible
))))
1911 (ert-deftest test-org
/hide-block-toggle
()
1912 "Test `org-hide-block-toggle' specifications."
1913 ;; Error when not at a block.
1915 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
1916 (org-hide-block-toggle 'off
)
1917 (get-char-property (line-end-position) 'invisible
)))
1920 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
1921 (org-hide-block-toggle)
1922 (get-char-property (line-end-position) 'invisible
)))
1924 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
1925 (org-hide-block-toggle)
1926 (get-char-property (line-end-position) 'invisible
)))
1927 ;; Show block unconditionally when optional argument is `off'.
1929 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
1930 (org-hide-block-toggle)
1931 (org-hide-block-toggle 'off
)
1932 (get-char-property (line-end-position) 'invisible
)))
1934 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
1935 (org-hide-block-toggle 'off
)
1936 (get-char-property (line-end-position) 'invisible
)))
1937 ;; Hide block unconditionally when optional argument is non-nil.
1939 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
1940 (org-hide-block-toggle t
)
1941 (get-char-property (line-end-position) 'invisible
)))
1943 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
1944 (org-hide-block-toggle)
1945 (org-hide-block-toggle t
)
1946 (get-char-property (line-end-position) 'invisible
)))
1947 ;; Do not hide block when called from final blank lines.
1949 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
1950 (org-hide-block-toggle)
1951 (goto-char (point-min))
1952 (get-char-property (line-end-position) 'invisible
)))
1953 ;; Don't leave point in an invisible part of the buffer when hiding
1956 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
1957 (org-hide-block-toggle)
1958 (get-char-property (point) 'invisible
))))
1960 (ert-deftest test-org
/hide-block-toggle-maybe
()
1961 "Test `org-hide-block-toggle-maybe' specifications."
1963 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
1964 (org-hide-block-toggle-maybe)))
1966 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
1971 ;;; test-org.el ends here