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"))))
195 ;; Relative date applied to current time if there is single
196 ;; plus/minus, or to default date when there are two of them.
200 (flet ((current-time () (apply #'encode-time
201 (org-parse-time-string "2014-03-04"))))
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (flet ((current-time () (apply #'encode-time
209 (org-parse-time-string "2014-03-04"))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (flet ((current-time () (apply #'encode-time
220 (org-parse-time-string "2014-03-04"))))
221 (let ((org-read-date-prefer-future t
))
222 (org-read-date t nil
"1")))))
226 (flet ((current-time () (apply #'encode-time
227 (org-parse-time-string "2012-03-29"))))
228 (let ((org-read-date-prefer-future t
))
229 (org-read-date t nil
"3-4")))))
233 (flet ((current-time () (apply #'encode-time
234 (org-parse-time-string "2012-03-29"))))
235 (let ((org-read-date-prefer-future nil
))
236 (org-read-date t nil
"3-4")))))
237 ;; When set to `org-read-date-prefer-future' is set to `time', read
238 ;; day is moved to tomorrow if specified hour is before current
239 ;; time. However, it only happens in no other part of the date is
244 (flet ((current-time () (apply #'encode-time
245 (org-parse-time-string "2012-03-29 16:40"))))
246 (let ((org-read-date-prefer-future 'time
))
247 (org-read-date t nil
"00:40" nil
)))))
251 (flet ((current-time () (apply #'encode-time
252 (org-parse-time-string "2012-03-29 16:40"))))
253 (let ((org-read-date-prefer-future 'time
))
254 (org-read-date t nil
"29 00:40" nil
)))))
255 ;; Caveat: `org-read-date-prefer-future' always refers to current
256 ;; time, not default time, when they differ.
261 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
262 (let ((org-read-date-prefer-future t
))
265 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
270 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
271 (let ((org-read-date-prefer-future t
))
274 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
276 (ert-deftest test-org
/org-parse-time-string
()
277 "Test `org-parse-time-string'."
278 (should (equal (org-parse-time-string "2012-03-29 16:40")
279 '(0 40 16 29 3 2012 nil nil nil
)))
280 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
281 '(0 40 16 29 3 2012 nil nil nil
)))
282 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
283 '(0 40 16 29 3 2012 nil nil nil
)))
284 (should (equal (org-parse-time-string "<2012-03-29>")
285 '(0 0 0 29 3 2012 nil nil nil
)))
286 (should (equal (org-parse-time-string "<2012-03-29>" t
)
287 '(0 nil nil
29 3 2012 nil nil nil
))))
289 (ert-deftest test-org
/closest-date
()
290 "Test `org-closest-date' specifications."
292 ;; Time stamps without a repeater are returned unchanged.
296 (calendar-gregorian-from-absolute
297 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
298 ;; Time stamps with a null repeater are returned unchanged.
302 (calendar-gregorian-from-absolute
303 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
304 ;; if PREFER is set to `past' always return a date before, or equal
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
314 (calendar-gregorian-from-absolute
315 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
316 ;; if PREFER is set to `future' always return a date before, or equal
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
326 (calendar-gregorian-from-absolute
327 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
328 ;; If PREFER is neither `past' nor `future', select closest date.
332 (calendar-gregorian-from-absolute
333 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
337 (calendar-gregorian-from-absolute
338 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
339 ;; Test "day" repeater.
342 (calendar-gregorian-from-absolute
343 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
346 (calendar-gregorian-from-absolute
347 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
348 ;; Test "month" repeater.
351 (calendar-gregorian-from-absolute
352 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
355 (calendar-gregorian-from-absolute
356 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
357 ;; Test "year" repeater.
360 (calendar-gregorian-from-absolute
361 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
364 (calendar-gregorian-from-absolute
365 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
370 (ert-deftest test-org
/insert-property-drawer
()
371 "Test `org-insert-property-drawer' specifications."
372 ;; Error before first headline.
373 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
374 ;; Insert drawer right after headline if there is no planning line,
375 ;; or after it otherwise.
377 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
378 (org-test-with-temp-text "* H\nParagraph<point>"
379 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
382 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
383 (org-test-with-temp-text
384 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
385 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
387 ;; Indent inserted drawer.
389 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
390 (org-test-with-temp-text "* H\nParagraph<point>"
391 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
393 ;; Handle insertion at eob.
395 (equal "* H\n:PROPERTIES:\n:END:\n"
396 (org-test-with-temp-text "* H"
397 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
399 ;; Skip inlinetasks before point.
400 (when (featurep 'org-inlinetask
)
402 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
403 (org-test-with-temp-text
404 "* H\n*************** I\n*************** END\nP<point>"
405 (let ((org-adapt-indentation nil
)
406 (org-inlinetask-min-level 15))
407 (org-insert-property-drawer))
409 ;; Correctly set drawer in an inlinetask.
410 (when (featurep 'org-inlinetask
)
412 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
413 (org-test-with-temp-text
414 "* H\n*************** I\nP<point>\n*************** END"
415 (let ((org-adapt-indentation nil
)
416 (org-inlinetask-min-level 15))
417 (org-insert-property-drawer))
423 (ert-deftest test-org
/fill-paragraph
()
424 "Test `org-fill-paragraph' specifications."
425 ;; At an Org table, align it.
428 (org-test-with-temp-text "|a|"
432 (equal "#+name: table\n| a |\n"
433 (org-test-with-temp-text "#+name: table\n| a |\n"
436 ;; At a paragraph, preserve line breaks.
437 (org-test-with-temp-text "some \\\\\nlong\ntext"
438 (let ((fill-column 20))
440 (should (equal (buffer-string) "some \\\\\nlong text"))))
441 ;; Correctly fill a paragraph when point is at its very end.
444 (org-test-with-temp-text "A\nB"
445 (let ((fill-column 20))
446 (goto-char (point-max))
449 ;; Correctly fill the last paragraph of a greater element.
451 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
452 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
453 (let ((fill-column 8))
458 ;; Correctly fill an element in a narrowed buffer.
461 (org-test-with-temp-text "01234 6789"
462 (let ((fill-column 5))
463 (narrow-to-region 1 8)
466 ;; Handle `adaptive-fill-regexp' in paragraphs.
469 (org-test-with-temp-text "> a\n> b"
470 (let ((fill-column 5)
471 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
474 ;; Special case: Fill first paragraph when point is at an item or
475 ;; a plain-list or a footnote reference.
478 (org-test-with-temp-text "- A\n B"
479 (let ((fill-column 20))
484 (org-test-with-temp-text "[fn:1] A\nB"
485 (let ((fill-column 20))
488 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
489 (let ((fill-column 20))
491 (should (equal (buffer-string)
492 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
493 ;; Fill contents of `comment-block' elements.
496 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
497 (let ((fill-column 20))
501 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
502 ;; Fill `comment' elements.
505 (org-test-with-temp-text " # A\n # B"
506 (let ((fill-column 20))
509 ;; Do not mix consecutive comments when filling one of them.
511 (equal "# A B\n\n# C"
512 (org-test-with-temp-text "# A\n# B\n\n# C"
513 (let ((fill-column 20))
516 ;; Use commented empty lines as separators when filling comments.
518 (equal "# A B\n#\n# C"
519 (org-test-with-temp-text "# A\n# B\n#\n# C"
520 (let ((fill-column 20))
523 ;; Handle `adaptive-fill-regexp' in comments.
526 (org-test-with-temp-text "# > a\n# > b"
527 (let ((fill-column 20)
528 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
531 ;; Do nothing at affiliated keywords.
532 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
533 (let ((fill-column 20))
535 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
536 ;; Do not move point after table when filling a table.
538 (org-test-with-temp-text "| a | b |\n| c | d |\n"
543 (ert-deftest test-org
/auto-fill-function
()
544 "Test auto-filling features."
545 ;; Auto fill paragraph.
548 (org-test-with-temp-text "12345 7890"
549 (let ((fill-column 5))
551 (org-auto-fill-function)
553 ;; Auto fill first paragraph in an item.
555 (equal "- 12345\n 7890"
556 (org-test-with-temp-text "- 12345 7890"
557 (let ((fill-column 7))
559 (org-auto-fill-function)
561 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
563 (equal "> 12345\n 7890"
564 (org-test-with-temp-text "> 12345 7890"
565 (let ((fill-column 10)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
567 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
569 (org-auto-fill-function)
572 (equal "> 12345\n> 12345\n> 7890"
573 (org-test-with-temp-text "> 12345\n> 12345 7890"
574 (let ((fill-column 10)
575 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
576 (goto-char (point-max))
577 (org-auto-fill-function)
580 (equal " 12345\n *12345\n *12345"
581 (org-test-with-temp-text " 12345\n *12345 12345"
582 (let ((fill-column 10)
583 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
584 (goto-char (point-max))
585 (org-auto-fill-function)
587 ;; Auto fill comments.
589 (equal " # 12345\n # 7890"
590 (org-test-with-temp-text " # 12345 7890"
591 (let ((fill-column 10))
593 (org-auto-fill-function)
595 ;; A hash within a line isn't a comment.
597 (equal "12345 # 7890\n# 1"
598 (org-test-with-temp-text "12345 # 7890 1"
599 (let ((fill-column 12))
601 (org-auto-fill-function)
603 ;; Correctly interpret empty prefix.
605 (equal "# a\n# b\nRegular\n# paragraph"
606 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
607 (let ((fill-column 12))
609 (org-auto-fill-function)
611 ;; Comment block: auto fill contents.
613 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
614 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
615 (let ((fill-column 5))
618 (org-auto-fill-function)
621 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
622 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
623 (let ((fill-column 5))
626 (org-auto-fill-function)
628 ;; Do not fill if a new item could be created.
631 (org-test-with-temp-text "12345 - 90"
632 (let ((fill-column 5))
634 (org-auto-fill-function)
636 ;; Do not fill if a line break could be introduced.
638 (equal "123\\\\\n7890"
639 (org-test-with-temp-text "123\\\\ 7890"
640 (let ((fill-column 6))
642 (org-auto-fill-function)
644 ;; Do not fill affiliated keywords.
646 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
647 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
648 (let ((fill-column 20))
650 (org-auto-fill-function)
657 (ert-deftest test-org
/indent-line
()
658 "Test `org-indent-line' specifications."
659 ;; Do not indent diary sexps, footnote definitions or headlines.
662 (org-test-with-temp-text "%%(org-calendar-holiday)"
664 (org-get-indentation))))
667 (org-test-with-temp-text "[fn:1] fn"
668 (let ((org-adapt-indentation t
)) (org-indent-line))
669 (org-get-indentation))))
672 (org-test-with-temp-text "* H"
674 (org-get-indentation))))
675 ;; Do not indent before first headline.
678 (org-test-with-temp-text ""
680 (org-get-indentation))))
681 ;; Indent according to headline level otherwise, unless
682 ;; `org-adapt-indentation' is nil.
685 (org-test-with-temp-text "* H\nA"
687 (let ((org-adapt-indentation t
)) (org-indent-line))
688 (org-get-indentation))))
691 (org-test-with-temp-text "* H\n\nA"
693 (let ((org-adapt-indentation t
)) (org-indent-line))
694 (org-get-indentation))))
697 (org-test-with-temp-text "* H\nA"
699 (let ((org-adapt-indentation nil
)) (org-indent-line))
700 (org-get-indentation))))
701 ;; Indenting preserves point position.
703 (org-test-with-temp-text "* H\nAB"
706 (let ((org-adapt-indentation t
)) (org-indent-line))
708 ;; Do not change indentation at an item.
711 (org-test-with-temp-text "* H\n - A"
713 (let ((org-adapt-indentation t
)) (org-indent-line))
714 (org-get-indentation))))
715 ;; On blank lines at the end of a list, indent like last element
716 ;; within it if the line is still in the list. If the last element
717 ;; is an item, indent like its contents. Otherwise, indent like the
721 (org-test-with-temp-text "* H\n- A\n - AA\n"
722 (goto-char (point-max))
723 (let ((org-adapt-indentation t
)) (org-indent-line))
724 (org-get-indentation))))
727 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
728 (goto-char (point-max))
729 (let ((org-adapt-indentation t
)) (org-indent-line))
730 (org-get-indentation))))
733 (org-test-with-temp-text "* H\n- A\n - \n"
734 (goto-char (point-max))
735 (let ((org-adapt-indentation t
)) (org-indent-line))
736 (org-get-indentation))))
737 ;; Likewise, on a blank line at the end of a footnote definition,
738 ;; indent at column 0 if line belongs to the definition. Otherwise,
739 ;; indent like the definition itself.
742 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
743 (goto-char (point-max))
744 (let ((org-adapt-indentation t
)) (org-indent-line))
745 (org-get-indentation))))
748 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
749 (goto-char (point-max))
750 (let ((org-adapt-indentation t
)) (org-indent-line))
751 (org-get-indentation))))
752 ;; After the end of the contents of a greater element, indent like
753 ;; the beginning of the element.
756 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
759 (org-get-indentation))))
760 ;; On blank lines after a paragraph, indent like its last non-empty
764 (org-test-with-temp-text " Paragraph\n\n<point>"
766 (org-get-indentation))))
767 ;; At the first line of an element, indent like previous element's
768 ;; first line, ignoring footnotes definitions and inline tasks, or
769 ;; according to parent.
772 (org-test-with-temp-text "A\n\n B\n\nC"
773 (goto-char (point-max))
775 (org-get-indentation))))
778 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
779 (goto-char (point-max))
781 (org-get-indentation))))
784 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
787 (org-get-indentation))))
788 ;; Within code part of a source block, use language major mode if
789 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
790 ;; according to line above.
793 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
795 (let ((org-src-tab-acts-natively t
)
796 (org-edit-src-content-indentation 0))
798 (org-get-indentation))))
801 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
803 (let ((org-src-tab-acts-natively nil
)
804 (org-edit-src-content-indentation 0))
806 (org-get-indentation))))
807 ;; Otherwise, indent like the first non-blank line above.
810 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
813 (org-get-indentation))))
814 ;; Align node properties according to `org-property-format'. Handle
815 ;; nicely empty values.
817 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
818 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
819 (let ((org-property-format "%-10s %s")) (org-indent-line))
822 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
823 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
824 (let ((org-property-format "%-10s %s")) (org-indent-line))
827 (ert-deftest test-org
/indent-region
()
828 "Test `org-indent-region' specifications."
832 (org-test-with-temp-text " A\nB\n C"
833 (org-indent-region (point-min) (point-max))
835 ;; Indent greater elements along with their contents.
837 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
838 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
839 (org-indent-region (point-min) (point-max))
841 ;; Ignore contents of verse blocks and example blocks.
843 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
844 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
845 (org-indent-region (point-min) (point-max))
848 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
849 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
850 (org-indent-region (point-min) (point-max))
852 ;; Indent according to mode if `org-src-tab-acts-natively' is
853 ;; non-nil. Otherwise, do not indent code at all.
855 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
856 (org-test-with-temp-text
857 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
858 (let ((org-src-tab-acts-natively t
)
859 (org-edit-src-content-indentation 0))
860 (org-indent-region (point-min) (point-max)))
863 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
864 (org-test-with-temp-text
865 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
866 (let ((org-src-tab-acts-natively nil
)
867 (org-edit-src-content-indentation 0))
868 (org-indent-region (point-min) (point-max)))
870 ;; Align node properties according to `org-property-format'. Handle
871 ;; nicely empty values.
873 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
874 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
875 (let ((org-property-format "%-10s %s")
876 (org-adapt-indentation nil
))
877 (org-indent-region (point) (point-max)))
880 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
881 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
882 (let ((org-property-format "%-10s %s")
883 (org-adapt-indentation nil
))
884 (org-indent-region (point) (point-max)))
886 ;; Indent plain lists.
888 (equal "- A\n B\n - C\n\n D"
889 (org-test-with-temp-text "- A\n B\n - C\n\n D"
890 (org-indent-region (point-min) (point-max))
894 (org-test-with-temp-text " - A\n\n - B"
895 (org-indent-region (point-min) (point-max))
897 ;; Indent footnote definitions.
899 (equal "[fn:1] Definition\n\nDefinition"
900 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
901 (org-indent-region (point-min) (point-max))
903 ;; Special case: Start indenting on a blank line.
906 (org-test-with-temp-text "\n Paragraph"
907 (org-indent-region (point-min) (point-max))
914 (ert-deftest test-org
/delete-indentation
()
915 "Test `org-delete-indentation' specifications."
917 (should (equal "foo bar"
918 (org-test-with-temp-text
920 (org-delete-indentation)
922 ;; With optional argument.
923 (should (equal "foo bar"
924 (org-test-with-temp-text
926 (org-delete-indentation t
)
928 ;; At headline text should be appended to the headline text.
930 (equal"* foo bar :tag:"
931 (let (org-auto-align-tags)
932 (org-test-with-temp-text
933 "* foo :tag:\n bar<point>"
934 (org-delete-indentation)
937 (equal "* foo bar :tag:"
938 (let (org-auto-align-tags)
939 (org-test-with-temp-text
940 "* foo <point>:tag:\n bar"
941 (org-delete-indentation t
)
944 (ert-deftest test-org
/return
()
945 "Test `org-return' specifications."
949 (org-test-with-temp-text "Para<point>graph"
952 ;; With optional argument, indent line.
954 (equal " Para\n graph"
955 (org-test-with-temp-text " Para<point>graph"
958 ;; On a table, call `org-table-next-row'.
960 (org-test-with-temp-text "| <point>a |\n| b |"
962 (org-looking-at-p "b")))
963 ;; Open link or timestamp under point when `org-return-follows-link'
966 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
967 (let ((org-return-follows-link t
)
968 (org-link-search-must-match-exact-headline nil
))
970 (org-looking-at-p "<<target>>")))
972 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
973 (let ((org-return-follows-link nil
)) (org-return))
974 (org-looking-at-p "<<target>>")))
976 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
977 (let ((org-return-follows-link t
)) (org-return))
978 (org-looking-at-p "* b")))
980 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
981 (let ((org-return-follows-link t
)
982 (org-link-search-must-match-exact-headline nil
))
984 (org-looking-at-p "<<target>>")))
986 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
987 (let ((org-return-follows-link t
)
988 (org-link-search-must-match-exact-headline nil
))
990 (org-looking-at-p "<<target>>")))
991 ;; When `org-return-follows-link' is non-nil, tolerate links and
992 ;; timestamps in comments, node properties, etc.
994 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
995 (let ((org-return-follows-link t
)
996 (org-link-search-must-match-exact-headline nil
))
998 (org-looking-at-p "<<target>>")))
1000 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1001 (let ((org-return-follows-link nil
)) (org-return))
1002 (org-looking-at-p "<<target>>")))
1004 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1005 (let ((org-return-follows-link t
)
1006 (org-link-search-must-match-exact-headline nil
))
1008 (org-looking-at-p "<<target>>")))
1009 ;; However, do not open link when point is in a table.
1011 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1012 (let ((org-return-follows-link t
)) (org-return))
1013 (org-looking-at-p "between")))
1014 ;; Special case: in a list, when indenting, do not break structure.
1017 (org-test-with-temp-text "- A <point>B"
1022 (org-test-with-temp-text "- A\n<point>- B"
1025 ;; On tags part of a headline, add a newline below it instead of
1028 (equal "* H :tag:\n"
1029 (org-test-with-temp-text "* H :<point>tag:"
1032 ;; Before headline text, add a newline below it instead of breaking
1035 (equal "* TODO H :tag:\n"
1036 (org-test-with-temp-text "* <point>TODO H :tag:"
1040 (equal "* TODO [#B] H :tag:\n"
1041 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1044 ;; At headline text, break headline text but preserve tags.
1046 (equal "* TODO [#B] foo :tag:\nbar"
1047 (let (org-auto-align-tags)
1048 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1051 ;; At bol of headline insert newline.
1054 (org-test-with-temp-text "<point>* h"
1057 ;; Refuse to leave invalid headline in buffer.
1060 (org-test-with-temp-text "*<point> h"
1064 (ert-deftest test-org
/meta-return
()
1065 "Test M-RET (`org-meta-return') specifications."
1066 ;; In a table field insert a row above.
1068 (org-test-with-temp-text "| a |"
1072 (looking-at "| |$")))
1073 ;; In a paragraph change current line into a header.
1075 (org-test-with-temp-text "a"
1078 (looking-at "\* a$")))
1079 ;; In an item insert an item, in this case above.
1081 (org-test-with-temp-text "- a"
1084 (looking-at "- $")))
1085 ;; In a drawer and item insert an item, in this case above.
1087 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1091 (looking-at "- $"))))
1093 (ert-deftest test-org
/insert-heading
()
1094 "Test `org-insert-heading' specifications."
1095 ;; In an empty buffer, insert a new headline.
1098 (org-test-with-temp-text ""
1099 (org-insert-heading)
1101 ;; At the beginning of a line, turn it into a headline
1104 (org-test-with-temp-text "<point>P"
1105 (org-insert-heading)
1107 ;; In the middle of a line, split the line if allowed, otherwise,
1108 ;; insert the headline at its end.
1110 (equal "Para\n* graph"
1111 (org-test-with-temp-text "Para<point>graph"
1112 (let ((org-M-RET-may-split-line '((default . t
))))
1113 (org-insert-heading))
1116 (equal "Paragraph\n* "
1117 (org-test-with-temp-text "Para<point>graph"
1118 (let ((org-M-RET-may-split-line '((default . nil
))))
1119 (org-insert-heading))
1121 ;; When on a list, insert an item instead, unless called with an
1122 ;; universal argument or if list is invisible. In this case, create
1123 ;; a new headline after contents.
1125 (equal "* H\n- item\n- "
1126 (org-test-with-temp-text "* H\n- item<point>"
1127 (let ((org-insert-heading-respect-content nil
))
1128 (org-insert-heading))
1131 (equal "* H\n- item\n- item 2\n* "
1132 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1133 (let ((org-insert-heading-respect-content nil
))
1134 (org-insert-heading '(4)))
1137 (equal "* H\n- item\n* "
1138 (org-test-with-temp-text "* H\n- item"
1140 (goto-char (point-max))
1141 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1143 ;; When called with two universal arguments, insert a new headline
1144 ;; at the end of the grandparent subtree.
1146 (equal "* H1\n** H3\n- item\n** H2\n** "
1147 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1148 (let ((org-insert-heading-respect-content nil
))
1149 (org-insert-heading '(16)))
1151 ;; When optional TOP-LEVEL argument is non-nil, always insert
1152 ;; a level 1 heading.
1154 (equal "* H1\n** H2\n* "
1155 (org-test-with-temp-text "* H1\n** H2<point>"
1156 (org-insert-heading nil nil t
)
1159 (equal "* H1\n- item\n* "
1160 (org-test-with-temp-text "* H1\n- item<point>"
1161 (org-insert-heading nil nil t
)
1163 ;; Corner case: correctly insert a headline after an empty one.
1166 (org-test-with-temp-text "* <point>"
1167 (org-insert-heading)
1170 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1171 "Test `org-insert-todo-heading-respect-content' specifications."
1172 ;; Create a TODO heading.
1174 (org-test-with-temp-text "* H1\n Body"
1175 (org-insert-todo-heading-respect-content)
1176 (nth 2 (org-heading-components))))
1177 ;; Add headline at the end of the first subtree
1179 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1180 (search-forward "H1Body")
1181 (org-insert-todo-heading-respect-content)
1182 (and (eobp) (org-at-heading-p))))
1183 ;; In a list, do not create a new item.
1185 (org-test-with-temp-text "* H\n- an item\n- another one"
1186 (search-forward "an ")
1187 (org-insert-todo-heading-respect-content)
1188 (and (eobp) (org-at-heading-p)))))
1190 (ert-deftest test-org
/clone-with-time-shift
()
1191 "Test `org-clone-subtree-with-time-shift'."
1192 ;; Clone non-repeating once.
1198 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1199 (org-clone-subtree-with-time-shift 1 "+2d")
1200 (replace-regexp-in-string
1201 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1203 ;; Clone repeating once.
1208 * H1\n<2015-06-25 +1w>
1210 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1211 (org-clone-subtree-with-time-shift 1 "+2d")
1212 (replace-regexp-in-string
1213 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1215 ;; Clone non-repeating zero times.
1220 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1221 (org-clone-subtree-with-time-shift 0 "+2d")
1222 (replace-regexp-in-string
1223 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1225 ;; Clone repeating "zero" times.
1229 * H1\n<2015-06-23 +1w>
1231 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1232 (org-clone-subtree-with-time-shift 0 "+2d")
1233 (replace-regexp-in-string
1234 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1238 ;;; Fixed-Width Areas
1240 (ert-deftest test-org
/toggle-fixed-width
()
1241 "Test `org-toggle-fixed-width' specifications."
1242 ;; No region: Toggle on fixed-width marker in paragraphs.
1245 (org-test-with-temp-text "A"
1246 (org-toggle-fixed-width)
1248 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1251 (org-test-with-temp-text ": A"
1252 (org-toggle-fixed-width)
1254 ;; No region: Toggle on marker in blank lines after elements or just
1255 ;; after a headline.
1258 (org-test-with-temp-text "* H\n"
1260 (org-toggle-fixed-width)
1263 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1264 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1265 (goto-char (point-max))
1266 (org-toggle-fixed-width)
1268 ;; No region: Toggle on marker in front of one line elements (e.g.,
1269 ;; headlines, clocks)
1271 (equal ": * Headline"
1272 (org-test-with-temp-text "* Headline"
1273 (org-toggle-fixed-width)
1276 (equal ": #+KEYWORD: value"
1277 (org-test-with-temp-text "#+KEYWORD: value"
1278 (org-toggle-fixed-width)
1280 ;; No region: error in other situations.
1282 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1284 (org-toggle-fixed-width)
1286 ;; No region: Indentation is preserved.
1289 (org-test-with-temp-text "- A\n B"
1291 (org-toggle-fixed-width)
1293 ;; Region: If it contains only fixed-width elements and blank lines,
1294 ;; toggle off fixed-width markup.
1297 (org-test-with-temp-text ": A\n\n: B"
1298 (transient-mark-mode 1)
1299 (push-mark (point) t t
)
1300 (goto-char (point-max))
1301 (org-toggle-fixed-width)
1303 ;; Region: If it contains anything else, toggle on fixed-width but
1304 ;; not on fixed-width areas.
1306 (equal ": A\n: \n: B\n: \n: C"
1307 (org-test-with-temp-text "A\n\n: B\n\nC"
1308 (transient-mark-mode 1)
1309 (push-mark (point) t t
)
1310 (goto-char (point-max))
1311 (org-toggle-fixed-width)
1313 ;; Region: Ignore blank lines at its end, unless it contains only
1317 (org-test-with-temp-text "A\n\n"
1318 (transient-mark-mode 1)
1319 (push-mark (point) t t
)
1320 (goto-char (point-max))
1321 (org-toggle-fixed-width)
1325 (org-test-with-temp-text "\n\n"
1326 (transient-mark-mode 1)
1327 (push-mark (point) t t
)
1328 (goto-char (point-max))
1329 (org-toggle-fixed-width)
1336 (ert-deftest test-org
/in-commented-heading-p
()
1337 "Test `org-in-commented-heading-p' specifications."
1338 ;; Commented headline.
1340 (org-test-with-temp-text "* COMMENT Headline\nBody"
1341 (goto-char (point-max))
1342 (org-in-commented-heading-p)))
1343 ;; Commented ancestor.
1345 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1346 (goto-char (point-max))
1347 (org-in-commented-heading-p)))
1348 ;; Comment keyword is case-sensitive.
1350 (org-test-with-temp-text "* Comment Headline\nBody"
1351 (goto-char (point-max))
1352 (org-in-commented-heading-p)))
1353 ;; Keyword is standalone.
1355 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1356 (goto-char (point-max))
1357 (org-in-commented-heading-p)))
1358 ;; Optional argument.
1360 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1361 (goto-char (point-max))
1362 (org-in-commented-heading-p t
))))
1364 (ert-deftest test-org
/entry-blocked-p
()
1365 ;; Check other dependencies.
1367 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1368 (let ((org-enforce-todo-dependencies t
)
1370 '(org-block-todo-from-children-or-siblings-or-parent)))
1371 (org-entry-blocked-p))))
1373 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1374 (let ((org-enforce-todo-dependencies t
)
1376 '(org-block-todo-from-children-or-siblings-or-parent)))
1377 (org-entry-blocked-p))))
1378 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1381 (org-test-with-temp-text "* Blocked\n** TODO one"
1382 (let ((org-enforce-todo-dependencies t
)
1384 '(org-block-todo-from-children-or-siblings-or-parent)))
1385 (org-entry-blocked-p))))
1387 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1388 (let ((org-enforce-todo-dependencies t
)
1390 '(org-block-todo-from-children-or-siblings-or-parent)))
1391 (org-entry-blocked-p))))
1392 ;; Follow :ORDERED: specifications.
1394 (org-test-with-temp-text
1395 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1396 (let ((org-enforce-todo-dependencies t
)
1398 '(org-block-todo-from-children-or-siblings-or-parent)))
1399 (org-entry-blocked-p))))
1401 (org-test-with-temp-text
1402 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1403 (let ((org-enforce-todo-dependencies t
)
1405 '(org-block-todo-from-children-or-siblings-or-parent)))
1406 (org-entry-blocked-p)))))
1408 (ert-deftest test-org
/format-outline-path
()
1410 (string= (org-format-outline-path (list "one" "two" "three"))
1414 (string= (org-format-outline-path '())
1417 (string= (org-format-outline-path '(nil))
1419 ;; Empty path and prefix.
1421 (string= (org-format-outline-path '() nil
">>")
1423 ;; Trailing whitespace in headings.
1425 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1427 ;; Non-default prefix and separators.
1429 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1430 ">>|one|two|three"))
1433 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1435 ;; Give a very narrow width.
1437 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1439 ;; Give a prefix that extends beyond the width.
1441 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1445 (ert-deftest test-org
/map-entries
()
1446 "Test `org-map-entries' specifications."
1450 (org-test-with-temp-text "* Level 1\n** Level 2"
1451 (org-map-entries #'point
))))
1455 (org-test-with-temp-text "* Level 1\n** Level 2"
1456 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1459 (org-test-with-temp-text "* Level 1\n** Level 2"
1460 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1464 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1465 (org-map-entries #'point
"yes"))))
1468 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1469 (org-map-entries #'point
"+yes-a"))))
1472 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1473 (org-map-entries #'point
"{yes?}"))))
1477 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1478 (org-map-entries #'point
"PRIORITY=\"A\""))))
1482 (org-test-with-temp-text "
1484 SCHEDULED: <2012-03-29 thu.>
1486 SCHEDULED: <2014-03-04 tue.>"
1487 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1490 (org-test-with-temp-text "
1492 SCHEDULED: <2012-03-29 thu.>
1494 SCHEDULED: <2014-03-04 tue.>"
1495 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1496 ;; Regular property match.
1499 (org-test-with-temp-text "
1508 (org-map-entries #'point
"TEST=1"))))
1509 ;; Multiple criteria.
1512 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1513 (let (org-odd-levels-only
1514 (org-use-tag-inheritance nil
))
1515 (org-map-entries #'point
"yes+LEVEL=1")))))
1519 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1520 (let (org-odd-levels-only)
1521 (org-map-entries #'point
"LEVEL=2|no")))))
1524 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1525 (let (org-odd-levels-only)
1526 (org-map-entries #'point
"yes|no")))))
1530 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1531 (let (org-odd-levels-only)
1532 (org-map-entries #'point
"yes&no"))))))
1538 (ert-deftest test-org
/set-regexps-and-options
()
1539 "Test `org-set-regexps-and-options' specifications."
1542 (equal '(("A" . ?a
) ("B") ("C"))
1543 (org-test-with-temp-text "#+TAGS: A(a) B C"
1547 (equal '(("A") (:newline
) ("B"))
1548 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1552 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1553 (org-test-with-temp-text "#+TAGS: { A B } C"
1557 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1558 (org-test-with-temp-text "#+TAGS: { A : B C }"
1562 (equal '(("A" "B" "C"))
1563 (org-test-with-temp-text "#+TAGS: { A : B C }"
1565 org-tag-groups-alist
)))
1567 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1568 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1572 (equal '(("A" "B" "C"))
1573 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1575 org-tag-groups-alist
)))
1576 ;; FILETAGS keyword.
1578 (equal '("A" "B" "C")
1579 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1582 ;; PROPERTY keyword. Property names are case-insensitive.
1585 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1587 (cdr (assoc "var" org-file-properties
)))))
1591 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1593 (cdr (assoc "var" org-file-properties
)))))
1597 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1599 (cdr (assoc "var" org-file-properties
)))))
1603 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1605 org-archive-location
)))
1606 ;; CATEGORY keyword.
1609 (org-test-with-temp-text "#+CATEGORY: test"
1614 (org-test-with-temp-text "#+CATEGORY: test"
1616 (cdr (assoc "CATEGORY" org-file-properties
)))))
1619 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1620 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1622 org-columns-default-format
)))
1623 ;; CONSTANTS keyword. Constants names are case sensitive.
1625 (equal '("299792458." "3.14")
1626 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1629 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1633 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1635 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1638 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1640 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1645 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1647 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1649 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1653 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1655 (list org-highest-priority org-lowest-priority org-default-priority
))))
1659 (org-test-with-temp-text "#+PRIORITIES: X Z"
1661 (list org-highest-priority org-lowest-priority org-default-priority
))))
1665 (org-test-with-temp-text "#+STARTUP: fold odd"
1667 (list org-startup-folded org-odd-levels-only
))))
1670 (equal '(("A" "B") ("C"))
1671 (org-test-with-temp-text "#+TODO: A B | C"
1673 (list org-not-done-keywords org-done-keywords
))))
1675 (equal '(("A" "C") ("B" "D"))
1676 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1678 (list org-not-done-keywords org-done-keywords
))))
1680 (equal '(("A" "B") ("C"))
1681 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1683 (list org-not-done-keywords org-done-keywords
))))
1685 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1686 (org-test-with-temp-text "#+TODO: A(a)"
1688 org-todo-key-alist
)))
1690 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1691 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1693 org-todo-log-states
)))
1694 ;; Enter SETUPFILE keyword.
1697 (org-test-with-temp-text
1698 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1700 (cdr (assoc "a" org-file-properties
))))))
1708 (ert-deftest test-org
/coderef
()
1709 "Test coderef links specifications."
1711 (org-test-with-temp-text "
1712 #+BEGIN_SRC emacs-lisp
1717 (looking-at "(ref:sc)")))
1718 ;; Find coderef even with alternate label format.
1720 (org-test-with-temp-text "
1721 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
1726 (looking-at "{ref:sc}"))))
1730 (ert-deftest test-org
/custom-id
()
1731 "Test custom ID links specifications."
1733 (org-test-with-temp-text
1734 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1736 (org-looking-at-p "\\* H1")))
1737 ;; Throw an error on false positives.
1739 (org-test-with-temp-text
1740 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1742 (org-looking-at-p "\\* H1"))))
1746 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1747 ;; a named element (#+name: text) and to headlines (* Text).
1749 (ert-deftest test-org
/fuzzy-links
()
1750 "Test fuzzy links specifications."
1751 ;; Fuzzy link goes in priority to a matching target.
1753 (org-test-with-temp-text
1754 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
1755 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1756 (looking-at "<<Test>>")))
1757 ;; Then fuzzy link points to an element with a given name.
1759 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
1760 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1761 (looking-at "#\\+NAME: Test")))
1762 ;; A target still lead to a matching headline otherwise.
1764 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
1765 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1766 (looking-at "\\* Head2")))
1767 ;; With a leading star in link, enforce heading match.
1769 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
1770 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1771 (looking-at "\\* Test")))
1772 ;; With a leading star in link, enforce exact heading match, even
1773 ;; with `org-link-search-must-match-exact-headline' set to nil.
1775 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1776 (let ((org-link-search-must-match-exact-headline nil
))
1777 (org-open-at-point))))
1778 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
1780 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
1781 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1782 (looking-at "\\* Test")))
1784 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
1785 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1786 (looking-at "\\* Test")))
1787 ;; Heading match should not care about spaces, cookies, TODO
1788 ;; keywords, priorities, and tags.
1791 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1792 (org-test-with-temp-text
1793 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1794 (let ((org-link-search-must-match-exact-headline nil
)
1795 (org-todo-regexp "TODO"))
1796 (org-open-at-point))
1797 (looking-at (regexp-quote first-line
)))))
1798 ;; Heading match should still be exact.
1801 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1802 (org-test-with-temp-text
1803 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1804 (let ((org-link-search-must-match-exact-headline nil
)
1805 (org-todo-regexp "TODO"))
1806 (org-open-at-point)))))
1807 ;; Heading match ignores COMMENT keyword.
1809 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1811 (looking-at "\\* COMMENT Test")))
1812 ;; Correctly un-hexify fuzzy links.
1814 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
1820 (ert-deftest test-org
/org-link-escape-ascii-character
()
1821 "Escape an ascii character."
1825 (org-link-escape "["))))
1827 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1828 "Escape an ascii control character."
1832 (org-link-escape "\t"))))
1834 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1835 "Escape an unicode multibyte character."
1839 (org-link-escape "€"))))
1841 (ert-deftest test-org
/org-link-escape-custom-table
()
1842 "Escape string with custom character table."
1846 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1848 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1849 "Escape string with custom table merged with default table."
1852 "%5BF%6F%6F%3A%42ar%0A%5D"
1853 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1855 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1856 "Unescape an ascii character."
1860 (org-link-unescape "%5B"))))
1862 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1863 "Unescpae an ascii control character."
1867 (org-link-unescape "%0A"))))
1869 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1870 "Unescape unicode multibyte character."
1874 (org-link-unescape "%E2%82%AC"))))
1876 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1877 "Unescape old style percent escaped character."
1880 "à âçèéêîôùû"
1881 (decode-coding-string
1882 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1884 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1885 "Escape and unescape a URL that includes an escaped char.
1886 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1889 "http://some.host.com/form?&id=blah%2Bblah25"
1891 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1893 (ert-deftest test-org
/org-link-escape-chars-browser
()
1894 "Test of the constant `org-link-escape-chars-browser'.
1895 See there why this test is a candidate to be removed once Org
1896 drops support for Emacs 24.1 and 24.2."
1899 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1900 "%22Release%208.2%22&idxname=emacs-orgmode")
1901 (org-link-escape-browser ; Do not replace with `url-encode-url',
1902 ; see docstring above.
1903 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1904 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1908 (ert-deftest test-org
/open-at-point-in-keyword
()
1909 "Does `org-open-at-point' open link in a keyword line?"
1911 (org-test-with-temp-text
1912 "#+KEYWORD: <point>[[info:emacs#Top]]"
1913 (org-open-at-point) t
)))
1915 (ert-deftest test-org
/open-at-point-in-property
()
1916 "Does `org-open-at-point' open link in property drawer?"
1918 (org-test-with-temp-text
1921 :URL: <point>[[info:emacs#Top]]
1923 (org-open-at-point) t
)))
1925 (ert-deftest test-org
/open-at-point-in-comment
()
1926 "Does `org-open-at-point' open link in a commented line?"
1928 (org-test-with-temp-text
1929 "# <point>[[info:emacs#Top]]"
1930 (org-open-at-point) t
)))
1932 (ert-deftest test-org
/open-at-point
/info
()
1933 "Test `org-open-at-point' on info links."
1935 (org-test-with-temp-text
1936 "<point>[[info:emacs#Top]]"
1938 (and (switch-to-buffer "*info*")
1940 (looking-at "\nThe Emacs Editor")
1943 (ert-deftest test-org
/open-at-point
/inline-image
()
1944 "Test `org-open-at-point' on nested links."
1946 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1948 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1949 (kill-buffer "*info*")))))
1951 (ert-deftest test-org
/open-at-point
/radio-target
()
1952 "Test `org-open-at-point' on radio targets."
1954 (org-test-with-temp-text "<<<target>>> <point>target"
1955 (org-update-radio-target-regexp)
1957 (eq (org-element-type (org-element-context)) 'radio-target
))))
1962 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1963 "Ensure properties accumulate in subtree drawers."
1964 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1965 (org-babel-next-src-block)
1966 (should (equal '(2 1) (org-babel-execute-src-block)))))
1968 (ert-deftest test-org
/custom-properties
()
1969 "Test custom properties specifications."
1972 (let ((org-custom-properties '("FOO")))
1973 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1974 (org-toggle-custom-properties-visibility)
1975 (org-invisible-p2))))
1976 ;; Properties are case-insensitive.
1978 (let ((org-custom-properties '("FOO")))
1979 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1980 (org-toggle-custom-properties-visibility)
1981 (org-invisible-p2))))
1983 (let ((org-custom-properties '("foo")))
1984 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1985 (org-toggle-custom-properties-visibility)
1986 (org-invisible-p2))))
1987 ;; Multiple custom properties in the same drawer.
1989 (let ((org-custom-properties '("FOO" "BAR")))
1990 (org-test-with-temp-text
1991 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1992 (org-toggle-custom-properties-visibility)
1993 (and (org-invisible-p2)
1994 (not (progn (forward-line) (org-invisible-p2)))
1995 (progn (forward-line) (org-invisible-p2))))))
1996 ;; Hide custom properties with an empty value.
1998 (let ((org-custom-properties '("FOO")))
1999 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2000 (org-toggle-custom-properties-visibility)
2001 (org-invisible-p2))))
2002 ;; Do not hide fake properties.
2004 (let ((org-custom-properties '("FOO")))
2005 (org-test-with-temp-text ":FOO: val\n"
2006 (org-toggle-custom-properties-visibility)
2007 (org-invisible-p2))))
2009 (let ((org-custom-properties '("A")))
2010 (org-test-with-temp-text
2011 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2012 (org-toggle-custom-properties-visibility)
2013 (org-invisible-p2)))))
2019 (ert-deftest test-org
/mark-subtree
()
2020 "Test `org-mark-subtree' specifications."
2021 ;; Error when point is before first headline.
2023 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2024 (progn (transient-mark-mode 1)
2025 (org-mark-subtree))))
2026 ;; Without argument, mark current subtree.
2030 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2031 (progn (transient-mark-mode 1)
2034 (list (region-beginning) (region-end))))))
2035 ;; With an argument, move ARG up.
2039 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2040 (progn (transient-mark-mode 1)
2042 (org-mark-subtree 1)
2043 (list (region-beginning) (region-end))))))
2044 ;; Do not get fooled by inlinetasks.
2045 (when (featurep 'org-inlinetask
)
2048 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2049 (progn (transient-mark-mode 1)
2051 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2052 (region-beginning)))))))
2058 (ert-deftest test-org
/in-regexp
()
2059 "Test `org-in-regexp' specifications."
2062 (org-test-with-temp-text "xx ab<point>c xx"
2063 (org-in-regexp "abc")))
2065 (org-test-with-temp-text "xx abc <point>xx"
2066 (org-in-regexp "abc")))
2067 ;; Return non-nil even with multiple matching regexps in the same
2070 (org-test-with-temp-text "abc xx ab<point>c xx"
2071 (org-in-regexp "abc")))
2072 ;; With optional argument NLINES, check extra lines around point.
2074 (org-test-with-temp-text "A\nB<point>\nC"
2075 (org-in-regexp "A\nB\nC")))
2077 (org-test-with-temp-text "A\nB<point>\nC"
2078 (org-in-regexp "A\nB\nC" 1)))
2080 (org-test-with-temp-text "A\nB\nC<point>"
2081 (org-in-regexp "A\nB\nC" 1)))
2082 ;; When optional argument VISUALLY is non-nil, return nil if at
2083 ;; regexp boundaries.
2085 (org-test-with-temp-text "xx abc<point> xx"
2086 (org-in-regexp "abc")))
2088 (org-test-with-temp-text "xx abc<point> xx"
2089 (org-in-regexp "abc" nil t
))))
2094 (ert-deftest test-org
/end-of-meta-data
()
2095 "Test `org-end-of-meta-data' specifications."
2096 ;; Skip planning line.
2098 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2099 (org-end-of-meta-data)
2101 ;; Skip properties drawer.
2103 (org-test-with-temp-text
2104 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2105 (org-end-of-meta-data)
2109 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2110 (org-end-of-meta-data)
2112 ;; Nothing to skip, go to first line.
2114 (org-test-with-temp-text "* Headline\nContents"
2115 (org-end-of-meta-data)
2116 (looking-at "Contents")))
2117 ;; With option argument, skip empty lines, regular drawers and
2120 (org-test-with-temp-text "* Headline\n\nContents"
2121 (org-end-of-meta-data t
)
2122 (looking-at "Contents")))
2124 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2125 (org-end-of-meta-data t
)
2126 (looking-at "Contents")))
2128 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2129 (org-end-of-meta-data t
)
2130 (looking-at "Contents")))
2131 ;; Special case: do not skip incomplete drawers.
2133 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2134 (org-end-of-meta-data t
)
2135 (looking-at ":LOGBOOK:")))
2136 ;; Special case: Be careful about consecutive headlines.
2138 (org-test-with-temp-text "* H1\n*H2\nContents"
2139 (org-end-of-meta-data t
)
2140 (looking-at "Contents"))))
2142 (ert-deftest test-org
/beginning-of-line
()
2143 "Test `org-beginning-of-line' specifications."
2146 (org-test-with-temp-text "Some text\nSome other text"
2147 (progn (org-beginning-of-line) (bolp))))
2148 ;; Standard test with `visual-line-mode'.
2150 (org-test-with-temp-text "A long line of text\nSome other text"
2151 (progn (visual-line-mode)
2153 (dotimes (i 1000) (insert "very "))
2154 (org-beginning-of-line)
2156 ;; At an headline with special movement.
2158 (org-test-with-temp-text "* TODO Headline"
2159 (let ((org-special-ctrl-a/e t
))
2161 (and (progn (org-beginning-of-line) (looking-at "Headline"))
2162 (progn (org-beginning-of-line) (bolp))
2163 (progn (org-beginning-of-line) (looking-at "Headline"))))))
2164 ;; Special case: Do not error when the buffer contains only a single
2167 (org-test-with-temp-text "*<point>"
2168 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
2170 (org-test-with-temp-text "*<point>"
2171 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
2173 (ert-deftest test-org
/end-of-line
()
2174 "Test `org-end-of-line' specifications."
2177 (org-test-with-temp-text "Some text\nSome other text"
2178 (progn (org-end-of-line) (eolp))))
2179 ;; Standard test with `visual-line-mode'.
2181 (org-test-with-temp-text "A long line of text\nSome other text"
2182 (progn (visual-line-mode)
2184 (dotimes (i 1000) (insert "very "))
2185 (goto-char (point-min))
2188 ;; At an headline with special movement.
2190 (org-test-with-temp-text "* Headline1 :tag:\n"
2191 (let ((org-special-ctrl-a/e t
))
2192 (and (progn (org-end-of-line) (looking-at " :tag:"))
2193 (progn (org-end-of-line) (eolp))
2194 (progn (org-end-of-line) (looking-at " :tag:"))))))
2195 ;; At an headline without special movement.
2197 (org-test-with-temp-text "* Headline2 :tag:\n"
2198 (let ((org-special-ctrl-a/e nil
))
2199 (and (progn (org-end-of-line) (eolp))
2200 (progn (org-end-of-line) (eolp))))))
2201 ;; At an headline, with reversed movement.
2203 (org-test-with-temp-text "* Headline3 :tag:\n"
2204 (let ((org-special-ctrl-a/e
'reversed
)
2205 (this-command last-command
))
2206 (and (progn (org-end-of-line) (eolp))
2207 (progn (org-end-of-line) (looking-at " :tag:"))))))
2208 ;; At a block without hidden contents.
2210 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2211 (progn (org-end-of-line) (eolp))))
2212 ;; At a block with hidden contents.
2214 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2215 (let ((org-special-ctrl-a/e t
))
2216 (org-hide-block-toggle)
2220 (ert-deftest test-org
/forward-sentence
()
2221 "Test `org-forward-sentence' specifications."
2222 ;; At the end of a table cell, move to the end of the next one.
2224 (org-test-with-temp-text "| a<point> | b |"
2225 (org-forward-sentence)
2226 (looking-at " |$")))
2227 ;; Elsewhere in a cell, move to its end.
2229 (org-test-with-temp-text "| a<point>c | b |"
2230 (org-forward-sentence)
2231 (looking-at " | b |$")))
2232 ;; Otherwise, simply call `forward-sentence'.
2234 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2235 (org-forward-sentence)
2236 (looking-at " Sentence 2.")))
2238 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2239 (org-forward-sentence)
2240 (org-forward-sentence)
2242 ;; At the end of an element, jump to the next one, without stopping
2243 ;; on blank lines in-between.
2245 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2246 (org-forward-sentence)
2249 (ert-deftest test-org
/backward-sentence
()
2250 "Test `org-backward-sentence' specifications."
2251 ;; At the beginning of a table cell, move to the beginning of the
2254 (org-test-with-temp-text "| a | <point>b |"
2255 (org-backward-sentence)
2256 (looking-at "a | b |$")))
2257 ;; Elsewhere in a cell, move to its beginning.
2259 (org-test-with-temp-text "| a | b<point>c |"
2260 (org-backward-sentence)
2261 (looking-at "bc |$")))
2262 ;; Otherwise, simply call `backward-sentence'.
2264 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2265 (org-backward-sentence)
2266 (looking-at "Sentence 2.")))
2268 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2269 (org-backward-sentence)
2270 (org-backward-sentence)
2272 ;; Make sure to hit the beginning of a sentence on the same line as
2275 (org-test-with-temp-text "- Line 1\n line <point>2."
2276 (org-backward-sentence)
2277 (looking-at "Line 1"))))
2279 (ert-deftest test-org
/forward-paragraph
()
2280 "Test `org-forward-paragraph' specifications."
2281 ;; At end of buffer, return an error.
2283 (org-test-with-temp-text "Paragraph"
2284 (goto-char (point-max))
2285 (org-forward-paragraph)))
2288 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2289 (org-forward-paragraph)
2293 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2294 (org-forward-paragraph)
2296 ;; Do not enter elements with invisible contents.
2298 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2299 (org-hide-block-toggle)
2300 (org-forward-paragraph)
2302 ;; On an affiliated keyword, jump to the beginning of the element.
2304 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2305 (org-forward-paragraph)
2306 (looking-at "Para")))
2307 ;; On an item or a footnote definition, move to the second element
2310 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2311 (org-forward-paragraph)
2312 (looking-at " Paragraph")))
2314 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2315 (org-forward-paragraph)
2316 (looking-at "Paragraph")))
2317 ;; On an item, or a footnote definition, when the first line is
2318 ;; empty, move to the first item.
2320 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2321 (org-forward-paragraph)
2322 (looking-at " Paragraph")))
2324 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2325 (org-forward-paragraph)
2326 (looking-at "Paragraph")))
2327 ;; On a table (resp. a property drawer) do not move through table
2328 ;; rows (resp. node properties).
2330 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2331 (org-forward-paragraph)
2332 (looking-at "Paragraph")))
2334 (org-test-with-temp-text
2335 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2336 (org-forward-paragraph)
2337 (looking-at "Paragraph")))
2338 ;; On a verse or source block, stop after blank lines.
2340 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2341 (org-forward-paragraph)
2344 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2345 (org-forward-paragraph)
2346 (looking-at "L2"))))
2348 (ert-deftest test-org
/backward-paragraph
()
2349 "Test `org-backward-paragraph' specifications."
2350 ;; Error at beginning of buffer.
2352 (org-test-with-temp-text "Paragraph"
2353 (org-backward-paragraph)))
2356 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2357 (goto-char (point-max))
2358 (org-backward-paragraph)
2361 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2362 (goto-char (point-max))
2364 (org-backward-paragraph)
2368 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2369 (goto-char (point-max))
2371 (org-backward-paragraph)
2373 ;; Ignore invisible elements.
2375 (org-test-with-temp-text "* H1\n P1\n* H2"
2377 (goto-char (point-max))
2379 (org-backward-paragraph)
2381 ;; On an affiliated keyword, jump to the first one.
2383 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2384 (search-forward "c2")
2385 (org-backward-paragraph)
2386 (looking-at "#\\+name")))
2387 ;; On the second element in an item or a footnote definition, jump
2388 ;; to item or the definition.
2390 (org-test-with-temp-text "- line1\n\n line2"
2391 (goto-char (point-max))
2393 (org-backward-paragraph)
2394 (looking-at "- line1")))
2396 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2397 (goto-char (point-max))
2399 (org-backward-paragraph)
2400 (looking-at "\\[fn:1\\] line1")))
2401 ;; On a table (resp. a property drawer), ignore table rows
2402 ;; (resp. node properties).
2404 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2405 (goto-char (point-max))
2407 (org-backward-paragraph)
2410 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2411 (org-backward-paragraph)
2412 (looking-at ":PROPERTIES:")))
2413 ;; On a source or verse block, stop before blank lines.
2415 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2416 (search-forward "L3")
2418 (org-backward-paragraph)
2421 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2422 (search-forward "L3")
2424 (org-backward-paragraph)
2425 (looking-at "L2"))))
2427 (ert-deftest test-org
/forward-element
()
2428 "Test `org-forward-element' specifications."
2429 ;; 1. At EOB: should error.
2430 (org-test-with-temp-text "Some text\n"
2431 (goto-char (point-max))
2432 (should-error (org-forward-element)))
2433 ;; 2. Standard move: expected to ignore blank lines.
2434 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2435 (org-forward-element)
2436 (should (looking-at (regexp-quote "Second paragraph."))))
2437 ;; 3. Headline tests.
2438 (org-test-with-temp-text "
2443 ;; 3.1. At an headline beginning: move to next headline at the
2446 (org-forward-element)
2447 (should (looking-at (regexp-quote "** Head 1.2")))
2448 ;; 3.2. At an headline beginning: move to parent headline if no
2449 ;; headline at the same level.
2451 (org-forward-element)
2452 (should (looking-at (regexp-quote "** Head 1.2"))))
2453 ;; 4. Greater element tests.
2454 (org-test-with-temp-text
2455 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2456 ;; 4.1. At a greater element: expected to skip contents.
2457 (org-forward-element)
2458 (should (looking-at (regexp-quote "Outside.")))
2459 ;; 4.2. At the end of greater element contents: expected to skip
2460 ;; to the end of the greater element.
2462 (org-forward-element)
2463 (should (looking-at (regexp-quote "Outside."))))
2465 (org-test-with-temp-text "
2479 ;; 5.1. At list top point: expected to move to the element after
2482 (org-forward-element)
2483 (should (looking-at (regexp-quote "Outside.")))
2484 ;; 5.2. Special case: at the first line of a sub-list, but not at
2485 ;; beginning of line, move to next item.
2488 (org-forward-element)
2489 (should (looking-at "- item2"))
2492 (org-forward-element)
2493 (should (looking-at " - sub2"))
2494 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2496 (org-forward-element)
2497 (should (looking-at (regexp-quote " Inner paragraph.")))
2498 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2500 (org-forward-element)
2501 (should (looking-at (regexp-quote " Inner paragraph.")))
2502 ;; 5.5. At an item: expected to move to next item, if any.
2504 (org-forward-element)
2505 (should (looking-at " - sub3"))))
2507 (ert-deftest test-org
/backward-element
()
2508 "Test `org-backward-element' specifications."
2509 ;; 1. Should error at BOB.
2510 (org-test-with-temp-text " \nParagraph."
2511 (should-error (org-backward-element)))
2512 ;; 2. Should move at BOB when called on the first element in buffer.
2514 (org-test-with-temp-text "\n#+TITLE: test"
2515 (progn (forward-line)
2516 (org-backward-element)
2518 ;; 3. Not at the beginning of an element: move at its beginning.
2519 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2522 (org-backward-element)
2523 (should (looking-at (regexp-quote "Paragraph2."))))
2524 ;; 4. Headline tests.
2525 (org-test-with-temp-text "
2530 ;; 4.1. At an headline beginning: move to previous headline at the
2533 (org-backward-element)
2534 (should (looking-at (regexp-quote "** Head 1.1")))
2535 ;; 4.2. At an headline beginning: move to parent headline if no
2536 ;; headline at the same level.
2538 (org-backward-element)
2539 (should (looking-at (regexp-quote "* Head 1")))
2540 ;; 4.3. At the first top-level headline: should error.
2542 (should-error (org-backward-element)))
2543 ;; 5. At beginning of first element inside a greater element:
2544 ;; expected to move to greater element's beginning.
2545 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2547 (org-backward-element)
2548 (should (looking-at "#\\+BEGIN_CENTER")))
2549 ;; 6. At the beginning of the first element in a section: should
2550 ;; move back to headline, if any.
2552 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2553 (progn (goto-char (point-max))
2555 (org-backward-element)
2556 (org-at-heading-p))))
2558 (org-test-with-temp-text "
2573 ;; 7.1. At beginning of sub-list: expected to move to the
2574 ;; paragraph before it.
2576 (org-backward-element)
2577 (should (looking-at "item1"))
2578 ;; 7.2. At an item in a list: expected to move at previous item.
2580 (org-backward-element)
2581 (should (looking-at " - sub2"))
2583 (org-backward-element)
2584 (should (looking-at "- item1"))
2585 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2588 (org-backward-element)
2589 (should (looking-at " - sub1"))
2591 (org-backward-element)
2592 (should (looking-at "- item1"))
2593 ;; 7.4. At blank-lines before list end: expected to move to top
2596 (org-backward-element)
2597 (should (looking-at "- item1"))))
2599 (ert-deftest test-org
/up-element
()
2600 "Test `org-up-element' specifications."
2601 ;; 1. At BOB or with no surrounding element: should error.
2602 (org-test-with-temp-text "Paragraph."
2603 (should-error (org-up-element)))
2604 (org-test-with-temp-text "* Head1\n* Head2"
2606 (should-error (org-up-element)))
2607 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2609 (should-error (org-up-element)))
2610 ;; 2. At an headline: move to parent headline.
2611 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2614 (should (looking-at "\\* Head1")))
2615 ;; 3. Inside a greater element: move to greater element beginning.
2616 (org-test-with-temp-text
2617 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2620 (should (looking-at "#\\+BEGIN_CENTER")))
2622 (org-test-with-temp-text "* Top
2629 Paragraph within sub2.
2632 ;; 4.1. Within an item: move to the item beginning.
2635 (should (looking-at " - sub2"))
2636 ;; 4.2. At an item in a sub-list: move to parent item.
2639 (should (looking-at "- item1"))
2640 ;; 4.3. At an item in top list: move to beginning of whole list.
2643 (should (looking-at "- item1"))
2644 ;; 4.4. Special case. At very top point: should move to parent of
2648 (should (looking-at "\\* Top"))))
2650 (ert-deftest test-org
/down-element
()
2651 "Test `org-down-element' specifications."
2652 ;; Error when the element hasn't got a recursive type.
2653 (org-test-with-temp-text "Paragraph."
2654 (should-error (org-down-element)))
2655 ;; Error when the element has no contents
2656 (org-test-with-temp-text "* Headline"
2657 (should-error (org-down-element)))
2658 ;; When at a plain-list, move to first item.
2659 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2662 (should (looking-at " - Item 1.1")))
2663 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2665 (should (looking-at " Item 1")))
2666 ;; When at a table, move to first row
2667 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2669 (should (looking-at " a | b |")))
2670 ;; Otherwise, move inside the greater element.
2671 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2673 (should (looking-at "Paragraph"))))
2675 (ert-deftest test-org
/drag-element-backward
()
2676 "Test `org-drag-element-backward' specifications."
2680 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2681 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2682 (org-drag-element-backward)
2686 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2687 (org-test-with-temp-text
2688 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2689 (org-drag-element-backward)
2691 ;; Preserve blank lines.
2693 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2694 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2695 (org-drag-element-backward)
2699 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2700 (org-drag-element-backward)
2701 (org-looking-at-p "2")))
2702 ;; Error when trying to move first element of buffer.
2704 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2705 (org-drag-element-backward)))
2706 ;; Error when trying to swap nested elements.
2708 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2710 (org-drag-element-backward)))
2711 ;; Error when trying to swap an headline element and a non-headline
2714 (org-test-with-temp-text "Test.\n* Head 1"
2716 (org-drag-element-backward)))
2717 ;; Preserve visibility of elements and their contents.
2719 (equal '((63 .
82) (26 .
48))
2720 (org-test-with-temp-text "
2728 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2729 (search-backward "- item 1")
2730 (org-drag-element-backward)
2731 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2732 (overlays-in (point-min) (point-max)))))))
2734 (ert-deftest test-org
/drag-element-forward
()
2735 "Test `org-drag-element-forward' specifications."
2736 ;; 1. Error when trying to move first element of buffer.
2737 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2739 (should-error (org-drag-element-forward)))
2740 ;; 2. Error when trying to swap nested elements.
2741 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2743 (should-error (org-drag-element-forward)))
2744 ;; 3. Error when trying to swap a non-headline element and an
2746 (org-test-with-temp-text "Test.\n* Head 1"
2747 (should-error (org-drag-element-forward)))
2748 ;; 4. Otherwise, swap elements, preserving column and blank lines
2749 ;; between elements.
2750 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2751 (search-forward "graph")
2752 (org-drag-element-forward)
2753 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2754 (should (looking-at " 1")))
2755 ;; 5. Preserve visibility of elements and their contents.
2756 (org-test-with-temp-text "
2764 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2765 (search-backward "#+BEGIN_CENTER")
2766 (org-drag-element-forward)
2769 '((63 .
82) (26 .
48))
2770 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2771 (overlays-in (point-min) (point-max)))))))
2773 (ert-deftest test-org
/next-block
()
2774 "Test `org-next-block' specifications."
2777 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2779 (looking-at "#\\+BEGIN_CENTER")))
2782 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2783 (let ((case-fold-search nil
))
2785 (looking-at "#\\+begin_center"))))
2786 ;; Ignore current line.
2788 (org-test-with-temp-text
2789 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2791 (looking-at "#\\+BEGIN_CENTER")))
2792 ;; Throw an error when no block is found.
2794 (org-test-with-temp-text "Paragraph"
2795 (org-next-block 1)))
2796 ;; With an argument, skip many blocks at once.
2798 (org-test-with-temp-text
2799 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2801 (looking-at "#\\+BEGIN_QUOTE")))
2802 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2804 (org-test-with-temp-text
2805 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2806 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2807 (looking-at "#\\+BEGIN_QUOTE")))
2808 ;; Optional argument is also case-insensitive.
2810 (org-test-with-temp-text
2811 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2812 (let ((case-fold-search nil
))
2813 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2814 (looking-at "#\\+begin_quote")))))
2816 (ert-deftest test-org
/previous-block
()
2817 "Test `org-previous-block' specifications."
2820 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2821 (org-previous-block 1)
2822 (looking-at "#\\+BEGIN_CENTER")))
2825 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2826 (let ((case-fold-search nil
))
2827 (org-previous-block 1)
2828 (looking-at "#\\+begin_center"))))
2829 ;; Ignore current line.
2831 (org-test-with-temp-text
2832 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2833 (org-previous-block 1)
2834 (looking-at "#\\+BEGIN_QUOTE")))
2835 ;; Throw an error when no block is found.
2837 (org-test-with-temp-text "Paragraph<point>"
2838 (org-previous-block 1)))
2839 ;; With an argument, skip many blocks at once.
2841 (org-test-with-temp-text
2842 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2843 (org-previous-block 2)
2844 (looking-at "#\\+BEGIN_CENTER")))
2845 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2847 (org-test-with-temp-text
2848 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2849 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2850 (looking-at "#\\+BEGIN_QUOTE")))
2851 ;; Optional argument is also case-insensitive.
2853 (org-test-with-temp-text
2854 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2855 (let ((case-fold-search nil
))
2856 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2857 (looking-at "#\\+begin_quote")))))
2860 ;;; Outline structure
2862 (ert-deftest test-org
/demote
()
2863 "Test `org-demote' specifications."
2864 ;; Add correct number of stars according to `org-odd-levels-only'.
2867 (org-test-with-temp-text "* H"
2868 (let ((org-odd-levels-only nil
)) (org-demote))
2869 (org-current-level))))
2872 (org-test-with-temp-text "* H"
2873 (let ((org-odd-levels-only t
)) (org-demote))
2874 (org-current-level))))
2875 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2877 (org-test-with-temp-text "* H :tag:"
2878 (let ((org-tags-column 10)
2879 (org-auto-align-tags t
)
2880 (org-odd-levels-only nil
))
2882 (org-move-to-column 10)
2883 (org-looking-at-p ":tag:$")))
2885 (org-test-with-temp-text "* H :tag:"
2886 (let ((org-tags-column 10)
2887 (org-auto-align-tags nil
)
2888 (org-odd-levels-only nil
))
2890 (org-move-to-column 10)
2891 (org-looking-at-p ":tag:$")))
2892 ;; When `org-adapt-indentation' is non-nil, always indent planning
2893 ;; info and property drawers accordingly.
2896 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2897 (let ((org-odd-levels-only nil
)
2898 (org-adapt-indentation t
))
2901 (org-get-indentation))))
2904 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2905 (let ((org-odd-levels-only nil
)
2906 (org-adapt-indentation t
))
2909 (org-get-indentation))))
2912 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2913 (let ((org-odd-levels-only nil
)
2914 (org-adapt-indentation nil
))
2917 (org-get-indentation))))
2918 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2919 ;; section accordingly. Ignore, however, footnote definitions and
2920 ;; inlinetasks boundaries.
2923 (org-test-with-temp-text "* H\n Paragraph"
2924 (let ((org-odd-levels-only nil
)
2925 (org-adapt-indentation t
))
2928 (org-get-indentation))))
2931 (org-test-with-temp-text "* H\n Paragraph"
2932 (let ((org-odd-levels-only nil
)
2933 (org-adapt-indentation nil
))
2936 (org-get-indentation))))
2939 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2940 (let ((org-odd-levels-only nil
)
2941 (org-adapt-indentation t
))
2943 (goto-char (point-max))
2944 (org-get-indentation))))
2947 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2948 (let ((org-odd-levels-only nil
)
2949 (org-adapt-indentation t
))
2951 (goto-char (point-max))
2952 (org-get-indentation))))
2953 (when (featurep 'org-inlinetask
)
2956 (let ((org-inlinetask-min-level 5)
2957 (org-adapt-indentation t
))
2958 (org-test-with-temp-text "* H\n***** I\n***** END"
2961 (org-get-indentation))))))
2962 (when (featurep 'org-inlinetask
)
2965 (let ((org-inlinetask-min-level 5)
2966 (org-adapt-indentation t
))
2967 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2970 (org-get-indentation))))))
2971 ;; Ignore contents of source blocks or example blocks when
2972 ;; indentation should be preserved (through
2973 ;; `org-src-preserve-indentation' or "-i" flag).
2976 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2977 (let ((org-adapt-indentation t
)
2978 (org-src-preserve-indentation nil
))
2981 (org-get-indentation))))
2984 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2985 (let ((org-adapt-indentation t
)
2986 (org-src-preserve-indentation t
))
2989 (org-get-indentation))))
2992 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2993 (let ((org-adapt-indentation t
)
2994 (org-src-preserve-indentation t
))
2997 (org-get-indentation))))
3000 (org-test-with-temp-text
3001 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3002 (let ((org-adapt-indentation t
)
3003 (org-src-preserve-indentation nil
))
3006 (org-get-indentation)))))
3008 (ert-deftest test-org
/promote
()
3009 "Test `org-promote' specifications."
3010 ;; Return an error if headline is to be promoted to level 0, unless
3011 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3012 ;; headline becomes a comment.
3014 (org-test-with-temp-text "* H"
3015 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3018 (org-test-with-temp-text "* H"
3019 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3021 ;; Remove correct number of stars according to
3022 ;; `org-odd-levels-only'.
3025 (org-test-with-temp-text "*** H"
3026 (let ((org-odd-levels-only nil
)) (org-promote))
3027 (org-current-level))))
3030 (org-test-with-temp-text "*** H"
3031 (let ((org-odd-levels-only t
)) (org-promote))
3032 (org-current-level))))
3033 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3035 (org-test-with-temp-text "** H :tag:"
3036 (let ((org-tags-column 10)
3037 (org-auto-align-tags t
)
3038 (org-odd-levels-only nil
))
3040 (org-move-to-column 10)
3041 (org-looking-at-p ":tag:$")))
3043 (org-test-with-temp-text "** H :tag:"
3044 (let ((org-tags-column 10)
3045 (org-auto-align-tags nil
)
3046 (org-odd-levels-only nil
))
3048 (org-move-to-column 10)
3049 (org-looking-at-p ":tag:$")))
3050 ;; When `org-adapt-indentation' is non-nil, always indent planning
3051 ;; info and property drawers.
3054 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3055 (let ((org-odd-levels-only nil
)
3056 (org-adapt-indentation t
))
3059 (org-get-indentation))))
3062 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3063 (let ((org-odd-levels-only nil
)
3064 (org-adapt-indentation t
))
3067 (org-get-indentation))))
3070 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3071 (let ((org-odd-levels-only nil
)
3072 (org-adapt-indentation nil
))
3075 (org-get-indentation))))
3076 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3077 ;; section accordingly. Ignore, however, footnote definitions and
3078 ;; inlinetasks boundaries.
3081 (org-test-with-temp-text "** H\n Paragraph"
3082 (let ((org-odd-levels-only nil
)
3083 (org-adapt-indentation t
))
3086 (org-get-indentation))))
3089 (org-test-with-temp-text "** H\n Paragraph"
3090 (let ((org-odd-levels-only nil
)
3091 (org-adapt-indentation nil
))
3094 (org-get-indentation))))
3097 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3098 (let ((org-odd-levels-only nil
)
3099 (org-adapt-indentation t
))
3102 (org-get-indentation))))
3103 (when (featurep 'org-inlinetask
)
3106 (let ((org-inlinetask-min-level 5)
3107 (org-adapt-indentation t
))
3108 (org-test-with-temp-text "** H\n***** I\n***** END"
3111 (org-get-indentation))))))
3112 (when (featurep 'org-inlinetask
)
3115 (let ((org-inlinetask-min-level 5)
3116 (org-adapt-indentation t
))
3117 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3120 (org-get-indentation))))))
3121 ;; Give up shifting if it would break document's structure
3125 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3126 (let ((org-odd-levels-only nil
)
3127 (org-adapt-indentation t
))
3130 (org-get-indentation))))
3133 (org-test-with-temp-text "** H\n Paragraph\n * list."
3134 (let ((org-odd-levels-only nil
)
3135 (org-adapt-indentation t
))
3138 (org-get-indentation))))
3139 ;; Ignore contents of source blocks or example blocks when
3140 ;; indentation should be preserved (through
3141 ;; `org-src-preserve-indentation' or "-i" flag).
3144 (org-test-with-temp-text
3145 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3146 (let ((org-adapt-indentation t
)
3147 (org-src-preserve-indentation nil
)
3148 (org-odd-levels-only nil
))
3151 (org-get-indentation))))
3154 (org-test-with-temp-text
3155 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3156 (let ((org-adapt-indentation t
)
3157 (org-src-preserve-indentation t
)
3158 (org-odd-levels-only nil
))
3161 (org-get-indentation))))
3164 (org-test-with-temp-text
3165 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3166 (let ((org-adapt-indentation t
)
3167 (org-src-preserve-indentation t
)
3168 (org-odd-levels-only nil
))
3171 (org-get-indentation))))
3174 (org-test-with-temp-text
3175 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3176 (let ((org-adapt-indentation t
)
3177 (org-src-preserve-indentation nil
)
3178 (org-odd-levels-only nil
))
3181 (org-get-indentation)))))
3186 (ert-deftest test-org
/at-planning-p
()
3187 "Test `org-at-planning-p' specifications."
3190 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3191 (org-at-planning-p)))
3193 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3194 (org-at-planning-p)))
3195 ;; Correctly find planning attached to inlinetasks.
3196 (when (featurep 'org-inlinetask
)
3198 (org-test-with-temp-text
3199 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3200 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3202 (org-test-with-temp-text
3203 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3204 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3206 (org-test-with-temp-text
3207 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3208 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3210 (org-test-with-temp-text
3211 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3212 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3214 (ert-deftest test-org
/add-planning-info
()
3215 "Test `org-add-planning-info'."
3216 ;; Create deadline when `org-adapt-indentation' is non-nil.
3218 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3219 (org-test-with-temp-text "* H\nParagraph<point>"
3220 (let ((org-adapt-indentation t
))
3221 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3222 (replace-regexp-in-string
3223 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3225 ;; Create deadline when `org-adapt-indentation' is nil.
3227 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3228 (org-test-with-temp-text "* H\nParagraph<point>"
3229 (let ((org-adapt-indentation nil
))
3230 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3231 (replace-regexp-in-string
3232 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3234 ;; Update deadline when `org-adapt-indentation' is non-nil.
3236 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3237 (org-test-with-temp-text "\
3239 DEADLINE: <2015-06-24 Wed>
3241 (let ((org-adapt-indentation t
))
3242 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3243 (replace-regexp-in-string
3244 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3246 ;; Update deadline when `org-adapt-indentation' is nil.
3248 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3249 (org-test-with-temp-text "\
3251 DEADLINE: <2015-06-24 Wed>
3253 (let ((org-adapt-indentation nil
))
3254 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3255 (replace-regexp-in-string
3256 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3258 ;; Schedule when `org-adapt-indentation' is non-nil.
3260 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3261 (org-test-with-temp-text "* H\nParagraph<point>"
3262 (let ((org-adapt-indentation t
))
3263 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3264 (replace-regexp-in-string
3265 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3267 ;; Schedule when `org-adapt-indentation' is nil.
3269 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3270 (org-test-with-temp-text "* H\nParagraph<point>"
3271 (let ((org-adapt-indentation nil
))
3272 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3273 (replace-regexp-in-string
3274 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3276 ;; Add deadline when scheduled.
3280 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3282 (org-test-with-temp-text "\
3284 SCHEDULED: <2015-06-24 Wed>
3286 (let ((org-adapt-indentation t
))
3287 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3288 (replace-regexp-in-string
3289 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3291 ;; Remove middle entry.
3295 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3297 (org-test-with-temp-text "\
3299 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3301 (let ((org-adapt-indentation t
))
3302 (org-add-planning-info nil nil
'deadline
))
3303 (replace-regexp-in-string
3304 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3306 ;; Remove last entry and then middle entry (order should not
3311 CLOSED: [2015-06-24]
3313 (org-test-with-temp-text "\
3315 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3317 (let ((org-adapt-indentation t
))
3318 (org-add-planning-info nil nil
'scheduled
'deadline
))
3319 (replace-regexp-in-string
3320 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3322 ;; Remove closed when `org-adapt-indentation' is non-nil.
3324 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3325 (org-test-with-temp-text "\
3327 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3329 (let ((org-adapt-indentation t
))
3330 (org-add-planning-info nil nil
'closed
))
3331 (replace-regexp-in-string
3332 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3335 (equal "* H\n Paragraph"
3336 (org-test-with-temp-text "\
3338 CLOSED: [2015-06-25 Thu]
3340 (let ((org-adapt-indentation t
))
3341 (org-add-planning-info nil nil
'closed
))
3342 (replace-regexp-in-string
3343 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3345 ;; Remove closed when `org-adapt-indentation' is nil.
3347 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3348 (org-test-with-temp-text "\
3350 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3352 (let ((org-adapt-indentation nil
))
3353 (org-add-planning-info nil nil
'closed
))
3354 (replace-regexp-in-string
3355 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3358 (equal "* H\nParagraph"
3359 (org-test-with-temp-text "\
3361 CLOSED: [2015-06-25 Thu]
3363 (let ((org-adapt-indentation nil
))
3364 (org-add-planning-info nil nil
'closed
))
3365 (replace-regexp-in-string
3366 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3368 ;; Remove closed entry and delete empty line.
3373 (org-test-with-temp-text "\
3375 CLOSED: [2015-06-24 Wed]
3377 (let ((org-adapt-indentation t
))
3378 (org-add-planning-info nil nil
'closed
))
3379 (replace-regexp-in-string
3380 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3382 ;; Remove one entry and update another.
3384 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3385 (org-test-with-temp-text "\
3387 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3389 (let ((org-adapt-indentation t
))
3390 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3391 (replace-regexp-in-string
3392 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3398 (ert-deftest test-org
/buffer-property-keys
()
3399 "Test `org-buffer-property-keys' specifications."
3400 ;; Retrieve properties accross siblings.
3403 (org-test-with-temp-text "
3412 (org-buffer-property-keys))))
3413 ;; Retrieve properties accross children.
3416 (org-test-with-temp-text "
3425 (org-buffer-property-keys))))
3426 ;; Retrieve muliple properties in the same drawer.
3429 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3430 (org-buffer-property-keys))))
3431 ;; Ignore extension symbol in property name.
3434 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3435 (org-buffer-property-keys))))
3436 ;; With non-nil COLUMNS, extract property names from columns.
3439 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3440 (org-buffer-property-keys nil nil t
))))
3442 (equal '("A" "B" "COLUMNS")
3443 (org-test-with-temp-text
3444 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3445 (org-buffer-property-keys nil nil t
))))
3446 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
3449 (org-test-with-temp-text
3450 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
3451 (org-buffer-property-keys nil nil nil t
)))))
3453 (ert-deftest test-org
/property-values
()
3454 "Test `org-property-values' specifications."
3458 (org-test-with-temp-text
3459 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3460 (org-property-values "A"))))
3461 ;; Ignore empty values.
3463 (org-test-with-temp-text
3464 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3465 (org-property-values "A")))
3466 ;; Take into consideration extended values.
3469 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3470 (org-property-values "A")))))
3472 (ert-deftest test-org
/find-property
()
3473 "Test `org-find-property' specifications."
3477 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3478 (org-find-property "prop"))))
3479 ;; Ignore false positives.
3482 (org-test-with-temp-text
3483 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3484 (org-find-property "A"))))
3485 ;; Return first entry found in buffer.
3488 (org-test-with-temp-text
3489 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3490 (org-find-property "A"))))
3491 ;; Only search visible part of the buffer.
3494 (org-test-with-temp-text
3495 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3496 (org-narrow-to-subtree)
3497 (org-find-property "A"))))
3498 ;; With optional argument, only find entries with a specific value.
3500 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3501 (org-find-property "A" "2")))
3504 (org-test-with-temp-text
3505 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3506 (org-find-property "A" "2"))))
3507 ;; Use "nil" for explicit nil values.
3510 (org-test-with-temp-text
3511 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3512 (org-find-property "A" "nil")))))
3514 (ert-deftest test-org
/entry-delete
()
3515 "Test `org-entry-delete' specifications."
3519 " *:PROPERTIES:\n *:B: +2\n *:END:"
3520 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3521 (org-entry-delete (point) "A")
3523 ;; Also remove accumulated properties.
3527 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3528 (org-entry-delete (point) "A")
3530 ;; When last property is removed, remove the property drawer.
3534 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3535 (org-entry-delete (point) "A")
3537 ;; Return a non-nil value when some property was removed.
3539 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3540 (org-entry-delete (point) "A")))
3542 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3543 (org-entry-delete (point) "C"))))
3545 (ert-deftest test-org
/entry-get
()
3546 "Test `org-entry-get' specifications."
3550 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3551 (org-entry-get (point) "A"))))
3555 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3556 (org-entry-get (point) "a"))))
3557 ;; Handle extended values, both before and after base value.
3560 (org-test-with-temp-text
3561 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3562 (org-entry-get (point) "A"))))
3563 ;; Empty values are returned as the empty string.
3566 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3567 (org-entry-get (point) "A"))))
3568 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3569 ;; otherwise, return nil.
3571 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3572 (org-entry-get (point) "A")))
3575 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3576 (org-entry-get (point) "A" nil t
))))
3577 ;; Return nil when no property is found, independently on the
3578 ;; LITERAL-NIL argument.
3580 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3581 (org-entry-get (point) "B")))
3583 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3584 (org-entry-get (point) "B" nil t
)))
3585 ;; Handle inheritance, when allowed. Include extended values and
3586 ;; possibly global values.
3590 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3591 (org-entry-get (point) "A" t
))))
3595 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3596 (let ((org-use-property-inheritance t
))
3597 (org-entry-get (point) "A" 'selective
)))))
3599 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3600 (let ((org-use-property-inheritance nil
))
3601 (org-entry-get (point) "A" 'selective
))))
3605 (org-test-with-temp-text
3606 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3607 (org-entry-get (point-max) "A" t
))))
3610 (org-test-with-temp-text
3611 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3613 (org-entry-get (point-max) "A" t
))))
3616 (org-test-with-temp-text
3617 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3619 (org-entry-get (point-max) "A" t
)))))
3621 (ert-deftest test-org
/entry-properties
()
3622 "Test `org-entry-properties' specifications."
3623 ;; Get "ITEM" property.
3626 (org-test-with-temp-text "* TODO H"
3627 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3630 (org-test-with-temp-text "* TODO H"
3631 (cdr (assoc "ITEM" (org-entry-properties))))))
3632 ;; Get "TODO" property. TODO keywords are case sensitive.
3635 (org-test-with-temp-text "* TODO H"
3636 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3639 (org-test-with-temp-text "* TODO H"
3640 (cdr (assoc "TODO" (org-entry-properties))))))
3642 (org-test-with-temp-text "* H"
3643 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3645 (org-test-with-temp-text "* todo H"
3646 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3647 ;; Get "PRIORITY" property.
3650 (org-test-with-temp-text "* [#A] H"
3651 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3654 (org-test-with-temp-text "* [#A] H"
3655 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3657 (equal (char-to-string org-default-priority
)
3658 (org-test-with-temp-text "* H"
3659 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3660 ;; Get "FILE" property.
3662 (org-test-with-temp-text-in-file "* H\nParagraph"
3663 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3664 (buffer-file-name))))
3666 (org-test-with-temp-text-in-file "* H\nParagraph"
3667 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3668 (buffer-file-name))))
3670 (org-test-with-temp-text "* H\nParagraph"
3671 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3672 ;; Get "TAGS" property.
3674 (equal ":tag1:tag2:"
3675 (org-test-with-temp-text "* H :tag1:tag2:"
3676 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3678 (equal ":tag1:tag2:"
3679 (org-test-with-temp-text "* H :tag1:tag2:"
3680 (cdr (assoc "TAGS" (org-entry-properties))))))
3682 (org-test-with-temp-text "* H"
3683 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3684 ;; Get "ALLTAGS" property.
3686 (equal ":tag1:tag2:"
3687 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3688 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3690 (equal ":tag1:tag2:"
3691 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3692 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3694 (org-test-with-temp-text "* H"
3695 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3696 ;; Get "BLOCKED" property.
3699 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3700 (let ((org-enforce-todo-dependencies t
)
3702 '(org-block-todo-from-children-or-siblings-or-parent)))
3703 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3706 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
3707 (let ((org-enforce-todo-dependencies t
)
3709 '(org-block-todo-from-children-or-siblings-or-parent)))
3710 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3711 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3715 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3716 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3720 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3721 (cdr (assoc "CLOSED" (org-entry-properties))))))
3723 (org-test-with-temp-text "* H"
3724 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3728 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3729 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3733 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3734 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3736 (org-test-with-temp-text "* H"
3737 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3741 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3742 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3746 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3747 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3749 (org-test-with-temp-text "* H"
3750 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3754 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3755 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3758 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3759 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3762 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3763 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3766 (org-test-with-temp-text
3767 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3769 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3770 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3771 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
3773 (equal "<2012-03-29 thu.>"
3774 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
3775 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
3777 (equal "[2012-03-29 thu.]"
3778 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
3779 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
3781 (equal "<2012-03-29 thu.>"
3782 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
3783 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
3785 (equal "[2014-03-04 tue.]"
3786 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
3787 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
3788 ;; Get standard properties.
3791 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3792 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3793 ;; Handle extended properties.
3796 (org-test-with-temp-text
3797 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3798 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3801 (org-test-with-temp-text
3802 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3803 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3804 ;; Ignore forbidden (special) properties.
3806 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3807 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3809 (ert-deftest test-org
/entry-put
()
3810 "Test `org-entry-put' specifications."
3811 ;; Error when not a string or nil.
3813 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3814 (org-entry-put 1 "test" 2)))
3815 ;; Error when property name is invalid.
3817 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3818 (org-entry-put 1 "no space" "value")))
3820 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3821 (org-entry-put 1 "" "value")))
3822 ;; Set "TODO" property.
3824 (string-match (regexp-quote " TODO H")
3825 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3826 (org-entry-put (point) "TODO" "TODO")
3829 (string-match (regexp-quote "* H")
3830 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3831 (org-entry-put (point) "TODO" nil
)
3833 ;; Set "PRIORITY" property.
3836 (org-test-with-temp-text "* [#B] H"
3837 (org-entry-put (point) "PRIORITY" "A")
3841 (org-test-with-temp-text "* [#B] H"
3842 (org-entry-put (point) "PRIORITY" nil
)
3844 ;; Set "SCHEDULED" property.
3846 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3847 (org-test-with-temp-text "* H"
3848 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3852 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3853 (org-entry-put (point) "SCHEDULED" nil
)
3856 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3857 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3858 (org-entry-put (point) "SCHEDULED" "earlier")
3861 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3862 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3863 (org-entry-put (point) "SCHEDULED" "later")
3865 ;; Set "DEADLINE" property.
3867 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3868 (org-test-with-temp-text "* H"
3869 (org-entry-put (point) "DEADLINE" "2014-03-04")
3873 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3874 (org-entry-put (point) "DEADLINE" nil
)
3877 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3878 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3879 (org-entry-put (point) "DEADLINE" "earlier")
3882 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3883 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3884 (org-entry-put (point) "DEADLINE" "later")
3886 ;; Set "CATEGORY" property
3888 (string-match "^ *:CATEGORY: cat"
3889 (org-test-with-temp-text "* H"
3890 (org-entry-put (point) "CATEGORY" "cat")
3892 ;; Regular properties, with or without pre-existing drawer.
3894 (string-match "^ *:A: +2$"
3895 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3896 (org-entry-put (point) "A" "2")
3899 (string-match "^ *:A: +1$"
3900 (org-test-with-temp-text "* H"
3901 (org-entry-put (point) "A" "1")
3903 ;; Special case: two consecutive headlines.
3905 (string-match "\\* A\n *:PROPERTIES:"
3906 (org-test-with-temp-text "* A\n** B"
3907 (org-entry-put (point) "A" "1")
3913 (ert-deftest test-org
/update-radio-target-regexp
()
3914 "Test `org-update-radio-target-regexp' specifications."
3915 ;; Properly update cache with no previous radio target regexp.
3918 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3919 (save-excursion (goto-char (point-max)) (org-element-context))
3921 (search-forward "o")
3923 (org-update-radio-target-regexp)
3924 (goto-char (point-max))
3925 (org-element-type (org-element-context)))))
3926 ;; Properly update cache with previous radio target regexp.
3929 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3930 (save-excursion (goto-char (point-max)) (org-element-context))
3932 (search-forward "o")
3934 (org-update-radio-target-regexp)
3935 (search-backward "r")
3938 (org-update-radio-target-regexp)
3939 (goto-char (point-max))
3940 (delete-region (line-beginning-position) (point))
3942 (org-element-type (org-element-context))))))
3947 (ert-deftest test-org
/match-sparse-tree
()
3948 "Test `org-match-sparse-tree' specifications."
3951 (org-test-with-temp-text "* H\n** H1 :tag:"
3952 (org-match-sparse-tree nil
"tag")
3953 (search-forward "H1")
3954 (org-invisible-p2)))
3956 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3957 (org-match-sparse-tree nil
"tag")
3958 (search-forward "H2")
3959 (org-invisible-p2)))
3960 ;; "-" operator for tags.
3962 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3963 (org-match-sparse-tree nil
"tag1-tag2")
3964 (search-forward "H1")
3965 (org-invisible-p2)))
3967 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3968 (org-match-sparse-tree nil
"tag1-tag2")
3969 (search-forward "H2")
3970 (org-invisible-p2)))
3971 ;; "&" operator for tags.
3973 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3974 (org-match-sparse-tree nil
"tag1&tag2")
3975 (search-forward "H1")
3976 (org-invisible-p2)))
3978 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3979 (org-match-sparse-tree nil
"tag1&tag2")
3980 (search-forward "H2")
3981 (org-invisible-p2)))
3982 ;; "|" operator for tags.
3984 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3985 (org-match-sparse-tree nil
"tag1|tag2")
3986 (search-forward "H1")
3987 (org-invisible-p2)))
3989 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3990 (org-match-sparse-tree nil
"tag1|tag2")
3991 (search-forward "H2")
3992 (org-invisible-p2)))
3993 ;; Regexp match on tags.
3995 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3996 (org-match-sparse-tree nil
"{^tag.*}")
3997 (search-forward "H1")
3998 (org-invisible-p2)))
4000 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4001 (org-match-sparse-tree nil
"{^tag.*}")
4002 (search-forward "H2")
4003 (org-invisible-p2)))
4004 ;; Match group tags.
4006 (org-test-with-temp-text
4007 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4008 (org-match-sparse-tree nil
"work")
4009 (search-forward "H1")
4010 (org-invisible-p2)))
4012 (org-test-with-temp-text
4013 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4014 (org-match-sparse-tree nil
"work")
4015 (search-forward "H2")
4016 (org-invisible-p2)))
4017 ;; Match group tags with hard brackets.
4019 (org-test-with-temp-text
4020 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4021 (org-match-sparse-tree nil
"work")
4022 (search-forward "H1")
4023 (org-invisible-p2)))
4025 (org-test-with-temp-text
4026 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4027 (org-match-sparse-tree nil
"work")
4028 (search-forward "H2")
4029 (org-invisible-p2)))
4030 ;; Match tags in hierarchies
4032 (org-test-with-temp-text
4033 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4034 #+TAGS: [ Lev_2 : Lev_3 ]\n
4035 #+TAGS: { Lev_3 : Lev_4 }\n
4036 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4037 (org-match-sparse-tree nil
"Lev_1")
4038 (search-forward "H4")
4039 (org-invisible-p2)))
4040 ;; Match regular expressions in tags
4042 (org-test-with-temp-text
4043 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4044 (org-match-sparse-tree nil
"Lev")
4045 (search-forward "H1")
4046 (org-invisible-p2)))
4048 (org-test-with-temp-text
4049 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4050 (org-match-sparse-tree nil
"Lev")
4051 (search-forward "H1")
4052 (org-invisible-p2)))
4053 ;; Match properties.
4055 (org-test-with-temp-text
4056 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4057 (org-match-sparse-tree nil
"A=\"1\"")
4058 (search-forward "H2")
4059 (org-invisible-p2)))
4061 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4062 (org-match-sparse-tree nil
"A=\"1\"")
4063 (search-forward "H2")
4064 (org-invisible-p2)))
4065 ;; Case is not significant when matching properties.
4067 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4068 (org-match-sparse-tree nil
"a=\"1\"")
4069 (search-forward "H2")
4070 (org-invisible-p2)))
4072 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4073 (org-match-sparse-tree nil
"A=\"1\"")
4074 (search-forward "H2")
4075 (org-invisible-p2)))
4076 ;; Match special LEVEL property.
4078 (org-test-with-temp-text "* H\n** H1\n*** H2"
4079 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4080 (search-forward "H1")
4081 (org-invisible-p2)))
4083 (org-test-with-temp-text "* H\n** H1\n*** H2"
4084 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4085 (search-forward "H2")
4086 (org-invisible-p2)))
4087 ;; Comparison operators when matching properties.
4089 (org-test-with-temp-text
4090 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4091 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4092 (search-forward "H1")
4093 (org-invisible-p2)))
4095 (org-test-with-temp-text
4096 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4097 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4098 (search-forward "H2")
4099 (org-invisible-p2)))
4100 ;; Regexp match on properties values.
4102 (org-test-with-temp-text
4103 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4104 (org-match-sparse-tree nil
"A={f.*}")
4105 (search-forward "H1")
4106 (org-invisible-p2)))
4108 (org-test-with-temp-text
4109 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4110 (org-match-sparse-tree nil
"A={f.*}")
4111 (search-forward "H2")
4112 (org-invisible-p2)))
4113 ;; With an optional argument, limit match to TODO entries.
4115 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4116 (org-match-sparse-tree t
"tag")
4117 (search-forward "H1")
4118 (org-invisible-p2)))
4120 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4121 (org-match-sparse-tree t
"tag")
4122 (search-forward "H2")
4123 (org-invisible-p2))))
4128 (ert-deftest test-org
/time-stamp
()
4129 "Test `org-time-stamp' specifications."
4130 ;; Insert chosen time stamp at point.
4133 "Te<2014-03-04 .*?>xt"
4134 (org-test-with-temp-text "Te<point>xt"
4135 (flet ((org-read-date
4137 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4138 (org-time-stamp nil
)
4140 ;; With a prefix argument, also insert time.
4143 "Te<2014-03-04 .*? 00:41>xt"
4144 (org-test-with-temp-text "Te<point>xt"
4145 (flet ((org-read-date
4147 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
4148 (org-time-stamp '(4))
4150 ;; With two universal prefix arguments, insert an active timestamp
4151 ;; with the current time without prompting the user.
4154 "Te<2014-03-04 .*? 00:41>xt"
4155 (org-test-with-temp-text "Te<point>xt"
4156 (flet ((current-time
4158 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
4159 (org-time-stamp '(16))
4161 ;; When optional argument is non-nil, insert an inactive timestamp.
4164 "Te\\[2014-03-04 .*?\\]xt"
4165 (org-test-with-temp-text "Te<point>xt"
4166 (flet ((org-read-date
4168 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4169 (org-time-stamp nil t
)
4171 ;; When called from a timestamp, replace existing one.
4175 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4176 (flet ((org-read-date
4178 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4179 (org-time-stamp nil
)
4183 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4184 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4185 (flet ((org-read-date
4187 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4188 (org-time-stamp nil
)
4190 ;; When replacing a timestamp, preserve repeater, if any.
4193 "<2014-03-04 .*? \\+2y>"
4194 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4195 (flet ((org-read-date
4197 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4198 (org-time-stamp nil
)
4200 ;; When called twice in a raw, build a date range.
4203 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4204 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4205 (flet ((org-read-date
4207 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4208 (let ((last-command 'org-time-stamp
)
4209 (this-command 'org-time-stamp
))
4210 (org-time-stamp nil
))
4211 (buffer-string))))))
4213 (ert-deftest test-org
/timestamp-has-time-p
()
4214 "Test `org-timestamp-has-time-p' specifications."
4217 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4218 (org-timestamp-has-time-p (org-element-context))))
4221 (org-test-with-temp-text "<2012-03-29 Thu>"
4222 (org-timestamp-has-time-p (org-element-context)))))
4224 (ert-deftest test-org
/timestamp-format
()
4225 "Test `org-timestamp-format' specifications."
4230 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4231 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4236 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4237 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4239 (ert-deftest test-org
/timestamp-split-range
()
4240 "Test `org-timestamp-split-range' specifications."
4241 ;; Extract range start (active).
4244 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4245 (let ((ts (org-timestamp-split-range (org-element-context))))
4246 (mapcar (lambda (p) (org-element-property p ts
))
4247 '(:year-end
:month-end
:day-end
))))))
4248 ;; Extract range start (inactive)
4251 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4252 (let ((ts (org-timestamp-split-range (org-element-context))))
4253 (mapcar (lambda (p) (org-element-property p ts
))
4254 '(:year-end
:month-end
:day-end
))))))
4255 ;; Extract range end (active).
4258 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4259 (let ((ts (org-timestamp-split-range
4260 (org-element-context) t
)))
4261 (mapcar (lambda (p) (org-element-property p ts
))
4262 '(:year-end
:month-end
:day-end
))))))
4263 ;; Extract range end (inactive)
4266 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4267 (let ((ts (org-timestamp-split-range
4268 (org-element-context) t
)))
4269 (mapcar (lambda (p) (org-element-property p ts
))
4270 '(:year-end
:month-end
:day-end
))))))
4271 ;; Return the timestamp if not a range.
4273 (org-test-with-temp-text "[2012-03-29 Thu]"
4274 (let* ((ts-orig (org-element-context))
4275 (ts-copy (org-timestamp-split-range ts-orig
)))
4276 (eq ts-orig ts-copy
))))
4278 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4279 (let* ((ts-orig (org-element-context))
4280 (ts-copy (org-timestamp-split-range ts-orig
)))
4281 (eq ts-orig ts-copy
)))))
4283 (ert-deftest test-org
/timestamp-translate
()
4284 "Test `org-timestamp-translate' specifications."
4285 ;; Translate whole date range.
4288 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4289 (let ((org-display-custom-times t
)
4290 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4291 (org-timestamp-translate (org-element-context))))))
4292 ;; Translate date range start.
4295 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4296 (let ((org-display-custom-times t
)
4297 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4298 (org-timestamp-translate (org-element-context) 'start
)))))
4299 ;; Translate date range end.
4302 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4303 (let ((org-display-custom-times t
)
4304 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4305 (org-timestamp-translate (org-element-context) 'end
)))))
4306 ;; Translate time range.
4309 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4310 (let ((org-display-custom-times t
)
4311 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4312 (org-timestamp-translate (org-element-context))))))
4313 ;; Translate non-range timestamp.
4316 (org-test-with-temp-text "<2012-03-29 Thu>"
4317 (let ((org-display-custom-times t
)
4318 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4319 (org-timestamp-translate (org-element-context))))))
4320 ;; Do not change `diary' timestamps.
4322 (equal "<%%(org-float t 4 2)>"
4323 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4324 (let ((org-display-custom-times t
)
4325 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4326 (org-timestamp-translate (org-element-context)))))))
4332 (ert-deftest test-org
/flag-drawer
()
4333 "Test `org-flag-drawer' specifications."
4336 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4338 (get-char-property (line-end-position) 'invisible
)))
4341 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4343 (org-flag-drawer nil
)
4344 (get-char-property (line-end-position) 'invisible
)))
4345 ;; Test optional argument.
4347 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4348 (let ((drawer (save-excursion (search-forward ":D2")
4349 (org-element-at-point))))
4350 (org-flag-drawer t drawer
)
4351 (get-char-property (progn (search-forward ":D2") (line-end-position))
4354 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4355 (let ((drawer (save-excursion (search-forward ":D2")
4356 (org-element-at-point))))
4357 (org-flag-drawer t drawer
)
4358 (get-char-property (line-end-position) 'invisible
))))
4359 ;; Do not hide fake drawers.
4361 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4364 (get-char-property (line-end-position) 'invisible
)))
4365 ;; Do not hide incomplete drawers.
4367 (org-test-with-temp-text ":D:\nparagraph"
4370 (get-char-property (line-end-position) 'invisible
)))
4371 ;; Do not hide drawers when called from final blank lines.
4373 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4374 (goto-char (point-max))
4376 (goto-char (point-min))
4377 (get-char-property (line-end-position) 'invisible
)))
4378 ;; Don't leave point in an invisible part of the buffer when hiding
4381 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4382 (goto-char (point-max))
4384 (get-char-property (point) 'invisible
))))
4386 (ert-deftest test-org
/hide-block-toggle
()
4387 "Test `org-hide-block-toggle' specifications."
4388 ;; Error when not at a block.
4390 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4391 (org-hide-block-toggle 'off
)
4392 (get-char-property (line-end-position) 'invisible
)))
4395 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4396 (org-hide-block-toggle)
4397 (get-char-property (line-end-position) 'invisible
)))
4399 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4400 (org-hide-block-toggle)
4401 (get-char-property (line-end-position) 'invisible
)))
4402 ;; Show block unconditionally when optional argument is `off'.
4404 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4405 (org-hide-block-toggle)
4406 (org-hide-block-toggle 'off
)
4407 (get-char-property (line-end-position) 'invisible
)))
4409 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4410 (org-hide-block-toggle 'off
)
4411 (get-char-property (line-end-position) 'invisible
)))
4412 ;; Hide block unconditionally when optional argument is non-nil.
4414 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4415 (org-hide-block-toggle t
)
4416 (get-char-property (line-end-position) 'invisible
)))
4418 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4419 (org-hide-block-toggle)
4420 (org-hide-block-toggle t
)
4421 (get-char-property (line-end-position) 'invisible
)))
4422 ;; Do not hide block when called from final blank lines.
4424 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4425 (org-hide-block-toggle)
4426 (goto-char (point-min))
4427 (get-char-property (line-end-position) 'invisible
)))
4428 ;; Don't leave point in an invisible part of the buffer when hiding
4431 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4432 (org-hide-block-toggle)
4433 (get-char-property (point) 'invisible
))))
4435 (ert-deftest test-org
/hide-block-toggle-maybe
()
4436 "Test `org-hide-block-toggle-maybe' specifications."
4438 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4439 (org-hide-block-toggle-maybe)))
4441 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4443 (ert-deftest test-org
/show-set-visibility
()
4444 "Test `org-show-set-visibility' specifications."
4445 ;; Do not throw an error before first heading.
4447 (org-test-with-temp-text "Preamble\n* Headline"
4448 (org-show-set-visibility 'tree
)
4450 ;; Test all visibility spans, both on headline and in entry.
4451 (let ((list-visible-lines
4452 (lambda (state headerp
)
4453 (org-test-with-temp-text "* Grandmother (0)
4464 **** The other child (11)
4469 (search-forward (if headerp
"Self" "Match"))
4470 (org-show-set-visibility state
)
4471 (goto-char (point-min))
4472 (let (result (line 0))
4474 (unless (org-invisible-p2) (push line result
))
4477 (nreverse result
))))))
4478 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4479 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4480 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4481 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4482 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4483 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4484 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4485 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4486 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4487 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4488 (funcall list-visible-lines
'tree nil
)))
4489 (should (equal '(0 1 3 4 5 7 12 13)
4490 (funcall list-visible-lines
'canonical t
)))
4491 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4492 (funcall list-visible-lines
'canonical nil
)))))
4497 ;;; test-org.el ends here