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/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (call-interactively #'org-comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (call-interactively #'org-comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# <point>Comment"
106 (let ((org-adapt-indentation t
))
107 (call-interactively #'org-comment-dwim
))
109 ;; Also recognize single # at column 0 as comments.
112 (org-test-with-temp-text "# Comment"
113 (call-interactively #'org-comment-dwim
)
115 ;; Region selected and only comments and blank lines within it:
116 ;; un-comment all commented lines.
118 (equal "Comment 1\n\nComment 2"
119 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
120 (transient-mark-mode 1)
121 (push-mark (point) t t
)
122 (goto-char (point-max))
123 (call-interactively #'org-comment-dwim
)
125 ;; Region selected without comments: comment all lines if
126 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
128 (equal "# Comment 1\n\n# Comment 2"
129 (org-test-with-temp-text "Comment 1\n\nComment 2"
130 (transient-mark-mode 1)
131 (push-mark (point) t t
)
132 (goto-char (point-max))
133 (let ((comment-empty-lines nil
))
134 (call-interactively #'org-comment-dwim
))
137 (equal "# Comment 1\n# \n# Comment 2"
138 (org-test-with-temp-text "Comment 1\n\nComment 2"
139 (transient-mark-mode 1)
140 (push-mark (point) t t
)
141 (goto-char (point-max))
142 (let ((comment-empty-lines t
))
143 (call-interactively #'org-comment-dwim
))
145 ;; In front of a keyword without region, insert a new comment.
147 (equal "# \n#+KEYWORD: value"
148 (org-test-with-temp-text "#+KEYWORD: value"
149 (call-interactively #'org-comment-dwim
)
151 ;; In a source block, use appropriate syntax.
154 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
155 (let ((org-edit-src-content-indentation 2))
156 (call-interactively #'org-comment-dwim
))
157 (buffer-substring-no-properties (line-beginning-position)
160 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
161 (org-test-with-temp-text
162 "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
163 (transient-mark-mode 1)
164 (push-mark (point) t t
)
166 (let ((org-edit-src-content-indentation 2))
167 (call-interactively #'org-comment-dwim
))
172 ;;; Date and time analysis
174 (ert-deftest test-org
/org-read-date
()
175 "Test `org-read-date' specifications."
176 ;; Parse ISO date with abbreviated year and month.
177 (should (equal "2012-03-29 16:40"
178 (let ((org-time-was-given t
))
179 (org-read-date t nil
"12-3-29 16:40"))))
180 ;; Parse Europeans dates.
181 (should (equal "2012-03-29 16:40"
182 (let ((org-time-was-given t
))
183 (org-read-date t nil
"29.03.2012 16:40"))))
184 ;; Parse Europeans dates without year.
185 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
186 (let ((org-time-was-given t
))
187 (org-read-date t nil
"29.03. 16:40"))))
188 ;; Relative date applied to current time if there is single
189 ;; plus/minus, or to default date when there are two of them.
193 (cl-letf (((symbol-function 'current-time
)
195 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
198 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
202 (cl-letf (((symbol-function 'current-time
)
204 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
207 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 ;; When `org-read-date-prefer-future' is non-nil, prefer future
209 ;; dates (relatively to now) when incomplete. Otherwise, use
214 (cl-letf (((symbol-function 'current-time
)
216 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
217 (let ((org-read-date-prefer-future t
))
218 (org-read-date t nil
"1")))))
222 (cl-letf (((symbol-function 'current-time
)
224 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
225 (let ((org-read-date-prefer-future t
))
226 (org-read-date t nil
"3-4")))))
230 (cl-letf (((symbol-function 'current-time
)
232 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
233 (let ((org-read-date-prefer-future nil
))
234 (org-read-date t nil
"3-4")))))
235 ;; When set to `org-read-date-prefer-future' is set to `time', read
236 ;; day is moved to tomorrow if specified hour is before current
237 ;; time. However, it only happens in no other part of the date is
242 (cl-letf (((symbol-function 'current-time
)
244 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
245 (let ((org-read-date-prefer-future 'time
))
246 (org-read-date t nil
"00:40" nil
)))))
250 (cl-letf (((symbol-function 'current-time
)
252 (apply #'encode-time
(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.
260 (cl-letf (((symbol-function 'current-time
)
262 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
263 (let ((org-read-date-prefer-future t
))
266 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
270 (cl-letf (((symbol-function 'current-time
)
272 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
273 (let ((org-read-date-prefer-future t
))
276 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
278 (ert-deftest test-org
/org-parse-time-string
()
279 "Test `org-parse-time-string'."
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 16:40>")
285 '(0 40 16 29 3 2012 nil nil nil
)))
286 (should (equal (org-parse-time-string "<2012-03-29>")
287 '(0 0 0 29 3 2012 nil nil nil
)))
288 (should (equal (org-parse-time-string "<2012-03-29>" t
)
289 '(0 nil nil
29 3 2012 nil nil nil
))))
291 (ert-deftest test-org
/closest-date
()
292 "Test `org-closest-date' specifications."
294 ;; Time stamps without a repeater are returned unchanged.
298 (calendar-gregorian-from-absolute
299 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
300 ;; Time stamps with a null repeater are returned unchanged.
304 (calendar-gregorian-from-absolute
305 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
306 ;; if PREFER is set to `past' always return a date before, or equal
311 (calendar-gregorian-from-absolute
312 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
318 ;; if PREFER is set to `future' always return a date before, or equal
323 (calendar-gregorian-from-absolute
324 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
330 ;; If PREFER is neither `past' nor `future', select closest date.
334 (calendar-gregorian-from-absolute
335 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
341 ;; Test "day" repeater.
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
348 (calendar-gregorian-from-absolute
349 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
350 ;; Test "month" repeater.
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
357 (calendar-gregorian-from-absolute
358 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
359 ;; Test "year" repeater.
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
366 (calendar-gregorian-from-absolute
367 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
369 (ert-deftest test-org
/deadline-close-p
()
370 "Test `org-deadline-close-p' specifications."
371 ;; Pretend that the current time is 2016-06-03 Fri 01:43
372 (cl-letf (((symbol-function 'current-time
)
375 (org-parse-time-string "2016-06-03 Fri 01:43")))))
376 ;; Timestamps are close if they are within `ndays' of lead time.
377 (org-test-with-temp-text "* Heading"
378 (should (org-deadline-close-p "2016-06-03 Fri" 0))
379 (should (org-deadline-close-p "2016-06-02 Thu" 0))
380 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
381 (should (org-deadline-close-p "2016-06-04 Sat" 1))
382 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
383 ;; Read `ndays' from timestamp if argument not given.
384 (org-test-with-temp-text "* H"
385 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
386 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
387 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
388 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
389 ;; Prefer `ndays' argument over lead time in timestamp.
390 (org-test-with-temp-text "* H"
391 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
392 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
393 ;; Completed tasks are never close.
394 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
395 (org-test-with-temp-text "* TODO Heading"
396 (should (org-deadline-close-p "2016-06-03")))
397 (org-test-with-temp-text "* DONE Heading"
398 (should-not (org-deadline-close-p "2016-06-03"))))))
403 (ert-deftest test-org
/insert-property-drawer
()
404 "Test `org-insert-property-drawer' specifications."
405 ;; Error before first headline.
406 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
407 ;; Insert drawer right after headline if there is no planning line,
408 ;; or after it otherwise.
410 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
411 (org-test-with-temp-text "* H\nParagraph<point>"
412 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
415 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text
417 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
418 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
420 ;; Indent inserted drawer.
422 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
423 (org-test-with-temp-text "* H\nParagraph<point>"
424 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
426 ;; Handle insertion at eob.
428 (equal "* H\n:PROPERTIES:\n:END:\n"
429 (org-test-with-temp-text "* H"
430 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
432 ;; Skip inlinetasks before point.
433 (when (featurep 'org-inlinetask
)
435 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
436 (org-test-with-temp-text
437 "* H\n*************** I\n*************** END\nP<point>"
438 (let ((org-adapt-indentation nil
)
439 (org-inlinetask-min-level 15))
440 (org-insert-property-drawer))
442 ;; Correctly set drawer in an inlinetask.
443 (when (featurep 'org-inlinetask
)
445 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
446 (org-test-with-temp-text
447 "* H\n*************** I\nP<point>\n*************** END"
448 (let ((org-adapt-indentation nil
)
449 (org-inlinetask-min-level 15))
450 (org-insert-property-drawer))
456 (ert-deftest test-org
/fill-element
()
457 "Test `org-fill-element' specifications."
458 ;; At an Org table, align it.
461 (org-test-with-temp-text "|a|"
465 (equal "#+name: table\n| a |\n"
466 (org-test-with-temp-text "#+name: table\n| a |\n"
469 ;; At a paragraph, preserve line breaks.
470 (org-test-with-temp-text "some \\\\\nlong\ntext"
471 (let ((fill-column 20))
473 (should (equal (buffer-string) "some \\\\\nlong text"))))
474 ;; Correctly fill a paragraph when point is at its very end.
477 (org-test-with-temp-text "A\nB"
478 (let ((fill-column 20))
479 (goto-char (point-max))
482 ;; Correctly fill the last paragraph of a greater element.
484 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
485 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
486 (let ((fill-column 8))
491 ;; Correctly fill an element in a narrowed buffer.
494 (org-test-with-temp-text "01234 6789"
495 (let ((fill-column 5))
496 (narrow-to-region 1 8)
499 ;; Handle `adaptive-fill-regexp' in paragraphs.
502 (org-test-with-temp-text "> a\n> b"
503 (let ((fill-column 5)
504 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
507 ;; Special case: Fill first paragraph when point is at an item or
508 ;; a plain-list or a footnote reference.
511 (org-test-with-temp-text "- A\n B"
512 (let ((fill-column 20))
517 (org-test-with-temp-text "[fn:1] A\nB"
518 (let ((fill-column 20))
521 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
522 (let ((fill-column 20))
524 (should (equal (buffer-string)
525 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
526 ;; Fill contents of `comment-block' elements.
529 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
530 (let ((fill-column 20))
534 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
535 ;; Fill `comment' elements.
538 (org-test-with-temp-text " # A\n # B"
539 (let ((fill-column 20))
542 ;; Do not mix consecutive comments when filling one of them.
544 (equal "# A B\n\n# C"
545 (org-test-with-temp-text "# A\n# B\n\n# C"
546 (let ((fill-column 20))
549 ;; Use commented empty lines as separators when filling comments.
551 (equal "# A B\n#\n# C"
552 (org-test-with-temp-text "# A\n# B\n#\n# C"
553 (let ((fill-column 20))
556 ;; Handle `adaptive-fill-regexp' in comments.
559 (org-test-with-temp-text "# > a\n# > b"
560 (let ((fill-column 20)
561 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
564 ;; Do nothing at affiliated keywords.
566 (equal "#+NAME: para\nSome\ntext."
567 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
568 (let ((fill-column 20))
571 ;; Do not move point after table when filling a table.
573 (org-test-with-temp-text "| a | b |\n| c | d |\n"
577 ;; Do not fill "n" macro, with or without arguments, followed by
578 ;; a dot or a closing parenthesis since it could be confused with
579 ;; a numbered bullet.
581 (equal "123456789\n{{{n}}}."
582 (org-test-with-temp-text "123456789 {{{n}}}."
583 (let ((fill-column 10))
587 (equal "123456789\n{{{n}}}\)"
588 (org-test-with-temp-text "123456789 {{{n}}}\)"
589 (let ((fill-column 10))
593 (equal "123456789\n{{{n()}}}."
594 (org-test-with-temp-text "123456789 {{{n()}}}."
595 (let ((fill-column 10))
599 (equal "123456789\n{{{n(counter)}}}."
600 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
601 (let ((fill-column 10))
605 (ert-deftest test-org
/auto-fill-function
()
606 "Test auto-filling features."
607 ;; Auto fill paragraph.
610 (org-test-with-temp-text "12345 7890"
611 (let ((fill-column 5))
613 (org-auto-fill-function)
615 ;; Auto fill first paragraph in an item.
617 (equal "- 12345\n 7890"
618 (org-test-with-temp-text "- 12345 7890"
619 (let ((fill-column 7))
621 (org-auto-fill-function)
623 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
625 (equal "> 12345\n 7890"
626 (org-test-with-temp-text "> 12345 7890"
627 (let ((fill-column 10)
628 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
629 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
631 (org-auto-fill-function)
634 (equal "> 12345\n> 12345\n> 7890"
635 (org-test-with-temp-text "> 12345\n> 12345 7890"
636 (let ((fill-column 10)
637 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
638 (goto-char (point-max))
639 (org-auto-fill-function)
642 (equal " 12345\n *12345\n *12345"
643 (org-test-with-temp-text " 12345\n *12345 12345"
644 (let ((fill-column 10)
645 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
646 (goto-char (point-max))
647 (org-auto-fill-function)
649 ;; Auto fill comments.
651 (equal " # 12345\n # 7890"
652 (org-test-with-temp-text " # 12345 7890"
653 (let ((fill-column 10))
655 (org-auto-fill-function)
657 ;; A hash within a line isn't a comment.
659 (equal "12345 # 7890\n# 1"
660 (org-test-with-temp-text "12345 # 7890 1"
661 (let ((fill-column 12))
663 (org-auto-fill-function)
665 ;; Correctly interpret empty prefix.
667 (equal "# a\n# b\nRegular\n# paragraph"
668 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
669 (let ((fill-column 12))
671 (org-auto-fill-function)
673 ;; Comment block: auto fill contents.
675 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
676 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
677 (let ((fill-column 5))
680 (org-auto-fill-function)
683 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
684 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
685 (let ((fill-column 5))
688 (org-auto-fill-function)
690 ;; Do not fill if a new item could be created.
693 (org-test-with-temp-text "12345 - 90"
694 (let ((fill-column 5))
696 (org-auto-fill-function)
698 ;; Do not fill if a line break could be introduced.
700 (equal "123\\\\\n7890"
701 (org-test-with-temp-text "123\\\\ 7890"
702 (let ((fill-column 6))
704 (org-auto-fill-function)
706 ;; Do not fill affiliated keywords.
708 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
709 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
710 (let ((fill-column 20))
712 (org-auto-fill-function)
719 (ert-deftest test-org
/indent-line
()
720 "Test `org-indent-line' specifications."
721 ;; Do not indent diary sexps, footnote definitions or headlines.
724 (org-test-with-temp-text "%%(org-calendar-holiday)"
726 (org-get-indentation))))
729 (org-test-with-temp-text "[fn:1] fn"
730 (let ((org-adapt-indentation t
)) (org-indent-line))
731 (org-get-indentation))))
734 (org-test-with-temp-text "* H"
736 (org-get-indentation))))
737 ;; Do not indent before first headline.
740 (org-test-with-temp-text ""
742 (org-get-indentation))))
743 ;; Indent according to headline level otherwise, unless
744 ;; `org-adapt-indentation' is nil.
747 (org-test-with-temp-text "* H\n<point>A"
748 (let ((org-adapt-indentation t
)) (org-indent-line))
749 (org-get-indentation))))
752 (org-test-with-temp-text "* H\n<point>\nA"
753 (let ((org-adapt-indentation t
)) (org-indent-line))
754 (org-get-indentation))))
757 (org-test-with-temp-text "* H\n<point>A"
758 (let ((org-adapt-indentation nil
)) (org-indent-line))
759 (org-get-indentation))))
760 ;; Indenting preserves point position.
762 (org-test-with-temp-text "* H\nA<point>B"
763 (let ((org-adapt-indentation t
)) (org-indent-line))
765 ;; Do not change indentation at an item or a LaTeX environment.
768 (org-test-with-temp-text "* H\n<point> - A"
769 (let ((org-adapt-indentation t
)) (org-indent-line))
770 (org-get-indentation))))
773 (org-test-with-temp-text
774 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
776 (org-get-indentation))))
777 ;; On blank lines at the end of a list, indent like last element
778 ;; within it if the line is still in the list. If the last element
779 ;; is an item, indent like its contents. Otherwise, indent like the
783 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
784 (let ((org-adapt-indentation t
)) (org-indent-line))
785 (org-get-indentation))))
788 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
789 (let ((org-adapt-indentation t
)) (org-indent-line))
790 (org-get-indentation))))
793 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
794 (let ((org-adapt-indentation t
)) (org-indent-line))
795 (org-get-indentation))))
798 (org-test-with-temp-text "* H\n- A\n - \n<point>"
799 (let ((org-adapt-indentation t
)) (org-indent-line))
800 (org-get-indentation))))
803 (org-test-with-temp-text
804 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
805 (let ((org-adapt-indentation t
)) (org-indent-line))
806 (org-get-indentation))))
809 (org-test-with-temp-text "- A\n B\n\n<point>"
810 (let ((org-adapt-indentation nil
)) (org-indent-line))
811 (org-get-indentation))))
814 (org-test-with-temp-text
815 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
816 (let ((org-adapt-indentation nil
)) (org-indent-line))
817 (org-get-indentation))))
818 ;; Likewise, on a blank line at the end of a footnote definition,
819 ;; indent at column 0 if line belongs to the definition. Otherwise,
820 ;; indent like the definition itself.
823 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
824 (let ((org-adapt-indentation t
)) (org-indent-line))
825 (org-get-indentation))))
828 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
829 (let ((org-adapt-indentation t
)) (org-indent-line))
830 (org-get-indentation))))
831 ;; After the end of the contents of a greater element, indent like
832 ;; the beginning of the element.
835 (org-test-with-temp-text
836 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
838 (org-get-indentation))))
839 ;; On blank lines after a paragraph, indent like its last non-empty
843 (org-test-with-temp-text " Paragraph\n\n<point>"
845 (org-get-indentation))))
846 ;; At the first line of an element, indent like previous element's
847 ;; first line, ignoring footnotes definitions and inline tasks, or
848 ;; according to parent.
851 (org-test-with-temp-text "A\n\n B\n\nC<point>"
853 (org-get-indentation))))
856 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
858 (org-get-indentation))))
861 (org-test-with-temp-text
862 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
864 (org-get-indentation))))
865 ;; Within code part of a source block, use language major mode if
866 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
867 ;; according to line above.
870 (org-test-with-temp-text
871 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
872 (let ((org-src-tab-acts-natively t
)
873 (org-edit-src-content-indentation 0))
875 (org-get-indentation))))
878 (org-test-with-temp-text
879 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
880 (let ((org-src-tab-acts-natively nil
)
881 (org-edit-src-content-indentation 0))
883 (org-get-indentation))))
884 ;; Otherwise, indent like the first non-blank line above.
887 (org-test-with-temp-text
888 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
890 (org-get-indentation))))
891 ;; Align node properties according to `org-property-format'. Handle
892 ;; nicely empty values.
894 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
895 (org-test-with-temp-text
896 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
897 (let ((org-property-format "%-10s %s")) (org-indent-line))
900 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
901 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
902 (let ((org-property-format "%-10s %s")) (org-indent-line))
905 (ert-deftest test-org
/indent-region
()
906 "Test `org-indent-region' specifications."
910 (org-test-with-temp-text " A\nB\n C"
911 (org-indent-region (point-min) (point-max))
913 ;; Indent greater elements along with their contents.
915 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
916 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
917 (org-indent-region (point-min) (point-max))
919 ;; Ignore contents of verse blocks. Only indent block delimiters.
921 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
922 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
923 (org-indent-region (point-min) (point-max))
926 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
927 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
928 (org-indent-region (point-min) (point-max))
930 ;; Indent example blocks as a single block, unless indentation
931 ;; should be preserved. In this case only indent the block markers.
933 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
934 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
935 (org-indent-region (point-min) (point-max))
938 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
939 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
940 (org-indent-region (point-min) (point-max))
943 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
944 (org-test-with-temp-text
945 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
946 (org-indent-region (point-min) (point-max))
949 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
950 (org-test-with-temp-text
951 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
952 (let ((org-src-preserve-indentation t
))
953 (org-indent-region (point-min) (point-max)))
955 ;; Treat export blocks as a whole.
957 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
958 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
959 (org-indent-region (point-min) (point-max))
962 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
963 (org-test-with-temp-text
964 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
965 (org-indent-region (point-min) (point-max))
967 ;; Indent according to mode if `org-src-tab-acts-natively' is
968 ;; non-nil. Otherwise, do not indent code at all.
970 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
971 (org-test-with-temp-text
972 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
973 (let ((org-src-tab-acts-natively t
)
974 (org-edit-src-content-indentation 0))
975 (org-indent-region (point-min) (point-max)))
978 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
979 (org-test-with-temp-text
980 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
981 (let ((org-src-tab-acts-natively nil
)
982 (org-edit-src-content-indentation 0))
983 (org-indent-region (point-min) (point-max)))
985 ;; Align node properties according to `org-property-format'. Handle
986 ;; nicely empty values.
988 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
989 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
990 (let ((org-property-format "%-10s %s")
991 (org-adapt-indentation nil
))
992 (org-indent-region (point) (point-max)))
995 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
996 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
997 (let ((org-property-format "%-10s %s")
998 (org-adapt-indentation nil
))
999 (org-indent-region (point) (point-max)))
1001 ;; Indent plain lists.
1003 (equal "- A\n B\n - C\n\n D"
1004 (org-test-with-temp-text "- A\n B\n - C\n\n D"
1005 (org-indent-region (point-min) (point-max))
1009 (org-test-with-temp-text " - A\n\n - B"
1010 (org-indent-region (point-min) (point-max))
1012 ;; Indent footnote definitions.
1014 (equal "[fn:1] Definition\n\nDefinition"
1015 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1016 (org-indent-region (point-min) (point-max))
1018 ;; Special case: Start indenting on a blank line.
1020 (equal "\nParagraph"
1021 (org-test-with-temp-text "\n Paragraph"
1022 (org-indent-region (point-min) (point-max))
1029 (ert-deftest test-org
/delete-indentation
()
1030 "Test `org-delete-indentation' specifications."
1032 (should (equal "foo bar"
1033 (org-test-with-temp-text
1035 (org-delete-indentation)
1037 ;; With optional argument.
1038 (should (equal "foo bar"
1039 (org-test-with-temp-text
1041 (org-delete-indentation t
)
1043 ;; At headline text should be appended to the headline text.
1045 (equal"* foo bar :tag:"
1046 (let (org-auto-align-tags)
1047 (org-test-with-temp-text
1048 "* foo :tag:\n bar<point>"
1049 (org-delete-indentation)
1052 (equal "* foo bar :tag:"
1053 (let (org-auto-align-tags)
1054 (org-test-with-temp-text
1055 "* foo <point>:tag:\n bar"
1056 (org-delete-indentation t
)
1057 (buffer-string))))))
1059 (ert-deftest test-org
/return
()
1060 "Test `org-return' specifications."
1063 (equal "Para\ngraph"
1064 (org-test-with-temp-text "Para<point>graph"
1067 ;; With optional argument, indent line.
1069 (equal " Para\n graph"
1070 (org-test-with-temp-text " Para<point>graph"
1073 ;; On a table, call `org-table-next-row'.
1075 (org-test-with-temp-text "| <point>a |\n| b |"
1077 (looking-at-p "b")))
1078 ;; Open link or timestamp under point when `org-return-follows-link'
1081 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1082 (let ((org-return-follows-link t
)
1083 (org-link-search-must-match-exact-headline nil
))
1085 (looking-at-p "<<target>>")))
1087 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1088 (let ((org-return-follows-link nil
)) (org-return))
1089 (looking-at-p "<<target>>")))
1091 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1092 (let ((org-return-follows-link t
)) (org-return))
1093 (looking-at-p "* b")))
1095 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1096 (let ((org-return-follows-link t
)
1097 (org-link-search-must-match-exact-headline nil
))
1099 (looking-at-p "<<target>>")))
1101 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1102 (let ((org-return-follows-link t
)
1103 (org-link-search-must-match-exact-headline nil
))
1105 (looking-at-p "<<target>>")))
1106 ;; When `org-return-follows-link' is non-nil, tolerate links and
1107 ;; timestamps in comments, node properties, etc.
1109 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1110 (let ((org-return-follows-link t
)
1111 (org-link-search-must-match-exact-headline nil
))
1113 (looking-at-p "<<target>>")))
1115 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1116 (let ((org-return-follows-link nil
)) (org-return))
1117 (looking-at-p "<<target>>")))
1119 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1120 (let ((org-return-follows-link t
)
1121 (org-link-search-must-match-exact-headline nil
))
1123 (looking-at-p "<<target>>")))
1124 ;; However, do not open link when point is in a table.
1126 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1127 (let ((org-return-follows-link t
)) (org-return))
1128 (looking-at-p "between")))
1129 ;; Special case: in a list, when indenting, do not break structure.
1132 (org-test-with-temp-text "- A <point>B"
1137 (org-test-with-temp-text "- A\n<point>- B"
1140 ;; On tags part of a headline, add a newline below it instead of
1143 (equal "* H :tag:\n"
1144 (org-test-with-temp-text "* H :<point>tag:"
1147 ;; Before headline text, add a newline below it instead of breaking
1150 (equal "* TODO H :tag:\n"
1151 (org-test-with-temp-text "* <point>TODO H :tag:"
1155 (equal "* TODO [#B] H :tag:\n"
1156 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1159 (should ;TODO are case-sensitive
1161 (org-test-with-temp-text "* <point>Todo"
1164 ;; At headline text, break headline text but preserve tags.
1166 (equal "* TODO [#B] foo :tag:\nbar"
1167 (let (org-auto-align-tags)
1168 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1171 ;; At bol of headline insert newline.
1174 (org-test-with-temp-text "<point>* h"
1177 ;; Refuse to leave invalid headline in buffer.
1180 (org-test-with-temp-text "*<point> h"
1183 ;; Before first column or after last one in a table, split the
1186 (equal "| a |\n\n| b |"
1187 (org-test-with-temp-text "| a |\n<point>| b |"
1191 (equal "| a |\n\n| b |"
1192 (org-test-with-temp-text "| a |<point>\n| b |"
1195 ;; Do not auto-fill on hitting <RET> inside a property drawer.
1197 (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
1198 (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
1199 (setq-local fill-column
10)
1204 (ert-deftest test-org
/meta-return
()
1205 "Test M-RET (`org-meta-return') specifications."
1206 ;; In a table field insert a row above.
1208 (org-test-with-temp-text "| a |"
1212 (looking-at "| |$")))
1213 ;; In a paragraph change current line into a header.
1215 (org-test-with-temp-text "a"
1218 (looking-at "\* a$")))
1219 ;; In an item insert an item, in this case above.
1221 (org-test-with-temp-text "- a"
1224 (looking-at "- $")))
1225 ;; In a drawer and item insert an item, in this case above.
1227 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1231 (looking-at "- $"))))
1233 (ert-deftest test-org
/insert-heading
()
1234 "Test `org-insert-heading' specifications."
1235 ;; In an empty buffer, insert a new headline.
1238 (org-test-with-temp-text ""
1239 (org-insert-heading)
1241 ;; At the beginning of a line, turn it into a headline.
1244 (org-test-with-temp-text "<point>P"
1245 (org-insert-heading)
1247 ;; In the middle of a line, split the line if allowed, otherwise,
1248 ;; insert the headline at its end.
1250 (equal "Para\n* graph"
1251 (org-test-with-temp-text "Para<point>graph"
1252 (let ((org-M-RET-may-split-line '((default . t
))))
1253 (org-insert-heading))
1256 (equal "Paragraph\n* "
1257 (org-test-with-temp-text "Para<point>graph"
1258 (let ((org-M-RET-may-split-line '((default . nil
))))
1259 (org-insert-heading))
1261 ;; At the beginning of a headline, create one above.
1264 (org-test-with-temp-text "* H"
1265 (org-insert-heading)
1267 ;; In the middle of a headline, split it if allowed.
1270 (org-test-with-temp-text "* H<point>1"
1271 (let ((org-M-RET-may-split-line '((headline . t
))))
1272 (org-insert-heading))
1276 (org-test-with-temp-text "* H<point>1"
1277 (let ((org-M-RET-may-split-line '((headline . nil
))))
1278 (org-insert-heading))
1280 ;; However, splitting cannot happen on TODO keywords, priorities or
1283 (equal "* TODO H1\n* \n"
1284 (org-test-with-temp-text "* TO<point>DO H1"
1285 (let ((org-M-RET-may-split-line '((headline . t
))))
1286 (org-insert-heading))
1289 (equal "* [#A] H1\n* \n"
1290 (org-test-with-temp-text "* [#<point>A] H1"
1291 (let ((org-M-RET-may-split-line '((headline . t
))))
1292 (org-insert-heading))
1295 (equal "* H1 :tag:\n* \n"
1296 (org-test-with-temp-text "* H1 :ta<point>g:"
1297 (let ((org-M-RET-may-split-line '((headline . t
))))
1298 (org-insert-heading))
1300 ;; New headline level depends on the level of the headline above.
1303 (org-test-with-temp-text "** H\n<point>P"
1304 (org-insert-heading)
1307 (equal "** H\nPara\n** graph"
1308 (org-test-with-temp-text "** H\nPara<point>graph"
1309 (let ((org-M-RET-may-split-line '((default . t
))))
1310 (org-insert-heading))
1314 (org-test-with-temp-text "** H"
1315 (org-insert-heading)
1317 ;; When called with one universal argument, insert a new headline at
1318 ;; the end of the current subtree, independently on the position of
1323 (org-test-with-temp-text "* H1\n** H2"
1324 (let ((org-insert-heading-respect-content nil
))
1325 (org-insert-heading '(4)))
1330 (org-test-with-temp-text "* H<point>1\n** H2"
1331 (let ((org-insert-heading-respect-content nil
))
1332 (org-insert-heading '(4)))
1334 ;; When called with two universal arguments, insert a new headline
1335 ;; at the end of the grandparent subtree.
1337 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1338 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1339 (let ((org-insert-heading-respect-content nil
))
1340 (org-insert-heading '(16)))
1342 ;; When optional TOP-LEVEL argument is non-nil, always insert
1343 ;; a level 1 heading.
1345 (equal "* H1\n** H2\n* \n"
1346 (org-test-with-temp-text "* H1\n** H2<point>"
1347 (org-insert-heading nil nil t
)
1350 (equal "* H1\n- item\n* "
1351 (org-test-with-temp-text "* H1\n- item<point>"
1352 (org-insert-heading nil nil t
)
1354 ;; Obey `org-blank-before-new-entry'.
1356 (equal "* H1\n\n* \n"
1357 (org-test-with-temp-text "* H1<point>"
1358 (let ((org-blank-before-new-entry '((heading . t
))))
1359 (org-insert-heading))
1363 (org-test-with-temp-text "* H1<point>"
1364 (let ((org-blank-before-new-entry '((heading . nil
))))
1365 (org-insert-heading))
1368 (equal "* H1\n* H2\n* \n"
1369 (org-test-with-temp-text "* H1\n* H2<point>"
1370 (let ((org-blank-before-new-entry '((heading . auto
))))
1371 (org-insert-heading))
1374 (equal "* H1\n\n* H2\n\n* \n"
1375 (org-test-with-temp-text "* H1\n\n* H2<point>"
1376 (let ((org-blank-before-new-entry '((heading . auto
))))
1377 (org-insert-heading))
1379 ;; Corner case: correctly insert a headline after an empty one.
1382 (org-test-with-temp-text "* <point>"
1383 (org-insert-heading)
1386 (org-test-with-temp-text "* <point>\n"
1387 (org-insert-heading)
1388 (looking-at-p "\n\\'")))
1389 ;; Do not insert spurious headlines when inserting a new headline.
1391 (equal "* H1\n* H2\n* \n"
1392 (org-test-with-temp-text "* H1\n* H2<point>\n"
1393 (org-insert-heading)
1395 ;; Preserve visibility at beginning of line. In particular, when
1396 ;; removing spurious blank lines, do not visually merge heading with
1397 ;; the line visible above.
1399 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1401 (let ((org-blank-before-new-entry '((heading . nil
))))
1402 (org-insert-heading '(4)))
1403 (invisible-p (line-end-position 0))))
1404 ;; Properly handle empty lines when forcing a headline below current
1407 (equal "* H1\n\n* H\n\n* \n"
1408 (org-test-with-temp-text "* H1\n\n* H<point>"
1409 (let ((org-blank-before-new-entry '((heading . t
))))
1410 (org-insert-heading '(4))
1411 (buffer-string))))))
1413 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1414 "Test `org-insert-todo-heading-respect-content' specifications."
1415 ;; Create a TODO heading.
1417 (org-test-with-temp-text "* H1\n Body"
1418 (org-insert-todo-heading-respect-content)
1419 (nth 2 (org-heading-components))))
1420 ;; Add headline at the end of the first subtree
1424 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1425 (org-insert-todo-heading-respect-content)
1426 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1427 ;; In a list, do not create a new item.
1431 (org-test-with-temp-text "* H\n- an item\n- another one"
1432 (search-forward "an ")
1433 (org-insert-todo-heading-respect-content)
1434 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1435 ;; Use the same TODO keyword as current heading.
1439 (org-test-with-temp-text "* TODO\n** WAITING\n"
1440 (org-insert-todo-heading-respect-content)
1441 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1443 (ert-deftest test-org
/clone-with-time-shift
()
1444 "Test `org-clone-subtree-with-time-shift'."
1445 ;; Raise an error before first heading.
1447 (org-test-with-temp-text ""
1448 (org-clone-subtree-with-time-shift 1)))
1449 ;; Raise an error on invalid number of clones.
1451 (org-test-with-temp-text "* Clone me"
1452 (org-clone-subtree-with-time-shift -
1)))
1453 ;; Clone non-repeating once.
1459 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1460 (org-clone-subtree-with-time-shift 1 "+2d")
1461 (replace-regexp-in-string
1462 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1464 ;; Clone repeating once.
1469 * H1\n<2015-06-25 +1w>
1471 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1472 (org-clone-subtree-with-time-shift 1 "+2d")
1473 (replace-regexp-in-string
1474 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1476 ;; Clone non-repeating zero times.
1481 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1482 (org-clone-subtree-with-time-shift 0 "+2d")
1483 (replace-regexp-in-string
1484 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1486 ;; Clone repeating "zero" times.
1490 * H1\n<2015-06-23 +1w>
1492 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1493 (org-clone-subtree-with-time-shift 0 "+2d")
1494 (replace-regexp-in-string
1495 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1497 ;; Clone with blank SHIFT argument.
1501 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1502 (org-clone-subtree-with-time-shift 1 "")
1503 (buffer-substring-no-properties (line-beginning-position 2)
1504 (line-end-position 2)))))
1505 ;; Find time stamps before point. If SHIFT is not specified, ask
1506 ;; for a time shift.
1510 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1511 (org-clone-subtree-with-time-shift 1 "+1d")
1512 (buffer-substring-no-properties (line-beginning-position 2)
1513 (line-end-position 2)))))
1517 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1518 (cl-letf (((symbol-function 'read-from-minibuffer
)
1519 (lambda (&rest args
) "+1d")))
1520 (org-clone-subtree-with-time-shift 1))
1521 (buffer-substring-no-properties (line-beginning-position 2)
1522 (line-end-position 2))))))
1525 ;;; Fixed-Width Areas
1527 (ert-deftest test-org
/toggle-fixed-width
()
1528 "Test `org-toggle-fixed-width' specifications."
1529 ;; No region: Toggle on fixed-width marker in paragraphs.
1532 (org-test-with-temp-text "A"
1533 (org-toggle-fixed-width)
1535 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1538 (org-test-with-temp-text ": A"
1539 (org-toggle-fixed-width)
1541 ;; No region: Toggle on marker in blank lines after elements or just
1542 ;; after a headline.
1545 (org-test-with-temp-text "* H\n"
1547 (org-toggle-fixed-width)
1550 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1551 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1552 (goto-char (point-max))
1553 (org-toggle-fixed-width)
1555 ;; No region: Toggle on marker in front of one line elements (e.g.,
1556 ;; headlines, clocks)
1558 (equal ": * Headline"
1559 (org-test-with-temp-text "* Headline"
1560 (org-toggle-fixed-width)
1563 (equal ": #+KEYWORD: value"
1564 (org-test-with-temp-text "#+KEYWORD: value"
1565 (org-toggle-fixed-width)
1567 ;; No region: error in other situations.
1569 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1571 (org-toggle-fixed-width)
1573 ;; No region: Indentation is preserved.
1576 (org-test-with-temp-text "- A\n B"
1578 (org-toggle-fixed-width)
1580 ;; Region: If it contains only fixed-width elements and blank lines,
1581 ;; toggle off fixed-width markup.
1584 (org-test-with-temp-text ": A\n\n: B"
1585 (transient-mark-mode 1)
1586 (push-mark (point) t t
)
1587 (goto-char (point-max))
1588 (org-toggle-fixed-width)
1590 ;; Region: If it contains anything else, toggle on fixed-width but
1591 ;; not on fixed-width areas.
1593 (equal ": A\n: \n: B\n: \n: C"
1594 (org-test-with-temp-text "A\n\n: B\n\nC"
1595 (transient-mark-mode 1)
1596 (push-mark (point) t t
)
1597 (goto-char (point-max))
1598 (org-toggle-fixed-width)
1600 ;; Region: Ignore blank lines at its end, unless it contains only
1604 (org-test-with-temp-text "A\n\n"
1605 (transient-mark-mode 1)
1606 (push-mark (point) t t
)
1607 (goto-char (point-max))
1608 (org-toggle-fixed-width)
1612 (org-test-with-temp-text "\n\n"
1613 (transient-mark-mode 1)
1614 (push-mark (point) t t
)
1615 (goto-char (point-max))
1616 (org-toggle-fixed-width)
1623 (ert-deftest test-org
/get-heading
()
1624 "Test `org-get-heading' specifications."
1625 ;; Return current heading, even if point is not on it.
1628 (org-test-with-temp-text "* H"
1629 (org-get-heading))))
1632 (org-test-with-temp-text "* H\nText<point>"
1633 (org-get-heading))))
1634 ;; Without any optional argument, return TODO keyword, priority
1635 ;; cookie, COMMENT keyword and tags.
1638 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1639 (org-get-heading))))
1642 (org-test-with-temp-text "* [#A] H"
1643 (org-get-heading))))
1646 (org-test-with-temp-text "* COMMENT H"
1647 (org-get-heading))))
1650 (org-test-with-temp-text "* H :tag:"
1651 (org-get-heading))))
1652 ;; With NO-TAGS argument, ignore tags.
1655 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1656 (org-get-heading t
))))
1659 (org-test-with-temp-text "* H :tag:"
1660 (org-get-heading t
))))
1661 ;; With NO-TODO, ignore TODO keyword.
1664 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1665 (org-get-heading nil t
))))
1668 (org-test-with-temp-text "* H :tag:"
1669 (org-get-heading nil t
))))
1670 ;; TODO keywords are case-sensitive.
1673 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1674 (org-get-heading nil t
))))
1675 ;; With NO-PRIORITY, ignore priority.
1678 (org-test-with-temp-text "* [#A] H"
1679 (org-get-heading nil nil t
))))
1682 (org-test-with-temp-text "* H"
1683 (org-get-heading nil nil t
))))
1686 (org-test-with-temp-text "* TODO [#A] H"
1687 (org-get-heading nil nil t
))))
1688 ;; With NO-COMMENT, ignore COMMENT keyword.
1691 (org-test-with-temp-text "* COMMENT H"
1692 (org-get-heading nil nil nil t
))))
1695 (org-test-with-temp-text "* H"
1696 (org-get-heading nil nil nil t
))))
1698 (equal "TODO [#A] H"
1699 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1700 (org-get-heading nil nil nil t
))))
1701 ;; On an empty headline, return value is consistent.
1702 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1703 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1704 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1705 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1707 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1709 (ert-deftest test-org
/in-commented-heading-p
()
1710 "Test `org-in-commented-heading-p' specifications."
1711 ;; Commented headline.
1713 (org-test-with-temp-text "* COMMENT Headline\nBody"
1714 (goto-char (point-max))
1715 (org-in-commented-heading-p)))
1716 ;; Commented ancestor.
1718 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1719 (goto-char (point-max))
1720 (org-in-commented-heading-p)))
1721 ;; Comment keyword is case-sensitive.
1723 (org-test-with-temp-text "* Comment Headline\nBody"
1724 (goto-char (point-max))
1725 (org-in-commented-heading-p)))
1726 ;; Keyword is standalone.
1728 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1729 (goto-char (point-max))
1730 (org-in-commented-heading-p)))
1731 ;; Optional argument.
1733 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1734 (goto-char (point-max))
1735 (org-in-commented-heading-p t
))))
1737 (ert-deftest test-org
/entry-blocked-p
()
1738 ;; Check other dependencies.
1740 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1741 (let ((org-enforce-todo-dependencies t
)
1743 '(org-block-todo-from-children-or-siblings-or-parent)))
1744 (org-entry-blocked-p))))
1746 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1747 (let ((org-enforce-todo-dependencies t
)
1749 '(org-block-todo-from-children-or-siblings-or-parent)))
1750 (org-entry-blocked-p))))
1751 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1754 (org-test-with-temp-text "* Blocked\n** TODO one"
1755 (let ((org-enforce-todo-dependencies t
)
1757 '(org-block-todo-from-children-or-siblings-or-parent)))
1758 (org-entry-blocked-p))))
1760 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1761 (let ((org-enforce-todo-dependencies t
)
1763 '(org-block-todo-from-children-or-siblings-or-parent)))
1764 (org-entry-blocked-p))))
1765 ;; Follow :ORDERED: specifications.
1767 (org-test-with-temp-text
1768 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1769 (let ((org-enforce-todo-dependencies t
)
1771 '(org-block-todo-from-children-or-siblings-or-parent)))
1772 (org-entry-blocked-p))))
1774 (org-test-with-temp-text
1775 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1776 (let ((org-enforce-todo-dependencies t
)
1778 '(org-block-todo-from-children-or-siblings-or-parent)))
1779 (org-entry-blocked-p)))))
1781 (ert-deftest test-org
/get-outline-path
()
1782 "Test `org-get-outline-path' specifications."
1783 ;; Top-level headlines have no outline path.
1785 (org-test-with-temp-text "* H"
1786 (org-get-outline-path)))
1787 ;; Otherwise, outline path is the path leading to the headline.
1790 (org-test-with-temp-text "* H\n** S<point>"
1791 (org-get-outline-path))))
1792 ;; Find path even when point is not on a headline.
1795 (org-test-with-temp-text "* H\n** S\nText<point>"
1796 (org-get-outline-path))))
1797 ;; TODO keywords, tags and statistics cookies are ignored.
1800 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1801 (org-get-outline-path))))
1802 ;; Links are replaced with their description or their path.
1805 (org-test-with-temp-text
1806 "* [[https://orgmode.org][Org]]\n** S<point>"
1807 (org-get-outline-path))))
1809 (equal '("https://orgmode.org")
1810 (org-test-with-temp-text
1811 "* [[https://orgmode.org]]\n** S<point>"
1812 (org-get-outline-path))))
1813 ;; When WITH-SELF is non-nil, include current heading.
1816 (org-test-with-temp-text "* H"
1817 (org-get-outline-path t
))))
1820 (org-test-with-temp-text "* H\n** S\nText<point>"
1821 (org-get-outline-path t
))))
1822 ;; Using cache is transparent to the user.
1825 (org-test-with-temp-text "* H\n** S<point>"
1826 (setq org-outline-path-cache nil
)
1827 (org-get-outline-path nil t
))))
1828 ;; Do not corrupt cache when finding outline path in distant part of
1832 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1833 (setq org-outline-path-cache nil
)
1834 (org-get-outline-path nil t
)
1835 (search-forward "S2")
1836 (org-get-outline-path nil t
))))
1837 ;; Do not choke on empty headlines.
1839 (org-test-with-temp-text "* H\n** <point>"
1840 (org-get-outline-path)))
1842 (org-test-with-temp-text "* \n** H<point>"
1843 (org-get-outline-path))))
1845 (ert-deftest test-org
/format-outline-path
()
1846 "Test `org-format-outline-path' specifications."
1848 (string= (org-format-outline-path (list "one" "two" "three"))
1852 (string= (org-format-outline-path '())
1855 (string= (org-format-outline-path '(nil))
1857 ;; Empty path and prefix.
1859 (string= (org-format-outline-path '() nil
">>")
1861 ;; Trailing whitespace in headings.
1863 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1865 ;; Non-default prefix and separators.
1867 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1868 ">>|one|two|three"))
1871 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1873 ;; Give a very narrow width.
1875 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1877 ;; Give a prefix that extends beyond the width.
1879 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1883 (ert-deftest test-org
/map-entries
()
1884 "Test `org-map-entries' specifications."
1888 (org-test-with-temp-text "* Level 1\n** Level 2"
1889 (org-map-entries #'point
))))
1893 (org-test-with-temp-text "* Level 1\n** Level 2"
1894 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1897 (org-test-with-temp-text "* Level 1\n** Level 2"
1898 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1902 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1903 (org-map-entries #'point
"yes"))))
1906 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1907 (org-map-entries #'point
"+yes-a"))))
1910 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1911 (org-map-entries #'point
"{yes?}"))))
1915 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1916 (org-map-entries #'point
"PRIORITY=\"A\""))))
1920 (org-test-with-temp-text "
1922 SCHEDULED: <2012-03-29 thu.>
1924 SCHEDULED: <2014-03-04 tue.>"
1925 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1928 (org-test-with-temp-text "
1930 SCHEDULED: <2012-03-29 thu.>
1932 SCHEDULED: <2014-03-04 tue.>"
1933 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1934 ;; Regular property match.
1937 (org-test-with-temp-text "
1946 (org-map-entries #'point
"TEST=1"))))
1947 ;; Multiple criteria.
1950 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1951 (let (org-odd-levels-only
1952 (org-use-tag-inheritance nil
))
1953 (org-map-entries #'point
"yes+LEVEL=1")))))
1957 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1958 (let (org-odd-levels-only)
1959 (org-map-entries #'point
"LEVEL=2|no")))))
1962 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1963 (let (org-odd-levels-only)
1964 (org-map-entries #'point
"yes|no")))))
1968 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1969 (let (org-odd-levels-only)
1970 (org-map-entries #'point
"yes&no"))))))
1972 (ert-deftest test-org
/edit-headline
()
1973 "Test `org-edit-headline' specifications."
1976 (org-test-with-temp-text "* A"
1977 (org-edit-headline "B")
1979 ;; Handle empty headings.
1982 (org-test-with-temp-text "* A"
1983 (org-edit-headline "")
1987 (org-test-with-temp-text "* "
1988 (org-edit-headline "A")
1990 ;; Handle TODO keywords and priority cookies.
1993 (org-test-with-temp-text "* TODO A"
1994 (org-edit-headline "B")
1998 (org-test-with-temp-text "* [#A] A"
1999 (org-edit-headline "B")
2002 (equal "* TODO [#A] B"
2003 (org-test-with-temp-text "* TODO [#A] A"
2004 (org-edit-headline "B")
2008 (org-test-with-temp-text "* A :tag:"
2009 (let ((org-tags-column 4)) (org-edit-headline "B"))
2016 (ert-deftest test-org
/set-regexps-and-options
()
2017 "Test `org-set-regexps-and-options' specifications."
2021 (let ((org-tag-alist '(("A")))
2022 (org-tag-persistent-alist nil
))
2023 (org-test-with-temp-text ""
2025 org-current-tag-alist
))))
2028 (let ((org-tag-alist '(("A")))
2029 (org-tag-persistent-alist nil
))
2030 (org-test-with-temp-text "#+TAGS: B"
2032 org-current-tag-alist
))))
2034 (equal '(("C") ("B"))
2035 (let ((org-tag-alist '(("A")))
2036 (org-tag-persistent-alist '(("C"))))
2037 (org-test-with-temp-text "#+TAGS: B"
2039 org-current-tag-alist
))))
2042 (let ((org-tag-alist '(("A")))
2043 (org-tag-persistent-alist '(("C"))))
2044 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2046 org-current-tag-alist
))))
2048 (equal '(("A" . ?a
) ("B") ("C"))
2049 (let ((org-tag-persistant-alist nil
))
2050 (org-test-with-temp-text "#+TAGS: A(a) B C"
2052 org-current-tag-alist
))))
2054 (equal '(("A") (:newline
) ("B"))
2055 (let ((org-tag-persistent-alist nil
))
2056 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2058 org-current-tag-alist
))))
2060 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2061 (let ((org-tag-persistent-alist nil
))
2062 (org-test-with-temp-text "#+TAGS: { A B } C"
2064 org-current-tag-alist
))))
2066 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2067 (let ((org-tag-persistent-alist nil
))
2068 (org-test-with-temp-text "#+TAGS: { A : B C }"
2070 org-current-tag-alist
))))
2072 (equal '(("A" "B" "C"))
2073 (let ((org-tag-persistent-alist nil
))
2074 (org-test-with-temp-text "#+TAGS: { A : B C }"
2076 org-tag-groups-alist
))))
2078 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2079 (let ((org-tag-persistent-alist nil
))
2080 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2082 org-current-tag-alist
))))
2084 (equal '(("A" "B" "C"))
2085 (let ((org-tag-persistent-alist nil
))
2086 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2088 org-tag-groups-alist
))))
2089 ;; FILETAGS keyword.
2091 (equal '("A" "B" "C")
2092 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2095 ;; PROPERTY keyword. Property names are case-insensitive.
2098 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2100 (cdr (assoc "var" org-file-properties
)))))
2104 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2106 (cdr (assoc "var" org-file-properties
)))))
2110 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2112 (cdr (assoc "var" org-file-properties
)))))
2116 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2118 org-archive-location
)))
2119 ;; CATEGORY keyword.
2122 (org-test-with-temp-text "#+CATEGORY: test"
2127 (org-test-with-temp-text "#+CATEGORY: test"
2129 (cdr (assoc "CATEGORY" org-file-properties
)))))
2132 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2133 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2135 org-columns-default-format
)))
2136 ;; CONSTANTS keyword. Constants names are case sensitive.
2138 (equal '("299792458." "3.14")
2139 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2142 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2146 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2148 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2151 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2153 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2158 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2160 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2162 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2166 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2168 (list org-highest-priority org-lowest-priority org-default-priority
))))
2172 (org-test-with-temp-text "#+PRIORITIES: X Z"
2174 (list org-highest-priority org-lowest-priority org-default-priority
))))
2178 (org-test-with-temp-text "#+STARTUP: fold odd"
2180 (list org-startup-folded org-odd-levels-only
))))
2183 (equal '(("A" "B") ("C"))
2184 (org-test-with-temp-text "#+TODO: A B | C"
2186 (list org-not-done-keywords org-done-keywords
))))
2188 (equal '(("A" "C") ("B" "D"))
2189 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2191 (list org-not-done-keywords org-done-keywords
))))
2193 (equal '(("A" "B") ("C"))
2194 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2196 (list org-not-done-keywords org-done-keywords
))))
2198 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2199 (org-test-with-temp-text "#+TODO: A(a)"
2201 org-todo-key-alist
)))
2203 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2204 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2206 org-todo-log-states
)))
2207 ;; Enter SETUPFILE keyword.
2210 (org-test-with-temp-text
2211 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2213 (cdr (assoc "a" org-file-properties
))))))
2221 (ert-deftest test-org
/coderef
()
2222 "Test coderef links specifications."
2224 (org-test-with-temp-text "
2225 #+BEGIN_SRC emacs-lisp
2230 (looking-at "(ref:sc)")))
2231 ;; Find coderef even with alternate label format.
2233 (org-test-with-temp-text "
2234 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2239 (looking-at "{ref:sc}"))))
2243 (ert-deftest test-org
/custom-id
()
2244 "Test custom ID links specifications."
2246 (org-test-with-temp-text
2247 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2249 (looking-at-p "\\* H1")))
2250 ;; Throw an error on false positives.
2252 (org-test-with-temp-text
2253 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2255 (looking-at-p "\\* H1"))))
2259 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2260 ;; a named element (#+name: text) and to headlines (* Text).
2262 (ert-deftest test-org
/fuzzy-links
()
2263 "Test fuzzy links specifications."
2264 ;; Fuzzy link goes in priority to a matching target.
2266 (org-test-with-temp-text
2267 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2268 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2269 (looking-at "<<Test>>")))
2270 ;; Then fuzzy link points to an element with a given name.
2272 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2273 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2274 (looking-at "#\\+NAME: Test")))
2275 ;; A target still lead to a matching headline otherwise.
2277 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2278 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2279 (looking-at "\\* Head2")))
2280 ;; With a leading star in link, enforce heading match.
2282 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2283 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2284 (looking-at "\\* Test")))
2285 ;; With a leading star in link, enforce exact heading match, even
2286 ;; with `org-link-search-must-match-exact-headline' set to nil.
2288 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2289 (let ((org-link-search-must-match-exact-headline nil
))
2290 (org-open-at-point))))
2291 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2293 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2294 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2295 (looking-at "\\* Test")))
2297 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2298 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2299 (looking-at "\\* Test")))
2300 ;; Heading match should not care about spaces, cookies, TODO
2301 ;; keywords, priorities, and tags. However, TODO keywords are
2305 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2306 (org-test-with-temp-text
2307 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2308 (let ((org-link-search-must-match-exact-headline nil
)
2309 (org-todo-regexp "TODO"))
2310 (org-open-at-point))
2311 (looking-at (regexp-quote first-line
)))))
2313 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2314 (let ((org-link-search-must-match-exact-headline nil
)
2315 (org-todo-regexp "TODO"))
2316 (org-open-at-point))))
2317 ;; Heading match should still be exact.
2319 (org-test-with-temp-text "
2320 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2323 (let ((org-link-search-must-match-exact-headline nil
)
2324 (org-todo-regexp "TODO"))
2325 (org-open-at-point))))
2327 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2328 (let ((org-link-search-must-match-exact-headline nil
)
2329 (org-todo-regexp "TODO"))
2330 (org-open-at-point))
2331 (looking-at-p (regexp-quote "** Test 1 2"))))
2332 ;; Heading match ignores COMMENT keyword.
2334 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2336 (looking-at "\\* COMMENT Test")))
2338 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2340 (looking-at "\\* TODO COMMENT Test")))
2341 ;; Correctly un-hexify fuzzy links.
2343 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2347 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2350 ;; Match search strings containing newline characters, including
2353 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2354 (let ((file (buffer-file-name)))
2355 (goto-char (point-max))
2356 (insert (format "[[file:%s::line1 line2]]" file
))
2358 (let ((org-link-search-must-match-exact-headline nil
))
2359 (org-open-at-point 0))
2360 (looking-at-p "line1"))))
2362 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2363 (let ((file (buffer-file-name)))
2364 (goto-char (point-max))
2365 (insert (format "[[file:%s::line1 line2]]" file
))
2367 (let ((org-link-search-must-match-exact-headline nil
))
2368 (org-open-at-point 0))
2369 (looking-at-p "line1")))))
2373 (ert-deftest test-org
/org-link-escape-ascii-character
()
2374 "Escape an ascii character."
2378 (org-link-escape "["))))
2380 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2381 "Escape an ascii control character."
2385 (org-link-escape "\t"))))
2387 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2388 "Escape an unicode multibyte character."
2392 (org-link-escape "€"))))
2394 (ert-deftest test-org
/org-link-escape-custom-table
()
2395 "Escape string with custom character table."
2399 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2401 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2402 "Escape string with custom table merged with default table."
2405 "%5BF%6F%6F%3A%42ar%0A%5D"
2406 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2408 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2409 "Unescape an ascii character."
2413 (org-link-unescape "%5B"))))
2415 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2416 "Unescpae an ascii control character."
2420 (org-link-unescape "%0A"))))
2422 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2423 "Unescape unicode multibyte character."
2427 (org-link-unescape "%E2%82%AC"))))
2429 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2430 "Unescape old style percent escaped character."
2433 "à âçèéêîôùû"
2434 (decode-coding-string
2435 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2437 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2438 "Escape and unescape a URL that includes an escaped char.
2439 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2442 "http://some.host.com/form?&id=blah%2Bblah25"
2444 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2448 (ert-deftest test-org
/open-at-point
/keyword
()
2449 "Does `org-open-at-point' open link in a keyword line?"
2451 (org-test-with-temp-text
2452 "<<top>>\n#+KEYWORD: <point>[[top]]"
2453 (org-open-at-point) t
))
2455 (org-test-with-temp-text
2456 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2457 (org-open-at-point) t
)))
2459 (ert-deftest test-org
/open-at-point
/property
()
2460 "Does `org-open-at-point' open link in property drawer?"
2462 (org-test-with-temp-text
2465 :URL: <point>[[*Headline]]
2467 (org-open-at-point) t
)))
2469 (ert-deftest test-org
/open-at-point
/comment
()
2470 "Does `org-open-at-point' open link in a commented line?"
2472 (org-test-with-temp-text
2473 "<<top>>\n# <point>[[top]]"
2474 (org-open-at-point) t
))
2476 (org-test-with-temp-text
2477 "* H\n<<top>>\n# <point>[[top]]"
2478 (org-open-at-point) t
)))
2480 (ert-deftest test-org
/open-at-point
/inline-image
()
2481 "Test `org-open-at-point' on nested links."
2483 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2487 (ert-deftest test-org
/open-at-point
/radio-target
()
2488 "Test `org-open-at-point' on radio targets."
2490 (org-test-with-temp-text "<<<target>>> <point>target"
2491 (org-update-radio-target-regexp)
2493 (eq (org-element-type (org-element-context)) 'radio-target
))))
2495 (ert-deftest test-org
/open-at-point
/tag
()
2496 "Test `org-open-at-point' on tags."
2498 (org-test-with-temp-text "* H :<point>tag:"
2500 (cl-letf (((symbol-function 'org-tags-view
)
2501 (lambda (&rest args
) (throw :result t
))))
2505 (org-test-with-temp-text-in-file "* H<point> :tag:"
2507 (cl-letf (((symbol-function 'org-tags-view
)
2508 (lambda (&rest args
) (throw :result t
))))
2514 (ert-deftest test-org
/store-link
()
2515 "Test `org-store-link' specifications."
2516 ;; On a headline, link to that headline. Use heading as the
2517 ;; description of the link.
2519 (let (org-store-link-props org-stored-links
)
2520 (org-test-with-temp-text-in-file "* H1"
2521 (let ((file (buffer-file-name)))
2522 (equal (format "[[file:%s::*H1][H1]]" file
)
2523 (org-store-link nil
))))))
2524 ;; On a headline, remove any link from description.
2526 (let (org-store-link-props org-stored-links
)
2527 (org-test-with-temp-text-in-file "* [[#l][d]]"
2528 (let ((file (buffer-file-name)))
2529 (equal (format "[[file:%s::*%s][d]]"
2531 (org-link-escape "[[#l][d]]"))
2532 (org-store-link nil
))))))
2534 (let (org-store-link-props org-stored-links
)
2535 (org-test-with-temp-text-in-file "* [[l]]"
2536 (let ((file (buffer-file-name)))
2537 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2538 (org-store-link nil
))))))
2540 (let (org-store-link-props org-stored-links
)
2541 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2542 (let ((file (buffer-file-name)))
2543 (equal (format "[[file:%s::*%s][d1 d2]]"
2545 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2546 (org-store-link nil
))))))
2547 ;; On a named element, link to that element.
2549 (let (org-store-link-props org-stored-links
)
2550 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2551 (let ((file (buffer-file-name)))
2552 (equal (format "[[file:%s::foo][foo]]" file
)
2553 (org-store-link nil
))))))
2554 ;; Store link to Org buffer, with context.
2556 (let ((org-stored-links nil
)
2557 (org-id-link-to-org-use-id nil
)
2558 (org-context-in-file-links t
))
2559 (org-test-with-temp-text-in-file "* h1"
2560 (let ((file (buffer-file-name)))
2561 (equal (format "[[file:%s::*h1][h1]]" file
)
2562 (org-store-link nil
))))))
2563 ;; Store link to Org buffer, without context.
2565 (let ((org-stored-links nil
)
2566 (org-id-link-to-org-use-id nil
)
2567 (org-context-in-file-links nil
))
2568 (org-test-with-temp-text-in-file "* h1"
2569 (let ((file (buffer-file-name)))
2570 (equal (format "[[file:%s][file:%s]]" file file
)
2571 (org-store-link nil
))))))
2572 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2574 (let ((org-stored-links nil
)
2575 (org-id-link-to-org-use-id nil
)
2576 (org-context-in-file-links nil
))
2577 (org-test-with-temp-text-in-file "* h1"
2578 (let ((file (buffer-file-name)))
2579 (equal (format "[[file:%s::*h1][h1]]" file
)
2580 (org-store-link '(4)))))))
2581 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2584 (let ((org-stored-links nil
)
2585 (org-id-link-to-org-use-id nil
)
2586 (org-context-in-file-links nil
))
2587 (org-test-with-temp-text-in-file "* h1"
2588 (let ((file (buffer-file-name)))
2589 (equal (format "[[file:%s][file:%s]]" file file
)
2590 (org-store-link '(16)))))))
2591 ;; Store file link to non-Org buffer, with context.
2593 (let ((org-stored-links nil
)
2594 (org-context-in-file-links t
))
2595 (org-test-with-temp-text-in-file "one\n<point>two"
2597 (let ((file (buffer-file-name)))
2598 (equal (format "[[file:%s::one]]" file
)
2599 (org-store-link nil
))))))
2600 ;; Store file link to non-Org buffer, without context.
2602 (let ((org-stored-links nil
)
2603 (org-context-in-file-links nil
))
2604 (org-test-with-temp-text-in-file "one\n<point>two"
2606 (let ((file (buffer-file-name)))
2607 (equal (format "[[file:%s][file:%s]]" file file
)
2608 (org-store-link nil
))))))
2609 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2612 (let ((org-stored-links nil
)
2613 (org-context-in-file-links nil
))
2614 (org-test-with-temp-text-in-file "one\n<point>two"
2616 (let ((file (buffer-file-name)))
2617 (equal (format "[[file:%s::one]]" file
)
2618 (org-store-link '(4)))))))
2619 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2622 (let ((org-stored-links nil
)
2623 (org-context-in-file-links nil
))
2624 (org-test-with-temp-text-in-file "one\n<point>two"
2626 (let ((file (buffer-file-name)))
2627 (equal (format "[[file:%s][file:%s]]" file file
)
2628 (org-store-link '(16))))))))
2633 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2634 "Ensure properties accumulate in subtree drawers."
2635 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2636 (org-babel-next-src-block)
2637 (should (equal '(2 1) (org-babel-execute-src-block)))))
2639 (ert-deftest test-org
/custom-properties
()
2640 "Test custom properties specifications."
2643 (let ((org-custom-properties '("FOO")))
2644 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2645 (org-toggle-custom-properties-visibility)
2646 (org-invisible-p2))))
2647 ;; Properties are case-insensitive.
2649 (let ((org-custom-properties '("FOO")))
2650 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2651 (org-toggle-custom-properties-visibility)
2652 (org-invisible-p2))))
2654 (let ((org-custom-properties '("foo")))
2655 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2656 (org-toggle-custom-properties-visibility)
2657 (org-invisible-p2))))
2658 ;; Multiple custom properties in the same drawer.
2660 (let ((org-custom-properties '("FOO" "BAR")))
2661 (org-test-with-temp-text
2662 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2663 (org-toggle-custom-properties-visibility)
2664 (and (org-invisible-p2)
2665 (not (progn (forward-line) (org-invisible-p2)))
2666 (progn (forward-line) (org-invisible-p2))))))
2667 ;; Hide custom properties with an empty value.
2669 (let ((org-custom-properties '("FOO")))
2670 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2671 (org-toggle-custom-properties-visibility)
2672 (org-invisible-p2))))
2673 ;; Do not hide fake properties.
2675 (let ((org-custom-properties '("FOO")))
2676 (org-test-with-temp-text ":FOO: val\n"
2677 (org-toggle-custom-properties-visibility)
2678 (org-invisible-p2))))
2680 (let ((org-custom-properties '("A")))
2681 (org-test-with-temp-text
2682 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2683 (org-toggle-custom-properties-visibility)
2684 (org-invisible-p2)))))
2690 (ert-deftest test-org
/mark-subtree
()
2691 "Test `org-mark-subtree' specifications."
2692 ;; Error when point is before first headline.
2694 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2695 (progn (transient-mark-mode 1)
2696 (org-mark-subtree))))
2697 ;; Without argument, mark current subtree.
2701 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2702 (progn (transient-mark-mode 1)
2705 (list (region-beginning) (region-end))))))
2706 ;; With an argument, move ARG up.
2710 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2711 (progn (transient-mark-mode 1)
2713 (org-mark-subtree 1)
2714 (list (region-beginning) (region-end))))))
2715 ;; Do not get fooled by inlinetasks.
2716 (when (featurep 'org-inlinetask
)
2719 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2720 (progn (transient-mark-mode 1)
2722 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2723 (region-beginning)))))))
2729 (ert-deftest test-org
/in-regexp
()
2730 "Test `org-in-regexp' specifications."
2733 (org-test-with-temp-text "xx ab<point>c xx"
2734 (org-in-regexp "abc")))
2736 (org-test-with-temp-text "xx abc <point>xx"
2737 (org-in-regexp "abc")))
2738 ;; Return non-nil even with multiple matching regexps in the same
2741 (org-test-with-temp-text "abc xx ab<point>c xx"
2742 (org-in-regexp "abc")))
2743 ;; With optional argument NLINES, check extra lines around point.
2745 (org-test-with-temp-text "A\nB<point>\nC"
2746 (org-in-regexp "A\nB\nC")))
2748 (org-test-with-temp-text "A\nB<point>\nC"
2749 (org-in-regexp "A\nB\nC" 1)))
2751 (org-test-with-temp-text "A\nB\nC<point>"
2752 (org-in-regexp "A\nB\nC" 1)))
2753 ;; When optional argument VISUALLY is non-nil, return nil if at
2754 ;; regexp boundaries.
2756 (org-test-with-temp-text "xx abc<point> xx"
2757 (org-in-regexp "abc")))
2759 (org-test-with-temp-text "xx abc<point> xx"
2760 (org-in-regexp "abc" nil t
))))
2762 (ert-deftest test-org
/sort-entries
()
2763 "Test `org-sort-entries'."
2764 ;; Sort alphabetically.
2766 (equal "\n* abc\n* def\n* xyz\n"
2767 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2768 (org-sort-entries nil ?a
)
2771 (equal "\n* xyz\n* def\n* abc\n"
2772 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2773 (org-sort-entries nil ?A
)
2775 ;; Sort numerically.
2777 (equal "\n* 1\n* 2\n* 10\n"
2778 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2779 (org-sort-entries nil ?n
)
2782 (equal "\n* 10\n* 2\n* 1\n"
2783 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2784 (org-sort-entries nil ?N
)
2786 ;; Sort by custom function.
2788 (equal "\n* b\n* aa\n* ccc\n"
2789 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2790 (org-sort-entries nil ?f
2792 (length (buffer-substring (point-at-bol)
2797 (equal "\n* ccc\n* aa\n* b\n"
2798 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2799 (org-sort-entries nil ?F
2801 (length (buffer-substring (point-at-bol)
2805 ;; Sort by TODO keyword.
2807 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2808 (org-test-with-temp-text
2809 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2810 (org-sort-entries nil ?o
)
2813 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2814 (org-test-with-temp-text
2815 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2816 (org-sort-entries nil ?O
)
2818 ;; Sort by priority.
2820 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2821 (org-test-with-temp-text
2822 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2823 (org-sort-entries nil ?p
)
2826 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2827 (org-test-with-temp-text
2828 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2829 (org-sort-entries nil ?P
)
2831 ;; Sort by creation time.
2841 (org-test-with-temp-text
2850 (org-sort-entries nil ?c
)
2853 ;; Sort by scheduled date.
2857 SCHEDULED: <2017-05-06 Sat>
2859 SCHEDULED: <2017-05-08 Mon>
2861 DEADLINE: <2017-05-09 Tue>
2863 DEADLINE: <2017-05-07 Sun>
2865 (org-test-with-temp-text
2868 DEADLINE: <2017-05-09 Tue>
2870 DEADLINE: <2017-05-07 Sun>
2872 SCHEDULED: <2017-05-08 Mon>
2874 SCHEDULED: <2017-05-06 Sat>
2876 (org-sort-entries nil ?s
)
2878 ;; Sort by deadline date.
2882 DEADLINE: <2017-05-07 Sun>
2884 DEADLINE: <2017-05-09 Tue>
2886 SCHEDULED: <2017-05-08 Mon>
2888 SCHEDULED: <2017-05-06 Sat>
2890 (org-test-with-temp-text
2893 DEADLINE: <2017-05-09 Tue>
2895 DEADLINE: <2017-05-07 Sun>
2897 SCHEDULED: <2017-05-08 Mon>
2899 SCHEDULED: <2017-05-06 Sat>
2901 (org-sort-entries nil ?d
)
2903 ;; Sort by any date/time
2907 SCHEDULED: <2017-05-06 Sat>
2909 DEADLINE: <2017-05-07 Sun>
2911 SCHEDULED: <2017-05-08 Mon>
2913 DEADLINE: <2017-05-09 Tue>
2915 (org-test-with-temp-text
2918 DEADLINE: <2017-05-09 Tue>
2920 DEADLINE: <2017-05-07 Sun>
2922 SCHEDULED: <2017-05-08 Mon>
2924 SCHEDULED: <2017-05-06 Sat>
2926 (org-sort-entries nil ?t
)
2928 ;; Sort by clocking time.
2933 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2934 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2938 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2939 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2942 (org-test-with-temp-text
2946 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2947 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2951 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2952 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2955 (org-sort-entries nil ?k
)
2958 (ert-deftest test-org
/file-contents
()
2959 "Test `org-file-contents' specifications."
2962 (string= "#+BIND: variable value
2968 " (org-file-contents (expand-file-name "setupfile3.org"
2969 (concat org-test-dir
"examples/")))))
2970 ;; Throw error when trying to access an invalid file.
2971 (should-error (org-file-contents "this-file-must-not-exist"))
2972 ;; Try to access an invalid file, but do not throw an error.
2974 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2978 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2980 ;; Simulate successful retrieval of a URL.
2981 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2983 (with-current-buffer buffer
2984 (insert "HTTP/1.1 200 OK\n\nfoo"))
2986 (org-file-contents "http://some-valid-url"))
2987 (kill-buffer buffer
)))))
2988 ;; Throw error when trying to access an invalid URL.
2990 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2992 ;; Simulate unsuccessful retrieval of a URL.
2993 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2995 (with-current-buffer buffer
2996 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2998 (org-file-contents "http://this-url-must-not-exist"))
2999 (kill-buffer buffer
))))
3000 ;; Try to access an invalid URL, but do not throw an error.
3002 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3004 ;; Simulate unsuccessful retrieval of a URL.
3005 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3007 (with-current-buffer buffer
3008 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3010 (org-file-contents "http://this-url-must-not-exist"))
3011 (kill-buffer buffer
))))
3013 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3015 ;; Simulate unsuccessful retrieval of a URL.
3016 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3018 (with-current-buffer buffer
3019 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3021 (org-file-contents "http://this-url-must-not-exist" :noerror
))
3022 (kill-buffer buffer
))
3028 (ert-deftest test-org
/forward-heading-same-level
()
3029 "Test `org-forward-heading-same-level' specifications."
3030 ;; Test navigation at top level, forward and backward.
3033 (org-test-with-temp-text "* H1\n* H2"
3034 (org-forward-heading-same-level 1)
3035 (buffer-substring-no-properties (point) (line-end-position)))))
3038 (org-test-with-temp-text "* H1\n<point>* H2"
3039 (org-forward-heading-same-level -
1)
3040 (buffer-substring-no-properties (point) (line-end-position)))))
3041 ;; Test navigation in a sub-tree, forward and backward.
3044 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
3045 (org-forward-heading-same-level 1)
3046 (buffer-substring-no-properties (point) (line-end-position)))))
3049 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3050 (org-forward-heading-same-level -
1)
3051 (buffer-substring-no-properties (point) (line-end-position)))))
3052 ;; Stop at first or last sub-heading.
3055 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3056 (org-forward-heading-same-level 1)
3057 (buffer-substring-no-properties (point) (line-end-position)))))
3060 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3061 (org-forward-heading-same-level -
1)
3062 (buffer-substring-no-properties (point) (line-end-position)))))
3063 ;; Allow multiple moves.
3066 (org-test-with-temp-text "* H1\n* H2\n* H3"
3067 (org-forward-heading-same-level 2)
3068 (buffer-substring-no-properties (point) (line-end-position)))))
3071 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3072 (org-forward-heading-same-level -
2)
3073 (buffer-substring-no-properties (point) (line-end-position)))))
3074 ;; Ignore spurious moves when first (or last) sibling is reached.
3077 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3078 (org-forward-heading-same-level 100)
3079 (buffer-substring-no-properties (point) (line-end-position)))))
3082 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3083 (org-forward-heading-same-level -
100)
3084 (buffer-substring-no-properties (point) (line-end-position))))))
3086 (ert-deftest test-org
/end-of-meta-data
()
3087 "Test `org-end-of-meta-data' specifications."
3088 ;; Skip planning line.
3090 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3091 (org-end-of-meta-data)
3093 ;; Skip properties drawer.
3095 (org-test-with-temp-text
3096 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3097 (org-end-of-meta-data)
3101 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3102 (org-end-of-meta-data)
3104 ;; Nothing to skip, go to first line.
3106 (org-test-with-temp-text "* Headline\nContents"
3107 (org-end-of-meta-data)
3108 (looking-at "Contents")))
3109 ;; With option argument, skip empty lines, regular drawers and
3112 (org-test-with-temp-text "* Headline\n\nContents"
3113 (org-end-of-meta-data t
)
3114 (looking-at "Contents")))
3116 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3117 (org-end-of-meta-data t
)
3118 (looking-at "Contents")))
3120 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3121 (org-end-of-meta-data t
)
3122 (looking-at "Contents")))
3123 ;; Special case: do not skip incomplete drawers.
3125 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3126 (org-end-of-meta-data t
)
3127 (looking-at ":LOGBOOK:")))
3128 ;; Special case: Be careful about consecutive headlines.
3130 (org-test-with-temp-text "* H1\n*H2\nContents"
3131 (org-end-of-meta-data t
)
3132 (looking-at "Contents"))))
3134 (ert-deftest test-org
/beginning-of-line
()
3135 "Test `org-beginning-of-line' specifications."
3136 ;; Move to beginning of line. If current line in invisible, move to
3137 ;; beginning of visible line instead.
3139 (org-test-with-temp-text "Some text\nSome other text<point>"
3140 (org-beginning-of-line)
3143 (org-test-with-temp-text "* H1\n** H2<point>"
3145 (org-beginning-of-line)
3146 (= (line-beginning-position) 1)))
3147 ;; With `visual-line-mode' active, move to beginning of visual line.
3149 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3151 (dotimes (i 1000) (insert "very "))
3152 (org-beginning-of-line)
3154 ;; In a wide headline, with `visual-line-mode', prefer going to the
3155 ;; beginning of a visual line than to the logical beginning of line,
3156 ;; even if special movement is active.
3158 (org-test-with-temp-text "* A <point>long headline"
3160 (dotimes (i 1000) (insert "very "))
3161 (goto-char (point-max))
3162 (org-beginning-of-line)
3165 (org-test-with-temp-text "* A <point>long headline"
3167 (dotimes (i 1000) (insert "very "))
3168 (goto-char (point-max))
3169 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3171 ;; At an headline with special movement, first move at beginning of
3172 ;; title, then at the beginning of line, rinse, repeat.
3174 (org-test-with-temp-text "* TODO Headline<point>"
3175 (let ((org-special-ctrl-a/e t
))
3176 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3177 (progn (org-beginning-of-line) (bolp))
3178 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3180 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3181 (let ((org-special-ctrl-a/e t
))
3182 (org-beginning-of-line)
3183 (looking-at "Headline"))))
3185 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3186 (let ((org-special-ctrl-a/e
'(t . nil
)))
3187 (org-beginning-of-line)
3188 (looking-at "Headline"))))
3190 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3191 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3192 (org-beginning-of-line)
3193 (looking-at "Headline"))))
3194 ;; At an headline with reversed movement, first move to beginning of
3195 ;; line, then to the beginning of title.
3197 (org-test-with-temp-text "* TODO Headline<point>"
3198 (let ((org-special-ctrl-a/e
'reversed
)
3199 (this-command last-command
))
3200 (and (progn (org-beginning-of-line) (bolp))
3201 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3203 (org-test-with-temp-text "* TODO Headline<point>"
3204 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3205 (this-command last-command
))
3206 (and (progn (org-beginning-of-line) (bolp))
3207 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3209 (org-test-with-temp-text "* TODO Headline<point>"
3210 (let ((org-special-ctrl-a/e
'(t . nil
))
3211 (this-command last-command
))
3212 (and (progn (org-beginning-of-line) (bolp))
3213 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3214 ;; At an item with special movement, first move after to beginning
3215 ;; of title, then to the beginning of line, rinse, repeat.
3217 (org-test-with-temp-text "- [ ] Item<point>"
3218 (let ((org-special-ctrl-a/e t
))
3219 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3220 (progn (org-beginning-of-line) (bolp))
3221 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3222 ;; At an item with reversed movement, first move to beginning of
3223 ;; line, then to the beginning of title.
3225 (org-test-with-temp-text "- [X] Item<point>"
3226 (let ((org-special-ctrl-a/e
'reversed
)
3227 (this-command last-command
))
3228 (and (progn (org-beginning-of-line) (bolp))
3229 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3230 ;; Leave point before invisible characters at column 0.
3232 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3233 (let ((org-special-ctrl-a/e nil
))
3234 (org-beginning-of-line)
3237 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3238 (let ((org-special-ctrl-a/e t
))
3239 (org-beginning-of-line)
3242 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3244 (org-beginning-of-line)
3246 ;; Special case: Do not error when the buffer contains only a single
3249 (org-test-with-temp-text "*<point>"
3250 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3252 (org-test-with-temp-text "*<point>"
3253 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3255 (ert-deftest test-org
/end-of-line
()
3256 "Test `org-end-of-line' specifications."
3259 (org-test-with-temp-text "Some text\nSome other text"
3262 ;; With `visual-line-mode' active, move to end of visible line.
3263 ;; However, never go past ellipsis.
3265 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3267 (dotimes (i 1000) (insert "very "))
3268 (goto-char (point-min))
3272 (org-test-with-temp-text "* A short headline\nSome contents"
3277 ;; In a wide headline, with `visual-line-mode', prefer going to end
3278 ;; of visible line if tags, or end of line, are farther.
3280 (org-test-with-temp-text "* A <point>long headline"
3282 (dotimes (i 1000) (insert "very "))
3283 (goto-char (point-min))
3287 (org-test-with-temp-text "* A <point>long headline :tag:"
3289 (dotimes (i 1000) (insert "very "))
3290 (goto-char (point-min))
3293 ;; At an headline without special movement, go to end of line.
3294 ;; However, never go past ellipsis.
3296 (org-test-with-temp-text "* Headline2b :tag:\n"
3297 (let ((org-special-ctrl-a/e nil
))
3298 (and (progn (org-end-of-line) (eolp))
3299 (progn (org-end-of-line) (eolp))))))
3301 (org-test-with-temp-text "* Headline2b :tag:\n"
3302 (let ((org-special-ctrl-a/e
'(t . nil
)))
3303 (and (progn (org-end-of-line) (eolp))
3304 (progn (org-end-of-line) (eolp))))))
3306 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3308 (let ((org-special-ctrl-a/e nil
))
3310 (= 1 (line-beginning-position)))))
3311 ;; At an headline with special movement, first move before tags,
3312 ;; then at the end of line, rinse, repeat. However, never go past
3315 (org-test-with-temp-text "* Headline1 :tag:\n"
3316 (let ((org-special-ctrl-a/e t
))
3317 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3318 (progn (org-end-of-line) (eolp))
3319 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3321 (org-test-with-temp-text "* Headline1 :tag:\n"
3322 (let ((org-special-ctrl-a/e
'(nil . t
)))
3323 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3324 (progn (org-end-of-line) (eolp))
3325 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3327 (org-test-with-temp-text "* Headline1 :tag:\n"
3328 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3329 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3330 (progn (org-end-of-line) (eolp))
3331 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3333 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3335 (let ((org-special-ctrl-a/e t
))
3338 (= 1 (line-beginning-position)))))
3339 ;; At an headline, with reversed movement, first go to end of line,
3340 ;; then before tags. However, never go past ellipsis.
3342 (org-test-with-temp-text "* Headline3 :tag:\n"
3343 (let ((org-special-ctrl-a/e
'reversed
)
3344 (this-command last-command
))
3345 (and (progn (org-end-of-line) (eolp))
3346 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3348 (org-test-with-temp-text "* Headline3 :tag:\n"
3349 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3350 (this-command last-command
))
3351 (and (progn (org-end-of-line) (eolp))
3352 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3354 (org-test-with-temp-text "* Headline3 :tag:\n"
3355 (let ((org-special-ctrl-a/e
'(nil . t
))
3356 (this-command last-command
))
3357 (and (progn (org-end-of-line) (eolp))
3358 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3360 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3362 (let ((org-special-ctrl-a/e
'reversed
))
3364 (= 1 (line-beginning-position)))))
3365 ;; At a block without hidden contents.
3367 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3368 (progn (org-end-of-line) (eolp))))
3369 ;; At a block with hidden contents.
3371 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3372 (let ((org-special-ctrl-a/e t
))
3373 (org-hide-block-toggle)
3376 ;; Get past invisible characters at the end of line.
3378 (org-test-with-temp-text "[[https://orgmode.org]]"
3382 (ert-deftest test-org
/open-line
()
3383 "Test `org-open-line' specifications."
3384 ;; Call `open-line' outside of tables.
3387 (org-test-with-temp-text "Text"
3390 ;; At a table, create a row above.
3392 (equal "\n| |\n| a |"
3393 (org-test-with-temp-text "\n<point>| a |"
3396 ;; At the very first character of the buffer, also call `open-line'.
3399 (org-test-with-temp-text "| a |"
3402 ;; Narrowing does not count.
3404 (equal "Text\n| |\n| a |"
3405 (org-test-with-temp-text "Text\n<point>| a |"
3406 (narrow-to-region (point) (point-max))
3411 (ert-deftest test-org
/forward-sentence
()
3412 "Test `org-forward-sentence' specifications."
3413 ;; At the end of a table cell, move to the end of the next one.
3415 (org-test-with-temp-text "| a<point> | b |"
3416 (org-forward-sentence)
3417 (looking-at " |$")))
3418 ;; Elsewhere in a cell, move to its end.
3420 (org-test-with-temp-text "| a<point>c | b |"
3421 (org-forward-sentence)
3422 (looking-at " | b |$")))
3423 ;; Otherwise, simply call `forward-sentence'.
3425 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3426 (org-forward-sentence)
3427 (looking-at " Sentence 2.")))
3429 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3430 (org-forward-sentence)
3431 (org-forward-sentence)
3433 ;; At the end of an element, jump to the next one, without stopping
3434 ;; on blank lines in-between.
3436 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3437 (org-forward-sentence)
3439 ;; Headlines are considered to be sentences by themselves, even if
3440 ;; they do not end with a full stop.
3444 (org-test-with-temp-text "* <point>Headline\nSentence."
3445 (org-forward-sentence)
3446 (buffer-substring-no-properties (line-beginning-position) (point)))))
3448 (org-test-with-temp-text "* Headline<point>\nSentence."
3449 (org-forward-sentence)
3452 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3453 (org-forward-sentence)
3454 (and (org-at-heading-p) (eolp)))))
3456 (ert-deftest test-org
/backward-sentence
()
3457 "Test `org-backward-sentence' specifications."
3458 ;; At the beginning of a table cell, move to the beginning of the
3461 (org-test-with-temp-text "| a | <point>b |"
3462 (org-backward-sentence)
3463 (looking-at "a | b |$")))
3464 ;; Elsewhere in a cell, move to its beginning.
3466 (org-test-with-temp-text "| a | b<point>c |"
3467 (org-backward-sentence)
3468 (looking-at "bc |$")))
3469 ;; Otherwise, simply call `backward-sentence'.
3471 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3472 (org-backward-sentence)
3473 (looking-at "Sentence 2.")))
3475 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3476 (org-backward-sentence)
3477 (org-backward-sentence)
3479 ;; Make sure to hit the beginning of a sentence on the same line as
3482 (org-test-with-temp-text "- Line 1\n line <point>2."
3483 (org-backward-sentence)
3484 (looking-at "Line 1"))))
3486 (ert-deftest test-org
/forward-paragraph
()
3487 "Test `org-forward-paragraph' specifications."
3488 ;; At end of buffer, do not return an error.
3490 (org-test-with-temp-text "Paragraph"
3491 (goto-char (point-max))
3492 (org-forward-paragraph)
3496 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3497 (org-forward-paragraph)
3501 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3502 (org-forward-paragraph)
3504 ;; Do not enter elements with invisible contents.
3506 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3507 (org-hide-block-toggle)
3508 (org-forward-paragraph)
3510 ;; On an affiliated keyword, jump to the beginning of the element.
3512 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3513 (org-forward-paragraph)
3514 (looking-at "Para")))
3515 ;; On an item or a footnote definition, move to the second element
3518 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3519 (org-forward-paragraph)
3520 (looking-at " Paragraph")))
3522 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3523 (org-forward-paragraph)
3524 (looking-at "Paragraph")))
3525 ;; On an item, or a footnote definition, when the first line is
3526 ;; empty, move to the first item.
3528 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3529 (org-forward-paragraph)
3530 (looking-at " Paragraph")))
3532 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3533 (org-forward-paragraph)
3534 (looking-at "Paragraph")))
3535 ;; On a table (resp. a property drawer) do not move through table
3536 ;; rows (resp. node properties).
3538 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3539 (org-forward-paragraph)
3540 (looking-at "Paragraph")))
3542 (org-test-with-temp-text
3543 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3544 (org-forward-paragraph)
3545 (looking-at "Paragraph")))
3546 ;; On a verse or source block, stop after blank lines.
3548 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3549 (org-forward-paragraph)
3552 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3553 (org-forward-paragraph)
3554 (looking-at "L2"))))
3556 (ert-deftest test-org
/backward-paragraph
()
3557 "Test `org-backward-paragraph' specifications."
3558 ;; Do not error at beginning of buffer.
3560 (org-test-with-temp-text "Paragraph"
3561 (org-backward-paragraph)
3565 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3566 (org-backward-paragraph)
3569 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3570 (org-backward-paragraph)
3571 (looking-at-p "P2")))
3574 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3575 (org-backward-paragraph)
3576 (looking-at-p "P2")))
3577 ;; Ignore invisible elements.
3579 (org-test-with-temp-text "* H1\n P1\n* H2"
3581 (goto-char (point-max))
3583 (org-backward-paragraph)
3585 ;; On an affiliated keyword, jump to the first one.
3587 (org-test-with-temp-text
3588 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3589 (org-backward-paragraph)
3590 (looking-at-p "#\\+name")))
3591 ;; On the second element in an item or a footnote definition, jump
3592 ;; to item or the definition.
3594 (org-test-with-temp-text "- line1\n\n<point> line2"
3595 (org-backward-paragraph)
3596 (looking-at-p "- line1")))
3598 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3599 (org-backward-paragraph)
3600 (looking-at-p "\\[fn:1\\] line1")))
3601 ;; On a table (resp. a property drawer), ignore table rows
3602 ;; (resp. node properties).
3604 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3605 (org-backward-paragraph)
3608 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3609 (org-backward-paragraph)
3610 (looking-at-p ":PROPERTIES:")))
3611 ;; On a comment, example, src and verse blocks, stop before blank
3614 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3615 (org-backward-paragraph)
3616 (looking-at-p "L2")))
3618 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3619 (org-backward-paragraph)
3620 (looking-at-p "L2")))
3621 ;; In comment, example, export, src and verse blocks, stop below
3622 ;; opening line when called from within the block.
3624 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3625 (org-backward-paragraph)
3626 (looking-at-p "L1")))
3628 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3629 (org-backward-paragraph)
3630 (looking-at-p "L1")))
3631 ;; When called from the opening line itself, however, move to
3632 ;; beginning of block.
3634 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3635 (org-backward-paragraph)
3637 ;; Pathological case: on an empty heading, move to its beginning.
3639 (org-test-with-temp-text "* <point>H"
3640 (org-backward-paragraph)
3643 (ert-deftest test-org
/forward-element
()
3644 "Test `org-forward-element' specifications."
3645 ;; 1. At EOB: should error.
3646 (org-test-with-temp-text "Some text\n"
3647 (goto-char (point-max))
3648 (should-error (org-forward-element)))
3649 ;; 2. Standard move: expected to ignore blank lines.
3650 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3651 (org-forward-element)
3652 (should (looking-at (regexp-quote "Second paragraph."))))
3653 ;; 3. Headline tests.
3654 (org-test-with-temp-text "
3659 ;; 3.1. At an headline beginning: move to next headline at the
3662 (org-forward-element)
3663 (should (looking-at (regexp-quote "** Head 1.2")))
3664 ;; 3.2. At an headline beginning: move to parent headline if no
3665 ;; headline at the same level.
3667 (org-forward-element)
3668 (should (looking-at (regexp-quote "** Head 1.2"))))
3669 ;; 4. Greater element tests.
3670 (org-test-with-temp-text
3671 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3672 ;; 4.1. At a greater element: expected to skip contents.
3673 (org-forward-element)
3674 (should (looking-at (regexp-quote "Outside.")))
3675 ;; 4.2. At the end of greater element contents: expected to skip
3676 ;; to the end of the greater element.
3678 (org-forward-element)
3679 (should (looking-at (regexp-quote "Outside."))))
3681 (org-test-with-temp-text "
3695 ;; 5.1. At list top point: expected to move to the element after
3698 (org-forward-element)
3699 (should (looking-at (regexp-quote "Outside.")))
3700 ;; 5.2. Special case: at the first line of a sub-list, but not at
3701 ;; beginning of line, move to next item.
3704 (org-forward-element)
3705 (should (looking-at "- item2"))
3708 (org-forward-element)
3709 (should (looking-at " - sub2"))
3710 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3712 (org-forward-element)
3713 (should (looking-at (regexp-quote " Inner paragraph.")))
3714 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3716 (org-forward-element)
3717 (should (looking-at (regexp-quote " Inner paragraph.")))
3718 ;; 5.5. At an item: expected to move to next item, if any.
3720 (org-forward-element)
3721 (should (looking-at " - sub3"))))
3723 (ert-deftest test-org
/backward-element
()
3724 "Test `org-backward-element' specifications."
3725 ;; 1. Should error at BOB.
3726 (org-test-with-temp-text " \nParagraph."
3727 (should-error (org-backward-element)))
3728 ;; 2. Should move at BOB when called on the first element in buffer.
3730 (org-test-with-temp-text "\n#+TITLE: test"
3731 (progn (forward-line)
3732 (org-backward-element)
3734 ;; 3. Not at the beginning of an element: move at its beginning.
3735 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3738 (org-backward-element)
3739 (should (looking-at (regexp-quote "Paragraph2."))))
3740 ;; 4. Headline tests.
3741 (org-test-with-temp-text "
3746 ;; 4.1. At an headline beginning: move to previous headline at the
3749 (org-backward-element)
3750 (should (looking-at (regexp-quote "** Head 1.1")))
3751 ;; 4.2. At an headline beginning: move to parent headline if no
3752 ;; headline at the same level.
3754 (org-backward-element)
3755 (should (looking-at (regexp-quote "* Head 1")))
3756 ;; 4.3. At the first top-level headline: should error.
3758 (should-error (org-backward-element)))
3759 ;; 5. At beginning of first element inside a greater element:
3760 ;; expected to move to greater element's beginning.
3761 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3763 (org-backward-element)
3764 (should (looking-at "#\\+BEGIN_CENTER")))
3765 ;; 6. At the beginning of the first element in a section: should
3766 ;; move back to headline, if any.
3768 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3769 (progn (goto-char (point-max))
3771 (org-backward-element)
3772 (org-at-heading-p))))
3774 (org-test-with-temp-text "
3789 ;; 7.1. At beginning of sub-list: expected to move to the
3790 ;; paragraph before it.
3792 (org-backward-element)
3793 (should (looking-at "item1"))
3794 ;; 7.2. At an item in a list: expected to move at previous item.
3796 (org-backward-element)
3797 (should (looking-at " - sub2"))
3799 (org-backward-element)
3800 (should (looking-at "- item1"))
3801 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3804 (org-backward-element)
3805 (should (looking-at " - sub1"))
3807 (org-backward-element)
3808 (should (looking-at "- item1"))
3809 ;; 7.4. At blank-lines before list end: expected to move to top
3812 (org-backward-element)
3813 (should (looking-at "- item1"))))
3815 (ert-deftest test-org
/up-element
()
3816 "Test `org-up-element' specifications."
3817 ;; 1. At BOB or with no surrounding element: should error.
3818 (org-test-with-temp-text "Paragraph."
3819 (should-error (org-up-element)))
3820 (org-test-with-temp-text "* Head1\n* Head2"
3822 (should-error (org-up-element)))
3823 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3825 (should-error (org-up-element)))
3826 ;; 2. At an headline: move to parent headline.
3827 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3830 (should (looking-at "\\* Head1")))
3831 ;; 3. Inside a greater element: move to greater element beginning.
3832 (org-test-with-temp-text
3833 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3836 (should (looking-at "#\\+BEGIN_CENTER")))
3838 (org-test-with-temp-text "* Top
3845 Paragraph within sub2.
3848 ;; 4.1. Within an item: move to the item beginning.
3851 (should (looking-at " - sub2"))
3852 ;; 4.2. At an item in a sub-list: move to parent item.
3855 (should (looking-at "- item1"))
3856 ;; 4.3. At an item in top list: move to beginning of whole list.
3859 (should (looking-at "- item1"))
3860 ;; 4.4. Special case. At very top point: should move to parent of
3864 (should (looking-at "\\* Top"))))
3866 (ert-deftest test-org
/down-element
()
3867 "Test `org-down-element' specifications."
3868 ;; Error when the element hasn't got a recursive type.
3869 (org-test-with-temp-text "Paragraph."
3870 (should-error (org-down-element)))
3871 ;; Error when the element has no contents
3872 (org-test-with-temp-text "* Headline"
3873 (should-error (org-down-element)))
3874 ;; When at a plain-list, move to first item.
3875 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3878 (should (looking-at " - Item 1.1")))
3879 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3881 (should (looking-at " Item 1")))
3882 ;; When at a table, move to first row
3883 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3885 (should (looking-at " a | b |")))
3886 ;; Otherwise, move inside the greater element.
3887 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3889 (should (looking-at "Paragraph"))))
3891 (ert-deftest test-org
/drag-element-backward
()
3892 "Test `org-drag-element-backward' specifications."
3896 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3897 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3898 (org-drag-element-backward)
3902 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3903 (org-test-with-temp-text
3904 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3905 (org-drag-element-backward)
3907 ;; Preserve blank lines.
3909 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3910 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3911 (org-drag-element-backward)
3915 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3916 (org-drag-element-backward)
3917 (looking-at-p "2")))
3918 ;; Error when trying to move first element of buffer.
3920 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3921 (org-drag-element-backward))
3923 ;; Error when trying to swap nested elements.
3925 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3926 (org-drag-element-backward))
3928 ;; Error when trying to swap an headline element and a non-headline
3931 (org-test-with-temp-text "Test.\n<point>* Head 1"
3932 (org-drag-element-backward))
3934 ;; Error when called before first element.
3936 (org-test-with-temp-text "\n<point>"
3937 (org-drag-element-backward))
3939 ;; Preserve visibility of elements and their contents.
3941 (equal '((63 .
82) (26 .
48))
3942 (org-test-with-temp-text "
3950 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3951 (search-backward "- item 1")
3952 (org-drag-element-backward)
3953 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3954 (overlays-in (point-min) (point-max))))))
3955 ;; Pathological case: handle call with point in blank lines right
3956 ;; after a headline.
3958 (equal "* H2\n* H1\nText\n\n"
3959 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3960 (org-drag-element-backward)
3963 (ert-deftest test-org
/drag-element-forward
()
3964 "Test `org-drag-element-forward' specifications."
3965 ;; 1. Error when trying to move first element of buffer.
3966 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3968 (should-error (org-drag-element-forward)))
3969 ;; 2. Error when trying to swap nested elements.
3970 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3972 (should-error (org-drag-element-forward)))
3973 ;; 3. Error when trying to swap a non-headline element and an
3975 (org-test-with-temp-text "Test.\n* Head 1"
3976 (should-error (org-drag-element-forward)))
3977 ;; 4. Error when called before first element.
3979 (org-test-with-temp-text "\n"
3981 (org-drag-element-backward))
3983 ;; 5. Otherwise, swap elements, preserving column and blank lines
3984 ;; between elements.
3985 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3986 (search-forward "graph")
3987 (org-drag-element-forward)
3988 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3989 (should (looking-at " 1")))
3990 ;; 5. Preserve visibility of elements and their contents.
3991 (org-test-with-temp-text "
3999 (while (search-forward "BEGIN_" nil t
) (org-cycle))
4000 (search-backward "#+BEGIN_CENTER")
4001 (org-drag-element-forward)
4004 '((63 .
82) (26 .
48))
4005 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
4006 (overlays-in (point-min) (point-max)))))))
4008 (ert-deftest test-org
/next-block
()
4009 "Test `org-next-block' specifications."
4012 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4014 (looking-at "#\\+BEGIN_CENTER")))
4017 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
4018 (let ((case-fold-search nil
))
4020 (looking-at "#\\+begin_center"))))
4021 ;; Ignore current line.
4023 (org-test-with-temp-text
4024 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
4026 (looking-at "#\\+BEGIN_CENTER")))
4027 ;; Throw an error when no block is found.
4029 (org-test-with-temp-text "Paragraph"
4030 (org-next-block 1)))
4031 ;; With an argument, skip many blocks at once.
4033 (org-test-with-temp-text
4034 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4036 (looking-at "#\\+BEGIN_QUOTE")))
4037 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4039 (org-test-with-temp-text
4040 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4041 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4042 (looking-at "#\\+BEGIN_QUOTE")))
4043 ;; Optional argument is also case-insensitive.
4045 (org-test-with-temp-text
4046 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4047 (let ((case-fold-search nil
))
4048 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4049 (looking-at "#\\+begin_quote")))))
4051 (ert-deftest test-org
/previous-block
()
4052 "Test `org-previous-block' specifications."
4055 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4056 (org-previous-block 1)
4057 (looking-at "#\\+BEGIN_CENTER")))
4060 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4061 (let ((case-fold-search nil
))
4062 (org-previous-block 1)
4063 (looking-at "#\\+begin_center"))))
4064 ;; Ignore current line.
4066 (org-test-with-temp-text
4067 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4068 (org-previous-block 1)
4069 (looking-at "#\\+BEGIN_QUOTE")))
4070 ;; Throw an error when no block is found.
4072 (org-test-with-temp-text "Paragraph<point>"
4073 (org-previous-block 1)))
4074 ;; With an argument, skip many blocks at once.
4076 (org-test-with-temp-text
4077 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4078 (org-previous-block 2)
4079 (looking-at "#\\+BEGIN_CENTER")))
4080 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4082 (org-test-with-temp-text
4083 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4084 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4085 (looking-at "#\\+BEGIN_QUOTE")))
4086 ;; Optional argument is also case-insensitive.
4088 (org-test-with-temp-text
4089 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4090 (let ((case-fold-search nil
))
4091 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4092 (looking-at "#\\+begin_quote")))))
4095 ;;; Outline structure
4097 (ert-deftest test-org
/demote
()
4098 "Test `org-demote' specifications."
4099 ;; Add correct number of stars according to `org-odd-levels-only'.
4102 (org-test-with-temp-text "* H"
4103 (let ((org-odd-levels-only nil
)) (org-demote))
4104 (org-current-level))))
4107 (org-test-with-temp-text "* H"
4108 (let ((org-odd-levels-only t
)) (org-demote))
4109 (org-current-level))))
4110 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4112 (org-test-with-temp-text "* H :tag:"
4113 (let ((org-tags-column 10)
4114 (org-auto-align-tags t
)
4115 (org-odd-levels-only nil
))
4117 (org-move-to-column 10)
4118 (looking-at-p ":tag:$")))
4120 (org-test-with-temp-text "* H :tag:"
4121 (let ((org-tags-column 10)
4122 (org-auto-align-tags nil
)
4123 (org-odd-levels-only nil
))
4125 (org-move-to-column 10)
4126 (looking-at-p ":tag:$")))
4127 ;; When `org-adapt-indentation' is non-nil, always indent planning
4128 ;; info and property drawers accordingly.
4131 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4132 (let ((org-odd-levels-only nil
)
4133 (org-adapt-indentation t
))
4136 (org-get-indentation))))
4139 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4140 (let ((org-odd-levels-only nil
)
4141 (org-adapt-indentation t
))
4144 (org-get-indentation))))
4147 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4148 (let ((org-odd-levels-only nil
)
4149 (org-adapt-indentation nil
))
4152 (org-get-indentation))))
4153 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4154 ;; section accordingly. Ignore, however, footnote definitions and
4155 ;; inlinetasks boundaries.
4158 (org-test-with-temp-text "* H\n Paragraph"
4159 (let ((org-odd-levels-only nil
)
4160 (org-adapt-indentation t
))
4163 (org-get-indentation))))
4166 (org-test-with-temp-text "* H\n Paragraph"
4167 (let ((org-odd-levels-only nil
)
4168 (org-adapt-indentation nil
))
4171 (org-get-indentation))))
4174 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4175 (let ((org-odd-levels-only nil
)
4176 (org-adapt-indentation t
))
4178 (goto-char (point-max))
4179 (org-get-indentation))))
4182 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4183 (let ((org-odd-levels-only nil
)
4184 (org-adapt-indentation t
))
4186 (goto-char (point-max))
4187 (org-get-indentation))))
4188 (when (featurep 'org-inlinetask
)
4191 (let ((org-inlinetask-min-level 5)
4192 (org-adapt-indentation t
))
4193 (org-test-with-temp-text "* H\n***** I\n***** END"
4196 (org-get-indentation))))))
4197 (when (featurep 'org-inlinetask
)
4200 (let ((org-inlinetask-min-level 5)
4201 (org-adapt-indentation t
))
4202 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4205 (org-get-indentation))))))
4206 ;; Ignore contents of source blocks or example blocks when
4207 ;; indentation should be preserved (through
4208 ;; `org-src-preserve-indentation' or "-i" flag).
4211 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4212 (let ((org-adapt-indentation t
)
4213 (org-src-preserve-indentation nil
))
4216 (org-get-indentation))))
4219 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4220 (let ((org-adapt-indentation t
)
4221 (org-src-preserve-indentation t
))
4224 (org-get-indentation))))
4227 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4228 (let ((org-adapt-indentation t
)
4229 (org-src-preserve-indentation t
))
4232 (org-get-indentation))))
4235 (org-test-with-temp-text
4236 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4237 (let ((org-adapt-indentation t
)
4238 (org-src-preserve-indentation nil
))
4241 (org-get-indentation)))))
4243 (ert-deftest test-org
/promote
()
4244 "Test `org-promote' specifications."
4245 ;; Return an error if headline is to be promoted to level 0, unless
4246 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4247 ;; headline becomes a comment.
4249 (org-test-with-temp-text "* H"
4250 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4253 (org-test-with-temp-text "* H"
4254 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4256 ;; Remove correct number of stars according to
4257 ;; `org-odd-levels-only'.
4260 (org-test-with-temp-text "*** H"
4261 (let ((org-odd-levels-only nil
)) (org-promote))
4262 (org-current-level))))
4265 (org-test-with-temp-text "*** H"
4266 (let ((org-odd-levels-only t
)) (org-promote))
4267 (org-current-level))))
4268 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4270 (org-test-with-temp-text "** H :tag:"
4271 (let ((org-tags-column 10)
4272 (org-auto-align-tags t
)
4273 (org-odd-levels-only nil
))
4275 (org-move-to-column 10)
4276 (looking-at-p ":tag:$")))
4278 (org-test-with-temp-text "** H :tag:"
4279 (let ((org-tags-column 10)
4280 (org-auto-align-tags nil
)
4281 (org-odd-levels-only nil
))
4283 (org-move-to-column 10)
4284 (looking-at-p ":tag:$")))
4285 ;; When `org-adapt-indentation' is non-nil, always indent planning
4286 ;; info and property drawers.
4289 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4290 (let ((org-odd-levels-only nil
)
4291 (org-adapt-indentation t
))
4294 (org-get-indentation))))
4297 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4298 (let ((org-odd-levels-only nil
)
4299 (org-adapt-indentation t
))
4302 (org-get-indentation))))
4305 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4306 (let ((org-odd-levels-only nil
)
4307 (org-adapt-indentation nil
))
4310 (org-get-indentation))))
4311 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4312 ;; section accordingly. Ignore, however, footnote definitions and
4313 ;; inlinetasks boundaries.
4316 (org-test-with-temp-text "** H\n Paragraph"
4317 (let ((org-odd-levels-only nil
)
4318 (org-adapt-indentation t
))
4321 (org-get-indentation))))
4324 (org-test-with-temp-text "** H\n Paragraph"
4325 (let ((org-odd-levels-only nil
)
4326 (org-adapt-indentation nil
))
4329 (org-get-indentation))))
4332 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4333 (let ((org-odd-levels-only nil
)
4334 (org-adapt-indentation t
))
4337 (org-get-indentation))))
4338 (when (featurep 'org-inlinetask
)
4341 (let ((org-inlinetask-min-level 5)
4342 (org-adapt-indentation t
))
4343 (org-test-with-temp-text "** H\n***** I\n***** END"
4346 (org-get-indentation))))))
4347 (when (featurep 'org-inlinetask
)
4350 (let ((org-inlinetask-min-level 5)
4351 (org-adapt-indentation t
))
4352 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4355 (org-get-indentation))))))
4356 ;; Give up shifting if it would break document's structure
4360 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4361 (let ((org-odd-levels-only nil
)
4362 (org-adapt-indentation t
))
4365 (org-get-indentation))))
4368 (org-test-with-temp-text "** H\n Paragraph\n * list."
4369 (let ((org-odd-levels-only nil
)
4370 (org-adapt-indentation t
))
4373 (org-get-indentation))))
4374 ;; Ignore contents of source blocks or example blocks when
4375 ;; indentation should be preserved (through
4376 ;; `org-src-preserve-indentation' or "-i" flag).
4379 (org-test-with-temp-text
4380 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4381 (let ((org-adapt-indentation t
)
4382 (org-src-preserve-indentation nil
)
4383 (org-odd-levels-only nil
))
4386 (org-get-indentation))))
4389 (org-test-with-temp-text
4390 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4391 (let ((org-adapt-indentation t
)
4392 (org-src-preserve-indentation t
)
4393 (org-odd-levels-only nil
))
4396 (org-get-indentation))))
4399 (org-test-with-temp-text
4400 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4401 (let ((org-adapt-indentation t
)
4402 (org-src-preserve-indentation t
)
4403 (org-odd-levels-only nil
))
4406 (org-get-indentation))))
4409 (org-test-with-temp-text
4410 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4411 (let ((org-adapt-indentation t
)
4412 (org-src-preserve-indentation nil
)
4413 (org-odd-levels-only nil
))
4416 (org-get-indentation)))))
4418 (ert-deftest test-org
/org-get-valid-level
()
4419 "Test function `org-get-valid-level' specifications."
4420 (let ((org-odd-levels-only nil
))
4421 (should (equal 1 (org-get-valid-level 0 0)))
4422 (should (equal 1 (org-get-valid-level 0 1)))
4423 (should (equal 2 (org-get-valid-level 0 2)))
4424 (should (equal 3 (org-get-valid-level 0 3)))
4425 (should (equal 1 (org-get-valid-level 1 0)))
4426 (should (equal 2 (org-get-valid-level 1 1)))
4427 (should (equal 23 (org-get-valid-level 1 22)))
4428 (should (equal 1 (org-get-valid-level 1 -
1)))
4429 (should (equal 1 (org-get-valid-level 2 -
1))))
4430 (let ((org-odd-levels-only t
))
4431 (should (equal 1 (org-get-valid-level 0 0)))
4432 (should (equal 1 (org-get-valid-level 0 1)))
4433 (should (equal 3 (org-get-valid-level 0 2)))
4434 (should (equal 5 (org-get-valid-level 0 3)))
4435 (should (equal 1 (org-get-valid-level 1 0)))
4436 (should (equal 3 (org-get-valid-level 1 1)))
4437 (should (equal 3 (org-get-valid-level 2 1)))
4438 (should (equal 5 (org-get-valid-level 3 1)))
4439 (should (equal 5 (org-get-valid-level 4 1)))
4440 (should (equal 43 (org-get-valid-level 1 21)))
4441 (should (equal 1 (org-get-valid-level 1 -
1)))
4442 (should (equal 1 (org-get-valid-level 2 -
1)))
4443 (should (equal 1 (org-get-valid-level 3 -
1)))
4444 (should (equal 3 (org-get-valid-level 4 -
1)))
4445 (should (equal 3 (org-get-valid-level 5 -
1)))))
4450 (ert-deftest test-org
/at-planning-p
()
4451 "Test `org-at-planning-p' specifications."
4454 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4455 (org-at-planning-p)))
4457 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4458 (org-at-planning-p)))
4459 ;; Correctly find planning attached to inlinetasks.
4460 (when (featurep 'org-inlinetask
)
4462 (org-test-with-temp-text
4463 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4464 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4466 (org-test-with-temp-text
4467 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4468 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4470 (org-test-with-temp-text
4471 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4472 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4474 (org-test-with-temp-text
4475 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4476 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4478 (ert-deftest test-org
/add-planning-info
()
4479 "Test `org-add-planning-info'."
4480 ;; Create deadline when `org-adapt-indentation' is non-nil.
4482 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4483 (org-test-with-temp-text "* H\nParagraph<point>"
4484 (let ((org-adapt-indentation t
))
4485 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4486 (replace-regexp-in-string
4487 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4489 ;; Create deadline when `org-adapt-indentation' is nil.
4491 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4492 (org-test-with-temp-text "* H\nParagraph<point>"
4493 (let ((org-adapt-indentation nil
))
4494 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4495 (replace-regexp-in-string
4496 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4498 ;; Update deadline when `org-adapt-indentation' is non-nil.
4500 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4501 (org-test-with-temp-text "\
4503 DEADLINE: <2015-06-24 Wed>
4505 (let ((org-adapt-indentation t
))
4506 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4507 (replace-regexp-in-string
4508 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4510 ;; Update deadline when `org-adapt-indentation' is nil.
4512 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4513 (org-test-with-temp-text "\
4515 DEADLINE: <2015-06-24 Wed>
4517 (let ((org-adapt-indentation nil
))
4518 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4519 (replace-regexp-in-string
4520 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4522 ;; Schedule when `org-adapt-indentation' is non-nil.
4524 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4525 (org-test-with-temp-text "* H\nParagraph<point>"
4526 (let ((org-adapt-indentation t
))
4527 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4528 (replace-regexp-in-string
4529 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4531 ;; Schedule when `org-adapt-indentation' is nil.
4533 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4534 (org-test-with-temp-text "* H\nParagraph<point>"
4535 (let ((org-adapt-indentation nil
))
4536 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4537 (replace-regexp-in-string
4538 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4540 ;; Add deadline when scheduled.
4544 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4546 (org-test-with-temp-text "\
4548 SCHEDULED: <2015-06-24 Wed>
4550 (let ((org-adapt-indentation t
))
4551 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4552 (replace-regexp-in-string
4553 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4555 ;; Remove middle entry.
4559 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4561 (org-test-with-temp-text "\
4563 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4565 (let ((org-adapt-indentation t
))
4566 (org-add-planning-info nil nil
'deadline
))
4567 (replace-regexp-in-string
4568 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4570 ;; Remove last entry and then middle entry (order should not
4575 CLOSED: [2015-06-24]
4577 (org-test-with-temp-text "\
4579 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4581 (let ((org-adapt-indentation t
))
4582 (org-add-planning-info nil nil
'scheduled
'deadline
))
4583 (replace-regexp-in-string
4584 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4586 ;; Remove closed when `org-adapt-indentation' is non-nil.
4588 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4589 (org-test-with-temp-text "\
4591 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4593 (let ((org-adapt-indentation t
))
4594 (org-add-planning-info nil nil
'closed
))
4595 (replace-regexp-in-string
4596 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4599 (equal "* H\n Paragraph"
4600 (org-test-with-temp-text "\
4602 CLOSED: [2015-06-25 Thu]
4604 (let ((org-adapt-indentation t
))
4605 (org-add-planning-info nil nil
'closed
))
4606 (replace-regexp-in-string
4607 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4609 ;; Remove closed when `org-adapt-indentation' is nil.
4611 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4612 (org-test-with-temp-text "\
4614 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4616 (let ((org-adapt-indentation nil
))
4617 (org-add-planning-info nil nil
'closed
))
4618 (replace-regexp-in-string
4619 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4622 (equal "* H\nParagraph"
4623 (org-test-with-temp-text "\
4625 CLOSED: [2015-06-25 Thu]
4627 (let ((org-adapt-indentation nil
))
4628 (org-add-planning-info nil nil
'closed
))
4629 (replace-regexp-in-string
4630 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4632 ;; Remove closed entry and delete empty line.
4637 (org-test-with-temp-text "\
4639 CLOSED: [2015-06-24 Wed]
4641 (let ((org-adapt-indentation t
))
4642 (org-add-planning-info nil nil
'closed
))
4643 (replace-regexp-in-string
4644 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4646 ;; Remove one entry and update another.
4648 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4649 (org-test-with-temp-text "\
4651 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4653 (let ((org-adapt-indentation t
))
4654 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4655 (replace-regexp-in-string
4656 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4659 (ert-deftest test-org
/deadline
()
4660 "Test `org-deadline' specifications."
4661 ;; Insert a new value or replace existing one.
4663 (equal "* H\nDEADLINE: <2012-03-29>\n"
4664 (org-test-with-temp-text "* H"
4665 (let ((org-adapt-indentation nil
)
4666 (org-last-inserted-timestamp nil
))
4667 (org-deadline nil
"<2012-03-29 Tue>"))
4668 (replace-regexp-in-string
4669 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4672 (equal "* H\nDEADLINE: <2014-03-04>"
4673 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4674 (let ((org-adapt-indentation nil
)
4675 (org-last-inserted-timestamp nil
))
4676 (org-deadline nil
"<2014-03-04 Thu>"))
4677 (replace-regexp-in-string
4678 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4680 ;; Accept delta time, e.g., "+2d".
4682 (equal "* H\nDEADLINE: <2015-03-04>\n"
4683 (cl-letf (((symbol-function 'current-time
)
4684 (lambda (&rest args
)
4685 (apply #'encode-time
4686 (org-parse-time-string "2014-03-04")))))
4687 (org-test-with-temp-text "* H"
4688 (let ((org-adapt-indentation nil
)
4689 (org-last-inserted-timestamp nil
))
4690 (org-deadline nil
"+1y"))
4691 (replace-regexp-in-string
4692 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4693 ;; Preserve repeater.
4695 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4696 (org-test-with-temp-text "* H"
4697 (let ((org-adapt-indentation nil
)
4698 (org-last-inserted-timestamp nil
))
4699 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4700 (replace-regexp-in-string
4701 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4702 ;; Remove CLOSED keyword, if any.
4704 (equal "* H\nDEADLINE: <2012-03-29>"
4705 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4706 (let ((org-adapt-indentation nil
)
4707 (org-last-inserted-timestamp nil
))
4708 (org-deadline nil
"<2012-03-29 Tue>"))
4709 (replace-regexp-in-string
4710 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4711 ;; With C-u argument, remove DEADLINE keyword.
4714 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4715 (let ((org-adapt-indentation nil
)
4716 (org-last-inserted-timestamp nil
))
4717 (org-deadline '(4)))
4721 (org-test-with-temp-text "* H"
4722 (let ((org-adapt-indentation nil
)
4723 (org-last-inserted-timestamp nil
))
4724 (org-deadline '(4)))
4726 ;; With C-u C-u argument, prompt for a delay cookie.
4728 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4729 (cl-letf (((symbol-function 'org-read-date
)
4730 (lambda (&rest args
)
4731 (apply #'encode-time
4732 (org-parse-time-string "2014-03-04")))))
4733 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4734 (let ((org-adapt-indentation nil
)
4735 (org-last-inserted-timestamp nil
))
4736 (org-deadline '(16)))
4739 (cl-letf (((symbol-function 'org-read-date
)
4740 (lambda (&rest args
)
4741 (apply #'encode-time
4742 (org-parse-time-string "2014-03-04")))))
4743 (org-test-with-temp-text "* H"
4744 (let ((org-adapt-indentation nil
)
4745 (org-last-inserted-timestamp nil
))
4746 (org-deadline '(16)))
4748 ;; When a region is active and
4749 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4750 ;; same value in all headlines in region.
4752 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4753 (org-test-with-temp-text "* H1\n* H2"
4754 (let ((org-adapt-indentation nil
)
4755 (org-last-inserted-timestamp nil
)
4756 (org-loop-over-headlines-in-active-region t
))
4757 (transient-mark-mode 1)
4758 (push-mark (point) t t
)
4759 (goto-char (point-max))
4760 (org-deadline nil
"2012-03-29"))
4761 (replace-regexp-in-string
4762 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4764 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4765 (org-test-with-temp-text "* H1\n* H2"
4766 (let ((org-adapt-indentation nil
)
4767 (org-last-inserted-timestamp nil
)
4768 (org-loop-over-headlines-in-active-region nil
))
4769 (transient-mark-mode 1)
4770 (push-mark (point) t t
)
4771 (goto-char (point-max))
4772 (org-deadline nil
"2012-03-29"))
4773 (replace-regexp-in-string
4774 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4776 (ert-deftest test-org
/schedule
()
4777 "Test `org-schedule' specifications."
4778 ;; Insert a new value or replace existing one.
4780 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4781 (org-test-with-temp-text "* H"
4782 (let ((org-adapt-indentation nil
)
4783 (org-last-inserted-timestamp nil
))
4784 (org-schedule nil
"<2012-03-29 Tue>"))
4785 (replace-regexp-in-string
4786 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4789 (equal "* H\nSCHEDULED: <2014-03-04>"
4790 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4791 (let ((org-adapt-indentation nil
)
4792 (org-last-inserted-timestamp nil
))
4793 (org-schedule nil
"<2014-03-04 Thu>"))
4794 (replace-regexp-in-string
4795 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4797 ;; Accept delta time, e.g., "+2d".
4799 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4800 (cl-letf (((symbol-function 'current-time
)
4801 (lambda (&rest args
)
4802 (apply #'encode-time
4803 (org-parse-time-string "2014-03-04")))))
4804 (org-test-with-temp-text "* H"
4805 (let ((org-adapt-indentation nil
)
4806 (org-last-inserted-timestamp nil
))
4807 (org-schedule nil
"+1y"))
4808 (replace-regexp-in-string
4809 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4810 ;; Preserve repeater.
4812 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4813 (org-test-with-temp-text "* H"
4814 (let ((org-adapt-indentation nil
)
4815 (org-last-inserted-timestamp nil
))
4816 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4817 (replace-regexp-in-string
4818 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4819 ;; Remove CLOSED keyword, if any.
4821 (equal "* H\nSCHEDULED: <2012-03-29>"
4822 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4823 (let ((org-adapt-indentation nil
)
4824 (org-last-inserted-timestamp nil
))
4825 (org-schedule nil
"<2012-03-29 Tue>"))
4826 (replace-regexp-in-string
4827 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4828 ;; With C-u argument, remove SCHEDULED keyword.
4831 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4832 (let ((org-adapt-indentation nil
)
4833 (org-last-inserted-timestamp nil
))
4834 (org-schedule '(4)))
4838 (org-test-with-temp-text "* H"
4839 (let ((org-adapt-indentation nil
)
4840 (org-last-inserted-timestamp nil
))
4841 (org-schedule '(4)))
4843 ;; With C-u C-u argument, prompt for a delay cookie.
4845 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4846 (cl-letf (((symbol-function 'org-read-date
)
4847 (lambda (&rest args
)
4848 (apply #'encode-time
4849 (org-parse-time-string "2014-03-04")))))
4850 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4851 (let ((org-adapt-indentation nil
)
4852 (org-last-inserted-timestamp nil
))
4853 (org-schedule '(16)))
4856 (cl-letf (((symbol-function 'org-read-date
)
4857 (lambda (&rest args
)
4858 (apply #'encode-time
4859 (org-parse-time-string "2014-03-04")))))
4860 (org-test-with-temp-text "* H"
4861 (let ((org-adapt-indentation nil
)
4862 (org-last-inserted-timestamp nil
))
4863 (org-schedule '(16)))
4865 ;; When a region is active and
4866 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4867 ;; same value in all headlines in region.
4869 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4870 (org-test-with-temp-text "* H1\n* H2"
4871 (let ((org-adapt-indentation nil
)
4872 (org-last-inserted-timestamp nil
)
4873 (org-loop-over-headlines-in-active-region t
))
4874 (transient-mark-mode 1)
4875 (push-mark (point) t t
)
4876 (goto-char (point-max))
4877 (org-schedule nil
"2012-03-29"))
4878 (replace-regexp-in-string
4879 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4881 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4882 (org-test-with-temp-text "* H1\n* H2"
4883 (let ((org-adapt-indentation nil
)
4884 (org-last-inserted-timestamp nil
)
4885 (org-loop-over-headlines-in-active-region nil
))
4886 (transient-mark-mode 1)
4887 (push-mark (point) t t
)
4888 (goto-char (point-max))
4889 (org-schedule nil
"2012-03-29"))
4890 (replace-regexp-in-string
4891 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4893 ;; check if a repeater survives re-scheduling.
4895 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4896 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4897 (let ((org-adapt-indentation nil
)
4898 (org-last-inserted-timestamp nil
))
4899 (org-schedule nil
"2017-02-01"))
4905 (ert-deftest test-org
/buffer-property-keys
()
4906 "Test `org-buffer-property-keys' specifications."
4907 ;; Retrieve properties accross siblings.
4910 (org-test-with-temp-text "
4919 (org-buffer-property-keys))))
4920 ;; Retrieve properties accross children.
4923 (org-test-with-temp-text "
4932 (org-buffer-property-keys))))
4933 ;; Retrieve muliple properties in the same drawer.
4936 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4937 (org-buffer-property-keys))))
4938 ;; Ignore extension symbol in property name.
4941 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4942 (org-buffer-property-keys))))
4943 ;; With non-nil COLUMNS, extract property names from columns.
4946 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4947 (org-buffer-property-keys nil nil t
))))
4949 (equal '("A" "B" "COLUMNS")
4950 (org-test-with-temp-text
4951 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4952 (org-buffer-property-keys nil nil t
))))
4953 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4956 (org-test-with-temp-text
4957 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4958 (org-buffer-property-keys nil nil nil t
))))
4959 ;; In COLUMNS, ignore title and summary-type.
4962 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4963 (org-buffer-property-keys nil nil t
))))
4966 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4967 (org-buffer-property-keys nil nil t
))))
4970 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4971 (org-buffer-property-keys nil nil t
)))))
4973 (ert-deftest test-org
/property-values
()
4974 "Test `org-property-values' specifications."
4978 (org-test-with-temp-text
4979 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4980 (org-property-values "A"))))
4981 ;; Ignore empty values.
4983 (org-test-with-temp-text
4984 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4985 (org-property-values "A")))
4986 ;; Take into consideration extended values.
4989 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4990 (org-property-values "A")))))
4992 (ert-deftest test-org
/find-property
()
4993 "Test `org-find-property' specifications."
4997 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4998 (org-find-property "prop"))))
4999 ;; Ignore false positives.
5002 (org-test-with-temp-text
5003 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
5004 (org-find-property "A"))))
5005 ;; Return first entry found in buffer.
5008 (org-test-with-temp-text
5009 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5010 (org-find-property "A"))))
5011 ;; Only search visible part of the buffer.
5014 (org-test-with-temp-text
5015 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5016 (org-narrow-to-subtree)
5017 (org-find-property "A"))))
5018 ;; With optional argument, only find entries with a specific value.
5020 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5021 (org-find-property "A" "2")))
5024 (org-test-with-temp-text
5025 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5026 (org-find-property "A" "2"))))
5027 ;; Use "nil" for explicit nil values.
5030 (org-test-with-temp-text
5031 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5032 (org-find-property "A" "nil")))))
5034 (ert-deftest test-org
/entry-delete
()
5035 "Test `org-entry-delete' specifications."
5039 " *:PROPERTIES:\n *:B: +2\n *:END:"
5040 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5041 (org-entry-delete (point) "A")
5043 ;; Also remove accumulated properties.
5047 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5048 (org-entry-delete (point) "A")
5050 ;; When last property is removed, remove the property drawer.
5054 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5055 (org-entry-delete (point) "A")
5057 ;; Return a non-nil value when some property was removed.
5059 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5060 (org-entry-delete (point) "A")))
5062 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5063 (org-entry-delete (point) "C")))
5064 ;; Special properties cannot be located in a drawer. Allow to
5065 ;; remove them anyway, in case of user error.
5067 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5068 (org-entry-delete (point) "SCHEDULED"))))
5070 (ert-deftest test-org
/entry-get
()
5071 "Test `org-entry-get' specifications."
5075 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5076 (org-entry-get (point) "A"))))
5080 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5081 (org-entry-get (point) "a"))))
5082 ;; Handle extended values, both before and after base value.
5085 (org-test-with-temp-text
5086 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5087 (org-entry-get (point) "A"))))
5088 ;; Empty values are returned as the empty string.
5091 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5092 (org-entry-get (point) "A"))))
5093 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5094 ;; otherwise, return nil.
5096 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5097 (org-entry-get (point) "A")))
5100 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5101 (org-entry-get (point) "A" nil t
))))
5102 ;; Return nil when no property is found, independently on the
5103 ;; LITERAL-NIL argument.
5105 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5106 (org-entry-get (point) "B")))
5108 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5109 (org-entry-get (point) "B" nil t
)))
5110 ;; Handle inheritance, when allowed. Include extended values and
5111 ;; possibly global values.
5115 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5116 (org-entry-get (point) "A" t
))))
5120 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5121 (let ((org-use-property-inheritance t
))
5122 (org-entry-get (point) "A" 'selective
)))))
5124 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5125 (let ((org-use-property-inheritance nil
))
5126 (org-entry-get (point) "A" 'selective
))))
5130 (org-test-with-temp-text
5131 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5132 (org-entry-get (point-max) "A" t
))))
5135 (org-test-with-temp-text
5136 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5138 (org-entry-get (point-max) "A" t
))))
5141 (org-test-with-temp-text
5142 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5144 (org-entry-get (point-max) "A" t
)))))
5146 (ert-deftest test-org
/entry-properties
()
5147 "Test `org-entry-properties' specifications."
5148 ;; Get "ITEM" property.
5151 (org-test-with-temp-text "* TODO H"
5152 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5155 (org-test-with-temp-text "* TODO H"
5156 (cdr (assoc "ITEM" (org-entry-properties))))))
5157 ;; Get "TODO" property. TODO keywords are case sensitive.
5160 (org-test-with-temp-text "* TODO H"
5161 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5164 (org-test-with-temp-text "* TODO H"
5165 (cdr (assoc "TODO" (org-entry-properties))))))
5167 (org-test-with-temp-text "* H"
5168 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5170 (org-test-with-temp-text "* todo H"
5171 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5172 ;; Get "PRIORITY" property.
5175 (org-test-with-temp-text "* [#A] H"
5176 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5179 (org-test-with-temp-text "* [#A] H"
5180 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5182 (equal (char-to-string org-default-priority
)
5183 (org-test-with-temp-text "* H"
5184 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5185 ;; Get "FILE" property.
5187 (org-test-with-temp-text-in-file "* H\nParagraph"
5188 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5189 (buffer-file-name))))
5191 (org-test-with-temp-text-in-file "* H\nParagraph"
5192 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5193 (buffer-file-name))))
5195 (org-test-with-temp-text "* H\nParagraph"
5196 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5197 ;; Get "TAGS" property.
5199 (equal ":tag1:tag2:"
5200 (org-test-with-temp-text "* H :tag1:tag2:"
5201 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5203 (equal ":tag1:tag2:"
5204 (org-test-with-temp-text "* H :tag1:tag2:"
5205 (cdr (assoc "TAGS" (org-entry-properties))))))
5207 (org-test-with-temp-text "* H"
5208 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5209 ;; Get "ALLTAGS" property.
5211 (equal ":tag1:tag2:"
5212 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5213 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5215 (equal ":tag1:tag2:"
5216 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5217 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5219 (org-test-with-temp-text "* H"
5220 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5221 ;; Get "BLOCKED" property.
5224 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5225 (let ((org-enforce-todo-dependencies t
)
5227 '(org-block-todo-from-children-or-siblings-or-parent)))
5228 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5231 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5232 (let ((org-enforce-todo-dependencies t
)
5234 '(org-block-todo-from-children-or-siblings-or-parent)))
5235 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5236 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5240 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5241 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5245 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5246 (cdr (assoc "CLOSED" (org-entry-properties))))))
5248 (org-test-with-temp-text "* H"
5249 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5253 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5254 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5258 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5259 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5261 (org-test-with-temp-text "* H"
5262 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5266 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5267 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5271 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5272 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5274 (org-test-with-temp-text "* H"
5275 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5279 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5280 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5283 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5284 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5287 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5288 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5291 (org-test-with-temp-text
5292 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5294 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5295 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5296 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5298 (equal "<2012-03-29 thu.>"
5299 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5300 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5302 (equal "[2012-03-29 thu.]"
5303 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5304 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5306 (equal "<2012-03-29 thu.>"
5307 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5308 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5310 (equal "[2014-03-04 tue.]"
5311 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5312 (cdr (assoc "TIMESTAMP_IA"
5313 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5315 (equal "<2012-03-29 thu.>"
5316 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5317 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5318 ;; Get standard properties.
5321 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5322 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5323 ;; Handle extended properties.
5326 (org-test-with-temp-text
5327 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5328 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5331 (org-test-with-temp-text
5332 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5333 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5334 ;; Ignore forbidden (special) properties.
5336 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5337 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5339 (ert-deftest test-org
/entry-put
()
5340 "Test `org-entry-put' specifications."
5341 ;; Error when not a string or nil.
5343 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5344 (org-entry-put 1 "test" 2)))
5345 ;; Error when property name is invalid.
5347 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5348 (org-entry-put 1 "no space" "value")))
5350 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5351 (org-entry-put 1 "" "value")))
5352 ;; Set "TODO" property.
5354 (string-match (regexp-quote " TODO H")
5355 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5356 (org-entry-put (point) "TODO" "TODO")
5359 (string-match (regexp-quote "* H")
5360 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5361 (org-entry-put (point) "TODO" nil
)
5363 ;; Set "PRIORITY" property.
5366 (org-test-with-temp-text "* [#B] H"
5367 (org-entry-put (point) "PRIORITY" "A")
5371 (org-test-with-temp-text "* [#B] H"
5372 (org-entry-put (point) "PRIORITY" nil
)
5374 ;; Set "SCHEDULED" property.
5376 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5377 (org-test-with-temp-text "* H"
5378 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5382 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5383 (org-entry-put (point) "SCHEDULED" nil
)
5386 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5387 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5388 (org-entry-put (point) "SCHEDULED" "earlier")
5391 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5392 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5393 (org-entry-put (point) "SCHEDULED" "later")
5395 ;; Set "DEADLINE" property.
5397 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5398 (org-test-with-temp-text "* H"
5399 (org-entry-put (point) "DEADLINE" "2014-03-04")
5403 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5404 (org-entry-put (point) "DEADLINE" nil
)
5407 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5408 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5409 (org-entry-put (point) "DEADLINE" "earlier")
5412 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5413 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5414 (org-entry-put (point) "DEADLINE" "later")
5416 ;; Set "CATEGORY" property
5418 (string-match "^ *:CATEGORY: cat"
5419 (org-test-with-temp-text "* H"
5420 (org-entry-put (point) "CATEGORY" "cat")
5422 ;; Regular properties, with or without pre-existing drawer.
5424 (string-match "^ *:A: +2$"
5425 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5426 (org-entry-put (point) "A" "2")
5429 (string-match "^ *:A: +1$"
5430 (org-test-with-temp-text "* H"
5431 (org-entry-put (point) "A" "1")
5433 ;; Special case: two consecutive headlines.
5435 (string-match "\\* A\n *:PROPERTIES:"
5436 (org-test-with-temp-text "* A\n** B"
5437 (org-entry-put (point) "A" "1")
5440 (ert-deftest test-org
/refresh-properties
()
5441 "Test `org-refresh-properties' specifications."
5444 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5445 (org-refresh-properties "A" 'org-test
)
5446 (get-text-property (point) 'org-test
))))
5448 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5449 (org-refresh-properties "B" 'org-test
)
5450 (get-text-property (point) 'org-test
)))
5451 ;; Handle properties only defined with extension syntax, i.e.,
5455 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5456 (org-refresh-properties "A" 'org-test
)
5457 (get-text-property (point) 'org-test
))))
5458 ;; When property is inherited, add text property to the whole
5462 (org-test-with-temp-text
5463 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5464 (let ((org-use-property-inheritance t
))
5465 (org-refresh-properties "A" 'org-test
))
5466 (get-text-property (point) 'org-test
))))
5467 ;; When property is inherited, use global value across the whole
5468 ;; buffer. However local values have precedence.
5471 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5473 (let ((org-use-property-inheritance nil
))
5474 (org-refresh-properties "A" 'org-test
))
5475 (get-text-property (point) 'org-test
))))
5478 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5480 (let ((org-use-property-inheritance t
))
5481 (org-refresh-properties "A" 'org-test
))
5482 (get-text-property (point) 'org-test
))))
5485 (org-test-with-temp-text
5486 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5488 (let ((org-use-property-inheritance t
))
5489 (org-refresh-properties "A" 'org-test
))
5490 (get-text-property (point) 'org-test
)))))
5495 (ert-deftest test-org
/update-radio-target-regexp
()
5496 "Test `org-update-radio-target-regexp' specifications."
5497 ;; Properly update cache with no previous radio target regexp.
5500 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5501 (save-excursion (goto-char (point-max)) (org-element-context))
5503 (search-forward "o")
5505 (org-update-radio-target-regexp)
5506 (goto-char (point-max))
5507 (org-element-type (org-element-context)))))
5508 ;; Properly update cache with previous radio target regexp.
5511 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5512 (save-excursion (goto-char (point-max)) (org-element-context))
5514 (search-forward "o")
5516 (org-update-radio-target-regexp)
5517 (search-backward "r")
5520 (org-update-radio-target-regexp)
5521 (goto-char (point-max))
5522 (delete-region (line-beginning-position) (point))
5524 (org-element-type (org-element-context))))))
5529 (ert-deftest test-org
/refile-get-targets
()
5530 "Test `org-refile-get-targets' specifications."
5531 ;; :maxlevel includes all headings above specified value.
5533 (equal '("H1" "H2" "H3")
5534 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5535 (let ((org-refile-use-outline-path nil
)
5536 (org-refile-targets `((nil :maxlevel .
3))))
5537 (mapcar #'car
(org-refile-get-targets))))))
5540 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5541 (let ((org-refile-use-outline-path nil
)
5542 (org-refile-targets `((nil :maxlevel .
2))))
5543 (mapcar #'car
(org-refile-get-targets))))))
5544 ;; :level limits targets to headlines with the specified level.
5547 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5548 (let ((org-refile-use-outline-path nil
)
5549 (org-refile-targets `((nil :level .
2))))
5550 (mapcar #'car
(org-refile-get-targets))))))
5551 ;; :tag limits targets to headlines with specified tag.
5554 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5555 (let ((org-refile-use-outline-path nil
)
5556 (org-refile-targets `((nil :tag .
"foo"))))
5557 (mapcar #'car
(org-refile-get-targets))))))
5558 ;; :todo limits targets to headlines with specified TODO keyword.
5561 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5562 (let ((org-refile-use-outline-path nil
)
5563 (org-refile-targets `((nil :todo .
"TODO"))))
5564 (mapcar #'car
(org-refile-get-targets))))))
5565 ;; :regexp filters targets matching provided regexp.
5568 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5569 (let ((org-refile-use-outline-path nil
)
5570 (org-refile-targets `((nil :regexp .
"F"))))
5571 (mapcar #'car
(org-refile-get-targets))))))
5572 ;; A nil `org-refile-targets' includes only top level headlines in
5576 (org-test-with-temp-text "* H1\n** S1\n* H2"
5577 (let ((org-refile-use-outline-path nil
)
5578 (org-refile-targets nil
))
5579 (mapcar #'car
(org-refile-get-targets))))))
5580 ;; Return value is the union of the targets according to all the
5581 ;; defined rules. However, prevent duplicates.
5583 (equal '("F2" "F3" "H1")
5584 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5585 (let ((org-refile-use-outline-path nil
)
5586 (org-refile-targets `((nil :regexp .
"F")
5587 (nil :todo .
"TODO"))))
5588 (mapcar #'car
(org-refile-get-targets))))))
5590 (equal '("F2" "F3" "H1")
5591 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5592 (let ((org-refile-use-outline-path nil
)
5593 (org-refile-targets `((nil :regexp .
"F")
5594 (nil :todo .
"TODO"))))
5595 (mapcar #'car
(org-refile-get-targets))))))
5596 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5599 (equal '("H1" "H1/H2" "H1/H2/H3")
5600 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5601 (let ((org-refile-use-outline-path t
)
5602 (org-refile-targets `((nil :maxlevel .
3))))
5603 (mapcar #'car
(org-refile-get-targets))))))
5604 ;; When providing targets as paths, escape forward slashes in
5605 ;; headings with backslashes.
5607 (equal '("H1\\/foo")
5608 (org-test-with-temp-text "* H1/foo"
5609 (let ((org-refile-use-outline-path t
)
5610 (org-refile-targets `((nil :maxlevel .
1))))
5611 (mapcar #'car
(org-refile-get-targets))))))
5612 ;; When `org-refile-use-outline-path' is `file', include file name
5613 ;; without directory in targets.
5615 (org-test-with-temp-text-in-file "* H1"
5616 (let* ((filename (buffer-file-name))
5617 (org-refile-use-outline-path 'file
)
5618 (org-refile-targets `(((,filename
) :level .
1))))
5619 (member (file-name-nondirectory filename
)
5620 (mapcar #'car
(org-refile-get-targets))))))
5621 ;; When `org-refile-use-outline-path' is `full-file-path', include
5624 (org-test-with-temp-text-in-file "* H1"
5625 (let* ((filename (file-truename (buffer-file-name)))
5626 (org-refile-use-outline-path 'full-file-path
)
5627 (org-refile-targets `(((,filename
) :level .
1))))
5628 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5629 ;; When `org-refile-use-outline-path' is `buffer-name', include
5632 (org-test-with-temp-text "* H1"
5633 (let* ((org-refile-use-outline-path 'buffer-name
)
5634 (org-refile-targets `((nil :level .
1))))
5635 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5641 (ert-deftest test-org
/match-sparse-tree
()
5642 "Test `org-match-sparse-tree' specifications."
5645 (org-test-with-temp-text "* H\n** H1 :tag:"
5646 (org-match-sparse-tree nil
"tag")
5647 (search-forward "H1")
5648 (org-invisible-p2)))
5650 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5651 (org-match-sparse-tree nil
"tag")
5652 (search-forward "H2")
5653 (org-invisible-p2)))
5654 ;; "-" operator for tags.
5656 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5657 (org-match-sparse-tree nil
"tag1-tag2")
5658 (search-forward "H1")
5659 (org-invisible-p2)))
5661 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5662 (org-match-sparse-tree nil
"tag1-tag2")
5663 (search-forward "H2")
5664 (org-invisible-p2)))
5665 ;; "&" operator for tags.
5667 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5668 (org-match-sparse-tree nil
"tag1&tag2")
5669 (search-forward "H1")
5670 (org-invisible-p2)))
5672 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5673 (org-match-sparse-tree nil
"tag1&tag2")
5674 (search-forward "H2")
5675 (org-invisible-p2)))
5676 ;; "|" operator for tags.
5678 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5679 (org-match-sparse-tree nil
"tag1|tag2")
5680 (search-forward "H1")
5681 (org-invisible-p2)))
5683 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5684 (org-match-sparse-tree nil
"tag1|tag2")
5685 (search-forward "H2")
5686 (org-invisible-p2)))
5687 ;; Regexp match on tags.
5689 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5690 (org-match-sparse-tree nil
"{^tag.*}")
5691 (search-forward "H1")
5692 (org-invisible-p2)))
5694 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5695 (org-match-sparse-tree nil
"{^tag.*}")
5696 (search-forward "H2")
5697 (org-invisible-p2)))
5698 ;; Match group tags.
5700 (org-test-with-temp-text
5701 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5702 (org-match-sparse-tree nil
"work")
5703 (search-forward "H1")
5704 (org-invisible-p2)))
5706 (org-test-with-temp-text
5707 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5708 (org-match-sparse-tree nil
"work")
5709 (search-forward "H2")
5710 (org-invisible-p2)))
5711 ;; Match group tags with hard brackets.
5713 (org-test-with-temp-text
5714 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5715 (org-match-sparse-tree nil
"work")
5716 (search-forward "H1")
5717 (org-invisible-p2)))
5719 (org-test-with-temp-text
5720 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5721 (org-match-sparse-tree nil
"work")
5722 (search-forward "H2")
5723 (org-invisible-p2)))
5724 ;; Match tags in hierarchies
5726 (org-test-with-temp-text
5727 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5728 #+TAGS: [ Lev_2 : Lev_3 ]\n
5729 #+TAGS: { Lev_3 : Lev_4 }\n
5730 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5731 (org-match-sparse-tree nil
"Lev_1")
5732 (search-forward "H4")
5733 (org-invisible-p2)))
5734 ;; Match regular expressions in tags
5736 (org-test-with-temp-text
5737 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5738 (org-match-sparse-tree nil
"Lev")
5739 (search-forward "H1")
5740 (org-invisible-p2)))
5742 (org-test-with-temp-text
5743 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5744 (org-match-sparse-tree nil
"Lev")
5745 (search-forward "H1")
5746 (org-invisible-p2)))
5747 ;; Match properties.
5749 (org-test-with-temp-text
5750 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5751 (org-match-sparse-tree nil
"A=\"1\"")
5752 (search-forward "H2")
5753 (org-invisible-p2)))
5755 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5756 (org-match-sparse-tree nil
"A=\"1\"")
5757 (search-forward "H2")
5758 (org-invisible-p2)))
5759 ;; Case is not significant when matching properties.
5761 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5762 (org-match-sparse-tree nil
"a=\"1\"")
5763 (search-forward "H2")
5764 (org-invisible-p2)))
5766 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5767 (org-match-sparse-tree nil
"A=\"1\"")
5768 (search-forward "H2")
5769 (org-invisible-p2)))
5770 ;; Match special LEVEL property.
5772 (org-test-with-temp-text "* H\n** H1\n*** H2"
5773 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5774 (search-forward "H1")
5775 (org-invisible-p2)))
5777 (org-test-with-temp-text "* H\n** H1\n*** H2"
5778 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5779 (search-forward "H2")
5780 (org-invisible-p2)))
5781 ;; Comparison operators when matching properties.
5783 (org-test-with-temp-text
5784 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5785 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5786 (search-forward "H1")
5787 (org-invisible-p2)))
5789 (org-test-with-temp-text
5790 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5791 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5792 (search-forward "H2")
5793 (org-invisible-p2)))
5794 ;; Regexp match on properties values.
5796 (org-test-with-temp-text
5797 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5798 (org-match-sparse-tree nil
"A={f.*}")
5799 (search-forward "H1")
5800 (org-invisible-p2)))
5802 (org-test-with-temp-text
5803 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5804 (org-match-sparse-tree nil
"A={f.*}")
5805 (search-forward "H2")
5806 (org-invisible-p2)))
5807 ;; With an optional argument, limit match to TODO entries.
5809 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5810 (org-match-sparse-tree t
"tag")
5811 (search-forward "H1")
5812 (org-invisible-p2)))
5814 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5815 (org-match-sparse-tree t
"tag")
5816 (search-forward "H2")
5817 (org-invisible-p2))))
5819 (ert-deftest test-org
/occur
()
5820 "Test `org-occur' specifications."
5821 ;; Count number of matches.
5824 (org-test-with-temp-text "* H\nA\n* H2"
5828 (org-test-with-temp-text "* H\nA\n* H2\nA"
5830 ;; Test CALLBACK optional argument.
5833 (org-test-with-temp-text "* H\nA\n* H2"
5834 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5837 (org-test-with-temp-text "* H\nA\n* H2\nA"
5838 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5839 ;; Case-fold searches according to `org-occur-case-fold-search'.
5842 (org-test-with-temp-text "Aa"
5843 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5846 (org-test-with-temp-text "Aa"
5847 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5850 (org-test-with-temp-text "Aa"
5851 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5854 (org-test-with-temp-text "Aa"
5855 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5858 (org-test-with-temp-text "Aa"
5859 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5862 (org-test-with-temp-text "Aa"
5863 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5868 (ert-deftest test-org
/tag-string-to-alist
()
5869 "Test `org-tag-string-to-alist' specifications."
5870 ;; Tag without selection key.
5871 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5872 ;; Tag with selection key.
5873 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5877 (org-tag-string-to-alist "[ group : t1 t2 ]")
5878 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5879 ;; Mutually exclusive tags.
5880 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5881 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5884 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5885 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5887 (ert-deftest test-org
/tag-alist-to-string
()
5888 "Test `org-tag-alist-to-string' specifications."
5889 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5890 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5893 (org-tag-alist-to-string
5894 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5895 "[ group : t1 t2 ]"))
5897 (equal (org-tag-alist-to-string
5898 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5902 (org-tag-alist-to-string
5903 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5904 "{ group : tag1 tag2 }")))
5906 (ert-deftest test-org
/tag-alist-to-groups
()
5907 "Test `org-tag-alist-to-groups' specifications."
5909 (equal (org-tag-alist-to-groups
5910 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5911 '(("group" "t1" "t2"))))
5914 (org-tag-alist-to-groups
5915 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5916 '(("group" "t1" "t2"))))
5918 (org-tag-alist-to-groups
5919 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5921 (ert-deftest test-org
/tag-align
()
5922 "Test tags alignment."
5923 ;; Test aligning tags with different display width.
5925 ;; 12345678901234567890
5926 (equal "* Test :abc:"
5927 (org-test-with-temp-text "* Test :abc:"
5928 (let ((org-tags-column -
20)
5929 (indent-tabs-mode nil
))
5930 (org-fix-tags-on-the-fly))
5933 ;; 12345678901234567890
5934 (equal "* Test :日本語:"
5935 (org-test-with-temp-text "* Test :日本語:"
5936 (let ((org-tags-column -
20)
5937 (indent-tabs-mode nil
))
5938 (org-fix-tags-on-the-fly))
5940 ;; Make sure aligning tags do not skip invisible text.
5942 (equal "* [[linkx]] :tag:"
5943 (org-test-with-temp-text "* [[link<point>]] :tag:"
5944 (let ((org-tags-column 0))
5945 (org-fix-tags-on-the-fly)
5947 (buffer-string))))))
5949 (ert-deftest test-org
/tags-at
()
5951 (equal '("foo" "bar")
5952 (org-test-with-temp-text
5953 "* T<point>est :foo:bar:"
5954 (org-get-tags-at)))))
5956 (ert-deftest test-org
/set-tags
()
5957 "Test `org-set-tags' specifications."
5958 ;; Tags set via fast-tag-selection should be visible afterwards
5960 (let ((org-tag-alist '(("NEXT" . ?n
)))
5961 (org-fast-tag-selection-single-key t
))
5962 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5963 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5964 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5965 ;; Show only headlines
5967 ;; Set NEXT tag on current entry
5968 (org-set-tags nil nil
)
5969 ;; Move point to that NEXT tag
5970 (search-forward "NEXT") (backward-word)
5971 ;; And it should be visible (i.e. no overlays)
5972 (not (overlays-at (point))))))))
5974 (ert-deftest test-org
/set-tags-to
()
5975 "Test `org-set-tags-to' specifications."
5976 ;; Throw an error on invalid data.
5978 (org-test-with-temp-text "* H"
5979 (org-set-tags-to 'foo
)))
5980 ;; `nil', an empty, and a blank string remove all tags.
5983 (org-test-with-temp-text "* H :tag1:tag2:"
5984 (org-set-tags-to nil
)
5988 (org-test-with-temp-text "* H :tag1:tag2:"
5989 (org-set-tags-to "")
5993 (org-test-with-temp-text "* H :tag1:tag2:"
5994 (org-set-tags-to " ")
5996 ;; If there's nothing to remove, just bail out.
5999 (org-test-with-temp-text "* H"
6000 (org-set-tags-to nil
)
6004 (org-test-with-temp-text "* "
6005 (org-set-tags-to nil
)
6007 ;; If DATA is a tag string, set current tags to it, even if it means
6008 ;; replacing old tags.
6011 (org-test-with-temp-text "* H :tag1:tag2:"
6012 (org-set-tags-to ":tag0:")
6016 (org-test-with-temp-text "* H"
6017 (org-set-tags-to ":tag0:")
6019 ;; If DATA is a list, set tags to this list, even if it means
6020 ;; replacing old tags.
6023 (org-test-with-temp-text "* H :tag1:tag2:"
6024 (org-set-tags-to '("tag0"))
6028 (org-test-with-temp-text "* H"
6029 (org-set-tags-to '("tag0"))
6031 ;; Special case: handle empty headlines.
6034 (org-test-with-temp-text "* "
6035 (org-set-tags-to '("tag0"))
6041 (ert-deftest test-org
/auto-repeat-maybe
()
6042 "Test `org-auto-repeat-maybe' specifications."
6043 ;; Do not auto repeat when there is no valid time stamp with
6044 ;; a repeater in the entry.
6048 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6049 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
6055 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6056 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
6059 ;; When switching to DONE state, switch back to first TODO keyword
6060 ;; in sequence, or the same keyword if they have different types.
6064 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6065 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6071 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6072 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6078 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
6079 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6082 ;; If there was no TODO keyword in the first place, do not insert
6087 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6088 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6091 ;; Revert to REPEAT_TO_STATE, if set.
6095 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6096 (org-test-with-temp-text
6099 :REPEAT_TO_STATE: KWD2
6101 <2012-03-29 Thu +2y>"
6104 ;; When switching to DONE state, update base date. If there are
6105 ;; multiple repeated time stamps, update them all.
6108 "<2014-03-29 .* \\+2y>"
6109 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6110 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6115 "<2015-03-04 .* \\+1y>"
6116 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6117 (org-test-with-temp-text
6118 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6121 ;; Throw an error if repeater unit is the hour and no time is
6122 ;; provided in the time-stamp.
6124 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6125 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6128 ;; Do not repeat commented time stamps.
6131 "<2015-03-04 .* \\+1y>"
6132 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6133 (org-test-with-temp-text
6134 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6139 "<2015-03-04 .* \\+1y>"
6140 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6141 (org-test-with-temp-text
6143 <2012-03-29 Thu. +2y>
6145 <2014-03-04 Tue +1y>
6149 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6150 ;; entry, record time of last repeat.
6154 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6155 (org-log-repeat nil
))
6156 (cl-letf (((symbol-function 'org-add-log-setup
)
6157 (lambda (&rest args
) nil
)))
6158 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6160 (buffer-string))))))
6164 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6166 (cl-letf (((symbol-function 'org-add-log-setup
)
6167 (lambda (&rest args
) nil
)))
6168 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6170 (buffer-string))))))
6174 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6175 (cl-letf (((symbol-function 'org-add-log-setup
)
6176 (lambda (&rest args
) nil
)))
6177 (org-test-with-temp-text
6178 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6180 (buffer-string))))))
6181 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6182 ;; the entry as it is no longer relevant.
6186 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6187 (org-test-with-temp-text
6188 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6191 ;; Properly advance repeater even when a clock entry is specified
6192 ;; and `org-log-repeat' is nil.
6195 "SCHEDULED: <2014-03-29"
6196 (let ((org-log-repeat nil
)
6197 (org-todo-keywords '((sequence "TODO" "DONE"))))
6198 (org-test-with-temp-text
6200 SCHEDULED: <2012-03-29 Thu +2y>
6201 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6203 (buffer-string))))))
6208 (ert-deftest test-org
/at-timestamp-p
()
6209 "Test `org-at-timestamp-p' specifications."
6211 (org-test-with-temp-text "<2012-03-29 Thu>"
6212 (org-at-timestamp-p)))
6214 (org-test-with-temp-text "2012-03-29 Thu"
6215 (org-at-timestamp-p)))
6216 ;; Test return values.
6219 (org-test-with-temp-text "<2012-03-29 Thu>"
6220 (org-at-timestamp-p))))
6223 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6224 (org-at-timestamp-p))))
6227 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6228 (org-at-timestamp-p))))
6231 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6232 (org-at-timestamp-p))))
6235 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6236 (org-at-timestamp-p))))
6239 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6240 (org-at-timestamp-p))))
6243 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6244 (org-at-timestamp-p))))
6247 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6248 (org-at-timestamp-p))))
6249 ;; Test `inactive' optional argument.
6251 (org-test-with-temp-text "[2012-03-29 Thu]"
6252 (org-at-timestamp-p 'inactive
)))
6254 (org-test-with-temp-text "[2012-03-29 Thu]"
6255 (org-at-timestamp-p)))
6256 ;; When optional argument is `agenda', recognize time-stamps in
6257 ;; planning info line, property drawers and clocks.
6259 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6260 (org-at-timestamp-p 'agenda
)))
6262 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6263 (org-at-timestamp-p)))
6265 (org-test-with-temp-text
6266 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6267 (org-at-timestamp-p 'agenda
)))
6269 (org-test-with-temp-text
6270 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6271 (org-at-timestamp-p)))
6273 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6274 (let ((org-agenda-include-inactive-timestamps t
))
6275 (org-at-timestamp-p 'agenda
))))
6277 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6278 (let ((org-agenda-include-inactive-timestamps t
))
6279 (org-at-timestamp-p))))
6281 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6282 (let ((org-agenda-include-inactive-timestamps t
))
6283 (org-at-timestamp-p 'inactive
))))
6284 ;; When optional argument is `lax', match any part of the document
6285 ;; with Org timestamp syntax.
6287 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6288 (org-at-timestamp-p 'lax
)))
6290 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6291 (org-at-timestamp-p)))
6293 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6294 (org-at-timestamp-p 'lax
)))
6296 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6297 (org-at-timestamp-p)))
6299 (org-test-with-temp-text
6300 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6301 (org-at-timestamp-p 'lax
)))
6303 (org-test-with-temp-text
6304 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6305 (org-at-timestamp-p)))
6306 ;; Optional argument `lax' also matches inactive timestamps.
6308 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6309 (org-at-timestamp-p 'lax
))))
6311 (ert-deftest test-org
/time-stamp
()
6312 "Test `org-time-stamp' specifications."
6313 ;; Insert chosen time stamp at point.
6316 "Te<2014-03-04 .*?>xt"
6317 (org-test-with-temp-text "Te<point>xt"
6318 (cl-letf (((symbol-function 'org-read-date
)
6319 (lambda (&rest args
)
6320 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6321 (org-time-stamp nil
)
6323 ;; With a prefix argument, also insert time.
6326 "Te<2014-03-04 .*? 00:41>xt"
6327 (org-test-with-temp-text "Te<point>xt"
6328 (cl-letf (((symbol-function 'org-read-date
)
6329 (lambda (&rest args
)
6330 (apply #'encode-time
6331 (org-parse-time-string "2014-03-04 00:41")))))
6332 (org-time-stamp '(4))
6334 ;; With two universal prefix arguments, insert an active timestamp
6335 ;; with the current time without prompting the user.
6338 "Te<2014-03-04 .*? 00:41>xt"
6339 (org-test-with-temp-text "Te<point>xt"
6340 (cl-letf (((symbol-function 'current-time
)
6342 (apply #'encode-time
6343 (org-parse-time-string "2014-03-04 00:41")))))
6344 (org-time-stamp '(16))
6346 ;; When optional argument is non-nil, insert an inactive timestamp.
6349 "Te\\[2014-03-04 .*?\\]xt"
6350 (org-test-with-temp-text "Te<point>xt"
6351 (cl-letf (((symbol-function 'org-read-date
)
6352 (lambda (&rest args
)
6353 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6354 (org-time-stamp nil t
)
6356 ;; When called from a timestamp, replace existing one.
6360 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6361 (cl-letf (((symbol-function 'org-read-date
)
6362 (lambda (&rest args
)
6363 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6364 (org-time-stamp nil
)
6368 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6369 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6370 (cl-letf (((symbol-function 'org-read-date
)
6371 (lambda (&rest args
)
6372 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6373 (org-time-stamp nil
)
6375 ;; When replacing a timestamp, preserve repeater, if any.
6378 "<2014-03-04 .*? \\+2y>"
6379 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6380 (cl-letf (((symbol-function 'org-read-date
)
6381 (lambda (&rest args
)
6382 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6383 (org-time-stamp nil
)
6385 ;; When called twice in a raw, build a date range.
6388 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6389 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6390 (cl-letf (((symbol-function 'org-read-date
)
6391 (lambda (&rest args
)
6392 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6393 (let ((last-command 'org-time-stamp
)
6394 (this-command 'org-time-stamp
))
6395 (org-time-stamp nil
))
6396 (buffer-string))))))
6398 (ert-deftest test-org
/timestamp-has-time-p
()
6399 "Test `org-timestamp-has-time-p' specifications."
6402 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6403 (org-timestamp-has-time-p (org-element-context))))
6406 (org-test-with-temp-text "<2012-03-29 Thu>"
6407 (org-timestamp-has-time-p (org-element-context)))))
6409 (ert-deftest test-org
/get-repeat
()
6410 "Test `org-get-repeat' specifications."
6412 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6415 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6417 ;; Return proper repeat string.
6420 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6422 ;; Prevent false positive (commented or verbatim time stamps)
6424 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6427 (org-test-with-temp-text
6428 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6430 ;; Return nil when called before first heading.
6432 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6434 ;; When called with an optional argument, extract repeater from that
6436 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6437 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6439 (ert-deftest test-org
/timestamp-format
()
6440 "Test `org-timestamp-format' specifications."
6445 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6446 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6451 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6452 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6454 (ert-deftest test-org
/timestamp-split-range
()
6455 "Test `org-timestamp-split-range' specifications."
6456 ;; Extract range start (active).
6459 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6460 (let ((ts (org-timestamp-split-range (org-element-context))))
6461 (mapcar (lambda (p) (org-element-property p ts
))
6462 '(:year-end
:month-end
:day-end
))))))
6463 ;; Extract range start (inactive)
6466 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6467 (let ((ts (org-timestamp-split-range (org-element-context))))
6468 (mapcar (lambda (p) (org-element-property p ts
))
6469 '(:year-end
:month-end
:day-end
))))))
6470 ;; Extract range end (active).
6473 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6474 (let ((ts (org-timestamp-split-range
6475 (org-element-context) t
)))
6476 (mapcar (lambda (p) (org-element-property p ts
))
6477 '(:year-end
:month-end
:day-end
))))))
6478 ;; Extract range end (inactive)
6481 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6482 (let ((ts (org-timestamp-split-range
6483 (org-element-context) t
)))
6484 (mapcar (lambda (p) (org-element-property p ts
))
6485 '(:year-end
:month-end
:day-end
))))))
6486 ;; Return the timestamp if not a range.
6488 (org-test-with-temp-text "[2012-03-29 Thu]"
6489 (let* ((ts-orig (org-element-context))
6490 (ts-copy (org-timestamp-split-range ts-orig
)))
6491 (eq ts-orig ts-copy
))))
6493 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6494 (let* ((ts-orig (org-element-context))
6495 (ts-copy (org-timestamp-split-range ts-orig
)))
6496 (eq ts-orig ts-copy
)))))
6498 (ert-deftest test-org
/timestamp-translate
()
6499 "Test `org-timestamp-translate' specifications."
6500 ;; Translate whole date range.
6503 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6504 (let ((org-display-custom-times t
)
6505 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6506 (org-timestamp-translate (org-element-context))))))
6507 ;; Translate date range start.
6510 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6511 (let ((org-display-custom-times t
)
6512 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6513 (org-timestamp-translate (org-element-context) 'start
)))))
6514 ;; Translate date range end.
6517 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6518 (let ((org-display-custom-times t
)
6519 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6520 (org-timestamp-translate (org-element-context) 'end
)))))
6521 ;; Translate time range.
6524 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6525 (let ((org-display-custom-times t
)
6526 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6527 (org-timestamp-translate (org-element-context))))))
6528 ;; Translate non-range timestamp.
6531 (org-test-with-temp-text "<2012-03-29 Thu>"
6532 (let ((org-display-custom-times t
)
6533 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6534 (org-timestamp-translate (org-element-context))))))
6535 ;; Do not change `diary' timestamps.
6537 (equal "<%%(org-float t 4 2)>"
6538 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6539 (let ((org-display-custom-times t
)
6540 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6541 (org-timestamp-translate (org-element-context)))))))
6547 (ert-deftest test-org
/flag-drawer
()
6548 "Test `org-flag-drawer' specifications."
6551 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6553 (get-char-property (line-end-position) 'invisible
)))
6556 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6558 (org-flag-drawer nil
)
6559 (get-char-property (line-end-position) 'invisible
)))
6560 ;; Test optional argument.
6562 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6563 (let ((drawer (save-excursion (search-forward ":D2")
6564 (org-element-at-point))))
6565 (org-flag-drawer t drawer
)
6566 (get-char-property (progn (search-forward ":D2") (line-end-position))
6569 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6570 (let ((drawer (save-excursion (search-forward ":D2")
6571 (org-element-at-point))))
6572 (org-flag-drawer t drawer
)
6573 (get-char-property (line-end-position) 'invisible
))))
6574 ;; Do not hide fake drawers.
6576 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6579 (get-char-property (line-end-position) 'invisible
)))
6580 ;; Do not hide incomplete drawers.
6582 (org-test-with-temp-text ":D:\nparagraph"
6585 (get-char-property (line-end-position) 'invisible
)))
6586 ;; Do not hide drawers when called from final blank lines.
6588 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6589 (goto-char (point-max))
6591 (goto-char (point-min))
6592 (get-char-property (line-end-position) 'invisible
)))
6593 ;; Don't leave point in an invisible part of the buffer when hiding
6596 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6597 (goto-char (point-max))
6599 (get-char-property (point) 'invisible
))))
6601 (ert-deftest test-org
/hide-block-toggle
()
6602 "Test `org-hide-block-toggle' specifications."
6603 ;; Error when not at a block.
6605 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6606 (org-hide-block-toggle 'off
)
6607 (get-char-property (line-end-position) 'invisible
)))
6610 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6611 (org-hide-block-toggle)
6612 (get-char-property (line-end-position) 'invisible
)))
6614 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6615 (org-hide-block-toggle)
6616 (get-char-property (line-end-position) 'invisible
)))
6617 ;; Show block unconditionally when optional argument is `off'.
6619 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6620 (org-hide-block-toggle)
6621 (org-hide-block-toggle 'off
)
6622 (get-char-property (line-end-position) 'invisible
)))
6624 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6625 (org-hide-block-toggle 'off
)
6626 (get-char-property (line-end-position) 'invisible
)))
6627 ;; Hide block unconditionally when optional argument is non-nil.
6629 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6630 (org-hide-block-toggle t
)
6631 (get-char-property (line-end-position) 'invisible
)))
6633 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6634 (org-hide-block-toggle)
6635 (org-hide-block-toggle t
)
6636 (get-char-property (line-end-position) 'invisible
)))
6637 ;; Do not hide block when called from final blank lines.
6639 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6640 (org-hide-block-toggle)
6641 (goto-char (point-min))
6642 (get-char-property (line-end-position) 'invisible
)))
6643 ;; Don't leave point in an invisible part of the buffer when hiding
6646 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6647 (org-hide-block-toggle)
6648 (get-char-property (point) 'invisible
))))
6650 (ert-deftest test-org
/hide-block-toggle-maybe
()
6651 "Test `org-hide-block-toggle-maybe' specifications."
6653 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6654 (org-hide-block-toggle-maybe)))
6656 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6658 (ert-deftest test-org
/show-set-visibility
()
6659 "Test `org-show-set-visibility' specifications."
6660 ;; Do not throw an error before first heading.
6662 (org-test-with-temp-text "Preamble\n* Headline"
6663 (org-show-set-visibility 'tree
)
6665 ;; Test all visibility spans, both on headline and in entry.
6666 (let ((list-visible-lines
6667 (lambda (state headerp
)
6668 (org-test-with-temp-text "* Grandmother (0)
6679 **** The other child (11)
6684 (search-forward (if headerp
"Self" "Match"))
6685 (org-show-set-visibility state
)
6686 (goto-char (point-min))
6687 (let (result (line 0))
6689 (unless (org-invisible-p2) (push line result
))
6692 (nreverse result
))))))
6693 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6694 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6695 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6696 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6697 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6698 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6699 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6700 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6701 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6702 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6703 (funcall list-visible-lines
'tree nil
)))
6704 (should (equal '(0 1 3 4 5 7 12 13)
6705 (funcall list-visible-lines
'canonical t
)))
6706 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6707 (funcall list-visible-lines
'canonical nil
))))
6708 ;; When point is hidden in a drawer or a block, make sure to make it
6711 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6712 (org-hide-block-toggle)
6713 (search-forward "Text")
6714 (org-show-set-visibility 'minimal
)
6715 (org-invisible-p2)))
6717 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6719 (search-forward "Text")
6720 (org-show-set-visibility 'minimal
)
6721 (org-invisible-p2)))
6723 (org-test-with-temp-text
6724 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6727 (org-hide-block-toggle)
6728 (search-forward "Text")
6729 (org-show-set-visibility 'minimal
)
6730 (org-invisible-p2))))
6732 (defun test-org/copy-visible
()
6733 "Test `org-copy-visible' specifications."
6736 (org-test-with-temp-text "Foo"
6737 (let ((kill-ring nil
))
6738 (org-copy-visible (point-min) (point-max))
6739 (current-kill 0 t
)))))
6740 ;; Skip invisible characters by text property.
6743 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6744 (let ((kill-ring nil
))
6745 (org-copy-visible (point-min) (point-max))
6746 (current-kill 0 t
)))))
6747 ;; Skip invisible characters by overlay.
6750 (org-test-with-temp-text "F<hidden>oo"
6751 (let ((o (make-overlay 2 10)))
6752 (overlay-put o
'invisible t
))
6753 (let ((kill-ring nil
))
6754 (org-copy-visible (point-min) (point-max))
6755 (current-kill 0 t
)))))
6756 ;; Handle invisible characters at the beginning and the end of the
6760 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6761 (let ((kill-ring nil
))
6762 (org-copy-visible (point-min) (point-max))
6763 (current-kill 0 t
)))))
6766 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6767 (let ((kill-ring nil
))
6768 (org-copy-visible (point-min) (point-max))
6769 (current-kill 0 t
)))))
6770 ;; Handle multiple visible parts.
6773 (org-test-with-temp-text
6774 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6775 (let ((kill-ring nil
))
6776 (org-copy-visible (point-min) (point-max))
6777 (current-kill 0 t
))))))
6779 (ert-deftest test-org
/set-visibility-according-to-property
()
6780 "Test `org-set-visibility-according-to-property' specifications."
6783 (org-test-with-temp-text
6790 (org-set-visibility-according-to-property)
6791 (invisible-p (point))))
6792 ;; "children" state.
6794 (org-test-with-temp-text
6798 :VISIBILITY: children
6803 (org-set-visibility-according-to-property)
6804 (invisible-p (point))))
6806 (org-test-with-temp-text
6810 :VISIBILITY: children
6815 (org-set-visibility-according-to-property)
6816 (invisible-p (point))))
6819 (org-test-with-temp-text
6823 :VISIBILITY: content
6828 (org-set-visibility-according-to-property)
6829 (invisible-p (point))))
6831 (org-test-with-temp-text
6835 :VISIBILITY: content
6840 (org-set-visibility-according-to-property)
6841 (not (invisible-p (point)))))
6844 (org-test-with-temp-text
6848 :VISIBILITY: showall
6853 (org-set-visibility-according-to-property)
6854 (not (invisible-p (point)))))
6856 (org-test-with-temp-text
6860 :VISIBILITY: showall
6865 (org-set-visibility-according-to-property)
6866 (not (invisible-p (point))))))
6871 ;;; test-org.el ends here