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
)
153 (equal "* COMMENT Test"
154 (org-test-with-temp-text "* Test"
155 (call-interactively #'org-comment-dwim
)
157 ;; In a source block, use appropriate syntax.
160 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively #'org-comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position)
166 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
167 (org-test-with-temp-text
168 "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
169 (transient-mark-mode 1)
170 (push-mark (point) t t
)
172 (let ((org-edit-src-content-indentation 2))
173 (call-interactively #'org-comment-dwim
))
178 ;;; Date and time analysis
180 (ert-deftest test-org
/org-read-date
()
181 "Test `org-read-date' specifications."
182 ;; Parse ISO date with abbreviated year and month.
183 (should (equal "2012-03-29 16:40"
184 (let ((org-time-was-given t
))
185 (org-read-date t nil
"12-3-29 16:40"))))
186 ;; Parse Europeans dates.
187 (should (equal "2012-03-29 16:40"
188 (let ((org-time-was-given t
))
189 (org-read-date t nil
"29.03.2012 16:40"))))
190 ;; Parse Europeans dates without year.
191 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
192 (let ((org-time-was-given t
))
193 (org-read-date t nil
"29.03. 16:40"))))
194 ;; Relative date applied to current time if there is single
195 ;; plus/minus, or to default date when there are two of them.
199 (cl-letf (((symbol-function 'current-time
)
201 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (cl-letf (((symbol-function 'current-time
)
210 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
213 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
214 ;; When `org-read-date-prefer-future' is non-nil, prefer future
215 ;; dates (relatively to now) when incomplete. Otherwise, use
220 (cl-letf (((symbol-function 'current-time
)
222 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
223 (let ((org-read-date-prefer-future t
))
224 (org-read-date t nil
"1")))))
228 (cl-letf (((symbol-function 'current-time
)
230 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
231 (let ((org-read-date-prefer-future t
))
232 (org-read-date t nil
"3-4")))))
236 (cl-letf (((symbol-function 'current-time
)
238 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
239 (let ((org-read-date-prefer-future nil
))
240 (org-read-date t nil
"3-4")))))
241 ;; When set to `org-read-date-prefer-future' is set to `time', read
242 ;; day is moved to tomorrow if specified hour is before current
243 ;; time. However, it only happens in no other part of the date is
248 (cl-letf (((symbol-function 'current-time
)
250 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
251 (let ((org-read-date-prefer-future 'time
))
252 (org-read-date t nil
"00:40" nil
)))))
256 (cl-letf (((symbol-function 'current-time
)
258 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
259 (let ((org-read-date-prefer-future 'time
))
260 (org-read-date t nil
"29 00:40" nil
)))))
261 ;; Caveat: `org-read-date-prefer-future' always refers to current
262 ;; time, not default time, when they differ.
266 (cl-letf (((symbol-function 'current-time
)
268 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
269 (let ((org-read-date-prefer-future t
))
272 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
276 (cl-letf (((symbol-function 'current-time
)
278 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
279 (let ((org-read-date-prefer-future t
))
282 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
284 (ert-deftest test-org
/org-parse-time-string
()
285 "Test `org-parse-time-string'."
286 (should (equal (org-parse-time-string "2012-03-29 16:40")
287 '(0 40 16 29 3 2012 nil nil nil
)))
288 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
289 '(0 40 16 29 3 2012 nil nil nil
)))
290 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
291 '(0 40 16 29 3 2012 nil nil nil
)))
292 (should (equal (org-parse-time-string "<2012-03-29>")
293 '(0 0 0 29 3 2012 nil nil nil
)))
294 (should (equal (org-parse-time-string "<2012-03-29>" t
)
295 '(0 nil nil
29 3 2012 nil nil nil
))))
297 (ert-deftest test-org
/closest-date
()
298 "Test `org-closest-date' specifications."
300 ;; Time stamps without a repeater are returned unchanged.
304 (calendar-gregorian-from-absolute
305 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
306 ;; Time stamps with a null repeater are returned unchanged.
310 (calendar-gregorian-from-absolute
311 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
312 ;; if PREFER is set to `past' always return a date before, or equal
317 (calendar-gregorian-from-absolute
318 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
322 (calendar-gregorian-from-absolute
323 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
324 ;; if PREFER is set to `future' always return a date before, or equal
329 (calendar-gregorian-from-absolute
330 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
334 (calendar-gregorian-from-absolute
335 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
336 ;; If PREFER is neither `past' nor `future', select closest date.
340 (calendar-gregorian-from-absolute
341 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
345 (calendar-gregorian-from-absolute
346 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
347 ;; Test "day" repeater.
350 (calendar-gregorian-from-absolute
351 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
354 (calendar-gregorian-from-absolute
355 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
356 ;; Test "month" repeater.
359 (calendar-gregorian-from-absolute
360 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
363 (calendar-gregorian-from-absolute
364 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
365 ;; Test "year" repeater.
368 (calendar-gregorian-from-absolute
369 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
372 (calendar-gregorian-from-absolute
373 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
375 (ert-deftest test-org
/deadline-close-p
()
376 "Test `org-deadline-close-p' specifications."
377 ;; Pretend that the current time is 2016-06-03 Fri 01:43
378 (cl-letf (((symbol-function 'current-time
)
381 (org-parse-time-string "2016-06-03 Fri 01:43")))))
382 ;; Timestamps are close if they are within `ndays' of lead time.
383 (org-test-with-temp-text "* Heading"
384 (should (org-deadline-close-p "2016-06-03 Fri" 0))
385 (should (org-deadline-close-p "2016-06-02 Thu" 0))
386 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
387 (should (org-deadline-close-p "2016-06-04 Sat" 1))
388 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
389 ;; Read `ndays' from timestamp if argument not given.
390 (org-test-with-temp-text "* H"
391 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
392 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
393 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
394 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
395 ;; Prefer `ndays' argument over lead time in timestamp.
396 (org-test-with-temp-text "* H"
397 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
398 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
399 ;; Completed tasks are never close.
400 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
401 (org-test-with-temp-text "* TODO Heading"
402 (should (org-deadline-close-p "2016-06-03")))
403 (org-test-with-temp-text "* DONE Heading"
404 (should-not (org-deadline-close-p "2016-06-03"))))))
409 (ert-deftest test-org
/insert-property-drawer
()
410 "Test `org-insert-property-drawer' specifications."
411 ;; Error before first headline.
412 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
413 ;; Insert drawer right after headline if there is no planning line,
414 ;; or after it otherwise.
416 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
417 (org-test-with-temp-text "* H\nParagraph<point>"
418 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
421 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
422 (org-test-with-temp-text
423 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
424 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
426 ;; Indent inserted drawer.
428 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
429 (org-test-with-temp-text "* H\nParagraph<point>"
430 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
432 ;; Handle insertion at eob.
434 (equal "* H\n:PROPERTIES:\n:END:\n"
435 (org-test-with-temp-text "* H"
436 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
438 ;; Skip inlinetasks before point.
439 (when (featurep 'org-inlinetask
)
441 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
442 (org-test-with-temp-text
443 "* H\n*************** I\n*************** END\nP<point>"
444 (let ((org-adapt-indentation nil
)
445 (org-inlinetask-min-level 15))
446 (org-insert-property-drawer))
448 ;; Correctly set drawer in an inlinetask.
449 (when (featurep 'org-inlinetask
)
451 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
452 (org-test-with-temp-text
453 "* H\n*************** I\nP<point>\n*************** END"
454 (let ((org-adapt-indentation nil
)
455 (org-inlinetask-min-level 15))
456 (org-insert-property-drawer))
462 (ert-deftest test-org
/fill-element
()
463 "Test `org-fill-element' specifications."
464 ;; At an Org table, align it.
467 (org-test-with-temp-text "|a|"
471 (equal "#+name: table\n| a |\n"
472 (org-test-with-temp-text "#+name: table\n| a |\n"
475 ;; At a paragraph, preserve line breaks.
476 (org-test-with-temp-text "some \\\\\nlong\ntext"
477 (let ((fill-column 20))
479 (should (equal (buffer-string) "some \\\\\nlong text"))))
480 ;; Correctly fill a paragraph when point is at its very end.
483 (org-test-with-temp-text "A\nB"
484 (let ((fill-column 20))
485 (goto-char (point-max))
488 ;; Correctly fill the last paragraph of a greater element.
490 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
491 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
492 (let ((fill-column 8))
497 ;; Correctly fill an element in a narrowed buffer.
500 (org-test-with-temp-text "01234 6789"
501 (let ((fill-column 5))
502 (narrow-to-region 1 8)
505 ;; Handle `adaptive-fill-regexp' in paragraphs.
508 (org-test-with-temp-text "> a\n> b"
509 (let ((fill-column 5)
510 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
513 ;; Special case: Fill first paragraph when point is at an item or
514 ;; a plain-list or a footnote reference.
517 (org-test-with-temp-text "- A\n B"
518 (let ((fill-column 20))
523 (org-test-with-temp-text "[fn:1] A\nB"
524 (let ((fill-column 20))
527 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
528 (let ((fill-column 20))
530 (should (equal (buffer-string)
531 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
532 ;; Fill contents of `comment-block' elements.
535 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
536 (let ((fill-column 20))
540 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
541 ;; Fill `comment' elements.
544 (org-test-with-temp-text " # A\n # B"
545 (let ((fill-column 20))
548 ;; Do not mix consecutive comments when filling one of them.
550 (equal "# A B\n\n# C"
551 (org-test-with-temp-text "# A\n# B\n\n# C"
552 (let ((fill-column 20))
555 ;; Use commented empty lines as separators when filling comments.
557 (equal "# A B\n#\n# C"
558 (org-test-with-temp-text "# A\n# B\n#\n# C"
559 (let ((fill-column 20))
562 ;; Handle `adaptive-fill-regexp' in comments.
565 (org-test-with-temp-text "# > a\n# > b"
566 (let ((fill-column 20)
567 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
570 ;; Do nothing at affiliated keywords.
572 (equal "#+NAME: para\nSome\ntext."
573 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
574 (let ((fill-column 20))
577 ;; Do not move point after table when filling a table.
579 (org-test-with-temp-text "| a | b |\n| c | d |\n"
583 ;; Do not fill "n" macro, with or without arguments, followed by
584 ;; a dot or a closing parenthesis since it could be confused with
585 ;; a numbered bullet.
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()}}}."
600 (org-test-with-temp-text "123456789 {{{n()}}}."
601 (let ((fill-column 10))
605 (equal "123456789\n{{{n(counter)}}}."
606 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
607 (let ((fill-column 10))
611 (ert-deftest test-org
/auto-fill-function
()
612 "Test auto-filling features."
613 ;; Auto fill paragraph.
616 (org-test-with-temp-text "12345 7890"
617 (let ((fill-column 5))
619 (org-auto-fill-function)
621 ;; Auto fill first paragraph in an item.
623 (equal "- 12345\n 7890"
624 (org-test-with-temp-text "- 12345 7890"
625 (let ((fill-column 7))
627 (org-auto-fill-function)
629 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
631 (equal "> 12345\n 7890"
632 (org-test-with-temp-text "> 12345 7890"
633 (let ((fill-column 10)
634 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
635 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
637 (org-auto-fill-function)
640 (equal "> 12345\n> 12345\n> 7890"
641 (org-test-with-temp-text "> 12345\n> 12345 7890"
642 (let ((fill-column 10)
643 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
644 (goto-char (point-max))
645 (org-auto-fill-function)
648 (equal " 12345\n *12345\n *12345"
649 (org-test-with-temp-text " 12345\n *12345 12345"
650 (let ((fill-column 10)
651 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
652 (goto-char (point-max))
653 (org-auto-fill-function)
655 ;; Auto fill comments.
657 (equal " # 12345\n # 7890"
658 (org-test-with-temp-text " # 12345 7890"
659 (let ((fill-column 10))
661 (org-auto-fill-function)
663 ;; A hash within a line isn't a comment.
665 (equal "12345 # 7890\n# 1"
666 (org-test-with-temp-text "12345 # 7890 1"
667 (let ((fill-column 12))
669 (org-auto-fill-function)
671 ;; Correctly interpret empty prefix.
673 (equal "# a\n# b\nRegular\n# paragraph"
674 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
675 (let ((fill-column 12))
677 (org-auto-fill-function)
679 ;; Comment block: auto fill contents.
681 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
682 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
683 (let ((fill-column 5))
686 (org-auto-fill-function)
689 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
690 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
691 (let ((fill-column 5))
694 (org-auto-fill-function)
696 ;; Do not fill if a new item could be created.
699 (org-test-with-temp-text "12345 - 90"
700 (let ((fill-column 5))
702 (org-auto-fill-function)
704 ;; Do not fill if a line break could be introduced.
706 (equal "123\\\\\n7890"
707 (org-test-with-temp-text "123\\\\ 7890"
708 (let ((fill-column 6))
710 (org-auto-fill-function)
712 ;; Do not fill affiliated keywords.
714 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
715 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
716 (let ((fill-column 20))
718 (org-auto-fill-function)
725 (ert-deftest test-org
/indent-line
()
726 "Test `org-indent-line' specifications."
727 ;; Do not indent diary sexps, footnote definitions or headlines.
730 (org-test-with-temp-text "%%(org-calendar-holiday)"
732 (org-get-indentation))))
735 (org-test-with-temp-text "[fn:1] fn"
736 (let ((org-adapt-indentation t
)) (org-indent-line))
737 (org-get-indentation))))
740 (org-test-with-temp-text "* H"
742 (org-get-indentation))))
743 ;; Do not indent before first headline.
746 (org-test-with-temp-text ""
748 (org-get-indentation))))
749 ;; Indent according to headline level otherwise, unless
750 ;; `org-adapt-indentation' is nil.
753 (org-test-with-temp-text "* H\n<point>A"
754 (let ((org-adapt-indentation t
)) (org-indent-line))
755 (org-get-indentation))))
758 (org-test-with-temp-text "* H\n<point>\nA"
759 (let ((org-adapt-indentation t
)) (org-indent-line))
760 (org-get-indentation))))
763 (org-test-with-temp-text "* H\n<point>A"
764 (let ((org-adapt-indentation nil
)) (org-indent-line))
765 (org-get-indentation))))
766 ;; Indenting preserves point position.
768 (org-test-with-temp-text "* H\nA<point>B"
769 (let ((org-adapt-indentation t
)) (org-indent-line))
771 ;; Do not change indentation at an item or a LaTeX environment.
774 (org-test-with-temp-text "* H\n<point> - A"
775 (let ((org-adapt-indentation t
)) (org-indent-line))
776 (org-get-indentation))))
779 (org-test-with-temp-text
780 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
782 (org-get-indentation))))
783 ;; On blank lines at the end of a list, indent like last element
784 ;; within it if the line is still in the list. If the last element
785 ;; is an item, indent like its contents. Otherwise, indent like the
789 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
790 (let ((org-adapt-indentation t
)) (org-indent-line))
791 (org-get-indentation))))
794 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
795 (let ((org-adapt-indentation t
)) (org-indent-line))
796 (org-get-indentation))))
799 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
800 (let ((org-adapt-indentation t
)) (org-indent-line))
801 (org-get-indentation))))
804 (org-test-with-temp-text "* H\n- A\n - \n<point>"
805 (let ((org-adapt-indentation t
)) (org-indent-line))
806 (org-get-indentation))))
809 (org-test-with-temp-text
810 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
811 (let ((org-adapt-indentation t
)) (org-indent-line))
812 (org-get-indentation))))
815 (org-test-with-temp-text "- A\n B\n\n<point>"
816 (let ((org-adapt-indentation nil
)) (org-indent-line))
817 (org-get-indentation))))
820 (org-test-with-temp-text
821 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
822 (let ((org-adapt-indentation nil
)) (org-indent-line))
823 (org-get-indentation))))
824 ;; Likewise, on a blank line at the end of a footnote definition,
825 ;; indent at column 0 if line belongs to the definition. Otherwise,
826 ;; indent like the definition itself.
829 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
830 (let ((org-adapt-indentation t
)) (org-indent-line))
831 (org-get-indentation))))
834 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
835 (let ((org-adapt-indentation t
)) (org-indent-line))
836 (org-get-indentation))))
837 ;; After the end of the contents of a greater element, indent like
838 ;; the beginning of the element.
841 (org-test-with-temp-text
842 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
844 (org-get-indentation))))
845 ;; On blank lines after a paragraph, indent like its last non-empty
849 (org-test-with-temp-text " Paragraph\n\n<point>"
851 (org-get-indentation))))
852 ;; At the first line of an element, indent like previous element's
853 ;; first line, ignoring footnotes definitions and inline tasks, or
854 ;; according to parent.
857 (org-test-with-temp-text "A\n\n B\n\nC<point>"
859 (org-get-indentation))))
862 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
864 (org-get-indentation))))
867 (org-test-with-temp-text
868 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
870 (org-get-indentation))))
871 ;; Within code part of a source block, use language major mode if
872 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
873 ;; according to line above.
876 (org-test-with-temp-text
877 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
878 (let ((org-src-tab-acts-natively t
)
879 (org-edit-src-content-indentation 0))
881 (org-get-indentation))))
884 (org-test-with-temp-text
885 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
886 (let ((org-src-tab-acts-natively nil
)
887 (org-edit-src-content-indentation 0))
889 (org-get-indentation))))
890 ;; Otherwise, indent like the first non-blank line above.
893 (org-test-with-temp-text
894 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
896 (org-get-indentation))))
897 ;; Align node properties according to `org-property-format'. Handle
898 ;; nicely empty values.
900 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
901 (org-test-with-temp-text
902 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
903 (let ((org-property-format "%-10s %s")) (org-indent-line))
906 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
907 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
908 (let ((org-property-format "%-10s %s")) (org-indent-line))
911 (ert-deftest test-org
/indent-region
()
912 "Test `org-indent-region' specifications."
916 (org-test-with-temp-text " A\nB\n C"
917 (org-indent-region (point-min) (point-max))
919 ;; Indent greater elements along with their contents.
921 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
922 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
923 (org-indent-region (point-min) (point-max))
925 ;; Ignore contents of verse blocks. Only indent block delimiters.
927 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
928 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
929 (org-indent-region (point-min) (point-max))
932 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
933 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
934 (org-indent-region (point-min) (point-max))
936 ;; Indent example blocks as a single block, unless indentation
937 ;; should be preserved. In this case only indent the block markers.
939 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
940 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
941 (org-indent-region (point-min) (point-max))
944 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
945 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
946 (org-indent-region (point-min) (point-max))
949 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
950 (org-test-with-temp-text
951 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
952 (org-indent-region (point-min) (point-max))
955 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
956 (org-test-with-temp-text
957 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
958 (let ((org-src-preserve-indentation t
))
959 (org-indent-region (point-min) (point-max)))
961 ;; Treat export blocks as a whole.
963 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
964 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
965 (org-indent-region (point-min) (point-max))
968 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
969 (org-test-with-temp-text
970 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
971 (org-indent-region (point-min) (point-max))
973 ;; Indent according to mode if `org-src-tab-acts-natively' is
974 ;; non-nil. Otherwise, do not indent code at all.
976 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
977 (org-test-with-temp-text
978 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
979 (let ((org-src-tab-acts-natively t
)
980 (org-edit-src-content-indentation 0))
981 (org-indent-region (point-min) (point-max)))
984 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
985 (org-test-with-temp-text
986 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
987 (let ((org-src-tab-acts-natively nil
)
988 (org-edit-src-content-indentation 0))
989 (org-indent-region (point-min) (point-max)))
991 ;; Align node properties according to `org-property-format'. Handle
992 ;; nicely empty values.
994 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
995 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
996 (let ((org-property-format "%-10s %s")
997 (org-adapt-indentation nil
))
998 (org-indent-region (point) (point-max)))
1001 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
1002 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
1003 (let ((org-property-format "%-10s %s")
1004 (org-adapt-indentation nil
))
1005 (org-indent-region (point) (point-max)))
1007 ;; Indent plain lists.
1009 (equal "- A\n B\n - C\n\n D"
1010 (org-test-with-temp-text "- A\n B\n - C\n\n D"
1011 (org-indent-region (point-min) (point-max))
1015 (org-test-with-temp-text " - A\n\n - B"
1016 (org-indent-region (point-min) (point-max))
1018 ;; Indent footnote definitions.
1020 (equal "[fn:1] Definition\n\nDefinition"
1021 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1022 (org-indent-region (point-min) (point-max))
1024 ;; Special case: Start indenting on a blank line.
1026 (equal "\nParagraph"
1027 (org-test-with-temp-text "\n Paragraph"
1028 (org-indent-region (point-min) (point-max))
1035 (ert-deftest test-org
/delete-indentation
()
1036 "Test `org-delete-indentation' specifications."
1038 (should (equal "foo bar"
1039 (org-test-with-temp-text
1041 (org-delete-indentation)
1043 ;; With optional argument.
1044 (should (equal "foo bar"
1045 (org-test-with-temp-text
1047 (org-delete-indentation t
)
1049 ;; At headline text should be appended to the headline text.
1051 (equal"* foo bar :tag:"
1052 (let (org-auto-align-tags)
1053 (org-test-with-temp-text
1054 "* foo :tag:\n bar<point>"
1055 (org-delete-indentation)
1058 (equal "* foo bar :tag:"
1059 (let (org-auto-align-tags)
1060 (org-test-with-temp-text
1061 "* foo <point>:tag:\n bar"
1062 (org-delete-indentation t
)
1063 (buffer-string))))))
1065 (ert-deftest test-org
/return
()
1066 "Test `org-return' specifications."
1069 (equal "Para\ngraph"
1070 (org-test-with-temp-text "Para<point>graph"
1073 ;; With optional argument, indent line.
1075 (equal " Para\n graph"
1076 (org-test-with-temp-text " Para<point>graph"
1079 ;; On a table, call `org-table-next-row'.
1081 (org-test-with-temp-text "| <point>a |\n| b |"
1083 (looking-at-p "b")))
1084 ;; Open link or timestamp under point when `org-return-follows-link'
1087 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1088 (let ((org-return-follows-link t
)
1089 (org-link-search-must-match-exact-headline nil
))
1091 (looking-at-p "<<target>>")))
1093 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1094 (let ((org-return-follows-link nil
)) (org-return))
1095 (looking-at-p "<<target>>")))
1097 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1098 (let ((org-return-follows-link t
)) (org-return))
1099 (looking-at-p "* b")))
1101 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1102 (let ((org-return-follows-link t
)
1103 (org-link-search-must-match-exact-headline nil
))
1105 (looking-at-p "<<target>>")))
1107 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1108 (let ((org-return-follows-link t
)
1109 (org-link-search-must-match-exact-headline nil
))
1111 (looking-at-p "<<target>>")))
1112 ;; When `org-return-follows-link' is non-nil, tolerate links and
1113 ;; timestamps in comments, node properties, etc.
1115 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1116 (let ((org-return-follows-link t
)
1117 (org-link-search-must-match-exact-headline nil
))
1119 (looking-at-p "<<target>>")))
1121 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1122 (let ((org-return-follows-link nil
)) (org-return))
1123 (looking-at-p "<<target>>")))
1125 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1126 (let ((org-return-follows-link t
)
1127 (org-link-search-must-match-exact-headline nil
))
1129 (looking-at-p "<<target>>")))
1130 ;; However, do not open link when point is in a table.
1132 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1133 (let ((org-return-follows-link t
)) (org-return))
1134 (looking-at-p "between")))
1135 ;; Special case: in a list, when indenting, do not break structure.
1138 (org-test-with-temp-text "- A <point>B"
1143 (org-test-with-temp-text "- A\n<point>- B"
1146 ;; On tags part of a headline, add a newline below it instead of
1149 (equal "* H :tag:\n"
1150 (org-test-with-temp-text "* H :<point>tag:"
1153 ;; Before headline text, add a newline below it instead of breaking
1156 (equal "* TODO H :tag:\n"
1157 (org-test-with-temp-text "* <point>TODO H :tag:"
1161 (equal "* TODO [#B] H :tag:\n"
1162 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1165 (should ;TODO are case-sensitive
1167 (org-test-with-temp-text "* <point>Todo"
1170 ;; At headline text, break headline text but preserve tags.
1172 (equal "* TODO [#B] foo :tag:\nbar"
1173 (let (org-auto-align-tags)
1174 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1177 ;; At bol of headline insert newline.
1180 (org-test-with-temp-text "<point>* h"
1183 ;; Refuse to leave invalid headline in buffer.
1186 (org-test-with-temp-text "*<point> h"
1189 ;; Before first column or after last one in a table, split the
1192 (equal "| a |\n\n| b |"
1193 (org-test-with-temp-text "| a |\n<point>| b |"
1197 (equal "| a |\n\n| b |"
1198 (org-test-with-temp-text "| a |<point>\n| b |"
1201 ;; Do not auto-fill on hitting <RET> inside a property drawer.
1203 (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:"
1204 (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:"
1205 (setq-local fill-column
10)
1210 (ert-deftest test-org
/meta-return
()
1211 "Test M-RET (`org-meta-return') specifications."
1212 ;; In a table field insert a row above.
1214 (org-test-with-temp-text "| a |"
1218 (looking-at "| |$")))
1219 ;; In a paragraph change current line into a header.
1221 (org-test-with-temp-text "a"
1224 (looking-at "\* a$")))
1225 ;; In an item insert an item, in this case above.
1227 (org-test-with-temp-text "- a"
1230 (looking-at "- $")))
1231 ;; In a drawer and item insert an item, in this case above.
1233 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1237 (looking-at "- $"))))
1239 (ert-deftest test-org
/insert-heading
()
1240 "Test `org-insert-heading' specifications."
1241 ;; In an empty buffer, insert a new headline.
1244 (org-test-with-temp-text ""
1245 (org-insert-heading)
1247 ;; At the beginning of a line, turn it into a headline.
1250 (org-test-with-temp-text "<point>P"
1251 (org-insert-heading)
1253 ;; In the middle of a line, split the line if allowed, otherwise,
1254 ;; insert the headline at its end.
1256 (equal "Para\n* graph"
1257 (org-test-with-temp-text "Para<point>graph"
1258 (let ((org-M-RET-may-split-line '((default . t
))))
1259 (org-insert-heading))
1262 (equal "Paragraph\n* "
1263 (org-test-with-temp-text "Para<point>graph"
1264 (let ((org-M-RET-may-split-line '((default . nil
))))
1265 (org-insert-heading))
1267 ;; At the beginning of a headline, create one above.
1270 (org-test-with-temp-text "* H"
1271 (org-insert-heading)
1273 ;; In the middle of a headline, split it if allowed.
1276 (org-test-with-temp-text "* H<point>1"
1277 (let ((org-M-RET-may-split-line '((headline . t
))))
1278 (org-insert-heading))
1282 (org-test-with-temp-text "* H<point>1"
1283 (let ((org-M-RET-may-split-line '((headline . nil
))))
1284 (org-insert-heading))
1286 ;; However, splitting cannot happen on TODO keywords, priorities or
1289 (equal "* TODO H1\n* \n"
1290 (org-test-with-temp-text "* TO<point>DO H1"
1291 (let ((org-M-RET-may-split-line '((headline . t
))))
1292 (org-insert-heading))
1295 (equal "* [#A] H1\n* \n"
1296 (org-test-with-temp-text "* [#<point>A] H1"
1297 (let ((org-M-RET-may-split-line '((headline . t
))))
1298 (org-insert-heading))
1301 (equal "* H1 :tag:\n* \n"
1302 (org-test-with-temp-text "* H1 :ta<point>g:"
1303 (let ((org-M-RET-may-split-line '((headline . t
))))
1304 (org-insert-heading))
1306 ;; New headline level depends on the level of the headline above.
1309 (org-test-with-temp-text "** H\n<point>P"
1310 (org-insert-heading)
1313 (equal "** H\nPara\n** graph"
1314 (org-test-with-temp-text "** H\nPara<point>graph"
1315 (let ((org-M-RET-may-split-line '((default . t
))))
1316 (org-insert-heading))
1320 (org-test-with-temp-text "** H"
1321 (org-insert-heading)
1323 ;; When called with one universal argument, insert a new headline at
1324 ;; the end of the current subtree, independently on the position of
1329 (org-test-with-temp-text "* H1\n** H2"
1330 (let ((org-insert-heading-respect-content nil
))
1331 (org-insert-heading '(4)))
1336 (org-test-with-temp-text "* H<point>1\n** H2"
1337 (let ((org-insert-heading-respect-content nil
))
1338 (org-insert-heading '(4)))
1340 ;; When called with two universal arguments, insert a new headline
1341 ;; at the end of the grandparent subtree.
1343 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1344 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1345 (let ((org-insert-heading-respect-content nil
))
1346 (org-insert-heading '(16)))
1348 ;; When optional TOP-LEVEL argument is non-nil, always insert
1349 ;; a level 1 heading.
1351 (equal "* H1\n** H2\n* \n"
1352 (org-test-with-temp-text "* H1\n** H2<point>"
1353 (org-insert-heading nil nil t
)
1356 (equal "* H1\n- item\n* "
1357 (org-test-with-temp-text "* H1\n- item<point>"
1358 (org-insert-heading nil nil t
)
1360 ;; Obey `org-blank-before-new-entry'.
1362 (equal "* H1\n\n* \n"
1363 (org-test-with-temp-text "* H1<point>"
1364 (let ((org-blank-before-new-entry '((heading . t
))))
1365 (org-insert-heading))
1369 (org-test-with-temp-text "* H1<point>"
1370 (let ((org-blank-before-new-entry '((heading . nil
))))
1371 (org-insert-heading))
1374 (equal "* H1\n* H2\n* \n"
1375 (org-test-with-temp-text "* H1\n* H2<point>"
1376 (let ((org-blank-before-new-entry '((heading . auto
))))
1377 (org-insert-heading))
1380 (equal "* H1\n\n* H2\n\n* \n"
1381 (org-test-with-temp-text "* H1\n\n* H2<point>"
1382 (let ((org-blank-before-new-entry '((heading . auto
))))
1383 (org-insert-heading))
1385 ;; Corner case: correctly insert a headline after an empty one.
1388 (org-test-with-temp-text "* <point>"
1389 (org-insert-heading)
1392 (org-test-with-temp-text "* <point>\n"
1393 (org-insert-heading)
1394 (looking-at-p "\n\\'")))
1395 ;; Do not insert spurious headlines when inserting a new headline.
1397 (equal "* H1\n* H2\n* \n"
1398 (org-test-with-temp-text "* H1\n* H2<point>\n"
1399 (org-insert-heading)
1401 ;; Preserve visibility at beginning of line. In particular, when
1402 ;; removing spurious blank lines, do not visually merge heading with
1403 ;; the line visible above.
1405 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1407 (let ((org-blank-before-new-entry '((heading . nil
))))
1408 (org-insert-heading '(4)))
1409 (invisible-p (line-end-position 0))))
1410 ;; Properly handle empty lines when forcing a headline below current
1413 (equal "* H1\n\n* H\n\n* \n"
1414 (org-test-with-temp-text "* H1\n\n* H<point>"
1415 (let ((org-blank-before-new-entry '((heading . t
))))
1416 (org-insert-heading '(4))
1417 (buffer-string))))))
1419 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1420 "Test `org-insert-todo-heading-respect-content' specifications."
1421 ;; Create a TODO heading.
1423 (org-test-with-temp-text "* H1\n Body"
1424 (org-insert-todo-heading-respect-content)
1425 (nth 2 (org-heading-components))))
1426 ;; Add headline at the end of the first subtree
1430 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1431 (org-insert-todo-heading-respect-content)
1432 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1433 ;; In a list, do not create a new item.
1437 (org-test-with-temp-text "* H\n- an item\n- another one"
1438 (search-forward "an ")
1439 (org-insert-todo-heading-respect-content)
1440 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1441 ;; Use the same TODO keyword as current heading.
1445 (org-test-with-temp-text "* TODO\n** WAITING\n"
1446 (org-insert-todo-heading-respect-content)
1447 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1449 (ert-deftest test-org
/clone-with-time-shift
()
1450 "Test `org-clone-subtree-with-time-shift'."
1451 ;; Raise an error before first heading.
1453 (org-test-with-temp-text ""
1454 (org-clone-subtree-with-time-shift 1)))
1455 ;; Raise an error on invalid number of clones.
1457 (org-test-with-temp-text "* Clone me"
1458 (org-clone-subtree-with-time-shift -
1)))
1459 ;; Clone non-repeating once.
1465 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1466 (org-clone-subtree-with-time-shift 1 "+2d")
1467 (replace-regexp-in-string
1468 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1470 ;; Clone repeating once.
1475 * H1\n<2015-06-25 +1w>
1477 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1478 (org-clone-subtree-with-time-shift 1 "+2d")
1479 (replace-regexp-in-string
1480 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1482 ;; Clone non-repeating zero times.
1487 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1488 (org-clone-subtree-with-time-shift 0 "+2d")
1489 (replace-regexp-in-string
1490 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1492 ;; Clone repeating "zero" times.
1496 * H1\n<2015-06-23 +1w>
1498 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1499 (org-clone-subtree-with-time-shift 0 "+2d")
1500 (replace-regexp-in-string
1501 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1503 ;; Clone with blank SHIFT argument.
1507 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1508 (org-clone-subtree-with-time-shift 1 "")
1509 (buffer-substring-no-properties (line-beginning-position 2)
1510 (line-end-position 2)))))
1511 ;; Find time stamps before point. If SHIFT is not specified, ask
1512 ;; for a time shift.
1516 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1517 (org-clone-subtree-with-time-shift 1 "+1d")
1518 (buffer-substring-no-properties (line-beginning-position 2)
1519 (line-end-position 2)))))
1523 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1524 (cl-letf (((symbol-function 'read-from-minibuffer
)
1525 (lambda (&rest args
) "+1d")))
1526 (org-clone-subtree-with-time-shift 1))
1527 (buffer-substring-no-properties (line-beginning-position 2)
1528 (line-end-position 2))))))
1531 ;;; Fixed-Width Areas
1533 (ert-deftest test-org
/toggle-fixed-width
()
1534 "Test `org-toggle-fixed-width' specifications."
1535 ;; No region: Toggle on fixed-width marker in paragraphs.
1538 (org-test-with-temp-text "A"
1539 (org-toggle-fixed-width)
1541 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1544 (org-test-with-temp-text ": A"
1545 (org-toggle-fixed-width)
1547 ;; No region: Toggle on marker in blank lines after elements or just
1548 ;; after a headline.
1551 (org-test-with-temp-text "* H\n"
1553 (org-toggle-fixed-width)
1556 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1557 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1558 (goto-char (point-max))
1559 (org-toggle-fixed-width)
1561 ;; No region: Toggle on marker in front of one line elements (e.g.,
1562 ;; headlines, clocks)
1564 (equal ": * Headline"
1565 (org-test-with-temp-text "* Headline"
1566 (org-toggle-fixed-width)
1569 (equal ": #+KEYWORD: value"
1570 (org-test-with-temp-text "#+KEYWORD: value"
1571 (org-toggle-fixed-width)
1573 ;; No region: error in other situations.
1575 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1577 (org-toggle-fixed-width)
1579 ;; No region: Indentation is preserved.
1582 (org-test-with-temp-text "- A\n B"
1584 (org-toggle-fixed-width)
1586 ;; Region: If it contains only fixed-width elements and blank lines,
1587 ;; toggle off fixed-width markup.
1590 (org-test-with-temp-text ": A\n\n: B"
1591 (transient-mark-mode 1)
1592 (push-mark (point) t t
)
1593 (goto-char (point-max))
1594 (org-toggle-fixed-width)
1596 ;; Region: If it contains anything else, toggle on fixed-width but
1597 ;; not on fixed-width areas.
1599 (equal ": A\n: \n: B\n: \n: C"
1600 (org-test-with-temp-text "A\n\n: B\n\nC"
1601 (transient-mark-mode 1)
1602 (push-mark (point) t t
)
1603 (goto-char (point-max))
1604 (org-toggle-fixed-width)
1606 ;; Region: Ignore blank lines at its end, unless it contains only
1610 (org-test-with-temp-text "A\n\n"
1611 (transient-mark-mode 1)
1612 (push-mark (point) t t
)
1613 (goto-char (point-max))
1614 (org-toggle-fixed-width)
1618 (org-test-with-temp-text "\n\n"
1619 (transient-mark-mode 1)
1620 (push-mark (point) t t
)
1621 (goto-char (point-max))
1622 (org-toggle-fixed-width)
1629 (ert-deftest test-org
/get-heading
()
1630 "Test `org-get-heading' specifications."
1631 ;; Return current heading, even if point is not on it.
1634 (org-test-with-temp-text "* H"
1635 (org-get-heading))))
1638 (org-test-with-temp-text "* H\nText<point>"
1639 (org-get-heading))))
1640 ;; Without any optional argument, return TODO keyword, priority
1641 ;; cookie, COMMENT keyword and tags.
1644 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1645 (org-get-heading))))
1648 (org-test-with-temp-text "* [#A] H"
1649 (org-get-heading))))
1652 (org-test-with-temp-text "* COMMENT H"
1653 (org-get-heading))))
1656 (org-test-with-temp-text "* H :tag:"
1657 (org-get-heading))))
1658 ;; With NO-TAGS argument, ignore tags.
1661 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1662 (org-get-heading t
))))
1665 (org-test-with-temp-text "* H :tag:"
1666 (org-get-heading t
))))
1667 ;; With NO-TODO, ignore TODO keyword.
1670 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1671 (org-get-heading nil t
))))
1674 (org-test-with-temp-text "* H :tag:"
1675 (org-get-heading nil t
))))
1676 ;; TODO keywords are case-sensitive.
1679 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1680 (org-get-heading nil t
))))
1681 ;; With NO-PRIORITY, ignore priority.
1684 (org-test-with-temp-text "* [#A] H"
1685 (org-get-heading nil nil t
))))
1688 (org-test-with-temp-text "* H"
1689 (org-get-heading nil nil t
))))
1692 (org-test-with-temp-text "* TODO [#A] H"
1693 (org-get-heading nil nil t
))))
1694 ;; With NO-COMMENT, ignore COMMENT keyword.
1697 (org-test-with-temp-text "* COMMENT H"
1698 (org-get-heading nil nil nil t
))))
1701 (org-test-with-temp-text "* H"
1702 (org-get-heading nil nil nil t
))))
1704 (equal "TODO [#A] H"
1705 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1706 (org-get-heading nil nil nil t
))))
1707 ;; On an empty headline, return value is consistent.
1708 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1709 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1710 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1711 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1713 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1715 (ert-deftest test-org
/in-commented-heading-p
()
1716 "Test `org-in-commented-heading-p' specifications."
1717 ;; Commented headline.
1719 (org-test-with-temp-text "* COMMENT Headline\nBody"
1720 (goto-char (point-max))
1721 (org-in-commented-heading-p)))
1722 ;; Commented ancestor.
1724 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1725 (goto-char (point-max))
1726 (org-in-commented-heading-p)))
1727 ;; Comment keyword is case-sensitive.
1729 (org-test-with-temp-text "* Comment Headline\nBody"
1730 (goto-char (point-max))
1731 (org-in-commented-heading-p)))
1732 ;; Keyword is standalone.
1734 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1735 (goto-char (point-max))
1736 (org-in-commented-heading-p)))
1737 ;; Optional argument.
1739 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1740 (goto-char (point-max))
1741 (org-in-commented-heading-p t
))))
1743 (ert-deftest test-org
/entry-blocked-p
()
1744 ;; Check other dependencies.
1746 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1747 (let ((org-enforce-todo-dependencies t
)
1749 '(org-block-todo-from-children-or-siblings-or-parent)))
1750 (org-entry-blocked-p))))
1752 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1753 (let ((org-enforce-todo-dependencies t
)
1755 '(org-block-todo-from-children-or-siblings-or-parent)))
1756 (org-entry-blocked-p))))
1757 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1760 (org-test-with-temp-text "* 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))))
1766 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1767 (let ((org-enforce-todo-dependencies t
)
1769 '(org-block-todo-from-children-or-siblings-or-parent)))
1770 (org-entry-blocked-p))))
1771 ;; Follow :ORDERED: specifications.
1773 (org-test-with-temp-text
1774 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1775 (let ((org-enforce-todo-dependencies t
)
1777 '(org-block-todo-from-children-or-siblings-or-parent)))
1778 (org-entry-blocked-p))))
1780 (org-test-with-temp-text
1781 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1782 (let ((org-enforce-todo-dependencies t
)
1784 '(org-block-todo-from-children-or-siblings-or-parent)))
1785 (org-entry-blocked-p)))))
1787 (ert-deftest test-org
/get-outline-path
()
1788 "Test `org-get-outline-path' specifications."
1789 ;; Top-level headlines have no outline path.
1791 (org-test-with-temp-text "* H"
1792 (org-get-outline-path)))
1793 ;; Otherwise, outline path is the path leading to the headline.
1796 (org-test-with-temp-text "* H\n** S<point>"
1797 (org-get-outline-path))))
1798 ;; Find path even when point is not on a headline.
1801 (org-test-with-temp-text "* H\n** S\nText<point>"
1802 (org-get-outline-path))))
1803 ;; TODO keywords, tags and statistics cookies are ignored.
1806 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1807 (org-get-outline-path))))
1808 ;; Links are replaced with their description or their path.
1811 (org-test-with-temp-text
1812 "* [[https://orgmode.org][Org]]\n** S<point>"
1813 (org-get-outline-path))))
1815 (equal '("https://orgmode.org")
1816 (org-test-with-temp-text
1817 "* [[https://orgmode.org]]\n** S<point>"
1818 (org-get-outline-path))))
1819 ;; When WITH-SELF is non-nil, include current heading.
1822 (org-test-with-temp-text "* H"
1823 (org-get-outline-path t
))))
1826 (org-test-with-temp-text "* H\n** S\nText<point>"
1827 (org-get-outline-path t
))))
1828 ;; Using cache is transparent to the user.
1831 (org-test-with-temp-text "* H\n** S<point>"
1832 (setq org-outline-path-cache nil
)
1833 (org-get-outline-path nil t
))))
1834 ;; Do not corrupt cache when finding outline path in distant part of
1838 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1839 (setq org-outline-path-cache nil
)
1840 (org-get-outline-path nil t
)
1841 (search-forward "S2")
1842 (org-get-outline-path nil t
))))
1843 ;; Do not choke on empty headlines.
1845 (org-test-with-temp-text "* H\n** <point>"
1846 (org-get-outline-path)))
1848 (org-test-with-temp-text "* \n** H<point>"
1849 (org-get-outline-path))))
1851 (ert-deftest test-org
/format-outline-path
()
1852 "Test `org-format-outline-path' specifications."
1854 (string= (org-format-outline-path (list "one" "two" "three"))
1858 (string= (org-format-outline-path '())
1861 (string= (org-format-outline-path '(nil))
1863 ;; Empty path and prefix.
1865 (string= (org-format-outline-path '() nil
">>")
1867 ;; Trailing whitespace in headings.
1869 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1871 ;; Non-default prefix and separators.
1873 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1874 ">>|one|two|three"))
1877 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1879 ;; Give a very narrow width.
1881 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1883 ;; Give a prefix that extends beyond the width.
1885 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1889 (ert-deftest test-org
/map-entries
()
1890 "Test `org-map-entries' specifications."
1894 (org-test-with-temp-text "* Level 1\n** Level 2"
1895 (org-map-entries #'point
))))
1899 (org-test-with-temp-text "* Level 1\n** Level 2"
1900 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1903 (org-test-with-temp-text "* Level 1\n** Level 2"
1904 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1908 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1909 (org-map-entries #'point
"yes"))))
1912 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1913 (org-map-entries #'point
"+yes-a"))))
1916 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1917 (org-map-entries #'point
"{yes?}"))))
1921 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1922 (org-map-entries #'point
"PRIORITY=\"A\""))))
1926 (org-test-with-temp-text "
1928 SCHEDULED: <2012-03-29 thu.>
1930 SCHEDULED: <2014-03-04 tue.>"
1931 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1934 (org-test-with-temp-text "
1936 SCHEDULED: <2012-03-29 thu.>
1938 SCHEDULED: <2014-03-04 tue.>"
1939 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1940 ;; Regular property match.
1943 (org-test-with-temp-text "
1952 (org-map-entries #'point
"TEST=1"))))
1953 ;; Multiple criteria.
1956 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1957 (let (org-odd-levels-only
1958 (org-use-tag-inheritance nil
))
1959 (org-map-entries #'point
"yes+LEVEL=1")))))
1963 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1964 (let (org-odd-levels-only)
1965 (org-map-entries #'point
"LEVEL=2|no")))))
1968 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1969 (let (org-odd-levels-only)
1970 (org-map-entries #'point
"yes|no")))))
1974 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1975 (let (org-odd-levels-only)
1976 (org-map-entries #'point
"yes&no"))))))
1978 (ert-deftest test-org
/edit-headline
()
1979 "Test `org-edit-headline' specifications."
1982 (org-test-with-temp-text "* A"
1983 (org-edit-headline "B")
1985 ;; Handle empty headings.
1988 (org-test-with-temp-text "* A"
1989 (org-edit-headline "")
1993 (org-test-with-temp-text "* "
1994 (org-edit-headline "A")
1996 ;; Handle TODO keywords and priority cookies.
1999 (org-test-with-temp-text "* TODO A"
2000 (org-edit-headline "B")
2004 (org-test-with-temp-text "* [#A] A"
2005 (org-edit-headline "B")
2008 (equal "* TODO [#A] B"
2009 (org-test-with-temp-text "* TODO [#A] A"
2010 (org-edit-headline "B")
2014 (org-test-with-temp-text "* A :tag:"
2015 (let ((org-tags-column 4)) (org-edit-headline "B"))
2022 (ert-deftest test-org
/set-regexps-and-options
()
2023 "Test `org-set-regexps-and-options' specifications."
2027 (let ((org-tag-alist '(("A")))
2028 (org-tag-persistent-alist nil
))
2029 (org-test-with-temp-text ""
2031 org-current-tag-alist
))))
2034 (let ((org-tag-alist '(("A")))
2035 (org-tag-persistent-alist nil
))
2036 (org-test-with-temp-text "#+TAGS: B"
2038 org-current-tag-alist
))))
2040 (equal '(("C") ("B"))
2041 (let ((org-tag-alist '(("A")))
2042 (org-tag-persistent-alist '(("C"))))
2043 (org-test-with-temp-text "#+TAGS: B"
2045 org-current-tag-alist
))))
2048 (let ((org-tag-alist '(("A")))
2049 (org-tag-persistent-alist '(("C"))))
2050 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2052 org-current-tag-alist
))))
2054 (equal '(("A" . ?a
) ("B") ("C"))
2055 (let ((org-tag-persistant-alist nil
))
2056 (org-test-with-temp-text "#+TAGS: A(a) B C"
2058 org-current-tag-alist
))))
2060 (equal '(("A") (:newline
) ("B"))
2061 (let ((org-tag-persistent-alist nil
))
2062 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2064 org-current-tag-alist
))))
2066 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2067 (let ((org-tag-persistent-alist nil
))
2068 (org-test-with-temp-text "#+TAGS: { A B } C"
2070 org-current-tag-alist
))))
2072 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2073 (let ((org-tag-persistent-alist nil
))
2074 (org-test-with-temp-text "#+TAGS: { A : B C }"
2076 org-current-tag-alist
))))
2078 (equal '(("A" "B" "C"))
2079 (let ((org-tag-persistent-alist nil
))
2080 (org-test-with-temp-text "#+TAGS: { A : B C }"
2082 org-tag-groups-alist
))))
2084 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2085 (let ((org-tag-persistent-alist nil
))
2086 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2088 org-current-tag-alist
))))
2090 (equal '(("A" "B" "C"))
2091 (let ((org-tag-persistent-alist nil
))
2092 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2094 org-tag-groups-alist
))))
2095 ;; FILETAGS keyword.
2097 (equal '("A" "B" "C")
2098 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2101 ;; PROPERTY keyword. Property names are case-insensitive.
2104 (org-test-with-temp-text "#+PROPERTY: var foo=1"
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 "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2118 (cdr (assoc "var" org-file-properties
)))))
2122 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2124 org-archive-location
)))
2125 ;; CATEGORY keyword.
2128 (org-test-with-temp-text "#+CATEGORY: test"
2133 (org-test-with-temp-text "#+CATEGORY: test"
2135 (cdr (assoc "CATEGORY" org-file-properties
)))))
2138 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2139 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2141 org-columns-default-format
)))
2142 ;; CONSTANTS keyword. Constants names are case sensitive.
2144 (equal '("299792458." "3.14")
2145 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2148 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2152 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2154 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2157 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2159 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2164 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2166 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2168 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2172 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2174 (list org-highest-priority org-lowest-priority org-default-priority
))))
2178 (org-test-with-temp-text "#+PRIORITIES: X Z"
2180 (list org-highest-priority org-lowest-priority org-default-priority
))))
2184 (org-test-with-temp-text "#+STARTUP: fold odd"
2186 (list org-startup-folded org-odd-levels-only
))))
2189 (equal '(("A" "B") ("C"))
2190 (org-test-with-temp-text "#+TODO: A B | C"
2192 (list org-not-done-keywords org-done-keywords
))))
2194 (equal '(("A" "C") ("B" "D"))
2195 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2197 (list org-not-done-keywords org-done-keywords
))))
2199 (equal '(("A" "B") ("C"))
2200 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2202 (list org-not-done-keywords org-done-keywords
))))
2204 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2205 (org-test-with-temp-text "#+TODO: A(a)"
2207 org-todo-key-alist
)))
2209 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2210 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2212 org-todo-log-states
)))
2213 ;; Enter SETUPFILE keyword.
2216 (org-test-with-temp-text
2217 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2219 (cdr (assoc "a" org-file-properties
))))))
2227 (ert-deftest test-org
/coderef
()
2228 "Test coderef links specifications."
2230 (org-test-with-temp-text "
2231 #+BEGIN_SRC emacs-lisp
2236 (looking-at "(ref:sc)")))
2237 ;; Find coderef even with alternate label format.
2239 (org-test-with-temp-text "
2240 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2245 (looking-at "{ref:sc}"))))
2249 (ert-deftest test-org
/custom-id
()
2250 "Test custom ID links specifications."
2252 (org-test-with-temp-text
2253 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2255 (looking-at-p "\\* H1")))
2256 ;; Throw an error on false positives.
2258 (org-test-with-temp-text
2259 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2261 (looking-at-p "\\* H1"))))
2265 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2266 ;; a named element (#+name: text) and to headlines (* Text).
2268 (ert-deftest test-org
/fuzzy-links
()
2269 "Test fuzzy links specifications."
2270 ;; Fuzzy link goes in priority to a matching target.
2272 (org-test-with-temp-text
2273 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2274 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2275 (looking-at "<<Test>>")))
2276 ;; Then fuzzy link points to an element with a given name.
2278 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2279 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2280 (looking-at "#\\+NAME: Test")))
2281 ;; A target still lead to a matching headline otherwise.
2283 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2284 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2285 (looking-at "\\* Head2")))
2286 ;; With a leading star in link, enforce heading match.
2288 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2289 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2290 (looking-at "\\* Test")))
2291 ;; With a leading star in link, enforce exact heading match, even
2292 ;; with `org-link-search-must-match-exact-headline' set to nil.
2294 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2295 (let ((org-link-search-must-match-exact-headline nil
))
2296 (org-open-at-point))))
2297 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2299 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2300 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2301 (looking-at "\\* Test")))
2303 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2304 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2305 (looking-at "\\* Test")))
2306 ;; Heading match should not care about spaces, cookies, TODO
2307 ;; keywords, priorities, and tags. However, TODO keywords are
2311 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2312 (org-test-with-temp-text
2313 (concat first-line
"\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 (looking-at (regexp-quote first-line
)))))
2319 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2320 (let ((org-link-search-must-match-exact-headline nil
)
2321 (org-todo-regexp "TODO"))
2322 (org-open-at-point))))
2323 ;; Heading match should still be exact.
2325 (org-test-with-temp-text "
2326 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2329 (let ((org-link-search-must-match-exact-headline nil
)
2330 (org-todo-regexp "TODO"))
2331 (org-open-at-point))))
2333 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2334 (let ((org-link-search-must-match-exact-headline nil
)
2335 (org-todo-regexp "TODO"))
2336 (org-open-at-point))
2337 (looking-at-p (regexp-quote "** Test 1 2"))))
2338 ;; Heading match ignores COMMENT keyword.
2340 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2342 (looking-at "\\* COMMENT Test")))
2344 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2346 (looking-at "\\* TODO COMMENT Test")))
2347 ;; Correctly un-hexify fuzzy links.
2349 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2353 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2356 ;; Match search strings containing newline characters, including
2359 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2360 (let ((file (buffer-file-name)))
2361 (goto-char (point-max))
2362 (insert (format "[[file:%s::line1 line2]]" file
))
2364 (let ((org-link-search-must-match-exact-headline nil
))
2365 (org-open-at-point 0))
2366 (looking-at-p "line1"))))
2368 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2369 (let ((file (buffer-file-name)))
2370 (goto-char (point-max))
2371 (insert (format "[[file:%s::line1 line2]]" file
))
2373 (let ((org-link-search-must-match-exact-headline nil
))
2374 (org-open-at-point 0))
2375 (looking-at-p "line1")))))
2379 (ert-deftest test-org
/org-link-escape-ascii-character
()
2380 "Escape an ascii character."
2384 (org-link-escape "["))))
2386 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2387 "Escape an ascii control character."
2391 (org-link-escape "\t"))))
2393 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2394 "Escape an unicode multibyte character."
2398 (org-link-escape "€"))))
2400 (ert-deftest test-org
/org-link-escape-custom-table
()
2401 "Escape string with custom character table."
2405 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2407 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2408 "Escape string with custom table merged with default table."
2411 "%5BF%6F%6F%3A%42ar%0A%5D"
2412 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2414 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2415 "Unescape an ascii character."
2419 (org-link-unescape "%5B"))))
2421 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2422 "Unescpae an ascii control character."
2426 (org-link-unescape "%0A"))))
2428 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2429 "Unescape unicode multibyte character."
2433 (org-link-unescape "%E2%82%AC"))))
2435 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2436 "Unescape old style percent escaped character."
2439 "à âçèéêîôùû"
2440 (decode-coding-string
2441 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2443 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2444 "Escape and unescape a URL that includes an escaped char.
2445 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2448 "http://some.host.com/form?&id=blah%2Bblah25"
2450 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2454 (ert-deftest test-org
/open-at-point
/keyword
()
2455 "Does `org-open-at-point' open link in a keyword line?"
2457 (org-test-with-temp-text
2458 "<<top>>\n#+KEYWORD: <point>[[top]]"
2459 (org-open-at-point) t
))
2461 (org-test-with-temp-text
2462 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2463 (org-open-at-point) t
)))
2465 (ert-deftest test-org
/open-at-point
/property
()
2466 "Does `org-open-at-point' open link in property drawer?"
2468 (org-test-with-temp-text
2471 :URL: <point>[[*Headline]]
2473 (org-open-at-point) t
)))
2475 (ert-deftest test-org
/open-at-point
/comment
()
2476 "Does `org-open-at-point' open link in a commented line?"
2478 (org-test-with-temp-text
2479 "<<top>>\n# <point>[[top]]"
2480 (org-open-at-point) t
))
2482 (org-test-with-temp-text
2483 "* H\n<<top>>\n# <point>[[top]]"
2484 (org-open-at-point) t
)))
2486 (ert-deftest test-org
/open-at-point
/inline-image
()
2487 "Test `org-open-at-point' on nested links."
2489 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2493 (ert-deftest test-org
/open-at-point
/radio-target
()
2494 "Test `org-open-at-point' on radio targets."
2496 (org-test-with-temp-text "<<<target>>> <point>target"
2497 (org-update-radio-target-regexp)
2499 (eq (org-element-type (org-element-context)) 'radio-target
))))
2501 (ert-deftest test-org
/open-at-point
/tag
()
2502 "Test `org-open-at-point' on tags."
2504 (org-test-with-temp-text "* H :<point>tag:"
2506 (cl-letf (((symbol-function 'org-tags-view
)
2507 (lambda (&rest args
) (throw :result t
))))
2511 (org-test-with-temp-text-in-file "* H<point> :tag:"
2513 (cl-letf (((symbol-function 'org-tags-view
)
2514 (lambda (&rest args
) (throw :result t
))))
2520 (ert-deftest test-org
/store-link
()
2521 "Test `org-store-link' specifications."
2522 ;; On a headline, link to that headline. Use heading as the
2523 ;; description of the link.
2525 (let (org-store-link-props org-stored-links
)
2526 (org-test-with-temp-text-in-file "* H1"
2527 (let ((file (buffer-file-name)))
2528 (equal (format "[[file:%s::*H1][H1]]" file
)
2529 (org-store-link nil
))))))
2530 ;; On a headline, remove any link from description.
2532 (let (org-store-link-props org-stored-links
)
2533 (org-test-with-temp-text-in-file "* [[#l][d]]"
2534 (let ((file (buffer-file-name)))
2535 (equal (format "[[file:%s::*%s][d]]"
2537 (org-link-escape "[[#l][d]]"))
2538 (org-store-link nil
))))))
2540 (let (org-store-link-props org-stored-links
)
2541 (org-test-with-temp-text-in-file "* [[l]]"
2542 (let ((file (buffer-file-name)))
2543 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2544 (org-store-link nil
))))))
2546 (let (org-store-link-props org-stored-links
)
2547 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2548 (let ((file (buffer-file-name)))
2549 (equal (format "[[file:%s::*%s][d1 d2]]"
2551 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2552 (org-store-link nil
))))))
2553 ;; On a named element, link to that element.
2555 (let (org-store-link-props org-stored-links
)
2556 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2557 (let ((file (buffer-file-name)))
2558 (equal (format "[[file:%s::foo][foo]]" file
)
2559 (org-store-link nil
))))))
2560 ;; Store link to Org buffer, with context.
2562 (let ((org-stored-links nil
)
2563 (org-id-link-to-org-use-id nil
)
2564 (org-context-in-file-links t
))
2565 (org-test-with-temp-text-in-file "* h1"
2566 (let ((file (buffer-file-name)))
2567 (equal (format "[[file:%s::*h1][h1]]" file
)
2568 (org-store-link nil
))))))
2569 ;; Store link to Org buffer, without context.
2571 (let ((org-stored-links nil
)
2572 (org-id-link-to-org-use-id nil
)
2573 (org-context-in-file-links nil
))
2574 (org-test-with-temp-text-in-file "* h1"
2575 (let ((file (buffer-file-name)))
2576 (equal (format "[[file:%s][file:%s]]" file file
)
2577 (org-store-link nil
))))))
2578 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2580 (let ((org-stored-links nil
)
2581 (org-id-link-to-org-use-id nil
)
2582 (org-context-in-file-links nil
))
2583 (org-test-with-temp-text-in-file "* h1"
2584 (let ((file (buffer-file-name)))
2585 (equal (format "[[file:%s::*h1][h1]]" file
)
2586 (org-store-link '(4)))))))
2587 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2590 (let ((org-stored-links nil
)
2591 (org-id-link-to-org-use-id nil
)
2592 (org-context-in-file-links nil
))
2593 (org-test-with-temp-text-in-file "* h1"
2594 (let ((file (buffer-file-name)))
2595 (equal (format "[[file:%s][file:%s]]" file file
)
2596 (org-store-link '(16)))))))
2597 ;; Store file link to non-Org buffer, with context.
2599 (let ((org-stored-links nil
)
2600 (org-context-in-file-links t
))
2601 (org-test-with-temp-text-in-file "one\n<point>two"
2603 (let ((file (buffer-file-name)))
2604 (equal (format "[[file:%s::one]]" file
)
2605 (org-store-link nil
))))))
2606 ;; Store file link to non-Org buffer, without context.
2608 (let ((org-stored-links nil
)
2609 (org-context-in-file-links nil
))
2610 (org-test-with-temp-text-in-file "one\n<point>two"
2612 (let ((file (buffer-file-name)))
2613 (equal (format "[[file:%s][file:%s]]" file file
)
2614 (org-store-link nil
))))))
2615 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2618 (let ((org-stored-links nil
)
2619 (org-context-in-file-links nil
))
2620 (org-test-with-temp-text-in-file "one\n<point>two"
2622 (let ((file (buffer-file-name)))
2623 (equal (format "[[file:%s::one]]" file
)
2624 (org-store-link '(4)))))))
2625 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2628 (let ((org-stored-links nil
)
2629 (org-context-in-file-links nil
))
2630 (org-test-with-temp-text-in-file "one\n<point>two"
2632 (let ((file (buffer-file-name)))
2633 (equal (format "[[file:%s][file:%s]]" file file
)
2634 (org-store-link '(16))))))))
2639 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2640 "Ensure properties accumulate in subtree drawers."
2641 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2642 (org-babel-next-src-block)
2643 (should (equal '(2 1) (org-babel-execute-src-block)))))
2645 (ert-deftest test-org
/custom-properties
()
2646 "Test custom properties specifications."
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))))
2653 ;; Properties are case-insensitive.
2655 (let ((org-custom-properties '("FOO")))
2656 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2657 (org-toggle-custom-properties-visibility)
2658 (org-invisible-p2))))
2660 (let ((org-custom-properties '("foo")))
2661 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2662 (org-toggle-custom-properties-visibility)
2663 (org-invisible-p2))))
2664 ;; Multiple custom properties in the same drawer.
2666 (let ((org-custom-properties '("FOO" "BAR")))
2667 (org-test-with-temp-text
2668 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2669 (org-toggle-custom-properties-visibility)
2670 (and (org-invisible-p2)
2671 (not (progn (forward-line) (org-invisible-p2)))
2672 (progn (forward-line) (org-invisible-p2))))))
2673 ;; Hide custom properties with an empty value.
2675 (let ((org-custom-properties '("FOO")))
2676 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2677 (org-toggle-custom-properties-visibility)
2678 (org-invisible-p2))))
2679 ;; Do not hide fake properties.
2681 (let ((org-custom-properties '("FOO")))
2682 (org-test-with-temp-text ":FOO: val\n"
2683 (org-toggle-custom-properties-visibility)
2684 (org-invisible-p2))))
2686 (let ((org-custom-properties '("A")))
2687 (org-test-with-temp-text
2688 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2689 (org-toggle-custom-properties-visibility)
2690 (org-invisible-p2)))))
2696 (ert-deftest test-org
/mark-subtree
()
2697 "Test `org-mark-subtree' specifications."
2698 ;; Error when point is before first headline.
2700 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2701 (progn (transient-mark-mode 1)
2702 (org-mark-subtree))))
2703 ;; Without argument, mark current subtree.
2707 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2708 (progn (transient-mark-mode 1)
2711 (list (region-beginning) (region-end))))))
2712 ;; With an argument, move ARG up.
2716 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2717 (progn (transient-mark-mode 1)
2719 (org-mark-subtree 1)
2720 (list (region-beginning) (region-end))))))
2721 ;; Do not get fooled by inlinetasks.
2722 (when (featurep 'org-inlinetask
)
2725 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2726 (progn (transient-mark-mode 1)
2728 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2729 (region-beginning)))))))
2735 (ert-deftest test-org
/sort-entries
()
2736 "Test `org-sort-entries'."
2737 ;; Sort alphabetically.
2739 (equal "\n* abc\n* def\n* xyz\n"
2740 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2741 (org-sort-entries nil ?a
)
2744 (equal "\n* xyz\n* def\n* abc\n"
2745 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2746 (org-sort-entries nil ?A
)
2749 (equal "\n* \n* klm\n* xyz\n"
2750 (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
2751 (org-sort-entries nil ?a
)
2753 ;; Sort numerically.
2755 (equal "\n* 1\n* 2\n* 10\n"
2756 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2757 (org-sort-entries nil ?n
)
2760 (equal "\n* 10\n* 2\n* 1\n"
2761 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2762 (org-sort-entries nil ?N
)
2765 (equal "\n* \n* 1\n* 2\n"
2766 (org-test-with-temp-text "\n* 1\n* \n* 2\n"
2767 (org-sort-entries nil ?n
)
2769 ;; Sort by custom function.
2771 (equal "\n* b\n* aa\n* ccc\n"
2772 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2773 (org-sort-entries nil ?f
2775 (length (buffer-substring (point-at-bol)
2780 (equal "\n* ccc\n* aa\n* b\n"
2781 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2782 (org-sort-entries nil ?F
2784 (length (buffer-substring (point-at-bol)
2788 ;; Sort by TODO keyword.
2790 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2791 (org-test-with-temp-text
2792 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2793 (org-sort-entries nil ?o
)
2796 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2797 (org-test-with-temp-text
2798 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2799 (org-sort-entries nil ?O
)
2801 ;; Sort by priority.
2803 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2804 (org-test-with-temp-text
2805 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2806 (org-sort-entries nil ?p
)
2809 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2810 (org-test-with-temp-text
2811 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2812 (org-sort-entries nil ?P
)
2814 ;; Sort by creation time.
2824 (org-test-with-temp-text
2833 (org-sort-entries nil ?c
)
2836 ;; Sort by scheduled date.
2840 SCHEDULED: <2017-05-06 Sat>
2842 SCHEDULED: <2017-05-08 Mon>
2844 DEADLINE: <2017-05-09 Tue>
2846 DEADLINE: <2017-05-07 Sun>
2848 (org-test-with-temp-text
2851 DEADLINE: <2017-05-09 Tue>
2853 DEADLINE: <2017-05-07 Sun>
2855 SCHEDULED: <2017-05-08 Mon>
2857 SCHEDULED: <2017-05-06 Sat>
2859 (org-sort-entries nil ?s
)
2861 ;; Sort by deadline date.
2865 DEADLINE: <2017-05-07 Sun>
2867 DEADLINE: <2017-05-09 Tue>
2869 SCHEDULED: <2017-05-08 Mon>
2871 SCHEDULED: <2017-05-06 Sat>
2873 (org-test-with-temp-text
2876 DEADLINE: <2017-05-09 Tue>
2878 DEADLINE: <2017-05-07 Sun>
2880 SCHEDULED: <2017-05-08 Mon>
2882 SCHEDULED: <2017-05-06 Sat>
2884 (org-sort-entries nil ?d
)
2886 ;; Sort by any date/time
2890 SCHEDULED: <2017-05-06 Sat>
2892 DEADLINE: <2017-05-07 Sun>
2894 SCHEDULED: <2017-05-08 Mon>
2896 DEADLINE: <2017-05-09 Tue>
2898 (org-test-with-temp-text
2901 DEADLINE: <2017-05-09 Tue>
2903 DEADLINE: <2017-05-07 Sun>
2905 SCHEDULED: <2017-05-08 Mon>
2907 SCHEDULED: <2017-05-06 Sat>
2909 (org-sort-entries nil ?t
)
2911 ;; Sort by clocking time.
2916 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2917 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2921 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2922 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2925 (org-test-with-temp-text
2929 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2930 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2934 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2935 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2938 (org-sort-entries nil ?k
)
2940 ;; Preserve file local variables when sorting.
2942 (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
2943 (org-test-with-temp-text
2944 "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
2945 (org-sort-entries nil ?a
)
2948 (ert-deftest test-org
/string-collate-greaterp
()
2949 "Test `org-string-collate-greaterp' specifications."
2950 (should (org-string-collate-greaterp "def" "abc"))
2951 (should-not (org-string-collate-greaterp "abc" "def")))
2953 (ert-deftest test-org
/file-contents
()
2954 "Test `org-file-contents' specifications."
2957 (string= "#+BIND: variable value
2963 " (org-file-contents (expand-file-name "setupfile3.org"
2964 (concat org-test-dir
"examples/")))))
2965 ;; Throw error when trying to access an invalid file.
2966 (should-error (org-file-contents "this-file-must-not-exist"))
2967 ;; Try to access an invalid file, but do not throw an error.
2969 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2973 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2975 ;; Simulate successful retrieval of a URL.
2976 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2978 (with-current-buffer buffer
2979 (insert "HTTP/1.1 200 OK\n\nfoo"))
2981 (org-file-contents "http://some-valid-url"))
2982 (kill-buffer buffer
)))))
2983 ;; Throw error when trying to access an invalid URL.
2985 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2987 ;; Simulate unsuccessful retrieval of a URL.
2988 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2990 (with-current-buffer buffer
2991 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2993 (org-file-contents "http://this-url-must-not-exist"))
2994 (kill-buffer buffer
))))
2995 ;; Try to access an invalid URL, but do not throw an error.
2997 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2999 ;; Simulate unsuccessful retrieval of a URL.
3000 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3002 (with-current-buffer buffer
3003 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3005 (org-file-contents "http://this-url-must-not-exist"))
3006 (kill-buffer buffer
))))
3008 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3010 ;; Simulate unsuccessful retrieval of a URL.
3011 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3013 (with-current-buffer buffer
3014 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3016 (org-file-contents "http://this-url-must-not-exist" :noerror
))
3017 (kill-buffer buffer
))
3023 (ert-deftest test-org
/forward-heading-same-level
()
3024 "Test `org-forward-heading-same-level' specifications."
3025 ;; Test navigation at top level, forward and backward.
3028 (org-test-with-temp-text "* H1\n* H2"
3029 (org-forward-heading-same-level 1)
3030 (buffer-substring-no-properties (point) (line-end-position)))))
3033 (org-test-with-temp-text "* H1\n<point>* H2"
3034 (org-forward-heading-same-level -
1)
3035 (buffer-substring-no-properties (point) (line-end-position)))))
3036 ;; Test navigation in a sub-tree, forward and backward.
3039 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
3040 (org-forward-heading-same-level 1)
3041 (buffer-substring-no-properties (point) (line-end-position)))))
3044 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3045 (org-forward-heading-same-level -
1)
3046 (buffer-substring-no-properties (point) (line-end-position)))))
3047 ;; Stop at first or last sub-heading.
3050 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3051 (org-forward-heading-same-level 1)
3052 (buffer-substring-no-properties (point) (line-end-position)))))
3055 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3056 (org-forward-heading-same-level -
1)
3057 (buffer-substring-no-properties (point) (line-end-position)))))
3058 ;; Allow multiple moves.
3061 (org-test-with-temp-text "* H1\n* H2\n* H3"
3062 (org-forward-heading-same-level 2)
3063 (buffer-substring-no-properties (point) (line-end-position)))))
3066 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3067 (org-forward-heading-same-level -
2)
3068 (buffer-substring-no-properties (point) (line-end-position)))))
3069 ;; Ignore spurious moves when first (or last) sibling is reached.
3072 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3073 (org-forward-heading-same-level 100)
3074 (buffer-substring-no-properties (point) (line-end-position)))))
3077 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3078 (org-forward-heading-same-level -
100)
3079 (buffer-substring-no-properties (point) (line-end-position))))))
3081 (ert-deftest test-org
/end-of-meta-data
()
3082 "Test `org-end-of-meta-data' specifications."
3083 ;; Skip planning line.
3085 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3086 (org-end-of-meta-data)
3088 ;; Skip properties drawer.
3090 (org-test-with-temp-text
3091 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3092 (org-end-of-meta-data)
3096 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3097 (org-end-of-meta-data)
3099 ;; Nothing to skip, go to first line.
3101 (org-test-with-temp-text "* Headline\nContents"
3102 (org-end-of-meta-data)
3103 (looking-at "Contents")))
3104 ;; With option argument, skip empty lines, regular drawers and
3107 (org-test-with-temp-text "* Headline\n\nContents"
3108 (org-end-of-meta-data t
)
3109 (looking-at "Contents")))
3111 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3112 (org-end-of-meta-data t
)
3113 (looking-at "Contents")))
3115 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3116 (org-end-of-meta-data t
)
3117 (looking-at "Contents")))
3118 ;; Special case: do not skip incomplete drawers.
3120 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3121 (org-end-of-meta-data t
)
3122 (looking-at ":LOGBOOK:")))
3123 ;; Special case: Be careful about consecutive headlines.
3125 (org-test-with-temp-text "* H1\n*H2\nContents"
3126 (org-end-of-meta-data t
)
3127 (looking-at "Contents"))))
3129 (ert-deftest test-org
/beginning-of-line
()
3130 "Test `org-beginning-of-line' specifications."
3131 ;; Move to beginning of line. If current line in invisible, move to
3132 ;; beginning of visible line instead.
3134 (org-test-with-temp-text "Some text\nSome other text<point>"
3135 (org-beginning-of-line)
3138 (org-test-with-temp-text "* H1\n** H2<point>"
3140 (org-beginning-of-line)
3141 (= (line-beginning-position) 1)))
3142 ;; With `visual-line-mode' active, move to beginning of visual line.
3144 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3146 (dotimes (i 1000) (insert "very "))
3147 (org-beginning-of-line)
3149 ;; In a wide headline, with `visual-line-mode', prefer going to the
3150 ;; beginning of a visual line than to the logical beginning of line,
3151 ;; even if special movement is active.
3153 (org-test-with-temp-text "* A <point>long headline"
3155 (dotimes (i 1000) (insert "very "))
3156 (goto-char (point-max))
3157 (org-beginning-of-line)
3160 (org-test-with-temp-text "* A <point>long headline"
3162 (dotimes (i 1000) (insert "very "))
3163 (goto-char (point-max))
3164 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3166 ;; At an headline with special movement, first move at beginning of
3167 ;; title, then at the beginning of line, rinse, repeat.
3169 (org-test-with-temp-text "* TODO Headline<point>"
3170 (let ((org-special-ctrl-a/e t
))
3171 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3172 (progn (org-beginning-of-line) (bolp))
3173 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3175 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3176 (let ((org-special-ctrl-a/e t
))
3177 (org-beginning-of-line)
3178 (looking-at "Headline"))))
3180 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3181 (let ((org-special-ctrl-a/e
'(t . nil
)))
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
'(nil . nil
)))
3187 (org-beginning-of-line)
3188 (looking-at "Headline"))))
3189 ;; At an headline with reversed movement, first move to beginning of
3190 ;; line, then to the beginning of title.
3192 (org-test-with-temp-text "* TODO Headline<point>"
3193 (let ((org-special-ctrl-a/e
'reversed
)
3194 (this-command last-command
))
3195 (and (progn (org-beginning-of-line) (bolp))
3196 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3198 (org-test-with-temp-text "* TODO Headline<point>"
3199 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3200 (this-command last-command
))
3201 (and (progn (org-beginning-of-line) (bolp))
3202 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3204 (org-test-with-temp-text "* TODO Headline<point>"
3205 (let ((org-special-ctrl-a/e
'(t . nil
))
3206 (this-command last-command
))
3207 (and (progn (org-beginning-of-line) (bolp))
3208 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3209 ;; At an item with special movement, first move after to beginning
3210 ;; of title, then to the beginning of line, rinse, repeat.
3212 (org-test-with-temp-text "- [ ] Item<point>"
3213 (let ((org-special-ctrl-a/e t
))
3214 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3215 (progn (org-beginning-of-line) (bolp))
3216 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3217 ;; At an item with reversed movement, first move to beginning of
3218 ;; line, then to the beginning of title.
3220 (org-test-with-temp-text "- [X] Item<point>"
3221 (let ((org-special-ctrl-a/e
'reversed
)
3222 (this-command last-command
))
3223 (and (progn (org-beginning-of-line) (bolp))
3224 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3225 ;; Leave point before invisible characters at column 0.
3227 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3228 (let ((org-special-ctrl-a/e nil
))
3229 (org-beginning-of-line)
3232 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3233 (let ((org-special-ctrl-a/e t
))
3234 (org-beginning-of-line)
3237 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3239 (org-beginning-of-line)
3241 ;; Special case: Do not error when the buffer contains only a single
3244 (org-test-with-temp-text "*<point>"
3245 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3247 (org-test-with-temp-text "*<point>"
3248 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3250 (ert-deftest test-org
/end-of-line
()
3251 "Test `org-end-of-line' specifications."
3254 (org-test-with-temp-text "Some text\nSome other text"
3257 ;; With `visual-line-mode' active, move to end of visible line.
3258 ;; However, never go past ellipsis.
3260 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3262 (dotimes (i 1000) (insert "very "))
3263 (goto-char (point-min))
3267 (org-test-with-temp-text "* A short headline\nSome contents"
3272 ;; In a wide headline, with `visual-line-mode', prefer going to end
3273 ;; of visible line if tags, or end of line, are farther.
3275 (org-test-with-temp-text "* A <point>long headline"
3277 (dotimes (i 1000) (insert "very "))
3278 (goto-char (point-min))
3282 (org-test-with-temp-text "* A <point>long headline :tag:"
3284 (dotimes (i 1000) (insert "very "))
3285 (goto-char (point-min))
3288 ;; At an headline without special movement, go to end of line.
3289 ;; However, never go past ellipsis.
3291 (org-test-with-temp-text "* Headline2b :tag:\n"
3292 (let ((org-special-ctrl-a/e nil
))
3293 (and (progn (org-end-of-line) (eolp))
3294 (progn (org-end-of-line) (eolp))))))
3296 (org-test-with-temp-text "* Headline2b :tag:\n"
3297 (let ((org-special-ctrl-a/e
'(t . nil
)))
3298 (and (progn (org-end-of-line) (eolp))
3299 (progn (org-end-of-line) (eolp))))))
3301 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3303 (let ((org-special-ctrl-a/e nil
))
3305 (= 1 (line-beginning-position)))))
3306 ;; At an headline with special movement, first move before tags,
3307 ;; then at the end of line, rinse, repeat. However, never go past
3310 (org-test-with-temp-text "* Headline1 :tag:\n"
3311 (let ((org-special-ctrl-a/e t
))
3312 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3313 (progn (org-end-of-line) (eolp))
3314 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3316 (org-test-with-temp-text "* Headline1 :tag:\n"
3317 (let ((org-special-ctrl-a/e
'(nil . t
)))
3318 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3319 (progn (org-end-of-line) (eolp))
3320 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3322 (org-test-with-temp-text "* Headline1 :tag:\n"
3323 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3324 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3325 (progn (org-end-of-line) (eolp))
3326 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3328 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3330 (let ((org-special-ctrl-a/e t
))
3333 (= 1 (line-beginning-position)))))
3334 ;; At an headline, with reversed movement, first go to end of line,
3335 ;; then before tags. However, never go past ellipsis.
3337 (org-test-with-temp-text "* Headline3 :tag:\n"
3338 (let ((org-special-ctrl-a/e
'reversed
)
3339 (this-command last-command
))
3340 (and (progn (org-end-of-line) (eolp))
3341 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3343 (org-test-with-temp-text "* Headline3 :tag:\n"
3344 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3345 (this-command last-command
))
3346 (and (progn (org-end-of-line) (eolp))
3347 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3349 (org-test-with-temp-text "* Headline3 :tag:\n"
3350 (let ((org-special-ctrl-a/e
'(nil . t
))
3351 (this-command last-command
))
3352 (and (progn (org-end-of-line) (eolp))
3353 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3355 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3357 (let ((org-special-ctrl-a/e
'reversed
))
3359 (= 1 (line-beginning-position)))))
3360 ;; At a block without hidden contents.
3362 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3363 (progn (org-end-of-line) (eolp))))
3364 ;; At a block with hidden contents.
3366 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3367 (let ((org-special-ctrl-a/e t
))
3368 (org-hide-block-toggle)
3371 ;; Get past invisible characters at the end of line.
3373 (org-test-with-temp-text "[[https://orgmode.org]]"
3377 (ert-deftest test-org
/open-line
()
3378 "Test `org-open-line' specifications."
3379 ;; Call `open-line' outside of tables.
3382 (org-test-with-temp-text "Text"
3385 ;; At a table, create a row above.
3387 (equal "\n| |\n| a |"
3388 (org-test-with-temp-text "\n<point>| a |"
3391 ;; At the very first character of the buffer, also call `open-line'.
3394 (org-test-with-temp-text "| a |"
3397 ;; Narrowing does not count.
3399 (equal "Text\n| |\n| a |"
3400 (org-test-with-temp-text "Text\n<point>| a |"
3401 (narrow-to-region (point) (point-max))
3406 (ert-deftest test-org
/forward-sentence
()
3407 "Test `org-forward-sentence' specifications."
3408 ;; At the end of a table cell, move to the end of the next one.
3410 (org-test-with-temp-text "| a<point> | b |"
3411 (org-forward-sentence)
3412 (looking-at " |$")))
3413 ;; Elsewhere in a cell, move to its end.
3415 (org-test-with-temp-text "| a<point>c | b |"
3416 (org-forward-sentence)
3417 (looking-at " | b |$")))
3418 ;; Otherwise, simply call `forward-sentence'.
3420 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3421 (org-forward-sentence)
3422 (looking-at " Sentence 2.")))
3424 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3425 (org-forward-sentence)
3426 (org-forward-sentence)
3428 ;; At the end of an element, jump to the next one, without stopping
3429 ;; on blank lines in-between.
3431 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3432 (org-forward-sentence)
3434 ;; Headlines are considered to be sentences by themselves, even if
3435 ;; they do not end with a full stop.
3439 (org-test-with-temp-text "* <point>Headline\nSentence."
3440 (org-forward-sentence)
3441 (buffer-substring-no-properties (line-beginning-position) (point)))))
3443 (org-test-with-temp-text "* Headline<point>\nSentence."
3444 (org-forward-sentence)
3447 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3448 (org-forward-sentence)
3449 (and (org-at-heading-p) (eolp)))))
3451 (ert-deftest test-org
/backward-sentence
()
3452 "Test `org-backward-sentence' specifications."
3453 ;; At the beginning of a table cell, move to the beginning of the
3456 (org-test-with-temp-text "| a | <point>b |"
3457 (org-backward-sentence)
3458 (looking-at "a | b |$")))
3459 ;; Elsewhere in a cell, move to its beginning.
3461 (org-test-with-temp-text "| a | b<point>c |"
3462 (org-backward-sentence)
3463 (looking-at "bc |$")))
3464 ;; Otherwise, simply call `backward-sentence'.
3466 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3467 (org-backward-sentence)
3468 (looking-at "Sentence 2.")))
3470 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3471 (org-backward-sentence)
3472 (org-backward-sentence)
3474 ;; Make sure to hit the beginning of a sentence on the same line as
3477 (org-test-with-temp-text "- Line 1\n line <point>2."
3478 (org-backward-sentence)
3479 (looking-at "Line 1"))))
3481 (ert-deftest test-org
/forward-paragraph
()
3482 "Test `org-forward-paragraph' specifications."
3483 ;; At end of buffer, do not return an error.
3485 (org-test-with-temp-text "Paragraph"
3486 (goto-char (point-max))
3487 (org-forward-paragraph)
3491 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3492 (org-forward-paragraph)
3496 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3497 (org-forward-paragraph)
3499 ;; Do not enter elements with invisible contents.
3501 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3502 (org-hide-block-toggle)
3503 (org-forward-paragraph)
3505 ;; On an affiliated keyword, jump to the beginning of the element.
3507 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3508 (org-forward-paragraph)
3509 (looking-at "Para")))
3510 ;; On an item or a footnote definition, move to the second element
3513 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3514 (org-forward-paragraph)
3515 (looking-at " Paragraph")))
3517 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3518 (org-forward-paragraph)
3519 (looking-at "Paragraph")))
3520 ;; On an item, or a footnote definition, when the first line is
3521 ;; empty, move to the first item.
3523 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3524 (org-forward-paragraph)
3525 (looking-at " Paragraph")))
3527 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3528 (org-forward-paragraph)
3529 (looking-at "Paragraph")))
3530 ;; On a table (resp. a property drawer) do not move through table
3531 ;; rows (resp. node properties).
3533 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3534 (org-forward-paragraph)
3535 (looking-at "Paragraph")))
3537 (org-test-with-temp-text
3538 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3539 (org-forward-paragraph)
3540 (looking-at "Paragraph")))
3541 ;; On a verse or source block, stop after blank lines.
3543 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3544 (org-forward-paragraph)
3547 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3548 (org-forward-paragraph)
3549 (looking-at "L2"))))
3551 (ert-deftest test-org
/backward-paragraph
()
3552 "Test `org-backward-paragraph' specifications."
3553 ;; Do not error at beginning of buffer.
3555 (org-test-with-temp-text "Paragraph"
3556 (org-backward-paragraph)
3560 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3561 (org-backward-paragraph)
3564 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3565 (org-backward-paragraph)
3566 (looking-at-p "P2")))
3569 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3570 (org-backward-paragraph)
3571 (looking-at-p "P2")))
3572 ;; Ignore invisible elements.
3574 (org-test-with-temp-text "* H1\n P1\n* H2"
3576 (goto-char (point-max))
3578 (org-backward-paragraph)
3580 ;; On an affiliated keyword, jump to the first one.
3582 (org-test-with-temp-text
3583 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3584 (org-backward-paragraph)
3585 (looking-at-p "#\\+name")))
3586 ;; On the second element in an item or a footnote definition, jump
3587 ;; to item or the definition.
3589 (org-test-with-temp-text "- line1\n\n<point> line2"
3590 (org-backward-paragraph)
3591 (looking-at-p "- line1")))
3593 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3594 (org-backward-paragraph)
3595 (looking-at-p "\\[fn:1\\] line1")))
3596 ;; On a table (resp. a property drawer), ignore table rows
3597 ;; (resp. node properties).
3599 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3600 (org-backward-paragraph)
3603 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3604 (org-backward-paragraph)
3605 (looking-at-p ":PROPERTIES:")))
3606 ;; On a comment, example, src and verse blocks, stop before blank
3609 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3610 (org-backward-paragraph)
3611 (looking-at-p "L2")))
3613 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3614 (org-backward-paragraph)
3615 (looking-at-p "L2")))
3616 ;; In comment, example, export, src and verse blocks, stop below
3617 ;; opening line when called from within the block.
3619 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3620 (org-backward-paragraph)
3621 (looking-at-p "L1")))
3623 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3624 (org-backward-paragraph)
3625 (looking-at-p "L1")))
3626 ;; When called from the opening line itself, however, move to
3627 ;; beginning of block.
3629 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3630 (org-backward-paragraph)
3632 ;; Pathological case: on an empty heading, move to its beginning.
3634 (org-test-with-temp-text "* <point>H"
3635 (org-backward-paragraph)
3638 (ert-deftest test-org
/forward-element
()
3639 "Test `org-forward-element' specifications."
3640 ;; 1. At EOB: should error.
3641 (org-test-with-temp-text "Some text\n"
3642 (goto-char (point-max))
3643 (should-error (org-forward-element)))
3644 ;; 2. Standard move: expected to ignore blank lines.
3645 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3646 (org-forward-element)
3647 (should (looking-at (regexp-quote "Second paragraph."))))
3648 ;; 3. Headline tests.
3649 (org-test-with-temp-text "
3654 ;; 3.1. At an headline beginning: move to next headline at the
3657 (org-forward-element)
3658 (should (looking-at (regexp-quote "** Head 1.2")))
3659 ;; 3.2. At an headline beginning: move to parent headline if no
3660 ;; headline at the same level.
3662 (org-forward-element)
3663 (should (looking-at (regexp-quote "** Head 1.2"))))
3664 ;; 4. Greater element tests.
3665 (org-test-with-temp-text
3666 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3667 ;; 4.1. At a greater element: expected to skip contents.
3668 (org-forward-element)
3669 (should (looking-at (regexp-quote "Outside.")))
3670 ;; 4.2. At the end of greater element contents: expected to skip
3671 ;; to the end of the greater element.
3673 (org-forward-element)
3674 (should (looking-at (regexp-quote "Outside."))))
3676 (org-test-with-temp-text "
3690 ;; 5.1. At list top point: expected to move to the element after
3693 (org-forward-element)
3694 (should (looking-at (regexp-quote "Outside.")))
3695 ;; 5.2. Special case: at the first line of a sub-list, but not at
3696 ;; beginning of line, move to next item.
3699 (org-forward-element)
3700 (should (looking-at "- item2"))
3703 (org-forward-element)
3704 (should (looking-at " - sub2"))
3705 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3707 (org-forward-element)
3708 (should (looking-at (regexp-quote " Inner paragraph.")))
3709 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3711 (org-forward-element)
3712 (should (looking-at (regexp-quote " Inner paragraph.")))
3713 ;; 5.5. At an item: expected to move to next item, if any.
3715 (org-forward-element)
3716 (should (looking-at " - sub3"))))
3718 (ert-deftest test-org
/backward-element
()
3719 "Test `org-backward-element' specifications."
3720 ;; 1. Should error at BOB.
3721 (org-test-with-temp-text " \nParagraph."
3722 (should-error (org-backward-element)))
3723 ;; 2. Should move at BOB when called on the first element in buffer.
3725 (org-test-with-temp-text "\n#+TITLE: test"
3726 (progn (forward-line)
3727 (org-backward-element)
3729 ;; 3. Not at the beginning of an element: move at its beginning.
3730 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3733 (org-backward-element)
3734 (should (looking-at (regexp-quote "Paragraph2."))))
3735 ;; 4. Headline tests.
3736 (org-test-with-temp-text "
3741 ;; 4.1. At an headline beginning: move to previous headline at the
3744 (org-backward-element)
3745 (should (looking-at (regexp-quote "** Head 1.1")))
3746 ;; 4.2. At an headline beginning: move to parent headline if no
3747 ;; headline at the same level.
3749 (org-backward-element)
3750 (should (looking-at (regexp-quote "* Head 1")))
3751 ;; 4.3. At the first top-level headline: should error.
3753 (should-error (org-backward-element)))
3754 ;; 5. At beginning of first element inside a greater element:
3755 ;; expected to move to greater element's beginning.
3756 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3758 (org-backward-element)
3759 (should (looking-at "#\\+BEGIN_CENTER")))
3760 ;; 6. At the beginning of the first element in a section: should
3761 ;; move back to headline, if any.
3763 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3764 (progn (goto-char (point-max))
3766 (org-backward-element)
3767 (org-at-heading-p))))
3769 (org-test-with-temp-text "
3784 ;; 7.1. At beginning of sub-list: expected to move to the
3785 ;; paragraph before it.
3787 (org-backward-element)
3788 (should (looking-at "item1"))
3789 ;; 7.2. At an item in a list: expected to move at previous item.
3791 (org-backward-element)
3792 (should (looking-at " - sub2"))
3794 (org-backward-element)
3795 (should (looking-at "- item1"))
3796 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3799 (org-backward-element)
3800 (should (looking-at " - sub1"))
3802 (org-backward-element)
3803 (should (looking-at "- item1"))
3804 ;; 7.4. At blank-lines before list end: expected to move to top
3807 (org-backward-element)
3808 (should (looking-at "- item1"))))
3810 (ert-deftest test-org
/up-element
()
3811 "Test `org-up-element' specifications."
3812 ;; 1. At BOB or with no surrounding element: should error.
3813 (org-test-with-temp-text "Paragraph."
3814 (should-error (org-up-element)))
3815 (org-test-with-temp-text "* Head1\n* Head2"
3817 (should-error (org-up-element)))
3818 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3820 (should-error (org-up-element)))
3821 ;; 2. At an headline: move to parent headline.
3822 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3825 (should (looking-at "\\* Head1")))
3826 ;; 3. Inside a greater element: move to greater element beginning.
3827 (org-test-with-temp-text
3828 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3831 (should (looking-at "#\\+BEGIN_CENTER")))
3833 (org-test-with-temp-text "* Top
3840 Paragraph within sub2.
3843 ;; 4.1. Within an item: move to the item beginning.
3846 (should (looking-at " - sub2"))
3847 ;; 4.2. At an item in a sub-list: move to parent item.
3850 (should (looking-at "- item1"))
3851 ;; 4.3. At an item in top list: move to beginning of whole list.
3854 (should (looking-at "- item1"))
3855 ;; 4.4. Special case. At very top point: should move to parent of
3859 (should (looking-at "\\* Top"))))
3861 (ert-deftest test-org
/down-element
()
3862 "Test `org-down-element' specifications."
3863 ;; Error when the element hasn't got a recursive type.
3864 (org-test-with-temp-text "Paragraph."
3865 (should-error (org-down-element)))
3866 ;; Error when the element has no contents
3867 (org-test-with-temp-text "* Headline"
3868 (should-error (org-down-element)))
3869 ;; When at a plain-list, move to first item.
3870 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3873 (should (looking-at " - Item 1.1")))
3874 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3876 (should (looking-at " Item 1")))
3877 ;; When at a table, move to first row
3878 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3880 (should (looking-at " a | b |")))
3881 ;; Otherwise, move inside the greater element.
3882 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3884 (should (looking-at "Paragraph"))))
3886 (ert-deftest test-org
/drag-element-backward
()
3887 "Test `org-drag-element-backward' specifications."
3891 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3892 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3893 (org-drag-element-backward)
3897 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3898 (org-test-with-temp-text
3899 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3900 (org-drag-element-backward)
3902 ;; Preserve blank lines.
3904 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3905 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3906 (org-drag-element-backward)
3910 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3911 (org-drag-element-backward)
3912 (looking-at-p "2")))
3913 ;; Error when trying to move first element of buffer.
3915 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3916 (org-drag-element-backward))
3918 ;; Error when trying to swap nested elements.
3920 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3921 (org-drag-element-backward))
3923 ;; Error when trying to swap an headline element and a non-headline
3926 (org-test-with-temp-text "Test.\n<point>* Head 1"
3927 (org-drag-element-backward))
3929 ;; Error when called before first element.
3931 (org-test-with-temp-text "\n<point>"
3932 (org-drag-element-backward))
3934 ;; Preserve visibility of elements and their contents.
3936 (equal '((63 .
82) (26 .
48))
3937 (org-test-with-temp-text "
3945 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3946 (search-backward "- item 1")
3947 (org-drag-element-backward)
3948 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3949 (overlays-in (point-min) (point-max))))))
3950 ;; Pathological case: handle call with point in blank lines right
3951 ;; after a headline.
3953 (equal "* H2\n* H1\nText\n\n"
3954 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3955 (org-drag-element-backward)
3958 (ert-deftest test-org
/drag-element-forward
()
3959 "Test `org-drag-element-forward' specifications."
3960 ;; 1. Error when trying to move first element of buffer.
3961 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3963 (should-error (org-drag-element-forward)))
3964 ;; 2. Error when trying to swap nested elements.
3965 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3967 (should-error (org-drag-element-forward)))
3968 ;; 3. Error when trying to swap a non-headline element and an
3970 (org-test-with-temp-text "Test.\n* Head 1"
3971 (should-error (org-drag-element-forward)))
3972 ;; 4. Error when called before first element.
3974 (org-test-with-temp-text "\n"
3976 (org-drag-element-backward))
3978 ;; 5. Otherwise, swap elements, preserving column and blank lines
3979 ;; between elements.
3980 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3981 (search-forward "graph")
3982 (org-drag-element-forward)
3983 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3984 (should (looking-at " 1")))
3985 ;; 5. Preserve visibility of elements and their contents.
3986 (org-test-with-temp-text "
3994 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3995 (search-backward "#+BEGIN_CENTER")
3996 (org-drag-element-forward)
3999 '((63 .
82) (26 .
48))
4000 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
4001 (overlays-in (point-min) (point-max)))))))
4003 (ert-deftest test-org
/next-block
()
4004 "Test `org-next-block' specifications."
4007 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4009 (looking-at "#\\+BEGIN_CENTER")))
4012 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
4013 (let ((case-fold-search nil
))
4015 (looking-at "#\\+begin_center"))))
4016 ;; Ignore current line.
4018 (org-test-with-temp-text
4019 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
4021 (looking-at "#\\+BEGIN_CENTER")))
4022 ;; Throw an error when no block is found.
4024 (org-test-with-temp-text "Paragraph"
4025 (org-next-block 1)))
4026 ;; With an argument, skip many blocks at once.
4028 (org-test-with-temp-text
4029 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4031 (looking-at "#\\+BEGIN_QUOTE")))
4032 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4034 (org-test-with-temp-text
4035 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4036 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4037 (looking-at "#\\+BEGIN_QUOTE")))
4038 ;; Optional argument is also case-insensitive.
4040 (org-test-with-temp-text
4041 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4042 (let ((case-fold-search nil
))
4043 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4044 (looking-at "#\\+begin_quote")))))
4046 (ert-deftest test-org
/insert-template
()
4047 "Test `org-insert-structure-template'."
4048 ;; Test in empty buffer.
4050 (string= "#+begin_foo\n#+end_foo\n"
4051 (org-test-with-temp-text ""
4052 (org-insert-structure-template "foo")
4054 ;; Test with multiple lines in buffer.
4056 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
4057 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4059 (org-insert-structure-template "foo")
4061 ;; Test with text in buffer, no region, no final newline.
4063 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
4064 (org-test-with-temp-text "I'm a paragraph."
4066 (org-insert-structure-template "foo")
4068 ;; Test with text in buffer and region set.
4070 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
4071 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
4073 (goto-char (point-max))
4074 (org-insert-structure-template "foo")
4076 ;; Test with example escaping.
4078 (string= "#+begin_example\n,* Heading\n#+end_example\n"
4079 (org-test-with-temp-text "* Heading"
4081 (org-insert-structure-template "example")
4083 ;; Test with indentation.
4085 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
4086 (org-test-with-temp-text " This is a paragraph"
4088 (org-insert-structure-template "foo")
4091 (ert-deftest test-org
/previous-block
()
4092 "Test `org-previous-block' specifications."
4095 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4096 (org-previous-block 1)
4097 (looking-at "#\\+BEGIN_CENTER")))
4100 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4101 (let ((case-fold-search nil
))
4102 (org-previous-block 1)
4103 (looking-at "#\\+begin_center"))))
4104 ;; Ignore current line.
4106 (org-test-with-temp-text
4107 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4108 (org-previous-block 1)
4109 (looking-at "#\\+BEGIN_QUOTE")))
4110 ;; Throw an error when no block is found.
4112 (org-test-with-temp-text "Paragraph<point>"
4113 (org-previous-block 1)))
4114 ;; With an argument, skip many blocks at once.
4116 (org-test-with-temp-text
4117 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4118 (org-previous-block 2)
4119 (looking-at "#\\+BEGIN_CENTER")))
4120 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4122 (org-test-with-temp-text
4123 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4124 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4125 (looking-at "#\\+BEGIN_QUOTE")))
4126 ;; Optional argument is also case-insensitive.
4128 (org-test-with-temp-text
4129 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4130 (let ((case-fold-search nil
))
4131 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4132 (looking-at "#\\+begin_quote")))))
4135 ;;; Outline structure
4137 (ert-deftest test-org
/demote
()
4138 "Test `org-demote' specifications."
4139 ;; Add correct number of stars according to `org-odd-levels-only'.
4142 (org-test-with-temp-text "* H"
4143 (let ((org-odd-levels-only nil
)) (org-demote))
4144 (org-current-level))))
4147 (org-test-with-temp-text "* H"
4148 (let ((org-odd-levels-only t
)) (org-demote))
4149 (org-current-level))))
4150 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4152 (org-test-with-temp-text "* H :tag:"
4153 (let ((org-tags-column 10)
4154 (org-auto-align-tags t
)
4155 (org-odd-levels-only nil
))
4157 (org-move-to-column 10)
4158 (looking-at-p ":tag:$")))
4160 (org-test-with-temp-text "* H :tag:"
4161 (let ((org-tags-column 10)
4162 (org-auto-align-tags nil
)
4163 (org-odd-levels-only nil
))
4165 (org-move-to-column 10)
4166 (looking-at-p ":tag:$")))
4167 ;; When `org-adapt-indentation' is non-nil, always indent planning
4168 ;; info and property drawers accordingly.
4171 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4172 (let ((org-odd-levels-only nil
)
4173 (org-adapt-indentation t
))
4176 (org-get-indentation))))
4179 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4180 (let ((org-odd-levels-only nil
)
4181 (org-adapt-indentation t
))
4184 (org-get-indentation))))
4187 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4188 (let ((org-odd-levels-only nil
)
4189 (org-adapt-indentation nil
))
4192 (org-get-indentation))))
4193 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4194 ;; section accordingly. Ignore, however, footnote definitions and
4195 ;; inlinetasks boundaries.
4198 (org-test-with-temp-text "* H\n Paragraph"
4199 (let ((org-odd-levels-only nil
)
4200 (org-adapt-indentation t
))
4203 (org-get-indentation))))
4206 (org-test-with-temp-text "* H\n Paragraph"
4207 (let ((org-odd-levels-only nil
)
4208 (org-adapt-indentation nil
))
4211 (org-get-indentation))))
4214 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4215 (let ((org-odd-levels-only nil
)
4216 (org-adapt-indentation t
))
4218 (goto-char (point-max))
4219 (org-get-indentation))))
4222 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4223 (let ((org-odd-levels-only nil
)
4224 (org-adapt-indentation t
))
4226 (goto-char (point-max))
4227 (org-get-indentation))))
4228 (when (featurep 'org-inlinetask
)
4231 (let ((org-inlinetask-min-level 5)
4232 (org-adapt-indentation t
))
4233 (org-test-with-temp-text "* H\n***** I\n***** END"
4236 (org-get-indentation))))))
4237 (when (featurep 'org-inlinetask
)
4240 (let ((org-inlinetask-min-level 5)
4241 (org-adapt-indentation t
))
4242 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4245 (org-get-indentation))))))
4246 ;; Ignore contents of source blocks or example blocks when
4247 ;; indentation should be preserved (through
4248 ;; `org-src-preserve-indentation' or "-i" flag).
4251 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4252 (let ((org-adapt-indentation t
)
4253 (org-src-preserve-indentation nil
))
4256 (org-get-indentation))))
4259 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4260 (let ((org-adapt-indentation t
)
4261 (org-src-preserve-indentation t
))
4264 (org-get-indentation))))
4267 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4268 (let ((org-adapt-indentation t
)
4269 (org-src-preserve-indentation t
))
4272 (org-get-indentation))))
4275 (org-test-with-temp-text
4276 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4277 (let ((org-adapt-indentation t
)
4278 (org-src-preserve-indentation nil
))
4281 (org-get-indentation)))))
4283 (ert-deftest test-org
/promote
()
4284 "Test `org-promote' specifications."
4285 ;; Return an error if headline is to be promoted to level 0, unless
4286 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4287 ;; headline becomes a comment.
4289 (org-test-with-temp-text "* H"
4290 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4293 (org-test-with-temp-text "* H"
4294 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4296 ;; Remove correct number of stars according to
4297 ;; `org-odd-levels-only'.
4300 (org-test-with-temp-text "*** H"
4301 (let ((org-odd-levels-only nil
)) (org-promote))
4302 (org-current-level))))
4305 (org-test-with-temp-text "*** H"
4306 (let ((org-odd-levels-only t
)) (org-promote))
4307 (org-current-level))))
4308 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4310 (org-test-with-temp-text "** H :tag:"
4311 (let ((org-tags-column 10)
4312 (org-auto-align-tags t
)
4313 (org-odd-levels-only nil
))
4315 (org-move-to-column 10)
4316 (looking-at-p ":tag:$")))
4318 (org-test-with-temp-text "** H :tag:"
4319 (let ((org-tags-column 10)
4320 (org-auto-align-tags nil
)
4321 (org-odd-levels-only nil
))
4323 (org-move-to-column 10)
4324 (looking-at-p ":tag:$")))
4325 ;; When `org-adapt-indentation' is non-nil, always indent planning
4326 ;; info and property drawers.
4329 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4330 (let ((org-odd-levels-only nil
)
4331 (org-adapt-indentation t
))
4334 (org-get-indentation))))
4337 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4338 (let ((org-odd-levels-only nil
)
4339 (org-adapt-indentation t
))
4342 (org-get-indentation))))
4345 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4346 (let ((org-odd-levels-only nil
)
4347 (org-adapt-indentation nil
))
4350 (org-get-indentation))))
4351 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4352 ;; section accordingly. Ignore, however, footnote definitions and
4353 ;; inlinetasks boundaries.
4356 (org-test-with-temp-text "** H\n Paragraph"
4357 (let ((org-odd-levels-only nil
)
4358 (org-adapt-indentation t
))
4361 (org-get-indentation))))
4364 (org-test-with-temp-text "** H\n Paragraph"
4365 (let ((org-odd-levels-only nil
)
4366 (org-adapt-indentation nil
))
4369 (org-get-indentation))))
4372 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4373 (let ((org-odd-levels-only nil
)
4374 (org-adapt-indentation t
))
4377 (org-get-indentation))))
4378 (when (featurep 'org-inlinetask
)
4381 (let ((org-inlinetask-min-level 5)
4382 (org-adapt-indentation t
))
4383 (org-test-with-temp-text "** H\n***** I\n***** END"
4386 (org-get-indentation))))))
4387 (when (featurep 'org-inlinetask
)
4390 (let ((org-inlinetask-min-level 5)
4391 (org-adapt-indentation t
))
4392 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4395 (org-get-indentation))))))
4396 ;; Give up shifting if it would break document's structure
4400 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4401 (let ((org-odd-levels-only nil
)
4402 (org-adapt-indentation t
))
4405 (org-get-indentation))))
4408 (org-test-with-temp-text "** H\n Paragraph\n * list."
4409 (let ((org-odd-levels-only nil
)
4410 (org-adapt-indentation t
))
4413 (org-get-indentation))))
4414 ;; Ignore contents of source blocks or example blocks when
4415 ;; indentation should be preserved (through
4416 ;; `org-src-preserve-indentation' or "-i" flag).
4419 (org-test-with-temp-text
4420 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4421 (let ((org-adapt-indentation t
)
4422 (org-src-preserve-indentation nil
)
4423 (org-odd-levels-only nil
))
4426 (org-get-indentation))))
4429 (org-test-with-temp-text
4430 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4431 (let ((org-adapt-indentation t
)
4432 (org-src-preserve-indentation t
)
4433 (org-odd-levels-only nil
))
4436 (org-get-indentation))))
4439 (org-test-with-temp-text
4440 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4441 (let ((org-adapt-indentation t
)
4442 (org-src-preserve-indentation t
)
4443 (org-odd-levels-only nil
))
4446 (org-get-indentation))))
4449 (org-test-with-temp-text
4450 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4451 (let ((org-adapt-indentation t
)
4452 (org-src-preserve-indentation nil
)
4453 (org-odd-levels-only nil
))
4456 (org-get-indentation)))))
4458 (ert-deftest test-org
/org-get-valid-level
()
4459 "Test function `org-get-valid-level' specifications."
4460 (let ((org-odd-levels-only nil
))
4461 (should (equal 1 (org-get-valid-level 0 0)))
4462 (should (equal 1 (org-get-valid-level 0 1)))
4463 (should (equal 2 (org-get-valid-level 0 2)))
4464 (should (equal 3 (org-get-valid-level 0 3)))
4465 (should (equal 1 (org-get-valid-level 1 0)))
4466 (should (equal 2 (org-get-valid-level 1 1)))
4467 (should (equal 23 (org-get-valid-level 1 22)))
4468 (should (equal 1 (org-get-valid-level 1 -
1)))
4469 (should (equal 1 (org-get-valid-level 2 -
1))))
4470 (let ((org-odd-levels-only t
))
4471 (should (equal 1 (org-get-valid-level 0 0)))
4472 (should (equal 1 (org-get-valid-level 0 1)))
4473 (should (equal 3 (org-get-valid-level 0 2)))
4474 (should (equal 5 (org-get-valid-level 0 3)))
4475 (should (equal 1 (org-get-valid-level 1 0)))
4476 (should (equal 3 (org-get-valid-level 1 1)))
4477 (should (equal 3 (org-get-valid-level 2 1)))
4478 (should (equal 5 (org-get-valid-level 3 1)))
4479 (should (equal 5 (org-get-valid-level 4 1)))
4480 (should (equal 43 (org-get-valid-level 1 21)))
4481 (should (equal 1 (org-get-valid-level 1 -
1)))
4482 (should (equal 1 (org-get-valid-level 2 -
1)))
4483 (should (equal 1 (org-get-valid-level 3 -
1)))
4484 (should (equal 3 (org-get-valid-level 4 -
1)))
4485 (should (equal 3 (org-get-valid-level 5 -
1)))))
4490 (ert-deftest test-org
/at-planning-p
()
4491 "Test `org-at-planning-p' specifications."
4494 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4495 (org-at-planning-p)))
4497 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4498 (org-at-planning-p)))
4499 ;; Correctly find planning attached to inlinetasks.
4500 (when (featurep 'org-inlinetask
)
4502 (org-test-with-temp-text
4503 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4504 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4506 (org-test-with-temp-text
4507 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4508 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4510 (org-test-with-temp-text
4511 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4512 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4514 (org-test-with-temp-text
4515 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4516 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4518 (ert-deftest test-org
/add-planning-info
()
4519 "Test `org-add-planning-info'."
4520 ;; Create deadline when `org-adapt-indentation' is non-nil.
4522 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4523 (org-test-with-temp-text "* H\nParagraph<point>"
4524 (let ((org-adapt-indentation t
))
4525 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4526 (replace-regexp-in-string
4527 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4529 ;; Create deadline when `org-adapt-indentation' is nil.
4531 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4532 (org-test-with-temp-text "* H\nParagraph<point>"
4533 (let ((org-adapt-indentation nil
))
4534 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4535 (replace-regexp-in-string
4536 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4538 ;; Update deadline when `org-adapt-indentation' is non-nil.
4540 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4541 (org-test-with-temp-text "\
4543 DEADLINE: <2015-06-24 Wed>
4545 (let ((org-adapt-indentation t
))
4546 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4547 (replace-regexp-in-string
4548 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4550 ;; Update deadline when `org-adapt-indentation' is nil.
4552 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4553 (org-test-with-temp-text "\
4555 DEADLINE: <2015-06-24 Wed>
4557 (let ((org-adapt-indentation nil
))
4558 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4559 (replace-regexp-in-string
4560 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4562 ;; Schedule when `org-adapt-indentation' is non-nil.
4564 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4565 (org-test-with-temp-text "* H\nParagraph<point>"
4566 (let ((org-adapt-indentation t
))
4567 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4568 (replace-regexp-in-string
4569 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4571 ;; Schedule when `org-adapt-indentation' is nil.
4573 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4574 (org-test-with-temp-text "* H\nParagraph<point>"
4575 (let ((org-adapt-indentation nil
))
4576 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4577 (replace-regexp-in-string
4578 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4580 ;; Add deadline when scheduled.
4584 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4586 (org-test-with-temp-text "\
4588 SCHEDULED: <2015-06-24 Wed>
4590 (let ((org-adapt-indentation t
))
4591 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4592 (replace-regexp-in-string
4593 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4595 ;; Remove middle entry.
4599 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4601 (org-test-with-temp-text "\
4603 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4605 (let ((org-adapt-indentation t
))
4606 (org-add-planning-info nil nil
'deadline
))
4607 (replace-regexp-in-string
4608 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4610 ;; Remove last entry and then middle entry (order should not
4615 CLOSED: [2015-06-24]
4617 (org-test-with-temp-text "\
4619 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4621 (let ((org-adapt-indentation t
))
4622 (org-add-planning-info nil nil
'scheduled
'deadline
))
4623 (replace-regexp-in-string
4624 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4626 ;; Remove closed when `org-adapt-indentation' is non-nil.
4628 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4629 (org-test-with-temp-text "\
4631 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4633 (let ((org-adapt-indentation t
))
4634 (org-add-planning-info nil nil
'closed
))
4635 (replace-regexp-in-string
4636 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4639 (equal "* H\n Paragraph"
4640 (org-test-with-temp-text "\
4642 CLOSED: [2015-06-25 Thu]
4644 (let ((org-adapt-indentation t
))
4645 (org-add-planning-info nil nil
'closed
))
4646 (replace-regexp-in-string
4647 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4649 ;; Remove closed when `org-adapt-indentation' is nil.
4651 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4652 (org-test-with-temp-text "\
4654 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4656 (let ((org-adapt-indentation nil
))
4657 (org-add-planning-info nil nil
'closed
))
4658 (replace-regexp-in-string
4659 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4662 (equal "* H\nParagraph"
4663 (org-test-with-temp-text "\
4665 CLOSED: [2015-06-25 Thu]
4667 (let ((org-adapt-indentation nil
))
4668 (org-add-planning-info nil nil
'closed
))
4669 (replace-regexp-in-string
4670 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4672 ;; Remove closed entry and delete empty line.
4677 (org-test-with-temp-text "\
4679 CLOSED: [2015-06-24 Wed]
4681 (let ((org-adapt-indentation t
))
4682 (org-add-planning-info nil nil
'closed
))
4683 (replace-regexp-in-string
4684 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4686 ;; Remove one entry and update another.
4688 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4689 (org-test-with-temp-text "\
4691 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4693 (let ((org-adapt-indentation t
))
4694 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4695 (replace-regexp-in-string
4696 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4699 (ert-deftest test-org
/deadline
()
4700 "Test `org-deadline' specifications."
4701 ;; Insert a new value or replace existing one.
4703 (equal "* H\nDEADLINE: <2012-03-29>\n"
4704 (org-test-with-temp-text "* H"
4705 (let ((org-adapt-indentation nil
)
4706 (org-last-inserted-timestamp nil
))
4707 (org-deadline nil
"<2012-03-29 Tue>"))
4708 (replace-regexp-in-string
4709 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4712 (equal "* H\nDEADLINE: <2014-03-04>"
4713 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4714 (let ((org-adapt-indentation nil
)
4715 (org-last-inserted-timestamp nil
))
4716 (org-deadline nil
"<2014-03-04 Thu>"))
4717 (replace-regexp-in-string
4718 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4720 ;; Accept delta time, e.g., "+2d".
4722 (equal "* H\nDEADLINE: <2015-03-04>\n"
4723 (cl-letf (((symbol-function 'current-time
)
4724 (lambda (&rest args
)
4725 (apply #'encode-time
4726 (org-parse-time-string "2014-03-04")))))
4727 (org-test-with-temp-text "* H"
4728 (let ((org-adapt-indentation nil
)
4729 (org-last-inserted-timestamp nil
))
4730 (org-deadline nil
"+1y"))
4731 (replace-regexp-in-string
4732 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4733 ;; Preserve repeater.
4735 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4736 (org-test-with-temp-text "* H"
4737 (let ((org-adapt-indentation nil
)
4738 (org-last-inserted-timestamp nil
))
4739 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4740 (replace-regexp-in-string
4741 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4742 ;; Remove CLOSED keyword, if any.
4744 (equal "* H\nDEADLINE: <2012-03-29>"
4745 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4746 (let ((org-adapt-indentation nil
)
4747 (org-last-inserted-timestamp nil
))
4748 (org-deadline nil
"<2012-03-29 Tue>"))
4749 (replace-regexp-in-string
4750 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4751 ;; With C-u argument, remove DEADLINE keyword.
4754 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4755 (let ((org-adapt-indentation nil
)
4756 (org-last-inserted-timestamp nil
))
4757 (org-deadline '(4)))
4761 (org-test-with-temp-text "* H"
4762 (let ((org-adapt-indentation nil
)
4763 (org-last-inserted-timestamp nil
))
4764 (org-deadline '(4)))
4766 ;; With C-u C-u argument, prompt for a delay cookie.
4768 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4769 (cl-letf (((symbol-function 'org-read-date
)
4770 (lambda (&rest args
)
4771 (apply #'encode-time
4772 (org-parse-time-string "2014-03-04")))))
4773 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4774 (let ((org-adapt-indentation nil
)
4775 (org-last-inserted-timestamp nil
))
4776 (org-deadline '(16)))
4779 (cl-letf (((symbol-function 'org-read-date
)
4780 (lambda (&rest args
)
4781 (apply #'encode-time
4782 (org-parse-time-string "2014-03-04")))))
4783 (org-test-with-temp-text "* H"
4784 (let ((org-adapt-indentation nil
)
4785 (org-last-inserted-timestamp nil
))
4786 (org-deadline '(16)))
4788 ;; When a region is active and
4789 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4790 ;; same value in all headlines in region.
4792 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4793 (org-test-with-temp-text "* H1\n* H2"
4794 (let ((org-adapt-indentation nil
)
4795 (org-last-inserted-timestamp nil
)
4796 (org-loop-over-headlines-in-active-region t
))
4797 (transient-mark-mode 1)
4798 (push-mark (point) t t
)
4799 (goto-char (point-max))
4800 (org-deadline nil
"2012-03-29"))
4801 (replace-regexp-in-string
4802 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4804 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4805 (org-test-with-temp-text "* H1\n* H2"
4806 (let ((org-adapt-indentation nil
)
4807 (org-last-inserted-timestamp nil
)
4808 (org-loop-over-headlines-in-active-region nil
))
4809 (transient-mark-mode 1)
4810 (push-mark (point) t t
)
4811 (goto-char (point-max))
4812 (org-deadline nil
"2012-03-29"))
4813 (replace-regexp-in-string
4814 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4816 (ert-deftest test-org
/schedule
()
4817 "Test `org-schedule' specifications."
4818 ;; Insert a new value or replace existing one.
4820 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4821 (org-test-with-temp-text "* H"
4822 (let ((org-adapt-indentation nil
)
4823 (org-last-inserted-timestamp nil
))
4824 (org-schedule nil
"<2012-03-29 Tue>"))
4825 (replace-regexp-in-string
4826 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4829 (equal "* H\nSCHEDULED: <2014-03-04>"
4830 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4831 (let ((org-adapt-indentation nil
)
4832 (org-last-inserted-timestamp nil
))
4833 (org-schedule nil
"<2014-03-04 Thu>"))
4834 (replace-regexp-in-string
4835 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4837 ;; Accept delta time, e.g., "+2d".
4839 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4840 (cl-letf (((symbol-function 'current-time
)
4841 (lambda (&rest args
)
4842 (apply #'encode-time
4843 (org-parse-time-string "2014-03-04")))))
4844 (org-test-with-temp-text "* H"
4845 (let ((org-adapt-indentation nil
)
4846 (org-last-inserted-timestamp nil
))
4847 (org-schedule nil
"+1y"))
4848 (replace-regexp-in-string
4849 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4850 ;; Preserve repeater.
4852 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4853 (org-test-with-temp-text "* H"
4854 (let ((org-adapt-indentation nil
)
4855 (org-last-inserted-timestamp nil
))
4856 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4857 (replace-regexp-in-string
4858 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4859 ;; Remove CLOSED keyword, if any.
4861 (equal "* H\nSCHEDULED: <2012-03-29>"
4862 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4863 (let ((org-adapt-indentation nil
)
4864 (org-last-inserted-timestamp nil
))
4865 (org-schedule nil
"<2012-03-29 Tue>"))
4866 (replace-regexp-in-string
4867 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4868 ;; With C-u argument, remove SCHEDULED keyword.
4871 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4872 (let ((org-adapt-indentation nil
)
4873 (org-last-inserted-timestamp nil
))
4874 (org-schedule '(4)))
4878 (org-test-with-temp-text "* H"
4879 (let ((org-adapt-indentation nil
)
4880 (org-last-inserted-timestamp nil
))
4881 (org-schedule '(4)))
4883 ;; With C-u C-u argument, prompt for a delay cookie.
4885 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4886 (cl-letf (((symbol-function 'org-read-date
)
4887 (lambda (&rest args
)
4888 (apply #'encode-time
4889 (org-parse-time-string "2014-03-04")))))
4890 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4891 (let ((org-adapt-indentation nil
)
4892 (org-last-inserted-timestamp nil
))
4893 (org-schedule '(16)))
4896 (cl-letf (((symbol-function 'org-read-date
)
4897 (lambda (&rest args
)
4898 (apply #'encode-time
4899 (org-parse-time-string "2014-03-04")))))
4900 (org-test-with-temp-text "* H"
4901 (let ((org-adapt-indentation nil
)
4902 (org-last-inserted-timestamp nil
))
4903 (org-schedule '(16)))
4905 ;; When a region is active and
4906 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4907 ;; same value in all headlines in region.
4909 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4910 (org-test-with-temp-text "* H1\n* H2"
4911 (let ((org-adapt-indentation nil
)
4912 (org-last-inserted-timestamp nil
)
4913 (org-loop-over-headlines-in-active-region t
))
4914 (transient-mark-mode 1)
4915 (push-mark (point) t t
)
4916 (goto-char (point-max))
4917 (org-schedule nil
"2012-03-29"))
4918 (replace-regexp-in-string
4919 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4921 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4922 (org-test-with-temp-text "* H1\n* H2"
4923 (let ((org-adapt-indentation nil
)
4924 (org-last-inserted-timestamp nil
)
4925 (org-loop-over-headlines-in-active-region nil
))
4926 (transient-mark-mode 1)
4927 (push-mark (point) t t
)
4928 (goto-char (point-max))
4929 (org-schedule nil
"2012-03-29"))
4930 (replace-regexp-in-string
4931 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4933 ;; check if a repeater survives re-scheduling.
4935 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4936 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4937 (let ((org-adapt-indentation nil
)
4938 (org-last-inserted-timestamp nil
))
4939 (org-schedule nil
"2017-02-01"))
4945 (ert-deftest test-org
/buffer-property-keys
()
4946 "Test `org-buffer-property-keys' specifications."
4947 ;; Retrieve properties accross siblings.
4950 (org-test-with-temp-text "
4959 (org-buffer-property-keys))))
4960 ;; Retrieve properties accross children.
4963 (org-test-with-temp-text "
4972 (org-buffer-property-keys))))
4973 ;; Retrieve muliple properties in the same drawer.
4976 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4977 (org-buffer-property-keys))))
4978 ;; Ignore extension symbol in property name.
4981 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4982 (org-buffer-property-keys))))
4983 ;; With non-nil COLUMNS, extract property names from columns.
4986 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4987 (org-buffer-property-keys nil nil t
))))
4989 (equal '("A" "B" "COLUMNS")
4990 (org-test-with-temp-text
4991 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4992 (org-buffer-property-keys nil nil t
))))
4993 ;; In COLUMNS, ignore title and summary-type.
4996 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4997 (org-buffer-property-keys nil nil t
))))
5000 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
5001 (org-buffer-property-keys nil nil t
))))
5004 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
5005 (org-buffer-property-keys nil nil t
)))))
5007 (ert-deftest test-org
/property-values
()
5008 "Test `org-property-values' specifications."
5012 (org-test-with-temp-text
5013 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
5014 (org-property-values "A"))))
5015 ;; Ignore empty values.
5017 (org-test-with-temp-text
5018 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
5019 (org-property-values "A")))
5020 ;; Take into consideration extended values.
5023 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
5024 (org-property-values "A")))))
5026 (ert-deftest test-org
/find-property
()
5027 "Test `org-find-property' specifications."
5031 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
5032 (org-find-property "prop"))))
5033 ;; Ignore false positives.
5036 (org-test-with-temp-text
5037 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
5038 (org-find-property "A"))))
5039 ;; Return first entry found in buffer.
5042 (org-test-with-temp-text
5043 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5044 (org-find-property "A"))))
5045 ;; Only search visible part of the buffer.
5048 (org-test-with-temp-text
5049 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5050 (org-narrow-to-subtree)
5051 (org-find-property "A"))))
5052 ;; With optional argument, only find entries with a specific value.
5054 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5055 (org-find-property "A" "2")))
5058 (org-test-with-temp-text
5059 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5060 (org-find-property "A" "2"))))
5061 ;; Use "nil" for explicit nil values.
5064 (org-test-with-temp-text
5065 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5066 (org-find-property "A" "nil")))))
5068 (ert-deftest test-org
/entry-delete
()
5069 "Test `org-entry-delete' specifications."
5073 " *:PROPERTIES:\n *:B: +2\n *:END:"
5074 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5075 (org-entry-delete (point) "A")
5077 ;; Also remove accumulated properties.
5081 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5082 (org-entry-delete (point) "A")
5084 ;; When last property is removed, remove the property drawer.
5088 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5089 (org-entry-delete (point) "A")
5091 ;; Return a non-nil value when some property was removed.
5093 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5094 (org-entry-delete (point) "A")))
5096 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5097 (org-entry-delete (point) "C")))
5098 ;; Special properties cannot be located in a drawer. Allow to
5099 ;; remove them anyway, in case of user error.
5101 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5102 (org-entry-delete (point) "SCHEDULED"))))
5104 (ert-deftest test-org
/entry-get
()
5105 "Test `org-entry-get' specifications."
5109 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5110 (org-entry-get (point) "A"))))
5114 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5115 (org-entry-get (point) "a"))))
5116 ;; Handle extended values, both before and after base value.
5119 (org-test-with-temp-text
5120 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5121 (org-entry-get (point) "A"))))
5122 ;; Empty values are returned as the empty string.
5125 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5126 (org-entry-get (point) "A"))))
5127 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5128 ;; otherwise, return nil.
5130 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5131 (org-entry-get (point) "A")))
5134 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5135 (org-entry-get (point) "A" nil t
))))
5136 ;; Return nil when no property is found, independently on the
5137 ;; LITERAL-NIL argument.
5139 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5140 (org-entry-get (point) "B")))
5142 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5143 (org-entry-get (point) "B" nil t
)))
5144 ;; Handle inheritance, when allowed. Include extended values and
5145 ;; possibly global values.
5149 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5150 (org-entry-get (point) "A" t
))))
5154 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5155 (let ((org-use-property-inheritance t
))
5156 (org-entry-get (point) "A" 'selective
)))))
5158 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5159 (let ((org-use-property-inheritance nil
))
5160 (org-entry-get (point) "A" 'selective
))))
5164 (org-test-with-temp-text
5165 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5166 (org-entry-get (point-max) "A" t
))))
5169 (org-test-with-temp-text
5170 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5172 (org-entry-get (point-max) "A" t
))))
5175 (org-test-with-temp-text
5176 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5178 (org-entry-get (point-max) "A" t
)))))
5180 (ert-deftest test-org
/entry-properties
()
5181 "Test `org-entry-properties' specifications."
5182 ;; Get "ITEM" property.
5185 (org-test-with-temp-text "* TODO H"
5186 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5189 (org-test-with-temp-text "* TODO H"
5190 (cdr (assoc "ITEM" (org-entry-properties))))))
5191 ;; Get "TODO" property. TODO keywords are case sensitive.
5194 (org-test-with-temp-text "* TODO H"
5195 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5198 (org-test-with-temp-text "* TODO H"
5199 (cdr (assoc "TODO" (org-entry-properties))))))
5201 (org-test-with-temp-text "* H"
5202 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5204 (org-test-with-temp-text "* todo H"
5205 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5206 ;; Get "PRIORITY" property.
5209 (org-test-with-temp-text "* [#A] H"
5210 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5213 (org-test-with-temp-text "* [#A] H"
5214 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5216 (equal (char-to-string org-default-priority
)
5217 (org-test-with-temp-text "* H"
5218 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5219 ;; Get "FILE" property.
5221 (org-test-with-temp-text-in-file "* H\nParagraph"
5222 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5223 (buffer-file-name))))
5225 (org-test-with-temp-text-in-file "* H\nParagraph"
5226 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5227 (buffer-file-name))))
5229 (org-test-with-temp-text "* H\nParagraph"
5230 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5231 ;; Get "TAGS" property.
5233 (equal ":tag1:tag2:"
5234 (org-test-with-temp-text "* H :tag1:tag2:"
5235 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5237 (equal ":tag1:tag2:"
5238 (org-test-with-temp-text "* H :tag1:tag2:"
5239 (cdr (assoc "TAGS" (org-entry-properties))))))
5241 (org-test-with-temp-text "* H"
5242 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5243 ;; Get "ALLTAGS" property.
5245 (equal ":tag1:tag2:"
5246 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5247 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5249 (equal ":tag1:tag2:"
5250 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5251 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5253 (org-test-with-temp-text "* H"
5254 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5255 ;; Get "BLOCKED" property.
5258 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5259 (let ((org-enforce-todo-dependencies t
)
5261 '(org-block-todo-from-children-or-siblings-or-parent)))
5262 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5265 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5266 (let ((org-enforce-todo-dependencies t
)
5268 '(org-block-todo-from-children-or-siblings-or-parent)))
5269 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5270 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5274 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5275 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5279 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5280 (cdr (assoc "CLOSED" (org-entry-properties))))))
5282 (org-test-with-temp-text "* H"
5283 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5287 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5288 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5292 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5293 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5295 (org-test-with-temp-text "* H"
5296 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5300 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5301 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5305 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5306 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5308 (org-test-with-temp-text "* H"
5309 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5313 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5314 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5317 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5318 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5321 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5322 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5325 (org-test-with-temp-text
5326 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5328 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5329 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5330 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5332 (equal "<2012-03-29 thu.>"
5333 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5334 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5336 (equal "[2012-03-29 thu.]"
5337 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5338 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5340 (equal "<2012-03-29 thu.>"
5341 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5342 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5344 (equal "[2014-03-04 tue.]"
5345 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5346 (cdr (assoc "TIMESTAMP_IA"
5347 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5349 (equal "<2012-03-29 thu.>"
5350 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5351 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5352 ;; Get standard properties.
5355 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5356 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5357 ;; Handle extended properties.
5360 (org-test-with-temp-text
5361 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5362 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5365 (org-test-with-temp-text
5366 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5367 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5368 ;; Ignore forbidden (special) properties.
5370 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5371 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5373 (ert-deftest test-org
/entry-put
()
5374 "Test `org-entry-put' specifications."
5375 ;; Error when not a string or nil.
5377 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5378 (org-entry-put 1 "test" 2)))
5379 ;; Error when property name is invalid.
5381 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5382 (org-entry-put 1 "no space" "value")))
5384 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5385 (org-entry-put 1 "" "value")))
5386 ;; Set "TODO" property.
5388 (string-match (regexp-quote " TODO H")
5389 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5390 (org-entry-put (point) "TODO" "TODO")
5393 (string-match (regexp-quote "* H")
5394 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5395 (org-entry-put (point) "TODO" nil
)
5397 ;; Set "PRIORITY" property.
5400 (org-test-with-temp-text "* [#B] H"
5401 (org-entry-put (point) "PRIORITY" "A")
5405 (org-test-with-temp-text "* [#B] H"
5406 (org-entry-put (point) "PRIORITY" nil
)
5408 ;; Set "SCHEDULED" property.
5410 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5411 (org-test-with-temp-text "* H"
5412 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5416 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5417 (org-entry-put (point) "SCHEDULED" nil
)
5420 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5421 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5422 (org-entry-put (point) "SCHEDULED" "earlier")
5425 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5426 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5427 (org-entry-put (point) "SCHEDULED" "later")
5429 ;; Set "DEADLINE" property.
5431 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5432 (org-test-with-temp-text "* H"
5433 (org-entry-put (point) "DEADLINE" "2014-03-04")
5437 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5438 (org-entry-put (point) "DEADLINE" nil
)
5441 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5442 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5443 (org-entry-put (point) "DEADLINE" "earlier")
5446 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5447 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5448 (org-entry-put (point) "DEADLINE" "later")
5450 ;; Set "CATEGORY" property
5452 (string-match "^ *:CATEGORY: cat"
5453 (org-test-with-temp-text "* H"
5454 (org-entry-put (point) "CATEGORY" "cat")
5456 ;; Regular properties, with or without pre-existing drawer.
5458 (string-match "^ *:A: +2$"
5459 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5460 (org-entry-put (point) "A" "2")
5463 (string-match "^ *:A: +1$"
5464 (org-test-with-temp-text "* H"
5465 (org-entry-put (point) "A" "1")
5467 ;; Special case: two consecutive headlines.
5469 (string-match "\\* A\n *:PROPERTIES:"
5470 (org-test-with-temp-text "* A\n** B"
5471 (org-entry-put (point) "A" "1")
5474 (ert-deftest test-org
/refresh-properties
()
5475 "Test `org-refresh-properties' specifications."
5478 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5479 (org-refresh-properties "A" 'org-test
)
5480 (get-text-property (point) 'org-test
))))
5482 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5483 (org-refresh-properties "B" 'org-test
)
5484 (get-text-property (point) 'org-test
)))
5485 ;; Handle properties only defined with extension syntax, i.e.,
5489 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5490 (org-refresh-properties "A" 'org-test
)
5491 (get-text-property (point) 'org-test
))))
5492 ;; When property is inherited, add text property to the whole
5496 (org-test-with-temp-text
5497 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5498 (let ((org-use-property-inheritance t
))
5499 (org-refresh-properties "A" 'org-test
))
5500 (get-text-property (point) 'org-test
))))
5501 ;; When property is inherited, use global value across the whole
5502 ;; buffer. However local values have precedence.
5505 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5507 (let ((org-use-property-inheritance nil
))
5508 (org-refresh-properties "A" 'org-test
))
5509 (get-text-property (point) 'org-test
))))
5512 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5514 (let ((org-use-property-inheritance t
))
5515 (org-refresh-properties "A" 'org-test
))
5516 (get-text-property (point) 'org-test
))))
5519 (org-test-with-temp-text
5520 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5522 (let ((org-use-property-inheritance t
))
5523 (org-refresh-properties "A" 'org-test
))
5524 (get-text-property (point) 'org-test
)))))
5529 (ert-deftest test-org
/update-radio-target-regexp
()
5530 "Test `org-update-radio-target-regexp' specifications."
5531 ;; Properly update cache with no previous radio target regexp.
5534 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5535 (save-excursion (goto-char (point-max)) (org-element-context))
5537 (search-forward "o")
5539 (org-update-radio-target-regexp)
5540 (goto-char (point-max))
5541 (org-element-type (org-element-context)))))
5542 ;; Properly update cache with previous radio target regexp.
5545 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5546 (save-excursion (goto-char (point-max)) (org-element-context))
5548 (search-forward "o")
5550 (org-update-radio-target-regexp)
5551 (search-backward "r")
5554 (org-update-radio-target-regexp)
5555 (goto-char (point-max))
5556 (delete-region (line-beginning-position) (point))
5558 (org-element-type (org-element-context))))))
5563 (ert-deftest test-org
/refile-get-targets
()
5564 "Test `org-refile-get-targets' specifications."
5565 ;; :maxlevel includes all headings above specified value.
5567 (equal '("H1" "H2" "H3")
5568 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5569 (let ((org-refile-use-outline-path nil
)
5570 (org-refile-targets `((nil :maxlevel .
3))))
5571 (mapcar #'car
(org-refile-get-targets))))))
5574 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5575 (let ((org-refile-use-outline-path nil
)
5576 (org-refile-targets `((nil :maxlevel .
2))))
5577 (mapcar #'car
(org-refile-get-targets))))))
5578 ;; :level limits targets to headlines with the specified level.
5581 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5582 (let ((org-refile-use-outline-path nil
)
5583 (org-refile-targets `((nil :level .
2))))
5584 (mapcar #'car
(org-refile-get-targets))))))
5585 ;; :tag limits targets to headlines with specified tag.
5588 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5589 (let ((org-refile-use-outline-path nil
)
5590 (org-refile-targets `((nil :tag .
"foo"))))
5591 (mapcar #'car
(org-refile-get-targets))))))
5592 ;; :todo limits targets to headlines with specified TODO keyword.
5595 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5596 (let ((org-refile-use-outline-path nil
)
5597 (org-refile-targets `((nil :todo .
"TODO"))))
5598 (mapcar #'car
(org-refile-get-targets))))))
5599 ;; :regexp filters targets matching provided regexp.
5602 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5603 (let ((org-refile-use-outline-path nil
)
5604 (org-refile-targets `((nil :regexp .
"F"))))
5605 (mapcar #'car
(org-refile-get-targets))))))
5606 ;; A nil `org-refile-targets' includes only top level headlines in
5610 (org-test-with-temp-text "* H1\n** S1\n* H2"
5611 (let ((org-refile-use-outline-path nil
)
5612 (org-refile-targets nil
))
5613 (mapcar #'car
(org-refile-get-targets))))))
5614 ;; Return value is the union of the targets according to all the
5615 ;; defined rules. However, prevent duplicates.
5617 (equal '("F2" "F3" "H1")
5618 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5619 (let ((org-refile-use-outline-path nil
)
5620 (org-refile-targets `((nil :regexp .
"F")
5621 (nil :todo .
"TODO"))))
5622 (mapcar #'car
(org-refile-get-targets))))))
5624 (equal '("F2" "F3" "H1")
5625 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5626 (let ((org-refile-use-outline-path nil
)
5627 (org-refile-targets `((nil :regexp .
"F")
5628 (nil :todo .
"TODO"))))
5629 (mapcar #'car
(org-refile-get-targets))))))
5630 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5633 (equal '("H1" "H1/H2" "H1/H2/H3")
5634 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5635 (let ((org-refile-use-outline-path t
)
5636 (org-refile-targets `((nil :maxlevel .
3))))
5637 (mapcar #'car
(org-refile-get-targets))))))
5638 ;; When providing targets as paths, escape forward slashes in
5639 ;; headings with backslashes.
5641 (equal '("H1\\/foo")
5642 (org-test-with-temp-text "* H1/foo"
5643 (let ((org-refile-use-outline-path t
)
5644 (org-refile-targets `((nil :maxlevel .
1))))
5645 (mapcar #'car
(org-refile-get-targets))))))
5646 ;; When `org-refile-use-outline-path' is `file', include file name
5647 ;; without directory in targets.
5649 (org-test-with-temp-text-in-file "* H1"
5650 (let* ((filename (buffer-file-name))
5651 (org-refile-use-outline-path 'file
)
5652 (org-refile-targets `(((,filename
) :level .
1))))
5653 (member (file-name-nondirectory filename
)
5654 (mapcar #'car
(org-refile-get-targets))))))
5655 ;; When `org-refile-use-outline-path' is `full-file-path', include
5658 (org-test-with-temp-text-in-file "* H1"
5659 (let* ((filename (file-truename (buffer-file-name)))
5660 (org-refile-use-outline-path 'full-file-path
)
5661 (org-refile-targets `(((,filename
) :level .
1))))
5662 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5663 ;; When `org-refile-use-outline-path' is `buffer-name', include
5666 (org-test-with-temp-text "* H1"
5667 (let* ((org-refile-use-outline-path 'buffer-name
)
5668 (org-refile-targets `((nil :level .
1))))
5669 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5675 (ert-deftest test-org
/match-sparse-tree
()
5676 "Test `org-match-sparse-tree' specifications."
5679 (org-test-with-temp-text "* H\n** H1 :tag:"
5680 (org-match-sparse-tree nil
"tag")
5681 (search-forward "H1")
5682 (org-invisible-p2)))
5684 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5685 (org-match-sparse-tree nil
"tag")
5686 (search-forward "H2")
5687 (org-invisible-p2)))
5688 ;; "-" operator for tags.
5690 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5691 (org-match-sparse-tree nil
"tag1-tag2")
5692 (search-forward "H1")
5693 (org-invisible-p2)))
5695 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5696 (org-match-sparse-tree nil
"tag1-tag2")
5697 (search-forward "H2")
5698 (org-invisible-p2)))
5699 ;; "&" operator for tags.
5701 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5702 (org-match-sparse-tree nil
"tag1&tag2")
5703 (search-forward "H1")
5704 (org-invisible-p2)))
5706 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5707 (org-match-sparse-tree nil
"tag1&tag2")
5708 (search-forward "H2")
5709 (org-invisible-p2)))
5710 ;; "|" operator for tags.
5712 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5713 (org-match-sparse-tree nil
"tag1|tag2")
5714 (search-forward "H1")
5715 (org-invisible-p2)))
5717 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5718 (org-match-sparse-tree nil
"tag1|tag2")
5719 (search-forward "H2")
5720 (org-invisible-p2)))
5721 ;; Regexp match on tags.
5723 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5724 (org-match-sparse-tree nil
"{^tag.*}")
5725 (search-forward "H1")
5726 (org-invisible-p2)))
5728 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5729 (org-match-sparse-tree nil
"{^tag.*}")
5730 (search-forward "H2")
5731 (org-invisible-p2)))
5732 ;; Match group tags.
5734 (org-test-with-temp-text
5735 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5736 (org-match-sparse-tree nil
"work")
5737 (search-forward "H1")
5738 (org-invisible-p2)))
5740 (org-test-with-temp-text
5741 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5742 (org-match-sparse-tree nil
"work")
5743 (search-forward "H2")
5744 (org-invisible-p2)))
5745 ;; Match group tags with hard brackets.
5747 (org-test-with-temp-text
5748 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5749 (org-match-sparse-tree nil
"work")
5750 (search-forward "H1")
5751 (org-invisible-p2)))
5753 (org-test-with-temp-text
5754 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5755 (org-match-sparse-tree nil
"work")
5756 (search-forward "H2")
5757 (org-invisible-p2)))
5758 ;; Match tags in hierarchies
5760 (org-test-with-temp-text
5761 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5762 #+TAGS: [ Lev_2 : Lev_3 ]\n
5763 #+TAGS: { Lev_3 : Lev_4 }\n
5764 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5765 (org-match-sparse-tree nil
"Lev_1")
5766 (search-forward "H4")
5767 (org-invisible-p2)))
5768 ;; Match regular expressions in tags
5770 (org-test-with-temp-text
5771 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5772 (org-match-sparse-tree nil
"Lev")
5773 (search-forward "H1")
5774 (org-invisible-p2)))
5776 (org-test-with-temp-text
5777 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5778 (org-match-sparse-tree nil
"Lev")
5779 (search-forward "H1")
5780 (org-invisible-p2)))
5781 ;; Match properties.
5783 (org-test-with-temp-text
5784 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5785 (org-match-sparse-tree nil
"A=\"1\"")
5786 (search-forward "H2")
5787 (org-invisible-p2)))
5789 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5790 (org-match-sparse-tree nil
"A=\"1\"")
5791 (search-forward "H2")
5792 (org-invisible-p2)))
5793 ;; Case is not significant when matching properties.
5795 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5796 (org-match-sparse-tree nil
"a=\"1\"")
5797 (search-forward "H2")
5798 (org-invisible-p2)))
5800 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5801 (org-match-sparse-tree nil
"A=\"1\"")
5802 (search-forward "H2")
5803 (org-invisible-p2)))
5804 ;; Match special LEVEL property.
5806 (org-test-with-temp-text "* H\n** H1\n*** H2"
5807 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5808 (search-forward "H1")
5809 (org-invisible-p2)))
5811 (org-test-with-temp-text "* H\n** H1\n*** H2"
5812 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5813 (search-forward "H2")
5814 (org-invisible-p2)))
5815 ;; Comparison operators when matching properties.
5817 (org-test-with-temp-text
5818 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5819 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5820 (search-forward "H1")
5821 (org-invisible-p2)))
5823 (org-test-with-temp-text
5824 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5825 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5826 (search-forward "H2")
5827 (org-invisible-p2)))
5828 ;; Regexp match on properties values.
5830 (org-test-with-temp-text
5831 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5832 (org-match-sparse-tree nil
"A={f.*}")
5833 (search-forward "H1")
5834 (org-invisible-p2)))
5836 (org-test-with-temp-text
5837 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5838 (org-match-sparse-tree nil
"A={f.*}")
5839 (search-forward "H2")
5840 (org-invisible-p2)))
5841 ;; With an optional argument, limit match to TODO entries.
5843 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5844 (org-match-sparse-tree t
"tag")
5845 (search-forward "H1")
5846 (org-invisible-p2)))
5848 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5849 (org-match-sparse-tree t
"tag")
5850 (search-forward "H2")
5851 (org-invisible-p2))))
5853 (ert-deftest test-org
/occur
()
5854 "Test `org-occur' specifications."
5855 ;; Count number of matches.
5858 (org-test-with-temp-text "* H\nA\n* H2"
5862 (org-test-with-temp-text "* H\nA\n* H2\nA"
5864 ;; Test CALLBACK optional argument.
5867 (org-test-with-temp-text "* H\nA\n* H2"
5868 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5871 (org-test-with-temp-text "* H\nA\n* H2\nA"
5872 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5873 ;; Case-fold searches according to `org-occur-case-fold-search'.
5876 (org-test-with-temp-text "Aa"
5877 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5880 (org-test-with-temp-text "Aa"
5881 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5884 (org-test-with-temp-text "Aa"
5885 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5888 (org-test-with-temp-text "Aa"
5889 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5892 (org-test-with-temp-text "Aa"
5893 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5896 (org-test-with-temp-text "Aa"
5897 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5902 (ert-deftest test-org
/tag-string-to-alist
()
5903 "Test `org-tag-string-to-alist' specifications."
5904 ;; Tag without selection key.
5905 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5906 ;; Tag with selection key.
5907 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5911 (org-tag-string-to-alist "[ group : t1 t2 ]")
5912 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5913 ;; Mutually exclusive tags.
5914 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5915 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5918 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5919 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5921 (ert-deftest test-org
/tag-alist-to-string
()
5922 "Test `org-tag-alist-to-string' specifications."
5923 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5924 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5927 (org-tag-alist-to-string
5928 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5929 "[ group : t1 t2 ]"))
5931 (equal (org-tag-alist-to-string
5932 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5936 (org-tag-alist-to-string
5937 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5938 "{ group : tag1 tag2 }")))
5940 (ert-deftest test-org
/tag-alist-to-groups
()
5941 "Test `org-tag-alist-to-groups' specifications."
5943 (equal (org-tag-alist-to-groups
5944 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5945 '(("group" "t1" "t2"))))
5948 (org-tag-alist-to-groups
5949 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5950 '(("group" "t1" "t2"))))
5952 (org-tag-alist-to-groups
5953 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5955 (ert-deftest test-org
/tag-align
()
5956 "Test tags alignment."
5957 ;; Test aligning tags with different display width.
5959 ;; 12345678901234567890
5960 (equal "* Test :abc:"
5961 (org-test-with-temp-text "* Test :abc:"
5962 (let ((org-tags-column -
20)
5963 (indent-tabs-mode nil
))
5964 (org-fix-tags-on-the-fly))
5967 ;; 12345678901234567890
5968 (equal "* Test :日本語:"
5969 (org-test-with-temp-text "* Test :日本語:"
5970 (let ((org-tags-column -
20)
5971 (indent-tabs-mode nil
))
5972 (org-fix-tags-on-the-fly))
5974 ;; Make sure aligning tags do not skip invisible text.
5976 (equal "* [[linkx]] :tag:"
5977 (org-test-with-temp-text "* [[link<point>]] :tag:"
5978 (let ((org-tags-column 0))
5979 (org-fix-tags-on-the-fly)
5981 (buffer-string))))))
5983 (ert-deftest test-org
/tags-at
()
5985 (equal '("foo" "bar")
5986 (org-test-with-temp-text
5987 "* T<point>est :foo:bar:"
5988 (org-get-tags-at)))))
5990 (ert-deftest test-org
/set-tags
()
5991 "Test `org-set-tags' specifications."
5992 ;; Tags set via fast-tag-selection should be visible afterwards
5994 (let ((org-tag-alist '(("NEXT" . ?n
)))
5995 (org-fast-tag-selection-single-key t
))
5996 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5997 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5998 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5999 ;; Show only headlines
6001 ;; Set NEXT tag on current entry
6002 (org-set-tags nil nil
)
6003 ;; Move point to that NEXT tag
6004 (search-forward "NEXT") (backward-word)
6005 ;; And it should be visible (i.e. no overlays)
6006 (not (overlays-at (point))))))))
6008 (ert-deftest test-org
/set-tags-to
()
6009 "Test `org-set-tags-to' specifications."
6010 ;; Throw an error on invalid data.
6012 (org-test-with-temp-text "* H"
6013 (org-set-tags-to 'foo
)))
6014 ;; `nil', an empty, and a blank string remove all tags.
6017 (org-test-with-temp-text "* H :tag1:tag2:"
6018 (org-set-tags-to nil
)
6022 (org-test-with-temp-text "* H :tag1:tag2:"
6023 (org-set-tags-to "")
6027 (org-test-with-temp-text "* H :tag1:tag2:"
6028 (org-set-tags-to " ")
6030 ;; If there's nothing to remove, just bail out.
6033 (org-test-with-temp-text "* H"
6034 (org-set-tags-to nil
)
6038 (org-test-with-temp-text "* "
6039 (org-set-tags-to nil
)
6041 ;; If DATA is a tag string, set current tags to it, even if it means
6042 ;; replacing old tags.
6045 (org-test-with-temp-text "* H :tag1:tag2:"
6046 (org-set-tags-to ":tag0:")
6050 (org-test-with-temp-text "* H"
6051 (org-set-tags-to ":tag0:")
6053 ;; If DATA is a list, set tags to this list, even if it means
6054 ;; replacing old tags.
6057 (org-test-with-temp-text "* H :tag1:tag2:"
6058 (org-set-tags-to '("tag0"))
6062 (org-test-with-temp-text "* H"
6063 (org-set-tags-to '("tag0"))
6065 ;; Special case: handle empty headlines.
6068 (org-test-with-temp-text "* "
6069 (org-set-tags-to '("tag0"))
6075 (ert-deftest test-org
/auto-repeat-maybe
()
6076 "Test `org-auto-repeat-maybe' specifications."
6077 ;; Do not auto repeat when there is no valid time stamp with
6078 ;; a repeater in the entry.
6082 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6083 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
6089 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6090 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
6093 ;; When switching to DONE state, switch back to first TODO keyword
6094 ;; in sequence, or the same keyword if they have different types.
6098 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6099 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6105 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6106 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6112 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
6113 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6116 ;; If there was no TODO keyword in the first place, do not insert
6121 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6122 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6125 ;; Revert to REPEAT_TO_STATE, if set.
6129 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6130 (org-test-with-temp-text
6133 :REPEAT_TO_STATE: KWD2
6135 <2012-03-29 Thu +2y>"
6138 ;; When switching to DONE state, update base date. If there are
6139 ;; multiple repeated time stamps, update them all.
6142 "<2014-03-29 .* \\+2y>"
6143 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6144 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6149 "<2015-03-04 .* \\+1y>"
6150 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6151 (org-test-with-temp-text
6152 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6155 ;; Throw an error if repeater unit is the hour and no time is
6156 ;; provided in the time-stamp.
6158 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6159 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6162 ;; Do not repeat commented time stamps.
6165 "<2015-03-04 .* \\+1y>"
6166 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6167 (org-test-with-temp-text
6168 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6173 "<2015-03-04 .* \\+1y>"
6174 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6175 (org-test-with-temp-text
6177 <2012-03-29 Thu. +2y>
6179 <2014-03-04 Tue +1y>
6183 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6184 ;; entry, record time of last repeat.
6188 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6189 (org-log-repeat nil
))
6190 (cl-letf (((symbol-function 'org-add-log-setup
)
6191 (lambda (&rest args
) nil
)))
6192 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6194 (buffer-string))))))
6198 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6200 (cl-letf (((symbol-function 'org-add-log-setup
)
6201 (lambda (&rest args
) nil
)))
6202 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6204 (buffer-string))))))
6208 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6209 (cl-letf (((symbol-function 'org-add-log-setup
)
6210 (lambda (&rest args
) nil
)))
6211 (org-test-with-temp-text
6212 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6214 (buffer-string))))))
6215 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6216 ;; the entry as it is no longer relevant.
6220 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6221 (org-test-with-temp-text
6222 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6225 ;; Properly advance repeater even when a clock entry is specified
6226 ;; and `org-log-repeat' is nil.
6229 "SCHEDULED: <2014-03-29"
6230 (let ((org-log-repeat nil
)
6231 (org-todo-keywords '((sequence "TODO" "DONE"))))
6232 (org-test-with-temp-text
6234 SCHEDULED: <2012-03-29 Thu +2y>
6235 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6237 (buffer-string))))))
6242 (ert-deftest test-org
/at-timestamp-p
()
6243 "Test `org-at-timestamp-p' specifications."
6245 (org-test-with-temp-text "<2012-03-29 Thu>"
6246 (org-at-timestamp-p)))
6248 (org-test-with-temp-text "2012-03-29 Thu"
6249 (org-at-timestamp-p)))
6250 ;; Test return values.
6253 (org-test-with-temp-text "<2012-03-29 Thu>"
6254 (org-at-timestamp-p))))
6257 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6258 (org-at-timestamp-p))))
6261 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6262 (org-at-timestamp-p))))
6265 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6266 (org-at-timestamp-p))))
6269 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6270 (org-at-timestamp-p))))
6273 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6274 (org-at-timestamp-p))))
6277 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6278 (org-at-timestamp-p))))
6281 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6282 (org-at-timestamp-p))))
6283 ;; Test `inactive' optional argument.
6285 (org-test-with-temp-text "[2012-03-29 Thu]"
6286 (org-at-timestamp-p 'inactive
)))
6288 (org-test-with-temp-text "[2012-03-29 Thu]"
6289 (org-at-timestamp-p)))
6290 ;; When optional argument is `agenda', recognize time-stamps in
6291 ;; planning info line, property drawers and clocks.
6293 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6294 (org-at-timestamp-p 'agenda
)))
6296 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6297 (org-at-timestamp-p)))
6299 (org-test-with-temp-text
6300 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6301 (org-at-timestamp-p 'agenda
)))
6303 (org-test-with-temp-text
6304 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6305 (org-at-timestamp-p)))
6307 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6308 (let ((org-agenda-include-inactive-timestamps t
))
6309 (org-at-timestamp-p 'agenda
))))
6311 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6312 (let ((org-agenda-include-inactive-timestamps t
))
6313 (org-at-timestamp-p))))
6315 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6316 (let ((org-agenda-include-inactive-timestamps t
))
6317 (org-at-timestamp-p 'inactive
))))
6318 ;; When optional argument is `lax', match any part of the document
6319 ;; with Org timestamp syntax.
6321 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6322 (org-at-timestamp-p 'lax
)))
6324 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6325 (org-at-timestamp-p)))
6327 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6328 (org-at-timestamp-p 'lax
)))
6330 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6331 (org-at-timestamp-p)))
6333 (org-test-with-temp-text
6334 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6335 (org-at-timestamp-p 'lax
)))
6337 (org-test-with-temp-text
6338 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6339 (org-at-timestamp-p)))
6340 ;; Optional argument `lax' also matches inactive timestamps.
6342 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6343 (org-at-timestamp-p 'lax
))))
6345 (ert-deftest test-org
/time-stamp
()
6346 "Test `org-time-stamp' specifications."
6347 ;; Insert chosen time stamp at point.
6350 "Te<2014-03-04 .*?>xt"
6351 (org-test-with-temp-text "Te<point>xt"
6352 (cl-letf (((symbol-function 'org-read-date
)
6353 (lambda (&rest args
)
6354 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6355 (org-time-stamp nil
)
6357 ;; With a prefix argument, also insert time.
6360 "Te<2014-03-04 .*? 00:41>xt"
6361 (org-test-with-temp-text "Te<point>xt"
6362 (cl-letf (((symbol-function 'org-read-date
)
6363 (lambda (&rest args
)
6364 (apply #'encode-time
6365 (org-parse-time-string "2014-03-04 00:41")))))
6366 (org-time-stamp '(4))
6368 ;; With two universal prefix arguments, insert an active timestamp
6369 ;; with the current time without prompting the user.
6372 "Te<2014-03-04 .*? 00:41>xt"
6373 (org-test-with-temp-text "Te<point>xt"
6374 (cl-letf (((symbol-function 'current-time
)
6376 (apply #'encode-time
6377 (org-parse-time-string "2014-03-04 00:41")))))
6378 (org-time-stamp '(16))
6380 ;; When optional argument is non-nil, insert an inactive timestamp.
6383 "Te\\[2014-03-04 .*?\\]xt"
6384 (org-test-with-temp-text "Te<point>xt"
6385 (cl-letf (((symbol-function 'org-read-date
)
6386 (lambda (&rest args
)
6387 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6388 (org-time-stamp nil t
)
6390 ;; When called from a timestamp, replace existing one.
6394 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6395 (cl-letf (((symbol-function 'org-read-date
)
6396 (lambda (&rest args
)
6397 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6398 (org-time-stamp nil
)
6402 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6403 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6404 (cl-letf (((symbol-function 'org-read-date
)
6405 (lambda (&rest args
)
6406 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6407 (org-time-stamp nil
)
6409 ;; When replacing a timestamp, preserve repeater, if any.
6412 "<2014-03-04 .*? \\+2y>"
6413 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6414 (cl-letf (((symbol-function 'org-read-date
)
6415 (lambda (&rest args
)
6416 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6417 (org-time-stamp nil
)
6419 ;; When called twice in a raw, build a date range.
6422 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6423 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6424 (cl-letf (((symbol-function 'org-read-date
)
6425 (lambda (&rest args
)
6426 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6427 (let ((last-command 'org-time-stamp
)
6428 (this-command 'org-time-stamp
))
6429 (org-time-stamp nil
))
6430 (buffer-string))))))
6432 (ert-deftest test-org
/timestamp-has-time-p
()
6433 "Test `org-timestamp-has-time-p' specifications."
6436 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6437 (org-timestamp-has-time-p (org-element-context))))
6440 (org-test-with-temp-text "<2012-03-29 Thu>"
6441 (org-timestamp-has-time-p (org-element-context)))))
6443 (ert-deftest test-org
/get-repeat
()
6444 "Test `org-get-repeat' specifications."
6446 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6449 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6451 ;; Return proper repeat string.
6454 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6456 ;; Prevent false positive (commented or verbatim time stamps)
6458 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6461 (org-test-with-temp-text
6462 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6464 ;; Return nil when called before first heading.
6466 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6468 ;; When called with an optional argument, extract repeater from that
6470 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6471 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6473 (ert-deftest test-org
/timestamp-format
()
6474 "Test `org-timestamp-format' specifications."
6479 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6480 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6485 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6486 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6488 (ert-deftest test-org
/timestamp-split-range
()
6489 "Test `org-timestamp-split-range' specifications."
6490 ;; Extract range start (active).
6493 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6494 (let ((ts (org-timestamp-split-range (org-element-context))))
6495 (mapcar (lambda (p) (org-element-property p ts
))
6496 '(:year-end
:month-end
:day-end
))))))
6497 ;; Extract range start (inactive)
6500 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6501 (let ((ts (org-timestamp-split-range (org-element-context))))
6502 (mapcar (lambda (p) (org-element-property p ts
))
6503 '(:year-end
:month-end
:day-end
))))))
6504 ;; Extract range end (active).
6507 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6508 (let ((ts (org-timestamp-split-range
6509 (org-element-context) t
)))
6510 (mapcar (lambda (p) (org-element-property p ts
))
6511 '(:year-end
:month-end
:day-end
))))))
6512 ;; Extract range end (inactive)
6515 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6516 (let ((ts (org-timestamp-split-range
6517 (org-element-context) t
)))
6518 (mapcar (lambda (p) (org-element-property p ts
))
6519 '(:year-end
:month-end
:day-end
))))))
6520 ;; Return the timestamp if not a range.
6522 (org-test-with-temp-text "[2012-03-29 Thu]"
6523 (let* ((ts-orig (org-element-context))
6524 (ts-copy (org-timestamp-split-range ts-orig
)))
6525 (eq ts-orig ts-copy
))))
6527 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6528 (let* ((ts-orig (org-element-context))
6529 (ts-copy (org-timestamp-split-range ts-orig
)))
6530 (eq ts-orig ts-copy
)))))
6532 (ert-deftest test-org
/timestamp-translate
()
6533 "Test `org-timestamp-translate' specifications."
6534 ;; Translate whole date range.
6537 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6538 (let ((org-display-custom-times t
)
6539 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6540 (org-timestamp-translate (org-element-context))))))
6541 ;; Translate date range start.
6544 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6545 (let ((org-display-custom-times t
)
6546 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6547 (org-timestamp-translate (org-element-context) 'start
)))))
6548 ;; Translate date range end.
6551 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6552 (let ((org-display-custom-times t
)
6553 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6554 (org-timestamp-translate (org-element-context) 'end
)))))
6555 ;; Translate time range.
6558 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6559 (let ((org-display-custom-times t
)
6560 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6561 (org-timestamp-translate (org-element-context))))))
6562 ;; Translate non-range timestamp.
6565 (org-test-with-temp-text "<2012-03-29 Thu>"
6566 (let ((org-display-custom-times t
)
6567 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6568 (org-timestamp-translate (org-element-context))))))
6569 ;; Do not change `diary' timestamps.
6571 (equal "<%%(org-float t 4 2)>"
6572 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6573 (let ((org-display-custom-times t
)
6574 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6575 (org-timestamp-translate (org-element-context)))))))
6577 (ert-deftest test-org
/timestamp-from-string
()
6578 "Test `org-timestamp-from-string' specifications."
6579 ;; Return nil if argument is not a valid Org timestamp.
6580 (should-not (org-timestamp-from-string ""))
6581 (should-not (org-timestamp-from-string nil
))
6582 (should-not (org-timestamp-from-string "<2012-03-29"))
6583 ;; Otherwise, return a valid Org timestamp object.
6585 (equal "<2012-03-29 Thu>"
6586 (let ((system-time-locale "en_US"))
6587 (org-element-interpret-data
6588 (org-timestamp-from-string "<2012-03-29 Thu>")))))
6590 (equal "[2014-03-04 Tue]"
6591 (let ((system-time-locale "en_US"))
6592 (org-element-interpret-data
6593 (org-timestamp-from-string "[2014-03-04 Tue]"))))))
6595 (ert-deftest test-org
/timestamp-from-time
()
6596 "Test `org-timestamp-from-time' specifications."
6599 (equal "<2012-03-29 Thu>"
6600 (let ((system-time-locale "en_US"))
6601 (org-element-interpret-data
6602 (org-timestamp-from-time
6603 (apply #'encode-time
6604 (org-parse-time-string "<2012-03-29 Thu 16:40>")))))))
6605 ;; When optional argument WITH-TIME is non-nil, provide time
6608 (equal "<2012-03-29 Thu 16:40>"
6609 (let ((system-time-locale "en_US"))
6610 (org-element-interpret-data
6611 (org-timestamp-from-time
6612 (apply #'encode-time
6613 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6615 ;; When optional argument INACTIVE is non-nil, return an inactive
6618 (equal "[2012-03-29 Thu]"
6619 (let ((system-time-locale "en_US"))
6620 (org-element-interpret-data
6621 (org-timestamp-from-time
6622 (apply #'encode-time
6623 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6626 (ert-deftest test-org
/timestamp-to-time
()
6627 "Test `org-timestamp-to-time' specifications."
6632 (org-timestamp-to-time
6633 (org-timestamp-from-string "<2014-03-04 Tue>")))))
6638 (org-timestamp-to-time
6639 (org-timestamp-from-string "[2014-03-04 Tue]")))))
6641 (equal "2012-03-29 08:30"
6644 (org-timestamp-to-time
6645 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
6650 (org-timestamp-to-time
6651 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
6656 (org-timestamp-to-time
6657 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
6658 ;; When optional argument END is non-nil, use end of date range or
6661 (equal "2012-03-29 16:40"
6664 (org-timestamp-to-time
6665 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
6671 (org-timestamp-to-time
6672 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
6678 (org-timestamp-to-time
6679 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
6685 (ert-deftest test-org
/flag-drawer
()
6686 "Test `org-flag-drawer' specifications."
6689 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6691 (get-char-property (line-end-position) 'invisible
)))
6694 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6696 (org-flag-drawer nil
)
6697 (get-char-property (line-end-position) 'invisible
)))
6698 ;; Test optional argument.
6700 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6701 (let ((drawer (save-excursion (search-forward ":D2")
6702 (org-element-at-point))))
6703 (org-flag-drawer t drawer
)
6704 (get-char-property (progn (search-forward ":D2") (line-end-position))
6707 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6708 (let ((drawer (save-excursion (search-forward ":D2")
6709 (org-element-at-point))))
6710 (org-flag-drawer t drawer
)
6711 (get-char-property (line-end-position) 'invisible
))))
6712 ;; Do not hide fake drawers.
6714 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6717 (get-char-property (line-end-position) 'invisible
)))
6718 ;; Do not hide incomplete drawers.
6720 (org-test-with-temp-text ":D:\nparagraph"
6723 (get-char-property (line-end-position) 'invisible
)))
6724 ;; Do not hide drawers when called from final blank lines.
6726 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6727 (goto-char (point-max))
6729 (goto-char (point-min))
6730 (get-char-property (line-end-position) 'invisible
)))
6731 ;; Don't leave point in an invisible part of the buffer when hiding
6734 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6735 (goto-char (point-max))
6737 (get-char-property (point) 'invisible
))))
6739 (ert-deftest test-org
/hide-block-toggle
()
6740 "Test `org-hide-block-toggle' specifications."
6741 ;; Error when not at a block.
6743 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6744 (org-hide-block-toggle 'off
)
6745 (get-char-property (line-end-position) 'invisible
)))
6748 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6749 (org-hide-block-toggle)
6750 (get-char-property (line-end-position) 'invisible
)))
6752 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6753 (org-hide-block-toggle)
6754 (get-char-property (line-end-position) 'invisible
)))
6755 ;; Show block unconditionally when optional argument is `off'.
6757 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6758 (org-hide-block-toggle)
6759 (org-hide-block-toggle 'off
)
6760 (get-char-property (line-end-position) 'invisible
)))
6762 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6763 (org-hide-block-toggle 'off
)
6764 (get-char-property (line-end-position) 'invisible
)))
6765 ;; Hide block unconditionally when optional argument is non-nil.
6767 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6768 (org-hide-block-toggle t
)
6769 (get-char-property (line-end-position) 'invisible
)))
6771 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6772 (org-hide-block-toggle)
6773 (org-hide-block-toggle t
)
6774 (get-char-property (line-end-position) 'invisible
)))
6775 ;; Do not hide block when called from final blank lines.
6777 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6778 (org-hide-block-toggle)
6779 (goto-char (point-min))
6780 (get-char-property (line-end-position) 'invisible
)))
6781 ;; Don't leave point in an invisible part of the buffer when hiding
6784 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6785 (org-hide-block-toggle)
6786 (get-char-property (point) 'invisible
))))
6788 (ert-deftest test-org
/hide-block-toggle-maybe
()
6789 "Test `org-hide-block-toggle-maybe' specifications."
6791 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6792 (org-hide-block-toggle-maybe)))
6794 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6796 (ert-deftest test-org
/show-set-visibility
()
6797 "Test `org-show-set-visibility' specifications."
6798 ;; Do not throw an error before first heading.
6800 (org-test-with-temp-text "Preamble\n* Headline"
6801 (org-show-set-visibility 'tree
)
6803 ;; Test all visibility spans, both on headline and in entry.
6804 (let ((list-visible-lines
6805 (lambda (state headerp
)
6806 (org-test-with-temp-text "* Grandmother (0)
6817 **** The other child (11)
6822 (search-forward (if headerp
"Self" "Match"))
6823 (org-show-set-visibility state
)
6824 (goto-char (point-min))
6825 (let (result (line 0))
6827 (unless (org-invisible-p2) (push line result
))
6830 (nreverse result
))))))
6831 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6832 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6833 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6834 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6835 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6836 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6837 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6838 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6839 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6840 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6841 (funcall list-visible-lines
'tree nil
)))
6842 (should (equal '(0 1 3 4 5 7 12 13)
6843 (funcall list-visible-lines
'canonical t
)))
6844 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6845 (funcall list-visible-lines
'canonical nil
))))
6846 ;; When point is hidden in a drawer or a block, make sure to make it
6849 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6850 (org-hide-block-toggle)
6851 (search-forward "Text")
6852 (org-show-set-visibility 'minimal
)
6853 (org-invisible-p2)))
6855 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6857 (search-forward "Text")
6858 (org-show-set-visibility 'minimal
)
6859 (org-invisible-p2)))
6861 (org-test-with-temp-text
6862 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6865 (org-hide-block-toggle)
6866 (search-forward "Text")
6867 (org-show-set-visibility 'minimal
)
6868 (org-invisible-p2))))
6870 (defun test-org/copy-visible
()
6871 "Test `org-copy-visible' specifications."
6874 (org-test-with-temp-text "Foo"
6875 (let ((kill-ring nil
))
6876 (org-copy-visible (point-min) (point-max))
6877 (current-kill 0 t
)))))
6878 ;; Skip invisible characters by text property.
6881 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6882 (let ((kill-ring nil
))
6883 (org-copy-visible (point-min) (point-max))
6884 (current-kill 0 t
)))))
6885 ;; Skip invisible characters by overlay.
6888 (org-test-with-temp-text "F<hidden>oo"
6889 (let ((o (make-overlay 2 10)))
6890 (overlay-put o
'invisible t
))
6891 (let ((kill-ring nil
))
6892 (org-copy-visible (point-min) (point-max))
6893 (current-kill 0 t
)))))
6894 ;; Handle invisible characters at the beginning and the end of the
6898 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6899 (let ((kill-ring nil
))
6900 (org-copy-visible (point-min) (point-max))
6901 (current-kill 0 t
)))))
6904 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6905 (let ((kill-ring nil
))
6906 (org-copy-visible (point-min) (point-max))
6907 (current-kill 0 t
)))))
6908 ;; Handle multiple visible parts.
6911 (org-test-with-temp-text
6912 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6913 (let ((kill-ring nil
))
6914 (org-copy-visible (point-min) (point-max))
6915 (current-kill 0 t
))))))
6917 (ert-deftest test-org
/set-visibility-according-to-property
()
6918 "Test `org-set-visibility-according-to-property' specifications."
6921 (org-test-with-temp-text
6928 (org-set-visibility-according-to-property)
6929 (invisible-p (point))))
6930 ;; "children" state.
6932 (org-test-with-temp-text
6936 :VISIBILITY: children
6941 (org-set-visibility-according-to-property)
6942 (invisible-p (point))))
6944 (org-test-with-temp-text
6948 :VISIBILITY: children
6953 (org-set-visibility-according-to-property)
6954 (invisible-p (point))))
6957 (org-test-with-temp-text
6961 :VISIBILITY: content
6966 (org-set-visibility-according-to-property)
6967 (invisible-p (point))))
6969 (org-test-with-temp-text
6973 :VISIBILITY: content
6978 (org-set-visibility-according-to-property)
6979 (not (invisible-p (point)))))
6982 (org-test-with-temp-text
6986 :VISIBILITY: showall
6991 (org-set-visibility-according-to-property)
6992 (not (invisible-p (point)))))
6994 (org-test-with-temp-text
6998 :VISIBILITY: showall
7003 (org-set-visibility-according-to-property)
7004 (not (invisible-p (point))))))
7009 (ert-deftest test-org
/paste-subtree
()
7010 "Test `org-paste-subtree' specifications."
7011 ;; Return an error if text to yank is not a set of subtrees.
7012 (should-error (org-paste-subtree nil
"Text"))
7013 ;; Adjust level according to current one.
7015 (equal "* H\n* Text\n"
7016 (org-test-with-temp-text "* H\n<point>"
7017 (org-paste-subtree nil
"* Text")
7020 (equal "* H1\n** H2\n** Text\n"
7021 (org-test-with-temp-text "* H1\n** H2\n<point>"
7022 (org-paste-subtree nil
"* Text")
7024 ;; When not on a heading, move to next heading before yanking.
7026 (equal "* H1\nParagraph\n* Text\n* H2"
7027 (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
7028 (org-paste-subtree nil
"* Text")
7030 ;; If point is between two headings, use the deepest level.
7032 (equal "* H1\n\n* Text\n* H2"
7033 (org-test-with-temp-text "* H1\n<point>\n* H2"
7034 (org-paste-subtree nil
"* Text")
7037 (equal "** H1\n\n** Text\n* H2"
7038 (org-test-with-temp-text "** H1\n<point>\n* H2"
7039 (org-paste-subtree nil
"* Text")
7042 (equal "* H1\n\n** Text\n** H2"
7043 (org-test-with-temp-text "* H1\n<point>\n** H2"
7044 (org-paste-subtree nil
"* Text")
7046 ;; When on an empty heading, after the stars, deduce the new level
7047 ;; from the number of stars.
7050 (org-test-with-temp-text "*** <point>"
7051 (org-paste-subtree nil
"* Text")
7053 ;; Optional argument LEVEL forces a level for the subtree.
7055 (equal "* H\n*** Text\n"
7056 (org-test-with-temp-text "* H<point>"
7057 (org-paste-subtree 3 "* Text")
7062 ;;; test-org.el ends here