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 |"
1202 (ert-deftest test-org
/meta-return
()
1203 "Test M-RET (`org-meta-return') specifications."
1204 ;; In a table field insert a row above.
1206 (org-test-with-temp-text "| a |"
1210 (looking-at "| |$")))
1211 ;; In a paragraph change current line into a header.
1213 (org-test-with-temp-text "a"
1216 (looking-at "\* a$")))
1217 ;; In an item insert an item, in this case above.
1219 (org-test-with-temp-text "- a"
1222 (looking-at "- $")))
1223 ;; In a drawer and item insert an item, in this case above.
1225 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1229 (looking-at "- $"))))
1231 (ert-deftest test-org
/insert-heading
()
1232 "Test `org-insert-heading' specifications."
1233 ;; In an empty buffer, insert a new headline.
1236 (org-test-with-temp-text ""
1237 (org-insert-heading)
1239 ;; At the beginning of a line, turn it into a headline.
1242 (org-test-with-temp-text "<point>P"
1243 (org-insert-heading)
1245 ;; In the middle of a line, split the line if allowed, otherwise,
1246 ;; insert the headline at its end.
1248 (equal "Para\n* graph"
1249 (org-test-with-temp-text "Para<point>graph"
1250 (let ((org-M-RET-may-split-line '((default . t
))))
1251 (org-insert-heading))
1254 (equal "Paragraph\n* "
1255 (org-test-with-temp-text "Para<point>graph"
1256 (let ((org-M-RET-may-split-line '((default . nil
))))
1257 (org-insert-heading))
1259 ;; At the beginning of a headline, create one above.
1262 (org-test-with-temp-text "* H"
1263 (org-insert-heading)
1265 ;; In the middle of a headline, split it if allowed.
1268 (org-test-with-temp-text "* H<point>1"
1269 (let ((org-M-RET-may-split-line '((headline . t
))))
1270 (org-insert-heading))
1274 (org-test-with-temp-text "* H<point>1"
1275 (let ((org-M-RET-may-split-line '((headline . nil
))))
1276 (org-insert-heading))
1278 ;; However, splitting cannot happen on TODO keywords, priorities or
1281 (equal "* TODO H1\n* \n"
1282 (org-test-with-temp-text "* TO<point>DO H1"
1283 (let ((org-M-RET-may-split-line '((headline . t
))))
1284 (org-insert-heading))
1287 (equal "* [#A] H1\n* \n"
1288 (org-test-with-temp-text "* [#<point>A] H1"
1289 (let ((org-M-RET-may-split-line '((headline . t
))))
1290 (org-insert-heading))
1293 (equal "* H1 :tag:\n* \n"
1294 (org-test-with-temp-text "* H1 :ta<point>g:"
1295 (let ((org-M-RET-may-split-line '((headline . t
))))
1296 (org-insert-heading))
1298 ;; New headline level depends on the level of the headline above.
1301 (org-test-with-temp-text "** H\n<point>P"
1302 (org-insert-heading)
1305 (equal "** H\nPara\n** graph"
1306 (org-test-with-temp-text "** H\nPara<point>graph"
1307 (let ((org-M-RET-may-split-line '((default . t
))))
1308 (org-insert-heading))
1312 (org-test-with-temp-text "** H"
1313 (org-insert-heading)
1315 ;; When called with one universal argument, insert a new headline at
1316 ;; the end of the current subtree, independently on the position of
1321 (org-test-with-temp-text "* H1\n** H2"
1322 (let ((org-insert-heading-respect-content nil
))
1323 (org-insert-heading '(4)))
1328 (org-test-with-temp-text "* H<point>1\n** H2"
1329 (let ((org-insert-heading-respect-content nil
))
1330 (org-insert-heading '(4)))
1332 ;; When called with two universal arguments, insert a new headline
1333 ;; at the end of the grandparent subtree.
1335 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1336 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1337 (let ((org-insert-heading-respect-content nil
))
1338 (org-insert-heading '(16)))
1340 ;; When optional TOP-LEVEL argument is non-nil, always insert
1341 ;; a level 1 heading.
1343 (equal "* H1\n** H2\n* \n"
1344 (org-test-with-temp-text "* H1\n** H2<point>"
1345 (org-insert-heading nil nil t
)
1348 (equal "* H1\n- item\n* "
1349 (org-test-with-temp-text "* H1\n- item<point>"
1350 (org-insert-heading nil nil t
)
1352 ;; Obey `org-blank-before-new-entry'.
1354 (equal "* H1\n\n* \n"
1355 (org-test-with-temp-text "* H1<point>"
1356 (let ((org-blank-before-new-entry '((heading . t
))))
1357 (org-insert-heading))
1361 (org-test-with-temp-text "* H1<point>"
1362 (let ((org-blank-before-new-entry '((heading . nil
))))
1363 (org-insert-heading))
1366 (equal "* H1\n* H2\n* \n"
1367 (org-test-with-temp-text "* H1\n* H2<point>"
1368 (let ((org-blank-before-new-entry '((heading . auto
))))
1369 (org-insert-heading))
1372 (equal "* H1\n\n* H2\n\n* \n"
1373 (org-test-with-temp-text "* H1\n\n* H2<point>"
1374 (let ((org-blank-before-new-entry '((heading . auto
))))
1375 (org-insert-heading))
1377 ;; Corner case: correctly insert a headline after an empty one.
1380 (org-test-with-temp-text "* <point>"
1381 (org-insert-heading)
1384 (org-test-with-temp-text "* <point>\n"
1385 (org-insert-heading)
1386 (looking-at-p "\n\\'")))
1387 ;; Do not insert spurious headlines when inserting a new headline.
1389 (equal "* H1\n* H2\n* \n"
1390 (org-test-with-temp-text "* H1\n* H2<point>\n"
1391 (org-insert-heading)
1393 ;; Preserve visibility at beginning of line. In particular, when
1394 ;; removing spurious blank lines, do not visually merge heading with
1395 ;; the line visible above.
1397 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1399 (let ((org-blank-before-new-entry '((heading . nil
))))
1400 (org-insert-heading '(4)))
1401 (invisible-p (line-end-position 0))))
1402 ;; Properly handle empty lines when forcing a headline below current
1405 (equal "* H1\n\n* H\n\n* \n"
1406 (org-test-with-temp-text "* H1\n\n* H<point>"
1407 (let ((org-blank-before-new-entry '((heading . t
))))
1408 (org-insert-heading '(4))
1409 (buffer-string))))))
1411 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1412 "Test `org-insert-todo-heading-respect-content' specifications."
1413 ;; Create a TODO heading.
1415 (org-test-with-temp-text "* H1\n Body"
1416 (org-insert-todo-heading-respect-content)
1417 (nth 2 (org-heading-components))))
1418 ;; Add headline at the end of the first subtree
1422 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1423 (org-insert-todo-heading-respect-content)
1424 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1425 ;; In a list, do not create a new item.
1429 (org-test-with-temp-text "* H\n- an item\n- another one"
1430 (search-forward "an ")
1431 (org-insert-todo-heading-respect-content)
1432 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1433 ;; Use the same TODO keyword as current heading.
1437 (org-test-with-temp-text "* TODO\n** WAITING\n"
1438 (org-insert-todo-heading-respect-content)
1439 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1441 (ert-deftest test-org
/clone-with-time-shift
()
1442 "Test `org-clone-subtree-with-time-shift'."
1443 ;; Raise an error before first heading.
1445 (org-test-with-temp-text ""
1446 (org-clone-subtree-with-time-shift 1)))
1447 ;; Raise an error on invalid number of clones.
1449 (org-test-with-temp-text "* Clone me"
1450 (org-clone-subtree-with-time-shift -
1)))
1451 ;; Clone non-repeating once.
1457 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1458 (org-clone-subtree-with-time-shift 1 "+2d")
1459 (replace-regexp-in-string
1460 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1462 ;; Clone repeating once.
1467 * H1\n<2015-06-25 +1w>
1469 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1470 (org-clone-subtree-with-time-shift 1 "+2d")
1471 (replace-regexp-in-string
1472 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1474 ;; Clone non-repeating zero times.
1479 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1480 (org-clone-subtree-with-time-shift 0 "+2d")
1481 (replace-regexp-in-string
1482 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1484 ;; Clone repeating "zero" times.
1488 * H1\n<2015-06-23 +1w>
1490 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1491 (org-clone-subtree-with-time-shift 0 "+2d")
1492 (replace-regexp-in-string
1493 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1495 ;; Clone with blank SHIFT argument.
1499 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1500 (org-clone-subtree-with-time-shift 1 "")
1501 (buffer-substring-no-properties (line-beginning-position 2)
1502 (line-end-position 2)))))
1503 ;; Find time stamps before point. If SHIFT is not specified, ask
1504 ;; for a time shift.
1508 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1509 (org-clone-subtree-with-time-shift 1 "+1d")
1510 (buffer-substring-no-properties (line-beginning-position 2)
1511 (line-end-position 2)))))
1515 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1516 (cl-letf (((symbol-function 'read-from-minibuffer
)
1517 (lambda (&rest args
) "+1d")))
1518 (org-clone-subtree-with-time-shift 1))
1519 (buffer-substring-no-properties (line-beginning-position 2)
1520 (line-end-position 2))))))
1523 ;;; Fixed-Width Areas
1525 (ert-deftest test-org
/toggle-fixed-width
()
1526 "Test `org-toggle-fixed-width' specifications."
1527 ;; No region: Toggle on fixed-width marker in paragraphs.
1530 (org-test-with-temp-text "A"
1531 (org-toggle-fixed-width)
1533 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1536 (org-test-with-temp-text ": A"
1537 (org-toggle-fixed-width)
1539 ;; No region: Toggle on marker in blank lines after elements or just
1540 ;; after a headline.
1543 (org-test-with-temp-text "* H\n"
1545 (org-toggle-fixed-width)
1548 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1549 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1550 (goto-char (point-max))
1551 (org-toggle-fixed-width)
1553 ;; No region: Toggle on marker in front of one line elements (e.g.,
1554 ;; headlines, clocks)
1556 (equal ": * Headline"
1557 (org-test-with-temp-text "* Headline"
1558 (org-toggle-fixed-width)
1561 (equal ": #+KEYWORD: value"
1562 (org-test-with-temp-text "#+KEYWORD: value"
1563 (org-toggle-fixed-width)
1565 ;; No region: error in other situations.
1567 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1569 (org-toggle-fixed-width)
1571 ;; No region: Indentation is preserved.
1574 (org-test-with-temp-text "- A\n B"
1576 (org-toggle-fixed-width)
1578 ;; Region: If it contains only fixed-width elements and blank lines,
1579 ;; toggle off fixed-width markup.
1582 (org-test-with-temp-text ": A\n\n: B"
1583 (transient-mark-mode 1)
1584 (push-mark (point) t t
)
1585 (goto-char (point-max))
1586 (org-toggle-fixed-width)
1588 ;; Region: If it contains anything else, toggle on fixed-width but
1589 ;; not on fixed-width areas.
1591 (equal ": A\n: \n: B\n: \n: C"
1592 (org-test-with-temp-text "A\n\n: B\n\nC"
1593 (transient-mark-mode 1)
1594 (push-mark (point) t t
)
1595 (goto-char (point-max))
1596 (org-toggle-fixed-width)
1598 ;; Region: Ignore blank lines at its end, unless it contains only
1602 (org-test-with-temp-text "A\n\n"
1603 (transient-mark-mode 1)
1604 (push-mark (point) t t
)
1605 (goto-char (point-max))
1606 (org-toggle-fixed-width)
1610 (org-test-with-temp-text "\n\n"
1611 (transient-mark-mode 1)
1612 (push-mark (point) t t
)
1613 (goto-char (point-max))
1614 (org-toggle-fixed-width)
1621 (ert-deftest test-org
/get-heading
()
1622 "Test `org-get-heading' specifications."
1623 ;; Return current heading, even if point is not on it.
1626 (org-test-with-temp-text "* H"
1627 (org-get-heading))))
1630 (org-test-with-temp-text "* H\nText<point>"
1631 (org-get-heading))))
1632 ;; Without any optional argument, return TODO keyword, priority
1633 ;; cookie, COMMENT keyword and tags.
1636 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1637 (org-get-heading))))
1640 (org-test-with-temp-text "* [#A] H"
1641 (org-get-heading))))
1644 (org-test-with-temp-text "* COMMENT H"
1645 (org-get-heading))))
1648 (org-test-with-temp-text "* H :tag:"
1649 (org-get-heading))))
1650 ;; With NO-TAGS argument, ignore tags.
1653 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1654 (org-get-heading t
))))
1657 (org-test-with-temp-text "* H :tag:"
1658 (org-get-heading t
))))
1659 ;; With NO-TODO, ignore TODO keyword.
1662 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1663 (org-get-heading nil t
))))
1666 (org-test-with-temp-text "* H :tag:"
1667 (org-get-heading nil t
))))
1668 ;; TODO keywords are case-sensitive.
1671 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1672 (org-get-heading nil t
))))
1673 ;; With NO-PRIORITY, ignore priority.
1676 (org-test-with-temp-text "* [#A] H"
1677 (org-get-heading nil nil t
))))
1680 (org-test-with-temp-text "* H"
1681 (org-get-heading nil nil t
))))
1684 (org-test-with-temp-text "* TODO [#A] H"
1685 (org-get-heading nil nil t
))))
1686 ;; With NO-COMMENT, ignore COMMENT keyword.
1689 (org-test-with-temp-text "* COMMENT H"
1690 (org-get-heading nil nil nil t
))))
1693 (org-test-with-temp-text "* H"
1694 (org-get-heading nil nil nil t
))))
1696 (equal "TODO [#A] H"
1697 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1698 (org-get-heading nil nil nil t
))))
1699 ;; On an empty headline, return value is consistent.
1700 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1701 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1702 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1703 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1705 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1707 (ert-deftest test-org
/in-commented-heading-p
()
1708 "Test `org-in-commented-heading-p' specifications."
1709 ;; Commented headline.
1711 (org-test-with-temp-text "* COMMENT Headline\nBody"
1712 (goto-char (point-max))
1713 (org-in-commented-heading-p)))
1714 ;; Commented ancestor.
1716 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1717 (goto-char (point-max))
1718 (org-in-commented-heading-p)))
1719 ;; Comment keyword is case-sensitive.
1721 (org-test-with-temp-text "* Comment Headline\nBody"
1722 (goto-char (point-max))
1723 (org-in-commented-heading-p)))
1724 ;; Keyword is standalone.
1726 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1727 (goto-char (point-max))
1728 (org-in-commented-heading-p)))
1729 ;; Optional argument.
1731 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1732 (goto-char (point-max))
1733 (org-in-commented-heading-p t
))))
1735 (ert-deftest test-org
/entry-blocked-p
()
1736 ;; Check other dependencies.
1738 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1739 (let ((org-enforce-todo-dependencies t
)
1741 '(org-block-todo-from-children-or-siblings-or-parent)))
1742 (org-entry-blocked-p))))
1744 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1745 (let ((org-enforce-todo-dependencies t
)
1747 '(org-block-todo-from-children-or-siblings-or-parent)))
1748 (org-entry-blocked-p))))
1749 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1752 (org-test-with-temp-text "* Blocked\n** TODO one"
1753 (let ((org-enforce-todo-dependencies t
)
1755 '(org-block-todo-from-children-or-siblings-or-parent)))
1756 (org-entry-blocked-p))))
1758 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1759 (let ((org-enforce-todo-dependencies t
)
1761 '(org-block-todo-from-children-or-siblings-or-parent)))
1762 (org-entry-blocked-p))))
1763 ;; Follow :ORDERED: specifications.
1765 (org-test-with-temp-text
1766 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1767 (let ((org-enforce-todo-dependencies t
)
1769 '(org-block-todo-from-children-or-siblings-or-parent)))
1770 (org-entry-blocked-p))))
1772 (org-test-with-temp-text
1773 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1774 (let ((org-enforce-todo-dependencies t
)
1776 '(org-block-todo-from-children-or-siblings-or-parent)))
1777 (org-entry-blocked-p)))))
1779 (ert-deftest test-org
/get-outline-path
()
1780 "Test `org-get-outline-path' specifications."
1781 ;; Top-level headlines have no outline path.
1783 (org-test-with-temp-text "* H"
1784 (org-get-outline-path)))
1785 ;; Otherwise, outline path is the path leading to the headline.
1788 (org-test-with-temp-text "* H\n** S<point>"
1789 (org-get-outline-path))))
1790 ;; Find path even when point is not on a headline.
1793 (org-test-with-temp-text "* H\n** S\nText<point>"
1794 (org-get-outline-path))))
1795 ;; TODO keywords, tags and statistics cookies are ignored.
1798 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1799 (org-get-outline-path))))
1800 ;; Links are replaced with their description or their path.
1803 (org-test-with-temp-text
1804 "* [[http://orgmode.org][Org]]\n** S<point>"
1805 (org-get-outline-path))))
1807 (equal '("http://orgmode.org")
1808 (org-test-with-temp-text
1809 "* [[http://orgmode.org]]\n** S<point>"
1810 (org-get-outline-path))))
1811 ;; When WITH-SELF is non-nil, include current heading.
1814 (org-test-with-temp-text "* H"
1815 (org-get-outline-path t
))))
1818 (org-test-with-temp-text "* H\n** S\nText<point>"
1819 (org-get-outline-path t
))))
1820 ;; Using cache is transparent to the user.
1823 (org-test-with-temp-text "* H\n** S<point>"
1824 (setq org-outline-path-cache nil
)
1825 (org-get-outline-path nil t
))))
1826 ;; Do not corrupt cache when finding outline path in distant part of
1830 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1831 (setq org-outline-path-cache nil
)
1832 (org-get-outline-path nil t
)
1833 (search-forward "S2")
1834 (org-get-outline-path nil t
))))
1835 ;; Do not choke on empty headlines.
1837 (org-test-with-temp-text "* H\n** <point>"
1838 (org-get-outline-path)))
1840 (org-test-with-temp-text "* \n** H<point>"
1841 (org-get-outline-path))))
1843 (ert-deftest test-org
/format-outline-path
()
1844 "Test `org-format-outline-path' specifications."
1846 (string= (org-format-outline-path (list "one" "two" "three"))
1850 (string= (org-format-outline-path '())
1853 (string= (org-format-outline-path '(nil))
1855 ;; Empty path and prefix.
1857 (string= (org-format-outline-path '() nil
">>")
1859 ;; Trailing whitespace in headings.
1861 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1863 ;; Non-default prefix and separators.
1865 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1866 ">>|one|two|three"))
1869 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1871 ;; Give a very narrow width.
1873 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1875 ;; Give a prefix that extends beyond the width.
1877 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1881 (ert-deftest test-org
/map-entries
()
1882 "Test `org-map-entries' specifications."
1886 (org-test-with-temp-text "* Level 1\n** Level 2"
1887 (org-map-entries #'point
))))
1891 (org-test-with-temp-text "* Level 1\n** Level 2"
1892 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1895 (org-test-with-temp-text "* Level 1\n** Level 2"
1896 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1900 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1901 (org-map-entries #'point
"yes"))))
1904 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1905 (org-map-entries #'point
"+yes-a"))))
1908 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1909 (org-map-entries #'point
"{yes?}"))))
1913 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1914 (org-map-entries #'point
"PRIORITY=\"A\""))))
1918 (org-test-with-temp-text "
1920 SCHEDULED: <2012-03-29 thu.>
1922 SCHEDULED: <2014-03-04 tue.>"
1923 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1926 (org-test-with-temp-text "
1928 SCHEDULED: <2012-03-29 thu.>
1930 SCHEDULED: <2014-03-04 tue.>"
1931 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1932 ;; Regular property match.
1935 (org-test-with-temp-text "
1944 (org-map-entries #'point
"TEST=1"))))
1945 ;; Multiple criteria.
1948 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1949 (let (org-odd-levels-only
1950 (org-use-tag-inheritance nil
))
1951 (org-map-entries #'point
"yes+LEVEL=1")))))
1955 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1956 (let (org-odd-levels-only)
1957 (org-map-entries #'point
"LEVEL=2|no")))))
1960 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1961 (let (org-odd-levels-only)
1962 (org-map-entries #'point
"yes|no")))))
1966 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1967 (let (org-odd-levels-only)
1968 (org-map-entries #'point
"yes&no"))))))
1970 (ert-deftest test-org
/edit-headline
()
1971 "Test `org-edit-headline' specifications."
1974 (org-test-with-temp-text "* A"
1975 (org-edit-headline "B")
1977 ;; Handle empty headings.
1980 (org-test-with-temp-text "* A"
1981 (org-edit-headline "")
1985 (org-test-with-temp-text "* "
1986 (org-edit-headline "A")
1988 ;; Handle TODO keywords and priority cookies.
1991 (org-test-with-temp-text "* TODO A"
1992 (org-edit-headline "B")
1996 (org-test-with-temp-text "* [#A] A"
1997 (org-edit-headline "B")
2000 (equal "* TODO [#A] B"
2001 (org-test-with-temp-text "* TODO [#A] A"
2002 (org-edit-headline "B")
2006 (org-test-with-temp-text "* A :tag:"
2007 (let ((org-tags-column 4)) (org-edit-headline "B"))
2014 (ert-deftest test-org
/set-regexps-and-options
()
2015 "Test `org-set-regexps-and-options' specifications."
2019 (let ((org-tag-alist '(("A")))
2020 (org-tag-persistent-alist nil
))
2021 (org-test-with-temp-text ""
2023 org-current-tag-alist
))))
2026 (let ((org-tag-alist '(("A")))
2027 (org-tag-persistent-alist nil
))
2028 (org-test-with-temp-text "#+TAGS: B"
2030 org-current-tag-alist
))))
2032 (equal '(("C") ("B"))
2033 (let ((org-tag-alist '(("A")))
2034 (org-tag-persistent-alist '(("C"))))
2035 (org-test-with-temp-text "#+TAGS: B"
2037 org-current-tag-alist
))))
2040 (let ((org-tag-alist '(("A")))
2041 (org-tag-persistent-alist '(("C"))))
2042 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2044 org-current-tag-alist
))))
2046 (equal '(("A" . ?a
) ("B") ("C"))
2047 (let ((org-tag-persistant-alist nil
))
2048 (org-test-with-temp-text "#+TAGS: A(a) B C"
2050 org-current-tag-alist
))))
2052 (equal '(("A") (:newline
) ("B"))
2053 (let ((org-tag-persistent-alist nil
))
2054 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2056 org-current-tag-alist
))))
2058 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2059 (let ((org-tag-persistent-alist nil
))
2060 (org-test-with-temp-text "#+TAGS: { A B } C"
2062 org-current-tag-alist
))))
2064 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2065 (let ((org-tag-persistent-alist nil
))
2066 (org-test-with-temp-text "#+TAGS: { A : B C }"
2068 org-current-tag-alist
))))
2070 (equal '(("A" "B" "C"))
2071 (let ((org-tag-persistent-alist nil
))
2072 (org-test-with-temp-text "#+TAGS: { A : B C }"
2074 org-tag-groups-alist
))))
2076 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2077 (let ((org-tag-persistent-alist nil
))
2078 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2080 org-current-tag-alist
))))
2082 (equal '(("A" "B" "C"))
2083 (let ((org-tag-persistent-alist nil
))
2084 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2086 org-tag-groups-alist
))))
2087 ;; FILETAGS keyword.
2089 (equal '("A" "B" "C")
2090 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2093 ;; PROPERTY keyword. Property names are case-insensitive.
2096 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2098 (cdr (assoc "var" org-file-properties
)))))
2102 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2104 (cdr (assoc "var" org-file-properties
)))))
2108 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2110 (cdr (assoc "var" org-file-properties
)))))
2114 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2116 org-archive-location
)))
2117 ;; CATEGORY keyword.
2120 (org-test-with-temp-text "#+CATEGORY: test"
2125 (org-test-with-temp-text "#+CATEGORY: test"
2127 (cdr (assoc "CATEGORY" org-file-properties
)))))
2130 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2131 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2133 org-columns-default-format
)))
2134 ;; CONSTANTS keyword. Constants names are case sensitive.
2136 (equal '("299792458." "3.14")
2137 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2140 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2144 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2146 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2149 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2151 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2156 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2158 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2160 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2164 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2166 (list org-highest-priority org-lowest-priority org-default-priority
))))
2170 (org-test-with-temp-text "#+PRIORITIES: X Z"
2172 (list org-highest-priority org-lowest-priority org-default-priority
))))
2176 (org-test-with-temp-text "#+STARTUP: fold odd"
2178 (list org-startup-folded org-odd-levels-only
))))
2181 (equal '(("A" "B") ("C"))
2182 (org-test-with-temp-text "#+TODO: A B | C"
2184 (list org-not-done-keywords org-done-keywords
))))
2186 (equal '(("A" "C") ("B" "D"))
2187 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2189 (list org-not-done-keywords org-done-keywords
))))
2191 (equal '(("A" "B") ("C"))
2192 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2194 (list org-not-done-keywords org-done-keywords
))))
2196 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2197 (org-test-with-temp-text "#+TODO: A(a)"
2199 org-todo-key-alist
)))
2201 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2202 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2204 org-todo-log-states
)))
2205 ;; Enter SETUPFILE keyword.
2208 (org-test-with-temp-text
2209 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2211 (cdr (assoc "a" org-file-properties
))))))
2219 (ert-deftest test-org
/coderef
()
2220 "Test coderef links specifications."
2222 (org-test-with-temp-text "
2223 #+BEGIN_SRC emacs-lisp
2228 (looking-at "(ref:sc)")))
2229 ;; Find coderef even with alternate label format.
2231 (org-test-with-temp-text "
2232 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2237 (looking-at "{ref:sc}"))))
2241 (ert-deftest test-org
/custom-id
()
2242 "Test custom ID links specifications."
2244 (org-test-with-temp-text
2245 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2247 (looking-at-p "\\* H1")))
2248 ;; Throw an error on false positives.
2250 (org-test-with-temp-text
2251 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2253 (looking-at-p "\\* H1"))))
2257 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2258 ;; a named element (#+name: text) and to headlines (* Text).
2260 (ert-deftest test-org
/fuzzy-links
()
2261 "Test fuzzy links specifications."
2262 ;; Fuzzy link goes in priority to a matching target.
2264 (org-test-with-temp-text
2265 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2266 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2267 (looking-at "<<Test>>")))
2268 ;; Then fuzzy link points to an element with a given name.
2270 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2271 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2272 (looking-at "#\\+NAME: Test")))
2273 ;; A target still lead to a matching headline otherwise.
2275 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2276 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2277 (looking-at "\\* Head2")))
2278 ;; With a leading star in link, enforce heading match.
2280 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2281 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2282 (looking-at "\\* Test")))
2283 ;; With a leading star in link, enforce exact heading match, even
2284 ;; with `org-link-search-must-match-exact-headline' set to nil.
2286 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2287 (let ((org-link-search-must-match-exact-headline nil
))
2288 (org-open-at-point))))
2289 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2291 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2292 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2293 (looking-at "\\* Test")))
2295 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2296 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2297 (looking-at "\\* Test")))
2298 ;; Heading match should not care about spaces, cookies, TODO
2299 ;; keywords, priorities, and tags. However, TODO keywords are
2303 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2304 (org-test-with-temp-text
2305 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2306 (let ((org-link-search-must-match-exact-headline nil
)
2307 (org-todo-regexp "TODO"))
2308 (org-open-at-point))
2309 (looking-at (regexp-quote first-line
)))))
2311 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2312 (let ((org-link-search-must-match-exact-headline nil
)
2313 (org-todo-regexp "TODO"))
2314 (org-open-at-point))))
2315 ;; Heading match should still be exact.
2317 (org-test-with-temp-text "
2318 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2321 (let ((org-link-search-must-match-exact-headline nil
)
2322 (org-todo-regexp "TODO"))
2323 (org-open-at-point))))
2325 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2326 (let ((org-link-search-must-match-exact-headline nil
)
2327 (org-todo-regexp "TODO"))
2328 (org-open-at-point))
2329 (looking-at-p (regexp-quote "** Test 1 2"))))
2330 ;; Heading match ignores COMMENT keyword.
2332 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2334 (looking-at "\\* COMMENT Test")))
2336 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2338 (looking-at "\\* TODO COMMENT Test")))
2339 ;; Correctly un-hexify fuzzy links.
2341 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2345 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2348 ;; Match search strings containing newline characters, including
2351 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2352 (let ((file (buffer-file-name)))
2353 (goto-char (point-max))
2354 (insert (format "[[file:%s::line1 line2]]" file
))
2356 (let ((org-link-search-must-match-exact-headline nil
))
2357 (org-open-at-point 0))
2358 (looking-at-p "line1"))))
2360 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2361 (let ((file (buffer-file-name)))
2362 (goto-char (point-max))
2363 (insert (format "[[file:%s::line1 line2]]" file
))
2365 (let ((org-link-search-must-match-exact-headline nil
))
2366 (org-open-at-point 0))
2367 (looking-at-p "line1")))))
2371 (ert-deftest test-org
/org-link-escape-ascii-character
()
2372 "Escape an ascii character."
2376 (org-link-escape "["))))
2378 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2379 "Escape an ascii control character."
2383 (org-link-escape "\t"))))
2385 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2386 "Escape an unicode multibyte character."
2390 (org-link-escape "€"))))
2392 (ert-deftest test-org
/org-link-escape-custom-table
()
2393 "Escape string with custom character table."
2397 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2399 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2400 "Escape string with custom table merged with default table."
2403 "%5BF%6F%6F%3A%42ar%0A%5D"
2404 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2406 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2407 "Unescape an ascii character."
2411 (org-link-unescape "%5B"))))
2413 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2414 "Unescpae an ascii control character."
2418 (org-link-unescape "%0A"))))
2420 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2421 "Unescape unicode multibyte character."
2425 (org-link-unescape "%E2%82%AC"))))
2427 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2428 "Unescape old style percent escaped character."
2431 "à âçèéêîôùû"
2432 (decode-coding-string
2433 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2435 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2436 "Escape and unescape a URL that includes an escaped char.
2437 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2440 "http://some.host.com/form?&id=blah%2Bblah25"
2442 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2446 (ert-deftest test-org
/open-at-point
/keyword
()
2447 "Does `org-open-at-point' open link in a keyword line?"
2449 (org-test-with-temp-text
2450 "<<top>>\n#+KEYWORD: <point>[[top]]"
2451 (org-open-at-point) t
))
2453 (org-test-with-temp-text
2454 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2455 (org-open-at-point) t
)))
2457 (ert-deftest test-org
/open-at-point
/property
()
2458 "Does `org-open-at-point' open link in property drawer?"
2460 (org-test-with-temp-text
2463 :URL: <point>[[*Headline]]
2465 (org-open-at-point) t
)))
2467 (ert-deftest test-org
/open-at-point
/comment
()
2468 "Does `org-open-at-point' open link in a commented line?"
2470 (org-test-with-temp-text
2471 "<<top>>\n# <point>[[top]]"
2472 (org-open-at-point) t
))
2474 (org-test-with-temp-text
2475 "* H\n<<top>>\n# <point>[[top]]"
2476 (org-open-at-point) t
)))
2478 (ert-deftest test-org
/open-at-point
/inline-image
()
2479 "Test `org-open-at-point' on nested links."
2481 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2485 (ert-deftest test-org
/open-at-point
/radio-target
()
2486 "Test `org-open-at-point' on radio targets."
2488 (org-test-with-temp-text "<<<target>>> <point>target"
2489 (org-update-radio-target-regexp)
2491 (eq (org-element-type (org-element-context)) 'radio-target
))))
2493 (ert-deftest test-org
/open-at-point
/tag
()
2494 "Test `org-open-at-point' on tags."
2496 (org-test-with-temp-text "* H :<point>tag:"
2498 (cl-letf (((symbol-function 'org-tags-view
)
2499 (lambda (&rest args
) (throw :result t
))))
2503 (org-test-with-temp-text-in-file "* H<point> :tag:"
2505 (cl-letf (((symbol-function 'org-tags-view
)
2506 (lambda (&rest args
) (throw :result t
))))
2512 (ert-deftest test-org
/store-link
()
2513 "Test `org-store-link' specifications."
2514 ;; On a headline, link to that headline. Use heading as the
2515 ;; description of the link.
2517 (let (org-store-link-props org-stored-links
)
2518 (org-test-with-temp-text-in-file "* H1"
2519 (let ((file (buffer-file-name)))
2520 (equal (format "[[file:%s::*H1][H1]]" file
)
2521 (org-store-link nil
))))))
2522 ;; On a headline, remove any link from description.
2524 (let (org-store-link-props org-stored-links
)
2525 (org-test-with-temp-text-in-file "* [[#l][d]]"
2526 (let ((file (buffer-file-name)))
2527 (equal (format "[[file:%s::*%s][d]]"
2529 (org-link-escape "[[#l][d]]"))
2530 (org-store-link nil
))))))
2532 (let (org-store-link-props org-stored-links
)
2533 (org-test-with-temp-text-in-file "* [[l]]"
2534 (let ((file (buffer-file-name)))
2535 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2536 (org-store-link nil
))))))
2538 (let (org-store-link-props org-stored-links
)
2539 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2540 (let ((file (buffer-file-name)))
2541 (equal (format "[[file:%s::*%s][d1 d2]]"
2543 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2544 (org-store-link nil
))))))
2545 ;; On a named element, link to that element.
2547 (let (org-store-link-props org-stored-links
)
2548 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2549 (let ((file (buffer-file-name)))
2550 (equal (format "[[file:%s::foo][foo]]" file
)
2551 (org-store-link nil
))))))
2552 ;; Store link to Org buffer, with context.
2554 (let ((org-stored-links nil
)
2555 (org-id-link-to-org-use-id nil
)
2556 (org-context-in-file-links t
))
2557 (org-test-with-temp-text-in-file "* h1"
2558 (let ((file (buffer-file-name)))
2559 (equal (format "[[file:%s::*h1][h1]]" file
)
2560 (org-store-link nil
))))))
2561 ;; Store link to Org buffer, without context.
2563 (let ((org-stored-links nil
)
2564 (org-id-link-to-org-use-id nil
)
2565 (org-context-in-file-links nil
))
2566 (org-test-with-temp-text-in-file "* h1"
2567 (let ((file (buffer-file-name)))
2568 (equal (format "[[file:%s][file:%s]]" file file
)
2569 (org-store-link nil
))))))
2570 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2572 (let ((org-stored-links nil
)
2573 (org-id-link-to-org-use-id nil
)
2574 (org-context-in-file-links nil
))
2575 (org-test-with-temp-text-in-file "* h1"
2576 (let ((file (buffer-file-name)))
2577 (equal (format "[[file:%s::*h1][h1]]" file
)
2578 (org-store-link '(4)))))))
2579 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2582 (let ((org-stored-links nil
)
2583 (org-id-link-to-org-use-id nil
)
2584 (org-context-in-file-links nil
))
2585 (org-test-with-temp-text-in-file "* h1"
2586 (let ((file (buffer-file-name)))
2587 (equal (format "[[file:%s][file:%s]]" file file
)
2588 (org-store-link '(16)))))))
2589 ;; Store file link to non-Org buffer, with context.
2591 (let ((org-stored-links nil
)
2592 (org-context-in-file-links t
))
2593 (org-test-with-temp-text-in-file "one\n<point>two"
2595 (let ((file (buffer-file-name)))
2596 (equal (format "[[file:%s::one]]" file
)
2597 (org-store-link nil
))))))
2598 ;; Store file link to non-Org buffer, without context.
2600 (let ((org-stored-links nil
)
2601 (org-context-in-file-links nil
))
2602 (org-test-with-temp-text-in-file "one\n<point>two"
2604 (let ((file (buffer-file-name)))
2605 (equal (format "[[file:%s][file:%s]]" file file
)
2606 (org-store-link nil
))))))
2607 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2610 (let ((org-stored-links nil
)
2611 (org-context-in-file-links nil
))
2612 (org-test-with-temp-text-in-file "one\n<point>two"
2614 (let ((file (buffer-file-name)))
2615 (equal (format "[[file:%s::one]]" file
)
2616 (org-store-link '(4)))))))
2617 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2620 (let ((org-stored-links nil
)
2621 (org-context-in-file-links nil
))
2622 (org-test-with-temp-text-in-file "one\n<point>two"
2624 (let ((file (buffer-file-name)))
2625 (equal (format "[[file:%s][file:%s]]" file file
)
2626 (org-store-link '(16))))))))
2631 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2632 "Ensure properties accumulate in subtree drawers."
2633 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2634 (org-babel-next-src-block)
2635 (should (equal '(2 1) (org-babel-execute-src-block)))))
2637 (ert-deftest test-org
/custom-properties
()
2638 "Test custom properties specifications."
2641 (let ((org-custom-properties '("FOO")))
2642 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2643 (org-toggle-custom-properties-visibility)
2644 (org-invisible-p2))))
2645 ;; Properties are case-insensitive.
2647 (let ((org-custom-properties '("FOO")))
2648 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2649 (org-toggle-custom-properties-visibility)
2650 (org-invisible-p2))))
2652 (let ((org-custom-properties '("foo")))
2653 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2654 (org-toggle-custom-properties-visibility)
2655 (org-invisible-p2))))
2656 ;; Multiple custom properties in the same drawer.
2658 (let ((org-custom-properties '("FOO" "BAR")))
2659 (org-test-with-temp-text
2660 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2661 (org-toggle-custom-properties-visibility)
2662 (and (org-invisible-p2)
2663 (not (progn (forward-line) (org-invisible-p2)))
2664 (progn (forward-line) (org-invisible-p2))))))
2665 ;; Hide custom properties with an empty value.
2667 (let ((org-custom-properties '("FOO")))
2668 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2669 (org-toggle-custom-properties-visibility)
2670 (org-invisible-p2))))
2671 ;; Do not hide fake properties.
2673 (let ((org-custom-properties '("FOO")))
2674 (org-test-with-temp-text ":FOO: val\n"
2675 (org-toggle-custom-properties-visibility)
2676 (org-invisible-p2))))
2678 (let ((org-custom-properties '("A")))
2679 (org-test-with-temp-text
2680 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2681 (org-toggle-custom-properties-visibility)
2682 (org-invisible-p2)))))
2688 (ert-deftest test-org
/mark-subtree
()
2689 "Test `org-mark-subtree' specifications."
2690 ;; Error when point is before first headline.
2692 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2693 (progn (transient-mark-mode 1)
2694 (org-mark-subtree))))
2695 ;; Without argument, mark current subtree.
2699 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2700 (progn (transient-mark-mode 1)
2703 (list (region-beginning) (region-end))))))
2704 ;; With an argument, move ARG up.
2708 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2709 (progn (transient-mark-mode 1)
2711 (org-mark-subtree 1)
2712 (list (region-beginning) (region-end))))))
2713 ;; Do not get fooled by inlinetasks.
2714 (when (featurep 'org-inlinetask
)
2717 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2718 (progn (transient-mark-mode 1)
2720 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2721 (region-beginning)))))))
2727 (ert-deftest test-org
/sort-entries
()
2728 "Test `org-sort-entries'."
2729 ;; Sort alphabetically.
2731 (equal "\n* abc\n* def\n* xyz\n"
2732 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2733 (org-sort-entries nil ?a
)
2736 (equal "\n* xyz\n* def\n* abc\n"
2737 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2738 (org-sort-entries nil ?A
)
2740 ;; Sort numerically.
2742 (equal "\n* 1\n* 2\n* 10\n"
2743 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2744 (org-sort-entries nil ?n
)
2747 (equal "\n* 10\n* 2\n* 1\n"
2748 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2749 (org-sort-entries nil ?N
)
2751 ;; Sort by custom function.
2753 (equal "\n* b\n* aa\n* ccc\n"
2754 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2755 (org-sort-entries nil ?f
2757 (length (buffer-substring (point-at-bol)
2762 (equal "\n* ccc\n* aa\n* b\n"
2763 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2764 (org-sort-entries nil ?F
2766 (length (buffer-substring (point-at-bol)
2770 ;; Sort by TODO keyword.
2772 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2773 (org-test-with-temp-text
2774 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2775 (org-sort-entries nil ?o
)
2778 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2779 (org-test-with-temp-text
2780 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2781 (org-sort-entries nil ?O
)
2783 ;; Sort by priority.
2785 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2786 (org-test-with-temp-text
2787 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2788 (org-sort-entries nil ?p
)
2791 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2792 (org-test-with-temp-text
2793 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2794 (org-sort-entries nil ?P
)
2796 ;; Sort by creation time.
2806 (org-test-with-temp-text
2815 (org-sort-entries nil ?c
)
2818 ;; Sort by scheduled date.
2822 SCHEDULED: <2017-05-06 Sat>
2824 SCHEDULED: <2017-05-08 Mon>
2826 DEADLINE: <2017-05-09 Tue>
2828 DEADLINE: <2017-05-07 Sun>
2830 (org-test-with-temp-text
2833 DEADLINE: <2017-05-09 Tue>
2835 DEADLINE: <2017-05-07 Sun>
2837 SCHEDULED: <2017-05-08 Mon>
2839 SCHEDULED: <2017-05-06 Sat>
2841 (org-sort-entries nil ?s
)
2843 ;; Sort by deadline date.
2847 DEADLINE: <2017-05-07 Sun>
2849 DEADLINE: <2017-05-09 Tue>
2851 SCHEDULED: <2017-05-08 Mon>
2853 SCHEDULED: <2017-05-06 Sat>
2855 (org-test-with-temp-text
2858 DEADLINE: <2017-05-09 Tue>
2860 DEADLINE: <2017-05-07 Sun>
2862 SCHEDULED: <2017-05-08 Mon>
2864 SCHEDULED: <2017-05-06 Sat>
2866 (org-sort-entries nil ?d
)
2868 ;; Sort by any date/time
2872 SCHEDULED: <2017-05-06 Sat>
2874 DEADLINE: <2017-05-07 Sun>
2876 SCHEDULED: <2017-05-08 Mon>
2878 DEADLINE: <2017-05-09 Tue>
2880 (org-test-with-temp-text
2883 DEADLINE: <2017-05-09 Tue>
2885 DEADLINE: <2017-05-07 Sun>
2887 SCHEDULED: <2017-05-08 Mon>
2889 SCHEDULED: <2017-05-06 Sat>
2891 (org-sort-entries nil ?t
)
2893 ;; Sort by clocking time.
2898 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2899 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2903 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2904 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2907 (org-test-with-temp-text
2911 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2912 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
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
2920 (org-sort-entries nil ?k
)
2922 ;; Preserve file local variables when sorting.
2924 (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
2925 (org-test-with-temp-text
2926 "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
2927 (org-sort-entries nil ?a
)
2930 (ert-deftest test-org
/file-contents
()
2931 "Test `org-file-contents' specifications."
2934 (string= "#+BIND: variable value
2940 " (org-file-contents (expand-file-name "setupfile3.org"
2941 (concat org-test-dir
"examples/")))))
2942 ;; Throw error when trying to access an invalid file.
2943 (should-error (org-file-contents "this-file-must-not-exist"))
2944 ;; Try to access an invalid file, but do not throw an error.
2946 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2950 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2952 ;; Simulate successful retrieval of a URL.
2953 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2955 (with-current-buffer buffer
2956 (insert "HTTP/1.1 200 OK\n\nfoo"))
2958 (org-file-contents "http://some-valid-url"))
2959 (kill-buffer buffer
)))))
2960 ;; Throw error when trying to access an invalid URL.
2962 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2964 ;; Simulate unsuccessful retrieval of a URL.
2965 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2967 (with-current-buffer buffer
2968 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2970 (org-file-contents "http://this-url-must-not-exist"))
2971 (kill-buffer buffer
))))
2972 ;; Try to access an invalid URL, but do not throw an error.
2974 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2976 ;; Simulate unsuccessful retrieval of a URL.
2977 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2979 (with-current-buffer buffer
2980 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2982 (org-file-contents "http://this-url-must-not-exist"))
2983 (kill-buffer buffer
))))
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" :noerror
))
2994 (kill-buffer buffer
))
3000 (ert-deftest test-org
/forward-heading-same-level
()
3001 "Test `org-forward-heading-same-level' specifications."
3002 ;; Test navigation at top level, forward and backward.
3005 (org-test-with-temp-text "* H1\n* H2"
3006 (org-forward-heading-same-level 1)
3007 (buffer-substring-no-properties (point) (line-end-position)))))
3010 (org-test-with-temp-text "* H1\n<point>* H2"
3011 (org-forward-heading-same-level -
1)
3012 (buffer-substring-no-properties (point) (line-end-position)))))
3013 ;; Test navigation in a sub-tree, forward and backward.
3016 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
3017 (org-forward-heading-same-level 1)
3018 (buffer-substring-no-properties (point) (line-end-position)))))
3021 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3022 (org-forward-heading-same-level -
1)
3023 (buffer-substring-no-properties (point) (line-end-position)))))
3024 ;; Stop at first or last sub-heading.
3027 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3028 (org-forward-heading-same-level 1)
3029 (buffer-substring-no-properties (point) (line-end-position)))))
3032 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3033 (org-forward-heading-same-level -
1)
3034 (buffer-substring-no-properties (point) (line-end-position)))))
3035 ;; Allow multiple moves.
3038 (org-test-with-temp-text "* H1\n* H2\n* H3"
3039 (org-forward-heading-same-level 2)
3040 (buffer-substring-no-properties (point) (line-end-position)))))
3043 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3044 (org-forward-heading-same-level -
2)
3045 (buffer-substring-no-properties (point) (line-end-position)))))
3046 ;; Ignore spurious moves when first (or last) sibling is reached.
3049 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3050 (org-forward-heading-same-level 100)
3051 (buffer-substring-no-properties (point) (line-end-position)))))
3054 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3055 (org-forward-heading-same-level -
100)
3056 (buffer-substring-no-properties (point) (line-end-position))))))
3058 (ert-deftest test-org
/end-of-meta-data
()
3059 "Test `org-end-of-meta-data' specifications."
3060 ;; Skip planning line.
3062 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3063 (org-end-of-meta-data)
3065 ;; Skip properties drawer.
3067 (org-test-with-temp-text
3068 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3069 (org-end-of-meta-data)
3073 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3074 (org-end-of-meta-data)
3076 ;; Nothing to skip, go to first line.
3078 (org-test-with-temp-text "* Headline\nContents"
3079 (org-end-of-meta-data)
3080 (looking-at "Contents")))
3081 ;; With option argument, skip empty lines, regular drawers and
3084 (org-test-with-temp-text "* Headline\n\nContents"
3085 (org-end-of-meta-data t
)
3086 (looking-at "Contents")))
3088 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3089 (org-end-of-meta-data t
)
3090 (looking-at "Contents")))
3092 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3093 (org-end-of-meta-data t
)
3094 (looking-at "Contents")))
3095 ;; Special case: do not skip incomplete drawers.
3097 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3098 (org-end-of-meta-data t
)
3099 (looking-at ":LOGBOOK:")))
3100 ;; Special case: Be careful about consecutive headlines.
3102 (org-test-with-temp-text "* H1\n*H2\nContents"
3103 (org-end-of-meta-data t
)
3104 (looking-at "Contents"))))
3106 (ert-deftest test-org
/beginning-of-line
()
3107 "Test `org-beginning-of-line' specifications."
3108 ;; Move to beginning of line. If current line in invisible, move to
3109 ;; beginning of visible line instead.
3111 (org-test-with-temp-text "Some text\nSome other text<point>"
3112 (org-beginning-of-line)
3115 (org-test-with-temp-text "* H1\n** H2<point>"
3117 (org-beginning-of-line)
3118 (= (line-beginning-position) 1)))
3119 ;; With `visual-line-mode' active, move to beginning of visual line.
3121 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3123 (dotimes (i 1000) (insert "very "))
3124 (org-beginning-of-line)
3126 ;; In a wide headline, with `visual-line-mode', prefer going to the
3127 ;; beginning of a visual line than to the logical beginning of line,
3128 ;; even if special movement is active.
3130 (org-test-with-temp-text "* A <point>long headline"
3132 (dotimes (i 1000) (insert "very "))
3133 (goto-char (point-max))
3134 (org-beginning-of-line)
3137 (org-test-with-temp-text "* A <point>long headline"
3139 (dotimes (i 1000) (insert "very "))
3140 (goto-char (point-max))
3141 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3143 ;; At an headline with special movement, first move at beginning of
3144 ;; title, then at the beginning of line, rinse, repeat.
3146 (org-test-with-temp-text "* TODO Headline<point>"
3147 (let ((org-special-ctrl-a/e t
))
3148 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3149 (progn (org-beginning-of-line) (bolp))
3150 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3152 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3153 (let ((org-special-ctrl-a/e t
))
3154 (org-beginning-of-line)
3155 (looking-at "Headline"))))
3157 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3158 (let ((org-special-ctrl-a/e
'(t . nil
)))
3159 (org-beginning-of-line)
3160 (looking-at "Headline"))))
3162 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3163 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3164 (org-beginning-of-line)
3165 (looking-at "Headline"))))
3166 ;; At an headline with reversed movement, first move to beginning of
3167 ;; line, then to the beginning of title.
3169 (org-test-with-temp-text "* TODO Headline<point>"
3170 (let ((org-special-ctrl-a/e
'reversed
)
3171 (this-command last-command
))
3172 (and (progn (org-beginning-of-line) (bolp))
3173 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3175 (org-test-with-temp-text "* TODO Headline<point>"
3176 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3177 (this-command last-command
))
3178 (and (progn (org-beginning-of-line) (bolp))
3179 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3181 (org-test-with-temp-text "* TODO Headline<point>"
3182 (let ((org-special-ctrl-a/e
'(t . nil
))
3183 (this-command last-command
))
3184 (and (progn (org-beginning-of-line) (bolp))
3185 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3186 ;; At an item with special movement, first move after to beginning
3187 ;; of title, then to the beginning of line, rinse, repeat.
3189 (org-test-with-temp-text "- [ ] Item<point>"
3190 (let ((org-special-ctrl-a/e t
))
3191 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3192 (progn (org-beginning-of-line) (bolp))
3193 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3194 ;; At an item with reversed movement, first move to beginning of
3195 ;; line, then to the beginning of title.
3197 (org-test-with-temp-text "- [X] Item<point>"
3198 (let ((org-special-ctrl-a/e
'reversed
)
3199 (this-command last-command
))
3200 (and (progn (org-beginning-of-line) (bolp))
3201 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3202 ;; Leave point before invisible characters at column 0.
3204 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3205 (let ((org-special-ctrl-a/e nil
))
3206 (org-beginning-of-line)
3209 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3210 (let ((org-special-ctrl-a/e t
))
3211 (org-beginning-of-line)
3214 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3216 (org-beginning-of-line)
3218 ;; Special case: Do not error when the buffer contains only a single
3221 (org-test-with-temp-text "*<point>"
3222 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3224 (org-test-with-temp-text "*<point>"
3225 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3227 (ert-deftest test-org
/end-of-line
()
3228 "Test `org-end-of-line' specifications."
3231 (org-test-with-temp-text "Some text\nSome other text"
3234 ;; With `visual-line-mode' active, move to end of visible line.
3235 ;; However, never go past ellipsis.
3237 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3239 (dotimes (i 1000) (insert "very "))
3240 (goto-char (point-min))
3244 (org-test-with-temp-text "* A short headline\nSome contents"
3249 ;; In a wide headline, with `visual-line-mode', prefer going to end
3250 ;; of visible line if tags, or end of line, are farther.
3252 (org-test-with-temp-text "* A <point>long headline"
3254 (dotimes (i 1000) (insert "very "))
3255 (goto-char (point-min))
3259 (org-test-with-temp-text "* A <point>long headline :tag:"
3261 (dotimes (i 1000) (insert "very "))
3262 (goto-char (point-min))
3265 ;; At an headline without special movement, go to end of line.
3266 ;; However, never go past ellipsis.
3268 (org-test-with-temp-text "* Headline2b :tag:\n"
3269 (let ((org-special-ctrl-a/e nil
))
3270 (and (progn (org-end-of-line) (eolp))
3271 (progn (org-end-of-line) (eolp))))))
3273 (org-test-with-temp-text "* Headline2b :tag:\n"
3274 (let ((org-special-ctrl-a/e
'(t . nil
)))
3275 (and (progn (org-end-of-line) (eolp))
3276 (progn (org-end-of-line) (eolp))))))
3278 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3280 (let ((org-special-ctrl-a/e nil
))
3282 (= 1 (line-beginning-position)))))
3283 ;; At an headline with special movement, first move before tags,
3284 ;; then at the end of line, rinse, repeat. However, never go past
3287 (org-test-with-temp-text "* Headline1 :tag:\n"
3288 (let ((org-special-ctrl-a/e t
))
3289 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3290 (progn (org-end-of-line) (eolp))
3291 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3293 (org-test-with-temp-text "* Headline1 :tag:\n"
3294 (let ((org-special-ctrl-a/e
'(nil . t
)))
3295 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3296 (progn (org-end-of-line) (eolp))
3297 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3299 (org-test-with-temp-text "* Headline1 :tag:\n"
3300 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3301 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3302 (progn (org-end-of-line) (eolp))
3303 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3305 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3307 (let ((org-special-ctrl-a/e t
))
3310 (= 1 (line-beginning-position)))))
3311 ;; At an headline, with reversed movement, first go to end of line,
3312 ;; then before tags. However, never go past ellipsis.
3314 (org-test-with-temp-text "* Headline3 :tag:\n"
3315 (let ((org-special-ctrl-a/e
'reversed
)
3316 (this-command last-command
))
3317 (and (progn (org-end-of-line) (eolp))
3318 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3320 (org-test-with-temp-text "* Headline3 :tag:\n"
3321 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3322 (this-command last-command
))
3323 (and (progn (org-end-of-line) (eolp))
3324 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3326 (org-test-with-temp-text "* Headline3 :tag:\n"
3327 (let ((org-special-ctrl-a/e
'(nil . t
))
3328 (this-command last-command
))
3329 (and (progn (org-end-of-line) (eolp))
3330 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3332 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3334 (let ((org-special-ctrl-a/e
'reversed
))
3336 (= 1 (line-beginning-position)))))
3337 ;; At a block without hidden contents.
3339 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3340 (progn (org-end-of-line) (eolp))))
3341 ;; At a block with hidden contents.
3343 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3344 (let ((org-special-ctrl-a/e t
))
3345 (org-hide-block-toggle)
3348 ;; Get past invisible characters at the end of line.
3350 (org-test-with-temp-text "[[http://orgmode.org]]"
3354 (ert-deftest test-org
/open-line
()
3355 "Test `org-open-line' specifications."
3356 ;; Call `open-line' outside of tables.
3359 (org-test-with-temp-text "Text"
3362 ;; At a table, create a row above.
3364 (equal "\n| |\n| a |"
3365 (org-test-with-temp-text "\n<point>| a |"
3368 ;; At the very first character of the buffer, also call `open-line'.
3371 (org-test-with-temp-text "| a |"
3374 ;; Narrowing does not count.
3376 (equal "Text\n| |\n| a |"
3377 (org-test-with-temp-text "Text\n<point>| a |"
3378 (narrow-to-region (point) (point-max))
3383 (ert-deftest test-org
/forward-sentence
()
3384 "Test `org-forward-sentence' specifications."
3385 ;; At the end of a table cell, move to the end of the next one.
3387 (org-test-with-temp-text "| a<point> | b |"
3388 (org-forward-sentence)
3389 (looking-at " |$")))
3390 ;; Elsewhere in a cell, move to its end.
3392 (org-test-with-temp-text "| a<point>c | b |"
3393 (org-forward-sentence)
3394 (looking-at " | b |$")))
3395 ;; Otherwise, simply call `forward-sentence'.
3397 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3398 (org-forward-sentence)
3399 (looking-at " Sentence 2.")))
3401 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3402 (org-forward-sentence)
3403 (org-forward-sentence)
3405 ;; At the end of an element, jump to the next one, without stopping
3406 ;; on blank lines in-between.
3408 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3409 (org-forward-sentence)
3411 ;; Headlines are considered to be sentences by themselves, even if
3412 ;; they do not end with a full stop.
3416 (org-test-with-temp-text "* <point>Headline\nSentence."
3417 (org-forward-sentence)
3418 (buffer-substring-no-properties (line-beginning-position) (point)))))
3420 (org-test-with-temp-text "* Headline<point>\nSentence."
3421 (org-forward-sentence)
3424 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3425 (org-forward-sentence)
3426 (and (org-at-heading-p) (eolp)))))
3428 (ert-deftest test-org
/backward-sentence
()
3429 "Test `org-backward-sentence' specifications."
3430 ;; At the beginning of a table cell, move to the beginning of the
3433 (org-test-with-temp-text "| a | <point>b |"
3434 (org-backward-sentence)
3435 (looking-at "a | b |$")))
3436 ;; Elsewhere in a cell, move to its beginning.
3438 (org-test-with-temp-text "| a | b<point>c |"
3439 (org-backward-sentence)
3440 (looking-at "bc |$")))
3441 ;; Otherwise, simply call `backward-sentence'.
3443 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3444 (org-backward-sentence)
3445 (looking-at "Sentence 2.")))
3447 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3448 (org-backward-sentence)
3449 (org-backward-sentence)
3451 ;; Make sure to hit the beginning of a sentence on the same line as
3454 (org-test-with-temp-text "- Line 1\n line <point>2."
3455 (org-backward-sentence)
3456 (looking-at "Line 1"))))
3458 (ert-deftest test-org
/forward-paragraph
()
3459 "Test `org-forward-paragraph' specifications."
3460 ;; At end of buffer, do not return an error.
3462 (org-test-with-temp-text "Paragraph"
3463 (goto-char (point-max))
3464 (org-forward-paragraph)
3468 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3469 (org-forward-paragraph)
3473 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3474 (org-forward-paragraph)
3476 ;; Do not enter elements with invisible contents.
3478 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3479 (org-hide-block-toggle)
3480 (org-forward-paragraph)
3482 ;; On an affiliated keyword, jump to the beginning of the element.
3484 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3485 (org-forward-paragraph)
3486 (looking-at "Para")))
3487 ;; On an item or a footnote definition, move to the second element
3490 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3491 (org-forward-paragraph)
3492 (looking-at " Paragraph")))
3494 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3495 (org-forward-paragraph)
3496 (looking-at "Paragraph")))
3497 ;; On an item, or a footnote definition, when the first line is
3498 ;; empty, move to the first item.
3500 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3501 (org-forward-paragraph)
3502 (looking-at " Paragraph")))
3504 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3505 (org-forward-paragraph)
3506 (looking-at "Paragraph")))
3507 ;; On a table (resp. a property drawer) do not move through table
3508 ;; rows (resp. node properties).
3510 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3511 (org-forward-paragraph)
3512 (looking-at "Paragraph")))
3514 (org-test-with-temp-text
3515 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3516 (org-forward-paragraph)
3517 (looking-at "Paragraph")))
3518 ;; On a verse or source block, stop after blank lines.
3520 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3521 (org-forward-paragraph)
3524 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3525 (org-forward-paragraph)
3526 (looking-at "L2"))))
3528 (ert-deftest test-org
/backward-paragraph
()
3529 "Test `org-backward-paragraph' specifications."
3530 ;; Do not error at beginning of buffer.
3532 (org-test-with-temp-text "Paragraph"
3533 (org-backward-paragraph)
3537 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3538 (org-backward-paragraph)
3541 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3542 (org-backward-paragraph)
3543 (looking-at-p "P2")))
3546 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3547 (org-backward-paragraph)
3548 (looking-at-p "P2")))
3549 ;; Ignore invisible elements.
3551 (org-test-with-temp-text "* H1\n P1\n* H2"
3553 (goto-char (point-max))
3555 (org-backward-paragraph)
3557 ;; On an affiliated keyword, jump to the first one.
3559 (org-test-with-temp-text
3560 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3561 (org-backward-paragraph)
3562 (looking-at-p "#\\+name")))
3563 ;; On the second element in an item or a footnote definition, jump
3564 ;; to item or the definition.
3566 (org-test-with-temp-text "- line1\n\n<point> line2"
3567 (org-backward-paragraph)
3568 (looking-at-p "- line1")))
3570 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3571 (org-backward-paragraph)
3572 (looking-at-p "\\[fn:1\\] line1")))
3573 ;; On a table (resp. a property drawer), ignore table rows
3574 ;; (resp. node properties).
3576 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3577 (org-backward-paragraph)
3580 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3581 (org-backward-paragraph)
3582 (looking-at-p ":PROPERTIES:")))
3583 ;; On a comment, example, src and verse blocks, stop before blank
3586 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3587 (org-backward-paragraph)
3588 (looking-at-p "L2")))
3590 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3591 (org-backward-paragraph)
3592 (looking-at-p "L2")))
3593 ;; In comment, example, export, src and verse blocks, stop below
3594 ;; opening line when called from within the block.
3596 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3597 (org-backward-paragraph)
3598 (looking-at-p "L1")))
3600 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3601 (org-backward-paragraph)
3602 (looking-at-p "L1")))
3603 ;; When called from the opening line itself, however, move to
3604 ;; beginning of block.
3606 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3607 (org-backward-paragraph)
3609 ;; Pathological case: on an empty heading, move to its beginning.
3611 (org-test-with-temp-text "* <point>H"
3612 (org-backward-paragraph)
3615 (ert-deftest test-org
/forward-element
()
3616 "Test `org-forward-element' specifications."
3617 ;; 1. At EOB: should error.
3618 (org-test-with-temp-text "Some text\n"
3619 (goto-char (point-max))
3620 (should-error (org-forward-element)))
3621 ;; 2. Standard move: expected to ignore blank lines.
3622 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3623 (org-forward-element)
3624 (should (looking-at (regexp-quote "Second paragraph."))))
3625 ;; 3. Headline tests.
3626 (org-test-with-temp-text "
3631 ;; 3.1. At an headline beginning: move to next headline at the
3634 (org-forward-element)
3635 (should (looking-at (regexp-quote "** Head 1.2")))
3636 ;; 3.2. At an headline beginning: move to parent headline if no
3637 ;; headline at the same level.
3639 (org-forward-element)
3640 (should (looking-at (regexp-quote "** Head 1.2"))))
3641 ;; 4. Greater element tests.
3642 (org-test-with-temp-text
3643 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3644 ;; 4.1. At a greater element: expected to skip contents.
3645 (org-forward-element)
3646 (should (looking-at (regexp-quote "Outside.")))
3647 ;; 4.2. At the end of greater element contents: expected to skip
3648 ;; to the end of the greater element.
3650 (org-forward-element)
3651 (should (looking-at (regexp-quote "Outside."))))
3653 (org-test-with-temp-text "
3667 ;; 5.1. At list top point: expected to move to the element after
3670 (org-forward-element)
3671 (should (looking-at (regexp-quote "Outside.")))
3672 ;; 5.2. Special case: at the first line of a sub-list, but not at
3673 ;; beginning of line, move to next item.
3676 (org-forward-element)
3677 (should (looking-at "- item2"))
3680 (org-forward-element)
3681 (should (looking-at " - sub2"))
3682 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3684 (org-forward-element)
3685 (should (looking-at (regexp-quote " Inner paragraph.")))
3686 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3688 (org-forward-element)
3689 (should (looking-at (regexp-quote " Inner paragraph.")))
3690 ;; 5.5. At an item: expected to move to next item, if any.
3692 (org-forward-element)
3693 (should (looking-at " - sub3"))))
3695 (ert-deftest test-org
/backward-element
()
3696 "Test `org-backward-element' specifications."
3697 ;; 1. Should error at BOB.
3698 (org-test-with-temp-text " \nParagraph."
3699 (should-error (org-backward-element)))
3700 ;; 2. Should move at BOB when called on the first element in buffer.
3702 (org-test-with-temp-text "\n#+TITLE: test"
3703 (progn (forward-line)
3704 (org-backward-element)
3706 ;; 3. Not at the beginning of an element: move at its beginning.
3707 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3710 (org-backward-element)
3711 (should (looking-at (regexp-quote "Paragraph2."))))
3712 ;; 4. Headline tests.
3713 (org-test-with-temp-text "
3718 ;; 4.1. At an headline beginning: move to previous headline at the
3721 (org-backward-element)
3722 (should (looking-at (regexp-quote "** Head 1.1")))
3723 ;; 4.2. At an headline beginning: move to parent headline if no
3724 ;; headline at the same level.
3726 (org-backward-element)
3727 (should (looking-at (regexp-quote "* Head 1")))
3728 ;; 4.3. At the first top-level headline: should error.
3730 (should-error (org-backward-element)))
3731 ;; 5. At beginning of first element inside a greater element:
3732 ;; expected to move to greater element's beginning.
3733 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3735 (org-backward-element)
3736 (should (looking-at "#\\+BEGIN_CENTER")))
3737 ;; 6. At the beginning of the first element in a section: should
3738 ;; move back to headline, if any.
3740 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3741 (progn (goto-char (point-max))
3743 (org-backward-element)
3744 (org-at-heading-p))))
3746 (org-test-with-temp-text "
3761 ;; 7.1. At beginning of sub-list: expected to move to the
3762 ;; paragraph before it.
3764 (org-backward-element)
3765 (should (looking-at "item1"))
3766 ;; 7.2. At an item in a list: expected to move at previous item.
3768 (org-backward-element)
3769 (should (looking-at " - sub2"))
3771 (org-backward-element)
3772 (should (looking-at "- item1"))
3773 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3776 (org-backward-element)
3777 (should (looking-at " - sub1"))
3779 (org-backward-element)
3780 (should (looking-at "- item1"))
3781 ;; 7.4. At blank-lines before list end: expected to move to top
3784 (org-backward-element)
3785 (should (looking-at "- item1"))))
3787 (ert-deftest test-org
/up-element
()
3788 "Test `org-up-element' specifications."
3789 ;; 1. At BOB or with no surrounding element: should error.
3790 (org-test-with-temp-text "Paragraph."
3791 (should-error (org-up-element)))
3792 (org-test-with-temp-text "* Head1\n* Head2"
3794 (should-error (org-up-element)))
3795 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3797 (should-error (org-up-element)))
3798 ;; 2. At an headline: move to parent headline.
3799 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3802 (should (looking-at "\\* Head1")))
3803 ;; 3. Inside a greater element: move to greater element beginning.
3804 (org-test-with-temp-text
3805 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3808 (should (looking-at "#\\+BEGIN_CENTER")))
3810 (org-test-with-temp-text "* Top
3817 Paragraph within sub2.
3820 ;; 4.1. Within an item: move to the item beginning.
3823 (should (looking-at " - sub2"))
3824 ;; 4.2. At an item in a sub-list: move to parent item.
3827 (should (looking-at "- item1"))
3828 ;; 4.3. At an item in top list: move to beginning of whole list.
3831 (should (looking-at "- item1"))
3832 ;; 4.4. Special case. At very top point: should move to parent of
3836 (should (looking-at "\\* Top"))))
3838 (ert-deftest test-org
/down-element
()
3839 "Test `org-down-element' specifications."
3840 ;; Error when the element hasn't got a recursive type.
3841 (org-test-with-temp-text "Paragraph."
3842 (should-error (org-down-element)))
3843 ;; Error when the element has no contents
3844 (org-test-with-temp-text "* Headline"
3845 (should-error (org-down-element)))
3846 ;; When at a plain-list, move to first item.
3847 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3850 (should (looking-at " - Item 1.1")))
3851 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3853 (should (looking-at " Item 1")))
3854 ;; When at a table, move to first row
3855 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3857 (should (looking-at " a | b |")))
3858 ;; Otherwise, move inside the greater element.
3859 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3861 (should (looking-at "Paragraph"))))
3863 (ert-deftest test-org
/drag-element-backward
()
3864 "Test `org-drag-element-backward' specifications."
3868 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3869 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3870 (org-drag-element-backward)
3874 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3875 (org-test-with-temp-text
3876 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3877 (org-drag-element-backward)
3879 ;; Preserve blank lines.
3881 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3882 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3883 (org-drag-element-backward)
3887 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3888 (org-drag-element-backward)
3889 (looking-at-p "2")))
3890 ;; Error when trying to move first element of buffer.
3892 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3893 (org-drag-element-backward))
3895 ;; Error when trying to swap nested elements.
3897 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3898 (org-drag-element-backward))
3900 ;; Error when trying to swap an headline element and a non-headline
3903 (org-test-with-temp-text "Test.\n<point>* Head 1"
3904 (org-drag-element-backward))
3906 ;; Error when called before first element.
3908 (org-test-with-temp-text "\n<point>"
3909 (org-drag-element-backward))
3911 ;; Preserve visibility of elements and their contents.
3913 (equal '((63 .
82) (26 .
48))
3914 (org-test-with-temp-text "
3922 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3923 (search-backward "- item 1")
3924 (org-drag-element-backward)
3925 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3926 (overlays-in (point-min) (point-max))))))
3927 ;; Pathological case: handle call with point in blank lines right
3928 ;; after a headline.
3930 (equal "* H2\n* H1\nText\n\n"
3931 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3932 (org-drag-element-backward)
3935 (ert-deftest test-org
/drag-element-forward
()
3936 "Test `org-drag-element-forward' specifications."
3937 ;; 1. Error when trying to move first element of buffer.
3938 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3940 (should-error (org-drag-element-forward)))
3941 ;; 2. Error when trying to swap nested elements.
3942 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3944 (should-error (org-drag-element-forward)))
3945 ;; 3. Error when trying to swap a non-headline element and an
3947 (org-test-with-temp-text "Test.\n* Head 1"
3948 (should-error (org-drag-element-forward)))
3949 ;; 4. Error when called before first element.
3951 (org-test-with-temp-text "\n"
3953 (org-drag-element-backward))
3955 ;; 5. Otherwise, swap elements, preserving column and blank lines
3956 ;; between elements.
3957 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3958 (search-forward "graph")
3959 (org-drag-element-forward)
3960 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3961 (should (looking-at " 1")))
3962 ;; 5. Preserve visibility of elements and their contents.
3963 (org-test-with-temp-text "
3971 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3972 (search-backward "#+BEGIN_CENTER")
3973 (org-drag-element-forward)
3976 '((63 .
82) (26 .
48))
3977 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3978 (overlays-in (point-min) (point-max)))))))
3980 (ert-deftest test-org
/next-block
()
3981 "Test `org-next-block' specifications."
3984 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3986 (looking-at "#\\+BEGIN_CENTER")))
3989 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3990 (let ((case-fold-search nil
))
3992 (looking-at "#\\+begin_center"))))
3993 ;; Ignore current line.
3995 (org-test-with-temp-text
3996 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3998 (looking-at "#\\+BEGIN_CENTER")))
3999 ;; Throw an error when no block is found.
4001 (org-test-with-temp-text "Paragraph"
4002 (org-next-block 1)))
4003 ;; With an argument, skip many blocks at once.
4005 (org-test-with-temp-text
4006 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4008 (looking-at "#\\+BEGIN_QUOTE")))
4009 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4011 (org-test-with-temp-text
4012 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4013 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4014 (looking-at "#\\+BEGIN_QUOTE")))
4015 ;; Optional argument is also case-insensitive.
4017 (org-test-with-temp-text
4018 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4019 (let ((case-fold-search nil
))
4020 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4021 (looking-at "#\\+begin_quote")))))
4023 (ert-deftest test-org
/insert-template
()
4024 "Test `org-insert-structure-template'."
4025 ;; Test in empty buffer.
4027 (string= "#+begin_foo\n#+end_foo\n"
4028 (org-test-with-temp-text ""
4029 (org-insert-structure-template "foo")
4031 ;; Test with multiple lines in buffer.
4033 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
4034 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4036 (org-insert-structure-template "foo")
4038 ;; Test with text in buffer, no region, no final newline.
4040 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
4041 (org-test-with-temp-text "I'm a paragraph."
4043 (org-insert-structure-template "foo")
4045 ;; Test with text in buffer and region set.
4047 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
4048 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
4050 (goto-char (point-max))
4051 (org-insert-structure-template "foo")
4053 ;; Test with example escaping.
4055 (string= "#+begin_example\n,* Heading\n#+end_example\n"
4056 (org-test-with-temp-text "* Heading"
4058 (org-insert-structure-template "example")
4060 ;; Test with indentation.
4062 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
4063 (org-test-with-temp-text " This is a paragraph"
4065 (org-insert-structure-template "foo")
4068 (ert-deftest test-org
/previous-block
()
4069 "Test `org-previous-block' specifications."
4072 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4073 (org-previous-block 1)
4074 (looking-at "#\\+BEGIN_CENTER")))
4077 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4078 (let ((case-fold-search nil
))
4079 (org-previous-block 1)
4080 (looking-at "#\\+begin_center"))))
4081 ;; Ignore current line.
4083 (org-test-with-temp-text
4084 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4085 (org-previous-block 1)
4086 (looking-at "#\\+BEGIN_QUOTE")))
4087 ;; Throw an error when no block is found.
4089 (org-test-with-temp-text "Paragraph<point>"
4090 (org-previous-block 1)))
4091 ;; With an argument, skip many blocks at once.
4093 (org-test-with-temp-text
4094 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4095 (org-previous-block 2)
4096 (looking-at "#\\+BEGIN_CENTER")))
4097 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4099 (org-test-with-temp-text
4100 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4101 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4102 (looking-at "#\\+BEGIN_QUOTE")))
4103 ;; Optional argument is also case-insensitive.
4105 (org-test-with-temp-text
4106 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4107 (let ((case-fold-search nil
))
4108 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4109 (looking-at "#\\+begin_quote")))))
4112 ;;; Outline structure
4114 (ert-deftest test-org
/demote
()
4115 "Test `org-demote' specifications."
4116 ;; Add correct number of stars according to `org-odd-levels-only'.
4119 (org-test-with-temp-text "* H"
4120 (let ((org-odd-levels-only nil
)) (org-demote))
4121 (org-current-level))))
4124 (org-test-with-temp-text "* H"
4125 (let ((org-odd-levels-only t
)) (org-demote))
4126 (org-current-level))))
4127 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4129 (org-test-with-temp-text "* H :tag:"
4130 (let ((org-tags-column 10)
4131 (org-auto-align-tags t
)
4132 (org-odd-levels-only nil
))
4134 (org-move-to-column 10)
4135 (looking-at-p ":tag:$")))
4137 (org-test-with-temp-text "* H :tag:"
4138 (let ((org-tags-column 10)
4139 (org-auto-align-tags nil
)
4140 (org-odd-levels-only nil
))
4142 (org-move-to-column 10)
4143 (looking-at-p ":tag:$")))
4144 ;; When `org-adapt-indentation' is non-nil, always indent planning
4145 ;; info and property drawers accordingly.
4148 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4149 (let ((org-odd-levels-only nil
)
4150 (org-adapt-indentation t
))
4153 (org-get-indentation))))
4156 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4157 (let ((org-odd-levels-only nil
)
4158 (org-adapt-indentation t
))
4161 (org-get-indentation))))
4164 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4165 (let ((org-odd-levels-only nil
)
4166 (org-adapt-indentation nil
))
4169 (org-get-indentation))))
4170 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4171 ;; section accordingly. Ignore, however, footnote definitions and
4172 ;; inlinetasks boundaries.
4175 (org-test-with-temp-text "* H\n Paragraph"
4176 (let ((org-odd-levels-only nil
)
4177 (org-adapt-indentation t
))
4180 (org-get-indentation))))
4183 (org-test-with-temp-text "* H\n Paragraph"
4184 (let ((org-odd-levels-only nil
)
4185 (org-adapt-indentation nil
))
4188 (org-get-indentation))))
4191 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4192 (let ((org-odd-levels-only nil
)
4193 (org-adapt-indentation t
))
4195 (goto-char (point-max))
4196 (org-get-indentation))))
4199 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4200 (let ((org-odd-levels-only nil
)
4201 (org-adapt-indentation t
))
4203 (goto-char (point-max))
4204 (org-get-indentation))))
4205 (when (featurep 'org-inlinetask
)
4208 (let ((org-inlinetask-min-level 5)
4209 (org-adapt-indentation t
))
4210 (org-test-with-temp-text "* H\n***** I\n***** END"
4213 (org-get-indentation))))))
4214 (when (featurep 'org-inlinetask
)
4217 (let ((org-inlinetask-min-level 5)
4218 (org-adapt-indentation t
))
4219 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4222 (org-get-indentation))))))
4223 ;; Ignore contents of source blocks or example blocks when
4224 ;; indentation should be preserved (through
4225 ;; `org-src-preserve-indentation' or "-i" flag).
4228 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4229 (let ((org-adapt-indentation t
)
4230 (org-src-preserve-indentation nil
))
4233 (org-get-indentation))))
4236 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4237 (let ((org-adapt-indentation t
)
4238 (org-src-preserve-indentation t
))
4241 (org-get-indentation))))
4244 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4245 (let ((org-adapt-indentation t
)
4246 (org-src-preserve-indentation t
))
4249 (org-get-indentation))))
4252 (org-test-with-temp-text
4253 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4254 (let ((org-adapt-indentation t
)
4255 (org-src-preserve-indentation nil
))
4258 (org-get-indentation)))))
4260 (ert-deftest test-org
/promote
()
4261 "Test `org-promote' specifications."
4262 ;; Return an error if headline is to be promoted to level 0, unless
4263 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4264 ;; headline becomes a comment.
4266 (org-test-with-temp-text "* H"
4267 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4270 (org-test-with-temp-text "* H"
4271 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4273 ;; Remove correct number of stars according to
4274 ;; `org-odd-levels-only'.
4277 (org-test-with-temp-text "*** H"
4278 (let ((org-odd-levels-only nil
)) (org-promote))
4279 (org-current-level))))
4282 (org-test-with-temp-text "*** H"
4283 (let ((org-odd-levels-only t
)) (org-promote))
4284 (org-current-level))))
4285 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4287 (org-test-with-temp-text "** H :tag:"
4288 (let ((org-tags-column 10)
4289 (org-auto-align-tags t
)
4290 (org-odd-levels-only nil
))
4292 (org-move-to-column 10)
4293 (looking-at-p ":tag:$")))
4295 (org-test-with-temp-text "** H :tag:"
4296 (let ((org-tags-column 10)
4297 (org-auto-align-tags nil
)
4298 (org-odd-levels-only nil
))
4300 (org-move-to-column 10)
4301 (looking-at-p ":tag:$")))
4302 ;; When `org-adapt-indentation' is non-nil, always indent planning
4303 ;; info and property drawers.
4306 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4307 (let ((org-odd-levels-only nil
)
4308 (org-adapt-indentation t
))
4311 (org-get-indentation))))
4314 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4315 (let ((org-odd-levels-only nil
)
4316 (org-adapt-indentation t
))
4319 (org-get-indentation))))
4322 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4323 (let ((org-odd-levels-only nil
)
4324 (org-adapt-indentation nil
))
4327 (org-get-indentation))))
4328 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4329 ;; section accordingly. Ignore, however, footnote definitions and
4330 ;; inlinetasks boundaries.
4333 (org-test-with-temp-text "** H\n Paragraph"
4334 (let ((org-odd-levels-only nil
)
4335 (org-adapt-indentation t
))
4338 (org-get-indentation))))
4341 (org-test-with-temp-text "** H\n Paragraph"
4342 (let ((org-odd-levels-only nil
)
4343 (org-adapt-indentation nil
))
4346 (org-get-indentation))))
4349 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4350 (let ((org-odd-levels-only nil
)
4351 (org-adapt-indentation t
))
4354 (org-get-indentation))))
4355 (when (featurep 'org-inlinetask
)
4358 (let ((org-inlinetask-min-level 5)
4359 (org-adapt-indentation t
))
4360 (org-test-with-temp-text "** H\n***** I\n***** END"
4363 (org-get-indentation))))))
4364 (when (featurep 'org-inlinetask
)
4367 (let ((org-inlinetask-min-level 5)
4368 (org-adapt-indentation t
))
4369 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4372 (org-get-indentation))))))
4373 ;; Give up shifting if it would break document's structure
4377 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4378 (let ((org-odd-levels-only nil
)
4379 (org-adapt-indentation t
))
4382 (org-get-indentation))))
4385 (org-test-with-temp-text "** H\n Paragraph\n * list."
4386 (let ((org-odd-levels-only nil
)
4387 (org-adapt-indentation t
))
4390 (org-get-indentation))))
4391 ;; Ignore contents of source blocks or example blocks when
4392 ;; indentation should be preserved (through
4393 ;; `org-src-preserve-indentation' or "-i" flag).
4396 (org-test-with-temp-text
4397 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4398 (let ((org-adapt-indentation t
)
4399 (org-src-preserve-indentation nil
)
4400 (org-odd-levels-only nil
))
4403 (org-get-indentation))))
4406 (org-test-with-temp-text
4407 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4408 (let ((org-adapt-indentation t
)
4409 (org-src-preserve-indentation t
)
4410 (org-odd-levels-only nil
))
4413 (org-get-indentation))))
4416 (org-test-with-temp-text
4417 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4418 (let ((org-adapt-indentation t
)
4419 (org-src-preserve-indentation t
)
4420 (org-odd-levels-only nil
))
4423 (org-get-indentation))))
4426 (org-test-with-temp-text
4427 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4428 (let ((org-adapt-indentation t
)
4429 (org-src-preserve-indentation nil
)
4430 (org-odd-levels-only nil
))
4433 (org-get-indentation)))))
4435 (ert-deftest test-org
/org-get-valid-level
()
4436 "Test function `org-get-valid-level' specifications."
4437 (let ((org-odd-levels-only nil
))
4438 (should (equal 1 (org-get-valid-level 0 0)))
4439 (should (equal 1 (org-get-valid-level 0 1)))
4440 (should (equal 2 (org-get-valid-level 0 2)))
4441 (should (equal 3 (org-get-valid-level 0 3)))
4442 (should (equal 1 (org-get-valid-level 1 0)))
4443 (should (equal 2 (org-get-valid-level 1 1)))
4444 (should (equal 23 (org-get-valid-level 1 22)))
4445 (should (equal 1 (org-get-valid-level 1 -
1)))
4446 (should (equal 1 (org-get-valid-level 2 -
1))))
4447 (let ((org-odd-levels-only t
))
4448 (should (equal 1 (org-get-valid-level 0 0)))
4449 (should (equal 1 (org-get-valid-level 0 1)))
4450 (should (equal 3 (org-get-valid-level 0 2)))
4451 (should (equal 5 (org-get-valid-level 0 3)))
4452 (should (equal 1 (org-get-valid-level 1 0)))
4453 (should (equal 3 (org-get-valid-level 1 1)))
4454 (should (equal 3 (org-get-valid-level 2 1)))
4455 (should (equal 5 (org-get-valid-level 3 1)))
4456 (should (equal 5 (org-get-valid-level 4 1)))
4457 (should (equal 43 (org-get-valid-level 1 21)))
4458 (should (equal 1 (org-get-valid-level 1 -
1)))
4459 (should (equal 1 (org-get-valid-level 2 -
1)))
4460 (should (equal 1 (org-get-valid-level 3 -
1)))
4461 (should (equal 3 (org-get-valid-level 4 -
1)))
4462 (should (equal 3 (org-get-valid-level 5 -
1)))))
4467 (ert-deftest test-org
/at-planning-p
()
4468 "Test `org-at-planning-p' specifications."
4471 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4472 (org-at-planning-p)))
4474 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4475 (org-at-planning-p)))
4476 ;; Correctly find planning attached to inlinetasks.
4477 (when (featurep 'org-inlinetask
)
4479 (org-test-with-temp-text
4480 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4481 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4483 (org-test-with-temp-text
4484 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4485 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4487 (org-test-with-temp-text
4488 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4489 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4491 (org-test-with-temp-text
4492 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4493 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4495 (ert-deftest test-org
/add-planning-info
()
4496 "Test `org-add-planning-info'."
4497 ;; Create deadline when `org-adapt-indentation' is non-nil.
4499 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4500 (org-test-with-temp-text "* H\nParagraph<point>"
4501 (let ((org-adapt-indentation t
))
4502 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4503 (replace-regexp-in-string
4504 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4506 ;; Create deadline when `org-adapt-indentation' is nil.
4508 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4509 (org-test-with-temp-text "* H\nParagraph<point>"
4510 (let ((org-adapt-indentation nil
))
4511 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4512 (replace-regexp-in-string
4513 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4515 ;; Update deadline when `org-adapt-indentation' is non-nil.
4517 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4518 (org-test-with-temp-text "\
4520 DEADLINE: <2015-06-24 Wed>
4522 (let ((org-adapt-indentation t
))
4523 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4524 (replace-regexp-in-string
4525 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4527 ;; Update deadline when `org-adapt-indentation' is nil.
4529 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4530 (org-test-with-temp-text "\
4532 DEADLINE: <2015-06-24 Wed>
4534 (let ((org-adapt-indentation nil
))
4535 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4536 (replace-regexp-in-string
4537 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4539 ;; Schedule when `org-adapt-indentation' is non-nil.
4541 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4542 (org-test-with-temp-text "* H\nParagraph<point>"
4543 (let ((org-adapt-indentation t
))
4544 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4545 (replace-regexp-in-string
4546 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4548 ;; Schedule when `org-adapt-indentation' is nil.
4550 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4551 (org-test-with-temp-text "* H\nParagraph<point>"
4552 (let ((org-adapt-indentation nil
))
4553 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4554 (replace-regexp-in-string
4555 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4557 ;; Add deadline when scheduled.
4561 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4563 (org-test-with-temp-text "\
4565 SCHEDULED: <2015-06-24 Wed>
4567 (let ((org-adapt-indentation t
))
4568 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4569 (replace-regexp-in-string
4570 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4572 ;; Remove middle entry.
4576 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4578 (org-test-with-temp-text "\
4580 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4582 (let ((org-adapt-indentation t
))
4583 (org-add-planning-info nil nil
'deadline
))
4584 (replace-regexp-in-string
4585 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4587 ;; Remove last entry and then middle entry (order should not
4592 CLOSED: [2015-06-24]
4594 (org-test-with-temp-text "\
4596 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4598 (let ((org-adapt-indentation t
))
4599 (org-add-planning-info nil nil
'scheduled
'deadline
))
4600 (replace-regexp-in-string
4601 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4603 ;; Remove closed when `org-adapt-indentation' is non-nil.
4605 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4606 (org-test-with-temp-text "\
4608 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4610 (let ((org-adapt-indentation t
))
4611 (org-add-planning-info nil nil
'closed
))
4612 (replace-regexp-in-string
4613 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4616 (equal "* H\n Paragraph"
4617 (org-test-with-temp-text "\
4619 CLOSED: [2015-06-25 Thu]
4621 (let ((org-adapt-indentation t
))
4622 (org-add-planning-info nil nil
'closed
))
4623 (replace-regexp-in-string
4624 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4626 ;; Remove closed when `org-adapt-indentation' is nil.
4628 (equal "* H\nDEADLINE: <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 nil
))
4634 (org-add-planning-info nil nil
'closed
))
4635 (replace-regexp-in-string
4636 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4639 (equal "* H\nParagraph"
4640 (org-test-with-temp-text "\
4642 CLOSED: [2015-06-25 Thu]
4644 (let ((org-adapt-indentation nil
))
4645 (org-add-planning-info nil nil
'closed
))
4646 (replace-regexp-in-string
4647 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4649 ;; Remove closed entry and delete empty line.
4654 (org-test-with-temp-text "\
4656 CLOSED: [2015-06-24 Wed]
4658 (let ((org-adapt-indentation t
))
4659 (org-add-planning-info nil nil
'closed
))
4660 (replace-regexp-in-string
4661 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4663 ;; Remove one entry and update another.
4665 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4666 (org-test-with-temp-text "\
4668 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4670 (let ((org-adapt-indentation t
))
4671 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4672 (replace-regexp-in-string
4673 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4676 (ert-deftest test-org
/deadline
()
4677 "Test `org-deadline' specifications."
4678 ;; Insert a new value or replace existing one.
4680 (equal "* H\nDEADLINE: <2012-03-29>\n"
4681 (org-test-with-temp-text "* H"
4682 (let ((org-adapt-indentation nil
)
4683 (org-last-inserted-timestamp nil
))
4684 (org-deadline nil
"<2012-03-29 Tue>"))
4685 (replace-regexp-in-string
4686 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4689 (equal "* H\nDEADLINE: <2014-03-04>"
4690 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4691 (let ((org-adapt-indentation nil
)
4692 (org-last-inserted-timestamp nil
))
4693 (org-deadline nil
"<2014-03-04 Thu>"))
4694 (replace-regexp-in-string
4695 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4697 ;; Accept delta time, e.g., "+2d".
4699 (equal "* H\nDEADLINE: <2015-03-04>\n"
4700 (cl-letf (((symbol-function 'current-time
)
4701 (lambda (&rest args
)
4702 (apply #'encode-time
4703 (org-parse-time-string "2014-03-04")))))
4704 (org-test-with-temp-text "* H"
4705 (let ((org-adapt-indentation nil
)
4706 (org-last-inserted-timestamp nil
))
4707 (org-deadline nil
"+1y"))
4708 (replace-regexp-in-string
4709 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4710 ;; Preserve repeater.
4712 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4713 (org-test-with-temp-text "* H"
4714 (let ((org-adapt-indentation nil
)
4715 (org-last-inserted-timestamp nil
))
4716 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4717 (replace-regexp-in-string
4718 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4719 ;; Remove CLOSED keyword, if any.
4721 (equal "* H\nDEADLINE: <2012-03-29>"
4722 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4723 (let ((org-adapt-indentation nil
)
4724 (org-last-inserted-timestamp nil
))
4725 (org-deadline nil
"<2012-03-29 Tue>"))
4726 (replace-regexp-in-string
4727 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4728 ;; With C-u argument, remove DEADLINE keyword.
4731 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4732 (let ((org-adapt-indentation nil
)
4733 (org-last-inserted-timestamp nil
))
4734 (org-deadline '(4)))
4738 (org-test-with-temp-text "* H"
4739 (let ((org-adapt-indentation nil
)
4740 (org-last-inserted-timestamp nil
))
4741 (org-deadline '(4)))
4743 ;; With C-u C-u argument, prompt for a delay cookie.
4745 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4746 (cl-letf (((symbol-function 'org-read-date
)
4747 (lambda (&rest args
)
4748 (apply #'encode-time
4749 (org-parse-time-string "2014-03-04")))))
4750 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4751 (let ((org-adapt-indentation nil
)
4752 (org-last-inserted-timestamp nil
))
4753 (org-deadline '(16)))
4756 (cl-letf (((symbol-function 'org-read-date
)
4757 (lambda (&rest args
)
4758 (apply #'encode-time
4759 (org-parse-time-string "2014-03-04")))))
4760 (org-test-with-temp-text "* H"
4761 (let ((org-adapt-indentation nil
)
4762 (org-last-inserted-timestamp nil
))
4763 (org-deadline '(16)))
4765 ;; When a region is active and
4766 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4767 ;; same value in all headlines in region.
4769 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4770 (org-test-with-temp-text "* H1\n* H2"
4771 (let ((org-adapt-indentation nil
)
4772 (org-last-inserted-timestamp nil
)
4773 (org-loop-over-headlines-in-active-region t
))
4774 (transient-mark-mode 1)
4775 (push-mark (point) t t
)
4776 (goto-char (point-max))
4777 (org-deadline nil
"2012-03-29"))
4778 (replace-regexp-in-string
4779 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4781 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4782 (org-test-with-temp-text "* H1\n* H2"
4783 (let ((org-adapt-indentation nil
)
4784 (org-last-inserted-timestamp nil
)
4785 (org-loop-over-headlines-in-active-region nil
))
4786 (transient-mark-mode 1)
4787 (push-mark (point) t t
)
4788 (goto-char (point-max))
4789 (org-deadline nil
"2012-03-29"))
4790 (replace-regexp-in-string
4791 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4793 (ert-deftest test-org
/schedule
()
4794 "Test `org-schedule' specifications."
4795 ;; Insert a new value or replace existing one.
4797 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4798 (org-test-with-temp-text "* H"
4799 (let ((org-adapt-indentation nil
)
4800 (org-last-inserted-timestamp nil
))
4801 (org-schedule nil
"<2012-03-29 Tue>"))
4802 (replace-regexp-in-string
4803 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4806 (equal "* H\nSCHEDULED: <2014-03-04>"
4807 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4808 (let ((org-adapt-indentation nil
)
4809 (org-last-inserted-timestamp nil
))
4810 (org-schedule nil
"<2014-03-04 Thu>"))
4811 (replace-regexp-in-string
4812 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4814 ;; Accept delta time, e.g., "+2d".
4816 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4817 (cl-letf (((symbol-function 'current-time
)
4818 (lambda (&rest args
)
4819 (apply #'encode-time
4820 (org-parse-time-string "2014-03-04")))))
4821 (org-test-with-temp-text "* H"
4822 (let ((org-adapt-indentation nil
)
4823 (org-last-inserted-timestamp nil
))
4824 (org-schedule nil
"+1y"))
4825 (replace-regexp-in-string
4826 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4827 ;; Preserve repeater.
4829 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4830 (org-test-with-temp-text "* H"
4831 (let ((org-adapt-indentation nil
)
4832 (org-last-inserted-timestamp nil
))
4833 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4834 (replace-regexp-in-string
4835 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4836 ;; Remove CLOSED keyword, if any.
4838 (equal "* H\nSCHEDULED: <2012-03-29>"
4839 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4840 (let ((org-adapt-indentation nil
)
4841 (org-last-inserted-timestamp nil
))
4842 (org-schedule nil
"<2012-03-29 Tue>"))
4843 (replace-regexp-in-string
4844 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4845 ;; With C-u argument, remove SCHEDULED keyword.
4848 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4849 (let ((org-adapt-indentation nil
)
4850 (org-last-inserted-timestamp nil
))
4851 (org-schedule '(4)))
4855 (org-test-with-temp-text "* H"
4856 (let ((org-adapt-indentation nil
)
4857 (org-last-inserted-timestamp nil
))
4858 (org-schedule '(4)))
4860 ;; With C-u C-u argument, prompt for a delay cookie.
4862 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4863 (cl-letf (((symbol-function 'org-read-date
)
4864 (lambda (&rest args
)
4865 (apply #'encode-time
4866 (org-parse-time-string "2014-03-04")))))
4867 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4868 (let ((org-adapt-indentation nil
)
4869 (org-last-inserted-timestamp nil
))
4870 (org-schedule '(16)))
4873 (cl-letf (((symbol-function 'org-read-date
)
4874 (lambda (&rest args
)
4875 (apply #'encode-time
4876 (org-parse-time-string "2014-03-04")))))
4877 (org-test-with-temp-text "* H"
4878 (let ((org-adapt-indentation nil
)
4879 (org-last-inserted-timestamp nil
))
4880 (org-schedule '(16)))
4882 ;; When a region is active and
4883 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4884 ;; same value in all headlines in region.
4886 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4887 (org-test-with-temp-text "* H1\n* H2"
4888 (let ((org-adapt-indentation nil
)
4889 (org-last-inserted-timestamp nil
)
4890 (org-loop-over-headlines-in-active-region t
))
4891 (transient-mark-mode 1)
4892 (push-mark (point) t t
)
4893 (goto-char (point-max))
4894 (org-schedule nil
"2012-03-29"))
4895 (replace-regexp-in-string
4896 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4898 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4899 (org-test-with-temp-text "* H1\n* H2"
4900 (let ((org-adapt-indentation nil
)
4901 (org-last-inserted-timestamp nil
)
4902 (org-loop-over-headlines-in-active-region nil
))
4903 (transient-mark-mode 1)
4904 (push-mark (point) t t
)
4905 (goto-char (point-max))
4906 (org-schedule nil
"2012-03-29"))
4907 (replace-regexp-in-string
4908 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4910 ;; check if a repeater survives re-scheduling.
4912 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4913 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4914 (let ((org-adapt-indentation nil
)
4915 (org-last-inserted-timestamp nil
))
4916 (org-schedule nil
"2017-02-01"))
4922 (ert-deftest test-org
/buffer-property-keys
()
4923 "Test `org-buffer-property-keys' specifications."
4924 ;; Retrieve properties accross siblings.
4927 (org-test-with-temp-text "
4936 (org-buffer-property-keys))))
4937 ;; Retrieve properties accross children.
4940 (org-test-with-temp-text "
4949 (org-buffer-property-keys))))
4950 ;; Retrieve muliple properties in the same drawer.
4953 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4954 (org-buffer-property-keys))))
4955 ;; Ignore extension symbol in property name.
4958 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4959 (org-buffer-property-keys))))
4960 ;; With non-nil COLUMNS, extract property names from columns.
4963 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4964 (org-buffer-property-keys nil nil t
))))
4966 (equal '("A" "B" "COLUMNS")
4967 (org-test-with-temp-text
4968 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4969 (org-buffer-property-keys nil nil t
))))
4970 ;; In COLUMNS, ignore title and summary-type.
4973 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4974 (org-buffer-property-keys nil nil t
))))
4977 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4978 (org-buffer-property-keys nil nil t
))))
4981 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4982 (org-buffer-property-keys nil nil t
)))))
4984 (ert-deftest test-org
/property-values
()
4985 "Test `org-property-values' specifications."
4989 (org-test-with-temp-text
4990 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4991 (org-property-values "A"))))
4992 ;; Ignore empty values.
4994 (org-test-with-temp-text
4995 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4996 (org-property-values "A")))
4997 ;; Take into consideration extended values.
5000 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
5001 (org-property-values "A")))))
5003 (ert-deftest test-org
/find-property
()
5004 "Test `org-find-property' specifications."
5008 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
5009 (org-find-property "prop"))))
5010 ;; Ignore false positives.
5013 (org-test-with-temp-text
5014 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
5015 (org-find-property "A"))))
5016 ;; Return first entry found in buffer.
5019 (org-test-with-temp-text
5020 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5021 (org-find-property "A"))))
5022 ;; Only search visible part of the buffer.
5025 (org-test-with-temp-text
5026 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5027 (org-narrow-to-subtree)
5028 (org-find-property "A"))))
5029 ;; With optional argument, only find entries with a specific value.
5031 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5032 (org-find-property "A" "2")))
5035 (org-test-with-temp-text
5036 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5037 (org-find-property "A" "2"))))
5038 ;; Use "nil" for explicit nil values.
5041 (org-test-with-temp-text
5042 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5043 (org-find-property "A" "nil")))))
5045 (ert-deftest test-org
/entry-delete
()
5046 "Test `org-entry-delete' specifications."
5050 " *:PROPERTIES:\n *:B: +2\n *:END:"
5051 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5052 (org-entry-delete (point) "A")
5054 ;; Also remove accumulated properties.
5058 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5059 (org-entry-delete (point) "A")
5061 ;; When last property is removed, remove the property drawer.
5065 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5066 (org-entry-delete (point) "A")
5068 ;; Return a non-nil value when some property was removed.
5070 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5071 (org-entry-delete (point) "A")))
5073 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5074 (org-entry-delete (point) "C")))
5075 ;; Special properties cannot be located in a drawer. Allow to
5076 ;; remove them anyway, in case of user error.
5078 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5079 (org-entry-delete (point) "SCHEDULED"))))
5081 (ert-deftest test-org
/entry-get
()
5082 "Test `org-entry-get' specifications."
5086 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5087 (org-entry-get (point) "A"))))
5091 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5092 (org-entry-get (point) "a"))))
5093 ;; Handle extended values, both before and after base value.
5096 (org-test-with-temp-text
5097 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5098 (org-entry-get (point) "A"))))
5099 ;; Empty values are returned as the empty string.
5102 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5103 (org-entry-get (point) "A"))))
5104 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5105 ;; otherwise, return nil.
5107 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5108 (org-entry-get (point) "A")))
5111 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5112 (org-entry-get (point) "A" nil t
))))
5113 ;; Return nil when no property is found, independently on the
5114 ;; LITERAL-NIL argument.
5116 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5117 (org-entry-get (point) "B")))
5119 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5120 (org-entry-get (point) "B" nil t
)))
5121 ;; Handle inheritance, when allowed. Include extended values and
5122 ;; possibly global values.
5126 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5127 (org-entry-get (point) "A" t
))))
5131 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5132 (let ((org-use-property-inheritance t
))
5133 (org-entry-get (point) "A" 'selective
)))))
5135 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5136 (let ((org-use-property-inheritance nil
))
5137 (org-entry-get (point) "A" 'selective
))))
5141 (org-test-with-temp-text
5142 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5143 (org-entry-get (point-max) "A" t
))))
5146 (org-test-with-temp-text
5147 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5149 (org-entry-get (point-max) "A" t
))))
5152 (org-test-with-temp-text
5153 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5155 (org-entry-get (point-max) "A" t
)))))
5157 (ert-deftest test-org
/entry-properties
()
5158 "Test `org-entry-properties' specifications."
5159 ;; Get "ITEM" property.
5162 (org-test-with-temp-text "* TODO H"
5163 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5166 (org-test-with-temp-text "* TODO H"
5167 (cdr (assoc "ITEM" (org-entry-properties))))))
5168 ;; Get "TODO" property. TODO keywords are case sensitive.
5171 (org-test-with-temp-text "* TODO H"
5172 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5175 (org-test-with-temp-text "* TODO H"
5176 (cdr (assoc "TODO" (org-entry-properties))))))
5178 (org-test-with-temp-text "* H"
5179 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5181 (org-test-with-temp-text "* todo H"
5182 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5183 ;; Get "PRIORITY" property.
5186 (org-test-with-temp-text "* [#A] H"
5187 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5190 (org-test-with-temp-text "* [#A] H"
5191 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5193 (equal (char-to-string org-default-priority
)
5194 (org-test-with-temp-text "* H"
5195 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5196 ;; Get "FILE" property.
5198 (org-test-with-temp-text-in-file "* H\nParagraph"
5199 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5200 (buffer-file-name))))
5202 (org-test-with-temp-text-in-file "* H\nParagraph"
5203 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5204 (buffer-file-name))))
5206 (org-test-with-temp-text "* H\nParagraph"
5207 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5208 ;; Get "TAGS" property.
5210 (equal ":tag1:tag2:"
5211 (org-test-with-temp-text "* H :tag1:tag2:"
5212 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5214 (equal ":tag1:tag2:"
5215 (org-test-with-temp-text "* H :tag1:tag2:"
5216 (cdr (assoc "TAGS" (org-entry-properties))))))
5218 (org-test-with-temp-text "* H"
5219 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5220 ;; Get "ALLTAGS" property.
5222 (equal ":tag1:tag2:"
5223 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5224 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5226 (equal ":tag1:tag2:"
5227 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5228 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5230 (org-test-with-temp-text "* H"
5231 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5232 ;; Get "BLOCKED" property.
5235 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5236 (let ((org-enforce-todo-dependencies t
)
5238 '(org-block-todo-from-children-or-siblings-or-parent)))
5239 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5242 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5243 (let ((org-enforce-todo-dependencies t
)
5245 '(org-block-todo-from-children-or-siblings-or-parent)))
5246 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5247 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5251 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5252 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5256 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5257 (cdr (assoc "CLOSED" (org-entry-properties))))))
5259 (org-test-with-temp-text "* H"
5260 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5264 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5265 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5269 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5270 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5272 (org-test-with-temp-text "* H"
5273 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5277 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5278 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5282 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5283 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5285 (org-test-with-temp-text "* H"
5286 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5290 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5291 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5294 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5295 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5298 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5299 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5302 (org-test-with-temp-text
5303 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5305 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5306 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5307 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5309 (equal "<2012-03-29 thu.>"
5310 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5311 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5313 (equal "[2012-03-29 thu.]"
5314 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5315 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5317 (equal "<2012-03-29 thu.>"
5318 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5319 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5321 (equal "[2014-03-04 tue.]"
5322 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5323 (cdr (assoc "TIMESTAMP_IA"
5324 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5326 (equal "<2012-03-29 thu.>"
5327 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5328 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5329 ;; Get standard properties.
5332 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5333 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5334 ;; Handle extended properties.
5337 (org-test-with-temp-text
5338 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5339 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5342 (org-test-with-temp-text
5343 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5344 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5345 ;; Ignore forbidden (special) properties.
5347 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5348 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5350 (ert-deftest test-org
/entry-put
()
5351 "Test `org-entry-put' specifications."
5352 ;; Error when not a string or nil.
5354 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5355 (org-entry-put 1 "test" 2)))
5356 ;; Error when property name is invalid.
5358 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5359 (org-entry-put 1 "no space" "value")))
5361 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5362 (org-entry-put 1 "" "value")))
5363 ;; Set "TODO" property.
5365 (string-match (regexp-quote " TODO H")
5366 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5367 (org-entry-put (point) "TODO" "TODO")
5370 (string-match (regexp-quote "* H")
5371 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5372 (org-entry-put (point) "TODO" nil
)
5374 ;; Set "PRIORITY" property.
5377 (org-test-with-temp-text "* [#B] H"
5378 (org-entry-put (point) "PRIORITY" "A")
5382 (org-test-with-temp-text "* [#B] H"
5383 (org-entry-put (point) "PRIORITY" nil
)
5385 ;; Set "SCHEDULED" property.
5387 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5388 (org-test-with-temp-text "* H"
5389 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5393 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5394 (org-entry-put (point) "SCHEDULED" nil
)
5397 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5398 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5399 (org-entry-put (point) "SCHEDULED" "earlier")
5402 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5403 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5404 (org-entry-put (point) "SCHEDULED" "later")
5406 ;; Set "DEADLINE" property.
5408 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5409 (org-test-with-temp-text "* H"
5410 (org-entry-put (point) "DEADLINE" "2014-03-04")
5414 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5415 (org-entry-put (point) "DEADLINE" nil
)
5418 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5419 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5420 (org-entry-put (point) "DEADLINE" "earlier")
5423 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5424 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5425 (org-entry-put (point) "DEADLINE" "later")
5427 ;; Set "CATEGORY" property
5429 (string-match "^ *:CATEGORY: cat"
5430 (org-test-with-temp-text "* H"
5431 (org-entry-put (point) "CATEGORY" "cat")
5433 ;; Regular properties, with or without pre-existing drawer.
5435 (string-match "^ *:A: +2$"
5436 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5437 (org-entry-put (point) "A" "2")
5440 (string-match "^ *:A: +1$"
5441 (org-test-with-temp-text "* H"
5442 (org-entry-put (point) "A" "1")
5444 ;; Special case: two consecutive headlines.
5446 (string-match "\\* A\n *:PROPERTIES:"
5447 (org-test-with-temp-text "* A\n** B"
5448 (org-entry-put (point) "A" "1")
5451 (ert-deftest test-org
/refresh-properties
()
5452 "Test `org-refresh-properties' specifications."
5455 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5456 (org-refresh-properties "A" 'org-test
)
5457 (get-text-property (point) 'org-test
))))
5459 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5460 (org-refresh-properties "B" 'org-test
)
5461 (get-text-property (point) 'org-test
)))
5462 ;; Handle properties only defined with extension syntax, i.e.,
5466 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5467 (org-refresh-properties "A" 'org-test
)
5468 (get-text-property (point) 'org-test
))))
5469 ;; When property is inherited, add text property to the whole
5473 (org-test-with-temp-text
5474 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5475 (let ((org-use-property-inheritance t
))
5476 (org-refresh-properties "A" 'org-test
))
5477 (get-text-property (point) 'org-test
))))
5478 ;; When property is inherited, use global value across the whole
5479 ;; buffer. However local values have precedence.
5482 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5484 (let ((org-use-property-inheritance nil
))
5485 (org-refresh-properties "A" 'org-test
))
5486 (get-text-property (point) 'org-test
))))
5489 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5491 (let ((org-use-property-inheritance t
))
5492 (org-refresh-properties "A" 'org-test
))
5493 (get-text-property (point) 'org-test
))))
5496 (org-test-with-temp-text
5497 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5499 (let ((org-use-property-inheritance t
))
5500 (org-refresh-properties "A" 'org-test
))
5501 (get-text-property (point) 'org-test
)))))
5506 (ert-deftest test-org
/update-radio-target-regexp
()
5507 "Test `org-update-radio-target-regexp' specifications."
5508 ;; Properly update cache with no previous radio target regexp.
5511 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5512 (save-excursion (goto-char (point-max)) (org-element-context))
5514 (search-forward "o")
5516 (org-update-radio-target-regexp)
5517 (goto-char (point-max))
5518 (org-element-type (org-element-context)))))
5519 ;; Properly update cache with previous radio target regexp.
5522 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5523 (save-excursion (goto-char (point-max)) (org-element-context))
5525 (search-forward "o")
5527 (org-update-radio-target-regexp)
5528 (search-backward "r")
5531 (org-update-radio-target-regexp)
5532 (goto-char (point-max))
5533 (delete-region (line-beginning-position) (point))
5535 (org-element-type (org-element-context))))))
5540 (ert-deftest test-org
/refile-get-targets
()
5541 "Test `org-refile-get-targets' specifications."
5542 ;; :maxlevel includes all headings above specified value.
5544 (equal '("H1" "H2" "H3")
5545 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5546 (let ((org-refile-use-outline-path nil
)
5547 (org-refile-targets `((nil :maxlevel .
3))))
5548 (mapcar #'car
(org-refile-get-targets))))))
5551 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5552 (let ((org-refile-use-outline-path nil
)
5553 (org-refile-targets `((nil :maxlevel .
2))))
5554 (mapcar #'car
(org-refile-get-targets))))))
5555 ;; :level limits targets to headlines with the specified level.
5558 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5559 (let ((org-refile-use-outline-path nil
)
5560 (org-refile-targets `((nil :level .
2))))
5561 (mapcar #'car
(org-refile-get-targets))))))
5562 ;; :tag limits targets to headlines with specified tag.
5565 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5566 (let ((org-refile-use-outline-path nil
)
5567 (org-refile-targets `((nil :tag .
"foo"))))
5568 (mapcar #'car
(org-refile-get-targets))))))
5569 ;; :todo limits targets to headlines with specified TODO keyword.
5572 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5573 (let ((org-refile-use-outline-path nil
)
5574 (org-refile-targets `((nil :todo .
"TODO"))))
5575 (mapcar #'car
(org-refile-get-targets))))))
5576 ;; :regexp filters targets matching provided regexp.
5579 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5580 (let ((org-refile-use-outline-path nil
)
5581 (org-refile-targets `((nil :regexp .
"F"))))
5582 (mapcar #'car
(org-refile-get-targets))))))
5583 ;; A nil `org-refile-targets' includes only top level headlines in
5587 (org-test-with-temp-text "* H1\n** S1\n* H2"
5588 (let ((org-refile-use-outline-path nil
)
5589 (org-refile-targets nil
))
5590 (mapcar #'car
(org-refile-get-targets))))))
5591 ;; Return value is the union of the targets according to all the
5592 ;; defined rules. However, prevent duplicates.
5594 (equal '("F2" "F3" "H1")
5595 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5596 (let ((org-refile-use-outline-path nil
)
5597 (org-refile-targets `((nil :regexp .
"F")
5598 (nil :todo .
"TODO"))))
5599 (mapcar #'car
(org-refile-get-targets))))))
5601 (equal '("F2" "F3" "H1")
5602 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5603 (let ((org-refile-use-outline-path nil
)
5604 (org-refile-targets `((nil :regexp .
"F")
5605 (nil :todo .
"TODO"))))
5606 (mapcar #'car
(org-refile-get-targets))))))
5607 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5610 (equal '("H1" "H1/H2" "H1/H2/H3")
5611 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5612 (let ((org-refile-use-outline-path t
)
5613 (org-refile-targets `((nil :maxlevel .
3))))
5614 (mapcar #'car
(org-refile-get-targets))))))
5615 ;; When providing targets as paths, escape forward slashes in
5616 ;; headings with backslashes.
5618 (equal '("H1\\/foo")
5619 (org-test-with-temp-text "* H1/foo"
5620 (let ((org-refile-use-outline-path t
)
5621 (org-refile-targets `((nil :maxlevel .
1))))
5622 (mapcar #'car
(org-refile-get-targets))))))
5623 ;; When `org-refile-use-outline-path' is `file', include file name
5624 ;; without directory in targets.
5626 (org-test-with-temp-text-in-file "* H1"
5627 (let* ((filename (buffer-file-name))
5628 (org-refile-use-outline-path 'file
)
5629 (org-refile-targets `(((,filename
) :level .
1))))
5630 (member (file-name-nondirectory filename
)
5631 (mapcar #'car
(org-refile-get-targets))))))
5632 ;; When `org-refile-use-outline-path' is `full-file-path', include
5635 (org-test-with-temp-text-in-file "* H1"
5636 (let* ((filename (file-truename (buffer-file-name)))
5637 (org-refile-use-outline-path 'full-file-path
)
5638 (org-refile-targets `(((,filename
) :level .
1))))
5639 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5640 ;; When `org-refile-use-outline-path' is `buffer-name', include
5643 (org-test-with-temp-text "* H1"
5644 (let* ((org-refile-use-outline-path 'buffer-name
)
5645 (org-refile-targets `((nil :level .
1))))
5646 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5652 (ert-deftest test-org
/match-sparse-tree
()
5653 "Test `org-match-sparse-tree' specifications."
5656 (org-test-with-temp-text "* H\n** H1 :tag:"
5657 (org-match-sparse-tree nil
"tag")
5658 (search-forward "H1")
5659 (org-invisible-p2)))
5661 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5662 (org-match-sparse-tree nil
"tag")
5663 (search-forward "H2")
5664 (org-invisible-p2)))
5665 ;; "-" operator for tags.
5667 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5668 (org-match-sparse-tree nil
"tag1-tag2")
5669 (search-forward "H1")
5670 (org-invisible-p2)))
5672 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5673 (org-match-sparse-tree nil
"tag1-tag2")
5674 (search-forward "H2")
5675 (org-invisible-p2)))
5676 ;; "&" operator for tags.
5678 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5679 (org-match-sparse-tree nil
"tag1&tag2")
5680 (search-forward "H1")
5681 (org-invisible-p2)))
5683 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5684 (org-match-sparse-tree nil
"tag1&tag2")
5685 (search-forward "H2")
5686 (org-invisible-p2)))
5687 ;; "|" operator for tags.
5689 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5690 (org-match-sparse-tree nil
"tag1|tag2")
5691 (search-forward "H1")
5692 (org-invisible-p2)))
5694 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5695 (org-match-sparse-tree nil
"tag1|tag2")
5696 (search-forward "H2")
5697 (org-invisible-p2)))
5698 ;; Regexp match on tags.
5700 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5701 (org-match-sparse-tree nil
"{^tag.*}")
5702 (search-forward "H1")
5703 (org-invisible-p2)))
5705 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5706 (org-match-sparse-tree nil
"{^tag.*}")
5707 (search-forward "H2")
5708 (org-invisible-p2)))
5709 ;; Match group tags.
5711 (org-test-with-temp-text
5712 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5713 (org-match-sparse-tree nil
"work")
5714 (search-forward "H1")
5715 (org-invisible-p2)))
5717 (org-test-with-temp-text
5718 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5719 (org-match-sparse-tree nil
"work")
5720 (search-forward "H2")
5721 (org-invisible-p2)))
5722 ;; Match group tags with hard brackets.
5724 (org-test-with-temp-text
5725 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5726 (org-match-sparse-tree nil
"work")
5727 (search-forward "H1")
5728 (org-invisible-p2)))
5730 (org-test-with-temp-text
5731 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5732 (org-match-sparse-tree nil
"work")
5733 (search-forward "H2")
5734 (org-invisible-p2)))
5735 ;; Match tags in hierarchies
5737 (org-test-with-temp-text
5738 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5739 #+TAGS: [ Lev_2 : Lev_3 ]\n
5740 #+TAGS: { Lev_3 : Lev_4 }\n
5741 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5742 (org-match-sparse-tree nil
"Lev_1")
5743 (search-forward "H4")
5744 (org-invisible-p2)))
5745 ;; Match regular expressions in tags
5747 (org-test-with-temp-text
5748 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5749 (org-match-sparse-tree nil
"Lev")
5750 (search-forward "H1")
5751 (org-invisible-p2)))
5753 (org-test-with-temp-text
5754 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5755 (org-match-sparse-tree nil
"Lev")
5756 (search-forward "H1")
5757 (org-invisible-p2)))
5758 ;; Match properties.
5760 (org-test-with-temp-text
5761 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5762 (org-match-sparse-tree nil
"A=\"1\"")
5763 (search-forward "H2")
5764 (org-invisible-p2)))
5766 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5767 (org-match-sparse-tree nil
"A=\"1\"")
5768 (search-forward "H2")
5769 (org-invisible-p2)))
5770 ;; Case is not significant when matching properties.
5772 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5773 (org-match-sparse-tree nil
"a=\"1\"")
5774 (search-forward "H2")
5775 (org-invisible-p2)))
5777 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5778 (org-match-sparse-tree nil
"A=\"1\"")
5779 (search-forward "H2")
5780 (org-invisible-p2)))
5781 ;; Match special LEVEL property.
5783 (org-test-with-temp-text "* H\n** H1\n*** H2"
5784 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5785 (search-forward "H1")
5786 (org-invisible-p2)))
5788 (org-test-with-temp-text "* H\n** H1\n*** H2"
5789 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5790 (search-forward "H2")
5791 (org-invisible-p2)))
5792 ;; Comparison operators when matching properties.
5794 (org-test-with-temp-text
5795 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5796 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5797 (search-forward "H1")
5798 (org-invisible-p2)))
5800 (org-test-with-temp-text
5801 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5802 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5803 (search-forward "H2")
5804 (org-invisible-p2)))
5805 ;; Regexp match on properties values.
5807 (org-test-with-temp-text
5808 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5809 (org-match-sparse-tree nil
"A={f.*}")
5810 (search-forward "H1")
5811 (org-invisible-p2)))
5813 (org-test-with-temp-text
5814 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5815 (org-match-sparse-tree nil
"A={f.*}")
5816 (search-forward "H2")
5817 (org-invisible-p2)))
5818 ;; With an optional argument, limit match to TODO entries.
5820 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5821 (org-match-sparse-tree t
"tag")
5822 (search-forward "H1")
5823 (org-invisible-p2)))
5825 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5826 (org-match-sparse-tree t
"tag")
5827 (search-forward "H2")
5828 (org-invisible-p2))))
5830 (ert-deftest test-org
/occur
()
5831 "Test `org-occur' specifications."
5832 ;; Count number of matches.
5835 (org-test-with-temp-text "* H\nA\n* H2"
5839 (org-test-with-temp-text "* H\nA\n* H2\nA"
5841 ;; Test CALLBACK optional argument.
5844 (org-test-with-temp-text "* H\nA\n* H2"
5845 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5848 (org-test-with-temp-text "* H\nA\n* H2\nA"
5849 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5850 ;; Case-fold searches according to `org-occur-case-fold-search'.
5853 (org-test-with-temp-text "Aa"
5854 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5857 (org-test-with-temp-text "Aa"
5858 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5861 (org-test-with-temp-text "Aa"
5862 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5865 (org-test-with-temp-text "Aa"
5866 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5869 (org-test-with-temp-text "Aa"
5870 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5873 (org-test-with-temp-text "Aa"
5874 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5879 (ert-deftest test-org
/tag-string-to-alist
()
5880 "Test `org-tag-string-to-alist' specifications."
5881 ;; Tag without selection key.
5882 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5883 ;; Tag with selection key.
5884 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5888 (org-tag-string-to-alist "[ group : t1 t2 ]")
5889 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5890 ;; Mutually exclusive tags.
5891 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5892 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5895 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5896 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5898 (ert-deftest test-org
/tag-alist-to-string
()
5899 "Test `org-tag-alist-to-string' specifications."
5900 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5901 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5904 (org-tag-alist-to-string
5905 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5906 "[ group : t1 t2 ]"))
5908 (equal (org-tag-alist-to-string
5909 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5913 (org-tag-alist-to-string
5914 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5915 "{ group : tag1 tag2 }")))
5917 (ert-deftest test-org
/tag-alist-to-groups
()
5918 "Test `org-tag-alist-to-groups' specifications."
5920 (equal (org-tag-alist-to-groups
5921 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5922 '(("group" "t1" "t2"))))
5925 (org-tag-alist-to-groups
5926 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5927 '(("group" "t1" "t2"))))
5929 (org-tag-alist-to-groups
5930 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5932 (ert-deftest test-org
/tag-align
()
5933 "Test tags alignment."
5934 ;; Test aligning tags with different display width.
5936 ;; 12345678901234567890
5937 (equal "* Test :abc:"
5938 (org-test-with-temp-text "* Test :abc:"
5939 (let ((org-tags-column -
20)
5940 (indent-tabs-mode nil
))
5941 (org-fix-tags-on-the-fly))
5944 ;; 12345678901234567890
5945 (equal "* Test :日本語:"
5946 (org-test-with-temp-text "* Test :日本語:"
5947 (let ((org-tags-column -
20)
5948 (indent-tabs-mode nil
))
5949 (org-fix-tags-on-the-fly))
5951 ;; Make sure aligning tags do not skip invisible text.
5953 (equal "* [[linkx]] :tag:"
5954 (org-test-with-temp-text "* [[link<point>]] :tag:"
5955 (let ((org-tags-column 0))
5956 (org-fix-tags-on-the-fly)
5958 (buffer-string))))))
5960 (ert-deftest test-org
/tags-at
()
5962 (equal '("foo" "bar")
5963 (org-test-with-temp-text
5964 "* T<point>est :foo:bar:"
5965 (org-get-tags-at)))))
5970 (ert-deftest test-org
/auto-repeat-maybe
()
5971 "Test `org-auto-repeat-maybe' specifications."
5972 ;; Do not auto repeat when there is no valid time stamp with
5973 ;; a repeater in the entry.
5977 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5978 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5984 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5985 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5988 ;; When switching to DONE state, switch back to first TODO keyword
5989 ;; in sequence, or the same keyword if they have different types.
5993 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5994 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6000 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6001 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6007 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
6008 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6011 ;; If there was no TODO keyword in the first place, do not insert
6016 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6017 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6020 ;; Revert to REPEAT_TO_STATE, if set.
6024 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6025 (org-test-with-temp-text
6028 :REPEAT_TO_STATE: KWD2
6030 <2012-03-29 Thu +2y>"
6033 ;; When switching to DONE state, update base date. If there are
6034 ;; multiple repeated time stamps, update them all.
6037 "<2014-03-29 .* \\+2y>"
6038 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6039 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6044 "<2015-03-04 .* \\+1y>"
6045 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6046 (org-test-with-temp-text
6047 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6050 ;; Throw an error if repeater unit is the hour and no time is
6051 ;; provided in the time-stamp.
6053 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6054 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6057 ;; Do not repeat commented time stamps.
6060 "<2015-03-04 .* \\+1y>"
6061 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6062 (org-test-with-temp-text
6063 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6068 "<2015-03-04 .* \\+1y>"
6069 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6070 (org-test-with-temp-text
6072 <2012-03-29 Thu. +2y>
6074 <2014-03-04 Tue +1y>
6078 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6079 ;; entry, record time of last repeat.
6083 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6084 (org-log-repeat nil
))
6085 (cl-letf (((symbol-function 'org-add-log-setup
)
6086 (lambda (&rest args
) nil
)))
6087 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6089 (buffer-string))))))
6093 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6095 (cl-letf (((symbol-function 'org-add-log-setup
)
6096 (lambda (&rest args
) nil
)))
6097 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6099 (buffer-string))))))
6103 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6104 (cl-letf (((symbol-function 'org-add-log-setup
)
6105 (lambda (&rest args
) nil
)))
6106 (org-test-with-temp-text
6107 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6109 (buffer-string))))))
6110 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6111 ;; the entry as it is no longer relevant.
6115 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6116 (org-test-with-temp-text
6117 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6120 ;; Properly advance repeater even when a clock entry is specified
6121 ;; and `org-log-repeat' is nil.
6124 "SCHEDULED: <2014-03-29"
6125 (let ((org-log-repeat nil
)
6126 (org-todo-keywords '((sequence "TODO" "DONE"))))
6127 (org-test-with-temp-text
6129 SCHEDULED: <2012-03-29 Thu +2y>
6130 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6132 (buffer-string))))))
6137 (ert-deftest test-org
/at-timestamp-p
()
6138 "Test `org-at-timestamp-p' specifications."
6140 (org-test-with-temp-text "<2012-03-29 Thu>"
6141 (org-at-timestamp-p)))
6143 (org-test-with-temp-text "2012-03-29 Thu"
6144 (org-at-timestamp-p)))
6145 ;; Test return values.
6148 (org-test-with-temp-text "<2012-03-29 Thu>"
6149 (org-at-timestamp-p))))
6152 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6153 (org-at-timestamp-p))))
6156 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6157 (org-at-timestamp-p))))
6160 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6161 (org-at-timestamp-p))))
6164 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6165 (org-at-timestamp-p))))
6168 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6169 (org-at-timestamp-p))))
6172 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6173 (org-at-timestamp-p))))
6176 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6177 (org-at-timestamp-p))))
6178 ;; Test `inactive' optional argument.
6180 (org-test-with-temp-text "[2012-03-29 Thu]"
6181 (org-at-timestamp-p 'inactive
)))
6183 (org-test-with-temp-text "[2012-03-29 Thu]"
6184 (org-at-timestamp-p)))
6185 ;; When optional argument is `agenda', recognize time-stamps in
6186 ;; planning info line, property drawers and clocks.
6188 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6189 (org-at-timestamp-p 'agenda
)))
6191 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6192 (org-at-timestamp-p)))
6194 (org-test-with-temp-text
6195 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6196 (org-at-timestamp-p 'agenda
)))
6198 (org-test-with-temp-text
6199 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6200 (org-at-timestamp-p)))
6202 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6203 (let ((org-agenda-include-inactive-timestamps t
))
6204 (org-at-timestamp-p 'agenda
))))
6206 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6207 (let ((org-agenda-include-inactive-timestamps t
))
6208 (org-at-timestamp-p))))
6210 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6211 (let ((org-agenda-include-inactive-timestamps t
))
6212 (org-at-timestamp-p 'inactive
))))
6213 ;; When optional argument is `lax', match any part of the document
6214 ;; with Org timestamp syntax.
6216 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6217 (org-at-timestamp-p 'lax
)))
6219 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6220 (org-at-timestamp-p)))
6222 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6223 (org-at-timestamp-p 'lax
)))
6225 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6226 (org-at-timestamp-p)))
6228 (org-test-with-temp-text
6229 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6230 (org-at-timestamp-p 'lax
)))
6232 (org-test-with-temp-text
6233 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6234 (org-at-timestamp-p)))
6235 ;; Optional argument `lax' also matches inactive timestamps.
6237 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6238 (org-at-timestamp-p 'lax
))))
6240 (ert-deftest test-org
/time-stamp
()
6241 "Test `org-time-stamp' specifications."
6242 ;; Insert chosen time stamp at point.
6245 "Te<2014-03-04 .*?>xt"
6246 (org-test-with-temp-text "Te<point>xt"
6247 (cl-letf (((symbol-function 'org-read-date
)
6248 (lambda (&rest args
)
6249 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6250 (org-time-stamp nil
)
6252 ;; With a prefix argument, also insert time.
6255 "Te<2014-03-04 .*? 00:41>xt"
6256 (org-test-with-temp-text "Te<point>xt"
6257 (cl-letf (((symbol-function 'org-read-date
)
6258 (lambda (&rest args
)
6259 (apply #'encode-time
6260 (org-parse-time-string "2014-03-04 00:41")))))
6261 (org-time-stamp '(4))
6263 ;; With two universal prefix arguments, insert an active timestamp
6264 ;; with the current time without prompting the user.
6267 "Te<2014-03-04 .*? 00:41>xt"
6268 (org-test-with-temp-text "Te<point>xt"
6269 (cl-letf (((symbol-function 'current-time
)
6271 (apply #'encode-time
6272 (org-parse-time-string "2014-03-04 00:41")))))
6273 (org-time-stamp '(16))
6275 ;; When optional argument is non-nil, insert an inactive timestamp.
6278 "Te\\[2014-03-04 .*?\\]xt"
6279 (org-test-with-temp-text "Te<point>xt"
6280 (cl-letf (((symbol-function 'org-read-date
)
6281 (lambda (&rest args
)
6282 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6283 (org-time-stamp nil t
)
6285 ;; When called from a timestamp, replace existing one.
6289 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6290 (cl-letf (((symbol-function 'org-read-date
)
6291 (lambda (&rest args
)
6292 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6293 (org-time-stamp nil
)
6297 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6298 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6299 (cl-letf (((symbol-function 'org-read-date
)
6300 (lambda (&rest args
)
6301 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6302 (org-time-stamp nil
)
6304 ;; When replacing a timestamp, preserve repeater, if any.
6307 "<2014-03-04 .*? \\+2y>"
6308 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6309 (cl-letf (((symbol-function 'org-read-date
)
6310 (lambda (&rest args
)
6311 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6312 (org-time-stamp nil
)
6314 ;; When called twice in a raw, build a date range.
6317 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6318 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6319 (cl-letf (((symbol-function 'org-read-date
)
6320 (lambda (&rest args
)
6321 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6322 (let ((last-command 'org-time-stamp
)
6323 (this-command 'org-time-stamp
))
6324 (org-time-stamp nil
))
6325 (buffer-string))))))
6327 (ert-deftest test-org
/timestamp-has-time-p
()
6328 "Test `org-timestamp-has-time-p' specifications."
6331 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6332 (org-timestamp-has-time-p (org-element-context))))
6335 (org-test-with-temp-text "<2012-03-29 Thu>"
6336 (org-timestamp-has-time-p (org-element-context)))))
6338 (ert-deftest test-org
/get-repeat
()
6339 "Test `org-get-repeat' specifications."
6341 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6344 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6346 ;; Return proper repeat string.
6349 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6351 ;; Prevent false positive (commented or verbatim time stamps)
6353 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6356 (org-test-with-temp-text
6357 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6359 ;; Return nil when called before first heading.
6361 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6363 ;; When called with an optional argument, extract repeater from that
6365 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6366 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6368 (ert-deftest test-org
/timestamp-format
()
6369 "Test `org-timestamp-format' specifications."
6374 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6375 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6380 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6381 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6383 (ert-deftest test-org
/timestamp-split-range
()
6384 "Test `org-timestamp-split-range' specifications."
6385 ;; Extract range start (active).
6388 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6389 (let ((ts (org-timestamp-split-range (org-element-context))))
6390 (mapcar (lambda (p) (org-element-property p ts
))
6391 '(:year-end
:month-end
:day-end
))))))
6392 ;; Extract range start (inactive)
6395 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6396 (let ((ts (org-timestamp-split-range (org-element-context))))
6397 (mapcar (lambda (p) (org-element-property p ts
))
6398 '(:year-end
:month-end
:day-end
))))))
6399 ;; Extract range end (active).
6402 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6403 (let ((ts (org-timestamp-split-range
6404 (org-element-context) t
)))
6405 (mapcar (lambda (p) (org-element-property p ts
))
6406 '(:year-end
:month-end
:day-end
))))))
6407 ;; Extract range end (inactive)
6410 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6411 (let ((ts (org-timestamp-split-range
6412 (org-element-context) t
)))
6413 (mapcar (lambda (p) (org-element-property p ts
))
6414 '(:year-end
:month-end
:day-end
))))))
6415 ;; Return the timestamp if not a range.
6417 (org-test-with-temp-text "[2012-03-29 Thu]"
6418 (let* ((ts-orig (org-element-context))
6419 (ts-copy (org-timestamp-split-range ts-orig
)))
6420 (eq ts-orig ts-copy
))))
6422 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6423 (let* ((ts-orig (org-element-context))
6424 (ts-copy (org-timestamp-split-range ts-orig
)))
6425 (eq ts-orig ts-copy
)))))
6427 (ert-deftest test-org
/timestamp-translate
()
6428 "Test `org-timestamp-translate' specifications."
6429 ;; Translate whole date range.
6432 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6433 (let ((org-display-custom-times t
)
6434 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6435 (org-timestamp-translate (org-element-context))))))
6436 ;; Translate date range start.
6439 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6440 (let ((org-display-custom-times t
)
6441 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6442 (org-timestamp-translate (org-element-context) 'start
)))))
6443 ;; Translate date range end.
6446 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6447 (let ((org-display-custom-times t
)
6448 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6449 (org-timestamp-translate (org-element-context) 'end
)))))
6450 ;; Translate time range.
6453 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6454 (let ((org-display-custom-times t
)
6455 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6456 (org-timestamp-translate (org-element-context))))))
6457 ;; Translate non-range timestamp.
6460 (org-test-with-temp-text "<2012-03-29 Thu>"
6461 (let ((org-display-custom-times t
)
6462 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6463 (org-timestamp-translate (org-element-context))))))
6464 ;; Do not change `diary' timestamps.
6466 (equal "<%%(org-float t 4 2)>"
6467 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6468 (let ((org-display-custom-times t
)
6469 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6470 (org-timestamp-translate (org-element-context)))))))
6476 (ert-deftest test-org
/flag-drawer
()
6477 "Test `org-flag-drawer' specifications."
6480 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6482 (get-char-property (line-end-position) 'invisible
)))
6485 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6487 (org-flag-drawer nil
)
6488 (get-char-property (line-end-position) 'invisible
)))
6489 ;; Test optional argument.
6491 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6492 (let ((drawer (save-excursion (search-forward ":D2")
6493 (org-element-at-point))))
6494 (org-flag-drawer t drawer
)
6495 (get-char-property (progn (search-forward ":D2") (line-end-position))
6498 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6499 (let ((drawer (save-excursion (search-forward ":D2")
6500 (org-element-at-point))))
6501 (org-flag-drawer t drawer
)
6502 (get-char-property (line-end-position) 'invisible
))))
6503 ;; Do not hide fake drawers.
6505 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6508 (get-char-property (line-end-position) 'invisible
)))
6509 ;; Do not hide incomplete drawers.
6511 (org-test-with-temp-text ":D:\nparagraph"
6514 (get-char-property (line-end-position) 'invisible
)))
6515 ;; Do not hide drawers when called from final blank lines.
6517 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6518 (goto-char (point-max))
6520 (goto-char (point-min))
6521 (get-char-property (line-end-position) 'invisible
)))
6522 ;; Don't leave point in an invisible part of the buffer when hiding
6525 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6526 (goto-char (point-max))
6528 (get-char-property (point) 'invisible
))))
6530 (ert-deftest test-org
/hide-block-toggle
()
6531 "Test `org-hide-block-toggle' specifications."
6532 ;; Error when not at a block.
6534 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6535 (org-hide-block-toggle 'off
)
6536 (get-char-property (line-end-position) 'invisible
)))
6539 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6540 (org-hide-block-toggle)
6541 (get-char-property (line-end-position) 'invisible
)))
6543 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6544 (org-hide-block-toggle)
6545 (get-char-property (line-end-position) 'invisible
)))
6546 ;; Show block unconditionally when optional argument is `off'.
6548 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6549 (org-hide-block-toggle)
6550 (org-hide-block-toggle 'off
)
6551 (get-char-property (line-end-position) 'invisible
)))
6553 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6554 (org-hide-block-toggle 'off
)
6555 (get-char-property (line-end-position) 'invisible
)))
6556 ;; Hide block unconditionally when optional argument is non-nil.
6558 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6559 (org-hide-block-toggle t
)
6560 (get-char-property (line-end-position) 'invisible
)))
6562 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6563 (org-hide-block-toggle)
6564 (org-hide-block-toggle t
)
6565 (get-char-property (line-end-position) 'invisible
)))
6566 ;; Do not hide block when called from final blank lines.
6568 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6569 (org-hide-block-toggle)
6570 (goto-char (point-min))
6571 (get-char-property (line-end-position) 'invisible
)))
6572 ;; Don't leave point in an invisible part of the buffer when hiding
6575 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6576 (org-hide-block-toggle)
6577 (get-char-property (point) 'invisible
))))
6579 (ert-deftest test-org
/hide-block-toggle-maybe
()
6580 "Test `org-hide-block-toggle-maybe' specifications."
6582 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6583 (org-hide-block-toggle-maybe)))
6585 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6587 (ert-deftest test-org
/set-tags
()
6588 "Test `org-set-tags' specifications."
6589 ;; Tags set via fast-tag-selection should be visible afterwards
6591 (let ((org-tag-alist '(("NEXT" . ?n
)))
6592 (org-fast-tag-selection-single-key t
))
6593 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6594 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6595 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6596 ;; Show only headlines
6598 ;; Set NEXT tag on current entry
6599 (org-set-tags nil nil
)
6600 ;; Move point to that NEXT tag
6601 (search-forward "NEXT") (backward-word)
6602 ;; And it should be visible (i.e. no overlays)
6603 (not (overlays-at (point))))))))
6605 (ert-deftest test-org
/show-set-visibility
()
6606 "Test `org-show-set-visibility' specifications."
6607 ;; Do not throw an error before first heading.
6609 (org-test-with-temp-text "Preamble\n* Headline"
6610 (org-show-set-visibility 'tree
)
6612 ;; Test all visibility spans, both on headline and in entry.
6613 (let ((list-visible-lines
6614 (lambda (state headerp
)
6615 (org-test-with-temp-text "* Grandmother (0)
6626 **** The other child (11)
6631 (search-forward (if headerp
"Self" "Match"))
6632 (org-show-set-visibility state
)
6633 (goto-char (point-min))
6634 (let (result (line 0))
6636 (unless (org-invisible-p2) (push line result
))
6639 (nreverse result
))))))
6640 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6641 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6642 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6643 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6644 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6645 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6646 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6647 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6648 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6649 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6650 (funcall list-visible-lines
'tree nil
)))
6651 (should (equal '(0 1 3 4 5 7 12 13)
6652 (funcall list-visible-lines
'canonical t
)))
6653 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6654 (funcall list-visible-lines
'canonical nil
))))
6655 ;; When point is hidden in a drawer or a block, make sure to make it
6658 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6659 (org-hide-block-toggle)
6660 (search-forward "Text")
6661 (org-show-set-visibility 'minimal
)
6662 (org-invisible-p2)))
6664 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6666 (search-forward "Text")
6667 (org-show-set-visibility 'minimal
)
6668 (org-invisible-p2)))
6670 (org-test-with-temp-text
6671 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6674 (org-hide-block-toggle)
6675 (search-forward "Text")
6676 (org-show-set-visibility 'minimal
)
6677 (org-invisible-p2))))
6679 (defun test-org/copy-visible
()
6680 "Test `org-copy-visible' specifications."
6683 (org-test-with-temp-text "Foo"
6684 (let ((kill-ring nil
))
6685 (org-copy-visible (point-min) (point-max))
6686 (current-kill 0 t
)))))
6687 ;; Skip invisible characters by text property.
6690 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6691 (let ((kill-ring nil
))
6692 (org-copy-visible (point-min) (point-max))
6693 (current-kill 0 t
)))))
6694 ;; Skip invisible characters by overlay.
6697 (org-test-with-temp-text "F<hidden>oo"
6698 (let ((o (make-overlay 2 10)))
6699 (overlay-put o
'invisible t
))
6700 (let ((kill-ring nil
))
6701 (org-copy-visible (point-min) (point-max))
6702 (current-kill 0 t
)))))
6703 ;; Handle invisible characters at the beginning and the end of the
6707 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6708 (let ((kill-ring nil
))
6709 (org-copy-visible (point-min) (point-max))
6710 (current-kill 0 t
)))))
6713 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6714 (let ((kill-ring nil
))
6715 (org-copy-visible (point-min) (point-max))
6716 (current-kill 0 t
)))))
6717 ;; Handle multiple visible parts.
6720 (org-test-with-temp-text
6721 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6722 (let ((kill-ring nil
))
6723 (org-copy-visible (point-min) (point-max))
6724 (current-kill 0 t
))))))
6729 ;;; test-org.el ends here