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 ;; `org-return-follows-link' handle multi-line lines.
1132 (org-test-with-temp-text
1133 "[[target][This is a very\n long description<point>]]\n <<target>>"
1134 (let ((org-return-follows-link t
)
1135 (org-link-search-must-match-exact-headline nil
))
1137 (looking-at-p "<<target>>")))
1139 (org-test-with-temp-text
1140 "[[target][This is a very\n long description]]<point>\n <<target>>"
1141 (let ((org-return-follows-link t
)
1142 (org-link-search-must-match-exact-headline nil
))
1144 (looking-at-p "<<target>>")))
1145 ;; However, do not open link when point is in a table.
1147 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1148 (let ((org-return-follows-link t
)) (org-return))
1149 (looking-at-p "between")))
1150 ;; Special case: in a list, when indenting, do not break structure.
1153 (org-test-with-temp-text "- A <point>B"
1158 (org-test-with-temp-text "- A\n<point>- B"
1161 ;; On tags part of a headline, add a newline below it instead of
1164 (equal "* H :tag:\n"
1165 (org-test-with-temp-text "* H :<point>tag:"
1168 ;; Before headline text, add a newline below it instead of breaking
1171 (equal "* TODO H :tag:\n"
1172 (org-test-with-temp-text "* <point>TODO H :tag:"
1176 (equal "* TODO [#B] H :tag:\n"
1177 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1180 (should ;TODO are case-sensitive
1182 (org-test-with-temp-text "* <point>Todo"
1185 ;; At headline text, break headline text but preserve tags.
1187 (equal "* TODO [#B] foo :tag:\nbar"
1188 (let (org-auto-align-tags)
1189 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1192 ;; At bol of headline insert newline.
1195 (org-test-with-temp-text "<point>* h"
1198 ;; Refuse to leave invalid headline in buffer.
1201 (org-test-with-temp-text "*<point> h"
1204 ;; Before first column or after last one in a table, split the
1207 (equal "| a |\n\n| b |"
1208 (org-test-with-temp-text "| a |\n<point>| b |"
1212 (equal "| a |\n\n| b |"
1213 (org-test-with-temp-text "| a |<point>\n| b |"
1216 ;; Do not auto-fill on hitting <RET> inside a property drawer.
1218 (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
1219 (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
1220 (setq-local fill-column
10)
1225 (ert-deftest test-org
/meta-return
()
1226 "Test M-RET (`org-meta-return') specifications."
1227 ;; In a table field insert a row above.
1229 (org-test-with-temp-text "| a |"
1233 (looking-at "| |$")))
1234 ;; In a paragraph change current line into a header.
1236 (org-test-with-temp-text "a"
1239 (looking-at "\* a$")))
1240 ;; In an item insert an item, in this case above.
1242 (org-test-with-temp-text "- a"
1245 (looking-at "- $")))
1246 ;; In a drawer and item insert an item, in this case above.
1248 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1252 (looking-at "- $"))))
1254 (ert-deftest test-org
/insert-heading
()
1255 "Test `org-insert-heading' specifications."
1256 ;; In an empty buffer, insert a new headline.
1259 (org-test-with-temp-text ""
1260 (org-insert-heading)
1262 ;; At the beginning of a line, turn it into a headline.
1265 (org-test-with-temp-text "<point>P"
1266 (org-insert-heading)
1268 ;; In the middle of a line, split the line if allowed, otherwise,
1269 ;; insert the headline at its end.
1271 (equal "Para\n* graph"
1272 (org-test-with-temp-text "Para<point>graph"
1273 (let ((org-M-RET-may-split-line '((default . t
))))
1274 (org-insert-heading))
1277 (equal "Paragraph\n* "
1278 (org-test-with-temp-text "Para<point>graph"
1279 (let ((org-M-RET-may-split-line '((default . nil
))))
1280 (org-insert-heading))
1282 ;; At the beginning of a headline, create one above.
1285 (org-test-with-temp-text "* H"
1286 (org-insert-heading)
1288 ;; In the middle of a headline, split it if allowed.
1291 (org-test-with-temp-text "* H<point>1"
1292 (let ((org-M-RET-may-split-line '((headline . t
))))
1293 (org-insert-heading))
1297 (org-test-with-temp-text "* H<point>1"
1298 (let ((org-M-RET-may-split-line '((headline . nil
))))
1299 (org-insert-heading))
1301 ;; However, splitting cannot happen on TODO keywords, priorities or
1304 (equal "* TODO H1\n* \n"
1305 (org-test-with-temp-text "* TO<point>DO H1"
1306 (let ((org-M-RET-may-split-line '((headline . t
))))
1307 (org-insert-heading))
1310 (equal "* [#A] H1\n* \n"
1311 (org-test-with-temp-text "* [#<point>A] H1"
1312 (let ((org-M-RET-may-split-line '((headline . t
))))
1313 (org-insert-heading))
1316 (equal "* H1 :tag:\n* \n"
1317 (org-test-with-temp-text "* H1 :ta<point>g:"
1318 (let ((org-M-RET-may-split-line '((headline . t
))))
1319 (org-insert-heading))
1321 ;; New headline level depends on the level of the headline above.
1324 (org-test-with-temp-text "** H\n<point>P"
1325 (org-insert-heading)
1328 (equal "** H\nPara\n** graph"
1329 (org-test-with-temp-text "** H\nPara<point>graph"
1330 (let ((org-M-RET-may-split-line '((default . t
))))
1331 (org-insert-heading))
1335 (org-test-with-temp-text "** H"
1336 (org-insert-heading)
1338 ;; When called with one universal argument, insert a new headline at
1339 ;; the end of the current subtree, independently on the position of
1344 (org-test-with-temp-text "* H1\n** H2"
1345 (let ((org-insert-heading-respect-content nil
))
1346 (org-insert-heading '(4)))
1351 (org-test-with-temp-text "* H<point>1\n** H2"
1352 (let ((org-insert-heading-respect-content nil
))
1353 (org-insert-heading '(4)))
1355 ;; When called with two universal arguments, insert a new headline
1356 ;; at the end of the grandparent subtree.
1358 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1359 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1360 (let ((org-insert-heading-respect-content nil
))
1361 (org-insert-heading '(16)))
1363 ;; When optional TOP-LEVEL argument is non-nil, always insert
1364 ;; a level 1 heading.
1366 (equal "* H1\n** H2\n* \n"
1367 (org-test-with-temp-text "* H1\n** H2<point>"
1368 (org-insert-heading nil nil t
)
1371 (equal "* H1\n- item\n* "
1372 (org-test-with-temp-text "* H1\n- item<point>"
1373 (org-insert-heading nil nil t
)
1375 ;; Obey `org-blank-before-new-entry'.
1377 (equal "* H1\n\n* \n"
1378 (org-test-with-temp-text "* H1<point>"
1379 (let ((org-blank-before-new-entry '((heading . t
))))
1380 (org-insert-heading))
1384 (org-test-with-temp-text "* H1<point>"
1385 (let ((org-blank-before-new-entry '((heading . nil
))))
1386 (org-insert-heading))
1389 (equal "* H1\n* H2\n* \n"
1390 (org-test-with-temp-text "* H1\n* H2<point>"
1391 (let ((org-blank-before-new-entry '((heading . auto
))))
1392 (org-insert-heading))
1395 (equal "* H1\n\n* H2\n\n* \n"
1396 (org-test-with-temp-text "* H1\n\n* H2<point>"
1397 (let ((org-blank-before-new-entry '((heading . auto
))))
1398 (org-insert-heading))
1400 ;; Corner case: correctly insert a headline after an empty one.
1403 (org-test-with-temp-text "* <point>"
1404 (org-insert-heading)
1407 (org-test-with-temp-text "* <point>\n"
1408 (org-insert-heading)
1409 (looking-at-p "\n\\'")))
1410 ;; Do not insert spurious headlines when inserting a new headline.
1412 (equal "* H1\n* H2\n* \n"
1413 (org-test-with-temp-text "* H1\n* H2<point>\n"
1414 (org-insert-heading)
1416 ;; Preserve visibility at beginning of line. In particular, when
1417 ;; removing spurious blank lines, do not visually merge heading with
1418 ;; the line visible above.
1420 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1422 (let ((org-blank-before-new-entry '((heading . nil
))))
1423 (org-insert-heading '(4)))
1424 (invisible-p (line-end-position 0))))
1425 ;; Properly handle empty lines when forcing a headline below current
1428 (equal "* H1\n\n* H\n\n* \n"
1429 (org-test-with-temp-text "* H1\n\n* H<point>"
1430 (let ((org-blank-before-new-entry '((heading . t
))))
1431 (org-insert-heading '(4))
1432 (buffer-string))))))
1434 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1435 "Test `org-insert-todo-heading-respect-content' specifications."
1436 ;; Create a TODO heading.
1438 (org-test-with-temp-text "* H1\n Body"
1439 (org-insert-todo-heading-respect-content)
1440 (nth 2 (org-heading-components))))
1441 ;; Add headline at the end of the first subtree
1445 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1446 (org-insert-todo-heading-respect-content)
1447 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1448 ;; In a list, do not create a new item.
1452 (org-test-with-temp-text "* H\n- an item\n- another one"
1453 (search-forward "an ")
1454 (org-insert-todo-heading-respect-content)
1455 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1456 ;; Use the same TODO keyword as current heading.
1460 (org-test-with-temp-text "* TODO\n** WAITING\n"
1461 (org-insert-todo-heading-respect-content)
1462 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1464 (ert-deftest test-org
/clone-with-time-shift
()
1465 "Test `org-clone-subtree-with-time-shift'."
1466 ;; Raise an error before first heading.
1468 (org-test-with-temp-text ""
1469 (org-clone-subtree-with-time-shift 1)))
1470 ;; Raise an error on invalid number of clones.
1472 (org-test-with-temp-text "* Clone me"
1473 (org-clone-subtree-with-time-shift -
1)))
1474 ;; Clone non-repeating once.
1480 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1481 (org-clone-subtree-with-time-shift 1 "+2d")
1482 (replace-regexp-in-string
1483 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1485 ;; Clone repeating once.
1490 * H1\n<2015-06-25 +1w>
1492 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1493 (org-clone-subtree-with-time-shift 1 "+2d")
1494 (replace-regexp-in-string
1495 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1497 ;; Clone non-repeating zero times.
1502 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1503 (org-clone-subtree-with-time-shift 0 "+2d")
1504 (replace-regexp-in-string
1505 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1507 ;; Clone repeating "zero" times.
1511 * H1\n<2015-06-23 +1w>
1513 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1514 (org-clone-subtree-with-time-shift 0 "+2d")
1515 (replace-regexp-in-string
1516 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1518 ;; Clone with blank SHIFT argument.
1522 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1523 (org-clone-subtree-with-time-shift 1 "")
1524 (buffer-substring-no-properties (line-beginning-position 2)
1525 (line-end-position 2)))))
1526 ;; Find time stamps before point. If SHIFT is not specified, ask
1527 ;; for a time shift.
1531 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1532 (org-clone-subtree-with-time-shift 1 "+1d")
1533 (buffer-substring-no-properties (line-beginning-position 2)
1534 (line-end-position 2)))))
1538 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1539 (cl-letf (((symbol-function 'read-from-minibuffer
)
1540 (lambda (&rest args
) "+1d")))
1541 (org-clone-subtree-with-time-shift 1))
1542 (buffer-substring-no-properties (line-beginning-position 2)
1543 (line-end-position 2))))))
1546 ;;; Fixed-Width Areas
1548 (ert-deftest test-org
/toggle-fixed-width
()
1549 "Test `org-toggle-fixed-width' specifications."
1550 ;; No region: Toggle on fixed-width marker in paragraphs.
1553 (org-test-with-temp-text "A"
1554 (org-toggle-fixed-width)
1556 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1559 (org-test-with-temp-text ": A"
1560 (org-toggle-fixed-width)
1562 ;; No region: Toggle on marker in blank lines after elements or just
1563 ;; after a headline.
1566 (org-test-with-temp-text "* H\n"
1568 (org-toggle-fixed-width)
1571 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1572 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1573 (goto-char (point-max))
1574 (org-toggle-fixed-width)
1576 ;; No region: Toggle on marker in front of one line elements (e.g.,
1577 ;; headlines, clocks)
1579 (equal ": * Headline"
1580 (org-test-with-temp-text "* Headline"
1581 (org-toggle-fixed-width)
1584 (equal ": #+KEYWORD: value"
1585 (org-test-with-temp-text "#+KEYWORD: value"
1586 (org-toggle-fixed-width)
1588 ;; No region: error in other situations.
1590 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1592 (org-toggle-fixed-width)
1594 ;; No region: Indentation is preserved.
1597 (org-test-with-temp-text "- A\n B"
1599 (org-toggle-fixed-width)
1601 ;; Region: If it contains only fixed-width elements and blank lines,
1602 ;; toggle off fixed-width markup.
1605 (org-test-with-temp-text ": A\n\n: B"
1606 (transient-mark-mode 1)
1607 (push-mark (point) t t
)
1608 (goto-char (point-max))
1609 (org-toggle-fixed-width)
1611 ;; Region: If it contains anything else, toggle on fixed-width but
1612 ;; not on fixed-width areas.
1614 (equal ": A\n: \n: B\n: \n: C"
1615 (org-test-with-temp-text "A\n\n: B\n\nC"
1616 (transient-mark-mode 1)
1617 (push-mark (point) t t
)
1618 (goto-char (point-max))
1619 (org-toggle-fixed-width)
1621 ;; Region: Ignore blank lines at its end, unless it contains only
1625 (org-test-with-temp-text "A\n\n"
1626 (transient-mark-mode 1)
1627 (push-mark (point) t t
)
1628 (goto-char (point-max))
1629 (org-toggle-fixed-width)
1633 (org-test-with-temp-text "\n\n"
1634 (transient-mark-mode 1)
1635 (push-mark (point) t t
)
1636 (goto-char (point-max))
1637 (org-toggle-fixed-width)
1644 (ert-deftest test-org
/get-heading
()
1645 "Test `org-get-heading' specifications."
1646 ;; Return current heading, even if point is not on it.
1649 (org-test-with-temp-text "* H"
1650 (org-get-heading))))
1653 (org-test-with-temp-text "* H\nText<point>"
1654 (org-get-heading))))
1655 ;; Without any optional argument, return TODO keyword, priority
1656 ;; cookie, COMMENT keyword and tags.
1659 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1660 (org-get-heading))))
1663 (org-test-with-temp-text "* [#A] H"
1664 (org-get-heading))))
1667 (org-test-with-temp-text "* COMMENT H"
1668 (org-get-heading))))
1671 (org-test-with-temp-text "* H :tag:"
1672 (org-get-heading))))
1673 ;; With NO-TAGS argument, ignore tags.
1676 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1677 (org-get-heading t
))))
1680 (org-test-with-temp-text "* H :tag:"
1681 (org-get-heading t
))))
1682 ;; With NO-TODO, ignore TODO keyword.
1685 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1686 (org-get-heading nil t
))))
1689 (org-test-with-temp-text "* H :tag:"
1690 (org-get-heading nil t
))))
1691 ;; TODO keywords are case-sensitive.
1694 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1695 (org-get-heading nil t
))))
1696 ;; With NO-PRIORITY, ignore priority.
1699 (org-test-with-temp-text "* [#A] H"
1700 (org-get-heading nil nil t
))))
1703 (org-test-with-temp-text "* H"
1704 (org-get-heading nil nil t
))))
1707 (org-test-with-temp-text "* TODO [#A] H"
1708 (org-get-heading nil nil t
))))
1709 ;; With NO-COMMENT, ignore COMMENT keyword.
1712 (org-test-with-temp-text "* COMMENT H"
1713 (org-get-heading nil nil nil t
))))
1716 (org-test-with-temp-text "* H"
1717 (org-get-heading nil nil nil t
))))
1719 (equal "TODO [#A] H"
1720 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1721 (org-get-heading nil nil nil t
))))
1722 ;; On an empty headline, return value is consistent.
1723 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1724 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1725 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1726 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1728 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1730 (ert-deftest test-org
/in-commented-heading-p
()
1731 "Test `org-in-commented-heading-p' specifications."
1732 ;; Commented headline.
1734 (org-test-with-temp-text "* COMMENT Headline\nBody"
1735 (goto-char (point-max))
1736 (org-in-commented-heading-p)))
1737 ;; Commented ancestor.
1739 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1740 (goto-char (point-max))
1741 (org-in-commented-heading-p)))
1742 ;; Comment keyword is case-sensitive.
1744 (org-test-with-temp-text "* Comment Headline\nBody"
1745 (goto-char (point-max))
1746 (org-in-commented-heading-p)))
1747 ;; Keyword is standalone.
1749 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1750 (goto-char (point-max))
1751 (org-in-commented-heading-p)))
1752 ;; Optional argument.
1754 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1755 (goto-char (point-max))
1756 (org-in-commented-heading-p t
))))
1758 (ert-deftest test-org
/entry-blocked-p
()
1759 ;; Check other dependencies.
1761 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1762 (let ((org-enforce-todo-dependencies t
)
1764 '(org-block-todo-from-children-or-siblings-or-parent)))
1765 (org-entry-blocked-p))))
1767 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1768 (let ((org-enforce-todo-dependencies t
)
1770 '(org-block-todo-from-children-or-siblings-or-parent)))
1771 (org-entry-blocked-p))))
1772 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1775 (org-test-with-temp-text "* Blocked\n** TODO one"
1776 (let ((org-enforce-todo-dependencies t
)
1778 '(org-block-todo-from-children-or-siblings-or-parent)))
1779 (org-entry-blocked-p))))
1781 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1782 (let ((org-enforce-todo-dependencies t
)
1784 '(org-block-todo-from-children-or-siblings-or-parent)))
1785 (org-entry-blocked-p))))
1786 ;; Follow :ORDERED: specifications.
1788 (org-test-with-temp-text
1789 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1790 (let ((org-enforce-todo-dependencies t
)
1792 '(org-block-todo-from-children-or-siblings-or-parent)))
1793 (org-entry-blocked-p))))
1795 (org-test-with-temp-text
1796 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1797 (let ((org-enforce-todo-dependencies t
)
1799 '(org-block-todo-from-children-or-siblings-or-parent)))
1800 (org-entry-blocked-p)))))
1802 (ert-deftest test-org
/get-outline-path
()
1803 "Test `org-get-outline-path' specifications."
1804 ;; Top-level headlines have no outline path.
1806 (org-test-with-temp-text "* H"
1807 (org-get-outline-path)))
1808 ;; Otherwise, outline path is the path leading to the headline.
1811 (org-test-with-temp-text "* H\n** S<point>"
1812 (org-get-outline-path))))
1813 ;; Find path even when point is not on a headline.
1816 (org-test-with-temp-text "* H\n** S\nText<point>"
1817 (org-get-outline-path))))
1818 ;; TODO keywords, tags and statistics cookies are ignored.
1821 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1822 (org-get-outline-path))))
1823 ;; Links are replaced with their description or their path.
1826 (org-test-with-temp-text
1827 "* [[https://orgmode.org][Org]]\n** S<point>"
1828 (org-get-outline-path))))
1830 (equal '("https://orgmode.org")
1831 (org-test-with-temp-text
1832 "* [[https://orgmode.org]]\n** S<point>"
1833 (org-get-outline-path))))
1834 ;; When WITH-SELF is non-nil, include current heading.
1837 (org-test-with-temp-text "* H"
1838 (org-get-outline-path t
))))
1841 (org-test-with-temp-text "* H\n** S\nText<point>"
1842 (org-get-outline-path t
))))
1843 ;; Using cache is transparent to the user.
1846 (org-test-with-temp-text "* H\n** S<point>"
1847 (setq org-outline-path-cache nil
)
1848 (org-get-outline-path nil t
))))
1849 ;; Do not corrupt cache when finding outline path in distant part of
1853 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1854 (setq org-outline-path-cache nil
)
1855 (org-get-outline-path nil t
)
1856 (search-forward "S2")
1857 (org-get-outline-path nil t
))))
1858 ;; Do not choke on empty headlines.
1860 (org-test-with-temp-text "* H\n** <point>"
1861 (org-get-outline-path)))
1863 (org-test-with-temp-text "* \n** H<point>"
1864 (org-get-outline-path))))
1866 (ert-deftest test-org
/format-outline-path
()
1867 "Test `org-format-outline-path' specifications."
1869 (string= (org-format-outline-path (list "one" "two" "three"))
1873 (string= (org-format-outline-path '())
1876 (string= (org-format-outline-path '(nil))
1878 ;; Empty path and prefix.
1880 (string= (org-format-outline-path '() nil
">>")
1882 ;; Trailing whitespace in headings.
1884 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1886 ;; Non-default prefix and separators.
1888 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1889 ">>|one|two|three"))
1892 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1894 ;; Give a very narrow width.
1896 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1898 ;; Give a prefix that extends beyond the width.
1900 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1904 (ert-deftest test-org
/map-entries
()
1905 "Test `org-map-entries' specifications."
1909 (org-test-with-temp-text "* Level 1\n** Level 2"
1910 (org-map-entries #'point
))))
1914 (org-test-with-temp-text "* Level 1\n** Level 2"
1915 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1918 (org-test-with-temp-text "* Level 1\n** Level 2"
1919 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1923 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1924 (org-map-entries #'point
"yes"))))
1927 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1928 (org-map-entries #'point
"+yes-a"))))
1931 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1932 (org-map-entries #'point
"{yes?}"))))
1936 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1937 (org-map-entries #'point
"PRIORITY=\"A\""))))
1941 (org-test-with-temp-text "
1943 SCHEDULED: <2012-03-29 thu.>
1945 SCHEDULED: <2014-03-04 tue.>"
1946 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1949 (org-test-with-temp-text "
1951 SCHEDULED: <2012-03-29 thu.>
1953 SCHEDULED: <2014-03-04 tue.>"
1954 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1955 ;; Regular property match.
1958 (org-test-with-temp-text "
1967 (org-map-entries #'point
"TEST=1"))))
1968 ;; Multiple criteria.
1971 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1972 (let (org-odd-levels-only
1973 (org-use-tag-inheritance nil
))
1974 (org-map-entries #'point
"yes+LEVEL=1")))))
1978 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1979 (let (org-odd-levels-only)
1980 (org-map-entries #'point
"LEVEL=2|no")))))
1983 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1984 (let (org-odd-levels-only)
1985 (org-map-entries #'point
"yes|no")))))
1989 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1990 (let (org-odd-levels-only)
1991 (org-map-entries #'point
"yes&no"))))))
1993 (ert-deftest test-org
/edit-headline
()
1994 "Test `org-edit-headline' specifications."
1997 (org-test-with-temp-text "* A"
1998 (org-edit-headline "B")
2000 ;; Handle empty headings.
2003 (org-test-with-temp-text "* A"
2004 (org-edit-headline "")
2008 (org-test-with-temp-text "* "
2009 (org-edit-headline "A")
2011 ;; Handle TODO keywords and priority cookies.
2014 (org-test-with-temp-text "* TODO A"
2015 (org-edit-headline "B")
2019 (org-test-with-temp-text "* [#A] A"
2020 (org-edit-headline "B")
2023 (equal "* TODO [#A] B"
2024 (org-test-with-temp-text "* TODO [#A] A"
2025 (org-edit-headline "B")
2029 (org-test-with-temp-text "* A :tag:"
2030 (let ((org-tags-column 4)) (org-edit-headline "B"))
2037 (ert-deftest test-org
/set-regexps-and-options
()
2038 "Test `org-set-regexps-and-options' specifications."
2042 (let ((org-tag-alist '(("A")))
2043 (org-tag-persistent-alist nil
))
2044 (org-test-with-temp-text ""
2046 org-current-tag-alist
))))
2049 (let ((org-tag-alist '(("A")))
2050 (org-tag-persistent-alist nil
))
2051 (org-test-with-temp-text "#+TAGS: B"
2053 org-current-tag-alist
))))
2055 (equal '(("C") ("B"))
2056 (let ((org-tag-alist '(("A")))
2057 (org-tag-persistent-alist '(("C"))))
2058 (org-test-with-temp-text "#+TAGS: B"
2060 org-current-tag-alist
))))
2063 (let ((org-tag-alist '(("A")))
2064 (org-tag-persistent-alist '(("C"))))
2065 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2067 org-current-tag-alist
))))
2069 (equal '(("A" . ?a
) ("B") ("C"))
2070 (let ((org-tag-persistant-alist nil
))
2071 (org-test-with-temp-text "#+TAGS: A(a) B C"
2073 org-current-tag-alist
))))
2075 (equal '(("A") (:newline
) ("B"))
2076 (let ((org-tag-persistent-alist nil
))
2077 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2079 org-current-tag-alist
))))
2081 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2082 (let ((org-tag-persistent-alist nil
))
2083 (org-test-with-temp-text "#+TAGS: { A B } C"
2085 org-current-tag-alist
))))
2087 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2088 (let ((org-tag-persistent-alist nil
))
2089 (org-test-with-temp-text "#+TAGS: { A : B C }"
2091 org-current-tag-alist
))))
2093 (equal '(("A" "B" "C"))
2094 (let ((org-tag-persistent-alist nil
))
2095 (org-test-with-temp-text "#+TAGS: { A : B C }"
2097 org-tag-groups-alist
))))
2099 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2100 (let ((org-tag-persistent-alist nil
))
2101 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2103 org-current-tag-alist
))))
2105 (equal '(("A" "B" "C"))
2106 (let ((org-tag-persistent-alist nil
))
2107 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2109 org-tag-groups-alist
))))
2110 ;; FILETAGS keyword.
2112 (equal '("A" "B" "C")
2113 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2116 ;; PROPERTY keyword. Property names are case-insensitive.
2119 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2121 (cdr (assoc "var" org-file-properties
)))))
2125 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2127 (cdr (assoc "var" org-file-properties
)))))
2131 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2133 (cdr (assoc "var" org-file-properties
)))))
2137 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2139 org-archive-location
)))
2140 ;; CATEGORY keyword.
2143 (org-test-with-temp-text "#+CATEGORY: test"
2148 (org-test-with-temp-text "#+CATEGORY: test"
2150 (cdr (assoc "CATEGORY" org-file-properties
)))))
2153 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2154 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2156 org-columns-default-format
)))
2157 ;; CONSTANTS keyword. Constants names are case sensitive.
2159 (equal '("299792458." "3.14")
2160 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2163 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2167 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2169 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2172 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2174 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2179 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2181 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2183 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2187 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2189 (list org-highest-priority org-lowest-priority org-default-priority
))))
2193 (org-test-with-temp-text "#+PRIORITIES: X Z"
2195 (list org-highest-priority org-lowest-priority org-default-priority
))))
2199 (org-test-with-temp-text "#+STARTUP: fold odd"
2201 (list org-startup-folded org-odd-levels-only
))))
2204 (equal '(("A" "B") ("C"))
2205 (org-test-with-temp-text "#+TODO: A B | C"
2207 (list org-not-done-keywords org-done-keywords
))))
2209 (equal '(("A" "C") ("B" "D"))
2210 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2212 (list org-not-done-keywords org-done-keywords
))))
2214 (equal '(("A" "B") ("C"))
2215 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2217 (list org-not-done-keywords org-done-keywords
))))
2219 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2220 (org-test-with-temp-text "#+TODO: A(a)"
2222 org-todo-key-alist
)))
2224 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2225 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2227 org-todo-log-states
)))
2228 ;; Enter SETUPFILE keyword.
2231 (org-test-with-temp-text
2232 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2234 (cdr (assoc "a" org-file-properties
))))))
2242 (ert-deftest test-org
/coderef
()
2243 "Test coderef links specifications."
2245 (org-test-with-temp-text "
2246 #+BEGIN_SRC emacs-lisp
2251 (looking-at "(ref:sc)")))
2252 ;; Find coderef even with alternate label format.
2254 (org-test-with-temp-text "
2255 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2260 (looking-at "{ref:sc}"))))
2264 (ert-deftest test-org
/custom-id
()
2265 "Test custom ID links specifications."
2267 (org-test-with-temp-text
2268 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2270 (looking-at-p "\\* H1")))
2271 ;; Throw an error on false positives.
2273 (org-test-with-temp-text
2274 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2276 (looking-at-p "\\* H1"))))
2280 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2281 ;; a named element (#+name: text) and to headlines (* Text).
2283 (ert-deftest test-org
/fuzzy-links
()
2284 "Test fuzzy links specifications."
2285 ;; Fuzzy link goes in priority to a matching target.
2287 (org-test-with-temp-text
2288 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2289 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2290 (looking-at "<<Test>>")))
2291 ;; Then fuzzy link points to an element with a given name.
2293 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2294 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2295 (looking-at "#\\+NAME: Test")))
2296 ;; A target still lead to a matching headline otherwise.
2298 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2299 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2300 (looking-at "\\* Head2")))
2301 ;; With a leading star in link, enforce heading match.
2303 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2304 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2305 (looking-at "\\* Test")))
2306 ;; With a leading star in link, enforce exact heading match, even
2307 ;; with `org-link-search-must-match-exact-headline' set to nil.
2309 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2310 (let ((org-link-search-must-match-exact-headline nil
))
2311 (org-open-at-point))))
2312 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2314 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2315 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2316 (looking-at "\\* Test")))
2318 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2319 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2320 (looking-at "\\* Test")))
2321 ;; Heading match should not care about spaces, cookies, TODO
2322 ;; keywords, priorities, and tags. However, TODO keywords are
2326 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2327 (org-test-with-temp-text
2328 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2329 (let ((org-link-search-must-match-exact-headline nil
)
2330 (org-todo-regexp "TODO"))
2331 (org-open-at-point))
2332 (looking-at (regexp-quote first-line
)))))
2334 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2335 (let ((org-link-search-must-match-exact-headline nil
)
2336 (org-todo-regexp "TODO"))
2337 (org-open-at-point))))
2338 ;; Heading match should still be exact.
2340 (org-test-with-temp-text "
2341 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2344 (let ((org-link-search-must-match-exact-headline nil
)
2345 (org-todo-regexp "TODO"))
2346 (org-open-at-point))))
2348 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2349 (let ((org-link-search-must-match-exact-headline nil
)
2350 (org-todo-regexp "TODO"))
2351 (org-open-at-point))
2352 (looking-at-p (regexp-quote "** Test 1 2"))))
2353 ;; Heading match ignores COMMENT keyword.
2355 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2357 (looking-at "\\* COMMENT Test")))
2359 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2361 (looking-at "\\* TODO COMMENT Test")))
2362 ;; Correctly un-hexify fuzzy links.
2364 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2368 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2371 ;; Match search strings containing newline characters, including
2374 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2375 (let ((file (buffer-file-name)))
2376 (goto-char (point-max))
2377 (insert (format "[[file:%s::line1 line2]]" file
))
2379 (let ((org-link-search-must-match-exact-headline nil
))
2380 (org-open-at-point 0))
2381 (looking-at-p "line1"))))
2383 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2384 (let ((file (buffer-file-name)))
2385 (goto-char (point-max))
2386 (insert (format "[[file:%s::line1 line2]]" file
))
2388 (let ((org-link-search-must-match-exact-headline nil
))
2389 (org-open-at-point 0))
2390 (looking-at-p "line1")))))
2394 (ert-deftest test-org
/org-link-escape-ascii-character
()
2395 "Escape an ascii character."
2399 (org-link-escape "["))))
2401 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2402 "Escape an ascii control character."
2406 (org-link-escape "\t"))))
2408 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2409 "Escape an unicode multibyte character."
2413 (org-link-escape "€"))))
2415 (ert-deftest test-org
/org-link-escape-custom-table
()
2416 "Escape string with custom character table."
2420 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2422 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2423 "Escape string with custom table merged with default table."
2426 "%5BF%6F%6F%3A%42ar%0A%5D"
2427 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2429 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2430 "Unescape an ascii character."
2434 (org-link-unescape "%5B"))))
2436 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2437 "Unescpae an ascii control character."
2441 (org-link-unescape "%0A"))))
2443 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2444 "Unescape unicode multibyte character."
2448 (org-link-unescape "%E2%82%AC"))))
2450 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2451 "Unescape old style percent escaped character."
2454 "à âçèéêîôùû"
2455 (decode-coding-string
2456 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2458 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2459 "Escape and unescape a URL that includes an escaped char.
2460 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2463 "http://some.host.com/form?&id=blah%2Bblah25"
2465 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2469 (ert-deftest test-org
/open-at-point
/keyword
()
2470 "Does `org-open-at-point' open link in a keyword line?"
2472 (org-test-with-temp-text
2473 "<<top>>\n#+KEYWORD: <point>[[top]]"
2474 (org-open-at-point) t
))
2476 (org-test-with-temp-text
2477 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2478 (org-open-at-point) t
)))
2480 (ert-deftest test-org
/open-at-point
/property
()
2481 "Does `org-open-at-point' open link in property drawer?"
2483 (org-test-with-temp-text
2486 :URL: <point>[[*Headline]]
2488 (org-open-at-point) t
)))
2490 (ert-deftest test-org
/open-at-point
/comment
()
2491 "Does `org-open-at-point' open link in a commented line?"
2493 (org-test-with-temp-text
2494 "<<top>>\n# <point>[[top]]"
2495 (org-open-at-point) t
))
2497 (org-test-with-temp-text
2498 "* H\n<<top>>\n# <point>[[top]]"
2499 (org-open-at-point) t
)))
2501 (ert-deftest test-org
/open-at-point
/inline-image
()
2502 "Test `org-open-at-point' on nested links."
2504 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2508 (ert-deftest test-org
/open-at-point
/radio-target
()
2509 "Test `org-open-at-point' on radio targets."
2511 (org-test-with-temp-text "<<<target>>> <point>target"
2512 (org-update-radio-target-regexp)
2514 (eq (org-element-type (org-element-context)) 'radio-target
))))
2516 (ert-deftest test-org
/open-at-point
/tag
()
2517 "Test `org-open-at-point' on tags."
2519 (org-test-with-temp-text "* H :<point>tag:"
2521 (cl-letf (((symbol-function 'org-tags-view
)
2522 (lambda (&rest args
) (throw :result t
))))
2526 (org-test-with-temp-text-in-file "* H<point> :tag:"
2528 (cl-letf (((symbol-function 'org-tags-view
)
2529 (lambda (&rest args
) (throw :result t
))))
2535 (ert-deftest test-org
/store-link
()
2536 "Test `org-store-link' specifications."
2537 ;; On a headline, link to that headline. Use heading as the
2538 ;; description of the link.
2540 (let (org-store-link-props org-stored-links
)
2541 (org-test-with-temp-text-in-file "* H1"
2542 (let ((file (buffer-file-name)))
2543 (equal (format "[[file:%s::*H1][H1]]" file
)
2544 (org-store-link nil
))))))
2545 ;; On a headline, remove any link from description.
2547 (let (org-store-link-props org-stored-links
)
2548 (org-test-with-temp-text-in-file "* [[#l][d]]"
2549 (let ((file (buffer-file-name)))
2550 (equal (format "[[file:%s::*%s][d]]"
2552 (org-link-escape "[[#l][d]]"))
2553 (org-store-link nil
))))))
2555 (let (org-store-link-props org-stored-links
)
2556 (org-test-with-temp-text-in-file "* [[l]]"
2557 (let ((file (buffer-file-name)))
2558 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2559 (org-store-link nil
))))))
2561 (let (org-store-link-props org-stored-links
)
2562 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2563 (let ((file (buffer-file-name)))
2564 (equal (format "[[file:%s::*%s][d1 d2]]"
2566 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2567 (org-store-link nil
))))))
2568 ;; On a named element, link to that element.
2570 (let (org-store-link-props org-stored-links
)
2571 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2572 (let ((file (buffer-file-name)))
2573 (equal (format "[[file:%s::foo][foo]]" file
)
2574 (org-store-link nil
))))))
2575 ;; Store link to Org buffer, with context.
2577 (let ((org-stored-links nil
)
2578 (org-id-link-to-org-use-id nil
)
2579 (org-context-in-file-links t
))
2580 (org-test-with-temp-text-in-file "* h1"
2581 (let ((file (buffer-file-name)))
2582 (equal (format "[[file:%s::*h1][h1]]" file
)
2583 (org-store-link nil
))))))
2584 ;; Store link to Org buffer, without context.
2586 (let ((org-stored-links nil
)
2587 (org-id-link-to-org-use-id nil
)
2588 (org-context-in-file-links nil
))
2589 (org-test-with-temp-text-in-file "* h1"
2590 (let ((file (buffer-file-name)))
2591 (equal (format "[[file:%s][file:%s]]" file file
)
2592 (org-store-link nil
))))))
2593 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2595 (let ((org-stored-links nil
)
2596 (org-id-link-to-org-use-id nil
)
2597 (org-context-in-file-links nil
))
2598 (org-test-with-temp-text-in-file "* h1"
2599 (let ((file (buffer-file-name)))
2600 (equal (format "[[file:%s::*h1][h1]]" file
)
2601 (org-store-link '(4)))))))
2602 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2605 (let ((org-stored-links nil
)
2606 (org-id-link-to-org-use-id nil
)
2607 (org-context-in-file-links nil
))
2608 (org-test-with-temp-text-in-file "* h1"
2609 (let ((file (buffer-file-name)))
2610 (equal (format "[[file:%s][file:%s]]" file file
)
2611 (org-store-link '(16)))))))
2612 ;; Store file link to non-Org buffer, with context.
2614 (let ((org-stored-links nil
)
2615 (org-context-in-file-links t
))
2616 (org-test-with-temp-text-in-file "one\n<point>two"
2618 (let ((file (buffer-file-name)))
2619 (equal (format "[[file:%s::one]]" file
)
2620 (org-store-link nil
))))))
2621 ;; Store file link to non-Org buffer, without context.
2623 (let ((org-stored-links nil
)
2624 (org-context-in-file-links nil
))
2625 (org-test-with-temp-text-in-file "one\n<point>two"
2627 (let ((file (buffer-file-name)))
2628 (equal (format "[[file:%s][file:%s]]" file file
)
2629 (org-store-link nil
))))))
2630 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2633 (let ((org-stored-links nil
)
2634 (org-context-in-file-links nil
))
2635 (org-test-with-temp-text-in-file "one\n<point>two"
2637 (let ((file (buffer-file-name)))
2638 (equal (format "[[file:%s::one]]" file
)
2639 (org-store-link '(4)))))))
2640 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2643 (let ((org-stored-links nil
)
2644 (org-context-in-file-links nil
))
2645 (org-test-with-temp-text-in-file "one\n<point>two"
2647 (let ((file (buffer-file-name)))
2648 (equal (format "[[file:%s][file:%s]]" file file
)
2649 (org-store-link '(16))))))))
2654 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2655 "Ensure properties accumulate in subtree drawers."
2656 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2657 (org-babel-next-src-block)
2658 (should (equal '(2 1) (org-babel-execute-src-block)))))
2660 (ert-deftest test-org
/custom-properties
()
2661 "Test custom properties specifications."
2664 (let ((org-custom-properties '("FOO")))
2665 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2666 (org-toggle-custom-properties-visibility)
2667 (org-invisible-p2))))
2668 ;; Properties are case-insensitive.
2670 (let ((org-custom-properties '("FOO")))
2671 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2672 (org-toggle-custom-properties-visibility)
2673 (org-invisible-p2))))
2675 (let ((org-custom-properties '("foo")))
2676 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2677 (org-toggle-custom-properties-visibility)
2678 (org-invisible-p2))))
2679 ;; Multiple custom properties in the same drawer.
2681 (let ((org-custom-properties '("FOO" "BAR")))
2682 (org-test-with-temp-text
2683 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2684 (org-toggle-custom-properties-visibility)
2685 (and (org-invisible-p2)
2686 (not (progn (forward-line) (org-invisible-p2)))
2687 (progn (forward-line) (org-invisible-p2))))))
2688 ;; Hide custom properties with an empty value.
2690 (let ((org-custom-properties '("FOO")))
2691 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2692 (org-toggle-custom-properties-visibility)
2693 (org-invisible-p2))))
2694 ;; Do not hide fake properties.
2696 (let ((org-custom-properties '("FOO")))
2697 (org-test-with-temp-text ":FOO: val\n"
2698 (org-toggle-custom-properties-visibility)
2699 (org-invisible-p2))))
2701 (let ((org-custom-properties '("A")))
2702 (org-test-with-temp-text
2703 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2704 (org-toggle-custom-properties-visibility)
2705 (org-invisible-p2)))))
2711 (ert-deftest test-org
/mark-subtree
()
2712 "Test `org-mark-subtree' specifications."
2713 ;; Error when point is before first headline.
2715 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2716 (progn (transient-mark-mode 1)
2717 (org-mark-subtree))))
2718 ;; Without argument, mark current subtree.
2722 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2723 (progn (transient-mark-mode 1)
2726 (list (region-beginning) (region-end))))))
2727 ;; With an argument, move ARG up.
2731 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2732 (progn (transient-mark-mode 1)
2734 (org-mark-subtree 1)
2735 (list (region-beginning) (region-end))))))
2736 ;; Do not get fooled by inlinetasks.
2737 (when (featurep 'org-inlinetask
)
2740 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2741 (progn (transient-mark-mode 1)
2743 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2744 (region-beginning)))))))
2750 (ert-deftest test-org
/sort-entries
()
2751 "Test `org-sort-entries'."
2752 ;; Sort alphabetically.
2754 (equal "\n* abc\n* def\n* xyz\n"
2755 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2756 (org-sort-entries nil ?a
)
2759 (equal "\n* xyz\n* def\n* abc\n"
2760 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2761 (org-sort-entries nil ?A
)
2764 (equal "\n* \n* klm\n* xyz\n"
2765 (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
2766 (org-sort-entries nil ?a
)
2768 ;; Sort numerically.
2770 (equal "\n* 1\n* 2\n* 10\n"
2771 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2772 (org-sort-entries nil ?n
)
2775 (equal "\n* 10\n* 2\n* 1\n"
2776 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2777 (org-sort-entries nil ?N
)
2780 (equal "\n* \n* 1\n* 2\n"
2781 (org-test-with-temp-text "\n* 1\n* \n* 2\n"
2782 (org-sort-entries nil ?n
)
2784 ;; Sort by custom function.
2786 (equal "\n* b\n* aa\n* ccc\n"
2787 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2788 (org-sort-entries nil ?f
2790 (length (buffer-substring (point-at-bol)
2795 (equal "\n* ccc\n* aa\n* b\n"
2796 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2797 (org-sort-entries nil ?F
2799 (length (buffer-substring (point-at-bol)
2803 ;; Sort by TODO keyword.
2805 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2806 (org-test-with-temp-text
2807 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2808 (org-sort-entries nil ?o
)
2811 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2812 (org-test-with-temp-text
2813 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2814 (org-sort-entries nil ?O
)
2816 ;; Sort by priority.
2818 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2819 (org-test-with-temp-text
2820 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2821 (org-sort-entries nil ?p
)
2824 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2825 (org-test-with-temp-text
2826 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2827 (org-sort-entries nil ?P
)
2829 ;; Sort by creation time.
2839 (org-test-with-temp-text
2848 (org-sort-entries nil ?c
)
2851 ;; Sort by scheduled date.
2855 SCHEDULED: <2017-05-06 Sat>
2857 SCHEDULED: <2017-05-08 Mon>
2859 DEADLINE: <2017-05-09 Tue>
2861 DEADLINE: <2017-05-07 Sun>
2863 (org-test-with-temp-text
2866 DEADLINE: <2017-05-09 Tue>
2868 DEADLINE: <2017-05-07 Sun>
2870 SCHEDULED: <2017-05-08 Mon>
2872 SCHEDULED: <2017-05-06 Sat>
2874 (org-sort-entries nil ?s
)
2876 ;; Sort by deadline date.
2880 DEADLINE: <2017-05-07 Sun>
2882 DEADLINE: <2017-05-09 Tue>
2884 SCHEDULED: <2017-05-08 Mon>
2886 SCHEDULED: <2017-05-06 Sat>
2888 (org-test-with-temp-text
2891 DEADLINE: <2017-05-09 Tue>
2893 DEADLINE: <2017-05-07 Sun>
2895 SCHEDULED: <2017-05-08 Mon>
2897 SCHEDULED: <2017-05-06 Sat>
2899 (org-sort-entries nil ?d
)
2901 ;; Sort by any date/time
2905 SCHEDULED: <2017-05-06 Sat>
2907 DEADLINE: <2017-05-07 Sun>
2909 SCHEDULED: <2017-05-08 Mon>
2911 DEADLINE: <2017-05-09 Tue>
2913 (org-test-with-temp-text
2916 DEADLINE: <2017-05-09 Tue>
2918 DEADLINE: <2017-05-07 Sun>
2920 SCHEDULED: <2017-05-08 Mon>
2922 SCHEDULED: <2017-05-06 Sat>
2924 (org-sort-entries nil ?t
)
2926 ;; Sort by clocking time.
2931 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2932 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2936 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2937 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2940 (org-test-with-temp-text
2944 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2945 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2949 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2950 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2953 (org-sort-entries nil ?k
)
2955 ;; Preserve file local variables when sorting.
2957 (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
2958 (org-test-with-temp-text
2959 "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
2960 (org-sort-entries nil ?a
)
2963 (ert-deftest test-org
/string-collate-greaterp
()
2964 "Test `org-string-collate-greaterp' specifications."
2965 (should (org-string-collate-greaterp "def" "abc"))
2966 (should-not (org-string-collate-greaterp "abc" "def")))
2968 (ert-deftest test-org
/file-contents
()
2969 "Test `org-file-contents' specifications."
2972 (string= "#+BIND: variable value
2978 " (org-file-contents (expand-file-name "setupfile3.org"
2979 (concat org-test-dir
"examples/")))))
2980 ;; Throw error when trying to access an invalid file.
2981 (should-error (org-file-contents "this-file-must-not-exist"))
2982 ;; Try to access an invalid file, but do not throw an error.
2984 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2988 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2990 ;; Simulate successful retrieval of a URL.
2991 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2993 (with-current-buffer buffer
2994 (insert "HTTP/1.1 200 OK\n\nfoo"))
2996 (org-file-contents "http://some-valid-url"))
2997 (kill-buffer buffer
)))))
2998 ;; Throw error when trying to access an invalid URL.
3000 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3002 ;; Simulate unsuccessful retrieval of a URL.
3003 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3005 (with-current-buffer buffer
3006 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3008 (org-file-contents "http://this-url-must-not-exist"))
3009 (kill-buffer buffer
))))
3010 ;; Try to access an invalid URL, but do not throw an error.
3012 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3014 ;; Simulate unsuccessful retrieval of a URL.
3015 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3017 (with-current-buffer buffer
3018 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3020 (org-file-contents "http://this-url-must-not-exist"))
3021 (kill-buffer buffer
))))
3023 (let ((buffer (generate-new-buffer "url-retrieve-output")))
3025 ;; Simulate unsuccessful retrieval of a URL.
3026 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
3028 (with-current-buffer buffer
3029 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
3031 (org-file-contents "http://this-url-must-not-exist" :noerror
))
3032 (kill-buffer buffer
))
3038 (ert-deftest test-org
/forward-heading-same-level
()
3039 "Test `org-forward-heading-same-level' specifications."
3040 ;; Test navigation at top level, forward and backward.
3043 (org-test-with-temp-text "* H1\n* H2"
3044 (org-forward-heading-same-level 1)
3045 (buffer-substring-no-properties (point) (line-end-position)))))
3048 (org-test-with-temp-text "* H1\n<point>* H2"
3049 (org-forward-heading-same-level -
1)
3050 (buffer-substring-no-properties (point) (line-end-position)))))
3051 ;; Test navigation in a sub-tree, forward and backward.
3054 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
3055 (org-forward-heading-same-level 1)
3056 (buffer-substring-no-properties (point) (line-end-position)))))
3059 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3060 (org-forward-heading-same-level -
1)
3061 (buffer-substring-no-properties (point) (line-end-position)))))
3062 ;; Stop at first or last sub-heading.
3065 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3066 (org-forward-heading-same-level 1)
3067 (buffer-substring-no-properties (point) (line-end-position)))))
3070 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3071 (org-forward-heading-same-level -
1)
3072 (buffer-substring-no-properties (point) (line-end-position)))))
3073 ;; Allow multiple moves.
3076 (org-test-with-temp-text "* H1\n* H2\n* H3"
3077 (org-forward-heading-same-level 2)
3078 (buffer-substring-no-properties (point) (line-end-position)))))
3081 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3082 (org-forward-heading-same-level -
2)
3083 (buffer-substring-no-properties (point) (line-end-position)))))
3084 ;; Ignore spurious moves when first (or last) sibling is reached.
3087 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3088 (org-forward-heading-same-level 100)
3089 (buffer-substring-no-properties (point) (line-end-position)))))
3092 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3093 (org-forward-heading-same-level -
100)
3094 (buffer-substring-no-properties (point) (line-end-position))))))
3096 (ert-deftest test-org
/end-of-meta-data
()
3097 "Test `org-end-of-meta-data' specifications."
3098 ;; Skip planning line.
3100 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3101 (org-end-of-meta-data)
3103 ;; Skip properties drawer.
3105 (org-test-with-temp-text
3106 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3107 (org-end-of-meta-data)
3111 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3112 (org-end-of-meta-data)
3114 ;; Nothing to skip, go to first line.
3116 (org-test-with-temp-text "* Headline\nContents"
3117 (org-end-of-meta-data)
3118 (looking-at "Contents")))
3119 ;; With option argument, skip empty lines, regular drawers and
3122 (org-test-with-temp-text "* Headline\n\nContents"
3123 (org-end-of-meta-data t
)
3124 (looking-at "Contents")))
3126 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3127 (org-end-of-meta-data t
)
3128 (looking-at "Contents")))
3130 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3131 (org-end-of-meta-data t
)
3132 (looking-at "Contents")))
3133 ;; Special case: do not skip incomplete drawers.
3135 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3136 (org-end-of-meta-data t
)
3137 (looking-at ":LOGBOOK:")))
3138 ;; Special case: Be careful about consecutive headlines.
3140 (org-test-with-temp-text "* H1\n*H2\nContents"
3141 (org-end-of-meta-data t
)
3142 (looking-at "Contents"))))
3144 (ert-deftest test-org
/beginning-of-line
()
3145 "Test `org-beginning-of-line' specifications."
3146 ;; Move to beginning of line. If current line in invisible, move to
3147 ;; beginning of visible line instead.
3149 (org-test-with-temp-text "Some text\nSome other text<point>"
3150 (org-beginning-of-line)
3153 (org-test-with-temp-text "* H1\n** H2<point>"
3155 (org-beginning-of-line)
3156 (= (line-beginning-position) 1)))
3157 ;; With `visual-line-mode' active, move to beginning of visual line.
3159 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3161 (dotimes (i 1000) (insert "very "))
3162 (org-beginning-of-line)
3164 ;; In a wide headline, with `visual-line-mode', prefer going to the
3165 ;; beginning of a visual line than to the logical beginning of line,
3166 ;; even if special movement is active.
3168 (org-test-with-temp-text "* A <point>long headline"
3170 (dotimes (i 1000) (insert "very "))
3171 (goto-char (point-max))
3172 (org-beginning-of-line)
3175 (org-test-with-temp-text "* A <point>long headline"
3177 (dotimes (i 1000) (insert "very "))
3178 (goto-char (point-max))
3179 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3181 ;; At an headline with special movement, first move at beginning of
3182 ;; title, then at the beginning of line, rinse, repeat.
3184 (org-test-with-temp-text "* TODO Headline<point>"
3185 (let ((org-special-ctrl-a/e t
))
3186 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3187 (progn (org-beginning-of-line) (bolp))
3188 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3190 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3191 (let ((org-special-ctrl-a/e t
))
3192 (org-beginning-of-line)
3193 (looking-at "Headline"))))
3195 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3196 (let ((org-special-ctrl-a/e
'(t . nil
)))
3197 (org-beginning-of-line)
3198 (looking-at "Headline"))))
3200 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3201 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3202 (org-beginning-of-line)
3203 (looking-at "Headline"))))
3204 ;; At an headline with reversed movement, first move to beginning of
3205 ;; line, then to the beginning of title.
3207 (org-test-with-temp-text "* TODO Headline<point>"
3208 (let ((org-special-ctrl-a/e
'reversed
)
3209 (this-command last-command
))
3210 (and (progn (org-beginning-of-line) (bolp))
3211 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3213 (org-test-with-temp-text "* TODO Headline<point>"
3214 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3215 (this-command last-command
))
3216 (and (progn (org-beginning-of-line) (bolp))
3217 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3219 (org-test-with-temp-text "* TODO Headline<point>"
3220 (let ((org-special-ctrl-a/e
'(t . nil
))
3221 (this-command last-command
))
3222 (and (progn (org-beginning-of-line) (bolp))
3223 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3224 ;; At an item with special movement, first move after to beginning
3225 ;; of title, then to the beginning of line, rinse, repeat.
3227 (org-test-with-temp-text "- [ ] Item<point>"
3228 (let ((org-special-ctrl-a/e t
))
3229 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3230 (progn (org-beginning-of-line) (bolp))
3231 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3232 ;; At an item with reversed movement, first move to beginning of
3233 ;; line, then to the beginning of title.
3235 (org-test-with-temp-text "- [X] Item<point>"
3236 (let ((org-special-ctrl-a/e
'reversed
)
3237 (this-command last-command
))
3238 (and (progn (org-beginning-of-line) (bolp))
3239 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3240 ;; Leave point before invisible characters at column 0.
3242 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3243 (let ((org-special-ctrl-a/e nil
))
3244 (org-beginning-of-line)
3247 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3248 (let ((org-special-ctrl-a/e t
))
3249 (org-beginning-of-line)
3252 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3254 (org-beginning-of-line)
3256 ;; Special case: Do not error when the buffer contains only a single
3259 (org-test-with-temp-text "*<point>"
3260 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3262 (org-test-with-temp-text "*<point>"
3263 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3265 (ert-deftest test-org
/end-of-line
()
3266 "Test `org-end-of-line' specifications."
3269 (org-test-with-temp-text "Some text\nSome other text"
3272 ;; With `visual-line-mode' active, move to end of visible line.
3273 ;; However, never go past ellipsis.
3275 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3277 (dotimes (i 1000) (insert "very "))
3278 (goto-char (point-min))
3282 (org-test-with-temp-text "* A short headline\nSome contents"
3287 ;; In a wide headline, with `visual-line-mode', prefer going to end
3288 ;; of visible line if tags, or end of line, are farther.
3290 (org-test-with-temp-text "* A <point>long headline"
3292 (dotimes (i 1000) (insert "very "))
3293 (goto-char (point-min))
3297 (org-test-with-temp-text "* A <point>long headline :tag:"
3299 (dotimes (i 1000) (insert "very "))
3300 (goto-char (point-min))
3303 ;; At an headline without special movement, go to end of line.
3304 ;; However, never go past ellipsis.
3306 (org-test-with-temp-text "* Headline2b :tag:\n"
3307 (let ((org-special-ctrl-a/e nil
))
3308 (and (progn (org-end-of-line) (eolp))
3309 (progn (org-end-of-line) (eolp))))))
3311 (org-test-with-temp-text "* Headline2b :tag:\n"
3312 (let ((org-special-ctrl-a/e
'(t . nil
)))
3313 (and (progn (org-end-of-line) (eolp))
3314 (progn (org-end-of-line) (eolp))))))
3316 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3318 (let ((org-special-ctrl-a/e nil
))
3320 (= 1 (line-beginning-position)))))
3321 ;; At an headline with special movement, first move before tags,
3322 ;; then at the end of line, rinse, repeat. However, never go past
3325 (org-test-with-temp-text "* Headline1 :tag:\n"
3326 (let ((org-special-ctrl-a/e t
))
3327 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3328 (progn (org-end-of-line) (eolp))
3329 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3331 (org-test-with-temp-text "* Headline1 :tag:\n"
3332 (let ((org-special-ctrl-a/e
'(nil . t
)))
3333 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3334 (progn (org-end-of-line) (eolp))
3335 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3337 (org-test-with-temp-text "* Headline1 :tag:\n"
3338 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3339 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3340 (progn (org-end-of-line) (eolp))
3341 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3343 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3345 (let ((org-special-ctrl-a/e t
))
3348 (= 1 (line-beginning-position)))))
3349 ;; At an headline, with reversed movement, first go to end of line,
3350 ;; then before tags. However, never go past ellipsis.
3352 (org-test-with-temp-text "* Headline3 :tag:\n"
3353 (let ((org-special-ctrl-a/e
'reversed
)
3354 (this-command last-command
))
3355 (and (progn (org-end-of-line) (eolp))
3356 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3358 (org-test-with-temp-text "* Headline3 :tag:\n"
3359 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3360 (this-command last-command
))
3361 (and (progn (org-end-of-line) (eolp))
3362 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3364 (org-test-with-temp-text "* Headline3 :tag:\n"
3365 (let ((org-special-ctrl-a/e
'(nil . t
))
3366 (this-command last-command
))
3367 (and (progn (org-end-of-line) (eolp))
3368 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3370 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3372 (let ((org-special-ctrl-a/e
'reversed
))
3374 (= 1 (line-beginning-position)))))
3375 ;; At a block without hidden contents.
3377 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3378 (progn (org-end-of-line) (eolp))))
3379 ;; At a block with hidden contents.
3381 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3382 (let ((org-special-ctrl-a/e t
))
3383 (org-hide-block-toggle)
3386 ;; Get past invisible characters at the end of line.
3388 (org-test-with-temp-text "[[https://orgmode.org]]"
3392 (ert-deftest test-org
/open-line
()
3393 "Test `org-open-line' specifications."
3394 ;; Call `open-line' outside of tables.
3397 (org-test-with-temp-text "Text"
3400 ;; At a table, create a row above.
3402 (equal "\n| |\n| a |"
3403 (org-test-with-temp-text "\n<point>| a |"
3406 ;; At the very first character of the buffer, also call `open-line'.
3409 (org-test-with-temp-text "| a |"
3412 ;; Narrowing does not count.
3414 (equal "Text\n| |\n| a |"
3415 (org-test-with-temp-text "Text\n<point>| a |"
3416 (narrow-to-region (point) (point-max))
3421 (ert-deftest test-org
/forward-sentence
()
3422 "Test `org-forward-sentence' specifications."
3423 ;; At the end of a table cell, move to the end of the next one.
3425 (org-test-with-temp-text "| a<point> | b |"
3426 (org-forward-sentence)
3427 (looking-at " |$")))
3428 ;; Elsewhere in a cell, move to its end.
3430 (org-test-with-temp-text "| a<point>c | b |"
3431 (org-forward-sentence)
3432 (looking-at " | b |$")))
3433 ;; Otherwise, simply call `forward-sentence'.
3435 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3436 (org-forward-sentence)
3437 (looking-at " Sentence 2.")))
3439 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3440 (org-forward-sentence)
3441 (org-forward-sentence)
3443 ;; At the end of an element, jump to the next one, without stopping
3444 ;; on blank lines in-between.
3446 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3447 (org-forward-sentence)
3449 ;; Headlines are considered to be sentences by themselves, even if
3450 ;; they do not end with a full stop.
3454 (org-test-with-temp-text "* <point>Headline\nSentence."
3455 (org-forward-sentence)
3456 (buffer-substring-no-properties (line-beginning-position) (point)))))
3458 (org-test-with-temp-text "* Headline<point>\nSentence."
3459 (org-forward-sentence)
3462 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3463 (org-forward-sentence)
3464 (and (org-at-heading-p) (eolp)))))
3466 (ert-deftest test-org
/backward-sentence
()
3467 "Test `org-backward-sentence' specifications."
3468 ;; At the beginning of a table cell, move to the beginning of the
3471 (org-test-with-temp-text "| a | <point>b |"
3472 (org-backward-sentence)
3473 (looking-at "a | b |$")))
3474 ;; Elsewhere in a cell, move to its beginning.
3476 (org-test-with-temp-text "| a | b<point>c |"
3477 (org-backward-sentence)
3478 (looking-at "bc |$")))
3479 ;; Otherwise, simply call `backward-sentence'.
3481 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3482 (org-backward-sentence)
3483 (looking-at "Sentence 2.")))
3485 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3486 (org-backward-sentence)
3487 (org-backward-sentence)
3489 ;; Make sure to hit the beginning of a sentence on the same line as
3492 (org-test-with-temp-text "- Line 1\n line <point>2."
3493 (org-backward-sentence)
3494 (looking-at "Line 1"))))
3496 (ert-deftest test-org
/forward-paragraph
()
3497 "Test `org-forward-paragraph' specifications."
3498 ;; At end of buffer, do not return an error.
3500 (org-test-with-temp-text "Paragraph"
3501 (goto-char (point-max))
3502 (org-forward-paragraph)
3506 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3507 (org-forward-paragraph)
3511 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3512 (org-forward-paragraph)
3514 ;; Do not enter elements with invisible contents.
3516 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3517 (org-hide-block-toggle)
3518 (org-forward-paragraph)
3520 ;; On an affiliated keyword, jump to the beginning of the element.
3522 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3523 (org-forward-paragraph)
3524 (looking-at "Para")))
3525 ;; On an item or a footnote definition, move to the second element
3528 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3529 (org-forward-paragraph)
3530 (looking-at " Paragraph")))
3532 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3533 (org-forward-paragraph)
3534 (looking-at "Paragraph")))
3535 ;; On an item, or a footnote definition, when the first line is
3536 ;; empty, move to the first item.
3538 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3539 (org-forward-paragraph)
3540 (looking-at " Paragraph")))
3542 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3543 (org-forward-paragraph)
3544 (looking-at "Paragraph")))
3545 ;; On a table (resp. a property drawer) do not move through table
3546 ;; rows (resp. node properties).
3548 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3549 (org-forward-paragraph)
3550 (looking-at "Paragraph")))
3552 (org-test-with-temp-text
3553 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3554 (org-forward-paragraph)
3555 (looking-at "Paragraph")))
3556 ;; On a verse or source block, stop after blank lines.
3558 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3559 (org-forward-paragraph)
3562 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3563 (org-forward-paragraph)
3564 (looking-at "L2"))))
3566 (ert-deftest test-org
/backward-paragraph
()
3567 "Test `org-backward-paragraph' specifications."
3568 ;; Do not error at beginning of buffer.
3570 (org-test-with-temp-text "Paragraph"
3571 (org-backward-paragraph)
3575 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3576 (org-backward-paragraph)
3579 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3580 (org-backward-paragraph)
3581 (looking-at-p "P2")))
3584 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3585 (org-backward-paragraph)
3586 (looking-at-p "P2")))
3587 ;; Ignore invisible elements.
3589 (org-test-with-temp-text "* H1\n P1\n* H2"
3591 (goto-char (point-max))
3593 (org-backward-paragraph)
3595 ;; On an affiliated keyword, jump to the first one.
3597 (org-test-with-temp-text
3598 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3599 (org-backward-paragraph)
3600 (looking-at-p "#\\+name")))
3601 ;; On the second element in an item or a footnote definition, jump
3602 ;; to item or the definition.
3604 (org-test-with-temp-text "- line1\n\n<point> line2"
3605 (org-backward-paragraph)
3606 (looking-at-p "- line1")))
3608 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3609 (org-backward-paragraph)
3610 (looking-at-p "\\[fn:1\\] line1")))
3611 ;; On a table (resp. a property drawer), ignore table rows
3612 ;; (resp. node properties).
3614 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3615 (org-backward-paragraph)
3618 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3619 (org-backward-paragraph)
3620 (looking-at-p ":PROPERTIES:")))
3621 ;; On a comment, example, src and verse blocks, stop before blank
3624 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3625 (org-backward-paragraph)
3626 (looking-at-p "L2")))
3628 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3629 (org-backward-paragraph)
3630 (looking-at-p "L2")))
3631 ;; In comment, example, export, src and verse blocks, stop below
3632 ;; opening line when called from within the block.
3634 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3635 (org-backward-paragraph)
3636 (looking-at-p "L1")))
3638 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3639 (org-backward-paragraph)
3640 (looking-at-p "L1")))
3641 ;; When called from the opening line itself, however, move to
3642 ;; beginning of block.
3644 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3645 (org-backward-paragraph)
3647 ;; Pathological case: on an empty heading, move to its beginning.
3649 (org-test-with-temp-text "* <point>H"
3650 (org-backward-paragraph)
3653 (ert-deftest test-org
/forward-element
()
3654 "Test `org-forward-element' specifications."
3655 ;; 1. At EOB: should error.
3656 (org-test-with-temp-text "Some text\n"
3657 (goto-char (point-max))
3658 (should-error (org-forward-element)))
3659 ;; 2. Standard move: expected to ignore blank lines.
3660 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3661 (org-forward-element)
3662 (should (looking-at (regexp-quote "Second paragraph."))))
3663 ;; 3. Headline tests.
3664 (org-test-with-temp-text "
3669 ;; 3.1. At an headline beginning: move to next headline at the
3672 (org-forward-element)
3673 (should (looking-at (regexp-quote "** Head 1.2")))
3674 ;; 3.2. At an headline beginning: move to parent headline if no
3675 ;; headline at the same level.
3677 (org-forward-element)
3678 (should (looking-at (regexp-quote "** Head 1.2"))))
3679 ;; 4. Greater element tests.
3680 (org-test-with-temp-text
3681 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3682 ;; 4.1. At a greater element: expected to skip contents.
3683 (org-forward-element)
3684 (should (looking-at (regexp-quote "Outside.")))
3685 ;; 4.2. At the end of greater element contents: expected to skip
3686 ;; to the end of the greater element.
3688 (org-forward-element)
3689 (should (looking-at (regexp-quote "Outside."))))
3691 (org-test-with-temp-text "
3705 ;; 5.1. At list top point: expected to move to the element after
3708 (org-forward-element)
3709 (should (looking-at (regexp-quote "Outside.")))
3710 ;; 5.2. Special case: at the first line of a sub-list, but not at
3711 ;; beginning of line, move to next item.
3714 (org-forward-element)
3715 (should (looking-at "- item2"))
3718 (org-forward-element)
3719 (should (looking-at " - sub2"))
3720 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3722 (org-forward-element)
3723 (should (looking-at (regexp-quote " Inner paragraph.")))
3724 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3726 (org-forward-element)
3727 (should (looking-at (regexp-quote " Inner paragraph.")))
3728 ;; 5.5. At an item: expected to move to next item, if any.
3730 (org-forward-element)
3731 (should (looking-at " - sub3"))))
3733 (ert-deftest test-org
/backward-element
()
3734 "Test `org-backward-element' specifications."
3735 ;; 1. Should error at BOB.
3736 (org-test-with-temp-text " \nParagraph."
3737 (should-error (org-backward-element)))
3738 ;; 2. Should move at BOB when called on the first element in buffer.
3740 (org-test-with-temp-text "\n#+TITLE: test"
3741 (progn (forward-line)
3742 (org-backward-element)
3744 ;; 3. Not at the beginning of an element: move at its beginning.
3745 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3748 (org-backward-element)
3749 (should (looking-at (regexp-quote "Paragraph2."))))
3750 ;; 4. Headline tests.
3751 (org-test-with-temp-text "
3756 ;; 4.1. At an headline beginning: move to previous headline at the
3759 (org-backward-element)
3760 (should (looking-at (regexp-quote "** Head 1.1")))
3761 ;; 4.2. At an headline beginning: move to parent headline if no
3762 ;; headline at the same level.
3764 (org-backward-element)
3765 (should (looking-at (regexp-quote "* Head 1")))
3766 ;; 4.3. At the first top-level headline: should error.
3768 (should-error (org-backward-element)))
3769 ;; 5. At beginning of first element inside a greater element:
3770 ;; expected to move to greater element's beginning.
3771 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3773 (org-backward-element)
3774 (should (looking-at "#\\+BEGIN_CENTER")))
3775 ;; 6. At the beginning of the first element in a section: should
3776 ;; move back to headline, if any.
3778 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3779 (progn (goto-char (point-max))
3781 (org-backward-element)
3782 (org-at-heading-p))))
3784 (org-test-with-temp-text "
3799 ;; 7.1. At beginning of sub-list: expected to move to the
3800 ;; paragraph before it.
3802 (org-backward-element)
3803 (should (looking-at "item1"))
3804 ;; 7.2. At an item in a list: expected to move at previous item.
3806 (org-backward-element)
3807 (should (looking-at " - sub2"))
3809 (org-backward-element)
3810 (should (looking-at "- item1"))
3811 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3814 (org-backward-element)
3815 (should (looking-at " - sub1"))
3817 (org-backward-element)
3818 (should (looking-at "- item1"))
3819 ;; 7.4. At blank-lines before list end: expected to move to top
3822 (org-backward-element)
3823 (should (looking-at "- item1"))))
3825 (ert-deftest test-org
/up-element
()
3826 "Test `org-up-element' specifications."
3827 ;; 1. At BOB or with no surrounding element: should error.
3828 (org-test-with-temp-text "Paragraph."
3829 (should-error (org-up-element)))
3830 (org-test-with-temp-text "* Head1\n* Head2"
3832 (should-error (org-up-element)))
3833 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3835 (should-error (org-up-element)))
3836 ;; 2. At an headline: move to parent headline.
3837 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3840 (should (looking-at "\\* Head1")))
3841 ;; 3. Inside a greater element: move to greater element beginning.
3842 (org-test-with-temp-text
3843 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3846 (should (looking-at "#\\+BEGIN_CENTER")))
3848 (org-test-with-temp-text "* Top
3855 Paragraph within sub2.
3858 ;; 4.1. Within an item: move to the item beginning.
3861 (should (looking-at " - sub2"))
3862 ;; 4.2. At an item in a sub-list: move to parent item.
3865 (should (looking-at "- item1"))
3866 ;; 4.3. At an item in top list: move to beginning of whole list.
3869 (should (looking-at "- item1"))
3870 ;; 4.4. Special case. At very top point: should move to parent of
3874 (should (looking-at "\\* Top"))))
3876 (ert-deftest test-org
/down-element
()
3877 "Test `org-down-element' specifications."
3878 ;; Error when the element hasn't got a recursive type.
3879 (org-test-with-temp-text "Paragraph."
3880 (should-error (org-down-element)))
3881 ;; Error when the element has no contents
3882 (org-test-with-temp-text "* Headline"
3883 (should-error (org-down-element)))
3884 ;; When at a plain-list, move to first item.
3885 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3888 (should (looking-at " - Item 1.1")))
3889 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3891 (should (looking-at " Item 1")))
3892 ;; When at a table, move to first row
3893 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3895 (should (looking-at " a | b |")))
3896 ;; Otherwise, move inside the greater element.
3897 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3899 (should (looking-at "Paragraph"))))
3901 (ert-deftest test-org
/drag-element-backward
()
3902 "Test `org-drag-element-backward' specifications."
3906 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3907 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3908 (org-drag-element-backward)
3912 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3913 (org-test-with-temp-text
3914 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3915 (org-drag-element-backward)
3917 ;; Preserve blank lines.
3919 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3920 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3921 (org-drag-element-backward)
3925 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3926 (org-drag-element-backward)
3927 (looking-at-p "2")))
3928 ;; Error when trying to move first element of buffer.
3930 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3931 (org-drag-element-backward))
3933 ;; Error when trying to swap nested elements.
3935 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3936 (org-drag-element-backward))
3938 ;; Error when trying to swap an headline element and a non-headline
3941 (org-test-with-temp-text "Test.\n<point>* Head 1"
3942 (org-drag-element-backward))
3944 ;; Error when called before first element.
3946 (org-test-with-temp-text "\n<point>"
3947 (org-drag-element-backward))
3949 ;; Preserve visibility of elements and their contents.
3951 (equal '((63 .
82) (26 .
48))
3952 (org-test-with-temp-text "
3960 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3961 (search-backward "- item 1")
3962 (org-drag-element-backward)
3963 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3964 (overlays-in (point-min) (point-max))))))
3965 ;; Pathological case: handle call with point in blank lines right
3966 ;; after a headline.
3968 (equal "* H2\n* H1\nText\n\n"
3969 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3970 (org-drag-element-backward)
3973 (ert-deftest test-org
/drag-element-forward
()
3974 "Test `org-drag-element-forward' specifications."
3975 ;; 1. Error when trying to move first element of buffer.
3976 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3978 (should-error (org-drag-element-forward)))
3979 ;; 2. Error when trying to swap nested elements.
3980 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3982 (should-error (org-drag-element-forward)))
3983 ;; 3. Error when trying to swap a non-headline element and an
3985 (org-test-with-temp-text "Test.\n* Head 1"
3986 (should-error (org-drag-element-forward)))
3987 ;; 4. Error when called before first element.
3989 (org-test-with-temp-text "\n"
3991 (org-drag-element-backward))
3993 ;; 5. Otherwise, swap elements, preserving column and blank lines
3994 ;; between elements.
3995 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3996 (search-forward "graph")
3997 (org-drag-element-forward)
3998 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3999 (should (looking-at " 1")))
4000 ;; 5. Preserve visibility of elements and their contents.
4001 (org-test-with-temp-text "
4009 (while (search-forward "BEGIN_" nil t
) (org-cycle))
4010 (search-backward "#+BEGIN_CENTER")
4011 (org-drag-element-forward)
4014 '((63 .
82) (26 .
48))
4015 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
4016 (overlays-in (point-min) (point-max)))))))
4018 (ert-deftest test-org
/next-block
()
4019 "Test `org-next-block' specifications."
4022 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4024 (looking-at "#\\+BEGIN_CENTER")))
4027 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
4028 (let ((case-fold-search nil
))
4030 (looking-at "#\\+begin_center"))))
4031 ;; Ignore current line.
4033 (org-test-with-temp-text
4034 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
4036 (looking-at "#\\+BEGIN_CENTER")))
4037 ;; Throw an error when no block is found.
4039 (org-test-with-temp-text "Paragraph"
4040 (org-next-block 1)))
4041 ;; With an argument, skip many blocks at once.
4043 (org-test-with-temp-text
4044 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4046 (looking-at "#\\+BEGIN_QUOTE")))
4047 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4049 (org-test-with-temp-text
4050 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4051 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4052 (looking-at "#\\+BEGIN_QUOTE")))
4053 ;; Optional argument is also case-insensitive.
4055 (org-test-with-temp-text
4056 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4057 (let ((case-fold-search nil
))
4058 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4059 (looking-at "#\\+begin_quote")))))
4061 (ert-deftest test-org
/insert-template
()
4062 "Test `org-insert-structure-template'."
4063 ;; Test in empty buffer.
4065 (string= "#+begin_foo\n\n#+end_foo\n"
4066 (org-test-with-temp-text ""
4067 (org-insert-structure-template "foo")
4069 ;; Test with multiple lines in buffer.
4071 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\nI'm a second paragraph"
4072 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4074 (org-insert-structure-template "foo")
4076 ;; Mark only the current line.
4078 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
4079 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4080 (set-mark (point-min))
4083 (org-insert-structure-template "foo")
4085 ;; Middle of paragraph
4087 (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
4088 (org-test-with-temp-text "p1\n<point>p2\np3"
4089 (set-mark (line-beginning-position))
4092 (org-insert-structure-template "foo")
4094 ;; Test with text in buffer, no region, no final newline.
4096 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
4097 (org-test-with-temp-text "I'm a paragraph."
4099 (org-insert-structure-template "foo")
4101 ;; Test with text in buffer and region set.
4103 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
4104 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
4106 (goto-char (point-max))
4107 (org-insert-structure-template "foo")
4109 ;; Test with example escaping.
4111 (string= "#+begin_example\n,* Heading\n#+end_example\n"
4112 (org-test-with-temp-text "* Heading"
4114 (org-insert-structure-template "example")
4116 ;; Test with indentation.
4118 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
4119 (org-test-with-temp-text " This is a paragraph"
4121 (org-insert-structure-template "foo")
4123 ;; Test point location.
4125 (eq (length "#\\+begin_foo\n")
4126 (org-test-with-temp-text ""
4127 (org-insert-structure-template "foo")
4130 (eq (length "#\\+begin_src ")
4131 (org-test-with-temp-text ""
4132 (org-insert-structure-template "src")
4135 (ert-deftest test-org
/previous-block
()
4136 "Test `org-previous-block' specifications."
4139 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4140 (org-previous-block 1)
4141 (looking-at "#\\+BEGIN_CENTER")))
4144 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4145 (let ((case-fold-search nil
))
4146 (org-previous-block 1)
4147 (looking-at "#\\+begin_center"))))
4148 ;; Ignore current line.
4150 (org-test-with-temp-text
4151 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4152 (org-previous-block 1)
4153 (looking-at "#\\+BEGIN_QUOTE")))
4154 ;; Throw an error when no block is found.
4156 (org-test-with-temp-text "Paragraph<point>"
4157 (org-previous-block 1)))
4158 ;; With an argument, skip many blocks at once.
4160 (org-test-with-temp-text
4161 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4162 (org-previous-block 2)
4163 (looking-at "#\\+BEGIN_CENTER")))
4164 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4166 (org-test-with-temp-text
4167 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4168 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4169 (looking-at "#\\+BEGIN_QUOTE")))
4170 ;; Optional argument is also case-insensitive.
4172 (org-test-with-temp-text
4173 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4174 (let ((case-fold-search nil
))
4175 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4176 (looking-at "#\\+begin_quote")))))
4179 ;;; Outline structure
4181 (ert-deftest test-org
/demote
()
4182 "Test `org-demote' specifications."
4183 ;; Add correct number of stars according to `org-odd-levels-only'.
4186 (org-test-with-temp-text "* H"
4187 (let ((org-odd-levels-only nil
)) (org-demote))
4188 (org-current-level))))
4191 (org-test-with-temp-text "* H"
4192 (let ((org-odd-levels-only t
)) (org-demote))
4193 (org-current-level))))
4194 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4196 (org-test-with-temp-text "* H :tag:"
4197 (let ((org-tags-column 10)
4198 (org-auto-align-tags t
)
4199 (org-odd-levels-only nil
))
4201 (org-move-to-column 10)
4202 (looking-at-p ":tag:$")))
4204 (org-test-with-temp-text "* H :tag:"
4205 (let ((org-tags-column 10)
4206 (org-auto-align-tags nil
)
4207 (org-odd-levels-only nil
))
4209 (org-move-to-column 10)
4210 (looking-at-p ":tag:$")))
4211 ;; When `org-adapt-indentation' is non-nil, always indent planning
4212 ;; info and property drawers accordingly.
4215 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4216 (let ((org-odd-levels-only nil
)
4217 (org-adapt-indentation t
))
4220 (org-get-indentation))))
4223 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4224 (let ((org-odd-levels-only nil
)
4225 (org-adapt-indentation t
))
4228 (org-get-indentation))))
4231 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4232 (let ((org-odd-levels-only nil
)
4233 (org-adapt-indentation nil
))
4236 (org-get-indentation))))
4237 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4238 ;; section accordingly. Ignore, however, footnote definitions and
4239 ;; inlinetasks boundaries.
4242 (org-test-with-temp-text "* H\n Paragraph"
4243 (let ((org-odd-levels-only nil
)
4244 (org-adapt-indentation t
))
4247 (org-get-indentation))))
4250 (org-test-with-temp-text "* H\n Paragraph"
4251 (let ((org-odd-levels-only nil
)
4252 (org-adapt-indentation nil
))
4255 (org-get-indentation))))
4258 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4259 (let ((org-odd-levels-only nil
)
4260 (org-adapt-indentation t
))
4262 (goto-char (point-max))
4263 (org-get-indentation))))
4266 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4267 (let ((org-odd-levels-only nil
)
4268 (org-adapt-indentation t
))
4270 (goto-char (point-max))
4271 (org-get-indentation))))
4272 (when (featurep 'org-inlinetask
)
4275 (let ((org-inlinetask-min-level 5)
4276 (org-adapt-indentation t
))
4277 (org-test-with-temp-text "* H\n***** I\n***** END"
4280 (org-get-indentation))))))
4281 (when (featurep 'org-inlinetask
)
4284 (let ((org-inlinetask-min-level 5)
4285 (org-adapt-indentation t
))
4286 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4289 (org-get-indentation))))))
4290 ;; Ignore contents of source blocks or example blocks when
4291 ;; indentation should be preserved (through
4292 ;; `org-src-preserve-indentation' or "-i" flag).
4295 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4296 (let ((org-adapt-indentation t
)
4297 (org-src-preserve-indentation nil
))
4300 (org-get-indentation))))
4303 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4304 (let ((org-adapt-indentation t
)
4305 (org-src-preserve-indentation t
))
4308 (org-get-indentation))))
4311 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4312 (let ((org-adapt-indentation t
)
4313 (org-src-preserve-indentation t
))
4316 (org-get-indentation))))
4319 (org-test-with-temp-text
4320 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4321 (let ((org-adapt-indentation t
)
4322 (org-src-preserve-indentation nil
))
4325 (org-get-indentation)))))
4327 (ert-deftest test-org
/promote
()
4328 "Test `org-promote' specifications."
4329 ;; Return an error if headline is to be promoted to level 0, unless
4330 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4331 ;; headline becomes a comment.
4333 (org-test-with-temp-text "* H"
4334 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4337 (org-test-with-temp-text "* H"
4338 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4340 ;; Remove correct number of stars according to
4341 ;; `org-odd-levels-only'.
4344 (org-test-with-temp-text "*** H"
4345 (let ((org-odd-levels-only nil
)) (org-promote))
4346 (org-current-level))))
4349 (org-test-with-temp-text "*** H"
4350 (let ((org-odd-levels-only t
)) (org-promote))
4351 (org-current-level))))
4352 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4354 (org-test-with-temp-text "** H :tag:"
4355 (let ((org-tags-column 10)
4356 (org-auto-align-tags t
)
4357 (org-odd-levels-only nil
))
4359 (org-move-to-column 10)
4360 (looking-at-p ":tag:$")))
4362 (org-test-with-temp-text "** H :tag:"
4363 (let ((org-tags-column 10)
4364 (org-auto-align-tags nil
)
4365 (org-odd-levels-only nil
))
4367 (org-move-to-column 10)
4368 (looking-at-p ":tag:$")))
4369 ;; When `org-adapt-indentation' is non-nil, always indent planning
4370 ;; info and property drawers.
4373 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4374 (let ((org-odd-levels-only nil
)
4375 (org-adapt-indentation t
))
4378 (org-get-indentation))))
4381 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4382 (let ((org-odd-levels-only nil
)
4383 (org-adapt-indentation t
))
4386 (org-get-indentation))))
4389 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4390 (let ((org-odd-levels-only nil
)
4391 (org-adapt-indentation nil
))
4394 (org-get-indentation))))
4395 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4396 ;; section accordingly. Ignore, however, footnote definitions and
4397 ;; inlinetasks boundaries.
4400 (org-test-with-temp-text "** H\n Paragraph"
4401 (let ((org-odd-levels-only nil
)
4402 (org-adapt-indentation t
))
4405 (org-get-indentation))))
4408 (org-test-with-temp-text "** H\n Paragraph"
4409 (let ((org-odd-levels-only nil
)
4410 (org-adapt-indentation nil
))
4413 (org-get-indentation))))
4416 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4417 (let ((org-odd-levels-only nil
)
4418 (org-adapt-indentation t
))
4421 (org-get-indentation))))
4422 (when (featurep 'org-inlinetask
)
4425 (let ((org-inlinetask-min-level 5)
4426 (org-adapt-indentation t
))
4427 (org-test-with-temp-text "** H\n***** I\n***** END"
4430 (org-get-indentation))))))
4431 (when (featurep 'org-inlinetask
)
4434 (let ((org-inlinetask-min-level 5)
4435 (org-adapt-indentation t
))
4436 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4439 (org-get-indentation))))))
4440 ;; Give up shifting if it would break document's structure
4444 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4445 (let ((org-odd-levels-only nil
)
4446 (org-adapt-indentation t
))
4449 (org-get-indentation))))
4452 (org-test-with-temp-text "** H\n Paragraph\n * list."
4453 (let ((org-odd-levels-only nil
)
4454 (org-adapt-indentation t
))
4457 (org-get-indentation))))
4458 ;; Ignore contents of source blocks or example blocks when
4459 ;; indentation should be preserved (through
4460 ;; `org-src-preserve-indentation' or "-i" flag).
4463 (org-test-with-temp-text
4464 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4465 (let ((org-adapt-indentation t
)
4466 (org-src-preserve-indentation nil
)
4467 (org-odd-levels-only nil
))
4470 (org-get-indentation))))
4473 (org-test-with-temp-text
4474 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4475 (let ((org-adapt-indentation t
)
4476 (org-src-preserve-indentation t
)
4477 (org-odd-levels-only nil
))
4480 (org-get-indentation))))
4483 (org-test-with-temp-text
4484 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4485 (let ((org-adapt-indentation t
)
4486 (org-src-preserve-indentation t
)
4487 (org-odd-levels-only nil
))
4490 (org-get-indentation))))
4493 (org-test-with-temp-text
4494 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4495 (let ((org-adapt-indentation t
)
4496 (org-src-preserve-indentation nil
)
4497 (org-odd-levels-only nil
))
4500 (org-get-indentation)))))
4502 (ert-deftest test-org
/org-get-valid-level
()
4503 "Test function `org-get-valid-level' specifications."
4504 (let ((org-odd-levels-only nil
))
4505 (should (equal 1 (org-get-valid-level 0 0)))
4506 (should (equal 1 (org-get-valid-level 0 1)))
4507 (should (equal 2 (org-get-valid-level 0 2)))
4508 (should (equal 3 (org-get-valid-level 0 3)))
4509 (should (equal 1 (org-get-valid-level 1 0)))
4510 (should (equal 2 (org-get-valid-level 1 1)))
4511 (should (equal 23 (org-get-valid-level 1 22)))
4512 (should (equal 1 (org-get-valid-level 1 -
1)))
4513 (should (equal 1 (org-get-valid-level 2 -
1))))
4514 (let ((org-odd-levels-only t
))
4515 (should (equal 1 (org-get-valid-level 0 0)))
4516 (should (equal 1 (org-get-valid-level 0 1)))
4517 (should (equal 3 (org-get-valid-level 0 2)))
4518 (should (equal 5 (org-get-valid-level 0 3)))
4519 (should (equal 1 (org-get-valid-level 1 0)))
4520 (should (equal 3 (org-get-valid-level 1 1)))
4521 (should (equal 3 (org-get-valid-level 2 1)))
4522 (should (equal 5 (org-get-valid-level 3 1)))
4523 (should (equal 5 (org-get-valid-level 4 1)))
4524 (should (equal 43 (org-get-valid-level 1 21)))
4525 (should (equal 1 (org-get-valid-level 1 -
1)))
4526 (should (equal 1 (org-get-valid-level 2 -
1)))
4527 (should (equal 1 (org-get-valid-level 3 -
1)))
4528 (should (equal 3 (org-get-valid-level 4 -
1)))
4529 (should (equal 3 (org-get-valid-level 5 -
1)))))
4534 (ert-deftest test-org
/at-planning-p
()
4535 "Test `org-at-planning-p' specifications."
4538 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4539 (org-at-planning-p)))
4541 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4542 (org-at-planning-p)))
4543 ;; Correctly find planning attached to inlinetasks.
4544 (when (featurep 'org-inlinetask
)
4546 (org-test-with-temp-text
4547 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4548 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4550 (org-test-with-temp-text
4551 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4552 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4554 (org-test-with-temp-text
4555 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4556 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4558 (org-test-with-temp-text
4559 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4560 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4562 (ert-deftest test-org
/add-planning-info
()
4563 "Test `org-add-planning-info'."
4564 ;; Create deadline when `org-adapt-indentation' is non-nil.
4566 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4567 (org-test-with-temp-text "* H\nParagraph<point>"
4568 (let ((org-adapt-indentation t
))
4569 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4570 (replace-regexp-in-string
4571 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4573 ;; Create deadline when `org-adapt-indentation' is nil.
4575 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4576 (org-test-with-temp-text "* H\nParagraph<point>"
4577 (let ((org-adapt-indentation nil
))
4578 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4579 (replace-regexp-in-string
4580 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4582 ;; Update deadline when `org-adapt-indentation' is non-nil.
4584 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4585 (org-test-with-temp-text "\
4587 DEADLINE: <2015-06-24 Wed>
4589 (let ((org-adapt-indentation t
))
4590 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4591 (replace-regexp-in-string
4592 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4594 ;; Update deadline when `org-adapt-indentation' is nil.
4596 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4597 (org-test-with-temp-text "\
4599 DEADLINE: <2015-06-24 Wed>
4601 (let ((org-adapt-indentation nil
))
4602 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4603 (replace-regexp-in-string
4604 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4606 ;; Schedule when `org-adapt-indentation' is non-nil.
4608 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4609 (org-test-with-temp-text "* H\nParagraph<point>"
4610 (let ((org-adapt-indentation t
))
4611 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4612 (replace-regexp-in-string
4613 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4615 ;; Schedule when `org-adapt-indentation' is nil.
4617 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4618 (org-test-with-temp-text "* H\nParagraph<point>"
4619 (let ((org-adapt-indentation nil
))
4620 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4621 (replace-regexp-in-string
4622 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4624 ;; Add deadline when scheduled.
4628 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4630 (org-test-with-temp-text "\
4632 SCHEDULED: <2015-06-24 Wed>
4634 (let ((org-adapt-indentation t
))
4635 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4636 (replace-regexp-in-string
4637 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4639 ;; Remove middle entry.
4643 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4645 (org-test-with-temp-text "\
4647 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4649 (let ((org-adapt-indentation t
))
4650 (org-add-planning-info nil nil
'deadline
))
4651 (replace-regexp-in-string
4652 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4654 ;; Remove last entry and then middle entry (order should not
4659 CLOSED: [2015-06-24]
4661 (org-test-with-temp-text "\
4663 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4665 (let ((org-adapt-indentation t
))
4666 (org-add-planning-info nil nil
'scheduled
'deadline
))
4667 (replace-regexp-in-string
4668 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4670 ;; Remove closed when `org-adapt-indentation' is non-nil.
4672 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4673 (org-test-with-temp-text "\
4675 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4677 (let ((org-adapt-indentation t
))
4678 (org-add-planning-info nil nil
'closed
))
4679 (replace-regexp-in-string
4680 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4683 (equal "* H\n Paragraph"
4684 (org-test-with-temp-text "\
4686 CLOSED: [2015-06-25 Thu]
4688 (let ((org-adapt-indentation t
))
4689 (org-add-planning-info nil nil
'closed
))
4690 (replace-regexp-in-string
4691 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4693 ;; Remove closed when `org-adapt-indentation' is nil.
4695 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4696 (org-test-with-temp-text "\
4698 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4700 (let ((org-adapt-indentation nil
))
4701 (org-add-planning-info nil nil
'closed
))
4702 (replace-regexp-in-string
4703 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4706 (equal "* H\nParagraph"
4707 (org-test-with-temp-text "\
4709 CLOSED: [2015-06-25 Thu]
4711 (let ((org-adapt-indentation nil
))
4712 (org-add-planning-info nil nil
'closed
))
4713 (replace-regexp-in-string
4714 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4716 ;; Remove closed entry and delete empty line.
4721 (org-test-with-temp-text "\
4723 CLOSED: [2015-06-24 Wed]
4725 (let ((org-adapt-indentation t
))
4726 (org-add-planning-info nil nil
'closed
))
4727 (replace-regexp-in-string
4728 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4730 ;; Remove one entry and update another.
4732 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4733 (org-test-with-temp-text "\
4735 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4737 (let ((org-adapt-indentation t
))
4738 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4739 (replace-regexp-in-string
4740 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4743 (ert-deftest test-org
/deadline
()
4744 "Test `org-deadline' specifications."
4745 ;; Insert a new value or replace existing one.
4747 (equal "* H\nDEADLINE: <2012-03-29>\n"
4748 (org-test-with-temp-text "* H"
4749 (let ((org-adapt-indentation nil
)
4750 (org-last-inserted-timestamp nil
))
4751 (org-deadline nil
"<2012-03-29 Tue>"))
4752 (replace-regexp-in-string
4753 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4756 (equal "* H\nDEADLINE: <2014-03-04>"
4757 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4758 (let ((org-adapt-indentation nil
)
4759 (org-last-inserted-timestamp nil
))
4760 (org-deadline nil
"<2014-03-04 Thu>"))
4761 (replace-regexp-in-string
4762 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4764 ;; Accept delta time, e.g., "+2d".
4766 (equal "* H\nDEADLINE: <2015-03-04>\n"
4767 (cl-letf (((symbol-function 'current-time
)
4768 (lambda (&rest args
)
4769 (apply #'encode-time
4770 (org-parse-time-string "2014-03-04")))))
4771 (org-test-with-temp-text "* H"
4772 (let ((org-adapt-indentation nil
)
4773 (org-last-inserted-timestamp nil
))
4774 (org-deadline nil
"+1y"))
4775 (replace-regexp-in-string
4776 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4777 ;; Preserve repeater.
4779 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4780 (org-test-with-temp-text "* H"
4781 (let ((org-adapt-indentation nil
)
4782 (org-last-inserted-timestamp nil
))
4783 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4784 (replace-regexp-in-string
4785 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4786 ;; Remove CLOSED keyword, if any.
4788 (equal "* H\nDEADLINE: <2012-03-29>"
4789 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4790 (let ((org-adapt-indentation nil
)
4791 (org-last-inserted-timestamp nil
))
4792 (org-deadline nil
"<2012-03-29 Tue>"))
4793 (replace-regexp-in-string
4794 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4795 ;; With C-u argument, remove DEADLINE keyword.
4798 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4799 (let ((org-adapt-indentation nil
)
4800 (org-last-inserted-timestamp nil
))
4801 (org-deadline '(4)))
4805 (org-test-with-temp-text "* H"
4806 (let ((org-adapt-indentation nil
)
4807 (org-last-inserted-timestamp nil
))
4808 (org-deadline '(4)))
4810 ;; With C-u C-u argument, prompt for a delay cookie.
4812 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4813 (cl-letf (((symbol-function 'org-read-date
)
4814 (lambda (&rest args
)
4815 (apply #'encode-time
4816 (org-parse-time-string "2014-03-04")))))
4817 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4818 (let ((org-adapt-indentation nil
)
4819 (org-last-inserted-timestamp nil
))
4820 (org-deadline '(16)))
4823 (cl-letf (((symbol-function 'org-read-date
)
4824 (lambda (&rest args
)
4825 (apply #'encode-time
4826 (org-parse-time-string "2014-03-04")))))
4827 (org-test-with-temp-text "* H"
4828 (let ((org-adapt-indentation nil
)
4829 (org-last-inserted-timestamp nil
))
4830 (org-deadline '(16)))
4832 ;; When a region is active and
4833 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4834 ;; same value in all headlines in region.
4836 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4837 (org-test-with-temp-text "* H1\n* H2"
4838 (let ((org-adapt-indentation nil
)
4839 (org-last-inserted-timestamp nil
)
4840 (org-loop-over-headlines-in-active-region t
))
4841 (transient-mark-mode 1)
4842 (push-mark (point) t t
)
4843 (goto-char (point-max))
4844 (org-deadline nil
"2012-03-29"))
4845 (replace-regexp-in-string
4846 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4848 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4849 (org-test-with-temp-text "* H1\n* H2"
4850 (let ((org-adapt-indentation nil
)
4851 (org-last-inserted-timestamp nil
)
4852 (org-loop-over-headlines-in-active-region nil
))
4853 (transient-mark-mode 1)
4854 (push-mark (point) t t
)
4855 (goto-char (point-max))
4856 (org-deadline nil
"2012-03-29"))
4857 (replace-regexp-in-string
4858 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4860 (ert-deftest test-org
/schedule
()
4861 "Test `org-schedule' specifications."
4862 ;; Insert a new value or replace existing one.
4864 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4865 (org-test-with-temp-text "* H"
4866 (let ((org-adapt-indentation nil
)
4867 (org-last-inserted-timestamp nil
))
4868 (org-schedule nil
"<2012-03-29 Tue>"))
4869 (replace-regexp-in-string
4870 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4873 (equal "* H\nSCHEDULED: <2014-03-04>"
4874 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4875 (let ((org-adapt-indentation nil
)
4876 (org-last-inserted-timestamp nil
))
4877 (org-schedule nil
"<2014-03-04 Thu>"))
4878 (replace-regexp-in-string
4879 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4881 ;; Accept delta time, e.g., "+2d".
4883 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4884 (cl-letf (((symbol-function 'current-time
)
4885 (lambda (&rest args
)
4886 (apply #'encode-time
4887 (org-parse-time-string "2014-03-04")))))
4888 (org-test-with-temp-text "* H"
4889 (let ((org-adapt-indentation nil
)
4890 (org-last-inserted-timestamp nil
))
4891 (org-schedule nil
"+1y"))
4892 (replace-regexp-in-string
4893 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4894 ;; Preserve repeater.
4896 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4897 (org-test-with-temp-text "* H"
4898 (let ((org-adapt-indentation nil
)
4899 (org-last-inserted-timestamp nil
))
4900 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4901 (replace-regexp-in-string
4902 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4903 ;; Remove CLOSED keyword, if any.
4905 (equal "* H\nSCHEDULED: <2012-03-29>"
4906 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4907 (let ((org-adapt-indentation nil
)
4908 (org-last-inserted-timestamp nil
))
4909 (org-schedule nil
"<2012-03-29 Tue>"))
4910 (replace-regexp-in-string
4911 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4912 ;; With C-u argument, remove SCHEDULED keyword.
4915 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4916 (let ((org-adapt-indentation nil
)
4917 (org-last-inserted-timestamp nil
))
4918 (org-schedule '(4)))
4922 (org-test-with-temp-text "* H"
4923 (let ((org-adapt-indentation nil
)
4924 (org-last-inserted-timestamp nil
))
4925 (org-schedule '(4)))
4927 ;; With C-u C-u argument, prompt for a delay cookie.
4929 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4930 (cl-letf (((symbol-function 'org-read-date
)
4931 (lambda (&rest args
)
4932 (apply #'encode-time
4933 (org-parse-time-string "2014-03-04")))))
4934 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4935 (let ((org-adapt-indentation nil
)
4936 (org-last-inserted-timestamp nil
))
4937 (org-schedule '(16)))
4940 (cl-letf (((symbol-function 'org-read-date
)
4941 (lambda (&rest args
)
4942 (apply #'encode-time
4943 (org-parse-time-string "2014-03-04")))))
4944 (org-test-with-temp-text "* H"
4945 (let ((org-adapt-indentation nil
)
4946 (org-last-inserted-timestamp nil
))
4947 (org-schedule '(16)))
4949 ;; When a region is active and
4950 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4951 ;; same value in all headlines in region.
4953 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4954 (org-test-with-temp-text "* H1\n* H2"
4955 (let ((org-adapt-indentation nil
)
4956 (org-last-inserted-timestamp nil
)
4957 (org-loop-over-headlines-in-active-region t
))
4958 (transient-mark-mode 1)
4959 (push-mark (point) t t
)
4960 (goto-char (point-max))
4961 (org-schedule nil
"2012-03-29"))
4962 (replace-regexp-in-string
4963 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4965 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4966 (org-test-with-temp-text "* H1\n* H2"
4967 (let ((org-adapt-indentation nil
)
4968 (org-last-inserted-timestamp nil
)
4969 (org-loop-over-headlines-in-active-region nil
))
4970 (transient-mark-mode 1)
4971 (push-mark (point) t t
)
4972 (goto-char (point-max))
4973 (org-schedule nil
"2012-03-29"))
4974 (replace-regexp-in-string
4975 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4977 ;; check if a repeater survives re-scheduling.
4979 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4980 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4981 (let ((org-adapt-indentation nil
)
4982 (org-last-inserted-timestamp nil
))
4983 (org-schedule nil
"2017-02-01"))
4989 (ert-deftest test-org
/buffer-property-keys
()
4990 "Test `org-buffer-property-keys' specifications."
4991 ;; Retrieve properties accross siblings.
4994 (org-test-with-temp-text "
5003 (org-buffer-property-keys))))
5004 ;; Retrieve properties accross children.
5007 (org-test-with-temp-text "
5016 (org-buffer-property-keys))))
5017 ;; Retrieve muliple properties in the same drawer.
5020 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5021 (org-buffer-property-keys))))
5022 ;; Ignore extension symbol in property name.
5025 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
5026 (org-buffer-property-keys))))
5027 ;; With non-nil COLUMNS, extract property names from columns.
5030 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
5031 (org-buffer-property-keys nil nil t
))))
5033 (equal '("A" "B" "COLUMNS")
5034 (org-test-with-temp-text
5035 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
5036 (org-buffer-property-keys nil nil t
))))
5037 ;; In COLUMNS, ignore title and summary-type.
5040 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
5041 (org-buffer-property-keys nil nil t
))))
5044 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
5045 (org-buffer-property-keys nil nil t
))))
5048 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
5049 (org-buffer-property-keys nil nil t
)))))
5051 (ert-deftest test-org
/property-values
()
5052 "Test `org-property-values' specifications."
5056 (org-test-with-temp-text
5057 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
5058 (org-property-values "A"))))
5059 ;; Ignore empty values.
5061 (org-test-with-temp-text
5062 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
5063 (org-property-values "A")))
5064 ;; Take into consideration extended values.
5067 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
5068 (org-property-values "A")))))
5070 (ert-deftest test-org
/find-property
()
5071 "Test `org-find-property' specifications."
5075 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
5076 (org-find-property "prop"))))
5077 ;; Ignore false positives.
5080 (org-test-with-temp-text
5081 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
5082 (org-find-property "A"))))
5083 ;; Return first entry found in buffer.
5086 (org-test-with-temp-text
5087 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5088 (org-find-property "A"))))
5089 ;; Only search visible part of the buffer.
5092 (org-test-with-temp-text
5093 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5094 (org-narrow-to-subtree)
5095 (org-find-property "A"))))
5096 ;; With optional argument, only find entries with a specific value.
5098 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5099 (org-find-property "A" "2")))
5102 (org-test-with-temp-text
5103 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5104 (org-find-property "A" "2"))))
5105 ;; Use "nil" for explicit nil values.
5108 (org-test-with-temp-text
5109 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5110 (org-find-property "A" "nil")))))
5112 (ert-deftest test-org
/entry-delete
()
5113 "Test `org-entry-delete' specifications."
5117 " *:PROPERTIES:\n *:B: +2\n *:END:"
5118 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5119 (org-entry-delete (point) "A")
5121 ;; Also remove accumulated properties.
5125 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5126 (org-entry-delete (point) "A")
5128 ;; When last property is removed, remove the property drawer.
5132 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5133 (org-entry-delete (point) "A")
5135 ;; Return a non-nil value when some property was removed.
5137 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5138 (org-entry-delete (point) "A")))
5140 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5141 (org-entry-delete (point) "C")))
5142 ;; Special properties cannot be located in a drawer. Allow to
5143 ;; remove them anyway, in case of user error.
5145 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5146 (org-entry-delete (point) "SCHEDULED"))))
5148 (ert-deftest test-org
/entry-get
()
5149 "Test `org-entry-get' specifications."
5153 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5154 (org-entry-get (point) "A"))))
5158 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5159 (org-entry-get (point) "a"))))
5160 ;; Handle extended values, both before and after base value.
5163 (org-test-with-temp-text
5164 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5165 (org-entry-get (point) "A"))))
5166 ;; Empty values are returned as the empty string.
5169 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5170 (org-entry-get (point) "A"))))
5171 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5172 ;; otherwise, return nil.
5174 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5175 (org-entry-get (point) "A")))
5178 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5179 (org-entry-get (point) "A" nil t
))))
5180 ;; Return nil when no property is found, independently on the
5181 ;; LITERAL-NIL argument.
5183 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5184 (org-entry-get (point) "B")))
5186 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5187 (org-entry-get (point) "B" nil t
)))
5188 ;; Handle inheritance, when allowed. Include extended values and
5189 ;; possibly global values.
5193 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5194 (org-entry-get (point) "A" t
))))
5198 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5199 (let ((org-use-property-inheritance t
))
5200 (org-entry-get (point) "A" 'selective
)))))
5202 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5203 (let ((org-use-property-inheritance nil
))
5204 (org-entry-get (point) "A" 'selective
))))
5208 (org-test-with-temp-text
5209 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5210 (org-entry-get (point-max) "A" t
))))
5213 (org-test-with-temp-text
5214 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5216 (org-entry-get (point-max) "A" t
))))
5219 (org-test-with-temp-text
5220 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5222 (org-entry-get (point-max) "A" t
)))))
5224 (ert-deftest test-org
/entry-properties
()
5225 "Test `org-entry-properties' specifications."
5226 ;; Get "ITEM" property.
5229 (org-test-with-temp-text "* TODO H"
5230 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5233 (org-test-with-temp-text "* TODO H"
5234 (cdr (assoc "ITEM" (org-entry-properties))))))
5235 ;; Get "TODO" property. TODO keywords are case sensitive.
5238 (org-test-with-temp-text "* TODO H"
5239 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5242 (org-test-with-temp-text "* TODO H"
5243 (cdr (assoc "TODO" (org-entry-properties))))))
5245 (org-test-with-temp-text "* H"
5246 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5248 (org-test-with-temp-text "* todo H"
5249 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5250 ;; Get "PRIORITY" property.
5253 (org-test-with-temp-text "* [#A] H"
5254 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5257 (org-test-with-temp-text "* [#A] H"
5258 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5260 (equal (char-to-string org-default-priority
)
5261 (org-test-with-temp-text "* H"
5262 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5263 ;; Get "FILE" property.
5265 (org-test-with-temp-text-in-file "* H\nParagraph"
5266 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5267 (buffer-file-name))))
5269 (org-test-with-temp-text-in-file "* H\nParagraph"
5270 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5271 (buffer-file-name))))
5273 (org-test-with-temp-text "* H\nParagraph"
5274 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5275 ;; Get "TAGS" property.
5277 (equal ":tag1:tag2:"
5278 (org-test-with-temp-text "* H :tag1:tag2:"
5279 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5281 (equal ":tag1:tag2:"
5282 (org-test-with-temp-text "* H :tag1:tag2:"
5283 (cdr (assoc "TAGS" (org-entry-properties))))))
5285 (org-test-with-temp-text "* H"
5286 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5287 ;; Get "ALLTAGS" property.
5289 (equal ":tag1:tag2:"
5290 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5291 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5293 (equal ":tag1:tag2:"
5294 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5295 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5297 (org-test-with-temp-text "* H"
5298 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5299 ;; Get "BLOCKED" property.
5302 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5303 (let ((org-enforce-todo-dependencies t
)
5305 '(org-block-todo-from-children-or-siblings-or-parent)))
5306 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5309 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5310 (let ((org-enforce-todo-dependencies t
)
5312 '(org-block-todo-from-children-or-siblings-or-parent)))
5313 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5314 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5318 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5319 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5323 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5324 (cdr (assoc "CLOSED" (org-entry-properties))))))
5326 (org-test-with-temp-text "* H"
5327 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5331 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5332 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5336 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5337 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5339 (org-test-with-temp-text "* H"
5340 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5344 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5345 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5349 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5350 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5352 (org-test-with-temp-text "* H"
5353 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5357 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5358 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5361 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5362 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5365 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5366 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5369 (org-test-with-temp-text
5370 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5372 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5373 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5374 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5376 (equal "<2012-03-29 thu.>"
5377 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5378 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5380 (equal "[2012-03-29 thu.]"
5381 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5382 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5384 (equal "<2012-03-29 thu.>"
5385 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5386 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5388 (equal "[2014-03-04 tue.]"
5389 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5390 (cdr (assoc "TIMESTAMP_IA"
5391 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5393 (equal "<2012-03-29 thu.>"
5394 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5395 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5396 ;; Get standard properties.
5399 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5400 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5401 ;; Handle extended properties.
5404 (org-test-with-temp-text
5405 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5406 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5409 (org-test-with-temp-text
5410 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5411 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5412 ;; Ignore forbidden (special) properties.
5414 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5415 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5417 (ert-deftest test-org
/entry-put
()
5418 "Test `org-entry-put' specifications."
5419 ;; Error when not a string or nil.
5421 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5422 (org-entry-put 1 "test" 2)))
5423 ;; Error when property name is invalid.
5425 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5426 (org-entry-put 1 "no space" "value")))
5428 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5429 (org-entry-put 1 "" "value")))
5430 ;; Set "TODO" property.
5432 (string-match (regexp-quote " TODO H")
5433 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5434 (org-entry-put (point) "TODO" "TODO")
5437 (string-match (regexp-quote "* H")
5438 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5439 (org-entry-put (point) "TODO" nil
)
5441 ;; Set "PRIORITY" property.
5444 (org-test-with-temp-text "* [#B] H"
5445 (org-entry-put (point) "PRIORITY" "A")
5449 (org-test-with-temp-text "* [#B] H"
5450 (org-entry-put (point) "PRIORITY" nil
)
5452 ;; Set "SCHEDULED" property.
5454 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5455 (org-test-with-temp-text "* H"
5456 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5460 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5461 (org-entry-put (point) "SCHEDULED" nil
)
5464 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5465 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5466 (org-entry-put (point) "SCHEDULED" "earlier")
5469 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5470 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5471 (org-entry-put (point) "SCHEDULED" "later")
5473 ;; Set "DEADLINE" property.
5475 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5476 (org-test-with-temp-text "* H"
5477 (org-entry-put (point) "DEADLINE" "2014-03-04")
5481 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5482 (org-entry-put (point) "DEADLINE" nil
)
5485 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5486 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5487 (org-entry-put (point) "DEADLINE" "earlier")
5490 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5491 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5492 (org-entry-put (point) "DEADLINE" "later")
5494 ;; Set "CATEGORY" property
5496 (string-match "^ *:CATEGORY: cat"
5497 (org-test-with-temp-text "* H"
5498 (org-entry-put (point) "CATEGORY" "cat")
5500 ;; Regular properties, with or without pre-existing drawer.
5502 (string-match "^ *:A: +2$"
5503 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5504 (org-entry-put (point) "A" "2")
5507 (string-match "^ *:A: +1$"
5508 (org-test-with-temp-text "* H"
5509 (org-entry-put (point) "A" "1")
5511 ;; Special case: two consecutive headlines.
5513 (string-match "\\* A\n *:PROPERTIES:"
5514 (org-test-with-temp-text "* A\n** B"
5515 (org-entry-put (point) "A" "1")
5518 (ert-deftest test-org
/refresh-properties
()
5519 "Test `org-refresh-properties' specifications."
5522 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5523 (org-refresh-properties "A" 'org-test
)
5524 (get-text-property (point) 'org-test
))))
5526 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5527 (org-refresh-properties "B" 'org-test
)
5528 (get-text-property (point) 'org-test
)))
5529 ;; Handle properties only defined with extension syntax, i.e.,
5533 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5534 (org-refresh-properties "A" 'org-test
)
5535 (get-text-property (point) 'org-test
))))
5536 ;; When property is inherited, add text property to the whole
5540 (org-test-with-temp-text
5541 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5542 (let ((org-use-property-inheritance t
))
5543 (org-refresh-properties "A" 'org-test
))
5544 (get-text-property (point) 'org-test
))))
5545 ;; When property is inherited, use global value across the whole
5546 ;; buffer. However local values have precedence.
5549 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5551 (let ((org-use-property-inheritance nil
))
5552 (org-refresh-properties "A" 'org-test
))
5553 (get-text-property (point) 'org-test
))))
5556 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5558 (let ((org-use-property-inheritance t
))
5559 (org-refresh-properties "A" 'org-test
))
5560 (get-text-property (point) 'org-test
))))
5563 (org-test-with-temp-text
5564 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5566 (let ((org-use-property-inheritance t
))
5567 (org-refresh-properties "A" 'org-test
))
5568 (get-text-property (point) 'org-test
)))))
5573 (ert-deftest test-org
/update-radio-target-regexp
()
5574 "Test `org-update-radio-target-regexp' specifications."
5575 ;; Properly update cache with no previous radio target regexp.
5578 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5579 (save-excursion (goto-char (point-max)) (org-element-context))
5581 (search-forward "o")
5583 (org-update-radio-target-regexp)
5584 (goto-char (point-max))
5585 (org-element-type (org-element-context)))))
5586 ;; Properly update cache with previous radio target regexp.
5589 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5590 (save-excursion (goto-char (point-max)) (org-element-context))
5592 (search-forward "o")
5594 (org-update-radio-target-regexp)
5595 (search-backward "r")
5598 (org-update-radio-target-regexp)
5599 (goto-char (point-max))
5600 (delete-region (line-beginning-position) (point))
5602 (org-element-type (org-element-context))))))
5607 (ert-deftest test-org
/refile-get-targets
()
5608 "Test `org-refile-get-targets' specifications."
5609 ;; :maxlevel includes all headings above specified value.
5611 (equal '("H1" "H2" "H3")
5612 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5613 (let ((org-refile-use-outline-path nil
)
5614 (org-refile-targets `((nil :maxlevel .
3))))
5615 (mapcar #'car
(org-refile-get-targets))))))
5618 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5619 (let ((org-refile-use-outline-path nil
)
5620 (org-refile-targets `((nil :maxlevel .
2))))
5621 (mapcar #'car
(org-refile-get-targets))))))
5622 ;; :level limits targets to headlines with the specified level.
5625 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5626 (let ((org-refile-use-outline-path nil
)
5627 (org-refile-targets `((nil :level .
2))))
5628 (mapcar #'car
(org-refile-get-targets))))))
5629 ;; :tag limits targets to headlines with specified tag.
5632 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5633 (let ((org-refile-use-outline-path nil
)
5634 (org-refile-targets `((nil :tag .
"foo"))))
5635 (mapcar #'car
(org-refile-get-targets))))))
5636 ;; :todo limits targets to headlines with specified TODO keyword.
5639 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5640 (let ((org-refile-use-outline-path nil
)
5641 (org-refile-targets `((nil :todo .
"TODO"))))
5642 (mapcar #'car
(org-refile-get-targets))))))
5643 ;; :regexp filters targets matching provided regexp.
5646 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5647 (let ((org-refile-use-outline-path nil
)
5648 (org-refile-targets `((nil :regexp .
"F"))))
5649 (mapcar #'car
(org-refile-get-targets))))))
5650 ;; A nil `org-refile-targets' includes only top level headlines in
5654 (org-test-with-temp-text "* H1\n** S1\n* H2"
5655 (let ((org-refile-use-outline-path nil
)
5656 (org-refile-targets nil
))
5657 (mapcar #'car
(org-refile-get-targets))))))
5658 ;; Return value is the union of the targets according to all the
5659 ;; defined rules. However, prevent duplicates.
5661 (equal '("F2" "F3" "H1")
5662 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5663 (let ((org-refile-use-outline-path nil
)
5664 (org-refile-targets `((nil :regexp .
"F")
5665 (nil :todo .
"TODO"))))
5666 (mapcar #'car
(org-refile-get-targets))))))
5668 (equal '("F2" "F3" "H1")
5669 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5670 (let ((org-refile-use-outline-path nil
)
5671 (org-refile-targets `((nil :regexp .
"F")
5672 (nil :todo .
"TODO"))))
5673 (mapcar #'car
(org-refile-get-targets))))))
5674 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5677 (equal '("H1" "H1/H2" "H1/H2/H3")
5678 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5679 (let ((org-refile-use-outline-path t
)
5680 (org-refile-targets `((nil :maxlevel .
3))))
5681 (mapcar #'car
(org-refile-get-targets))))))
5682 ;; When providing targets as paths, escape forward slashes in
5683 ;; headings with backslashes.
5685 (equal '("H1\\/foo")
5686 (org-test-with-temp-text "* H1/foo"
5687 (let ((org-refile-use-outline-path t
)
5688 (org-refile-targets `((nil :maxlevel .
1))))
5689 (mapcar #'car
(org-refile-get-targets))))))
5690 ;; When `org-refile-use-outline-path' is `file', include file name
5691 ;; without directory in targets.
5693 (org-test-with-temp-text-in-file "* H1"
5694 (let* ((filename (buffer-file-name))
5695 (org-refile-use-outline-path 'file
)
5696 (org-refile-targets `(((,filename
) :level .
1))))
5697 (member (file-name-nondirectory filename
)
5698 (mapcar #'car
(org-refile-get-targets))))))
5699 ;; When `org-refile-use-outline-path' is `full-file-path', include
5702 (org-test-with-temp-text-in-file "* H1"
5703 (let* ((filename (file-truename (buffer-file-name)))
5704 (org-refile-use-outline-path 'full-file-path
)
5705 (org-refile-targets `(((,filename
) :level .
1))))
5706 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5707 ;; When `org-refile-use-outline-path' is `buffer-name', include
5710 (org-test-with-temp-text "* H1"
5711 (let* ((org-refile-use-outline-path 'buffer-name
)
5712 (org-refile-targets `((nil :level .
1))))
5713 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5719 (ert-deftest test-org
/match-sparse-tree
()
5720 "Test `org-match-sparse-tree' specifications."
5723 (org-test-with-temp-text "* H\n** H1 :tag:"
5724 (org-match-sparse-tree nil
"tag")
5725 (search-forward "H1")
5726 (org-invisible-p2)))
5728 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5729 (org-match-sparse-tree nil
"tag")
5730 (search-forward "H2")
5731 (org-invisible-p2)))
5732 ;; "-" operator for tags.
5734 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5735 (org-match-sparse-tree nil
"tag1-tag2")
5736 (search-forward "H1")
5737 (org-invisible-p2)))
5739 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5740 (org-match-sparse-tree nil
"tag1-tag2")
5741 (search-forward "H2")
5742 (org-invisible-p2)))
5743 ;; "&" operator for tags.
5745 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5746 (org-match-sparse-tree nil
"tag1&tag2")
5747 (search-forward "H1")
5748 (org-invisible-p2)))
5750 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5751 (org-match-sparse-tree nil
"tag1&tag2")
5752 (search-forward "H2")
5753 (org-invisible-p2)))
5754 ;; "|" operator for tags.
5756 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5757 (org-match-sparse-tree nil
"tag1|tag2")
5758 (search-forward "H1")
5759 (org-invisible-p2)))
5761 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5762 (org-match-sparse-tree nil
"tag1|tag2")
5763 (search-forward "H2")
5764 (org-invisible-p2)))
5765 ;; Regexp match on tags.
5767 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5768 (org-match-sparse-tree nil
"{^tag.*}")
5769 (search-forward "H1")
5770 (org-invisible-p2)))
5772 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5773 (org-match-sparse-tree nil
"{^tag.*}")
5774 (search-forward "H2")
5775 (org-invisible-p2)))
5776 ;; Match group tags.
5778 (org-test-with-temp-text
5779 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5780 (org-match-sparse-tree nil
"work")
5781 (search-forward "H1")
5782 (org-invisible-p2)))
5784 (org-test-with-temp-text
5785 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5786 (org-match-sparse-tree nil
"work")
5787 (search-forward "H2")
5788 (org-invisible-p2)))
5789 ;; Match group tags with hard brackets.
5791 (org-test-with-temp-text
5792 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5793 (org-match-sparse-tree nil
"work")
5794 (search-forward "H1")
5795 (org-invisible-p2)))
5797 (org-test-with-temp-text
5798 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5799 (org-match-sparse-tree nil
"work")
5800 (search-forward "H2")
5801 (org-invisible-p2)))
5802 ;; Match tags in hierarchies
5804 (org-test-with-temp-text
5805 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5806 #+TAGS: [ Lev_2 : Lev_3 ]\n
5807 #+TAGS: { Lev_3 : Lev_4 }\n
5808 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5809 (org-match-sparse-tree nil
"Lev_1")
5810 (search-forward "H4")
5811 (org-invisible-p2)))
5813 (org-test-with-temp-text
5814 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5815 #+TAGS: [ Lev_2 : Lev_3 ]\n
5816 #+TAGS: { Lev_3 : Lev_4 }\n
5817 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5818 (org-match-sparse-tree nil
"Lev_1+Lev_3")
5819 (search-forward "H4")
5820 (org-invisible-p2)))
5821 ;; Match regular expressions in tags
5823 (org-test-with-temp-text
5824 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5825 (org-match-sparse-tree nil
"Lev")
5826 (search-forward "H1")
5827 (org-invisible-p2)))
5829 (org-test-with-temp-text
5830 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5831 (org-match-sparse-tree nil
"Lev")
5832 (search-forward "H1")
5833 (org-invisible-p2)))
5834 ;; Match properties.
5836 (org-test-with-temp-text
5837 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5838 (org-match-sparse-tree nil
"A=\"1\"")
5839 (search-forward "H2")
5840 (org-invisible-p2)))
5842 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5843 (org-match-sparse-tree nil
"A=\"1\"")
5844 (search-forward "H2")
5845 (org-invisible-p2)))
5846 ;; Case is not significant when matching properties.
5848 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5849 (org-match-sparse-tree nil
"a=\"1\"")
5850 (search-forward "H2")
5851 (org-invisible-p2)))
5853 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5854 (org-match-sparse-tree nil
"A=\"1\"")
5855 (search-forward "H2")
5856 (org-invisible-p2)))
5857 ;; Match special LEVEL property.
5859 (org-test-with-temp-text "* H\n** H1\n*** H2"
5860 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5861 (search-forward "H1")
5862 (org-invisible-p2)))
5864 (org-test-with-temp-text "* H\n** H1\n*** H2"
5865 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5866 (search-forward "H2")
5867 (org-invisible-p2)))
5868 ;; Comparison operators when matching properties.
5870 (org-test-with-temp-text
5871 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5872 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5873 (search-forward "H1")
5874 (org-invisible-p2)))
5876 (org-test-with-temp-text
5877 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5878 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5879 (search-forward "H2")
5880 (org-invisible-p2)))
5881 ;; Regexp match on properties values.
5883 (org-test-with-temp-text
5884 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5885 (org-match-sparse-tree nil
"A={f.*}")
5886 (search-forward "H1")
5887 (org-invisible-p2)))
5889 (org-test-with-temp-text
5890 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5891 (org-match-sparse-tree nil
"A={f.*}")
5892 (search-forward "H2")
5893 (org-invisible-p2)))
5894 ;; With an optional argument, limit match to TODO entries.
5896 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5897 (org-match-sparse-tree t
"tag")
5898 (search-forward "H1")
5899 (org-invisible-p2)))
5901 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5902 (org-match-sparse-tree t
"tag")
5903 (search-forward "H2")
5904 (org-invisible-p2))))
5906 (ert-deftest test-org
/occur
()
5907 "Test `org-occur' specifications."
5908 ;; Count number of matches.
5911 (org-test-with-temp-text "* H\nA\n* H2"
5915 (org-test-with-temp-text "* H\nA\n* H2\nA"
5917 ;; Test CALLBACK optional argument.
5920 (org-test-with-temp-text "* H\nA\n* H2"
5921 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5924 (org-test-with-temp-text "* H\nA\n* H2\nA"
5925 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5926 ;; Case-fold searches according to `org-occur-case-fold-search'.
5929 (org-test-with-temp-text "Aa"
5930 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5933 (org-test-with-temp-text "Aa"
5934 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5937 (org-test-with-temp-text "Aa"
5938 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5941 (org-test-with-temp-text "Aa"
5942 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5945 (org-test-with-temp-text "Aa"
5946 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5949 (org-test-with-temp-text "Aa"
5950 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5955 (ert-deftest test-org
/tag-string-to-alist
()
5956 "Test `org-tag-string-to-alist' specifications."
5957 ;; Tag without selection key.
5958 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5959 ;; Tag with selection key.
5960 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5964 (org-tag-string-to-alist "[ group : t1 t2 ]")
5965 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5966 ;; Mutually exclusive tags.
5967 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5968 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5971 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5972 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5974 (ert-deftest test-org
/tag-alist-to-string
()
5975 "Test `org-tag-alist-to-string' specifications."
5976 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5977 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5980 (org-tag-alist-to-string
5981 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5982 "[ group : t1 t2 ]"))
5984 (equal (org-tag-alist-to-string
5985 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5989 (org-tag-alist-to-string
5990 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5991 "{ group : tag1 tag2 }")))
5993 (ert-deftest test-org
/tag-alist-to-groups
()
5994 "Test `org-tag-alist-to-groups' specifications."
5996 (equal (org-tag-alist-to-groups
5997 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5998 '(("group" "t1" "t2"))))
6001 (org-tag-alist-to-groups
6002 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
6003 '(("group" "t1" "t2"))))
6005 (org-tag-alist-to-groups
6006 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
6008 (ert-deftest test-org
/tag-align
()
6009 "Test tags alignment."
6010 ;; Test aligning tags with different display width.
6012 ;; 12345678901234567890
6013 (equal "* Test :abc:"
6014 (org-test-with-temp-text "* Test :abc:"
6015 (let ((org-tags-column -
20)
6016 (indent-tabs-mode nil
))
6017 (org-fix-tags-on-the-fly))
6020 ;; 12345678901234567890
6021 (equal "* Test :日本語:"
6022 (org-test-with-temp-text "* Test :日本語:"
6023 (let ((org-tags-column -
20)
6024 (indent-tabs-mode nil
))
6025 (org-fix-tags-on-the-fly))
6027 ;; Make sure aligning tags do not skip invisible text.
6029 (equal "* [[linkx]] :tag:"
6030 (org-test-with-temp-text "* [[link<point>]] :tag:"
6031 (let ((org-tags-column 0))
6032 (org-fix-tags-on-the-fly)
6034 (buffer-string))))))
6036 (ert-deftest test-org
/tags-at
()
6038 (equal '("foo" "bar")
6039 (org-test-with-temp-text
6040 "* T<point>est :foo:bar:"
6041 (org-get-tags-at)))))
6043 (ert-deftest test-org
/set-tags
()
6044 "Test `org-set-tags' specifications."
6045 ;; Tags set via fast-tag-selection should be visible afterwards
6047 (let ((org-tag-alist '(("NEXT" . ?n
)))
6048 (org-fast-tag-selection-single-key t
))
6049 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6050 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6051 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6052 ;; Show only headlines
6054 ;; Set NEXT tag on current entry
6055 (org-set-tags nil nil
)
6056 ;; Move point to that NEXT tag
6057 (search-forward "NEXT") (backward-word)
6058 ;; And it should be visible (i.e. no overlays)
6059 (not (overlays-at (point))))))))
6061 (ert-deftest test-org
/set-tags-to
()
6062 "Test `org-set-tags-to' specifications."
6063 ;; Throw an error on invalid data.
6065 (org-test-with-temp-text "* H"
6066 (org-set-tags-to 'foo
)))
6067 ;; `nil', an empty, and a blank string remove all tags.
6070 (org-test-with-temp-text "* H :tag1:tag2:"
6071 (org-set-tags-to nil
)
6075 (org-test-with-temp-text "* H :tag1:tag2:"
6076 (org-set-tags-to "")
6080 (org-test-with-temp-text "* H :tag1:tag2:"
6081 (org-set-tags-to " ")
6083 ;; If there's nothing to remove, just bail out.
6086 (org-test-with-temp-text "* H"
6087 (org-set-tags-to nil
)
6091 (org-test-with-temp-text "* "
6092 (org-set-tags-to nil
)
6094 ;; If DATA is a tag string, set current tags to it, even if it means
6095 ;; replacing old tags.
6098 (org-test-with-temp-text "* H :tag1:tag2:"
6099 (org-set-tags-to ":tag0:")
6103 (org-test-with-temp-text "* H"
6104 (org-set-tags-to ":tag0:")
6106 ;; If DATA is a list, set tags to this list, even if it means
6107 ;; replacing old tags.
6110 (org-test-with-temp-text "* H :tag1:tag2:"
6111 (org-set-tags-to '("tag0"))
6115 (org-test-with-temp-text "* H"
6116 (org-set-tags-to '("tag0"))
6118 ;; Special case: handle empty headlines.
6121 (org-test-with-temp-text "* "
6122 (org-set-tags-to '("tag0"))
6128 (ert-deftest test-org
/auto-repeat-maybe
()
6129 "Test `org-auto-repeat-maybe' specifications."
6130 ;; Do not auto repeat when there is no valid time stamp with
6131 ;; a repeater in the entry.
6135 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6136 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
6142 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6143 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
6146 ;; When switching to DONE state, switch back to first TODO keyword
6147 ;; in sequence, or the same keyword if they have different types.
6151 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6152 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6158 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6159 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6165 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
6166 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6169 ;; If there was no TODO keyword in the first place, do not insert
6174 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6175 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6178 ;; Revert to REPEAT_TO_STATE, if set.
6182 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6183 (org-test-with-temp-text
6186 :REPEAT_TO_STATE: KWD2
6188 <2012-03-29 Thu +2y>"
6191 ;; When switching to DONE state, update base date. If there are
6192 ;; multiple repeated time stamps, update them all.
6195 "<2014-03-29 .* \\+2y>"
6196 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6197 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6202 "<2015-03-04 .* \\+1y>"
6203 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6204 (org-test-with-temp-text
6205 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6208 ;; Throw an error if repeater unit is the hour and no time is
6209 ;; provided in the time-stamp.
6211 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6212 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6215 ;; Do not repeat commented time stamps.
6218 "<2015-03-04 .* \\+1y>"
6219 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6220 (org-test-with-temp-text
6221 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6226 "<2015-03-04 .* \\+1y>"
6227 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6228 (org-test-with-temp-text
6230 <2012-03-29 Thu. +2y>
6232 <2014-03-04 Tue +1y>
6236 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6237 ;; entry, record time of last repeat.
6241 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6242 (org-log-repeat nil
))
6243 (cl-letf (((symbol-function 'org-add-log-setup
)
6244 (lambda (&rest args
) nil
)))
6245 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6247 (buffer-string))))))
6251 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6253 (cl-letf (((symbol-function 'org-add-log-setup
)
6254 (lambda (&rest args
) nil
)))
6255 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6257 (buffer-string))))))
6261 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6262 (cl-letf (((symbol-function 'org-add-log-setup
)
6263 (lambda (&rest args
) nil
)))
6264 (org-test-with-temp-text
6265 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6267 (buffer-string))))))
6268 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6269 ;; the entry as it is no longer relevant.
6273 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6274 (org-test-with-temp-text
6275 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6278 ;; Properly advance repeater even when a clock entry is specified
6279 ;; and `org-log-repeat' is nil.
6282 "SCHEDULED: <2014-03-29"
6283 (let ((org-log-repeat nil
)
6284 (org-todo-keywords '((sequence "TODO" "DONE"))))
6285 (org-test-with-temp-text
6287 SCHEDULED: <2012-03-29 Thu +2y>
6288 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6290 (buffer-string))))))
6295 (ert-deftest test-org
/at-timestamp-p
()
6296 "Test `org-at-timestamp-p' specifications."
6298 (org-test-with-temp-text "<2012-03-29 Thu>"
6299 (org-at-timestamp-p)))
6301 (org-test-with-temp-text "2012-03-29 Thu"
6302 (org-at-timestamp-p)))
6303 ;; Test return values.
6306 (org-test-with-temp-text "<2012-03-29 Thu>"
6307 (org-at-timestamp-p))))
6310 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6311 (org-at-timestamp-p))))
6314 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6315 (org-at-timestamp-p))))
6318 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6319 (org-at-timestamp-p))))
6322 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6323 (org-at-timestamp-p))))
6326 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6327 (org-at-timestamp-p))))
6330 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6331 (org-at-timestamp-p))))
6334 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6335 (org-at-timestamp-p))))
6336 ;; Test `inactive' optional argument.
6338 (org-test-with-temp-text "[2012-03-29 Thu]"
6339 (org-at-timestamp-p 'inactive
)))
6341 (org-test-with-temp-text "[2012-03-29 Thu]"
6342 (org-at-timestamp-p)))
6343 ;; When optional argument is `agenda', recognize time-stamps in
6344 ;; planning info line, property drawers and clocks.
6346 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6347 (org-at-timestamp-p 'agenda
)))
6349 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6350 (org-at-timestamp-p)))
6352 (org-test-with-temp-text
6353 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6354 (org-at-timestamp-p 'agenda
)))
6356 (org-test-with-temp-text
6357 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6358 (org-at-timestamp-p)))
6360 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6361 (let ((org-agenda-include-inactive-timestamps t
))
6362 (org-at-timestamp-p 'agenda
))))
6364 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6365 (let ((org-agenda-include-inactive-timestamps t
))
6366 (org-at-timestamp-p))))
6368 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6369 (let ((org-agenda-include-inactive-timestamps t
))
6370 (org-at-timestamp-p 'inactive
))))
6371 ;; When optional argument is `lax', match any part of the document
6372 ;; with Org timestamp syntax.
6374 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6375 (org-at-timestamp-p 'lax
)))
6377 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6378 (org-at-timestamp-p)))
6380 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6381 (org-at-timestamp-p 'lax
)))
6383 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6384 (org-at-timestamp-p)))
6386 (org-test-with-temp-text
6387 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6388 (org-at-timestamp-p 'lax
)))
6390 (org-test-with-temp-text
6391 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6392 (org-at-timestamp-p)))
6393 ;; Optional argument `lax' also matches inactive timestamps.
6395 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6396 (org-at-timestamp-p 'lax
))))
6398 (ert-deftest test-org
/time-stamp
()
6399 "Test `org-time-stamp' specifications."
6400 ;; Insert chosen time stamp at point.
6403 "Te<2014-03-04 .*?>xt"
6404 (org-test-with-temp-text "Te<point>xt"
6405 (cl-letf (((symbol-function 'org-read-date
)
6406 (lambda (&rest args
)
6407 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6408 (org-time-stamp nil
)
6410 ;; With a prefix argument, also insert time.
6413 "Te<2014-03-04 .*? 00:41>xt"
6414 (org-test-with-temp-text "Te<point>xt"
6415 (cl-letf (((symbol-function 'org-read-date
)
6416 (lambda (&rest args
)
6417 (apply #'encode-time
6418 (org-parse-time-string "2014-03-04 00:41")))))
6419 (org-time-stamp '(4))
6421 ;; With two universal prefix arguments, insert an active timestamp
6422 ;; with the current time without prompting the user.
6425 "Te<2014-03-04 .*? 00:41>xt"
6426 (org-test-with-temp-text "Te<point>xt"
6427 (cl-letf (((symbol-function 'current-time
)
6429 (apply #'encode-time
6430 (org-parse-time-string "2014-03-04 00:41")))))
6431 (org-time-stamp '(16))
6433 ;; When optional argument is non-nil, insert an inactive timestamp.
6436 "Te\\[2014-03-04 .*?\\]xt"
6437 (org-test-with-temp-text "Te<point>xt"
6438 (cl-letf (((symbol-function 'org-read-date
)
6439 (lambda (&rest args
)
6440 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6441 (org-time-stamp nil t
)
6443 ;; When called from a timestamp, replace existing one.
6447 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6448 (cl-letf (((symbol-function 'org-read-date
)
6449 (lambda (&rest args
)
6450 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6451 (org-time-stamp nil
)
6455 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6456 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6457 (cl-letf (((symbol-function 'org-read-date
)
6458 (lambda (&rest args
)
6459 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6460 (org-time-stamp nil
)
6462 ;; When replacing a timestamp, preserve repeater, if any.
6465 "<2014-03-04 .*? \\+2y>"
6466 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6467 (cl-letf (((symbol-function 'org-read-date
)
6468 (lambda (&rest args
)
6469 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6470 (org-time-stamp nil
)
6472 ;; When called twice in a raw, build a date range.
6475 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6476 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6477 (cl-letf (((symbol-function 'org-read-date
)
6478 (lambda (&rest args
)
6479 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6480 (let ((last-command 'org-time-stamp
)
6481 (this-command 'org-time-stamp
))
6482 (org-time-stamp nil
))
6483 (buffer-string))))))
6485 (ert-deftest test-org
/timestamp-has-time-p
()
6486 "Test `org-timestamp-has-time-p' specifications."
6489 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6490 (org-timestamp-has-time-p (org-element-context))))
6493 (org-test-with-temp-text "<2012-03-29 Thu>"
6494 (org-timestamp-has-time-p (org-element-context)))))
6496 (ert-deftest test-org
/get-repeat
()
6497 "Test `org-get-repeat' specifications."
6499 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6502 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6504 ;; Return proper repeat string.
6507 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6509 ;; Prevent false positive (commented or verbatim time stamps)
6511 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6514 (org-test-with-temp-text
6515 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6517 ;; Return nil when called before first heading.
6519 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6521 ;; When called with an optional argument, extract repeater from that
6523 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6524 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6526 (ert-deftest test-org
/timestamp-format
()
6527 "Test `org-timestamp-format' specifications."
6532 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6533 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6538 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6539 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6541 (ert-deftest test-org
/timestamp-split-range
()
6542 "Test `org-timestamp-split-range' specifications."
6543 ;; Extract range start (active).
6546 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6547 (let ((ts (org-timestamp-split-range (org-element-context))))
6548 (mapcar (lambda (p) (org-element-property p ts
))
6549 '(:year-end
:month-end
:day-end
))))))
6550 ;; Extract range start (inactive)
6553 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6554 (let ((ts (org-timestamp-split-range (org-element-context))))
6555 (mapcar (lambda (p) (org-element-property p ts
))
6556 '(:year-end
:month-end
:day-end
))))))
6557 ;; Extract range end (active).
6560 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6561 (let ((ts (org-timestamp-split-range
6562 (org-element-context) t
)))
6563 (mapcar (lambda (p) (org-element-property p ts
))
6564 '(:year-end
:month-end
:day-end
))))))
6565 ;; Extract range end (inactive)
6568 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6569 (let ((ts (org-timestamp-split-range
6570 (org-element-context) t
)))
6571 (mapcar (lambda (p) (org-element-property p ts
))
6572 '(:year-end
:month-end
:day-end
))))))
6573 ;; Return the timestamp if not a range.
6575 (org-test-with-temp-text "[2012-03-29 Thu]"
6576 (let* ((ts-orig (org-element-context))
6577 (ts-copy (org-timestamp-split-range ts-orig
)))
6578 (eq ts-orig ts-copy
))))
6580 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6581 (let* ((ts-orig (org-element-context))
6582 (ts-copy (org-timestamp-split-range ts-orig
)))
6583 (eq ts-orig ts-copy
)))))
6585 (ert-deftest test-org
/timestamp-translate
()
6586 "Test `org-timestamp-translate' specifications."
6587 ;; Translate whole date range.
6590 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6591 (let ((org-display-custom-times t
)
6592 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6593 (org-timestamp-translate (org-element-context))))))
6594 ;; Translate date range start.
6597 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6598 (let ((org-display-custom-times t
)
6599 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6600 (org-timestamp-translate (org-element-context) 'start
)))))
6601 ;; Translate date range end.
6604 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6605 (let ((org-display-custom-times t
)
6606 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6607 (org-timestamp-translate (org-element-context) 'end
)))))
6608 ;; Translate time range.
6611 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6612 (let ((org-display-custom-times t
)
6613 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6614 (org-timestamp-translate (org-element-context))))))
6615 ;; Translate non-range timestamp.
6618 (org-test-with-temp-text "<2012-03-29 Thu>"
6619 (let ((org-display-custom-times t
)
6620 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6621 (org-timestamp-translate (org-element-context))))))
6622 ;; Do not change `diary' timestamps.
6624 (equal "<%%(org-float t 4 2)>"
6625 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6626 (let ((org-display-custom-times t
)
6627 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6628 (org-timestamp-translate (org-element-context)))))))
6630 (ert-deftest test-org
/timestamp-from-string
()
6631 "Test `org-timestamp-from-string' specifications."
6632 ;; Return nil if argument is not a valid Org timestamp.
6633 (should-not (org-timestamp-from-string ""))
6634 (should-not (org-timestamp-from-string nil
))
6635 (should-not (org-timestamp-from-string "<2012-03-29"))
6636 ;; Otherwise, return a valid Org timestamp object.
6638 (equal "<2012-03-29 Thu>"
6639 (let ((system-time-locale "en_US"))
6640 (org-element-interpret-data
6641 (org-timestamp-from-string "<2012-03-29 Thu>")))))
6643 (equal "[2014-03-04 Tue]"
6644 (let ((system-time-locale "en_US"))
6645 (org-element-interpret-data
6646 (org-timestamp-from-string "[2014-03-04 Tue]"))))))
6648 (ert-deftest test-org
/timestamp-from-time
()
6649 "Test `org-timestamp-from-time' specifications."
6652 (equal "<2012-03-29 Thu>"
6653 (let ((system-time-locale "en_US"))
6654 (org-element-interpret-data
6655 (org-timestamp-from-time
6656 (apply #'encode-time
6657 (org-parse-time-string "<2012-03-29 Thu 16:40>")))))))
6658 ;; When optional argument WITH-TIME is non-nil, provide time
6661 (equal "<2012-03-29 Thu 16:40>"
6662 (let ((system-time-locale "en_US"))
6663 (org-element-interpret-data
6664 (org-timestamp-from-time
6665 (apply #'encode-time
6666 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6668 ;; When optional argument INACTIVE is non-nil, return an inactive
6671 (equal "[2012-03-29 Thu]"
6672 (let ((system-time-locale "en_US"))
6673 (org-element-interpret-data
6674 (org-timestamp-from-time
6675 (apply #'encode-time
6676 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6679 (ert-deftest test-org
/timestamp-to-time
()
6680 "Test `org-timestamp-to-time' specifications."
6685 (org-timestamp-to-time
6686 (org-timestamp-from-string "<2014-03-04 Tue>")))))
6691 (org-timestamp-to-time
6692 (org-timestamp-from-string "[2014-03-04 Tue]")))))
6694 (equal "2012-03-29 08:30"
6697 (org-timestamp-to-time
6698 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
6703 (org-timestamp-to-time
6704 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
6709 (org-timestamp-to-time
6710 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
6711 ;; When optional argument END is non-nil, use end of date range or
6714 (equal "2012-03-29 16:40"
6717 (org-timestamp-to-time
6718 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
6724 (org-timestamp-to-time
6725 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
6731 (org-timestamp-to-time
6732 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
6738 (ert-deftest test-org
/flag-drawer
()
6739 "Test `org-flag-drawer' specifications."
6742 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6744 (get-char-property (line-end-position) 'invisible
)))
6747 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6749 (org-flag-drawer nil
)
6750 (get-char-property (line-end-position) 'invisible
)))
6751 ;; Test optional argument.
6753 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6754 (let ((drawer (save-excursion (search-forward ":D2")
6755 (org-element-at-point))))
6756 (org-flag-drawer t drawer
)
6757 (get-char-property (progn (search-forward ":D2") (line-end-position))
6760 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6761 (let ((drawer (save-excursion (search-forward ":D2")
6762 (org-element-at-point))))
6763 (org-flag-drawer t drawer
)
6764 (get-char-property (line-end-position) 'invisible
))))
6765 ;; Do not hide fake drawers.
6767 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6770 (get-char-property (line-end-position) 'invisible
)))
6771 ;; Do not hide incomplete drawers.
6773 (org-test-with-temp-text ":D:\nparagraph"
6776 (get-char-property (line-end-position) 'invisible
)))
6777 ;; Do not hide drawers when called from final blank lines.
6779 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6780 (goto-char (point-max))
6782 (goto-char (point-min))
6783 (get-char-property (line-end-position) 'invisible
)))
6784 ;; Don't leave point in an invisible part of the buffer when hiding
6787 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6788 (goto-char (point-max))
6790 (get-char-property (point) 'invisible
))))
6792 (ert-deftest test-org
/hide-block-toggle
()
6793 "Test `org-hide-block-toggle' specifications."
6794 ;; Error when not at a block.
6796 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6797 (org-hide-block-toggle 'off
)
6798 (get-char-property (line-end-position) 'invisible
)))
6801 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6802 (org-hide-block-toggle)
6803 (get-char-property (line-end-position) 'invisible
)))
6805 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6806 (org-hide-block-toggle)
6807 (get-char-property (line-end-position) 'invisible
)))
6808 ;; Show block unconditionally when optional argument is `off'.
6810 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6811 (org-hide-block-toggle)
6812 (org-hide-block-toggle 'off
)
6813 (get-char-property (line-end-position) 'invisible
)))
6815 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6816 (org-hide-block-toggle 'off
)
6817 (get-char-property (line-end-position) 'invisible
)))
6818 ;; Hide block unconditionally when optional argument is non-nil.
6820 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6821 (org-hide-block-toggle t
)
6822 (get-char-property (line-end-position) 'invisible
)))
6824 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6825 (org-hide-block-toggle)
6826 (org-hide-block-toggle t
)
6827 (get-char-property (line-end-position) 'invisible
)))
6828 ;; Do not hide block when called from final blank lines.
6830 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6831 (org-hide-block-toggle)
6832 (goto-char (point-min))
6833 (get-char-property (line-end-position) 'invisible
)))
6834 ;; Don't leave point in an invisible part of the buffer when hiding
6837 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6838 (org-hide-block-toggle)
6839 (get-char-property (point) 'invisible
))))
6841 (ert-deftest test-org
/hide-block-toggle-maybe
()
6842 "Test `org-hide-block-toggle-maybe' specifications."
6844 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6845 (org-hide-block-toggle-maybe)))
6847 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6849 (ert-deftest test-org
/show-set-visibility
()
6850 "Test `org-show-set-visibility' specifications."
6851 ;; Do not throw an error before first heading.
6853 (org-test-with-temp-text "Preamble\n* Headline"
6854 (org-show-set-visibility 'tree
)
6856 ;; Test all visibility spans, both on headline and in entry.
6857 (let ((list-visible-lines
6858 (lambda (state headerp
)
6859 (org-test-with-temp-text "* Grandmother (0)
6870 **** The other child (11)
6875 (search-forward (if headerp
"Self" "Match"))
6876 (org-show-set-visibility state
)
6877 (goto-char (point-min))
6878 (let (result (line 0))
6880 (unless (org-invisible-p2) (push line result
))
6883 (nreverse result
))))))
6884 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6885 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6886 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6887 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6888 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6889 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6890 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6891 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6892 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6893 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6894 (funcall list-visible-lines
'tree nil
)))
6895 (should (equal '(0 1 3 4 5 7 12 13)
6896 (funcall list-visible-lines
'canonical t
)))
6897 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6898 (funcall list-visible-lines
'canonical nil
))))
6899 ;; When point is hidden in a drawer or a block, make sure to make it
6902 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6903 (org-hide-block-toggle)
6904 (search-forward "Text")
6905 (org-show-set-visibility 'minimal
)
6906 (org-invisible-p2)))
6908 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6910 (search-forward "Text")
6911 (org-show-set-visibility 'minimal
)
6912 (org-invisible-p2)))
6914 (org-test-with-temp-text
6915 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6918 (org-hide-block-toggle)
6919 (search-forward "Text")
6920 (org-show-set-visibility 'minimal
)
6921 (org-invisible-p2))))
6923 (defun test-org/copy-visible
()
6924 "Test `org-copy-visible' specifications."
6927 (org-test-with-temp-text "Foo"
6928 (let ((kill-ring nil
))
6929 (org-copy-visible (point-min) (point-max))
6930 (current-kill 0 t
)))))
6931 ;; Skip invisible characters by text property.
6934 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6935 (let ((kill-ring nil
))
6936 (org-copy-visible (point-min) (point-max))
6937 (current-kill 0 t
)))))
6938 ;; Skip invisible characters by overlay.
6941 (org-test-with-temp-text "F<hidden>oo"
6942 (let ((o (make-overlay 2 10)))
6943 (overlay-put o
'invisible t
))
6944 (let ((kill-ring nil
))
6945 (org-copy-visible (point-min) (point-max))
6946 (current-kill 0 t
)))))
6947 ;; Handle invisible characters at the beginning and the end of the
6951 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6952 (let ((kill-ring nil
))
6953 (org-copy-visible (point-min) (point-max))
6954 (current-kill 0 t
)))))
6957 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6958 (let ((kill-ring nil
))
6959 (org-copy-visible (point-min) (point-max))
6960 (current-kill 0 t
)))))
6961 ;; Handle multiple visible parts.
6964 (org-test-with-temp-text
6965 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6966 (let ((kill-ring nil
))
6967 (org-copy-visible (point-min) (point-max))
6968 (current-kill 0 t
))))))
6970 (ert-deftest test-org
/set-visibility-according-to-property
()
6971 "Test `org-set-visibility-according-to-property' specifications."
6974 (org-test-with-temp-text
6981 (org-set-visibility-according-to-property)
6982 (invisible-p (point))))
6983 ;; "children" state.
6985 (org-test-with-temp-text
6989 :VISIBILITY: children
6994 (org-set-visibility-according-to-property)
6995 (invisible-p (point))))
6997 (org-test-with-temp-text
7001 :VISIBILITY: children
7006 (org-set-visibility-according-to-property)
7007 (invisible-p (point))))
7010 (org-test-with-temp-text
7014 :VISIBILITY: content
7019 (org-set-visibility-according-to-property)
7020 (invisible-p (point))))
7022 (org-test-with-temp-text
7026 :VISIBILITY: content
7031 (org-set-visibility-according-to-property)
7032 (not (invisible-p (point)))))
7035 (org-test-with-temp-text
7039 :VISIBILITY: showall
7044 (org-set-visibility-according-to-property)
7045 (not (invisible-p (point)))))
7047 (org-test-with-temp-text
7051 :VISIBILITY: showall
7056 (org-set-visibility-according-to-property)
7057 (not (invisible-p (point))))))
7062 (ert-deftest test-org
/paste-subtree
()
7063 "Test `org-paste-subtree' specifications."
7064 ;; Return an error if text to yank is not a set of subtrees.
7065 (should-error (org-paste-subtree nil
"Text"))
7066 ;; Adjust level according to current one.
7068 (equal "* H\n* Text\n"
7069 (org-test-with-temp-text "* H\n<point>"
7070 (org-paste-subtree nil
"* Text")
7073 (equal "* H1\n** H2\n** Text\n"
7074 (org-test-with-temp-text "* H1\n** H2\n<point>"
7075 (org-paste-subtree nil
"* Text")
7077 ;; When not on a heading, move to next heading before yanking.
7079 (equal "* H1\nParagraph\n* Text\n* H2"
7080 (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
7081 (org-paste-subtree nil
"* Text")
7083 ;; If point is between two headings, use the deepest level.
7085 (equal "* H1\n\n* Text\n* H2"
7086 (org-test-with-temp-text "* H1\n<point>\n* H2"
7087 (org-paste-subtree nil
"* Text")
7090 (equal "** H1\n\n** Text\n* H2"
7091 (org-test-with-temp-text "** H1\n<point>\n* H2"
7092 (org-paste-subtree nil
"* Text")
7095 (equal "* H1\n\n** Text\n** H2"
7096 (org-test-with-temp-text "* H1\n<point>\n** H2"
7097 (org-paste-subtree nil
"* Text")
7099 ;; When on an empty heading, after the stars, deduce the new level
7100 ;; from the number of stars.
7103 (org-test-with-temp-text "*** <point>"
7104 (org-paste-subtree nil
"* Text")
7106 ;; Optional argument LEVEL forces a level for the subtree.
7108 (equal "* H\n*** Text\n"
7109 (org-test-with-temp-text "* H<point>"
7110 (org-paste-subtree 3 "* Text")
7115 ;;; test-org.el ends here