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"
1190 (ert-deftest test-org
/meta-return
()
1191 "Test M-RET (`org-meta-return') specifications."
1192 ;; In a table field insert a row above.
1194 (org-test-with-temp-text "| a |"
1198 (looking-at "| |$")))
1199 ;; In a paragraph change current line into a header.
1201 (org-test-with-temp-text "a"
1204 (looking-at "\* a$")))
1205 ;; In an item insert an item, in this case above.
1207 (org-test-with-temp-text "- a"
1210 (looking-at "- $")))
1211 ;; In a drawer and item insert an item, in this case above.
1213 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1217 (looking-at "- $"))))
1219 (ert-deftest test-org
/insert-heading
()
1220 "Test `org-insert-heading' specifications."
1221 ;; In an empty buffer, insert a new headline.
1224 (org-test-with-temp-text ""
1225 (org-insert-heading)
1227 ;; At the beginning of a line, turn it into a headline.
1230 (org-test-with-temp-text "<point>P"
1231 (org-insert-heading)
1233 ;; In the middle of a line, split the line if allowed, otherwise,
1234 ;; insert the headline at its end.
1236 (equal "Para\n* graph"
1237 (org-test-with-temp-text "Para<point>graph"
1238 (let ((org-M-RET-may-split-line '((default . t
))))
1239 (org-insert-heading))
1242 (equal "Paragraph\n* "
1243 (org-test-with-temp-text "Para<point>graph"
1244 (let ((org-M-RET-may-split-line '((default . nil
))))
1245 (org-insert-heading))
1247 ;; At the beginning of a headline, create one above.
1250 (org-test-with-temp-text "* H"
1251 (org-insert-heading)
1253 ;; In the middle of a headline, split it if allowed.
1256 (org-test-with-temp-text "* H<point>1"
1257 (let ((org-M-RET-may-split-line '((headline . t
))))
1258 (org-insert-heading))
1262 (org-test-with-temp-text "* H<point>1"
1263 (let ((org-M-RET-may-split-line '((headline . nil
))))
1264 (org-insert-heading))
1266 ;; However, splitting cannot happen on TODO keywords, priorities or
1269 (equal "* TODO H1\n* \n"
1270 (org-test-with-temp-text "* TO<point>DO H1"
1271 (let ((org-M-RET-may-split-line '((headline . t
))))
1272 (org-insert-heading))
1275 (equal "* [#A] H1\n* \n"
1276 (org-test-with-temp-text "* [#<point>A] H1"
1277 (let ((org-M-RET-may-split-line '((headline . t
))))
1278 (org-insert-heading))
1281 (equal "* H1 :tag:\n* \n"
1282 (org-test-with-temp-text "* H1 :ta<point>g:"
1283 (let ((org-M-RET-may-split-line '((headline . t
))))
1284 (org-insert-heading))
1286 ;; New headline level depends on the level of the headline above.
1289 (org-test-with-temp-text "** H\n<point>P"
1290 (org-insert-heading)
1293 (equal "** H\nPara\n** graph"
1294 (org-test-with-temp-text "** H\nPara<point>graph"
1295 (let ((org-M-RET-may-split-line '((default . t
))))
1296 (org-insert-heading))
1300 (org-test-with-temp-text "** H"
1301 (org-insert-heading)
1303 ;; When called with one universal argument, insert a new headline at
1304 ;; the end of the current subtree, independently on the position of
1309 (org-test-with-temp-text "* H1\n** H2"
1310 (let ((org-insert-heading-respect-content nil
))
1311 (org-insert-heading '(4)))
1316 (org-test-with-temp-text "* H<point>1\n** H2"
1317 (let ((org-insert-heading-respect-content nil
))
1318 (org-insert-heading '(4)))
1320 ;; When called with two universal arguments, insert a new headline
1321 ;; at the end of the grandparent subtree.
1323 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1324 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1325 (let ((org-insert-heading-respect-content nil
))
1326 (org-insert-heading '(16)))
1328 ;; When optional TOP-LEVEL argument is non-nil, always insert
1329 ;; a level 1 heading.
1331 (equal "* H1\n** H2\n* \n"
1332 (org-test-with-temp-text "* H1\n** H2<point>"
1333 (org-insert-heading nil nil t
)
1336 (equal "* H1\n- item\n* "
1337 (org-test-with-temp-text "* H1\n- item<point>"
1338 (org-insert-heading nil nil t
)
1340 ;; Obey `org-blank-before-new-entry'.
1342 (equal "* H1\n\n* \n"
1343 (org-test-with-temp-text "* H1<point>"
1344 (let ((org-blank-before-new-entry '((heading . t
))))
1345 (org-insert-heading))
1349 (org-test-with-temp-text "* H1<point>"
1350 (let ((org-blank-before-new-entry '((heading . nil
))))
1351 (org-insert-heading))
1354 (equal "* H1\n* H2\n* \n"
1355 (org-test-with-temp-text "* H1\n* H2<point>"
1356 (let ((org-blank-before-new-entry '((heading . auto
))))
1357 (org-insert-heading))
1360 (equal "* H1\n\n* H2\n\n* \n"
1361 (org-test-with-temp-text "* H1\n\n* H2<point>"
1362 (let ((org-blank-before-new-entry '((heading . auto
))))
1363 (org-insert-heading))
1365 ;; Corner case: correctly insert a headline after an empty one.
1368 (org-test-with-temp-text "* <point>"
1369 (org-insert-heading)
1372 (org-test-with-temp-text "* <point>\n"
1373 (org-insert-heading)
1374 (looking-at-p "\n\\'")))
1375 ;; Do not insert spurious headlines when inserting a new headline.
1377 (equal "* H1\n* H2\n* \n"
1378 (org-test-with-temp-text "* H1\n* H2<point>\n"
1379 (org-insert-heading)
1381 ;; Preserve visibility at beginning of line. In particular, when
1382 ;; removing spurious blank lines, do not visually merge heading with
1383 ;; the line visible above.
1385 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1387 (let ((org-blank-before-new-entry '((heading . nil
))))
1388 (org-insert-heading '(4)))
1389 (invisible-p (line-end-position 0))))
1390 ;; Properly handle empty lines when forcing a headline below current
1393 (equal "* H1\n\n* H\n\n* \n"
1394 (org-test-with-temp-text "* H1\n\n* H<point>"
1395 (let ((org-blank-before-new-entry '((heading . t
))))
1396 (org-insert-heading '(4))
1397 (buffer-string))))))
1399 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1400 "Test `org-insert-todo-heading-respect-content' specifications."
1401 ;; Create a TODO heading.
1403 (org-test-with-temp-text "* H1\n Body"
1404 (org-insert-todo-heading-respect-content)
1405 (nth 2 (org-heading-components))))
1406 ;; Add headline at the end of the first subtree
1410 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1411 (org-insert-todo-heading-respect-content)
1412 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1413 ;; In a list, do not create a new item.
1417 (org-test-with-temp-text "* H\n- an item\n- another one"
1418 (search-forward "an ")
1419 (org-insert-todo-heading-respect-content)
1420 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1421 ;; Use the same TODO keyword as current heading.
1425 (org-test-with-temp-text "* TODO\n** WAITING\n"
1426 (org-insert-todo-heading-respect-content)
1427 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1429 (ert-deftest test-org
/clone-with-time-shift
()
1430 "Test `org-clone-subtree-with-time-shift'."
1431 ;; Raise an error before first heading.
1433 (org-test-with-temp-text ""
1434 (org-clone-subtree-with-time-shift 1)))
1435 ;; Raise an error on invalid number of clones.
1437 (org-test-with-temp-text "* Clone me"
1438 (org-clone-subtree-with-time-shift -
1)))
1439 ;; Clone non-repeating once.
1445 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1446 (org-clone-subtree-with-time-shift 1 "+2d")
1447 (replace-regexp-in-string
1448 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1450 ;; Clone repeating once.
1455 * H1\n<2015-06-25 +1w>
1457 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
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 non-repeating zero times.
1467 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1468 (org-clone-subtree-with-time-shift 0 "+2d")
1469 (replace-regexp-in-string
1470 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1472 ;; Clone repeating "zero" times.
1476 * H1\n<2015-06-23 +1w>
1478 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1479 (org-clone-subtree-with-time-shift 0 "+2d")
1480 (replace-regexp-in-string
1481 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1483 ;; Clone with blank SHIFT argument.
1487 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1488 (org-clone-subtree-with-time-shift 1 "")
1489 (buffer-substring-no-properties (line-beginning-position 2)
1490 (line-end-position 2)))))
1491 ;; Find time stamps before point. If SHIFT is not specified, ask
1492 ;; for a time shift.
1496 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1497 (org-clone-subtree-with-time-shift 1 "+1d")
1498 (buffer-substring-no-properties (line-beginning-position 2)
1499 (line-end-position 2)))))
1503 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1504 (cl-letf (((symbol-function 'read-from-minibuffer
)
1505 (lambda (&rest args
) "+1d")))
1506 (org-clone-subtree-with-time-shift 1))
1507 (buffer-substring-no-properties (line-beginning-position 2)
1508 (line-end-position 2))))))
1511 ;;; Fixed-Width Areas
1513 (ert-deftest test-org
/toggle-fixed-width
()
1514 "Test `org-toggle-fixed-width' specifications."
1515 ;; No region: Toggle on fixed-width marker in paragraphs.
1518 (org-test-with-temp-text "A"
1519 (org-toggle-fixed-width)
1521 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1524 (org-test-with-temp-text ": A"
1525 (org-toggle-fixed-width)
1527 ;; No region: Toggle on marker in blank lines after elements or just
1528 ;; after a headline.
1531 (org-test-with-temp-text "* H\n"
1533 (org-toggle-fixed-width)
1536 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1537 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1538 (goto-char (point-max))
1539 (org-toggle-fixed-width)
1541 ;; No region: Toggle on marker in front of one line elements (e.g.,
1542 ;; headlines, clocks)
1544 (equal ": * Headline"
1545 (org-test-with-temp-text "* Headline"
1546 (org-toggle-fixed-width)
1549 (equal ": #+KEYWORD: value"
1550 (org-test-with-temp-text "#+KEYWORD: value"
1551 (org-toggle-fixed-width)
1553 ;; No region: error in other situations.
1555 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1557 (org-toggle-fixed-width)
1559 ;; No region: Indentation is preserved.
1562 (org-test-with-temp-text "- A\n B"
1564 (org-toggle-fixed-width)
1566 ;; Region: If it contains only fixed-width elements and blank lines,
1567 ;; toggle off fixed-width markup.
1570 (org-test-with-temp-text ": A\n\n: B"
1571 (transient-mark-mode 1)
1572 (push-mark (point) t t
)
1573 (goto-char (point-max))
1574 (org-toggle-fixed-width)
1576 ;; Region: If it contains anything else, toggle on fixed-width but
1577 ;; not on fixed-width areas.
1579 (equal ": A\n: \n: B\n: \n: C"
1580 (org-test-with-temp-text "A\n\n: B\n\nC"
1581 (transient-mark-mode 1)
1582 (push-mark (point) t t
)
1583 (goto-char (point-max))
1584 (org-toggle-fixed-width)
1586 ;; Region: Ignore blank lines at its end, unless it contains only
1590 (org-test-with-temp-text "A\n\n"
1591 (transient-mark-mode 1)
1592 (push-mark (point) t t
)
1593 (goto-char (point-max))
1594 (org-toggle-fixed-width)
1598 (org-test-with-temp-text "\n\n"
1599 (transient-mark-mode 1)
1600 (push-mark (point) t t
)
1601 (goto-char (point-max))
1602 (org-toggle-fixed-width)
1609 (ert-deftest test-org
/get-heading
()
1610 "Test `org-get-heading' specifications."
1611 ;; Return current heading, even if point is not on it.
1614 (org-test-with-temp-text "* H"
1615 (org-get-heading))))
1618 (org-test-with-temp-text "* H\nText<point>"
1619 (org-get-heading))))
1620 ;; Without any optional argument, return TODO keyword, priority
1621 ;; cookie, COMMENT keyword and tags.
1624 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1625 (org-get-heading))))
1628 (org-test-with-temp-text "* [#A] H"
1629 (org-get-heading))))
1632 (org-test-with-temp-text "* COMMENT H"
1633 (org-get-heading))))
1636 (org-test-with-temp-text "* H :tag:"
1637 (org-get-heading))))
1638 ;; With NO-TAGS argument, ignore tags.
1641 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1642 (org-get-heading t
))))
1645 (org-test-with-temp-text "* H :tag:"
1646 (org-get-heading t
))))
1647 ;; With NO-TODO, ignore TODO keyword.
1650 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1651 (org-get-heading nil t
))))
1654 (org-test-with-temp-text "* H :tag:"
1655 (org-get-heading nil t
))))
1656 ;; TODO keywords are case-sensitive.
1659 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1660 (org-get-heading nil t
))))
1661 ;; With NO-PRIORITY, ignore priority.
1664 (org-test-with-temp-text "* [#A] H"
1665 (org-get-heading nil nil t
))))
1668 (org-test-with-temp-text "* H"
1669 (org-get-heading nil nil t
))))
1672 (org-test-with-temp-text "* TODO [#A] H"
1673 (org-get-heading nil nil t
))))
1674 ;; With NO-COMMENT, ignore COMMENT keyword.
1677 (org-test-with-temp-text "* COMMENT H"
1678 (org-get-heading nil nil nil t
))))
1681 (org-test-with-temp-text "* H"
1682 (org-get-heading nil nil nil t
))))
1684 (equal "TODO [#A] H"
1685 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1686 (org-get-heading nil nil nil t
))))
1687 ;; On an empty headline, return value is consistent.
1688 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1689 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1690 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1691 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1693 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1695 (ert-deftest test-org
/in-commented-heading-p
()
1696 "Test `org-in-commented-heading-p' specifications."
1697 ;; Commented headline.
1699 (org-test-with-temp-text "* COMMENT Headline\nBody"
1700 (goto-char (point-max))
1701 (org-in-commented-heading-p)))
1702 ;; Commented ancestor.
1704 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1705 (goto-char (point-max))
1706 (org-in-commented-heading-p)))
1707 ;; Comment keyword is case-sensitive.
1709 (org-test-with-temp-text "* Comment Headline\nBody"
1710 (goto-char (point-max))
1711 (org-in-commented-heading-p)))
1712 ;; Keyword is standalone.
1714 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1715 (goto-char (point-max))
1716 (org-in-commented-heading-p)))
1717 ;; Optional argument.
1719 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1720 (goto-char (point-max))
1721 (org-in-commented-heading-p t
))))
1723 (ert-deftest test-org
/entry-blocked-p
()
1724 ;; Check other dependencies.
1726 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1727 (let ((org-enforce-todo-dependencies t
)
1729 '(org-block-todo-from-children-or-siblings-or-parent)))
1730 (org-entry-blocked-p))))
1732 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1733 (let ((org-enforce-todo-dependencies t
)
1735 '(org-block-todo-from-children-or-siblings-or-parent)))
1736 (org-entry-blocked-p))))
1737 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1740 (org-test-with-temp-text "* Blocked\n** TODO one"
1741 (let ((org-enforce-todo-dependencies t
)
1743 '(org-block-todo-from-children-or-siblings-or-parent)))
1744 (org-entry-blocked-p))))
1746 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1747 (let ((org-enforce-todo-dependencies t
)
1749 '(org-block-todo-from-children-or-siblings-or-parent)))
1750 (org-entry-blocked-p))))
1751 ;; Follow :ORDERED: specifications.
1753 (org-test-with-temp-text
1754 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1755 (let ((org-enforce-todo-dependencies t
)
1757 '(org-block-todo-from-children-or-siblings-or-parent)))
1758 (org-entry-blocked-p))))
1760 (org-test-with-temp-text
1761 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1762 (let ((org-enforce-todo-dependencies t
)
1764 '(org-block-todo-from-children-or-siblings-or-parent)))
1765 (org-entry-blocked-p)))))
1767 (ert-deftest test-org
/get-outline-path
()
1768 "Test `org-get-outline-path' specifications."
1769 ;; Top-level headlines have no outline path.
1771 (org-test-with-temp-text "* H"
1772 (org-get-outline-path)))
1773 ;; Otherwise, outline path is the path leading to the headline.
1776 (org-test-with-temp-text "* H\n** S<point>"
1777 (org-get-outline-path))))
1778 ;; Find path even when point is not on a headline.
1781 (org-test-with-temp-text "* H\n** S\nText<point>"
1782 (org-get-outline-path))))
1783 ;; TODO keywords, tags and statistics cookies are ignored.
1786 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1787 (org-get-outline-path))))
1788 ;; Links are replaced with their description or their path.
1791 (org-test-with-temp-text
1792 "* [[http://orgmode.org][Org]]\n** S<point>"
1793 (org-get-outline-path))))
1795 (equal '("http://orgmode.org")
1796 (org-test-with-temp-text
1797 "* [[http://orgmode.org]]\n** S<point>"
1798 (org-get-outline-path))))
1799 ;; When WITH-SELF is non-nil, include current heading.
1802 (org-test-with-temp-text "* H"
1803 (org-get-outline-path t
))))
1806 (org-test-with-temp-text "* H\n** S\nText<point>"
1807 (org-get-outline-path t
))))
1808 ;; Using cache is transparent to the user.
1811 (org-test-with-temp-text "* H\n** S<point>"
1812 (setq org-outline-path-cache nil
)
1813 (org-get-outline-path nil t
))))
1814 ;; Do not corrupt cache when finding outline path in distant part of
1818 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1819 (setq org-outline-path-cache nil
)
1820 (org-get-outline-path nil t
)
1821 (search-forward "S2")
1822 (org-get-outline-path nil t
))))
1823 ;; Do not choke on empty headlines.
1825 (org-test-with-temp-text "* H\n** <point>"
1826 (org-get-outline-path)))
1828 (org-test-with-temp-text "* \n** H<point>"
1829 (org-get-outline-path))))
1831 (ert-deftest test-org
/format-outline-path
()
1832 "Test `org-format-outline-path' specifications."
1834 (string= (org-format-outline-path (list "one" "two" "three"))
1838 (string= (org-format-outline-path '())
1841 (string= (org-format-outline-path '(nil))
1843 ;; Empty path and prefix.
1845 (string= (org-format-outline-path '() nil
">>")
1847 ;; Trailing whitespace in headings.
1849 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1851 ;; Non-default prefix and separators.
1853 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1854 ">>|one|two|three"))
1857 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1859 ;; Give a very narrow width.
1861 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1863 ;; Give a prefix that extends beyond the width.
1865 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1869 (ert-deftest test-org
/map-entries
()
1870 "Test `org-map-entries' specifications."
1874 (org-test-with-temp-text "* Level 1\n** Level 2"
1875 (org-map-entries #'point
))))
1879 (org-test-with-temp-text "* Level 1\n** Level 2"
1880 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1883 (org-test-with-temp-text "* Level 1\n** Level 2"
1884 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1888 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1889 (org-map-entries #'point
"yes"))))
1892 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1893 (org-map-entries #'point
"+yes-a"))))
1896 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1897 (org-map-entries #'point
"{yes?}"))))
1901 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1902 (org-map-entries #'point
"PRIORITY=\"A\""))))
1906 (org-test-with-temp-text "
1908 SCHEDULED: <2012-03-29 thu.>
1910 SCHEDULED: <2014-03-04 tue.>"
1911 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1914 (org-test-with-temp-text "
1916 SCHEDULED: <2012-03-29 thu.>
1918 SCHEDULED: <2014-03-04 tue.>"
1919 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1920 ;; Regular property match.
1923 (org-test-with-temp-text "
1932 (org-map-entries #'point
"TEST=1"))))
1933 ;; Multiple criteria.
1936 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1937 (let (org-odd-levels-only
1938 (org-use-tag-inheritance nil
))
1939 (org-map-entries #'point
"yes+LEVEL=1")))))
1943 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1944 (let (org-odd-levels-only)
1945 (org-map-entries #'point
"LEVEL=2|no")))))
1948 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1949 (let (org-odd-levels-only)
1950 (org-map-entries #'point
"yes|no")))))
1954 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1955 (let (org-odd-levels-only)
1956 (org-map-entries #'point
"yes&no"))))))
1958 (ert-deftest test-org
/edit-headline
()
1959 "Test `org-edit-headline' specifications."
1962 (org-test-with-temp-text "* A"
1963 (org-edit-headline "B")
1965 ;; Handle empty headings.
1968 (org-test-with-temp-text "* A"
1969 (org-edit-headline "")
1973 (org-test-with-temp-text "* "
1974 (org-edit-headline "A")
1976 ;; Handle TODO keywords and priority cookies.
1979 (org-test-with-temp-text "* TODO A"
1980 (org-edit-headline "B")
1984 (org-test-with-temp-text "* [#A] A"
1985 (org-edit-headline "B")
1988 (equal "* TODO [#A] B"
1989 (org-test-with-temp-text "* TODO [#A] A"
1990 (org-edit-headline "B")
1994 (org-test-with-temp-text "* A :tag:"
1995 (let ((org-tags-column 4)) (org-edit-headline "B"))
2002 (ert-deftest test-org
/set-regexps-and-options
()
2003 "Test `org-set-regexps-and-options' specifications."
2007 (let ((org-tag-alist '(("A")))
2008 (org-tag-persistent-alist nil
))
2009 (org-test-with-temp-text ""
2011 org-current-tag-alist
))))
2014 (let ((org-tag-alist '(("A")))
2015 (org-tag-persistent-alist nil
))
2016 (org-test-with-temp-text "#+TAGS: B"
2018 org-current-tag-alist
))))
2020 (equal '(("C") ("B"))
2021 (let ((org-tag-alist '(("A")))
2022 (org-tag-persistent-alist '(("C"))))
2023 (org-test-with-temp-text "#+TAGS: B"
2025 org-current-tag-alist
))))
2028 (let ((org-tag-alist '(("A")))
2029 (org-tag-persistent-alist '(("C"))))
2030 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2032 org-current-tag-alist
))))
2034 (equal '(("A" . ?a
) ("B") ("C"))
2035 (let ((org-tag-persistant-alist nil
))
2036 (org-test-with-temp-text "#+TAGS: A(a) B C"
2038 org-current-tag-alist
))))
2040 (equal '(("A") (:newline
) ("B"))
2041 (let ((org-tag-persistent-alist nil
))
2042 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2044 org-current-tag-alist
))))
2046 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2047 (let ((org-tag-persistent-alist nil
))
2048 (org-test-with-temp-text "#+TAGS: { A B } C"
2050 org-current-tag-alist
))))
2052 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2053 (let ((org-tag-persistent-alist nil
))
2054 (org-test-with-temp-text "#+TAGS: { A : B C }"
2056 org-current-tag-alist
))))
2058 (equal '(("A" "B" "C"))
2059 (let ((org-tag-persistent-alist nil
))
2060 (org-test-with-temp-text "#+TAGS: { A : B C }"
2062 org-tag-groups-alist
))))
2064 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
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
))))
2075 ;; FILETAGS keyword.
2077 (equal '("A" "B" "C")
2078 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2081 ;; PROPERTY keyword. Property names are case-insensitive.
2084 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2086 (cdr (assoc "var" org-file-properties
)))))
2090 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2092 (cdr (assoc "var" org-file-properties
)))))
2096 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2098 (cdr (assoc "var" org-file-properties
)))))
2102 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2104 org-archive-location
)))
2105 ;; CATEGORY keyword.
2108 (org-test-with-temp-text "#+CATEGORY: test"
2113 (org-test-with-temp-text "#+CATEGORY: test"
2115 (cdr (assoc "CATEGORY" org-file-properties
)))))
2118 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2119 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2121 org-columns-default-format
)))
2122 ;; CONSTANTS keyword. Constants names are case sensitive.
2124 (equal '("299792458." "3.14")
2125 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2128 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2132 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2134 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2137 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2139 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2144 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2146 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2148 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2152 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2154 (list org-highest-priority org-lowest-priority org-default-priority
))))
2158 (org-test-with-temp-text "#+PRIORITIES: X Z"
2160 (list org-highest-priority org-lowest-priority org-default-priority
))))
2164 (org-test-with-temp-text "#+STARTUP: fold odd"
2166 (list org-startup-folded org-odd-levels-only
))))
2169 (equal '(("A" "B") ("C"))
2170 (org-test-with-temp-text "#+TODO: A B | C"
2172 (list org-not-done-keywords org-done-keywords
))))
2174 (equal '(("A" "C") ("B" "D"))
2175 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2177 (list org-not-done-keywords org-done-keywords
))))
2179 (equal '(("A" "B") ("C"))
2180 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2182 (list org-not-done-keywords org-done-keywords
))))
2184 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2185 (org-test-with-temp-text "#+TODO: A(a)"
2187 org-todo-key-alist
)))
2189 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2190 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2192 org-todo-log-states
)))
2193 ;; Enter SETUPFILE keyword.
2196 (org-test-with-temp-text
2197 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2199 (cdr (assoc "a" org-file-properties
))))))
2207 (ert-deftest test-org
/coderef
()
2208 "Test coderef links specifications."
2210 (org-test-with-temp-text "
2211 #+BEGIN_SRC emacs-lisp
2216 (looking-at "(ref:sc)")))
2217 ;; Find coderef even with alternate label format.
2219 (org-test-with-temp-text "
2220 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2225 (looking-at "{ref:sc}"))))
2229 (ert-deftest test-org
/custom-id
()
2230 "Test custom ID links specifications."
2232 (org-test-with-temp-text
2233 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2235 (looking-at-p "\\* H1")))
2236 ;; Throw an error on false positives.
2238 (org-test-with-temp-text
2239 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2241 (looking-at-p "\\* H1"))))
2245 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2246 ;; a named element (#+name: text) and to headlines (* Text).
2248 (ert-deftest test-org
/fuzzy-links
()
2249 "Test fuzzy links specifications."
2250 ;; Fuzzy link goes in priority to a matching target.
2252 (org-test-with-temp-text
2253 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2254 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2255 (looking-at "<<Test>>")))
2256 ;; Then fuzzy link points to an element with a given name.
2258 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2259 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2260 (looking-at "#\\+NAME: Test")))
2261 ;; A target still lead to a matching headline otherwise.
2263 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2264 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2265 (looking-at "\\* Head2")))
2266 ;; With a leading star in link, enforce heading match.
2268 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2269 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2270 (looking-at "\\* Test")))
2271 ;; With a leading star in link, enforce exact heading match, even
2272 ;; with `org-link-search-must-match-exact-headline' set to nil.
2274 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2275 (let ((org-link-search-must-match-exact-headline nil
))
2276 (org-open-at-point))))
2277 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2279 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2280 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2281 (looking-at "\\* Test")))
2283 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2284 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2285 (looking-at "\\* Test")))
2286 ;; Heading match should not care about spaces, cookies, TODO
2287 ;; keywords, priorities, and tags. However, TODO keywords are
2291 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2292 (org-test-with-temp-text
2293 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2294 (let ((org-link-search-must-match-exact-headline nil
)
2295 (org-todo-regexp "TODO"))
2296 (org-open-at-point))
2297 (looking-at (regexp-quote first-line
)))))
2299 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2300 (let ((org-link-search-must-match-exact-headline nil
)
2301 (org-todo-regexp "TODO"))
2302 (org-open-at-point))))
2303 ;; Heading match should still be exact.
2305 (org-test-with-temp-text "
2306 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2309 (let ((org-link-search-must-match-exact-headline nil
)
2310 (org-todo-regexp "TODO"))
2311 (org-open-at-point))))
2313 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2314 (let ((org-link-search-must-match-exact-headline nil
)
2315 (org-todo-regexp "TODO"))
2316 (org-open-at-point))
2317 (looking-at-p (regexp-quote "** Test 1 2"))))
2318 ;; Heading match ignores COMMENT keyword.
2320 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2322 (looking-at "\\* COMMENT Test")))
2324 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2326 (looking-at "\\* TODO COMMENT Test")))
2327 ;; Correctly un-hexify fuzzy links.
2329 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2333 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2336 ;; Match search strings containing newline characters, including
2339 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2340 (let ((file (buffer-file-name)))
2341 (goto-char (point-max))
2342 (insert (format "[[file:%s::line1 line2]]" file
))
2344 (let ((org-link-search-must-match-exact-headline nil
))
2345 (org-open-at-point 0))
2346 (looking-at-p "line1"))))
2348 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2349 (let ((file (buffer-file-name)))
2350 (goto-char (point-max))
2351 (insert (format "[[file:%s::line1 line2]]" file
))
2353 (let ((org-link-search-must-match-exact-headline nil
))
2354 (org-open-at-point 0))
2355 (looking-at-p "line1")))))
2359 (ert-deftest test-org
/org-link-escape-ascii-character
()
2360 "Escape an ascii character."
2364 (org-link-escape "["))))
2366 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2367 "Escape an ascii control character."
2371 (org-link-escape "\t"))))
2373 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2374 "Escape an unicode multibyte character."
2378 (org-link-escape "€"))))
2380 (ert-deftest test-org
/org-link-escape-custom-table
()
2381 "Escape string with custom character table."
2385 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2387 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2388 "Escape string with custom table merged with default table."
2391 "%5BF%6F%6F%3A%42ar%0A%5D"
2392 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2394 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2395 "Unescape an ascii character."
2399 (org-link-unescape "%5B"))))
2401 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2402 "Unescpae an ascii control character."
2406 (org-link-unescape "%0A"))))
2408 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2409 "Unescape unicode multibyte character."
2413 (org-link-unescape "%E2%82%AC"))))
2415 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2416 "Unescape old style percent escaped character."
2419 "à âçèéêîôùû"
2420 (decode-coding-string
2421 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2423 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2424 "Escape and unescape a URL that includes an escaped char.
2425 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2428 "http://some.host.com/form?&id=blah%2Bblah25"
2430 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2434 (ert-deftest test-org
/open-at-point
/keyword
()
2435 "Does `org-open-at-point' open link in a keyword line?"
2437 (org-test-with-temp-text
2438 "<<top>>\n#+KEYWORD: <point>[[top]]"
2439 (org-open-at-point) t
))
2441 (org-test-with-temp-text
2442 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2443 (org-open-at-point) t
)))
2445 (ert-deftest test-org
/open-at-point
/property
()
2446 "Does `org-open-at-point' open link in property drawer?"
2448 (org-test-with-temp-text
2451 :URL: <point>[[*Headline]]
2453 (org-open-at-point) t
)))
2455 (ert-deftest test-org
/open-at-point
/comment
()
2456 "Does `org-open-at-point' open link in a commented line?"
2458 (org-test-with-temp-text
2459 "<<top>>\n# <point>[[top]]"
2460 (org-open-at-point) t
))
2462 (org-test-with-temp-text
2463 "* H\n<<top>>\n# <point>[[top]]"
2464 (org-open-at-point) t
)))
2466 (ert-deftest test-org
/open-at-point
/inline-image
()
2467 "Test `org-open-at-point' on nested links."
2469 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2473 (ert-deftest test-org
/open-at-point
/radio-target
()
2474 "Test `org-open-at-point' on radio targets."
2476 (org-test-with-temp-text "<<<target>>> <point>target"
2477 (org-update-radio-target-regexp)
2479 (eq (org-element-type (org-element-context)) 'radio-target
))))
2481 (ert-deftest test-org
/open-at-point
/tag
()
2482 "Test `org-open-at-point' on tags."
2484 (org-test-with-temp-text "* H :<point>tag:"
2486 (cl-letf (((symbol-function 'org-tags-view
)
2487 (lambda (&rest args
) (throw :result t
))))
2491 (org-test-with-temp-text-in-file "* H<point> :tag:"
2493 (cl-letf (((symbol-function 'org-tags-view
)
2494 (lambda (&rest args
) (throw :result t
))))
2500 (ert-deftest test-org
/store-link
()
2501 "Test `org-store-link' specifications."
2502 ;; On a headline, link to that headline. Use heading as the
2503 ;; description of the link.
2505 (let (org-store-link-props org-stored-links
)
2506 (org-test-with-temp-text-in-file "* H1"
2507 (let ((file (buffer-file-name)))
2508 (equal (format "[[file:%s::*H1][H1]]" file
)
2509 (org-store-link nil
))))))
2510 ;; On a headline, remove any link from description.
2512 (let (org-store-link-props org-stored-links
)
2513 (org-test-with-temp-text-in-file "* [[#l][d]]"
2514 (let ((file (buffer-file-name)))
2515 (equal (format "[[file:%s::*%s][d]]"
2517 (org-link-escape "[[#l][d]]"))
2518 (org-store-link nil
))))))
2520 (let (org-store-link-props org-stored-links
)
2521 (org-test-with-temp-text-in-file "* [[l]]"
2522 (let ((file (buffer-file-name)))
2523 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2524 (org-store-link nil
))))))
2526 (let (org-store-link-props org-stored-links
)
2527 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2528 (let ((file (buffer-file-name)))
2529 (equal (format "[[file:%s::*%s][d1 d2]]"
2531 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2532 (org-store-link nil
))))))
2533 ;; On a named element, link to that element.
2535 (let (org-store-link-props org-stored-links
)
2536 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2537 (let ((file (buffer-file-name)))
2538 (equal (format "[[file:%s::foo][foo]]" file
)
2539 (org-store-link nil
))))))
2540 ;; Store link to Org buffer, with context.
2542 (let ((org-stored-links nil
)
2543 (org-id-link-to-org-use-id nil
)
2544 (org-context-in-file-links t
))
2545 (org-test-with-temp-text-in-file "* h1"
2546 (let ((file (buffer-file-name)))
2547 (equal (format "[[file:%s::*h1][h1]]" file
)
2548 (org-store-link nil
))))))
2549 ;; Store link to Org buffer, without context.
2551 (let ((org-stored-links nil
)
2552 (org-id-link-to-org-use-id nil
)
2553 (org-context-in-file-links nil
))
2554 (org-test-with-temp-text-in-file "* h1"
2555 (let ((file (buffer-file-name)))
2556 (equal (format "[[file:%s][file:%s]]" file file
)
2557 (org-store-link nil
))))))
2558 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2560 (let ((org-stored-links nil
)
2561 (org-id-link-to-org-use-id nil
)
2562 (org-context-in-file-links nil
))
2563 (org-test-with-temp-text-in-file "* h1"
2564 (let ((file (buffer-file-name)))
2565 (equal (format "[[file:%s::*h1][h1]]" file
)
2566 (org-store-link '(4)))))))
2567 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2570 (let ((org-stored-links nil
)
2571 (org-id-link-to-org-use-id nil
)
2572 (org-context-in-file-links nil
))
2573 (org-test-with-temp-text-in-file "* h1"
2574 (let ((file (buffer-file-name)))
2575 (equal (format "[[file:%s][file:%s]]" file file
)
2576 (org-store-link '(16)))))))
2577 ;; Store file link to non-Org buffer, with context.
2579 (let ((org-stored-links nil
)
2580 (org-context-in-file-links t
))
2581 (org-test-with-temp-text-in-file "one\n<point>two"
2583 (let ((file (buffer-file-name)))
2584 (equal (format "[[file:%s::one]]" file
)
2585 (org-store-link nil
))))))
2586 ;; Store file link to non-Org buffer, without context.
2588 (let ((org-stored-links nil
)
2589 (org-context-in-file-links nil
))
2590 (org-test-with-temp-text-in-file "one\n<point>two"
2592 (let ((file (buffer-file-name)))
2593 (equal (format "[[file:%s][file:%s]]" file file
)
2594 (org-store-link nil
))))))
2595 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2598 (let ((org-stored-links nil
)
2599 (org-context-in-file-links nil
))
2600 (org-test-with-temp-text-in-file "one\n<point>two"
2602 (let ((file (buffer-file-name)))
2603 (equal (format "[[file:%s::one]]" file
)
2604 (org-store-link '(4)))))))
2605 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2608 (let ((org-stored-links nil
)
2609 (org-context-in-file-links nil
))
2610 (org-test-with-temp-text-in-file "one\n<point>two"
2612 (let ((file (buffer-file-name)))
2613 (equal (format "[[file:%s][file:%s]]" file file
)
2614 (org-store-link '(16))))))))
2619 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2620 "Ensure properties accumulate in subtree drawers."
2621 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2622 (org-babel-next-src-block)
2623 (should (equal '(2 1) (org-babel-execute-src-block)))))
2625 (ert-deftest test-org
/custom-properties
()
2626 "Test custom properties specifications."
2629 (let ((org-custom-properties '("FOO")))
2630 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2631 (org-toggle-custom-properties-visibility)
2632 (org-invisible-p2))))
2633 ;; Properties are case-insensitive.
2635 (let ((org-custom-properties '("FOO")))
2636 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2637 (org-toggle-custom-properties-visibility)
2638 (org-invisible-p2))))
2640 (let ((org-custom-properties '("foo")))
2641 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2642 (org-toggle-custom-properties-visibility)
2643 (org-invisible-p2))))
2644 ;; Multiple custom properties in the same drawer.
2646 (let ((org-custom-properties '("FOO" "BAR")))
2647 (org-test-with-temp-text
2648 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2649 (org-toggle-custom-properties-visibility)
2650 (and (org-invisible-p2)
2651 (not (progn (forward-line) (org-invisible-p2)))
2652 (progn (forward-line) (org-invisible-p2))))))
2653 ;; Hide custom properties with an empty value.
2655 (let ((org-custom-properties '("FOO")))
2656 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2657 (org-toggle-custom-properties-visibility)
2658 (org-invisible-p2))))
2659 ;; Do not hide fake properties.
2661 (let ((org-custom-properties '("FOO")))
2662 (org-test-with-temp-text ":FOO: val\n"
2663 (org-toggle-custom-properties-visibility)
2664 (org-invisible-p2))))
2666 (let ((org-custom-properties '("A")))
2667 (org-test-with-temp-text
2668 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2669 (org-toggle-custom-properties-visibility)
2670 (org-invisible-p2)))))
2676 (ert-deftest test-org
/mark-subtree
()
2677 "Test `org-mark-subtree' specifications."
2678 ;; Error when point is before first headline.
2680 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2681 (progn (transient-mark-mode 1)
2682 (org-mark-subtree))))
2683 ;; Without argument, mark current subtree.
2687 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2688 (progn (transient-mark-mode 1)
2691 (list (region-beginning) (region-end))))))
2692 ;; With an argument, move ARG up.
2696 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2697 (progn (transient-mark-mode 1)
2699 (org-mark-subtree 1)
2700 (list (region-beginning) (region-end))))))
2701 ;; Do not get fooled by inlinetasks.
2702 (when (featurep 'org-inlinetask
)
2705 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2706 (progn (transient-mark-mode 1)
2708 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2709 (region-beginning)))))))
2715 (ert-deftest test-org
/sort-entries
()
2716 "Test `org-sort-entries'."
2717 ;; Sort alphabetically.
2719 (equal "\n* abc\n* def\n* xyz\n"
2720 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2721 (org-sort-entries nil ?a
)
2724 (equal "\n* xyz\n* def\n* abc\n"
2725 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2726 (org-sort-entries nil ?A
)
2728 ;; Sort numerically.
2730 (equal "\n* 1\n* 2\n* 10\n"
2731 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2732 (org-sort-entries nil ?n
)
2735 (equal "\n* 10\n* 2\n* 1\n"
2736 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2737 (org-sort-entries nil ?N
)
2739 ;; Sort by custom function.
2741 (equal "\n* b\n* aa\n* ccc\n"
2742 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2743 (org-sort-entries nil ?f
2745 (length (buffer-substring (point-at-bol)
2750 (equal "\n* ccc\n* aa\n* b\n"
2751 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2752 (org-sort-entries nil ?F
2754 (length (buffer-substring (point-at-bol)
2758 ;; Sort by TODO keyword.
2760 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2761 (org-test-with-temp-text
2762 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2763 (org-sort-entries nil ?o
)
2766 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2767 (org-test-with-temp-text
2768 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2769 (org-sort-entries nil ?O
)
2771 ;; Sort by priority.
2773 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2774 (org-test-with-temp-text
2775 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2776 (org-sort-entries nil ?p
)
2779 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2780 (org-test-with-temp-text
2781 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2782 (org-sort-entries nil ?P
)
2784 ;; Sort by creation time.
2794 (org-test-with-temp-text
2803 (org-sort-entries nil ?c
)
2806 ;; Sort by scheduled date.
2810 SCHEDULED: <2017-05-06 Sat>
2812 SCHEDULED: <2017-05-08 Mon>
2814 DEADLINE: <2017-05-09 Tue>
2816 DEADLINE: <2017-05-07 Sun>
2818 (org-test-with-temp-text
2821 DEADLINE: <2017-05-09 Tue>
2823 DEADLINE: <2017-05-07 Sun>
2825 SCHEDULED: <2017-05-08 Mon>
2827 SCHEDULED: <2017-05-06 Sat>
2829 (org-sort-entries nil ?s
)
2831 ;; Sort by deadline date.
2835 DEADLINE: <2017-05-07 Sun>
2837 DEADLINE: <2017-05-09 Tue>
2839 SCHEDULED: <2017-05-08 Mon>
2841 SCHEDULED: <2017-05-06 Sat>
2843 (org-test-with-temp-text
2846 DEADLINE: <2017-05-09 Tue>
2848 DEADLINE: <2017-05-07 Sun>
2850 SCHEDULED: <2017-05-08 Mon>
2852 SCHEDULED: <2017-05-06 Sat>
2854 (org-sort-entries nil ?d
)
2856 ;; Sort by any date/time
2860 SCHEDULED: <2017-05-06 Sat>
2862 DEADLINE: <2017-05-07 Sun>
2864 SCHEDULED: <2017-05-08 Mon>
2866 DEADLINE: <2017-05-09 Tue>
2868 (org-test-with-temp-text
2871 DEADLINE: <2017-05-09 Tue>
2873 DEADLINE: <2017-05-07 Sun>
2875 SCHEDULED: <2017-05-08 Mon>
2877 SCHEDULED: <2017-05-06 Sat>
2879 (org-sort-entries nil ?t
)
2881 ;; Sort by clocking time.
2886 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2887 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2891 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2892 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2895 (org-test-with-temp-text
2899 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2900 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2904 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2905 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2908 (org-sort-entries nil ?k
)
2911 (ert-deftest test-org
/file-contents
()
2912 "Test `org-file-contents' specifications."
2915 (string= "#+BIND: variable value
2921 " (org-file-contents (expand-file-name "setupfile3.org"
2922 (concat org-test-dir
"examples/")))))
2923 ;; Throw error when trying to access an invalid file.
2924 (should-error (org-file-contents "this-file-must-not-exist"))
2925 ;; Try to access an invalid file, but do not throw an error.
2927 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2931 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2933 ;; Simulate successful retrieval of a URL.
2934 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2936 (with-current-buffer buffer
2937 (insert "HTTP/1.1 200 OK\n\nfoo"))
2939 (org-file-contents "http://some-valid-url"))
2940 (kill-buffer buffer
)))))
2941 ;; Throw error when trying to access an invalid URL.
2943 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2945 ;; Simulate unsuccessful retrieval of a URL.
2946 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2948 (with-current-buffer buffer
2949 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2951 (org-file-contents "http://this-url-must-not-exist"))
2952 (kill-buffer buffer
))))
2953 ;; Try to access an invalid URL, but do not throw an error.
2955 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2957 ;; Simulate unsuccessful retrieval of a URL.
2958 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2960 (with-current-buffer buffer
2961 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2963 (org-file-contents "http://this-url-must-not-exist"))
2964 (kill-buffer buffer
))))
2966 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2968 ;; Simulate unsuccessful retrieval of a URL.
2969 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2971 (with-current-buffer buffer
2972 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2974 (org-file-contents "http://this-url-must-not-exist" :noerror
))
2975 (kill-buffer buffer
))
2981 (ert-deftest test-org
/forward-heading-same-level
()
2982 "Test `org-forward-heading-same-level' specifications."
2983 ;; Test navigation at top level, forward and backward.
2986 (org-test-with-temp-text "* H1\n* H2"
2987 (org-forward-heading-same-level 1)
2988 (buffer-substring-no-properties (point) (line-end-position)))))
2991 (org-test-with-temp-text "* H1\n<point>* H2"
2992 (org-forward-heading-same-level -
1)
2993 (buffer-substring-no-properties (point) (line-end-position)))))
2994 ;; Test navigation in a sub-tree, forward and backward.
2997 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2998 (org-forward-heading-same-level 1)
2999 (buffer-substring-no-properties (point) (line-end-position)))))
3002 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3003 (org-forward-heading-same-level -
1)
3004 (buffer-substring-no-properties (point) (line-end-position)))))
3005 ;; Stop at first or last sub-heading.
3008 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3009 (org-forward-heading-same-level 1)
3010 (buffer-substring-no-properties (point) (line-end-position)))))
3013 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3014 (org-forward-heading-same-level -
1)
3015 (buffer-substring-no-properties (point) (line-end-position)))))
3016 ;; Allow multiple moves.
3019 (org-test-with-temp-text "* H1\n* H2\n* H3"
3020 (org-forward-heading-same-level 2)
3021 (buffer-substring-no-properties (point) (line-end-position)))))
3024 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3025 (org-forward-heading-same-level -
2)
3026 (buffer-substring-no-properties (point) (line-end-position)))))
3027 ;; Ignore spurious moves when first (or last) sibling is reached.
3030 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3031 (org-forward-heading-same-level 100)
3032 (buffer-substring-no-properties (point) (line-end-position)))))
3035 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3036 (org-forward-heading-same-level -
100)
3037 (buffer-substring-no-properties (point) (line-end-position))))))
3039 (ert-deftest test-org
/end-of-meta-data
()
3040 "Test `org-end-of-meta-data' specifications."
3041 ;; Skip planning line.
3043 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3044 (org-end-of-meta-data)
3046 ;; Skip properties drawer.
3048 (org-test-with-temp-text
3049 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3050 (org-end-of-meta-data)
3054 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3055 (org-end-of-meta-data)
3057 ;; Nothing to skip, go to first line.
3059 (org-test-with-temp-text "* Headline\nContents"
3060 (org-end-of-meta-data)
3061 (looking-at "Contents")))
3062 ;; With option argument, skip empty lines, regular drawers and
3065 (org-test-with-temp-text "* Headline\n\nContents"
3066 (org-end-of-meta-data t
)
3067 (looking-at "Contents")))
3069 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3070 (org-end-of-meta-data t
)
3071 (looking-at "Contents")))
3073 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3074 (org-end-of-meta-data t
)
3075 (looking-at "Contents")))
3076 ;; Special case: do not skip incomplete drawers.
3078 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3079 (org-end-of-meta-data t
)
3080 (looking-at ":LOGBOOK:")))
3081 ;; Special case: Be careful about consecutive headlines.
3083 (org-test-with-temp-text "* H1\n*H2\nContents"
3084 (org-end-of-meta-data t
)
3085 (looking-at "Contents"))))
3087 (ert-deftest test-org
/beginning-of-line
()
3088 "Test `org-beginning-of-line' specifications."
3089 ;; Move to beginning of line. If current line in invisible, move to
3090 ;; beginning of visible line instead.
3092 (org-test-with-temp-text "Some text\nSome other text<point>"
3093 (org-beginning-of-line)
3096 (org-test-with-temp-text "* H1\n** H2<point>"
3098 (org-beginning-of-line)
3099 (= (line-beginning-position) 1)))
3100 ;; With `visual-line-mode' active, move to beginning of visual line.
3102 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3104 (dotimes (i 1000) (insert "very "))
3105 (org-beginning-of-line)
3107 ;; In a wide headline, with `visual-line-mode', prefer going to the
3108 ;; beginning of a visual line than to the logical beginning of line,
3109 ;; even if special movement is active.
3111 (org-test-with-temp-text "* A <point>long headline"
3113 (dotimes (i 1000) (insert "very "))
3114 (goto-char (point-max))
3115 (org-beginning-of-line)
3118 (org-test-with-temp-text "* A <point>long headline"
3120 (dotimes (i 1000) (insert "very "))
3121 (goto-char (point-max))
3122 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3124 ;; At an headline with special movement, first move at beginning of
3125 ;; title, then at the beginning of line, rinse, repeat.
3127 (org-test-with-temp-text "* TODO Headline<point>"
3128 (let ((org-special-ctrl-a/e t
))
3129 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3130 (progn (org-beginning-of-line) (bolp))
3131 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3133 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3134 (let ((org-special-ctrl-a/e t
))
3135 (org-beginning-of-line)
3136 (looking-at "Headline"))))
3138 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3139 (let ((org-special-ctrl-a/e
'(t . nil
)))
3140 (org-beginning-of-line)
3141 (looking-at "Headline"))))
3143 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3144 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3145 (org-beginning-of-line)
3146 (looking-at "Headline"))))
3147 ;; At an headline with reversed movement, first move to beginning of
3148 ;; line, then to the beginning of title.
3150 (org-test-with-temp-text "* TODO Headline<point>"
3151 (let ((org-special-ctrl-a/e
'reversed
)
3152 (this-command last-command
))
3153 (and (progn (org-beginning-of-line) (bolp))
3154 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3156 (org-test-with-temp-text "* TODO Headline<point>"
3157 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3158 (this-command last-command
))
3159 (and (progn (org-beginning-of-line) (bolp))
3160 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3162 (org-test-with-temp-text "* TODO Headline<point>"
3163 (let ((org-special-ctrl-a/e
'(t . nil
))
3164 (this-command last-command
))
3165 (and (progn (org-beginning-of-line) (bolp))
3166 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3167 ;; At an item with special movement, first move after to beginning
3168 ;; of title, then to the beginning of line, rinse, repeat.
3170 (org-test-with-temp-text "- [ ] Item<point>"
3171 (let ((org-special-ctrl-a/e t
))
3172 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3173 (progn (org-beginning-of-line) (bolp))
3174 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3175 ;; At an item with reversed movement, first move to beginning of
3176 ;; line, then to the beginning of title.
3178 (org-test-with-temp-text "- [X] Item<point>"
3179 (let ((org-special-ctrl-a/e
'reversed
)
3180 (this-command last-command
))
3181 (and (progn (org-beginning-of-line) (bolp))
3182 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3183 ;; Leave point before invisible characters at column 0.
3185 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3186 (let ((org-special-ctrl-a/e nil
))
3187 (org-beginning-of-line)
3190 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3191 (let ((org-special-ctrl-a/e t
))
3192 (org-beginning-of-line)
3195 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3197 (org-beginning-of-line)
3199 ;; Special case: Do not error when the buffer contains only a single
3202 (org-test-with-temp-text "*<point>"
3203 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3205 (org-test-with-temp-text "*<point>"
3206 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3208 (ert-deftest test-org
/end-of-line
()
3209 "Test `org-end-of-line' specifications."
3212 (org-test-with-temp-text "Some text\nSome other text"
3215 ;; With `visual-line-mode' active, move to end of visible line.
3216 ;; However, never go past ellipsis.
3218 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3220 (dotimes (i 1000) (insert "very "))
3221 (goto-char (point-min))
3225 (org-test-with-temp-text "* A short headline\nSome contents"
3230 ;; In a wide headline, with `visual-line-mode', prefer going to end
3231 ;; of visible line if tags, or end of line, are farther.
3233 (org-test-with-temp-text "* A <point>long headline"
3235 (dotimes (i 1000) (insert "very "))
3236 (goto-char (point-min))
3240 (org-test-with-temp-text "* A <point>long headline :tag:"
3242 (dotimes (i 1000) (insert "very "))
3243 (goto-char (point-min))
3246 ;; At an headline without special movement, go to end of line.
3247 ;; However, never go past ellipsis.
3249 (org-test-with-temp-text "* Headline2b :tag:\n"
3250 (let ((org-special-ctrl-a/e nil
))
3251 (and (progn (org-end-of-line) (eolp))
3252 (progn (org-end-of-line) (eolp))))))
3254 (org-test-with-temp-text "* Headline2b :tag:\n"
3255 (let ((org-special-ctrl-a/e
'(t . nil
)))
3256 (and (progn (org-end-of-line) (eolp))
3257 (progn (org-end-of-line) (eolp))))))
3259 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3261 (let ((org-special-ctrl-a/e nil
))
3263 (= 1 (line-beginning-position)))))
3264 ;; At an headline with special movement, first move before tags,
3265 ;; then at the end of line, rinse, repeat. However, never go past
3268 (org-test-with-temp-text "* Headline1 :tag:\n"
3269 (let ((org-special-ctrl-a/e t
))
3270 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3271 (progn (org-end-of-line) (eolp))
3272 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3274 (org-test-with-temp-text "* Headline1 :tag:\n"
3275 (let ((org-special-ctrl-a/e
'(nil . t
)))
3276 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3277 (progn (org-end-of-line) (eolp))
3278 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3280 (org-test-with-temp-text "* Headline1 :tag:\n"
3281 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3282 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3283 (progn (org-end-of-line) (eolp))
3284 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3286 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3288 (let ((org-special-ctrl-a/e t
))
3291 (= 1 (line-beginning-position)))))
3292 ;; At an headline, with reversed movement, first go to end of line,
3293 ;; then before tags. However, never go past ellipsis.
3295 (org-test-with-temp-text "* Headline3 :tag:\n"
3296 (let ((org-special-ctrl-a/e
'reversed
)
3297 (this-command last-command
))
3298 (and (progn (org-end-of-line) (eolp))
3299 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3301 (org-test-with-temp-text "* Headline3 :tag:\n"
3302 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3303 (this-command last-command
))
3304 (and (progn (org-end-of-line) (eolp))
3305 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3307 (org-test-with-temp-text "* Headline3 :tag:\n"
3308 (let ((org-special-ctrl-a/e
'(nil . t
))
3309 (this-command last-command
))
3310 (and (progn (org-end-of-line) (eolp))
3311 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3313 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3315 (let ((org-special-ctrl-a/e
'reversed
))
3317 (= 1 (line-beginning-position)))))
3318 ;; At a block without hidden contents.
3320 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3321 (progn (org-end-of-line) (eolp))))
3322 ;; At a block with hidden contents.
3324 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3325 (let ((org-special-ctrl-a/e t
))
3326 (org-hide-block-toggle)
3329 ;; Get past invisible characters at the end of line.
3331 (org-test-with-temp-text "[[http://orgmode.org]]"
3335 (ert-deftest test-org
/open-line
()
3336 "Test `org-open-line' specifications."
3337 ;; Call `open-line' outside of tables.
3340 (org-test-with-temp-text "Text"
3343 ;; At a table, create a row above.
3345 (equal "\n| |\n| a |"
3346 (org-test-with-temp-text "\n<point>| a |"
3349 ;; At the very first character of the buffer, also call `open-line'.
3352 (org-test-with-temp-text "| a |"
3355 ;; Narrowing does not count.
3357 (equal "Text\n| |\n| a |"
3358 (org-test-with-temp-text "Text\n<point>| a |"
3359 (narrow-to-region (point) (point-max))
3364 (ert-deftest test-org
/forward-sentence
()
3365 "Test `org-forward-sentence' specifications."
3366 ;; At the end of a table cell, move to the end of the next one.
3368 (org-test-with-temp-text "| a<point> | b |"
3369 (org-forward-sentence)
3370 (looking-at " |$")))
3371 ;; Elsewhere in a cell, move to its end.
3373 (org-test-with-temp-text "| a<point>c | b |"
3374 (org-forward-sentence)
3375 (looking-at " | b |$")))
3376 ;; Otherwise, simply call `forward-sentence'.
3378 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3379 (org-forward-sentence)
3380 (looking-at " Sentence 2.")))
3382 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3383 (org-forward-sentence)
3384 (org-forward-sentence)
3386 ;; At the end of an element, jump to the next one, without stopping
3387 ;; on blank lines in-between.
3389 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3390 (org-forward-sentence)
3392 ;; Headlines are considered to be sentences by themselves, even if
3393 ;; they do not end with a full stop.
3397 (org-test-with-temp-text "* <point>Headline\nSentence."
3398 (org-forward-sentence)
3399 (buffer-substring-no-properties (line-beginning-position) (point)))))
3401 (org-test-with-temp-text "* Headline<point>\nSentence."
3402 (org-forward-sentence)
3405 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3406 (org-forward-sentence)
3407 (and (org-at-heading-p) (eolp)))))
3409 (ert-deftest test-org
/backward-sentence
()
3410 "Test `org-backward-sentence' specifications."
3411 ;; At the beginning of a table cell, move to the beginning of the
3414 (org-test-with-temp-text "| a | <point>b |"
3415 (org-backward-sentence)
3416 (looking-at "a | b |$")))
3417 ;; Elsewhere in a cell, move to its beginning.
3419 (org-test-with-temp-text "| a | b<point>c |"
3420 (org-backward-sentence)
3421 (looking-at "bc |$")))
3422 ;; Otherwise, simply call `backward-sentence'.
3424 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3425 (org-backward-sentence)
3426 (looking-at "Sentence 2.")))
3428 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3429 (org-backward-sentence)
3430 (org-backward-sentence)
3432 ;; Make sure to hit the beginning of a sentence on the same line as
3435 (org-test-with-temp-text "- Line 1\n line <point>2."
3436 (org-backward-sentence)
3437 (looking-at "Line 1"))))
3439 (ert-deftest test-org
/forward-paragraph
()
3440 "Test `org-forward-paragraph' specifications."
3441 ;; At end of buffer, do not return an error.
3443 (org-test-with-temp-text "Paragraph"
3444 (goto-char (point-max))
3445 (org-forward-paragraph)
3449 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3450 (org-forward-paragraph)
3454 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3455 (org-forward-paragraph)
3457 ;; Do not enter elements with invisible contents.
3459 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3460 (org-hide-block-toggle)
3461 (org-forward-paragraph)
3463 ;; On an affiliated keyword, jump to the beginning of the element.
3465 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3466 (org-forward-paragraph)
3467 (looking-at "Para")))
3468 ;; On an item or a footnote definition, move to the second element
3471 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3472 (org-forward-paragraph)
3473 (looking-at " Paragraph")))
3475 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3476 (org-forward-paragraph)
3477 (looking-at "Paragraph")))
3478 ;; On an item, or a footnote definition, when the first line is
3479 ;; empty, move to the first item.
3481 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3482 (org-forward-paragraph)
3483 (looking-at " Paragraph")))
3485 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3486 (org-forward-paragraph)
3487 (looking-at "Paragraph")))
3488 ;; On a table (resp. a property drawer) do not move through table
3489 ;; rows (resp. node properties).
3491 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3492 (org-forward-paragraph)
3493 (looking-at "Paragraph")))
3495 (org-test-with-temp-text
3496 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3497 (org-forward-paragraph)
3498 (looking-at "Paragraph")))
3499 ;; On a verse or source block, stop after blank lines.
3501 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3502 (org-forward-paragraph)
3505 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3506 (org-forward-paragraph)
3507 (looking-at "L2"))))
3509 (ert-deftest test-org
/backward-paragraph
()
3510 "Test `org-backward-paragraph' specifications."
3511 ;; Do not error at beginning of buffer.
3513 (org-test-with-temp-text "Paragraph"
3514 (org-backward-paragraph)
3518 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3519 (org-backward-paragraph)
3522 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3523 (org-backward-paragraph)
3524 (looking-at-p "P2")))
3527 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3528 (org-backward-paragraph)
3529 (looking-at-p "P2")))
3530 ;; Ignore invisible elements.
3532 (org-test-with-temp-text "* H1\n P1\n* H2"
3534 (goto-char (point-max))
3536 (org-backward-paragraph)
3538 ;; On an affiliated keyword, jump to the first one.
3540 (org-test-with-temp-text
3541 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3542 (org-backward-paragraph)
3543 (looking-at-p "#\\+name")))
3544 ;; On the second element in an item or a footnote definition, jump
3545 ;; to item or the definition.
3547 (org-test-with-temp-text "- line1\n\n<point> line2"
3548 (org-backward-paragraph)
3549 (looking-at-p "- line1")))
3551 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3552 (org-backward-paragraph)
3553 (looking-at-p "\\[fn:1\\] line1")))
3554 ;; On a table (resp. a property drawer), ignore table rows
3555 ;; (resp. node properties).
3557 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3558 (org-backward-paragraph)
3561 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3562 (org-backward-paragraph)
3563 (looking-at-p ":PROPERTIES:")))
3564 ;; On a comment, example, src and verse blocks, stop before blank
3567 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3568 (org-backward-paragraph)
3569 (looking-at-p "L2")))
3571 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3572 (org-backward-paragraph)
3573 (looking-at-p "L2")))
3574 ;; In comment, example, export, src and verse blocks, stop below
3575 ;; opening line when called from within the block.
3577 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3578 (org-backward-paragraph)
3579 (looking-at-p "L1")))
3581 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3582 (org-backward-paragraph)
3583 (looking-at-p "L1")))
3584 ;; When called from the opening line itself, however, move to
3585 ;; beginning of block.
3587 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3588 (org-backward-paragraph)
3590 ;; Pathological case: on an empty heading, move to its beginning.
3592 (org-test-with-temp-text "* <point>H"
3593 (org-backward-paragraph)
3596 (ert-deftest test-org
/forward-element
()
3597 "Test `org-forward-element' specifications."
3598 ;; 1. At EOB: should error.
3599 (org-test-with-temp-text "Some text\n"
3600 (goto-char (point-max))
3601 (should-error (org-forward-element)))
3602 ;; 2. Standard move: expected to ignore blank lines.
3603 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3604 (org-forward-element)
3605 (should (looking-at (regexp-quote "Second paragraph."))))
3606 ;; 3. Headline tests.
3607 (org-test-with-temp-text "
3612 ;; 3.1. At an headline beginning: move to next headline at the
3615 (org-forward-element)
3616 (should (looking-at (regexp-quote "** Head 1.2")))
3617 ;; 3.2. At an headline beginning: move to parent headline if no
3618 ;; headline at the same level.
3620 (org-forward-element)
3621 (should (looking-at (regexp-quote "** Head 1.2"))))
3622 ;; 4. Greater element tests.
3623 (org-test-with-temp-text
3624 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3625 ;; 4.1. At a greater element: expected to skip contents.
3626 (org-forward-element)
3627 (should (looking-at (regexp-quote "Outside.")))
3628 ;; 4.2. At the end of greater element contents: expected to skip
3629 ;; to the end of the greater element.
3631 (org-forward-element)
3632 (should (looking-at (regexp-quote "Outside."))))
3634 (org-test-with-temp-text "
3648 ;; 5.1. At list top point: expected to move to the element after
3651 (org-forward-element)
3652 (should (looking-at (regexp-quote "Outside.")))
3653 ;; 5.2. Special case: at the first line of a sub-list, but not at
3654 ;; beginning of line, move to next item.
3657 (org-forward-element)
3658 (should (looking-at "- item2"))
3661 (org-forward-element)
3662 (should (looking-at " - sub2"))
3663 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3665 (org-forward-element)
3666 (should (looking-at (regexp-quote " Inner paragraph.")))
3667 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3669 (org-forward-element)
3670 (should (looking-at (regexp-quote " Inner paragraph.")))
3671 ;; 5.5. At an item: expected to move to next item, if any.
3673 (org-forward-element)
3674 (should (looking-at " - sub3"))))
3676 (ert-deftest test-org
/backward-element
()
3677 "Test `org-backward-element' specifications."
3678 ;; 1. Should error at BOB.
3679 (org-test-with-temp-text " \nParagraph."
3680 (should-error (org-backward-element)))
3681 ;; 2. Should move at BOB when called on the first element in buffer.
3683 (org-test-with-temp-text "\n#+TITLE: test"
3684 (progn (forward-line)
3685 (org-backward-element)
3687 ;; 3. Not at the beginning of an element: move at its beginning.
3688 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3691 (org-backward-element)
3692 (should (looking-at (regexp-quote "Paragraph2."))))
3693 ;; 4. Headline tests.
3694 (org-test-with-temp-text "
3699 ;; 4.1. At an headline beginning: move to previous headline at the
3702 (org-backward-element)
3703 (should (looking-at (regexp-quote "** Head 1.1")))
3704 ;; 4.2. At an headline beginning: move to parent headline if no
3705 ;; headline at the same level.
3707 (org-backward-element)
3708 (should (looking-at (regexp-quote "* Head 1")))
3709 ;; 4.3. At the first top-level headline: should error.
3711 (should-error (org-backward-element)))
3712 ;; 5. At beginning of first element inside a greater element:
3713 ;; expected to move to greater element's beginning.
3714 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3716 (org-backward-element)
3717 (should (looking-at "#\\+BEGIN_CENTER")))
3718 ;; 6. At the beginning of the first element in a section: should
3719 ;; move back to headline, if any.
3721 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3722 (progn (goto-char (point-max))
3724 (org-backward-element)
3725 (org-at-heading-p))))
3727 (org-test-with-temp-text "
3742 ;; 7.1. At beginning of sub-list: expected to move to the
3743 ;; paragraph before it.
3745 (org-backward-element)
3746 (should (looking-at "item1"))
3747 ;; 7.2. At an item in a list: expected to move at previous item.
3749 (org-backward-element)
3750 (should (looking-at " - sub2"))
3752 (org-backward-element)
3753 (should (looking-at "- item1"))
3754 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3757 (org-backward-element)
3758 (should (looking-at " - sub1"))
3760 (org-backward-element)
3761 (should (looking-at "- item1"))
3762 ;; 7.4. At blank-lines before list end: expected to move to top
3765 (org-backward-element)
3766 (should (looking-at "- item1"))))
3768 (ert-deftest test-org
/up-element
()
3769 "Test `org-up-element' specifications."
3770 ;; 1. At BOB or with no surrounding element: should error.
3771 (org-test-with-temp-text "Paragraph."
3772 (should-error (org-up-element)))
3773 (org-test-with-temp-text "* Head1\n* Head2"
3775 (should-error (org-up-element)))
3776 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3778 (should-error (org-up-element)))
3779 ;; 2. At an headline: move to parent headline.
3780 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3783 (should (looking-at "\\* Head1")))
3784 ;; 3. Inside a greater element: move to greater element beginning.
3785 (org-test-with-temp-text
3786 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3789 (should (looking-at "#\\+BEGIN_CENTER")))
3791 (org-test-with-temp-text "* Top
3798 Paragraph within sub2.
3801 ;; 4.1. Within an item: move to the item beginning.
3804 (should (looking-at " - sub2"))
3805 ;; 4.2. At an item in a sub-list: move to parent item.
3808 (should (looking-at "- item1"))
3809 ;; 4.3. At an item in top list: move to beginning of whole list.
3812 (should (looking-at "- item1"))
3813 ;; 4.4. Special case. At very top point: should move to parent of
3817 (should (looking-at "\\* Top"))))
3819 (ert-deftest test-org
/down-element
()
3820 "Test `org-down-element' specifications."
3821 ;; Error when the element hasn't got a recursive type.
3822 (org-test-with-temp-text "Paragraph."
3823 (should-error (org-down-element)))
3824 ;; Error when the element has no contents
3825 (org-test-with-temp-text "* Headline"
3826 (should-error (org-down-element)))
3827 ;; When at a plain-list, move to first item.
3828 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3831 (should (looking-at " - Item 1.1")))
3832 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3834 (should (looking-at " Item 1")))
3835 ;; When at a table, move to first row
3836 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3838 (should (looking-at " a | b |")))
3839 ;; Otherwise, move inside the greater element.
3840 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3842 (should (looking-at "Paragraph"))))
3844 (ert-deftest test-org
/drag-element-backward
()
3845 "Test `org-drag-element-backward' specifications."
3849 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3850 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3851 (org-drag-element-backward)
3855 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3856 (org-test-with-temp-text
3857 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3858 (org-drag-element-backward)
3860 ;; Preserve blank lines.
3862 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3863 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3864 (org-drag-element-backward)
3868 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3869 (org-drag-element-backward)
3870 (looking-at-p "2")))
3871 ;; Error when trying to move first element of buffer.
3873 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3874 (org-drag-element-backward))
3876 ;; Error when trying to swap nested elements.
3878 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3879 (org-drag-element-backward))
3881 ;; Error when trying to swap an headline element and a non-headline
3884 (org-test-with-temp-text "Test.\n<point>* Head 1"
3885 (org-drag-element-backward))
3887 ;; Error when called before first element.
3889 (org-test-with-temp-text "\n<point>"
3890 (org-drag-element-backward))
3892 ;; Preserve visibility of elements and their contents.
3894 (equal '((63 .
82) (26 .
48))
3895 (org-test-with-temp-text "
3903 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3904 (search-backward "- item 1")
3905 (org-drag-element-backward)
3906 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3907 (overlays-in (point-min) (point-max))))))
3908 ;; Pathological case: handle call with point in blank lines right
3909 ;; after a headline.
3911 (equal "* H2\n* H1\nText\n\n"
3912 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3913 (org-drag-element-backward)
3916 (ert-deftest test-org
/drag-element-forward
()
3917 "Test `org-drag-element-forward' specifications."
3918 ;; 1. Error when trying to move first element of buffer.
3919 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3921 (should-error (org-drag-element-forward)))
3922 ;; 2. Error when trying to swap nested elements.
3923 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3925 (should-error (org-drag-element-forward)))
3926 ;; 3. Error when trying to swap a non-headline element and an
3928 (org-test-with-temp-text "Test.\n* Head 1"
3929 (should-error (org-drag-element-forward)))
3930 ;; 4. Error when called before first element.
3932 (org-test-with-temp-text "\n"
3934 (org-drag-element-backward))
3936 ;; 5. Otherwise, swap elements, preserving column and blank lines
3937 ;; between elements.
3938 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3939 (search-forward "graph")
3940 (org-drag-element-forward)
3941 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3942 (should (looking-at " 1")))
3943 ;; 5. Preserve visibility of elements and their contents.
3944 (org-test-with-temp-text "
3952 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3953 (search-backward "#+BEGIN_CENTER")
3954 (org-drag-element-forward)
3957 '((63 .
82) (26 .
48))
3958 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3959 (overlays-in (point-min) (point-max)))))))
3961 (ert-deftest test-org
/next-block
()
3962 "Test `org-next-block' specifications."
3965 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3967 (looking-at "#\\+BEGIN_CENTER")))
3970 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3971 (let ((case-fold-search nil
))
3973 (looking-at "#\\+begin_center"))))
3974 ;; Ignore current line.
3976 (org-test-with-temp-text
3977 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3979 (looking-at "#\\+BEGIN_CENTER")))
3980 ;; Throw an error when no block is found.
3982 (org-test-with-temp-text "Paragraph"
3983 (org-next-block 1)))
3984 ;; With an argument, skip many blocks at once.
3986 (org-test-with-temp-text
3987 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3989 (looking-at "#\\+BEGIN_QUOTE")))
3990 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3992 (org-test-with-temp-text
3993 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3994 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3995 (looking-at "#\\+BEGIN_QUOTE")))
3996 ;; Optional argument is also case-insensitive.
3998 (org-test-with-temp-text
3999 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4000 (let ((case-fold-search nil
))
4001 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4002 (looking-at "#\\+begin_quote")))))
4004 (ert-deftest test-org
/insert-template
()
4005 "Test `org-insert-structure-template'."
4006 ;; Test in empty buffer.
4008 (string= "#+begin_foo\n#+end_foo\n"
4009 (org-test-with-temp-text ""
4010 (org-insert-structure-template "foo")
4012 ;; Test with multiple lines in buffer.
4014 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
4015 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4017 (org-insert-structure-template "foo")
4019 ;; Test with text in buffer, no region, no final newline.
4021 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
4022 (org-test-with-temp-text "I'm a paragraph."
4024 (org-insert-structure-template "foo")
4026 ;; Test with text in buffer and region set.
4028 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
4029 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
4031 (goto-char (point-max))
4032 (org-insert-structure-template "foo")
4034 ;; Test with example escaping.
4036 (string= "#+begin_example\n,* Heading\n#+end_example\n"
4037 (org-test-with-temp-text "* Heading"
4039 (org-insert-structure-template "example")
4041 ;; Test with indentation.
4043 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
4044 (org-test-with-temp-text " This is a paragraph"
4046 (org-insert-structure-template "foo")
4049 (ert-deftest test-org
/previous-block
()
4050 "Test `org-previous-block' specifications."
4053 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4054 (org-previous-block 1)
4055 (looking-at "#\\+BEGIN_CENTER")))
4058 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4059 (let ((case-fold-search nil
))
4060 (org-previous-block 1)
4061 (looking-at "#\\+begin_center"))))
4062 ;; Ignore current line.
4064 (org-test-with-temp-text
4065 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4066 (org-previous-block 1)
4067 (looking-at "#\\+BEGIN_QUOTE")))
4068 ;; Throw an error when no block is found.
4070 (org-test-with-temp-text "Paragraph<point>"
4071 (org-previous-block 1)))
4072 ;; With an argument, skip many blocks at once.
4074 (org-test-with-temp-text
4075 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4076 (org-previous-block 2)
4077 (looking-at "#\\+BEGIN_CENTER")))
4078 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4080 (org-test-with-temp-text
4081 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4082 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4083 (looking-at "#\\+BEGIN_QUOTE")))
4084 ;; Optional argument is also case-insensitive.
4086 (org-test-with-temp-text
4087 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4088 (let ((case-fold-search nil
))
4089 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4090 (looking-at "#\\+begin_quote")))))
4093 ;;; Outline structure
4095 (ert-deftest test-org
/demote
()
4096 "Test `org-demote' specifications."
4097 ;; Add correct number of stars according to `org-odd-levels-only'.
4100 (org-test-with-temp-text "* H"
4101 (let ((org-odd-levels-only nil
)) (org-demote))
4102 (org-current-level))))
4105 (org-test-with-temp-text "* H"
4106 (let ((org-odd-levels-only t
)) (org-demote))
4107 (org-current-level))))
4108 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4110 (org-test-with-temp-text "* H :tag:"
4111 (let ((org-tags-column 10)
4112 (org-auto-align-tags t
)
4113 (org-odd-levels-only nil
))
4115 (org-move-to-column 10)
4116 (looking-at-p ":tag:$")))
4118 (org-test-with-temp-text "* H :tag:"
4119 (let ((org-tags-column 10)
4120 (org-auto-align-tags nil
)
4121 (org-odd-levels-only nil
))
4123 (org-move-to-column 10)
4124 (looking-at-p ":tag:$")))
4125 ;; When `org-adapt-indentation' is non-nil, always indent planning
4126 ;; info and property drawers accordingly.
4129 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4130 (let ((org-odd-levels-only nil
)
4131 (org-adapt-indentation t
))
4134 (org-get-indentation))))
4137 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4138 (let ((org-odd-levels-only nil
)
4139 (org-adapt-indentation t
))
4142 (org-get-indentation))))
4145 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4146 (let ((org-odd-levels-only nil
)
4147 (org-adapt-indentation nil
))
4150 (org-get-indentation))))
4151 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4152 ;; section accordingly. Ignore, however, footnote definitions and
4153 ;; inlinetasks boundaries.
4156 (org-test-with-temp-text "* H\n Paragraph"
4157 (let ((org-odd-levels-only nil
)
4158 (org-adapt-indentation t
))
4161 (org-get-indentation))))
4164 (org-test-with-temp-text "* H\n Paragraph"
4165 (let ((org-odd-levels-only nil
)
4166 (org-adapt-indentation nil
))
4169 (org-get-indentation))))
4172 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4173 (let ((org-odd-levels-only nil
)
4174 (org-adapt-indentation t
))
4176 (goto-char (point-max))
4177 (org-get-indentation))))
4180 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4181 (let ((org-odd-levels-only nil
)
4182 (org-adapt-indentation t
))
4184 (goto-char (point-max))
4185 (org-get-indentation))))
4186 (when (featurep 'org-inlinetask
)
4189 (let ((org-inlinetask-min-level 5)
4190 (org-adapt-indentation t
))
4191 (org-test-with-temp-text "* H\n***** I\n***** END"
4194 (org-get-indentation))))))
4195 (when (featurep 'org-inlinetask
)
4198 (let ((org-inlinetask-min-level 5)
4199 (org-adapt-indentation t
))
4200 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4203 (org-get-indentation))))))
4204 ;; Ignore contents of source blocks or example blocks when
4205 ;; indentation should be preserved (through
4206 ;; `org-src-preserve-indentation' or "-i" flag).
4209 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4210 (let ((org-adapt-indentation t
)
4211 (org-src-preserve-indentation nil
))
4214 (org-get-indentation))))
4217 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4218 (let ((org-adapt-indentation t
)
4219 (org-src-preserve-indentation t
))
4222 (org-get-indentation))))
4225 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4226 (let ((org-adapt-indentation t
)
4227 (org-src-preserve-indentation t
))
4230 (org-get-indentation))))
4233 (org-test-with-temp-text
4234 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4235 (let ((org-adapt-indentation t
)
4236 (org-src-preserve-indentation nil
))
4239 (org-get-indentation)))))
4241 (ert-deftest test-org
/promote
()
4242 "Test `org-promote' specifications."
4243 ;; Return an error if headline is to be promoted to level 0, unless
4244 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4245 ;; headline becomes a comment.
4247 (org-test-with-temp-text "* H"
4248 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4251 (org-test-with-temp-text "* H"
4252 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4254 ;; Remove correct number of stars according to
4255 ;; `org-odd-levels-only'.
4258 (org-test-with-temp-text "*** H"
4259 (let ((org-odd-levels-only nil
)) (org-promote))
4260 (org-current-level))))
4263 (org-test-with-temp-text "*** H"
4264 (let ((org-odd-levels-only t
)) (org-promote))
4265 (org-current-level))))
4266 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4268 (org-test-with-temp-text "** H :tag:"
4269 (let ((org-tags-column 10)
4270 (org-auto-align-tags t
)
4271 (org-odd-levels-only nil
))
4273 (org-move-to-column 10)
4274 (looking-at-p ":tag:$")))
4276 (org-test-with-temp-text "** H :tag:"
4277 (let ((org-tags-column 10)
4278 (org-auto-align-tags nil
)
4279 (org-odd-levels-only nil
))
4281 (org-move-to-column 10)
4282 (looking-at-p ":tag:$")))
4283 ;; When `org-adapt-indentation' is non-nil, always indent planning
4284 ;; info and property drawers.
4287 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4288 (let ((org-odd-levels-only nil
)
4289 (org-adapt-indentation t
))
4292 (org-get-indentation))))
4295 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4296 (let ((org-odd-levels-only nil
)
4297 (org-adapt-indentation t
))
4300 (org-get-indentation))))
4303 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4304 (let ((org-odd-levels-only nil
)
4305 (org-adapt-indentation nil
))
4308 (org-get-indentation))))
4309 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4310 ;; section accordingly. Ignore, however, footnote definitions and
4311 ;; inlinetasks boundaries.
4314 (org-test-with-temp-text "** H\n Paragraph"
4315 (let ((org-odd-levels-only nil
)
4316 (org-adapt-indentation t
))
4319 (org-get-indentation))))
4322 (org-test-with-temp-text "** H\n Paragraph"
4323 (let ((org-odd-levels-only nil
)
4324 (org-adapt-indentation nil
))
4327 (org-get-indentation))))
4330 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4331 (let ((org-odd-levels-only nil
)
4332 (org-adapt-indentation t
))
4335 (org-get-indentation))))
4336 (when (featurep 'org-inlinetask
)
4339 (let ((org-inlinetask-min-level 5)
4340 (org-adapt-indentation t
))
4341 (org-test-with-temp-text "** H\n***** I\n***** END"
4344 (org-get-indentation))))))
4345 (when (featurep 'org-inlinetask
)
4348 (let ((org-inlinetask-min-level 5)
4349 (org-adapt-indentation t
))
4350 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4353 (org-get-indentation))))))
4354 ;; Give up shifting if it would break document's structure
4358 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4359 (let ((org-odd-levels-only nil
)
4360 (org-adapt-indentation t
))
4363 (org-get-indentation))))
4366 (org-test-with-temp-text "** H\n Paragraph\n * list."
4367 (let ((org-odd-levels-only nil
)
4368 (org-adapt-indentation t
))
4371 (org-get-indentation))))
4372 ;; Ignore contents of source blocks or example blocks when
4373 ;; indentation should be preserved (through
4374 ;; `org-src-preserve-indentation' or "-i" flag).
4377 (org-test-with-temp-text
4378 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4379 (let ((org-adapt-indentation t
)
4380 (org-src-preserve-indentation nil
)
4381 (org-odd-levels-only nil
))
4384 (org-get-indentation))))
4387 (org-test-with-temp-text
4388 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4389 (let ((org-adapt-indentation t
)
4390 (org-src-preserve-indentation t
)
4391 (org-odd-levels-only nil
))
4394 (org-get-indentation))))
4397 (org-test-with-temp-text
4398 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4399 (let ((org-adapt-indentation t
)
4400 (org-src-preserve-indentation t
)
4401 (org-odd-levels-only nil
))
4404 (org-get-indentation))))
4407 (org-test-with-temp-text
4408 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4409 (let ((org-adapt-indentation t
)
4410 (org-src-preserve-indentation nil
)
4411 (org-odd-levels-only nil
))
4414 (org-get-indentation)))))
4416 (ert-deftest test-org
/org-get-valid-level
()
4417 "Test function `org-get-valid-level' specifications."
4418 (let ((org-odd-levels-only nil
))
4419 (should (equal 1 (org-get-valid-level 0 0)))
4420 (should (equal 1 (org-get-valid-level 0 1)))
4421 (should (equal 2 (org-get-valid-level 0 2)))
4422 (should (equal 3 (org-get-valid-level 0 3)))
4423 (should (equal 1 (org-get-valid-level 1 0)))
4424 (should (equal 2 (org-get-valid-level 1 1)))
4425 (should (equal 23 (org-get-valid-level 1 22)))
4426 (should (equal 1 (org-get-valid-level 1 -
1)))
4427 (should (equal 1 (org-get-valid-level 2 -
1))))
4428 (let ((org-odd-levels-only t
))
4429 (should (equal 1 (org-get-valid-level 0 0)))
4430 (should (equal 1 (org-get-valid-level 0 1)))
4431 (should (equal 3 (org-get-valid-level 0 2)))
4432 (should (equal 5 (org-get-valid-level 0 3)))
4433 (should (equal 1 (org-get-valid-level 1 0)))
4434 (should (equal 3 (org-get-valid-level 1 1)))
4435 (should (equal 3 (org-get-valid-level 2 1)))
4436 (should (equal 5 (org-get-valid-level 3 1)))
4437 (should (equal 5 (org-get-valid-level 4 1)))
4438 (should (equal 43 (org-get-valid-level 1 21)))
4439 (should (equal 1 (org-get-valid-level 1 -
1)))
4440 (should (equal 1 (org-get-valid-level 2 -
1)))
4441 (should (equal 1 (org-get-valid-level 3 -
1)))
4442 (should (equal 3 (org-get-valid-level 4 -
1)))
4443 (should (equal 3 (org-get-valid-level 5 -
1)))))
4448 (ert-deftest test-org
/at-planning-p
()
4449 "Test `org-at-planning-p' specifications."
4452 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4453 (org-at-planning-p)))
4455 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4456 (org-at-planning-p)))
4457 ;; Correctly find planning attached to inlinetasks.
4458 (when (featurep 'org-inlinetask
)
4460 (org-test-with-temp-text
4461 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4462 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4464 (org-test-with-temp-text
4465 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4466 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4468 (org-test-with-temp-text
4469 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4470 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4472 (org-test-with-temp-text
4473 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4474 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4476 (ert-deftest test-org
/add-planning-info
()
4477 "Test `org-add-planning-info'."
4478 ;; Create deadline when `org-adapt-indentation' is non-nil.
4480 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4481 (org-test-with-temp-text "* H\nParagraph<point>"
4482 (let ((org-adapt-indentation t
))
4483 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4484 (replace-regexp-in-string
4485 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4487 ;; Create deadline when `org-adapt-indentation' is nil.
4489 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4490 (org-test-with-temp-text "* H\nParagraph<point>"
4491 (let ((org-adapt-indentation nil
))
4492 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4493 (replace-regexp-in-string
4494 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4496 ;; Update deadline when `org-adapt-indentation' is non-nil.
4498 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4499 (org-test-with-temp-text "\
4501 DEADLINE: <2015-06-24 Wed>
4503 (let ((org-adapt-indentation t
))
4504 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4505 (replace-regexp-in-string
4506 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4508 ;; Update deadline when `org-adapt-indentation' is nil.
4510 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4511 (org-test-with-temp-text "\
4513 DEADLINE: <2015-06-24 Wed>
4515 (let ((org-adapt-indentation nil
))
4516 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4517 (replace-regexp-in-string
4518 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4520 ;; Schedule when `org-adapt-indentation' is non-nil.
4522 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4523 (org-test-with-temp-text "* H\nParagraph<point>"
4524 (let ((org-adapt-indentation t
))
4525 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4526 (replace-regexp-in-string
4527 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4529 ;; Schedule when `org-adapt-indentation' is nil.
4531 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4532 (org-test-with-temp-text "* H\nParagraph<point>"
4533 (let ((org-adapt-indentation nil
))
4534 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4535 (replace-regexp-in-string
4536 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4538 ;; Add deadline when scheduled.
4542 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4544 (org-test-with-temp-text "\
4546 SCHEDULED: <2015-06-24 Wed>
4548 (let ((org-adapt-indentation t
))
4549 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4550 (replace-regexp-in-string
4551 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4553 ;; Remove middle entry.
4557 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4559 (org-test-with-temp-text "\
4561 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4563 (let ((org-adapt-indentation t
))
4564 (org-add-planning-info nil nil
'deadline
))
4565 (replace-regexp-in-string
4566 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4568 ;; Remove last entry and then middle entry (order should not
4573 CLOSED: [2015-06-24]
4575 (org-test-with-temp-text "\
4577 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4579 (let ((org-adapt-indentation t
))
4580 (org-add-planning-info nil nil
'scheduled
'deadline
))
4581 (replace-regexp-in-string
4582 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4584 ;; Remove closed when `org-adapt-indentation' is non-nil.
4586 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4587 (org-test-with-temp-text "\
4589 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4591 (let ((org-adapt-indentation t
))
4592 (org-add-planning-info nil nil
'closed
))
4593 (replace-regexp-in-string
4594 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4597 (equal "* H\n Paragraph"
4598 (org-test-with-temp-text "\
4600 CLOSED: [2015-06-25 Thu]
4602 (let ((org-adapt-indentation t
))
4603 (org-add-planning-info nil nil
'closed
))
4604 (replace-regexp-in-string
4605 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4607 ;; Remove closed when `org-adapt-indentation' is nil.
4609 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4610 (org-test-with-temp-text "\
4612 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4614 (let ((org-adapt-indentation nil
))
4615 (org-add-planning-info nil nil
'closed
))
4616 (replace-regexp-in-string
4617 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4620 (equal "* H\nParagraph"
4621 (org-test-with-temp-text "\
4623 CLOSED: [2015-06-25 Thu]
4625 (let ((org-adapt-indentation nil
))
4626 (org-add-planning-info nil nil
'closed
))
4627 (replace-regexp-in-string
4628 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4630 ;; Remove closed entry and delete empty line.
4635 (org-test-with-temp-text "\
4637 CLOSED: [2015-06-24 Wed]
4639 (let ((org-adapt-indentation t
))
4640 (org-add-planning-info nil nil
'closed
))
4641 (replace-regexp-in-string
4642 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4644 ;; Remove one entry and update another.
4646 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4647 (org-test-with-temp-text "\
4649 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4651 (let ((org-adapt-indentation t
))
4652 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4653 (replace-regexp-in-string
4654 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4657 (ert-deftest test-org
/deadline
()
4658 "Test `org-deadline' specifications."
4659 ;; Insert a new value or replace existing one.
4661 (equal "* H\nDEADLINE: <2012-03-29>\n"
4662 (org-test-with-temp-text "* H"
4663 (let ((org-adapt-indentation nil
)
4664 (org-last-inserted-timestamp nil
))
4665 (org-deadline nil
"<2012-03-29 Tue>"))
4666 (replace-regexp-in-string
4667 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4670 (equal "* H\nDEADLINE: <2014-03-04>"
4671 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4672 (let ((org-adapt-indentation nil
)
4673 (org-last-inserted-timestamp nil
))
4674 (org-deadline nil
"<2014-03-04 Thu>"))
4675 (replace-regexp-in-string
4676 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4678 ;; Accept delta time, e.g., "+2d".
4680 (equal "* H\nDEADLINE: <2015-03-04>\n"
4681 (cl-letf (((symbol-function 'current-time
)
4682 (lambda (&rest args
)
4683 (apply #'encode-time
4684 (org-parse-time-string "2014-03-04")))))
4685 (org-test-with-temp-text "* H"
4686 (let ((org-adapt-indentation nil
)
4687 (org-last-inserted-timestamp nil
))
4688 (org-deadline nil
"+1y"))
4689 (replace-regexp-in-string
4690 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4691 ;; Preserve repeater.
4693 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4694 (org-test-with-temp-text "* H"
4695 (let ((org-adapt-indentation nil
)
4696 (org-last-inserted-timestamp nil
))
4697 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4698 (replace-regexp-in-string
4699 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4700 ;; Remove CLOSED keyword, if any.
4702 (equal "* H\nDEADLINE: <2012-03-29>"
4703 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4704 (let ((org-adapt-indentation nil
)
4705 (org-last-inserted-timestamp nil
))
4706 (org-deadline nil
"<2012-03-29 Tue>"))
4707 (replace-regexp-in-string
4708 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4709 ;; With C-u argument, remove DEADLINE keyword.
4712 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4713 (let ((org-adapt-indentation nil
)
4714 (org-last-inserted-timestamp nil
))
4715 (org-deadline '(4)))
4719 (org-test-with-temp-text "* H"
4720 (let ((org-adapt-indentation nil
)
4721 (org-last-inserted-timestamp nil
))
4722 (org-deadline '(4)))
4724 ;; With C-u C-u argument, prompt for a delay cookie.
4726 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4727 (cl-letf (((symbol-function 'org-read-date
)
4728 (lambda (&rest args
)
4729 (apply #'encode-time
4730 (org-parse-time-string "2014-03-04")))))
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 '(16)))
4737 (cl-letf (((symbol-function 'org-read-date
)
4738 (lambda (&rest args
)
4739 (apply #'encode-time
4740 (org-parse-time-string "2014-03-04")))))
4741 (org-test-with-temp-text "* H"
4742 (let ((org-adapt-indentation nil
)
4743 (org-last-inserted-timestamp nil
))
4744 (org-deadline '(16)))
4746 ;; When a region is active and
4747 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4748 ;; same value in all headlines in region.
4750 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4751 (org-test-with-temp-text "* H1\n* H2"
4752 (let ((org-adapt-indentation nil
)
4753 (org-last-inserted-timestamp nil
)
4754 (org-loop-over-headlines-in-active-region t
))
4755 (transient-mark-mode 1)
4756 (push-mark (point) t t
)
4757 (goto-char (point-max))
4758 (org-deadline nil
"2012-03-29"))
4759 (replace-regexp-in-string
4760 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4762 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4763 (org-test-with-temp-text "* H1\n* H2"
4764 (let ((org-adapt-indentation nil
)
4765 (org-last-inserted-timestamp nil
)
4766 (org-loop-over-headlines-in-active-region nil
))
4767 (transient-mark-mode 1)
4768 (push-mark (point) t t
)
4769 (goto-char (point-max))
4770 (org-deadline nil
"2012-03-29"))
4771 (replace-regexp-in-string
4772 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4774 (ert-deftest test-org
/schedule
()
4775 "Test `org-schedule' specifications."
4776 ;; Insert a new value or replace existing one.
4778 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4779 (org-test-with-temp-text "* H"
4780 (let ((org-adapt-indentation nil
)
4781 (org-last-inserted-timestamp nil
))
4782 (org-schedule nil
"<2012-03-29 Tue>"))
4783 (replace-regexp-in-string
4784 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4787 (equal "* H\nSCHEDULED: <2014-03-04>"
4788 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4789 (let ((org-adapt-indentation nil
)
4790 (org-last-inserted-timestamp nil
))
4791 (org-schedule nil
"<2014-03-04 Thu>"))
4792 (replace-regexp-in-string
4793 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4795 ;; Accept delta time, e.g., "+2d".
4797 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4798 (cl-letf (((symbol-function 'current-time
)
4799 (lambda (&rest args
)
4800 (apply #'encode-time
4801 (org-parse-time-string "2014-03-04")))))
4802 (org-test-with-temp-text "* H"
4803 (let ((org-adapt-indentation nil
)
4804 (org-last-inserted-timestamp nil
))
4805 (org-schedule nil
"+1y"))
4806 (replace-regexp-in-string
4807 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4808 ;; Preserve repeater.
4810 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4811 (org-test-with-temp-text "* H"
4812 (let ((org-adapt-indentation nil
)
4813 (org-last-inserted-timestamp nil
))
4814 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4815 (replace-regexp-in-string
4816 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4817 ;; Remove CLOSED keyword, if any.
4819 (equal "* H\nSCHEDULED: <2012-03-29>"
4820 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4821 (let ((org-adapt-indentation nil
)
4822 (org-last-inserted-timestamp nil
))
4823 (org-schedule nil
"<2012-03-29 Tue>"))
4824 (replace-regexp-in-string
4825 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4826 ;; With C-u argument, remove SCHEDULED keyword.
4829 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4830 (let ((org-adapt-indentation nil
)
4831 (org-last-inserted-timestamp nil
))
4832 (org-schedule '(4)))
4836 (org-test-with-temp-text "* H"
4837 (let ((org-adapt-indentation nil
)
4838 (org-last-inserted-timestamp nil
))
4839 (org-schedule '(4)))
4841 ;; With C-u C-u argument, prompt for a delay cookie.
4843 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4844 (cl-letf (((symbol-function 'org-read-date
)
4845 (lambda (&rest args
)
4846 (apply #'encode-time
4847 (org-parse-time-string "2014-03-04")))))
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 '(16)))
4854 (cl-letf (((symbol-function 'org-read-date
)
4855 (lambda (&rest args
)
4856 (apply #'encode-time
4857 (org-parse-time-string "2014-03-04")))))
4858 (org-test-with-temp-text "* H"
4859 (let ((org-adapt-indentation nil
)
4860 (org-last-inserted-timestamp nil
))
4861 (org-schedule '(16)))
4863 ;; When a region is active and
4864 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4865 ;; same value in all headlines in region.
4867 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4868 (org-test-with-temp-text "* H1\n* H2"
4869 (let ((org-adapt-indentation nil
)
4870 (org-last-inserted-timestamp nil
)
4871 (org-loop-over-headlines-in-active-region t
))
4872 (transient-mark-mode 1)
4873 (push-mark (point) t t
)
4874 (goto-char (point-max))
4875 (org-schedule nil
"2012-03-29"))
4876 (replace-regexp-in-string
4877 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4879 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4880 (org-test-with-temp-text "* H1\n* H2"
4881 (let ((org-adapt-indentation nil
)
4882 (org-last-inserted-timestamp nil
)
4883 (org-loop-over-headlines-in-active-region nil
))
4884 (transient-mark-mode 1)
4885 (push-mark (point) t t
)
4886 (goto-char (point-max))
4887 (org-schedule nil
"2012-03-29"))
4888 (replace-regexp-in-string
4889 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4891 ;; check if a repeater survives re-scheduling.
4893 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4894 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4895 (let ((org-adapt-indentation nil
)
4896 (org-last-inserted-timestamp nil
))
4897 (org-schedule nil
"2017-02-01"))
4903 (ert-deftest test-org
/buffer-property-keys
()
4904 "Test `org-buffer-property-keys' specifications."
4905 ;; Retrieve properties accross siblings.
4908 (org-test-with-temp-text "
4917 (org-buffer-property-keys))))
4918 ;; Retrieve properties accross children.
4921 (org-test-with-temp-text "
4930 (org-buffer-property-keys))))
4931 ;; Retrieve muliple properties in the same drawer.
4934 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4935 (org-buffer-property-keys))))
4936 ;; Ignore extension symbol in property name.
4939 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4940 (org-buffer-property-keys))))
4941 ;; With non-nil COLUMNS, extract property names from columns.
4944 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4945 (org-buffer-property-keys nil nil t
))))
4947 (equal '("A" "B" "COLUMNS")
4948 (org-test-with-temp-text
4949 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4950 (org-buffer-property-keys nil nil t
))))
4951 ;; In COLUMNS, ignore title and summary-type.
4954 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4955 (org-buffer-property-keys nil nil t
))))
4958 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4959 (org-buffer-property-keys nil nil t
))))
4962 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4963 (org-buffer-property-keys nil nil t
)))))
4965 (ert-deftest test-org
/property-values
()
4966 "Test `org-property-values' specifications."
4970 (org-test-with-temp-text
4971 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4972 (org-property-values "A"))))
4973 ;; Ignore empty values.
4975 (org-test-with-temp-text
4976 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4977 (org-property-values "A")))
4978 ;; Take into consideration extended values.
4981 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4982 (org-property-values "A")))))
4984 (ert-deftest test-org
/find-property
()
4985 "Test `org-find-property' specifications."
4989 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4990 (org-find-property "prop"))))
4991 ;; Ignore false positives.
4994 (org-test-with-temp-text
4995 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4996 (org-find-property "A"))))
4997 ;; Return first entry found in buffer.
5000 (org-test-with-temp-text
5001 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5002 (org-find-property "A"))))
5003 ;; Only search visible part of the buffer.
5006 (org-test-with-temp-text
5007 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5008 (org-narrow-to-subtree)
5009 (org-find-property "A"))))
5010 ;; With optional argument, only find entries with a specific value.
5012 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5013 (org-find-property "A" "2")))
5016 (org-test-with-temp-text
5017 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5018 (org-find-property "A" "2"))))
5019 ;; Use "nil" for explicit nil values.
5022 (org-test-with-temp-text
5023 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5024 (org-find-property "A" "nil")))))
5026 (ert-deftest test-org
/entry-delete
()
5027 "Test `org-entry-delete' specifications."
5031 " *:PROPERTIES:\n *:B: +2\n *:END:"
5032 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5033 (org-entry-delete (point) "A")
5035 ;; Also remove accumulated properties.
5039 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5040 (org-entry-delete (point) "A")
5042 ;; When last property is removed, remove the property drawer.
5046 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5047 (org-entry-delete (point) "A")
5049 ;; Return a non-nil value when some property was removed.
5051 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5052 (org-entry-delete (point) "A")))
5054 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5055 (org-entry-delete (point) "C")))
5056 ;; Special properties cannot be located in a drawer. Allow to
5057 ;; remove them anyway, in case of user error.
5059 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5060 (org-entry-delete (point) "SCHEDULED"))))
5062 (ert-deftest test-org
/entry-get
()
5063 "Test `org-entry-get' specifications."
5067 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5068 (org-entry-get (point) "A"))))
5072 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5073 (org-entry-get (point) "a"))))
5074 ;; Handle extended values, both before and after base value.
5077 (org-test-with-temp-text
5078 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5079 (org-entry-get (point) "A"))))
5080 ;; Empty values are returned as the empty string.
5083 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5084 (org-entry-get (point) "A"))))
5085 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5086 ;; otherwise, return nil.
5088 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5089 (org-entry-get (point) "A")))
5092 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5093 (org-entry-get (point) "A" nil t
))))
5094 ;; Return nil when no property is found, independently on the
5095 ;; LITERAL-NIL argument.
5097 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5098 (org-entry-get (point) "B")))
5100 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5101 (org-entry-get (point) "B" nil t
)))
5102 ;; Handle inheritance, when allowed. Include extended values and
5103 ;; possibly global values.
5107 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5108 (org-entry-get (point) "A" t
))))
5112 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5113 (let ((org-use-property-inheritance t
))
5114 (org-entry-get (point) "A" 'selective
)))))
5116 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5117 (let ((org-use-property-inheritance nil
))
5118 (org-entry-get (point) "A" 'selective
))))
5122 (org-test-with-temp-text
5123 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5124 (org-entry-get (point-max) "A" t
))))
5127 (org-test-with-temp-text
5128 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5130 (org-entry-get (point-max) "A" t
))))
5133 (org-test-with-temp-text
5134 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5136 (org-entry-get (point-max) "A" t
)))))
5138 (ert-deftest test-org
/entry-properties
()
5139 "Test `org-entry-properties' specifications."
5140 ;; Get "ITEM" property.
5143 (org-test-with-temp-text "* TODO H"
5144 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5147 (org-test-with-temp-text "* TODO H"
5148 (cdr (assoc "ITEM" (org-entry-properties))))))
5149 ;; Get "TODO" property. TODO keywords are case sensitive.
5152 (org-test-with-temp-text "* TODO H"
5153 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5156 (org-test-with-temp-text "* TODO H"
5157 (cdr (assoc "TODO" (org-entry-properties))))))
5159 (org-test-with-temp-text "* H"
5160 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5162 (org-test-with-temp-text "* todo H"
5163 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5164 ;; Get "PRIORITY" property.
5167 (org-test-with-temp-text "* [#A] H"
5168 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5171 (org-test-with-temp-text "* [#A] H"
5172 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5174 (equal (char-to-string org-default-priority
)
5175 (org-test-with-temp-text "* H"
5176 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5177 ;; Get "FILE" property.
5179 (org-test-with-temp-text-in-file "* H\nParagraph"
5180 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5181 (buffer-file-name))))
5183 (org-test-with-temp-text-in-file "* H\nParagraph"
5184 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5185 (buffer-file-name))))
5187 (org-test-with-temp-text "* H\nParagraph"
5188 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5189 ;; Get "TAGS" property.
5191 (equal ":tag1:tag2:"
5192 (org-test-with-temp-text "* H :tag1:tag2:"
5193 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5195 (equal ":tag1:tag2:"
5196 (org-test-with-temp-text "* H :tag1:tag2:"
5197 (cdr (assoc "TAGS" (org-entry-properties))))))
5199 (org-test-with-temp-text "* H"
5200 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5201 ;; Get "ALLTAGS" property.
5203 (equal ":tag1:tag2:"
5204 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5205 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5207 (equal ":tag1:tag2:"
5208 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5209 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5211 (org-test-with-temp-text "* H"
5212 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5213 ;; Get "BLOCKED" property.
5216 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5217 (let ((org-enforce-todo-dependencies t
)
5219 '(org-block-todo-from-children-or-siblings-or-parent)))
5220 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5223 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5224 (let ((org-enforce-todo-dependencies t
)
5226 '(org-block-todo-from-children-or-siblings-or-parent)))
5227 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5228 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5232 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5233 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5237 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5238 (cdr (assoc "CLOSED" (org-entry-properties))))))
5240 (org-test-with-temp-text "* H"
5241 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5245 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5246 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5250 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5251 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5253 (org-test-with-temp-text "* H"
5254 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5258 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5259 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5263 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5264 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5266 (org-test-with-temp-text "* H"
5267 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5271 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5272 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5275 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5276 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5279 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5280 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5283 (org-test-with-temp-text
5284 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5286 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5287 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5288 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5290 (equal "<2012-03-29 thu.>"
5291 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5292 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5294 (equal "[2012-03-29 thu.]"
5295 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5296 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5298 (equal "<2012-03-29 thu.>"
5299 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5300 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5302 (equal "[2014-03-04 tue.]"
5303 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5304 (cdr (assoc "TIMESTAMP_IA"
5305 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5307 (equal "<2012-03-29 thu.>"
5308 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5309 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5310 ;; Get standard properties.
5313 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5314 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5315 ;; Handle extended properties.
5318 (org-test-with-temp-text
5319 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5320 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5323 (org-test-with-temp-text
5324 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5325 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5326 ;; Ignore forbidden (special) properties.
5328 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5329 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5331 (ert-deftest test-org
/entry-put
()
5332 "Test `org-entry-put' specifications."
5333 ;; Error when not a string or nil.
5335 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5336 (org-entry-put 1 "test" 2)))
5337 ;; Error when property name is invalid.
5339 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5340 (org-entry-put 1 "no space" "value")))
5342 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5343 (org-entry-put 1 "" "value")))
5344 ;; Set "TODO" property.
5346 (string-match (regexp-quote " TODO H")
5347 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5348 (org-entry-put (point) "TODO" "TODO")
5351 (string-match (regexp-quote "* H")
5352 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5353 (org-entry-put (point) "TODO" nil
)
5355 ;; Set "PRIORITY" property.
5358 (org-test-with-temp-text "* [#B] H"
5359 (org-entry-put (point) "PRIORITY" "A")
5363 (org-test-with-temp-text "* [#B] H"
5364 (org-entry-put (point) "PRIORITY" nil
)
5366 ;; Set "SCHEDULED" property.
5368 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5369 (org-test-with-temp-text "* H"
5370 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5374 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5375 (org-entry-put (point) "SCHEDULED" nil
)
5378 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5379 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5380 (org-entry-put (point) "SCHEDULED" "earlier")
5383 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5384 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5385 (org-entry-put (point) "SCHEDULED" "later")
5387 ;; Set "DEADLINE" property.
5389 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5390 (org-test-with-temp-text "* H"
5391 (org-entry-put (point) "DEADLINE" "2014-03-04")
5395 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5396 (org-entry-put (point) "DEADLINE" nil
)
5399 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5400 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5401 (org-entry-put (point) "DEADLINE" "earlier")
5404 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5405 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5406 (org-entry-put (point) "DEADLINE" "later")
5408 ;; Set "CATEGORY" property
5410 (string-match "^ *:CATEGORY: cat"
5411 (org-test-with-temp-text "* H"
5412 (org-entry-put (point) "CATEGORY" "cat")
5414 ;; Regular properties, with or without pre-existing drawer.
5416 (string-match "^ *:A: +2$"
5417 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5418 (org-entry-put (point) "A" "2")
5421 (string-match "^ *:A: +1$"
5422 (org-test-with-temp-text "* H"
5423 (org-entry-put (point) "A" "1")
5425 ;; Special case: two consecutive headlines.
5427 (string-match "\\* A\n *:PROPERTIES:"
5428 (org-test-with-temp-text "* A\n** B"
5429 (org-entry-put (point) "A" "1")
5432 (ert-deftest test-org
/refresh-properties
()
5433 "Test `org-refresh-properties' specifications."
5436 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5437 (org-refresh-properties "A" 'org-test
)
5438 (get-text-property (point) 'org-test
))))
5440 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5441 (org-refresh-properties "B" 'org-test
)
5442 (get-text-property (point) 'org-test
)))
5443 ;; Handle properties only defined with extension syntax, i.e.,
5447 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5448 (org-refresh-properties "A" 'org-test
)
5449 (get-text-property (point) 'org-test
))))
5450 ;; When property is inherited, add text property to the whole
5454 (org-test-with-temp-text
5455 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5456 (let ((org-use-property-inheritance t
))
5457 (org-refresh-properties "A" 'org-test
))
5458 (get-text-property (point) 'org-test
))))
5459 ;; When property is inherited, use global value across the whole
5460 ;; buffer. However local values have precedence.
5463 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5465 (let ((org-use-property-inheritance nil
))
5466 (org-refresh-properties "A" 'org-test
))
5467 (get-text-property (point) 'org-test
))))
5470 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5472 (let ((org-use-property-inheritance t
))
5473 (org-refresh-properties "A" 'org-test
))
5474 (get-text-property (point) 'org-test
))))
5477 (org-test-with-temp-text
5478 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5480 (let ((org-use-property-inheritance t
))
5481 (org-refresh-properties "A" 'org-test
))
5482 (get-text-property (point) 'org-test
)))))
5487 (ert-deftest test-org
/update-radio-target-regexp
()
5488 "Test `org-update-radio-target-regexp' specifications."
5489 ;; Properly update cache with no previous radio target regexp.
5492 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5493 (save-excursion (goto-char (point-max)) (org-element-context))
5495 (search-forward "o")
5497 (org-update-radio-target-regexp)
5498 (goto-char (point-max))
5499 (org-element-type (org-element-context)))))
5500 ;; Properly update cache with previous radio target regexp.
5503 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5504 (save-excursion (goto-char (point-max)) (org-element-context))
5506 (search-forward "o")
5508 (org-update-radio-target-regexp)
5509 (search-backward "r")
5512 (org-update-radio-target-regexp)
5513 (goto-char (point-max))
5514 (delete-region (line-beginning-position) (point))
5516 (org-element-type (org-element-context))))))
5521 (ert-deftest test-org
/refile-get-targets
()
5522 "Test `org-refile-get-targets' specifications."
5523 ;; :maxlevel includes all headings above specified value.
5525 (equal '("H1" "H2" "H3")
5526 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5527 (let ((org-refile-use-outline-path nil
)
5528 (org-refile-targets `((nil :maxlevel .
3))))
5529 (mapcar #'car
(org-refile-get-targets))))))
5532 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5533 (let ((org-refile-use-outline-path nil
)
5534 (org-refile-targets `((nil :maxlevel .
2))))
5535 (mapcar #'car
(org-refile-get-targets))))))
5536 ;; :level limits targets to headlines with the specified level.
5539 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5540 (let ((org-refile-use-outline-path nil
)
5541 (org-refile-targets `((nil :level .
2))))
5542 (mapcar #'car
(org-refile-get-targets))))))
5543 ;; :tag limits targets to headlines with specified tag.
5546 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5547 (let ((org-refile-use-outline-path nil
)
5548 (org-refile-targets `((nil :tag .
"foo"))))
5549 (mapcar #'car
(org-refile-get-targets))))))
5550 ;; :todo limits targets to headlines with specified TODO keyword.
5553 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5554 (let ((org-refile-use-outline-path nil
)
5555 (org-refile-targets `((nil :todo .
"TODO"))))
5556 (mapcar #'car
(org-refile-get-targets))))))
5557 ;; :regexp filters targets matching provided regexp.
5560 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5561 (let ((org-refile-use-outline-path nil
)
5562 (org-refile-targets `((nil :regexp .
"F"))))
5563 (mapcar #'car
(org-refile-get-targets))))))
5564 ;; A nil `org-refile-targets' includes only top level headlines in
5568 (org-test-with-temp-text "* H1\n** S1\n* H2"
5569 (let ((org-refile-use-outline-path nil
)
5570 (org-refile-targets nil
))
5571 (mapcar #'car
(org-refile-get-targets))))))
5572 ;; Return value is the union of the targets according to all the
5573 ;; defined rules. However, prevent duplicates.
5575 (equal '("F2" "F3" "H1")
5576 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5577 (let ((org-refile-use-outline-path nil
)
5578 (org-refile-targets `((nil :regexp .
"F")
5579 (nil :todo .
"TODO"))))
5580 (mapcar #'car
(org-refile-get-targets))))))
5582 (equal '("F2" "F3" "H1")
5583 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5584 (let ((org-refile-use-outline-path nil
)
5585 (org-refile-targets `((nil :regexp .
"F")
5586 (nil :todo .
"TODO"))))
5587 (mapcar #'car
(org-refile-get-targets))))))
5588 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5591 (equal '("H1" "H1/H2" "H1/H2/H3")
5592 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5593 (let ((org-refile-use-outline-path t
)
5594 (org-refile-targets `((nil :maxlevel .
3))))
5595 (mapcar #'car
(org-refile-get-targets))))))
5596 ;; When providing targets as paths, escape forward slashes in
5597 ;; headings with backslashes.
5599 (equal '("H1\\/foo")
5600 (org-test-with-temp-text "* H1/foo"
5601 (let ((org-refile-use-outline-path t
)
5602 (org-refile-targets `((nil :maxlevel .
1))))
5603 (mapcar #'car
(org-refile-get-targets))))))
5604 ;; When `org-refile-use-outline-path' is `file', include file name
5605 ;; without directory in targets.
5607 (org-test-with-temp-text-in-file "* H1"
5608 (let* ((filename (buffer-file-name))
5609 (org-refile-use-outline-path 'file
)
5610 (org-refile-targets `(((,filename
) :level .
1))))
5611 (member (file-name-nondirectory filename
)
5612 (mapcar #'car
(org-refile-get-targets))))))
5613 ;; When `org-refile-use-outline-path' is `full-file-path', include
5616 (org-test-with-temp-text-in-file "* H1"
5617 (let* ((filename (file-truename (buffer-file-name)))
5618 (org-refile-use-outline-path 'full-file-path
)
5619 (org-refile-targets `(((,filename
) :level .
1))))
5620 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5621 ;; When `org-refile-use-outline-path' is `buffer-name', include
5624 (org-test-with-temp-text "* H1"
5625 (let* ((org-refile-use-outline-path 'buffer-name
)
5626 (org-refile-targets `((nil :level .
1))))
5627 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5633 (ert-deftest test-org
/match-sparse-tree
()
5634 "Test `org-match-sparse-tree' specifications."
5637 (org-test-with-temp-text "* H\n** H1 :tag:"
5638 (org-match-sparse-tree nil
"tag")
5639 (search-forward "H1")
5640 (org-invisible-p2)))
5642 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5643 (org-match-sparse-tree nil
"tag")
5644 (search-forward "H2")
5645 (org-invisible-p2)))
5646 ;; "-" operator for tags.
5648 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5649 (org-match-sparse-tree nil
"tag1-tag2")
5650 (search-forward "H1")
5651 (org-invisible-p2)))
5653 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5654 (org-match-sparse-tree nil
"tag1-tag2")
5655 (search-forward "H2")
5656 (org-invisible-p2)))
5657 ;; "&" operator for tags.
5659 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5660 (org-match-sparse-tree nil
"tag1&tag2")
5661 (search-forward "H1")
5662 (org-invisible-p2)))
5664 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5665 (org-match-sparse-tree nil
"tag1&tag2")
5666 (search-forward "H2")
5667 (org-invisible-p2)))
5668 ;; "|" operator for tags.
5670 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5671 (org-match-sparse-tree nil
"tag1|tag2")
5672 (search-forward "H1")
5673 (org-invisible-p2)))
5675 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5676 (org-match-sparse-tree nil
"tag1|tag2")
5677 (search-forward "H2")
5678 (org-invisible-p2)))
5679 ;; Regexp match on tags.
5681 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5682 (org-match-sparse-tree nil
"{^tag.*}")
5683 (search-forward "H1")
5684 (org-invisible-p2)))
5686 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5687 (org-match-sparse-tree nil
"{^tag.*}")
5688 (search-forward "H2")
5689 (org-invisible-p2)))
5690 ;; Match group tags.
5692 (org-test-with-temp-text
5693 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5694 (org-match-sparse-tree nil
"work")
5695 (search-forward "H1")
5696 (org-invisible-p2)))
5698 (org-test-with-temp-text
5699 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5700 (org-match-sparse-tree nil
"work")
5701 (search-forward "H2")
5702 (org-invisible-p2)))
5703 ;; Match group tags with hard brackets.
5705 (org-test-with-temp-text
5706 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5707 (org-match-sparse-tree nil
"work")
5708 (search-forward "H1")
5709 (org-invisible-p2)))
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 "H2")
5715 (org-invisible-p2)))
5716 ;; Match tags in hierarchies
5718 (org-test-with-temp-text
5719 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5720 #+TAGS: [ Lev_2 : Lev_3 ]\n
5721 #+TAGS: { Lev_3 : Lev_4 }\n
5722 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5723 (org-match-sparse-tree nil
"Lev_1")
5724 (search-forward "H4")
5725 (org-invisible-p2)))
5726 ;; Match regular expressions in tags
5728 (org-test-with-temp-text
5729 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5730 (org-match-sparse-tree nil
"Lev")
5731 (search-forward "H1")
5732 (org-invisible-p2)))
5734 (org-test-with-temp-text
5735 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5736 (org-match-sparse-tree nil
"Lev")
5737 (search-forward "H1")
5738 (org-invisible-p2)))
5739 ;; Match properties.
5741 (org-test-with-temp-text
5742 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5743 (org-match-sparse-tree nil
"A=\"1\"")
5744 (search-forward "H2")
5745 (org-invisible-p2)))
5747 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5748 (org-match-sparse-tree nil
"A=\"1\"")
5749 (search-forward "H2")
5750 (org-invisible-p2)))
5751 ;; Case is not significant when matching properties.
5753 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5754 (org-match-sparse-tree nil
"a=\"1\"")
5755 (search-forward "H2")
5756 (org-invisible-p2)))
5758 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5759 (org-match-sparse-tree nil
"A=\"1\"")
5760 (search-forward "H2")
5761 (org-invisible-p2)))
5762 ;; Match special LEVEL property.
5764 (org-test-with-temp-text "* H\n** H1\n*** H2"
5765 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5766 (search-forward "H1")
5767 (org-invisible-p2)))
5769 (org-test-with-temp-text "* H\n** H1\n*** H2"
5770 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5771 (search-forward "H2")
5772 (org-invisible-p2)))
5773 ;; Comparison operators when matching properties.
5775 (org-test-with-temp-text
5776 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5777 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5778 (search-forward "H1")
5779 (org-invisible-p2)))
5781 (org-test-with-temp-text
5782 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5783 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5784 (search-forward "H2")
5785 (org-invisible-p2)))
5786 ;; Regexp match on properties values.
5788 (org-test-with-temp-text
5789 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5790 (org-match-sparse-tree nil
"A={f.*}")
5791 (search-forward "H1")
5792 (org-invisible-p2)))
5794 (org-test-with-temp-text
5795 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5796 (org-match-sparse-tree nil
"A={f.*}")
5797 (search-forward "H2")
5798 (org-invisible-p2)))
5799 ;; With an optional argument, limit match to TODO entries.
5801 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5802 (org-match-sparse-tree t
"tag")
5803 (search-forward "H1")
5804 (org-invisible-p2)))
5806 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5807 (org-match-sparse-tree t
"tag")
5808 (search-forward "H2")
5809 (org-invisible-p2))))
5811 (ert-deftest test-org
/occur
()
5812 "Test `org-occur' specifications."
5813 ;; Count number of matches.
5816 (org-test-with-temp-text "* H\nA\n* H2"
5820 (org-test-with-temp-text "* H\nA\n* H2\nA"
5822 ;; Test CALLBACK optional argument.
5825 (org-test-with-temp-text "* H\nA\n* H2"
5826 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5829 (org-test-with-temp-text "* H\nA\n* H2\nA"
5830 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5831 ;; Case-fold searches according to `org-occur-case-fold-search'.
5834 (org-test-with-temp-text "Aa"
5835 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5838 (org-test-with-temp-text "Aa"
5839 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5842 (org-test-with-temp-text "Aa"
5843 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5846 (org-test-with-temp-text "Aa"
5847 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5850 (org-test-with-temp-text "Aa"
5851 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5854 (org-test-with-temp-text "Aa"
5855 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5860 (ert-deftest test-org
/tag-string-to-alist
()
5861 "Test `org-tag-string-to-alist' specifications."
5862 ;; Tag without selection key.
5863 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5864 ;; Tag with selection key.
5865 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5869 (org-tag-string-to-alist "[ group : t1 t2 ]")
5870 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5871 ;; Mutually exclusive tags.
5872 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5873 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5876 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5877 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5879 (ert-deftest test-org
/tag-alist-to-string
()
5880 "Test `org-tag-alist-to-string' specifications."
5881 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5882 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5885 (org-tag-alist-to-string
5886 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5887 "[ group : t1 t2 ]"))
5889 (equal (org-tag-alist-to-string
5890 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5894 (org-tag-alist-to-string
5895 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5896 "{ group : tag1 tag2 }")))
5898 (ert-deftest test-org
/tag-alist-to-groups
()
5899 "Test `org-tag-alist-to-groups' specifications."
5901 (equal (org-tag-alist-to-groups
5902 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5903 '(("group" "t1" "t2"))))
5906 (org-tag-alist-to-groups
5907 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5908 '(("group" "t1" "t2"))))
5910 (org-tag-alist-to-groups
5911 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5913 (ert-deftest test-org
/tag-align
()
5914 "Test tags alignment."
5915 ;; Test aligning tags with different display width.
5917 ;; 12345678901234567890
5918 (equal "* Test :abc:"
5919 (org-test-with-temp-text "* Test :abc:"
5920 (let ((org-tags-column -
20)
5921 (indent-tabs-mode nil
))
5922 (org-fix-tags-on-the-fly))
5925 ;; 12345678901234567890
5926 (equal "* Test :日本語:"
5927 (org-test-with-temp-text "* Test :日本語:"
5928 (let ((org-tags-column -
20)
5929 (indent-tabs-mode nil
))
5930 (org-fix-tags-on-the-fly))
5932 ;; Make sure aligning tags do not skip invisible text.
5934 (equal "* [[linkx]] :tag:"
5935 (org-test-with-temp-text "* [[link<point>]] :tag:"
5936 (let ((org-tags-column 0))
5937 (org-fix-tags-on-the-fly)
5939 (buffer-string))))))
5941 (ert-deftest test-org
/tags-at
()
5943 (equal '("foo" "bar")
5944 (org-test-with-temp-text
5945 "* T<point>est :foo:bar:"
5946 (org-get-tags-at)))))
5951 (ert-deftest test-org
/auto-repeat-maybe
()
5952 "Test `org-auto-repeat-maybe' specifications."
5953 ;; Do not auto repeat when there is no valid time stamp with
5954 ;; a repeater in the entry.
5958 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5959 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5965 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5966 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5969 ;; When switching to DONE state, switch back to first TODO keyword
5970 ;; in sequence, or the same keyword if they have different types.
5974 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5975 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5981 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5982 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5988 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5989 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5992 ;; If there was no TODO keyword in the first place, do not insert
5997 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5998 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6001 ;; Revert to REPEAT_TO_STATE, if set.
6005 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6006 (org-test-with-temp-text
6009 :REPEAT_TO_STATE: KWD2
6011 <2012-03-29 Thu +2y>"
6014 ;; When switching to DONE state, update base date. If there are
6015 ;; multiple repeated time stamps, update them all.
6018 "<2014-03-29 .* \\+2y>"
6019 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6020 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6025 "<2015-03-04 .* \\+1y>"
6026 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6027 (org-test-with-temp-text
6028 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6031 ;; Throw an error if repeater unit is the hour and no time is
6032 ;; provided in the time-stamp.
6034 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6035 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6038 ;; Do not repeat commented time stamps.
6041 "<2015-03-04 .* \\+1y>"
6042 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6043 (org-test-with-temp-text
6044 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6049 "<2015-03-04 .* \\+1y>"
6050 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6051 (org-test-with-temp-text
6053 <2012-03-29 Thu. +2y>
6055 <2014-03-04 Tue +1y>
6059 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6060 ;; entry, record time of last repeat.
6064 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6065 (org-log-repeat nil
))
6066 (cl-letf (((symbol-function 'org-add-log-setup
)
6067 (lambda (&rest args
) nil
)))
6068 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6070 (buffer-string))))))
6074 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6076 (cl-letf (((symbol-function 'org-add-log-setup
)
6077 (lambda (&rest args
) nil
)))
6078 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6080 (buffer-string))))))
6084 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6085 (cl-letf (((symbol-function 'org-add-log-setup
)
6086 (lambda (&rest args
) nil
)))
6087 (org-test-with-temp-text
6088 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6090 (buffer-string))))))
6091 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6092 ;; the entry as it is no longer relevant.
6096 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6097 (org-test-with-temp-text
6098 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6101 ;; Properly advance repeater even when a clock entry is specified
6102 ;; and `org-log-repeat' is nil.
6105 "SCHEDULED: <2014-03-29"
6106 (let ((org-log-repeat nil
)
6107 (org-todo-keywords '((sequence "TODO" "DONE"))))
6108 (org-test-with-temp-text
6110 SCHEDULED: <2012-03-29 Thu +2y>
6111 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6113 (buffer-string))))))
6118 (ert-deftest test-org
/at-timestamp-p
()
6119 "Test `org-at-timestamp-p' specifications."
6121 (org-test-with-temp-text "<2012-03-29 Thu>"
6122 (org-at-timestamp-p)))
6124 (org-test-with-temp-text "2012-03-29 Thu"
6125 (org-at-timestamp-p)))
6126 ;; Test return values.
6129 (org-test-with-temp-text "<2012-03-29 Thu>"
6130 (org-at-timestamp-p))))
6133 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6134 (org-at-timestamp-p))))
6137 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6138 (org-at-timestamp-p))))
6141 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6142 (org-at-timestamp-p))))
6145 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6146 (org-at-timestamp-p))))
6149 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6150 (org-at-timestamp-p))))
6153 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6154 (org-at-timestamp-p))))
6157 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6158 (org-at-timestamp-p))))
6159 ;; Test `inactive' optional argument.
6161 (org-test-with-temp-text "[2012-03-29 Thu]"
6162 (org-at-timestamp-p 'inactive
)))
6164 (org-test-with-temp-text "[2012-03-29 Thu]"
6165 (org-at-timestamp-p)))
6166 ;; When optional argument is `agenda', recognize time-stamps in
6167 ;; planning info line, property drawers and clocks.
6169 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6170 (org-at-timestamp-p 'agenda
)))
6172 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6173 (org-at-timestamp-p)))
6175 (org-test-with-temp-text
6176 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6177 (org-at-timestamp-p 'agenda
)))
6179 (org-test-with-temp-text
6180 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6181 (org-at-timestamp-p)))
6183 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6184 (let ((org-agenda-include-inactive-timestamps t
))
6185 (org-at-timestamp-p 'agenda
))))
6187 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6188 (let ((org-agenda-include-inactive-timestamps t
))
6189 (org-at-timestamp-p))))
6191 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6192 (let ((org-agenda-include-inactive-timestamps t
))
6193 (org-at-timestamp-p 'inactive
))))
6194 ;; When optional argument is `lax', match any part of the document
6195 ;; with Org timestamp syntax.
6197 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6198 (org-at-timestamp-p 'lax
)))
6200 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6201 (org-at-timestamp-p)))
6203 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6204 (org-at-timestamp-p 'lax
)))
6206 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6207 (org-at-timestamp-p)))
6209 (org-test-with-temp-text
6210 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6211 (org-at-timestamp-p 'lax
)))
6213 (org-test-with-temp-text
6214 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6215 (org-at-timestamp-p)))
6216 ;; Optional argument `lax' also matches inactive timestamps.
6218 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6219 (org-at-timestamp-p 'lax
))))
6221 (ert-deftest test-org
/time-stamp
()
6222 "Test `org-time-stamp' specifications."
6223 ;; Insert chosen time stamp at point.
6226 "Te<2014-03-04 .*?>xt"
6227 (org-test-with-temp-text "Te<point>xt"
6228 (cl-letf (((symbol-function 'org-read-date
)
6229 (lambda (&rest args
)
6230 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6231 (org-time-stamp nil
)
6233 ;; With a prefix argument, also insert time.
6236 "Te<2014-03-04 .*? 00:41>xt"
6237 (org-test-with-temp-text "Te<point>xt"
6238 (cl-letf (((symbol-function 'org-read-date
)
6239 (lambda (&rest args
)
6240 (apply #'encode-time
6241 (org-parse-time-string "2014-03-04 00:41")))))
6242 (org-time-stamp '(4))
6244 ;; With two universal prefix arguments, insert an active timestamp
6245 ;; with the current time without prompting the user.
6248 "Te<2014-03-04 .*? 00:41>xt"
6249 (org-test-with-temp-text "Te<point>xt"
6250 (cl-letf (((symbol-function 'current-time
)
6252 (apply #'encode-time
6253 (org-parse-time-string "2014-03-04 00:41")))))
6254 (org-time-stamp '(16))
6256 ;; When optional argument is non-nil, insert an inactive timestamp.
6259 "Te\\[2014-03-04 .*?\\]xt"
6260 (org-test-with-temp-text "Te<point>xt"
6261 (cl-letf (((symbol-function 'org-read-date
)
6262 (lambda (&rest args
)
6263 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6264 (org-time-stamp nil t
)
6266 ;; When called from a timestamp, replace existing one.
6270 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6271 (cl-letf (((symbol-function 'org-read-date
)
6272 (lambda (&rest args
)
6273 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6274 (org-time-stamp nil
)
6278 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6279 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
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
)
6285 ;; When replacing a timestamp, preserve repeater, if any.
6288 "<2014-03-04 .*? \\+2y>"
6289 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
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
)
6295 ;; When called twice in a raw, build a date range.
6298 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6299 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6300 (cl-letf (((symbol-function 'org-read-date
)
6301 (lambda (&rest args
)
6302 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6303 (let ((last-command 'org-time-stamp
)
6304 (this-command 'org-time-stamp
))
6305 (org-time-stamp nil
))
6306 (buffer-string))))))
6308 (ert-deftest test-org
/timestamp-has-time-p
()
6309 "Test `org-timestamp-has-time-p' specifications."
6312 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6313 (org-timestamp-has-time-p (org-element-context))))
6316 (org-test-with-temp-text "<2012-03-29 Thu>"
6317 (org-timestamp-has-time-p (org-element-context)))))
6319 (ert-deftest test-org
/get-repeat
()
6320 "Test `org-get-repeat' specifications."
6322 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6325 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6327 ;; Return proper repeat string.
6330 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6332 ;; Prevent false positive (commented or verbatim time stamps)
6334 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6337 (org-test-with-temp-text
6338 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6340 ;; Return nil when called before first heading.
6342 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6344 ;; When called with an optional argument, extract repeater from that
6346 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6347 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6349 (ert-deftest test-org
/timestamp-format
()
6350 "Test `org-timestamp-format' specifications."
6355 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6356 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6361 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6362 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6364 (ert-deftest test-org
/timestamp-split-range
()
6365 "Test `org-timestamp-split-range' specifications."
6366 ;; Extract range start (active).
6369 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6370 (let ((ts (org-timestamp-split-range (org-element-context))))
6371 (mapcar (lambda (p) (org-element-property p ts
))
6372 '(:year-end
:month-end
:day-end
))))))
6373 ;; Extract range start (inactive)
6376 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6377 (let ((ts (org-timestamp-split-range (org-element-context))))
6378 (mapcar (lambda (p) (org-element-property p ts
))
6379 '(:year-end
:month-end
:day-end
))))))
6380 ;; Extract range end (active).
6383 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6384 (let ((ts (org-timestamp-split-range
6385 (org-element-context) t
)))
6386 (mapcar (lambda (p) (org-element-property p ts
))
6387 '(:year-end
:month-end
:day-end
))))))
6388 ;; Extract range end (inactive)
6391 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6392 (let ((ts (org-timestamp-split-range
6393 (org-element-context) t
)))
6394 (mapcar (lambda (p) (org-element-property p ts
))
6395 '(:year-end
:month-end
:day-end
))))))
6396 ;; Return the timestamp if not a range.
6398 (org-test-with-temp-text "[2012-03-29 Thu]"
6399 (let* ((ts-orig (org-element-context))
6400 (ts-copy (org-timestamp-split-range ts-orig
)))
6401 (eq ts-orig ts-copy
))))
6403 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6404 (let* ((ts-orig (org-element-context))
6405 (ts-copy (org-timestamp-split-range ts-orig
)))
6406 (eq ts-orig ts-copy
)))))
6408 (ert-deftest test-org
/timestamp-translate
()
6409 "Test `org-timestamp-translate' specifications."
6410 ;; Translate whole date range.
6413 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6414 (let ((org-display-custom-times t
)
6415 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6416 (org-timestamp-translate (org-element-context))))))
6417 ;; Translate date range start.
6420 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6421 (let ((org-display-custom-times t
)
6422 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6423 (org-timestamp-translate (org-element-context) 'start
)))))
6424 ;; Translate date range end.
6427 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6428 (let ((org-display-custom-times t
)
6429 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6430 (org-timestamp-translate (org-element-context) 'end
)))))
6431 ;; Translate time range.
6434 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6435 (let ((org-display-custom-times t
)
6436 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6437 (org-timestamp-translate (org-element-context))))))
6438 ;; Translate non-range timestamp.
6441 (org-test-with-temp-text "<2012-03-29 Thu>"
6442 (let ((org-display-custom-times t
)
6443 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6444 (org-timestamp-translate (org-element-context))))))
6445 ;; Do not change `diary' timestamps.
6447 (equal "<%%(org-float t 4 2)>"
6448 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6449 (let ((org-display-custom-times t
)
6450 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6451 (org-timestamp-translate (org-element-context)))))))
6457 (ert-deftest test-org
/flag-drawer
()
6458 "Test `org-flag-drawer' specifications."
6461 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6463 (get-char-property (line-end-position) 'invisible
)))
6466 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6468 (org-flag-drawer nil
)
6469 (get-char-property (line-end-position) 'invisible
)))
6470 ;; Test optional argument.
6472 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6473 (let ((drawer (save-excursion (search-forward ":D2")
6474 (org-element-at-point))))
6475 (org-flag-drawer t drawer
)
6476 (get-char-property (progn (search-forward ":D2") (line-end-position))
6479 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6480 (let ((drawer (save-excursion (search-forward ":D2")
6481 (org-element-at-point))))
6482 (org-flag-drawer t drawer
)
6483 (get-char-property (line-end-position) 'invisible
))))
6484 ;; Do not hide fake drawers.
6486 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6489 (get-char-property (line-end-position) 'invisible
)))
6490 ;; Do not hide incomplete drawers.
6492 (org-test-with-temp-text ":D:\nparagraph"
6495 (get-char-property (line-end-position) 'invisible
)))
6496 ;; Do not hide drawers when called from final blank lines.
6498 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6499 (goto-char (point-max))
6501 (goto-char (point-min))
6502 (get-char-property (line-end-position) 'invisible
)))
6503 ;; Don't leave point in an invisible part of the buffer when hiding
6506 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6507 (goto-char (point-max))
6509 (get-char-property (point) 'invisible
))))
6511 (ert-deftest test-org
/hide-block-toggle
()
6512 "Test `org-hide-block-toggle' specifications."
6513 ;; Error when not at a block.
6515 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6516 (org-hide-block-toggle 'off
)
6517 (get-char-property (line-end-position) 'invisible
)))
6520 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6521 (org-hide-block-toggle)
6522 (get-char-property (line-end-position) 'invisible
)))
6524 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6525 (org-hide-block-toggle)
6526 (get-char-property (line-end-position) 'invisible
)))
6527 ;; Show block unconditionally when optional argument is `off'.
6529 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6530 (org-hide-block-toggle)
6531 (org-hide-block-toggle 'off
)
6532 (get-char-property (line-end-position) 'invisible
)))
6534 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6535 (org-hide-block-toggle 'off
)
6536 (get-char-property (line-end-position) 'invisible
)))
6537 ;; Hide block unconditionally when optional argument is non-nil.
6539 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6540 (org-hide-block-toggle t
)
6541 (get-char-property (line-end-position) 'invisible
)))
6543 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6544 (org-hide-block-toggle)
6545 (org-hide-block-toggle t
)
6546 (get-char-property (line-end-position) 'invisible
)))
6547 ;; Do not hide block when called from final blank lines.
6549 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6550 (org-hide-block-toggle)
6551 (goto-char (point-min))
6552 (get-char-property (line-end-position) 'invisible
)))
6553 ;; Don't leave point in an invisible part of the buffer when hiding
6556 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6557 (org-hide-block-toggle)
6558 (get-char-property (point) 'invisible
))))
6560 (ert-deftest test-org
/hide-block-toggle-maybe
()
6561 "Test `org-hide-block-toggle-maybe' specifications."
6563 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6564 (org-hide-block-toggle-maybe)))
6566 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6568 (ert-deftest test-org
/set-tags
()
6569 "Test `org-set-tags' specifications."
6570 ;; Tags set via fast-tag-selection should be visible afterwards
6572 (let ((org-tag-alist '(("NEXT" . ?n
)))
6573 (org-fast-tag-selection-single-key t
))
6574 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6575 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6576 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6577 ;; Show only headlines
6579 ;; Set NEXT tag on current entry
6580 (org-set-tags nil nil
)
6581 ;; Move point to that NEXT tag
6582 (search-forward "NEXT") (backward-word)
6583 ;; And it should be visible (i.e. no overlays)
6584 (not (overlays-at (point))))))))
6586 (ert-deftest test-org
/show-set-visibility
()
6587 "Test `org-show-set-visibility' specifications."
6588 ;; Do not throw an error before first heading.
6590 (org-test-with-temp-text "Preamble\n* Headline"
6591 (org-show-set-visibility 'tree
)
6593 ;; Test all visibility spans, both on headline and in entry.
6594 (let ((list-visible-lines
6595 (lambda (state headerp
)
6596 (org-test-with-temp-text "* Grandmother (0)
6607 **** The other child (11)
6612 (search-forward (if headerp
"Self" "Match"))
6613 (org-show-set-visibility state
)
6614 (goto-char (point-min))
6615 (let (result (line 0))
6617 (unless (org-invisible-p2) (push line result
))
6620 (nreverse result
))))))
6621 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6622 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6623 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6624 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6625 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6626 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6627 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6628 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6629 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6630 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6631 (funcall list-visible-lines
'tree nil
)))
6632 (should (equal '(0 1 3 4 5 7 12 13)
6633 (funcall list-visible-lines
'canonical t
)))
6634 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6635 (funcall list-visible-lines
'canonical nil
))))
6636 ;; When point is hidden in a drawer or a block, make sure to make it
6639 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6640 (org-hide-block-toggle)
6641 (search-forward "Text")
6642 (org-show-set-visibility 'minimal
)
6643 (org-invisible-p2)))
6645 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6647 (search-forward "Text")
6648 (org-show-set-visibility 'minimal
)
6649 (org-invisible-p2)))
6651 (org-test-with-temp-text
6652 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6655 (org-hide-block-toggle)
6656 (search-forward "Text")
6657 (org-show-set-visibility 'minimal
)
6658 (org-invisible-p2))))
6660 (defun test-org/copy-visible
()
6661 "Test `org-copy-visible' specifications."
6664 (org-test-with-temp-text "Foo"
6665 (let ((kill-ring nil
))
6666 (org-copy-visible (point-min) (point-max))
6667 (current-kill 0 t
)))))
6668 ;; Skip invisible characters by text property.
6671 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6672 (let ((kill-ring nil
))
6673 (org-copy-visible (point-min) (point-max))
6674 (current-kill 0 t
)))))
6675 ;; Skip invisible characters by overlay.
6678 (org-test-with-temp-text "F<hidden>oo"
6679 (let ((o (make-overlay 2 10)))
6680 (overlay-put o
'invisible t
))
6681 (let ((kill-ring nil
))
6682 (org-copy-visible (point-min) (point-max))
6683 (current-kill 0 t
)))))
6684 ;; Handle invisible characters at the beginning and the end of the
6688 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6689 (let ((kill-ring nil
))
6690 (org-copy-visible (point-min) (point-max))
6691 (current-kill 0 t
)))))
6694 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6695 (let ((kill-ring nil
))
6696 (org-copy-visible (point-min) (point-max))
6697 (current-kill 0 t
)))))
6698 ;; Handle multiple visible parts.
6701 (org-test-with-temp-text
6702 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6703 (let ((kill-ring nil
))
6704 (org-copy-visible (point-min) (point-max))
6705 (current-kill 0 t
))))))
6710 ;;; test-org.el ends here