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
25 (eval-and-compile (require 'cl-lib
))
30 (ert-deftest test-org
/toggle-comment
()
31 "Test `org-toggle-comment' specifications."
35 (org-test-with-temp-text "* COMMENT Test"
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
43 ;; Headline with a regular keyword.
46 (org-test-with-temp-text "* TODO COMMENT Test"
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
57 (org-test-with-temp-text "* COMMENT"
62 (org-test-with-temp-text "* "
65 ;; Headline with a single keyword.
68 (org-test-with-temp-text "* TODO COMMENT"
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
76 ;; Headline with a keyword, a priority cookie and contents.
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
88 (ert-deftest test-org
/comment-dwim
()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
94 (org-test-with-temp-text "Comment"
95 (call-interactively #'org-comment-dwim
)
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (call-interactively #'org-comment-dwim
)
104 ;; No region selected, and a comment on this line: indent it.
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# <point>Comment"
108 (let ((org-adapt-indentation t
))
109 (call-interactively #'org-comment-dwim
))
111 ;; Also recognize single # at column 0 as comments.
114 (org-test-with-temp-text "# Comment"
115 (call-interactively #'org-comment-dwim
)
117 ;; Region selected and only comments and blank lines within it:
118 ;; un-comment all commented lines.
120 (equal "Comment 1\n\nComment 2"
121 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
122 (transient-mark-mode 1)
123 (push-mark (point) t t
)
124 (goto-char (point-max))
125 (call-interactively #'org-comment-dwim
)
127 ;; Region selected without comments: comment all lines if
128 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
130 (equal "# Comment 1\n\n# Comment 2"
131 (org-test-with-temp-text "Comment 1\n\nComment 2"
132 (transient-mark-mode 1)
133 (push-mark (point) t t
)
134 (goto-char (point-max))
135 (let ((comment-empty-lines nil
))
136 (call-interactively #'org-comment-dwim
))
139 (equal "# Comment 1\n# \n# Comment 2"
140 (org-test-with-temp-text "Comment 1\n\nComment 2"
141 (transient-mark-mode 1)
142 (push-mark (point) t t
)
143 (goto-char (point-max))
144 (let ((comment-empty-lines t
))
145 (call-interactively #'org-comment-dwim
))
147 ;; In front of a keyword without region, insert a new comment.
149 (equal "# \n#+KEYWORD: value"
150 (org-test-with-temp-text "#+KEYWORD: value"
151 (call-interactively #'org-comment-dwim
)
155 (equal "* COMMENT Test"
156 (org-test-with-temp-text "* Test"
157 (call-interactively #'org-comment-dwim
)
159 ;; In a source block, use appropriate syntax.
162 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively #'org-comment-dwim
))
165 (buffer-substring-no-properties (line-beginning-position)
168 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
169 (org-test-with-temp-text
170 "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
171 (transient-mark-mode 1)
172 (push-mark (point) t t
)
174 (let ((org-edit-src-content-indentation 2))
175 (call-interactively #'org-comment-dwim
))
180 ;;; Date and time analysis
182 (ert-deftest test-org
/org-read-date
()
183 "Test `org-read-date' specifications."
184 ;; Parse ISO date with abbreviated year and month.
185 (should (equal "2012-03-29 16:40"
186 (let ((org-time-was-given t
))
187 (org-read-date t nil
"12-3-29 16:40"))))
188 ;; Parse Europeans dates.
189 (should (equal "2012-03-29 16:40"
190 (let ((org-time-was-given t
))
191 (org-read-date t nil
"29.03.2012 16:40"))))
192 ;; Parse Europeans dates without year.
193 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
194 (let ((org-time-was-given t
))
195 (org-read-date t nil
"29.03. 16:40"))))
196 ;; Relative date applied to current time if there is single
197 ;; plus/minus, or to default date when there are two of them.
201 (org-test-at-time "2014-03-04"
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (org-test-at-time "2014-03-04"
211 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
212 ;; When `org-read-date-prefer-future' is non-nil, prefer future
213 ;; dates (relatively to now) when incomplete. Otherwise, use
218 (org-test-at-time "2014-03-04"
219 (let ((org-read-date-prefer-future t
))
220 (org-read-date t nil
"1")))))
224 (org-test-at-time "2012-03-29"
225 (let ((org-read-date-prefer-future t
))
226 (org-read-date t nil
"3-4")))))
230 (org-test-at-time "2012-03-29"
231 (let ((org-read-date-prefer-future nil
))
232 (org-read-date t nil
"3-4")))))
233 ;; When set to `org-read-date-prefer-future' is set to `time', read
234 ;; day is moved to tomorrow if specified hour is before current
235 ;; time. However, it only happens in no other part of the date is
240 (org-test-at-time "2012-03-29 16:40"
241 (let ((org-read-date-prefer-future 'time
))
242 (org-read-date t nil
"00:40" nil
)))))
246 (org-test-at-time "2012-03-29 16:40"
247 (let ((org-read-date-prefer-future 'time
))
248 (org-read-date t nil
"29 00:40" nil
)))))
249 ;; Caveat: `org-read-date-prefer-future' always refers to current
250 ;; time, not default time, when they differ.
254 (org-test-at-time "2014-03-04"
255 (let ((org-read-date-prefer-future t
))
258 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
262 (org-test-at-time "2014-03-04"
263 (let ((org-read-date-prefer-future t
))
266 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
268 (ert-deftest test-org
/org-parse-time-string
()
269 "Test `org-parse-time-string'."
270 (should (equal (org-parse-time-string "2012-03-29 16:40")
271 '(0 40 16 29 3 2012 nil nil nil
)))
272 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
273 '(0 40 16 29 3 2012 nil nil nil
)))
274 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
275 '(0 40 16 29 3 2012 nil nil nil
)))
276 (should (equal (org-parse-time-string "<2012-03-29>")
277 '(0 0 0 29 3 2012 nil nil nil
)))
278 (should (equal (org-parse-time-string "<2012-03-29>" t
)
279 '(0 nil nil
29 3 2012 nil nil nil
))))
281 (ert-deftest test-org
/closest-date
()
282 "Test `org-closest-date' specifications."
284 ;; Time stamps without a repeater are returned unchanged.
288 (calendar-gregorian-from-absolute
289 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
290 ;; Time stamps with a null repeater are returned unchanged.
294 (calendar-gregorian-from-absolute
295 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
296 ;; if PREFER is set to `past' always return a date before, or equal
301 (calendar-gregorian-from-absolute
302 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
306 (calendar-gregorian-from-absolute
307 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
308 ;; if PREFER is set to `future' always return a date before, or equal
313 (calendar-gregorian-from-absolute
314 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
318 (calendar-gregorian-from-absolute
319 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
320 ;; If PREFER is neither `past' nor `future', select closest date.
324 (calendar-gregorian-from-absolute
325 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
329 (calendar-gregorian-from-absolute
330 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
331 ;; Test "day" repeater.
334 (calendar-gregorian-from-absolute
335 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
338 (calendar-gregorian-from-absolute
339 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
340 ;; Test "month" repeater.
343 (calendar-gregorian-from-absolute
344 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
347 (calendar-gregorian-from-absolute
348 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
349 ;; Test "year" repeater.
352 (calendar-gregorian-from-absolute
353 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
356 (calendar-gregorian-from-absolute
357 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
359 (ert-deftest test-org
/deadline-close-p
()
360 "Test `org-deadline-close-p' specifications."
361 (org-test-at-time "2016-06-03 Fri 01:43"
362 ;; Timestamps are close if they are within `ndays' of lead time.
363 (org-test-with-temp-text "* Heading"
364 (should (org-deadline-close-p "2016-06-03 Fri" 0))
365 (should (org-deadline-close-p "2016-06-02 Thu" 0))
366 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
367 (should (org-deadline-close-p "2016-06-04 Sat" 1))
368 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
369 ;; Read `ndays' from timestamp if argument not given.
370 (org-test-with-temp-text "* H"
371 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
372 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
373 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
374 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
375 ;; Prefer `ndays' argument over lead time in timestamp.
376 (org-test-with-temp-text "* H"
377 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
378 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
379 ;; Completed tasks are never close.
380 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
381 (org-test-with-temp-text "* TODO Heading"
382 (should (org-deadline-close-p "2016-06-03")))
383 (org-test-with-temp-text "* DONE Heading"
384 (should-not (org-deadline-close-p "2016-06-03"))))))
389 (ert-deftest test-org
/insert-property-drawer
()
390 "Test `org-insert-property-drawer' specifications."
391 ;; Error before first headline.
392 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
393 ;; Insert drawer right after headline if there is no planning line,
394 ;; or after it otherwise.
396 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
397 (org-test-with-temp-text "* H\nParagraph<point>"
398 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
401 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
402 (org-test-with-temp-text
403 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
404 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
406 ;; Indent inserted drawer.
408 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
409 (org-test-with-temp-text "* H\nParagraph<point>"
410 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
412 ;; Handle insertion at eob.
414 (equal "* H\n:PROPERTIES:\n:END:\n"
415 (org-test-with-temp-text "* H"
416 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
418 ;; Skip inlinetasks before point.
419 (when (featurep 'org-inlinetask
)
421 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
422 (org-test-with-temp-text
423 "* H\n*************** I\n*************** END\nP<point>"
424 (let ((org-adapt-indentation nil
)
425 (org-inlinetask-min-level 15))
426 (org-insert-property-drawer))
428 ;; Correctly set drawer in an inlinetask.
429 (when (featurep 'org-inlinetask
)
431 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
432 (org-test-with-temp-text
433 "* H\n*************** I\nP<point>\n*************** END"
434 (let ((org-adapt-indentation nil
)
435 (org-inlinetask-min-level 15))
436 (org-insert-property-drawer))
442 (ert-deftest test-org
/fill-element
()
443 "Test `org-fill-element' specifications."
444 ;; At an Org table, align it.
447 (org-test-with-temp-text "|a|"
451 (equal "#+name: table\n| a |\n"
452 (org-test-with-temp-text "#+name: table\n| a |\n"
455 ;; At a paragraph, preserve line breaks.
456 (org-test-with-temp-text "some \\\\\nlong\ntext"
457 (let ((fill-column 20))
459 (should (equal (buffer-string) "some \\\\\nlong text"))))
460 ;; Correctly fill a paragraph when point is at its very end.
463 (org-test-with-temp-text "A\nB"
464 (let ((fill-column 20))
465 (goto-char (point-max))
468 ;; Correctly fill the last paragraph of a greater element.
470 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
471 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
472 (let ((fill-column 8))
477 ;; Correctly fill an element in a narrowed buffer.
480 (org-test-with-temp-text "01234 6789"
481 (let ((fill-column 5))
482 (narrow-to-region 1 8)
485 ;; Handle `adaptive-fill-regexp' in paragraphs.
488 (org-test-with-temp-text "> a\n> b"
489 (let ((fill-column 5)
490 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
493 ;; Special case: Fill first paragraph when point is at an item or
494 ;; a plain-list or a footnote reference.
497 (org-test-with-temp-text "- A\n B"
498 (let ((fill-column 20))
503 (org-test-with-temp-text "[fn:1] A\nB"
504 (let ((fill-column 20))
507 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
508 (let ((fill-column 20))
510 (should (equal (buffer-string)
511 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
512 ;; Fill contents of `comment-block' elements.
515 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
516 (let ((fill-column 20))
520 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
521 ;; Fill `comment' elements.
524 (org-test-with-temp-text " # A\n # B"
525 (let ((fill-column 20))
528 ;; Do not mix consecutive comments when filling one of them.
530 (equal "# A B\n\n# C"
531 (org-test-with-temp-text "# A\n# B\n\n# C"
532 (let ((fill-column 20))
535 ;; Use commented empty lines as separators when filling comments.
537 (equal "# A B\n#\n# C"
538 (org-test-with-temp-text "# A\n# B\n#\n# C"
539 (let ((fill-column 20))
542 ;; Handle `adaptive-fill-regexp' in comments.
545 (org-test-with-temp-text "# > a\n# > b"
546 (let ((fill-column 20)
547 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
550 ;; Do nothing at affiliated keywords.
552 (equal "#+NAME: para\nSome\ntext."
553 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
554 (let ((fill-column 20))
557 ;; Do not move point after table when filling a table.
559 (org-test-with-temp-text "| a | b |\n| c | d |\n"
563 ;; Do not fill "n" macro, with or without arguments, followed by
564 ;; a dot or a closing parenthesis since it could be confused with
565 ;; a numbered bullet.
567 (equal "123456789\n{{{n}}}."
568 (org-test-with-temp-text "123456789 {{{n}}}."
569 (let ((fill-column 10))
573 (equal "123456789\n{{{n}}}\)"
574 (org-test-with-temp-text "123456789 {{{n}}}\)"
575 (let ((fill-column 10))
579 (equal "123456789\n{{{n()}}}."
580 (org-test-with-temp-text "123456789 {{{n()}}}."
581 (let ((fill-column 10))
585 (equal "123456789\n{{{n(counter)}}}."
586 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
587 (let ((fill-column 10))
591 (ert-deftest test-org
/auto-fill-function
()
592 "Test auto-filling features."
593 ;; Auto fill paragraph.
596 (org-test-with-temp-text "12345 7890"
597 (let ((fill-column 5))
599 (org-auto-fill-function)
601 ;; Auto fill first paragraph in an item.
603 (equal "- 12345\n 7890"
604 (org-test-with-temp-text "- 12345 7890"
605 (let ((fill-column 7))
607 (org-auto-fill-function)
609 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
611 (equal "> 12345\n 7890"
612 (org-test-with-temp-text "> 12345 7890"
613 (let ((fill-column 10)
614 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
615 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
617 (org-auto-fill-function)
620 (equal "> 12345\n> 12345\n> 7890"
621 (org-test-with-temp-text "> 12345\n> 12345 7890"
622 (let ((fill-column 10)
623 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
624 (goto-char (point-max))
625 (org-auto-fill-function)
628 (equal " 12345\n *12345\n *12345"
629 (org-test-with-temp-text " 12345\n *12345 12345"
630 (let ((fill-column 10)
631 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
632 (goto-char (point-max))
633 (org-auto-fill-function)
635 ;; Auto fill comments.
637 (equal " # 12345\n # 7890"
638 (org-test-with-temp-text " # 12345 7890"
639 (let ((fill-column 10))
641 (org-auto-fill-function)
643 ;; A hash within a line isn't a comment.
645 (equal "12345 # 7890\n# 1"
646 (org-test-with-temp-text "12345 # 7890 1"
647 (let ((fill-column 12))
649 (org-auto-fill-function)
651 ;; Correctly interpret empty prefix.
653 (equal "# a\n# b\nRegular\n# paragraph"
654 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
655 (let ((fill-column 12))
657 (org-auto-fill-function)
659 ;; Comment block: auto fill contents.
661 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
662 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
663 (let ((fill-column 5))
666 (org-auto-fill-function)
669 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
670 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
671 (let ((fill-column 5))
674 (org-auto-fill-function)
676 ;; Do not fill if a new item could be created.
679 (org-test-with-temp-text "12345 - 90"
680 (let ((fill-column 5))
682 (org-auto-fill-function)
684 ;; Do not fill if a line break could be introduced.
686 (equal "123\\\\\n7890"
687 (org-test-with-temp-text "123\\\\ 7890"
688 (let ((fill-column 6))
690 (org-auto-fill-function)
692 ;; Do not fill affiliated keywords.
694 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
695 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
696 (let ((fill-column 20))
698 (org-auto-fill-function)
705 (ert-deftest test-org
/indent-line
()
706 "Test `org-indent-line' specifications."
707 ;; Do not indent diary sexps, footnote definitions or headlines.
710 (org-test-with-temp-text "%%(org-calendar-holiday)"
712 (org-get-indentation))))
715 (org-test-with-temp-text "[fn:1] fn"
716 (let ((org-adapt-indentation t
)) (org-indent-line))
717 (org-get-indentation))))
720 (org-test-with-temp-text "* H"
722 (org-get-indentation))))
723 ;; Do not indent before first headline.
726 (org-test-with-temp-text ""
728 (org-get-indentation))))
729 ;; Indent according to headline level otherwise, unless
730 ;; `org-adapt-indentation' is nil.
733 (org-test-with-temp-text "* H\n<point>A"
734 (let ((org-adapt-indentation t
)) (org-indent-line))
735 (org-get-indentation))))
738 (org-test-with-temp-text "* H\n<point>\nA"
739 (let ((org-adapt-indentation t
)) (org-indent-line))
740 (org-get-indentation))))
743 (org-test-with-temp-text "* H\n<point>A"
744 (let ((org-adapt-indentation nil
)) (org-indent-line))
745 (org-get-indentation))))
746 ;; Indenting preserves point position.
748 (org-test-with-temp-text "* H\nA<point>B"
749 (let ((org-adapt-indentation t
)) (org-indent-line))
751 ;; Do not change indentation at an item or a LaTeX environment.
754 (org-test-with-temp-text "* H\n<point> - A"
755 (let ((org-adapt-indentation t
)) (org-indent-line))
756 (org-get-indentation))))
759 (org-test-with-temp-text
760 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
762 (org-get-indentation))))
763 ;; On blank lines at the end of a list, indent like last element
764 ;; within it if the line is still in the list. If the last element
765 ;; is an item, indent like its contents. Otherwise, indent like the
769 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
770 (let ((org-adapt-indentation t
)) (org-indent-line))
771 (org-get-indentation))))
774 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
775 (let ((org-adapt-indentation t
)) (org-indent-line))
776 (org-get-indentation))))
779 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
780 (let ((org-adapt-indentation t
)) (org-indent-line))
781 (org-get-indentation))))
784 (org-test-with-temp-text "* H\n- A\n - \n<point>"
785 (let ((org-adapt-indentation t
)) (org-indent-line))
786 (org-get-indentation))))
789 (org-test-with-temp-text
790 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
791 (let ((org-adapt-indentation t
)) (org-indent-line))
792 (org-get-indentation))))
795 (org-test-with-temp-text "- A\n B\n\n<point>"
796 (let ((org-adapt-indentation nil
)) (org-indent-line))
797 (org-get-indentation))))
800 (org-test-with-temp-text
801 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
802 (let ((org-adapt-indentation nil
)) (org-indent-line))
803 (org-get-indentation))))
804 ;; Likewise, on a blank line at the end of a footnote definition,
805 ;; indent at column 0 if line belongs to the definition. Otherwise,
806 ;; indent like the definition itself.
809 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
810 (let ((org-adapt-indentation t
)) (org-indent-line))
811 (org-get-indentation))))
814 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
815 (let ((org-adapt-indentation t
)) (org-indent-line))
816 (org-get-indentation))))
817 ;; After the end of the contents of a greater element, indent like
818 ;; the beginning of the element.
821 (org-test-with-temp-text
822 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
824 (org-get-indentation))))
825 ;; On blank lines after a paragraph, indent like its last non-empty
829 (org-test-with-temp-text " Paragraph\n\n<point>"
831 (org-get-indentation))))
832 ;; At the first line of an element, indent like previous element's
833 ;; first line, ignoring footnotes definitions and inline tasks, or
834 ;; according to parent.
837 (org-test-with-temp-text "A\n\n B\n\nC<point>"
839 (org-get-indentation))))
842 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
844 (org-get-indentation))))
847 (org-test-with-temp-text
848 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
850 (org-get-indentation))))
851 ;; Within code part of a source block, use language major mode if
852 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
853 ;; according to line above.
856 (org-test-with-temp-text
857 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
858 (let ((org-src-tab-acts-natively t
)
859 (org-edit-src-content-indentation 0))
861 (org-get-indentation))))
864 (org-test-with-temp-text
865 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
866 (let ((org-src-tab-acts-natively nil
)
867 (org-edit-src-content-indentation 0))
869 (org-get-indentation))))
870 ;; Otherwise, indent like the first non-blank line above.
873 (org-test-with-temp-text
874 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
876 (org-get-indentation))))
877 ;; Align node properties according to `org-property-format'. Handle
878 ;; nicely empty values.
880 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
881 (org-test-with-temp-text
882 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
883 (let ((org-property-format "%-10s %s")) (org-indent-line))
886 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
887 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
888 (let ((org-property-format "%-10s %s")) (org-indent-line))
891 (ert-deftest test-org
/indent-region
()
892 "Test `org-indent-region' specifications."
896 (org-test-with-temp-text " A\nB\n C"
897 (org-indent-region (point-min) (point-max))
899 ;; Indent greater elements along with their contents.
901 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
902 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
903 (org-indent-region (point-min) (point-max))
905 ;; Ignore contents of verse blocks. Only indent block delimiters.
907 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
908 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
909 (org-indent-region (point-min) (point-max))
912 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
913 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
914 (org-indent-region (point-min) (point-max))
916 ;; Indent example blocks as a single block, unless indentation
917 ;; should be preserved. In this case only indent the block markers.
919 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
920 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
921 (org-indent-region (point-min) (point-max))
924 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
925 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
926 (org-indent-region (point-min) (point-max))
929 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
930 (org-test-with-temp-text
931 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
932 (org-indent-region (point-min) (point-max))
935 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
936 (org-test-with-temp-text
937 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
938 (let ((org-src-preserve-indentation t
))
939 (org-indent-region (point-min) (point-max)))
941 ;; Treat export blocks as a whole.
943 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
944 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
945 (org-indent-region (point-min) (point-max))
948 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
949 (org-test-with-temp-text
950 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
951 (org-indent-region (point-min) (point-max))
953 ;; Indent according to mode if `org-src-tab-acts-natively' is
954 ;; non-nil. Otherwise, do not indent code at all.
956 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
957 (org-test-with-temp-text
958 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
959 (let ((org-src-tab-acts-natively t
)
960 (org-edit-src-content-indentation 0))
961 (org-indent-region (point-min) (point-max)))
964 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
965 (org-test-with-temp-text
966 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
967 (let ((org-src-tab-acts-natively nil
)
968 (org-edit-src-content-indentation 0))
969 (org-indent-region (point-min) (point-max)))
971 ;; Align node properties according to `org-property-format'. Handle
972 ;; nicely empty values.
974 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
975 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
976 (let ((org-property-format "%-10s %s")
977 (org-adapt-indentation nil
))
978 (org-indent-region (point) (point-max)))
981 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
982 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
983 (let ((org-property-format "%-10s %s")
984 (org-adapt-indentation nil
))
985 (org-indent-region (point) (point-max)))
987 ;; Indent plain lists.
989 (equal "- A\n B\n - C\n\n D"
990 (org-test-with-temp-text "- A\n B\n - C\n\n D"
991 (org-indent-region (point-min) (point-max))
995 (org-test-with-temp-text " - A\n\n - B"
996 (org-indent-region (point-min) (point-max))
998 ;; Indent footnote definitions.
1000 (equal "[fn:1] Definition\n\nDefinition"
1001 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1002 (org-indent-region (point-min) (point-max))
1004 ;; Special case: Start indenting on a blank line.
1006 (equal "\nParagraph"
1007 (org-test-with-temp-text "\n Paragraph"
1008 (org-indent-region (point-min) (point-max))
1015 (ert-deftest test-org
/delete-indentation
()
1016 "Test `org-delete-indentation' specifications."
1018 (should (equal "foo bar"
1019 (org-test-with-temp-text
1021 (org-delete-indentation)
1023 ;; With optional argument.
1024 (should (equal "foo bar"
1025 (org-test-with-temp-text
1027 (org-delete-indentation t
)
1029 ;; At headline text should be appended to the headline text.
1031 (equal"* foo bar :tag:"
1032 (let (org-auto-align-tags)
1033 (org-test-with-temp-text
1034 "* foo :tag:\n bar<point>"
1035 (org-delete-indentation)
1038 (equal "* foo bar :tag:"
1039 (let (org-auto-align-tags)
1040 (org-test-with-temp-text
1041 "* foo <point>:tag:\n bar"
1042 (org-delete-indentation t
)
1043 (buffer-string))))))
1045 (ert-deftest test-org
/return
()
1046 "Test `org-return' specifications."
1049 (equal "Para\ngraph"
1050 (org-test-with-temp-text "Para<point>graph"
1053 ;; With optional argument, indent line.
1055 (equal " Para\n graph"
1056 (org-test-with-temp-text " Para<point>graph"
1059 ;; On a table, call `org-table-next-row'.
1061 (org-test-with-temp-text "| <point>a |\n| b |"
1063 (looking-at-p "b")))
1064 ;; Open link or timestamp under point when `org-return-follows-link'
1067 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1068 (let ((org-return-follows-link t
)
1069 (org-link-search-must-match-exact-headline nil
))
1071 (looking-at-p "<<target>>")))
1073 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1074 (let ((org-return-follows-link nil
)) (org-return))
1075 (looking-at-p "<<target>>")))
1077 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1078 (let ((org-return-follows-link t
)) (org-return))
1079 (looking-at-p "* b")))
1081 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1082 (let ((org-return-follows-link t
)
1083 (org-link-search-must-match-exact-headline nil
))
1085 (looking-at-p "<<target>>")))
1087 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1088 (let ((org-return-follows-link t
)
1089 (org-link-search-must-match-exact-headline nil
))
1091 (looking-at-p "<<target>>")))
1092 ;; When `org-return-follows-link' is non-nil, tolerate links and
1093 ;; timestamps in comments, node properties, etc.
1095 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1096 (let ((org-return-follows-link t
)
1097 (org-link-search-must-match-exact-headline nil
))
1099 (looking-at-p "<<target>>")))
1101 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1102 (let ((org-return-follows-link nil
)) (org-return))
1103 (looking-at-p "<<target>>")))
1105 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1106 (let ((org-return-follows-link t
)
1107 (org-link-search-must-match-exact-headline nil
))
1109 (looking-at-p "<<target>>")))
1110 ;; `org-return-follows-link' handle multi-line lines.
1112 (org-test-with-temp-text
1113 "[[target][This is a very\n long description<point>]]\n <<target>>"
1114 (let ((org-return-follows-link t
)
1115 (org-link-search-must-match-exact-headline nil
))
1117 (looking-at-p "<<target>>")))
1119 (org-test-with-temp-text
1120 "[[target][This is a very\n long description]]<point>\n <<target>>"
1121 (let ((org-return-follows-link t
)
1122 (org-link-search-must-match-exact-headline nil
))
1124 (looking-at-p "<<target>>")))
1125 ;; However, do not open link when point is in a table.
1127 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1128 (let ((org-return-follows-link t
)) (org-return))
1129 (looking-at-p "between")))
1130 ;; Special case: in a list, when indenting, do not break structure.
1133 (org-test-with-temp-text "- A <point>B"
1138 (org-test-with-temp-text "- A\n<point>- B"
1141 ;; On tags part of a headline, add a newline below it instead of
1144 (equal "* H :tag:\n"
1145 (org-test-with-temp-text "* H :<point>tag:"
1148 ;; Before headline text, add a newline below it instead of breaking
1151 (equal "* TODO H :tag:\n"
1152 (org-test-with-temp-text "* <point>TODO H :tag:"
1156 (equal "* TODO [#B] H :tag:\n"
1157 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1160 (should ;TODO are case-sensitive
1162 (org-test-with-temp-text "* <point>Todo"
1165 ;; At headline text, break headline text but preserve tags.
1167 (equal "* TODO [#B] foo :tag:\nbar"
1168 (let (org-auto-align-tags)
1169 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1172 ;; At bol of headline insert newline.
1175 (org-test-with-temp-text "<point>* h"
1178 ;; Refuse to leave invalid headline in buffer.
1181 (org-test-with-temp-text "*<point> h"
1184 ;; Before first column or after last one in a table, split the
1187 (equal "| a |\n\n| b |"
1188 (org-test-with-temp-text "| a |\n<point>| b |"
1192 (equal "| a |\n\n| b |"
1193 (org-test-with-temp-text "| a |<point>\n| b |"
1196 ;; Do not auto-fill on hitting <RET> inside a property drawer.
1198 (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:"
1199 (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:"
1200 (setq-local fill-column
10)
1205 (ert-deftest test-org
/meta-return
()
1206 "Test M-RET (`org-meta-return') specifications."
1207 ;; In a table field insert a row above.
1209 (org-test-with-temp-text "| a |"
1213 (looking-at "| |$")))
1214 ;; In a paragraph change current line into a header.
1216 (org-test-with-temp-text "a"
1219 (looking-at "\* a$")))
1220 ;; In an item insert an item, in this case above.
1222 (org-test-with-temp-text "- a"
1225 (looking-at "- $")))
1226 ;; In a drawer and item insert an item, in this case above.
1228 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1232 (looking-at "- $"))))
1234 (ert-deftest test-org
/insert-heading
()
1235 "Test `org-insert-heading' specifications."
1236 ;; In an empty buffer, insert a new headline.
1239 (org-test-with-temp-text ""
1240 (org-insert-heading)
1242 ;; At the beginning of a line, turn it into a headline.
1245 (org-test-with-temp-text "<point>P"
1246 (org-insert-heading)
1248 ;; In the middle of a line, split the line if allowed, otherwise,
1249 ;; insert the headline at its end.
1251 (equal "Para\n* graph"
1252 (org-test-with-temp-text "Para<point>graph"
1253 (let ((org-M-RET-may-split-line '((default . t
))))
1254 (org-insert-heading))
1257 (equal "Paragraph\n* "
1258 (org-test-with-temp-text "Para<point>graph"
1259 (let ((org-M-RET-may-split-line '((default . nil
))))
1260 (org-insert-heading))
1262 ;; At the beginning of a headline, create one above.
1265 (org-test-with-temp-text "* H"
1266 (org-insert-heading)
1268 ;; In the middle of a headline, split it if allowed.
1271 (org-test-with-temp-text "* H<point>1"
1272 (let ((org-M-RET-may-split-line '((headline . t
))))
1273 (org-insert-heading))
1277 (org-test-with-temp-text "* H<point>1"
1278 (let ((org-M-RET-may-split-line '((headline . nil
))))
1279 (org-insert-heading))
1281 ;; However, splitting cannot happen on TODO keywords, priorities or
1284 (equal "* TODO H1\n* "
1285 (org-test-with-temp-text "* TO<point>DO H1"
1286 (let ((org-M-RET-may-split-line '((headline . t
))))
1287 (org-insert-heading))
1290 (equal "* [#A] H1\n* "
1291 (org-test-with-temp-text "* [#<point>A] H1"
1292 (let ((org-M-RET-may-split-line '((headline . t
))))
1293 (org-insert-heading))
1296 (equal "* H1 :tag:\n* "
1297 (org-test-with-temp-text "* H1 :ta<point>g:"
1298 (let ((org-M-RET-may-split-line '((headline . t
))))
1299 (org-insert-heading))
1301 ;; New headline level depends on the level of the headline above.
1304 (org-test-with-temp-text "** H\n<point>P"
1305 (org-insert-heading)
1308 (equal "** H\nPara\n** graph"
1309 (org-test-with-temp-text "** H\nPara<point>graph"
1310 (let ((org-M-RET-may-split-line '((default . t
))))
1311 (org-insert-heading))
1315 (org-test-with-temp-text "** H"
1316 (org-insert-heading)
1318 ;; When called with one universal argument, insert a new headline at
1319 ;; the end of the current subtree, independently on the position of
1324 (org-test-with-temp-text "* H1\n** H2"
1325 (let ((org-insert-heading-respect-content nil
))
1326 (org-insert-heading '(4)))
1331 (org-test-with-temp-text "* H<point>1\n** H2"
1332 (let ((org-insert-heading-respect-content nil
))
1333 (org-insert-heading '(4)))
1335 ;; When called with two universal arguments, insert a new headline
1336 ;; at the end of the grandparent subtree.
1338 (equal "* H1\n** H3\n- item\n** H2\n** "
1339 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1340 (let ((org-insert-heading-respect-content nil
))
1341 (org-insert-heading '(16)))
1343 ;; When optional TOP-LEVEL argument is non-nil, always insert
1344 ;; a level 1 heading.
1346 (equal "* H1\n** H2\n* "
1347 (org-test-with-temp-text "* H1\n** H2<point>"
1348 (org-insert-heading nil nil t
)
1351 (equal "* H1\n- item\n* "
1352 (org-test-with-temp-text "* H1\n- item<point>"
1353 (org-insert-heading nil nil t
)
1355 ;; Obey `org-blank-before-new-entry'.
1358 (org-test-with-temp-text "* H1<point>"
1359 (let ((org-blank-before-new-entry '((heading . t
))))
1360 (org-insert-heading))
1364 (org-test-with-temp-text "* H1<point>"
1365 (let ((org-blank-before-new-entry '((heading . nil
))))
1366 (org-insert-heading))
1369 (equal "* H1\n* H2\n* "
1370 (org-test-with-temp-text "* H1\n* H2<point>"
1371 (let ((org-blank-before-new-entry '((heading . auto
))))
1372 (org-insert-heading))
1375 (equal "* H1\n\n* H2\n\n* "
1376 (org-test-with-temp-text "* H1\n\n* H2<point>"
1377 (let ((org-blank-before-new-entry '((heading . auto
))))
1378 (org-insert-heading))
1380 ;; Corner case: correctly insert a headline after an empty one.
1383 (org-test-with-temp-text "* <point>"
1384 (org-insert-heading)
1387 (org-test-with-temp-text "* <point>\n"
1388 (org-insert-heading)
1389 (looking-at-p "\n\\'")))
1390 ;; Do not insert spurious headlines when inserting a new headline.
1392 (equal "* H1\n* H2\n* \n"
1393 (org-test-with-temp-text "* H1\n* H2<point>\n"
1394 (org-insert-heading)
1396 ;; Preserve visibility at beginning of line. In particular, when
1397 ;; removing spurious blank lines, do not visually merge heading with
1398 ;; the line visible above.
1400 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1402 (let ((org-blank-before-new-entry '((heading . nil
))))
1403 (org-insert-heading '(4)))
1404 (invisible-p (line-end-position 0))))
1405 ;; Properly handle empty lines when forcing a headline below current
1408 (equal "* H1\n\n* H\n\n* "
1409 (org-test-with-temp-text "* H1\n\n* H<point>"
1410 (let ((org-blank-before-new-entry '((heading . t
))))
1411 (org-insert-heading '(4))
1412 (buffer-string))))))
1414 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1415 "Test `org-insert-todo-heading-respect-content' specifications."
1416 ;; Create a TODO heading.
1418 (org-test-with-temp-text "* H1\n Body"
1419 (org-insert-todo-heading-respect-content)
1420 (nth 2 (org-heading-components))))
1421 ;; Add headline at the end of the first subtree
1425 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1426 (org-insert-todo-heading-respect-content)
1427 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1428 ;; In a list, do not create a new item.
1432 (org-test-with-temp-text "* H\n- an item\n- another one"
1433 (search-forward "an ")
1434 (org-insert-todo-heading-respect-content)
1435 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1436 ;; Use the same TODO keyword as current heading.
1440 (org-test-with-temp-text "* TODO\n** WAITING\n"
1441 (org-insert-todo-heading-respect-content)
1442 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1444 (ert-deftest test-org
/clone-with-time-shift
()
1445 "Test `org-clone-subtree-with-time-shift'."
1446 ;; Raise an error before first heading.
1448 (org-test-with-temp-text ""
1449 (org-clone-subtree-with-time-shift 1)))
1450 ;; Raise an error on invalid number of clones.
1452 (org-test-with-temp-text "* Clone me"
1453 (org-clone-subtree-with-time-shift -
1)))
1454 ;; Clone non-repeating once.
1460 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1461 (org-clone-subtree-with-time-shift 1 "+2d")
1462 (replace-regexp-in-string
1463 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1465 ;; Clone repeating once.
1470 * H1\n<2015-06-25 +1w>
1472 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1473 (org-clone-subtree-with-time-shift 1 "+2d")
1474 (replace-regexp-in-string
1475 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1477 ;; Clone repeating once in backward.
1482 * H1\n<2015-06-17 +1w>
1484 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1485 (org-clone-subtree-with-time-shift 1 "-2d")
1486 (replace-regexp-in-string
1487 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1489 ;; Clone non-repeating zero times.
1494 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1495 (org-clone-subtree-with-time-shift 0 "+2d")
1496 (replace-regexp-in-string
1497 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1499 ;; Clone repeating "zero" times.
1503 * H1\n<2015-06-23 +1w>
1505 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1506 (org-clone-subtree-with-time-shift 0 "+2d")
1507 (replace-regexp-in-string
1508 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1510 ;; Clone with blank SHIFT argument.
1514 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1515 (org-clone-subtree-with-time-shift 1 "")
1516 (buffer-substring-no-properties (line-beginning-position 2)
1517 (line-end-position 2)))))
1518 ;; Find time stamps before point. If SHIFT is not specified, ask
1519 ;; for a time shift.
1523 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1524 (org-clone-subtree-with-time-shift 1 "+1d")
1525 (buffer-substring-no-properties (line-beginning-position 2)
1526 (line-end-position 2)))))
1530 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1531 (cl-letf (((symbol-function 'read-from-minibuffer
)
1532 (lambda (&rest args
) "+1d")))
1533 (org-clone-subtree-with-time-shift 1))
1534 (buffer-substring-no-properties (line-beginning-position 2)
1535 (line-end-position 2))))))
1538 ;;; Fixed-Width Areas
1540 (ert-deftest test-org
/toggle-fixed-width
()
1541 "Test `org-toggle-fixed-width' specifications."
1542 ;; No region: Toggle on fixed-width marker in paragraphs.
1545 (org-test-with-temp-text "A"
1546 (org-toggle-fixed-width)
1548 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1551 (org-test-with-temp-text ": A"
1552 (org-toggle-fixed-width)
1554 ;; No region: Toggle on marker in blank lines after elements or just
1555 ;; after a headline.
1558 (org-test-with-temp-text "* H\n"
1560 (org-toggle-fixed-width)
1563 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1564 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1565 (goto-char (point-max))
1566 (org-toggle-fixed-width)
1568 ;; No region: Toggle on marker in front of one line elements (e.g.,
1569 ;; headlines, clocks)
1571 (equal ": * Headline"
1572 (org-test-with-temp-text "* Headline"
1573 (org-toggle-fixed-width)
1576 (equal ": #+KEYWORD: value"
1577 (org-test-with-temp-text "#+KEYWORD: value"
1578 (org-toggle-fixed-width)
1580 ;; No region: error in other situations.
1582 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1584 (org-toggle-fixed-width)
1586 ;; No region: Indentation is preserved.
1589 (org-test-with-temp-text "- A\n B"
1591 (org-toggle-fixed-width)
1593 ;; Region: If it contains only fixed-width elements and blank lines,
1594 ;; toggle off fixed-width markup.
1597 (org-test-with-temp-text ": A\n\n: B"
1598 (transient-mark-mode 1)
1599 (push-mark (point) t t
)
1600 (goto-char (point-max))
1601 (org-toggle-fixed-width)
1603 ;; Region: If it contains anything else, toggle on fixed-width but
1604 ;; not on fixed-width areas.
1606 (equal ": A\n: \n: B\n: \n: C"
1607 (org-test-with-temp-text "A\n\n: B\n\nC"
1608 (transient-mark-mode 1)
1609 (push-mark (point) t t
)
1610 (goto-char (point-max))
1611 (org-toggle-fixed-width)
1613 ;; Region: Ignore blank lines at its end, unless it contains only
1617 (org-test-with-temp-text "A\n\n"
1618 (transient-mark-mode 1)
1619 (push-mark (point) t t
)
1620 (goto-char (point-max))
1621 (org-toggle-fixed-width)
1625 (org-test-with-temp-text "\n\n"
1626 (transient-mark-mode 1)
1627 (push-mark (point) t t
)
1628 (goto-char (point-max))
1629 (org-toggle-fixed-width)
1632 (ert-deftest test-org
/kill-line
()
1633 "Test `org-kill-line' specifications."
1634 ;; At the beginning of a line, kill whole line.
1637 (org-test-with-temp-text "abc"
1640 ;; In the middle of a line, kill line until its end.
1643 (org-test-with-temp-text "a<point>bc"
1646 ;; Do not kill newline character.
1649 (org-test-with-temp-text "abc\n123"
1654 (org-test-with-temp-text "a<point>bc\n123"
1657 ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
1661 (org-test-with-temp-text "* A<point>B :tag:"
1662 (let ((org-special-ctrl-k t
)
1663 (org-tags-column 0))
1666 ;; If point is on tags, only kill part left until the end of line.
1669 (org-test-with-temp-text "* A :tag:<point>tag2:"
1670 (let ((org-special-ctrl-k t
)
1671 (org-tags-column 0))
1674 ;; However, if point is at the beginning of the line, kill whole
1678 (org-test-with-temp-text "* AB :tag:"
1679 (let ((org-special-ctrl-k t
)
1680 (org-tags-column 0))
1683 ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
1684 ;; invisible text, ask before removing it. When set to `error',
1687 (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
1689 (let ((org-special-ctrl-k nil
)
1690 (org-ctrl-k-protect-subtree t
))
1691 (cl-letf (((symbol-function 'y-or-n-p
) 'ignore
))
1694 (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
1696 (let ((org-special-ctrl-k nil
)
1697 (org-ctrl-k-protect-subtree 'error
))
1704 (ert-deftest test-org
/get-heading
()
1705 "Test `org-get-heading' specifications."
1706 ;; Return current heading, even if point is not on it.
1709 (org-test-with-temp-text "* H"
1710 (org-get-heading))))
1713 (org-test-with-temp-text "* H\nText<point>"
1714 (org-get-heading))))
1715 ;; Without any optional argument, return TODO keyword, priority
1716 ;; cookie, COMMENT keyword and tags.
1719 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1720 (org-get-heading))))
1723 (org-test-with-temp-text "* [#A] H"
1724 (org-get-heading))))
1727 (org-test-with-temp-text "* COMMENT H"
1728 (org-get-heading))))
1731 (org-test-with-temp-text "* H :tag:"
1732 (org-get-heading))))
1733 ;; With NO-TAGS argument, ignore tags.
1736 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1737 (org-get-heading t
))))
1740 (org-test-with-temp-text "* H :tag:"
1741 (org-get-heading t
))))
1742 ;; With NO-TODO, ignore TODO keyword.
1745 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1746 (org-get-heading nil t
))))
1749 (org-test-with-temp-text "* H :tag:"
1750 (org-get-heading nil t
))))
1751 ;; TODO keywords are case-sensitive.
1754 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1755 (org-get-heading nil t
))))
1756 ;; With NO-PRIORITY, ignore priority.
1759 (org-test-with-temp-text "* [#A] H"
1760 (org-get-heading nil nil t
))))
1763 (org-test-with-temp-text "* H"
1764 (org-get-heading nil nil t
))))
1767 (org-test-with-temp-text "* TODO [#A] H"
1768 (org-get-heading nil nil t
))))
1769 ;; With NO-COMMENT, ignore COMMENT keyword.
1772 (org-test-with-temp-text "* COMMENT H"
1773 (org-get-heading nil nil nil t
))))
1776 (org-test-with-temp-text "* H"
1777 (org-get-heading nil nil nil t
))))
1779 (equal "TODO [#A] H"
1780 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1781 (org-get-heading nil nil nil t
))))
1782 ;; On an empty headline, return value is consistent.
1783 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1784 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1785 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1786 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1788 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1790 (ert-deftest test-org
/in-commented-heading-p
()
1791 "Test `org-in-commented-heading-p' specifications."
1792 ;; Commented headline.
1794 (org-test-with-temp-text "* COMMENT Headline\nBody"
1795 (goto-char (point-max))
1796 (org-in-commented-heading-p)))
1797 ;; Commented ancestor.
1799 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1800 (goto-char (point-max))
1801 (org-in-commented-heading-p)))
1802 ;; Comment keyword is case-sensitive.
1804 (org-test-with-temp-text "* Comment Headline\nBody"
1805 (goto-char (point-max))
1806 (org-in-commented-heading-p)))
1807 ;; Keyword is standalone.
1809 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1810 (goto-char (point-max))
1811 (org-in-commented-heading-p)))
1812 ;; Optional argument.
1814 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1815 (goto-char (point-max))
1816 (org-in-commented-heading-p t
))))
1818 (ert-deftest test-org
/entry-blocked-p
()
1819 ;; Check other dependencies.
1821 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1822 (let ((org-enforce-todo-dependencies t
)
1824 '(org-block-todo-from-children-or-siblings-or-parent)))
1825 (org-entry-blocked-p))))
1827 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1828 (let ((org-enforce-todo-dependencies t
)
1830 '(org-block-todo-from-children-or-siblings-or-parent)))
1831 (org-entry-blocked-p))))
1832 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1835 (org-test-with-temp-text "* Blocked\n** TODO one"
1836 (let ((org-enforce-todo-dependencies t
)
1838 '(org-block-todo-from-children-or-siblings-or-parent)))
1839 (org-entry-blocked-p))))
1841 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1842 (let ((org-enforce-todo-dependencies t
)
1844 '(org-block-todo-from-children-or-siblings-or-parent)))
1845 (org-entry-blocked-p))))
1846 ;; Follow :ORDERED: specifications.
1848 (org-test-with-temp-text
1849 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1850 (let ((org-enforce-todo-dependencies t
)
1852 '(org-block-todo-from-children-or-siblings-or-parent)))
1853 (org-entry-blocked-p))))
1855 (org-test-with-temp-text
1856 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1857 (let ((org-enforce-todo-dependencies t
)
1859 '(org-block-todo-from-children-or-siblings-or-parent)))
1860 (org-entry-blocked-p)))))
1862 (ert-deftest test-org
/get-outline-path
()
1863 "Test `org-get-outline-path' specifications."
1864 ;; Top-level headlines have no outline path.
1866 (org-test-with-temp-text "* H"
1867 (org-get-outline-path)))
1868 ;; Otherwise, outline path is the path leading to the headline.
1871 (org-test-with-temp-text "* H\n** S<point>"
1872 (org-get-outline-path))))
1873 ;; Find path even when point is not on a headline.
1876 (org-test-with-temp-text "* H\n** S\nText<point>"
1877 (org-get-outline-path))))
1878 ;; TODO keywords, tags and statistics cookies are ignored.
1881 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1882 (org-get-outline-path))))
1883 ;; Links are replaced with their description or their path.
1886 (org-test-with-temp-text
1887 "* [[https://orgmode.org][Org]]\n** S<point>"
1888 (org-get-outline-path))))
1890 (equal '("https://orgmode.org")
1891 (org-test-with-temp-text
1892 "* [[https://orgmode.org]]\n** S<point>"
1893 (org-get-outline-path))))
1894 ;; When WITH-SELF is non-nil, include current heading.
1897 (org-test-with-temp-text "* H"
1898 (org-get-outline-path t
))))
1901 (org-test-with-temp-text "* H\n** S\nText<point>"
1902 (org-get-outline-path t
))))
1903 ;; Using cache is transparent to the user.
1906 (org-test-with-temp-text "* H\n** S<point>"
1907 (setq org-outline-path-cache nil
)
1908 (org-get-outline-path nil t
))))
1909 ;; Do not corrupt cache when finding outline path in distant part of
1913 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1914 (setq org-outline-path-cache nil
)
1915 (org-get-outline-path nil t
)
1916 (search-forward "S2")
1917 (org-get-outline-path nil t
))))
1918 ;; Do not choke on empty headlines.
1920 (org-test-with-temp-text "* H\n** <point>"
1921 (org-get-outline-path)))
1923 (org-test-with-temp-text "* \n** H<point>"
1924 (org-get-outline-path))))
1926 (ert-deftest test-org
/format-outline-path
()
1927 "Test `org-format-outline-path' specifications."
1929 (string= (org-format-outline-path (list "one" "two" "three"))
1933 (string= (org-format-outline-path '())
1936 (string= (org-format-outline-path '(nil))
1938 ;; Empty path and prefix.
1940 (string= (org-format-outline-path '() nil
">>")
1942 ;; Trailing whitespace in headings.
1944 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1946 ;; Non-default prefix and separators.
1948 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1949 ">>|one|two|three"))
1952 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1954 ;; Give a very narrow width.
1956 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1958 ;; Give a prefix that extends beyond the width.
1960 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1964 (ert-deftest test-org
/map-entries
()
1965 "Test `org-map-entries' specifications."
1969 (org-test-with-temp-text "* Level 1\n** Level 2"
1970 (org-map-entries #'point
))))
1974 (org-test-with-temp-text "* Level 1\n** Level 2"
1975 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1978 (org-test-with-temp-text "* Level 1\n** Level 2"
1979 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1983 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1984 (org-map-entries #'point
"yes"))))
1987 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1988 (org-map-entries #'point
"+yes-a"))))
1991 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1992 (org-map-entries #'point
"{yes?}"))))
1996 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1997 (org-map-entries #'point
"PRIORITY=\"A\""))))
2001 (org-test-with-temp-text "
2003 SCHEDULED: <2012-03-29 thu.>
2005 SCHEDULED: <2014-03-04 tue.>"
2006 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
2009 (org-test-with-temp-text "
2011 SCHEDULED: <2012-03-29 thu.>
2013 SCHEDULED: <2014-03-04 tue.>"
2014 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
2015 ;; Regular property match.
2018 (org-test-with-temp-text "
2027 (org-map-entries #'point
"TEST=1"))))
2028 ;; Multiple criteria.
2031 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
2032 (let (org-odd-levels-only
2033 (org-use-tag-inheritance nil
))
2034 (org-map-entries #'point
"yes+LEVEL=1")))))
2038 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
2039 (let (org-odd-levels-only)
2040 (org-map-entries #'point
"LEVEL=2|no")))))
2043 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
2044 (let (org-odd-levels-only)
2045 (org-map-entries #'point
"yes|no")))))
2049 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
2050 (let (org-odd-levels-only)
2051 (org-map-entries #'point
"yes&no"))))))
2053 (ert-deftest test-org
/edit-headline
()
2054 "Test `org-edit-headline' specifications."
2057 (org-test-with-temp-text "* A"
2058 (org-edit-headline "B")
2060 ;; Handle empty headings.
2063 (org-test-with-temp-text "* A"
2064 (org-edit-headline "")
2068 (org-test-with-temp-text "* "
2069 (org-edit-headline "A")
2071 ;; Handle TODO keywords and priority cookies.
2074 (org-test-with-temp-text "* TODO A"
2075 (org-edit-headline "B")
2079 (org-test-with-temp-text "* [#A] A"
2080 (org-edit-headline "B")
2083 (equal "* TODO [#A] B"
2084 (org-test-with-temp-text "* TODO [#A] A"
2085 (org-edit-headline "B")
2089 (org-test-with-temp-text "* A :tag:"
2090 (let ((org-tags-column 4)) (org-edit-headline "B"))
2097 (ert-deftest test-org
/set-regexps-and-options
()
2098 "Test `org-set-regexps-and-options' specifications."
2102 (let ((org-tag-alist '(("A")))
2103 (org-tag-persistent-alist nil
))
2104 (org-test-with-temp-text ""
2106 org-current-tag-alist
))))
2109 (let ((org-tag-alist '(("A")))
2110 (org-tag-persistent-alist nil
))
2111 (org-test-with-temp-text "#+TAGS: B"
2113 org-current-tag-alist
))))
2115 (equal '(("C") ("B"))
2116 (let ((org-tag-alist '(("A")))
2117 (org-tag-persistent-alist '(("C"))))
2118 (org-test-with-temp-text "#+TAGS: B"
2120 org-current-tag-alist
))))
2123 (let ((org-tag-alist '(("A")))
2124 (org-tag-persistent-alist '(("C"))))
2125 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2127 org-current-tag-alist
))))
2129 (equal '(("A" . ?a
) ("B") ("C"))
2130 (let ((org-tag-persistant-alist nil
))
2131 (org-test-with-temp-text "#+TAGS: A(a) B C"
2133 org-current-tag-alist
))))
2135 (equal '(("A") (:newline
) ("B"))
2136 (let ((org-tag-persistent-alist nil
))
2137 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2139 org-current-tag-alist
))))
2141 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2142 (let ((org-tag-persistent-alist nil
))
2143 (org-test-with-temp-text "#+TAGS: { A B } C"
2145 org-current-tag-alist
))))
2147 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2148 (let ((org-tag-persistent-alist nil
))
2149 (org-test-with-temp-text "#+TAGS: { A : B C }"
2151 org-current-tag-alist
))))
2153 (equal '(("A" "B" "C"))
2154 (let ((org-tag-persistent-alist nil
))
2155 (org-test-with-temp-text "#+TAGS: { A : B C }"
2157 org-tag-groups-alist
))))
2159 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2160 (let ((org-tag-persistent-alist nil
))
2161 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2163 org-current-tag-alist
))))
2165 (equal '(("A" "B" "C"))
2166 (let ((org-tag-persistent-alist nil
))
2167 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2169 org-tag-groups-alist
))))
2170 ;; FILETAGS keyword.
2172 (equal '("A" "B" "C")
2173 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2176 ;; PROPERTY keyword. Property names are case-insensitive.
2179 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2181 (cdr (assoc "var" org-file-properties
)))))
2185 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2187 (cdr (assoc "var" org-file-properties
)))))
2191 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2193 (cdr (assoc "var" org-file-properties
)))))
2197 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2199 org-archive-location
)))
2200 ;; CATEGORY keyword.
2203 (org-test-with-temp-text "#+CATEGORY: test"
2208 (org-test-with-temp-text "#+CATEGORY: test"
2210 (cdr (assoc "CATEGORY" org-file-properties
)))))
2213 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2214 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2216 org-columns-default-format
)))
2217 ;; CONSTANTS keyword. Constants names are case sensitive.
2219 (equal '("299792458." "3.14")
2220 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2223 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2227 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2229 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2232 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2234 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2239 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2241 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2243 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2247 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2249 (list org-highest-priority org-lowest-priority org-default-priority
))))
2253 (org-test-with-temp-text "#+PRIORITIES: X Z"
2255 (list org-highest-priority org-lowest-priority org-default-priority
))))
2259 (org-test-with-temp-text "#+STARTUP: fold odd"
2261 (list org-startup-folded org-odd-levels-only
))))
2264 (equal '(("A" "B") ("C"))
2265 (org-test-with-temp-text "#+TODO: A B | C"
2267 (list org-not-done-keywords org-done-keywords
))))
2269 (equal '(("A" "C") ("B" "D"))
2270 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2272 (list org-not-done-keywords org-done-keywords
))))
2274 (equal '(("A" "B") ("C"))
2275 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2277 (list org-not-done-keywords org-done-keywords
))))
2279 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2280 (org-test-with-temp-text "#+TODO: A(a)"
2282 org-todo-key-alist
)))
2284 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2285 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2287 org-todo-log-states
)))
2288 ;; Enter SETUPFILE keyword.
2291 (org-test-with-temp-text
2292 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2294 (cdr (assoc "a" org-file-properties
))))))
2302 (ert-deftest test-org
/coderef
()
2303 "Test coderef links specifications."
2305 (org-test-with-temp-text "
2306 #+BEGIN_SRC emacs-lisp
2311 (looking-at "(ref:sc)")))
2312 ;; Find coderef even with alternate label format.
2314 (org-test-with-temp-text "
2315 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2320 (looking-at "{ref:sc}"))))
2324 (ert-deftest test-org
/custom-id
()
2325 "Test custom ID links specifications."
2327 (org-test-with-temp-text
2328 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2330 (looking-at-p "\\* H1")))
2331 ;; Handle escape characters.
2333 (org-test-with-temp-text
2334 "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#[%\\]<point>]]"
2336 (looking-at-p "\\* H1")))
2337 ;; Throw an error on false positives.
2339 (org-test-with-temp-text
2340 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2342 (looking-at-p "\\* H1"))))
2346 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2347 ;; a named element (#+name: text) and to headlines (* Text).
2349 (ert-deftest test-org
/fuzzy-links
()
2350 "Test fuzzy links specifications."
2351 ;; Fuzzy link goes in priority to a matching target.
2353 (org-test-with-temp-text
2354 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2355 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2356 (looking-at "<<Test>>")))
2357 ;; Then fuzzy link points to an element with a given name.
2359 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2360 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2361 (looking-at "#\\+NAME: Test")))
2362 ;; A target still lead to a matching headline otherwise.
2364 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2365 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2366 (looking-at "\\* Head2")))
2367 ;; With a leading star in link, enforce heading match.
2369 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2370 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2371 (looking-at "\\* Test")))
2372 ;; With a leading star in link, enforce exact heading match, even
2373 ;; with `org-link-search-must-match-exact-headline' set to nil.
2375 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2376 (let ((org-link-search-must-match-exact-headline nil
))
2377 (org-open-at-point))))
2378 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2380 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2381 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2382 (looking-at "\\* Test")))
2384 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2385 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2386 (looking-at "\\* Test")))
2387 ;; Heading match should not care about spaces, cookies, TODO
2388 ;; keywords, priorities, and tags. However, TODO keywords are
2392 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2393 (org-test-with-temp-text
2394 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2395 (let ((org-link-search-must-match-exact-headline nil
)
2396 (org-todo-regexp "TODO"))
2397 (org-open-at-point))
2398 (looking-at (regexp-quote first-line
)))))
2400 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2401 (let ((org-link-search-must-match-exact-headline nil
)
2402 (org-todo-regexp "TODO"))
2403 (org-open-at-point))))
2404 ;; Heading match should still be exact.
2406 (org-test-with-temp-text "
2407 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2410 (let ((org-link-search-must-match-exact-headline nil
)
2411 (org-todo-regexp "TODO"))
2412 (org-open-at-point))))
2414 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2415 (let ((org-link-search-must-match-exact-headline nil
)
2416 (org-todo-regexp "TODO"))
2417 (org-open-at-point))
2418 (looking-at-p (regexp-quote "** Test 1 2"))))
2419 ;; Heading match ignores COMMENT keyword.
2421 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2423 (looking-at "\\* COMMENT Test")))
2425 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2427 (looking-at "\\* TODO COMMENT Test")))
2428 ;; Correctly un-escape fuzzy links.
2430 (org-test-with-temp-text "* [foo]\n[[*[foo\\]][With escaped characters]]"
2433 ;; Match search strings containing newline characters, including
2436 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2437 (let ((file (buffer-file-name)))
2438 (goto-char (point-max))
2439 (insert (format "[[file:%s::line1 line2]]" file
))
2441 (let ((org-link-search-must-match-exact-headline nil
))
2442 (org-open-at-point 0))
2443 (looking-at-p "line1"))))
2445 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2446 (let ((file (buffer-file-name)))
2447 (goto-char (point-max))
2448 (insert (format "[[file:%s::line1 line2]]" file
))
2450 (let ((org-link-search-must-match-exact-headline nil
))
2451 (org-open-at-point 0))
2452 (looking-at-p "line1")))))
2456 (ert-deftest test-org
/open-at-point
/keyword
()
2457 "Does `org-open-at-point' open link in a keyword line?"
2459 (org-test-with-temp-text
2460 "<<top>>\n#+KEYWORD: <point>[[top]]"
2461 (org-open-at-point) t
))
2463 (org-test-with-temp-text
2464 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2465 (org-open-at-point) t
)))
2467 (ert-deftest test-org
/open-at-point
/property
()
2468 "Does `org-open-at-point' open link in property drawer?"
2470 (org-test-with-temp-text
2473 :URL: <point>[[*Headline]]
2475 (org-open-at-point) t
)))
2477 (ert-deftest test-org
/open-at-point
/comment
()
2478 "Does `org-open-at-point' open link in a commented line?"
2480 (org-test-with-temp-text
2481 "<<top>>\n# <point>[[top]]"
2482 (org-open-at-point) t
))
2484 (org-test-with-temp-text
2485 "* H\n<<top>>\n# <point>[[top]]"
2486 (org-open-at-point) t
)))
2488 (ert-deftest test-org
/open-at-point
/inline-image
()
2489 "Test `org-open-at-point' on nested links."
2491 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2495 (ert-deftest test-org
/open-at-point
/radio-target
()
2496 "Test `org-open-at-point' on radio targets."
2498 (org-test-with-temp-text "<<<target>>> <point>target"
2499 (org-update-radio-target-regexp)
2501 (eq (org-element-type (org-element-context)) 'radio-target
))))
2503 (ert-deftest test-org
/open-at-point
/tag
()
2504 "Test `org-open-at-point' on tags."
2506 (org-test-with-temp-text "* H :<point>tag:"
2508 (cl-letf (((symbol-function 'org-tags-view
)
2509 (lambda (&rest args
) (throw :result t
))))
2513 (org-test-with-temp-text-in-file "* H<point> :tag:"
2515 (cl-letf (((symbol-function 'org-tags-view
)
2516 (lambda (&rest args
) (throw :result t
))))
2523 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2524 "Ensure properties accumulate in subtree drawers."
2525 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2526 (org-babel-next-src-block)
2527 (should (equal '(2 1) (org-babel-execute-src-block)))))
2529 (ert-deftest test-org
/custom-properties
()
2530 "Test custom properties specifications."
2533 (let ((org-custom-properties '("FOO")))
2534 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2535 (org-toggle-custom-properties-visibility)
2536 (org-invisible-p2))))
2537 ;; Properties are case-insensitive.
2539 (let ((org-custom-properties '("FOO")))
2540 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2541 (org-toggle-custom-properties-visibility)
2542 (org-invisible-p2))))
2544 (let ((org-custom-properties '("foo")))
2545 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2546 (org-toggle-custom-properties-visibility)
2547 (org-invisible-p2))))
2548 ;; Multiple custom properties in the same drawer.
2550 (let ((org-custom-properties '("FOO" "BAR")))
2551 (org-test-with-temp-text
2552 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2553 (org-toggle-custom-properties-visibility)
2554 (and (org-invisible-p2)
2555 (not (progn (forward-line) (org-invisible-p2)))
2556 (progn (forward-line) (org-invisible-p2))))))
2557 ;; Hide custom properties with an empty value.
2559 (let ((org-custom-properties '("FOO")))
2560 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2561 (org-toggle-custom-properties-visibility)
2562 (org-invisible-p2))))
2563 ;; Do not hide fake properties.
2565 (let ((org-custom-properties '("FOO")))
2566 (org-test-with-temp-text ":FOO: val\n"
2567 (org-toggle-custom-properties-visibility)
2568 (org-invisible-p2))))
2570 (let ((org-custom-properties '("A")))
2571 (org-test-with-temp-text
2572 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2573 (org-toggle-custom-properties-visibility)
2574 (org-invisible-p2)))))
2580 (ert-deftest test-org
/mark-subtree
()
2581 "Test `org-mark-subtree' specifications."
2582 ;; Error when point is before first headline.
2584 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2585 (progn (transient-mark-mode 1)
2586 (org-mark-subtree))))
2587 ;; Without argument, mark current subtree.
2591 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2592 (progn (transient-mark-mode 1)
2595 (list (region-beginning) (region-end))))))
2596 ;; With an argument, move ARG up.
2600 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2601 (progn (transient-mark-mode 1)
2603 (org-mark-subtree 1)
2604 (list (region-beginning) (region-end))))))
2605 ;; Do not get fooled by inlinetasks.
2606 (when (featurep 'org-inlinetask
)
2609 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2610 (progn (transient-mark-mode 1)
2612 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2613 (region-beginning)))))))
2619 (ert-deftest test-org
/sort-entries
()
2620 "Test `org-sort-entries'."
2621 ;; Sort alphabetically.
2623 (equal "\n* abc\n* def\n* xyz\n"
2624 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2625 (org-sort-entries nil ?a
)
2628 (equal "\n* xyz\n* def\n* abc\n"
2629 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2630 (org-sort-entries nil ?A
)
2633 (equal "\n* \n* klm\n* xyz\n"
2634 (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
2635 (org-sort-entries nil ?a
)
2637 ;; Sort numerically.
2639 (equal "\n* 1\n* 2\n* 10\n"
2640 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2641 (org-sort-entries nil ?n
)
2644 (equal "\n* 10\n* 2\n* 1\n"
2645 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2646 (org-sort-entries nil ?N
)
2649 (equal "\n* \n* 1\n* 2\n"
2650 (org-test-with-temp-text "\n* 1\n* \n* 2\n"
2651 (org-sort-entries nil ?n
)
2653 ;; Sort by custom function.
2655 (equal "\n* b\n* aa\n* ccc\n"
2656 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2657 (org-sort-entries nil ?f
2659 (length (buffer-substring (point-at-bol)
2664 (equal "\n* ccc\n* aa\n* b\n"
2665 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2666 (org-sort-entries nil ?F
2668 (length (buffer-substring (point-at-bol)
2672 ;; Sort by TODO keyword.
2674 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2675 (org-test-with-temp-text
2676 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2677 (org-sort-entries nil ?o
)
2680 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2681 (org-test-with-temp-text
2682 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2683 (org-sort-entries nil ?O
)
2685 ;; Sort by priority.
2687 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2688 (org-test-with-temp-text
2689 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2690 (org-sort-entries nil ?p
)
2693 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2694 (org-test-with-temp-text
2695 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2696 (org-sort-entries nil ?P
)
2698 ;; Sort by creation time.
2708 (org-test-with-temp-text
2717 (org-sort-entries nil ?c
)
2720 ;; Sort by scheduled date.
2724 SCHEDULED: <2017-05-06 Sat>
2726 SCHEDULED: <2017-05-08 Mon>
2728 DEADLINE: <2017-05-09 Tue>
2730 DEADLINE: <2017-05-07 Sun>
2732 (org-test-with-temp-text
2735 DEADLINE: <2017-05-09 Tue>
2737 DEADLINE: <2017-05-07 Sun>
2739 SCHEDULED: <2017-05-08 Mon>
2741 SCHEDULED: <2017-05-06 Sat>
2743 (org-sort-entries nil ?s
)
2745 ;; Sort by deadline date.
2749 DEADLINE: <2017-05-07 Sun>
2751 DEADLINE: <2017-05-09 Tue>
2753 SCHEDULED: <2017-05-08 Mon>
2755 SCHEDULED: <2017-05-06 Sat>
2757 (org-test-with-temp-text
2760 DEADLINE: <2017-05-09 Tue>
2762 DEADLINE: <2017-05-07 Sun>
2764 SCHEDULED: <2017-05-08 Mon>
2766 SCHEDULED: <2017-05-06 Sat>
2768 (org-sort-entries nil ?d
)
2770 ;; Sort by any date/time
2774 SCHEDULED: <2017-05-06 Sat>
2776 DEADLINE: <2017-05-07 Sun>
2778 SCHEDULED: <2017-05-08 Mon>
2780 DEADLINE: <2017-05-09 Tue>
2782 (org-test-with-temp-text
2785 DEADLINE: <2017-05-09 Tue>
2787 DEADLINE: <2017-05-07 Sun>
2789 SCHEDULED: <2017-05-08 Mon>
2791 SCHEDULED: <2017-05-06 Sat>
2793 (org-sort-entries nil ?t
)
2795 ;; Sort by clocking time.
2800 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2801 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2805 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2806 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2809 (org-test-with-temp-text
2813 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2814 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2818 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2819 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2822 (org-sort-entries nil ?k
)
2824 ;; Preserve file local variables when sorting.
2826 (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
2827 (org-test-with-temp-text
2828 "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
2829 (org-sort-entries nil ?a
)
2832 (ert-deftest test-org
/string-collate-greaterp
()
2833 "Test `org-string-collate-greaterp' specifications."
2834 (should (org-string-collate-greaterp "def" "abc"))
2835 (should-not (org-string-collate-greaterp "abc" "def")))
2837 (ert-deftest test-org
/file-contents
()
2838 "Test `org-file-contents' specifications."
2841 (string= "#+BIND: variable value
2847 " (org-file-contents (expand-file-name "setupfile3.org"
2848 (concat org-test-dir
"examples/")))))
2849 ;; Throw error when trying to access an invalid file.
2850 (should-error (org-file-contents "this-file-must-not-exist"))
2851 ;; Try to access an invalid file, but do not throw an error.
2853 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2857 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2859 ;; Simulate successful retrieval of a URL.
2860 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2862 (with-current-buffer buffer
2863 (insert "HTTP/1.1 200 OK\n\nfoo"))
2865 (org-file-contents "http://some-valid-url"))
2866 (kill-buffer buffer
)))))
2867 ;; Throw error when trying to access an invalid URL.
2869 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2871 ;; Simulate unsuccessful retrieval of a URL.
2872 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2874 (with-current-buffer buffer
2875 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2877 (org-file-contents "http://this-url-must-not-exist"))
2878 (kill-buffer buffer
))))
2879 ;; Try to access an invalid URL, but do not throw an error.
2881 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2883 ;; Simulate unsuccessful retrieval of a URL.
2884 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2886 (with-current-buffer buffer
2887 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2889 (org-file-contents "http://this-url-must-not-exist"))
2890 (kill-buffer buffer
))))
2892 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2894 ;; Simulate unsuccessful retrieval of a URL.
2895 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2897 (with-current-buffer buffer
2898 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2900 (org-file-contents "http://this-url-must-not-exist" :noerror
))
2901 (kill-buffer buffer
))
2907 (ert-deftest test-org
/forward-heading-same-level
()
2908 "Test `org-forward-heading-same-level' specifications."
2909 ;; Test navigation at top level, forward and backward.
2912 (org-test-with-temp-text "* H1\n* H2"
2913 (org-forward-heading-same-level 1)
2914 (buffer-substring-no-properties (point) (line-end-position)))))
2917 (org-test-with-temp-text "* H1\n<point>* H2"
2918 (org-forward-heading-same-level -
1)
2919 (buffer-substring-no-properties (point) (line-end-position)))))
2920 ;; Test navigation in a sub-tree, forward and backward.
2923 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2924 (org-forward-heading-same-level 1)
2925 (buffer-substring-no-properties (point) (line-end-position)))))
2928 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
2929 (org-forward-heading-same-level -
1)
2930 (buffer-substring-no-properties (point) (line-end-position)))))
2931 ;; Stop at first or last sub-heading.
2934 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
2935 (org-forward-heading-same-level 1)
2936 (buffer-substring-no-properties (point) (line-end-position)))))
2939 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
2940 (org-forward-heading-same-level -
1)
2941 (buffer-substring-no-properties (point) (line-end-position)))))
2942 ;; Allow multiple moves.
2945 (org-test-with-temp-text "* H1\n* H2\n* H3"
2946 (org-forward-heading-same-level 2)
2947 (buffer-substring-no-properties (point) (line-end-position)))))
2950 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
2951 (org-forward-heading-same-level -
2)
2952 (buffer-substring-no-properties (point) (line-end-position)))))
2953 ;; Ignore spurious moves when first (or last) sibling is reached.
2956 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
2957 (org-forward-heading-same-level 100)
2958 (buffer-substring-no-properties (point) (line-end-position)))))
2961 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
2962 (org-forward-heading-same-level -
100)
2963 (buffer-substring-no-properties (point) (line-end-position))))))
2965 (ert-deftest test-org
/end-of-meta-data
()
2966 "Test `org-end-of-meta-data' specifications."
2967 ;; Skip planning line.
2969 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2970 (org-end-of-meta-data)
2972 ;; Skip properties drawer.
2974 (org-test-with-temp-text
2975 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2976 (org-end-of-meta-data)
2980 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2981 (org-end-of-meta-data)
2983 ;; Nothing to skip, go to first line.
2985 (org-test-with-temp-text "* Headline\nContents"
2986 (org-end-of-meta-data)
2987 (looking-at "Contents")))
2988 ;; With option argument, skip empty lines, regular drawers and
2991 (org-test-with-temp-text "* Headline\n\nContents"
2992 (org-end-of-meta-data t
)
2993 (looking-at "Contents")))
2995 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2996 (org-end-of-meta-data t
)
2997 (looking-at "Contents")))
2999 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3000 (org-end-of-meta-data t
)
3001 (looking-at "Contents")))
3002 ;; Special case: do not skip incomplete drawers.
3004 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3005 (org-end-of-meta-data t
)
3006 (looking-at ":LOGBOOK:")))
3007 ;; Special case: Be careful about consecutive headlines.
3009 (org-test-with-temp-text "* H1\n*H2\nContents"
3010 (org-end-of-meta-data t
)
3011 (looking-at "Contents"))))
3013 (ert-deftest test-org
/beginning-of-line
()
3014 "Test `org-beginning-of-line' specifications."
3015 ;; Move to beginning of line. If current line in invisible, move to
3016 ;; beginning of visible line instead.
3018 (org-test-with-temp-text "Some text\nSome other text<point>"
3019 (org-beginning-of-line)
3022 (org-test-with-temp-text "* H1\n** H2<point>"
3024 (org-beginning-of-line)
3025 (= (line-beginning-position) 1)))
3026 ;; With `visual-line-mode' active, move to beginning of visual line.
3028 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3030 (dotimes (i 1000) (insert "very "))
3031 (org-beginning-of-line)
3033 ;; In a wide headline, with `visual-line-mode', prefer going to the
3034 ;; beginning of a visual line than to the logical beginning of line,
3035 ;; even if special movement is active.
3037 (org-test-with-temp-text "* A <point>long headline"
3039 (dotimes (i 1000) (insert "very "))
3040 (goto-char (point-max))
3041 (org-beginning-of-line)
3044 (org-test-with-temp-text "* A <point>long headline"
3046 (dotimes (i 1000) (insert "very "))
3047 (goto-char (point-max))
3048 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3050 ;; At an headline with special movement, first move at beginning of
3051 ;; title, then at the beginning of line, rinse, repeat.
3053 (org-test-with-temp-text "* TODO Headline<point>"
3054 (let ((org-special-ctrl-a/e t
))
3055 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3056 (progn (org-beginning-of-line) (bolp))
3057 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3059 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3060 (let ((org-special-ctrl-a/e t
))
3061 (org-beginning-of-line)
3062 (looking-at "Headline"))))
3064 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3065 (let ((org-special-ctrl-a/e
'(t . nil
)))
3066 (org-beginning-of-line)
3067 (looking-at "Headline"))))
3069 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3070 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3071 (org-beginning-of-line)
3072 (looking-at "Headline"))))
3073 ;; At an headline with reversed movement, first move to beginning of
3074 ;; line, then to the beginning of title.
3076 (org-test-with-temp-text "* TODO Headline<point>"
3077 (let ((org-special-ctrl-a/e
'reversed
)
3078 (this-command last-command
))
3079 (and (progn (org-beginning-of-line) (bolp))
3080 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3082 (org-test-with-temp-text "* TODO Headline<point>"
3083 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3084 (this-command last-command
))
3085 (and (progn (org-beginning-of-line) (bolp))
3086 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3088 (org-test-with-temp-text "* TODO Headline<point>"
3089 (let ((org-special-ctrl-a/e
'(t . nil
))
3090 (this-command last-command
))
3091 (and (progn (org-beginning-of-line) (bolp))
3092 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3093 ;; At an item with special movement, first move after to beginning
3094 ;; of title, then to the beginning of line, rinse, repeat.
3096 (org-test-with-temp-text "- [ ] Item<point>"
3097 (let ((org-special-ctrl-a/e t
))
3098 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3099 (progn (org-beginning-of-line) (bolp))
3100 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3101 ;; At an item with reversed movement, first move to beginning of
3102 ;; line, then to the beginning of title.
3104 (org-test-with-temp-text "- [X] Item<point>"
3105 (let ((org-special-ctrl-a/e
'reversed
)
3106 (this-command last-command
))
3107 (and (progn (org-beginning-of-line) (bolp))
3108 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3109 ;; Leave point before invisible characters at column 0.
3111 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3112 (let ((org-special-ctrl-a/e nil
))
3113 (org-beginning-of-line)
3116 (org-test-with-temp-text "[[https://orgmode.org]]<point>"
3117 (let ((org-special-ctrl-a/e t
))
3118 (org-beginning-of-line)
3121 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3123 (org-beginning-of-line)
3125 ;; Special case: Do not error when the buffer contains only a single
3128 (org-test-with-temp-text "*<point>"
3129 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3131 (org-test-with-temp-text "*<point>"
3132 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3134 (ert-deftest test-org
/end-of-line
()
3135 "Test `org-end-of-line' specifications."
3138 (org-test-with-temp-text "Some text\nSome other text"
3141 ;; With `visual-line-mode' active, move to end of visible line.
3142 ;; However, never go past ellipsis.
3144 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3146 (dotimes (i 1000) (insert "very "))
3147 (goto-char (point-min))
3151 (org-test-with-temp-text "* A short headline\nSome contents"
3156 ;; In a wide headline, with `visual-line-mode', prefer going to end
3157 ;; of visible line if tags, or end of line, are farther.
3159 (org-test-with-temp-text "* A <point>long headline"
3161 (dotimes (i 1000) (insert "very "))
3162 (goto-char (point-min))
3166 (org-test-with-temp-text "* A <point>long headline :tag:"
3168 (dotimes (i 1000) (insert "very "))
3169 (goto-char (point-min))
3172 ;; At an headline without special movement, go to end of line.
3173 ;; However, never go past ellipsis.
3175 (org-test-with-temp-text "* Headline2b :tag:\n"
3176 (let ((org-special-ctrl-a/e nil
))
3177 (and (progn (org-end-of-line) (eolp))
3178 (progn (org-end-of-line) (eolp))))))
3180 (org-test-with-temp-text "* Headline2b :tag:\n"
3181 (let ((org-special-ctrl-a/e
'(t . nil
)))
3182 (and (progn (org-end-of-line) (eolp))
3183 (progn (org-end-of-line) (eolp))))))
3185 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3187 (let ((org-special-ctrl-a/e nil
))
3189 (= 1 (line-beginning-position)))))
3190 ;; At an headline with special movement, first move before tags,
3191 ;; then at the end of line, rinse, repeat. However, never go past
3194 (org-test-with-temp-text "* Headline1 :tag:\n"
3195 (let ((org-special-ctrl-a/e t
))
3196 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3197 (progn (org-end-of-line) (eolp))
3198 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3200 (org-test-with-temp-text "* Headline1 :tag:\n"
3201 (let ((org-special-ctrl-a/e
'(nil . t
)))
3202 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3203 (progn (org-end-of-line) (eolp))
3204 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3206 (org-test-with-temp-text "* Headline1 :tag:\n"
3207 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3208 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3209 (progn (org-end-of-line) (eolp))
3210 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3212 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3214 (let ((org-special-ctrl-a/e t
))
3217 (= 1 (line-beginning-position)))))
3218 ;; At an headline, with reversed movement, first go to end of line,
3219 ;; then before tags. However, never go past ellipsis.
3221 (org-test-with-temp-text "* Headline3 :tag:\n"
3222 (let ((org-special-ctrl-a/e
'reversed
)
3223 (this-command last-command
))
3224 (and (progn (org-end-of-line) (eolp))
3225 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3227 (org-test-with-temp-text "* Headline3 :tag:\n"
3228 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3229 (this-command last-command
))
3230 (and (progn (org-end-of-line) (eolp))
3231 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3233 (org-test-with-temp-text "* Headline3 :tag:\n"
3234 (let ((org-special-ctrl-a/e
'(nil . t
))
3235 (this-command last-command
))
3236 (and (progn (org-end-of-line) (eolp))
3237 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3239 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3241 (let ((org-special-ctrl-a/e
'reversed
))
3243 (= 1 (line-beginning-position)))))
3244 ;; At a block without hidden contents.
3246 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3247 (progn (org-end-of-line) (eolp))))
3248 ;; At a block with hidden contents.
3250 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3251 (let ((org-special-ctrl-a/e t
))
3252 (org-hide-block-toggle)
3255 ;; Get past invisible characters at the end of line.
3257 (org-test-with-temp-text "[[https://orgmode.org]]"
3261 (ert-deftest test-org
/open-line
()
3262 "Test `org-open-line' specifications."
3263 ;; Call `open-line' outside of tables.
3266 (org-test-with-temp-text "Text"
3269 ;; At a table, create a row above.
3271 (equal "\n| |\n| a |"
3272 (org-test-with-temp-text "\n<point>| a |"
3275 ;; At the very first character of the buffer, also call `open-line'.
3278 (org-test-with-temp-text "| a |"
3281 ;; Narrowing does not count.
3283 (equal "Text\n| |\n| a |"
3284 (org-test-with-temp-text "Text\n<point>| a |"
3285 (narrow-to-region (point) (point-max))
3290 (ert-deftest test-org
/forward-sentence
()
3291 "Test `org-forward-sentence' specifications."
3292 ;; At the end of a table cell, move to the end of the next one.
3294 (org-test-with-temp-text "| a<point> | b |"
3295 (org-forward-sentence)
3296 (looking-at " |$")))
3297 ;; Elsewhere in a cell, move to its end.
3299 (org-test-with-temp-text "| a<point>c | b |"
3300 (org-forward-sentence)
3301 (looking-at " | b |$")))
3302 ;; Otherwise, simply call `forward-sentence'.
3304 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3305 (org-forward-sentence)
3306 (looking-at " Sentence 2.")))
3308 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3309 (org-forward-sentence)
3310 (org-forward-sentence)
3312 ;; At the end of an element, jump to the next one, without stopping
3313 ;; on blank lines in-between.
3315 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3316 (org-forward-sentence)
3318 ;; Headlines are considered to be sentences by themselves, even if
3319 ;; they do not end with a full stop.
3323 (org-test-with-temp-text "* <point>Headline\nSentence."
3324 (org-forward-sentence)
3325 (buffer-substring-no-properties (line-beginning-position) (point)))))
3327 (org-test-with-temp-text "* Headline<point>\nSentence."
3328 (org-forward-sentence)
3331 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3332 (org-forward-sentence)
3333 (and (org-at-heading-p) (eolp)))))
3335 (ert-deftest test-org
/backward-sentence
()
3336 "Test `org-backward-sentence' specifications."
3337 ;; At the beginning of a table cell, move to the beginning of the
3340 (org-test-with-temp-text "| a | <point>b |"
3341 (org-backward-sentence)
3342 (looking-at "a | b |$")))
3343 ;; Elsewhere in a cell, move to its beginning.
3345 (org-test-with-temp-text "| a | b<point>c |"
3346 (org-backward-sentence)
3347 (looking-at "bc |$")))
3348 ;; Otherwise, simply call `backward-sentence'.
3350 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3351 (org-backward-sentence)
3352 (looking-at "Sentence 2.")))
3354 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3355 (org-backward-sentence)
3356 (org-backward-sentence)
3358 ;; Make sure to hit the beginning of a sentence on the same line as
3361 (org-test-with-temp-text "- Line 1\n line <point>2."
3362 (org-backward-sentence)
3363 (looking-at "Line 1"))))
3365 (ert-deftest test-org
/forward-paragraph
()
3366 "Test `org-forward-paragraph' specifications."
3367 ;; At end of buffer, do not return an error.
3369 (org-test-with-temp-text "Paragraph"
3370 (goto-char (point-max))
3371 (org-forward-paragraph)
3375 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3376 (org-forward-paragraph)
3380 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3381 (org-forward-paragraph)
3383 ;; Do not enter elements with invisible contents.
3385 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3386 (org-hide-block-toggle)
3387 (org-forward-paragraph)
3389 ;; On an affiliated keyword, jump to the beginning of the element.
3391 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3392 (org-forward-paragraph)
3393 (looking-at "Para")))
3394 ;; On an item or a footnote definition, move to the second element
3397 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3398 (org-forward-paragraph)
3399 (looking-at " Paragraph")))
3401 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3402 (org-forward-paragraph)
3403 (looking-at "Paragraph")))
3404 ;; On an item, or a footnote definition, when the first line is
3405 ;; empty, move to the first item.
3407 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3408 (org-forward-paragraph)
3409 (looking-at " Paragraph")))
3411 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3412 (org-forward-paragraph)
3413 (looking-at "Paragraph")))
3414 ;; On a table (resp. a property drawer) do not move through table
3415 ;; rows (resp. node properties).
3417 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3418 (org-forward-paragraph)
3419 (looking-at "Paragraph")))
3421 (org-test-with-temp-text
3422 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3423 (org-forward-paragraph)
3424 (looking-at "Paragraph")))
3425 ;; On a verse or source block, stop after blank lines.
3427 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3428 (org-forward-paragraph)
3431 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3432 (org-forward-paragraph)
3433 (looking-at "L2"))))
3435 (ert-deftest test-org
/backward-paragraph
()
3436 "Test `org-backward-paragraph' specifications."
3437 ;; Do not error at beginning of buffer.
3439 (org-test-with-temp-text "Paragraph"
3440 (org-backward-paragraph)
3444 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3445 (org-backward-paragraph)
3448 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3449 (org-backward-paragraph)
3450 (looking-at-p "P2")))
3453 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3454 (org-backward-paragraph)
3455 (looking-at-p "P2")))
3456 ;; Ignore invisible elements.
3458 (org-test-with-temp-text "* H1\n P1\n* H2"
3460 (goto-char (point-max))
3462 (org-backward-paragraph)
3464 ;; On an affiliated keyword, jump to the first one.
3466 (org-test-with-temp-text
3467 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3468 (org-backward-paragraph)
3469 (looking-at-p "#\\+name")))
3470 ;; On the second element in an item or a footnote definition, jump
3471 ;; to item or the definition.
3473 (org-test-with-temp-text "- line1\n\n<point> line2"
3474 (org-backward-paragraph)
3475 (looking-at-p "- line1")))
3477 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3478 (org-backward-paragraph)
3479 (looking-at-p "\\[fn:1\\] line1")))
3480 ;; On a table (resp. a property drawer), ignore table rows
3481 ;; (resp. node properties).
3483 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3484 (org-backward-paragraph)
3487 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3488 (org-backward-paragraph)
3489 (looking-at-p ":PROPERTIES:")))
3490 ;; On a comment, example, src and verse blocks, stop before blank
3493 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3494 (org-backward-paragraph)
3495 (looking-at-p "L2")))
3497 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3498 (org-backward-paragraph)
3499 (looking-at-p "L2")))
3500 ;; In comment, example, export, src and verse blocks, stop below
3501 ;; opening line when called from within the block.
3503 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3504 (org-backward-paragraph)
3505 (looking-at-p "L1")))
3507 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3508 (org-backward-paragraph)
3509 (looking-at-p "L1")))
3510 ;; When called from the opening line itself, however, move to
3511 ;; beginning of block.
3513 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3514 (org-backward-paragraph)
3516 ;; Pathological case: on an empty heading, move to its beginning.
3518 (org-test-with-temp-text "* <point>H"
3519 (org-backward-paragraph)
3522 (ert-deftest test-org
/forward-element
()
3523 "Test `org-forward-element' specifications."
3524 ;; 1. At EOB: should error.
3525 (org-test-with-temp-text "Some text\n"
3526 (goto-char (point-max))
3527 (should-error (org-forward-element)))
3528 ;; 2. Standard move: expected to ignore blank lines.
3529 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3530 (org-forward-element)
3531 (should (looking-at (regexp-quote "Second paragraph."))))
3532 ;; 3. Headline tests.
3533 (org-test-with-temp-text "
3538 ;; 3.1. At an headline beginning: move to next headline at the
3541 (org-forward-element)
3542 (should (looking-at (regexp-quote "** Head 1.2")))
3543 ;; 3.2. At an headline beginning: move to parent headline if no
3544 ;; headline at the same level.
3546 (org-forward-element)
3547 (should (looking-at (regexp-quote "** Head 1.2"))))
3548 ;; 4. Greater element tests.
3549 (org-test-with-temp-text
3550 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3551 ;; 4.1. At a greater element: expected to skip contents.
3552 (org-forward-element)
3553 (should (looking-at (regexp-quote "Outside.")))
3554 ;; 4.2. At the end of greater element contents: expected to skip
3555 ;; to the end of the greater element.
3557 (org-forward-element)
3558 (should (looking-at (regexp-quote "Outside."))))
3560 (org-test-with-temp-text "
3574 ;; 5.1. At list top point: expected to move to the element after
3577 (org-forward-element)
3578 (should (looking-at (regexp-quote "Outside.")))
3579 ;; 5.2. Special case: at the first line of a sub-list, but not at
3580 ;; beginning of line, move to next item.
3583 (org-forward-element)
3584 (should (looking-at "- item2"))
3587 (org-forward-element)
3588 (should (looking-at " - sub2"))
3589 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3591 (org-forward-element)
3592 (should (looking-at (regexp-quote " Inner paragraph.")))
3593 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3595 (org-forward-element)
3596 (should (looking-at (regexp-quote " Inner paragraph.")))
3597 ;; 5.5. At an item: expected to move to next item, if any.
3599 (org-forward-element)
3600 (should (looking-at " - sub3"))))
3602 (ert-deftest test-org
/backward-element
()
3603 "Test `org-backward-element' specifications."
3604 ;; 1. Should error at BOB.
3605 (org-test-with-temp-text " \nParagraph."
3606 (should-error (org-backward-element)))
3607 ;; 2. Should move at BOB when called on the first element in buffer.
3609 (org-test-with-temp-text "\n#+TITLE: test"
3610 (progn (forward-line)
3611 (org-backward-element)
3613 ;; 3. Not at the beginning of an element: move at its beginning.
3614 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3617 (org-backward-element)
3618 (should (looking-at (regexp-quote "Paragraph2."))))
3619 ;; 4. Headline tests.
3620 (org-test-with-temp-text "
3625 ;; 4.1. At an headline beginning: move to previous headline at the
3628 (org-backward-element)
3629 (should (looking-at (regexp-quote "** Head 1.1")))
3630 ;; 4.2. At an headline beginning: move to parent headline if no
3631 ;; headline at the same level.
3633 (org-backward-element)
3634 (should (looking-at (regexp-quote "* Head 1")))
3635 ;; 4.3. At the first top-level headline: should error.
3637 (should-error (org-backward-element)))
3638 ;; 5. At beginning of first element inside a greater element:
3639 ;; expected to move to greater element's beginning.
3640 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3642 (org-backward-element)
3643 (should (looking-at "#\\+BEGIN_CENTER")))
3644 ;; 6. At the beginning of the first element in a section: should
3645 ;; move back to headline, if any.
3647 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3648 (progn (goto-char (point-max))
3650 (org-backward-element)
3651 (org-at-heading-p))))
3653 (org-test-with-temp-text "
3668 ;; 7.1. At beginning of sub-list: expected to move to the
3669 ;; paragraph before it.
3671 (org-backward-element)
3672 (should (looking-at "item1"))
3673 ;; 7.2. At an item in a list: expected to move at previous item.
3675 (org-backward-element)
3676 (should (looking-at " - sub2"))
3678 (org-backward-element)
3679 (should (looking-at "- item1"))
3680 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3683 (org-backward-element)
3684 (should (looking-at " - sub1"))
3686 (org-backward-element)
3687 (should (looking-at "- item1"))
3688 ;; 7.4. At blank-lines before list end: expected to move to top
3691 (org-backward-element)
3692 (should (looking-at "- item1"))))
3694 (ert-deftest test-org
/up-element
()
3695 "Test `org-up-element' specifications."
3696 ;; 1. At BOB or with no surrounding element: should error.
3697 (org-test-with-temp-text "Paragraph."
3698 (should-error (org-up-element)))
3699 (org-test-with-temp-text "* Head1\n* Head2"
3701 (should-error (org-up-element)))
3702 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3704 (should-error (org-up-element)))
3705 ;; 2. At an headline: move to parent headline.
3706 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3709 (should (looking-at "\\* Head1")))
3710 ;; 3. Inside a greater element: move to greater element beginning.
3711 (org-test-with-temp-text
3712 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3715 (should (looking-at "#\\+BEGIN_CENTER")))
3717 (org-test-with-temp-text "* Top
3724 Paragraph within sub2.
3727 ;; 4.1. Within an item: move to the item beginning.
3730 (should (looking-at " - sub2"))
3731 ;; 4.2. At an item in a sub-list: move to parent item.
3734 (should (looking-at "- item1"))
3735 ;; 4.3. At an item in top list: move to beginning of whole list.
3738 (should (looking-at "- item1"))
3739 ;; 4.4. Special case. At very top point: should move to parent of
3743 (should (looking-at "\\* Top"))))
3745 (ert-deftest test-org
/down-element
()
3746 "Test `org-down-element' specifications."
3747 ;; Error when the element hasn't got a recursive type.
3748 (org-test-with-temp-text "Paragraph."
3749 (should-error (org-down-element)))
3750 ;; Error when the element has no contents
3751 (org-test-with-temp-text "* Headline"
3752 (should-error (org-down-element)))
3753 ;; When at a plain-list, move to first item.
3754 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3757 (should (looking-at " - Item 1.1")))
3758 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3760 (should (looking-at " Item 1")))
3761 ;; When at a table, move to first row
3762 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3764 (should (looking-at " a | b |")))
3765 ;; Otherwise, move inside the greater element.
3766 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3768 (should (looking-at "Paragraph"))))
3770 (ert-deftest test-org
/drag-element-backward
()
3771 "Test `org-drag-element-backward' specifications."
3775 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3776 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3777 (org-drag-element-backward)
3781 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3782 (org-test-with-temp-text
3783 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3784 (org-drag-element-backward)
3786 ;; Preserve blank lines.
3788 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3789 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3790 (org-drag-element-backward)
3794 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3795 (org-drag-element-backward)
3796 (looking-at-p "2")))
3797 ;; Error when trying to move first element of buffer.
3799 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3800 (org-drag-element-backward))
3802 ;; Error when trying to swap nested elements.
3804 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3805 (org-drag-element-backward))
3807 ;; Error when trying to swap an headline element and a non-headline
3810 (org-test-with-temp-text "Test.\n<point>* Head 1"
3811 (org-drag-element-backward))
3813 ;; Error when called before first element.
3815 (org-test-with-temp-text "\n<point>"
3816 (org-drag-element-backward))
3818 ;; Preserve visibility of elements and their contents.
3820 (equal '((63 .
82) (26 .
48))
3821 (org-test-with-temp-text "
3829 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3830 (search-backward "- item 1")
3831 (org-drag-element-backward)
3832 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3833 (overlays-in (point-min) (point-max))))))
3834 ;; Pathological case: handle call with point in blank lines right
3835 ;; after a headline.
3837 (equal "* H2\n\n* H1\nText\n"
3838 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3839 (org-drag-element-backward)
3842 (ert-deftest test-org
/drag-element-forward
()
3843 "Test `org-drag-element-forward' specifications."
3844 ;; 1. Error when trying to move first element of buffer.
3845 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3847 (should-error (org-drag-element-forward)))
3848 ;; 2. Error when trying to swap nested elements.
3849 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3851 (should-error (org-drag-element-forward)))
3852 ;; 3. Error when trying to swap a non-headline element and an
3854 (org-test-with-temp-text "Test.\n* Head 1"
3855 (should-error (org-drag-element-forward)))
3856 ;; 4. Error when called before first element.
3858 (org-test-with-temp-text "\n"
3860 (org-drag-element-backward))
3862 ;; 5. Otherwise, swap elements, preserving column and blank lines
3863 ;; between elements.
3864 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3865 (search-forward "graph")
3866 (org-drag-element-forward)
3867 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3868 (should (looking-at " 1")))
3869 ;; 5. Preserve visibility of elements and their contents.
3870 (org-test-with-temp-text "
3878 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3879 (search-backward "#+BEGIN_CENTER")
3880 (org-drag-element-forward)
3883 '((63 .
82) (26 .
48))
3884 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3885 (overlays-in (point-min) (point-max)))))))
3887 (ert-deftest test-org
/next-block
()
3888 "Test `org-next-block' specifications."
3891 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3893 (looking-at "#\\+BEGIN_CENTER")))
3896 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3897 (let ((case-fold-search nil
))
3899 (looking-at "#\\+begin_center"))))
3900 ;; Ignore current line.
3902 (org-test-with-temp-text
3903 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3905 (looking-at "#\\+BEGIN_CENTER")))
3906 ;; Throw an error when no block is found.
3908 (org-test-with-temp-text "Paragraph"
3909 (org-next-block 1)))
3910 ;; With an argument, skip many blocks at once.
3912 (org-test-with-temp-text
3913 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3915 (looking-at "#\\+BEGIN_QUOTE")))
3916 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3918 (org-test-with-temp-text
3919 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3920 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3921 (looking-at "#\\+BEGIN_QUOTE")))
3922 ;; Optional argument is also case-insensitive.
3924 (org-test-with-temp-text
3925 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3926 (let ((case-fold-search nil
))
3927 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3928 (looking-at "#\\+begin_quote")))))
3930 (ert-deftest test-org
/insert-structure-template
()
3931 "Test `org-insert-structure-template'."
3932 ;; Test in empty buffer.
3934 (string= "#+begin_foo\n#+end_foo\n"
3935 (org-test-with-temp-text ""
3936 (org-insert-structure-template "foo")
3938 ;; Test with multiple lines in buffer.
3940 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
3941 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
3942 (transient-mark-mode 1)
3944 (org-insert-structure-template "foo")
3946 ;; Mark only the current line.
3948 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
3949 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
3950 (transient-mark-mode 1)
3951 (set-mark (point-min))
3953 (org-insert-structure-template "foo")
3955 ;; Middle of paragraph.
3957 (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
3958 (org-test-with-temp-text "p1\n<point>p2\np3"
3959 (set-mark (line-beginning-position))
3962 (org-insert-structure-template "foo")
3964 ;; Test with text in buffer, no region, no final newline.
3966 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
3967 (org-test-with-temp-text "I'm a paragraph."
3969 (org-insert-structure-template "foo")
3971 ;; Test with text in buffer and region set.
3973 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
3974 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
3976 (goto-char (point-max))
3977 (org-insert-structure-template "foo")
3979 ;; Test with example escaping.
3981 (string= "#+begin_example\n,* Heading\n#+end_example\n"
3982 (org-test-with-temp-text "* Heading"
3984 (org-insert-structure-template "example")
3986 ;; Test with indentation.
3988 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
3989 (org-test-with-temp-text " This is a paragraph"
3991 (org-insert-structure-template "foo")
3994 (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
3995 (org-test-with-temp-text " Line 1\n Line2"
3997 (org-insert-structure-template "foo")
3999 ;; Test point location.
4001 (string= "#+begin_foo\n"
4002 (org-test-with-temp-text ""
4003 (org-insert-structure-template "foo")
4004 (buffer-substring (point-min) (point)))))
4006 (string= "#+begin_src "
4007 (org-test-with-temp-text ""
4008 (org-insert-structure-template "src")
4009 (buffer-substring (point-min) (point))))))
4011 (ert-deftest test-org
/previous-block
()
4012 "Test `org-previous-block' specifications."
4015 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4016 (org-previous-block 1)
4017 (looking-at "#\\+BEGIN_CENTER")))
4020 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4021 (let ((case-fold-search nil
))
4022 (org-previous-block 1)
4023 (looking-at "#\\+begin_center"))))
4024 ;; Ignore current line.
4026 (org-test-with-temp-text
4027 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4028 (org-previous-block 1)
4029 (looking-at "#\\+BEGIN_QUOTE")))
4030 ;; Throw an error when no block is found.
4032 (org-test-with-temp-text "Paragraph<point>"
4033 (org-previous-block 1)))
4034 ;; With an argument, skip many blocks at once.
4036 (org-test-with-temp-text
4037 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4038 (org-previous-block 2)
4039 (looking-at "#\\+BEGIN_CENTER")))
4040 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4042 (org-test-with-temp-text
4043 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4044 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4045 (looking-at "#\\+BEGIN_QUOTE")))
4046 ;; Optional argument is also case-insensitive.
4048 (org-test-with-temp-text
4049 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4050 (let ((case-fold-search nil
))
4051 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4052 (looking-at "#\\+begin_quote")))))
4055 ;;; Outline structure
4057 (ert-deftest test-org
/demote
()
4058 "Test `org-demote' specifications."
4059 ;; Add correct number of stars according to `org-odd-levels-only'.
4062 (org-test-with-temp-text "* H"
4063 (let ((org-odd-levels-only nil
)) (org-demote))
4064 (org-current-level))))
4067 (org-test-with-temp-text "* H"
4068 (let ((org-odd-levels-only t
)) (org-demote))
4069 (org-current-level))))
4070 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4072 (org-test-with-temp-text "* H :tag:"
4073 (let ((org-tags-column 10)
4074 (org-auto-align-tags t
)
4075 (org-odd-levels-only nil
))
4077 (org-move-to-column 10)
4078 (looking-at-p ":tag:$")))
4080 (org-test-with-temp-text "* H :tag:"
4081 (let ((org-tags-column 10)
4082 (org-auto-align-tags nil
)
4083 (org-odd-levels-only nil
))
4085 (org-move-to-column 10)
4086 (looking-at-p ":tag:$")))
4087 ;; When `org-adapt-indentation' is non-nil, always indent planning
4088 ;; info and property drawers accordingly.
4091 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4092 (let ((org-odd-levels-only nil
)
4093 (org-adapt-indentation t
))
4096 (org-get-indentation))))
4099 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4100 (let ((org-odd-levels-only nil
)
4101 (org-adapt-indentation t
))
4104 (org-get-indentation))))
4107 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4108 (let ((org-odd-levels-only nil
)
4109 (org-adapt-indentation nil
))
4112 (org-get-indentation))))
4113 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4114 ;; section accordingly. Ignore, however, footnote definitions and
4115 ;; inlinetasks boundaries.
4118 (org-test-with-temp-text "* H\n Paragraph"
4119 (let ((org-odd-levels-only nil
)
4120 (org-adapt-indentation t
))
4123 (org-get-indentation))))
4126 (org-test-with-temp-text "* H\n Paragraph"
4127 (let ((org-odd-levels-only nil
)
4128 (org-adapt-indentation nil
))
4131 (org-get-indentation))))
4134 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4135 (let ((org-odd-levels-only nil
)
4136 (org-adapt-indentation t
))
4138 (goto-char (point-max))
4139 (org-get-indentation))))
4142 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4143 (let ((org-odd-levels-only nil
)
4144 (org-adapt-indentation t
))
4146 (goto-char (point-max))
4147 (org-get-indentation))))
4148 (when (featurep 'org-inlinetask
)
4151 (let ((org-inlinetask-min-level 5)
4152 (org-adapt-indentation t
))
4153 (org-test-with-temp-text "* H\n***** I\n***** END"
4156 (org-get-indentation))))))
4157 (when (featurep 'org-inlinetask
)
4160 (let ((org-inlinetask-min-level 5)
4161 (org-adapt-indentation t
))
4162 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4165 (org-get-indentation))))))
4166 ;; Ignore contents of source blocks or example blocks when
4167 ;; indentation should be preserved (through
4168 ;; `org-src-preserve-indentation' or "-i" flag).
4171 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4172 (let ((org-adapt-indentation t
)
4173 (org-src-preserve-indentation nil
))
4176 (org-get-indentation))))
4179 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4180 (let ((org-adapt-indentation t
)
4181 (org-src-preserve-indentation t
))
4184 (org-get-indentation))))
4187 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4188 (let ((org-adapt-indentation t
)
4189 (org-src-preserve-indentation t
))
4192 (org-get-indentation))))
4195 (org-test-with-temp-text
4196 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4197 (let ((org-adapt-indentation t
)
4198 (org-src-preserve-indentation nil
))
4201 (org-get-indentation)))))
4203 (ert-deftest test-org
/promote
()
4204 "Test `org-promote' specifications."
4205 ;; Return an error if headline is to be promoted to level 0, unless
4206 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4207 ;; headline becomes a comment.
4209 (org-test-with-temp-text "* H"
4210 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4213 (org-test-with-temp-text "* H"
4214 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4216 ;; Remove correct number of stars according to
4217 ;; `org-odd-levels-only'.
4220 (org-test-with-temp-text "*** H"
4221 (let ((org-odd-levels-only nil
)) (org-promote))
4222 (org-current-level))))
4225 (org-test-with-temp-text "*** H"
4226 (let ((org-odd-levels-only t
)) (org-promote))
4227 (org-current-level))))
4228 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4230 (org-test-with-temp-text "** H :tag:"
4231 (let ((org-tags-column 10)
4232 (org-auto-align-tags t
)
4233 (org-odd-levels-only nil
))
4235 (org-move-to-column 10)
4236 (looking-at-p ":tag:$")))
4238 (org-test-with-temp-text "** H :tag:"
4239 (let ((org-tags-column 10)
4240 (org-auto-align-tags nil
)
4241 (org-odd-levels-only nil
))
4243 (org-move-to-column 10)
4244 (looking-at-p ":tag:$")))
4245 ;; When `org-adapt-indentation' is non-nil, always indent planning
4246 ;; info and property drawers.
4249 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4250 (let ((org-odd-levels-only nil
)
4251 (org-adapt-indentation t
))
4254 (org-get-indentation))))
4257 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4258 (let ((org-odd-levels-only nil
)
4259 (org-adapt-indentation t
))
4262 (org-get-indentation))))
4265 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4266 (let ((org-odd-levels-only nil
)
4267 (org-adapt-indentation nil
))
4270 (org-get-indentation))))
4271 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4272 ;; section accordingly. Ignore, however, footnote definitions and
4273 ;; inlinetasks boundaries.
4276 (org-test-with-temp-text "** H\n Paragraph"
4277 (let ((org-odd-levels-only nil
)
4278 (org-adapt-indentation t
))
4281 (org-get-indentation))))
4284 (org-test-with-temp-text "** H\n Paragraph"
4285 (let ((org-odd-levels-only nil
)
4286 (org-adapt-indentation nil
))
4289 (org-get-indentation))))
4292 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4293 (let ((org-odd-levels-only nil
)
4294 (org-adapt-indentation t
))
4297 (org-get-indentation))))
4298 (when (featurep 'org-inlinetask
)
4301 (let ((org-inlinetask-min-level 5)
4302 (org-adapt-indentation t
))
4303 (org-test-with-temp-text "** H\n***** I\n***** END"
4306 (org-get-indentation))))))
4307 (when (featurep 'org-inlinetask
)
4310 (let ((org-inlinetask-min-level 5)
4311 (org-adapt-indentation t
))
4312 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4315 (org-get-indentation))))))
4316 ;; Give up shifting if it would break document's structure
4320 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4321 (let ((org-odd-levels-only nil
)
4322 (org-adapt-indentation t
))
4325 (org-get-indentation))))
4328 (org-test-with-temp-text "** H\n Paragraph\n * list."
4329 (let ((org-odd-levels-only nil
)
4330 (org-adapt-indentation t
))
4333 (org-get-indentation))))
4334 ;; Ignore contents of source blocks or example blocks when
4335 ;; indentation should be preserved (through
4336 ;; `org-src-preserve-indentation' or "-i" flag).
4339 (org-test-with-temp-text
4340 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4341 (let ((org-adapt-indentation t
)
4342 (org-src-preserve-indentation nil
)
4343 (org-odd-levels-only nil
))
4346 (org-get-indentation))))
4349 (org-test-with-temp-text
4350 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4351 (let ((org-adapt-indentation t
)
4352 (org-src-preserve-indentation t
)
4353 (org-odd-levels-only nil
))
4356 (org-get-indentation))))
4359 (org-test-with-temp-text
4360 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4361 (let ((org-adapt-indentation t
)
4362 (org-src-preserve-indentation t
)
4363 (org-odd-levels-only nil
))
4366 (org-get-indentation))))
4369 (org-test-with-temp-text
4370 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4371 (let ((org-adapt-indentation t
)
4372 (org-src-preserve-indentation nil
)
4373 (org-odd-levels-only nil
))
4376 (org-get-indentation)))))
4378 (ert-deftest test-org
/org-get-valid-level
()
4379 "Test function `org-get-valid-level' specifications."
4380 (let ((org-odd-levels-only nil
))
4381 (should (equal 1 (org-get-valid-level 0 0)))
4382 (should (equal 1 (org-get-valid-level 0 1)))
4383 (should (equal 2 (org-get-valid-level 0 2)))
4384 (should (equal 3 (org-get-valid-level 0 3)))
4385 (should (equal 1 (org-get-valid-level 1 0)))
4386 (should (equal 2 (org-get-valid-level 1 1)))
4387 (should (equal 23 (org-get-valid-level 1 22)))
4388 (should (equal 1 (org-get-valid-level 1 -
1)))
4389 (should (equal 1 (org-get-valid-level 2 -
1))))
4390 (let ((org-odd-levels-only t
))
4391 (should (equal 1 (org-get-valid-level 0 0)))
4392 (should (equal 1 (org-get-valid-level 0 1)))
4393 (should (equal 3 (org-get-valid-level 0 2)))
4394 (should (equal 5 (org-get-valid-level 0 3)))
4395 (should (equal 1 (org-get-valid-level 1 0)))
4396 (should (equal 3 (org-get-valid-level 1 1)))
4397 (should (equal 3 (org-get-valid-level 2 1)))
4398 (should (equal 5 (org-get-valid-level 3 1)))
4399 (should (equal 5 (org-get-valid-level 4 1)))
4400 (should (equal 43 (org-get-valid-level 1 21)))
4401 (should (equal 1 (org-get-valid-level 1 -
1)))
4402 (should (equal 1 (org-get-valid-level 2 -
1)))
4403 (should (equal 1 (org-get-valid-level 3 -
1)))
4404 (should (equal 3 (org-get-valid-level 4 -
1)))
4405 (should (equal 3 (org-get-valid-level 5 -
1)))))
4410 (ert-deftest test-org
/at-planning-p
()
4411 "Test `org-at-planning-p' specifications."
4414 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4415 (org-at-planning-p)))
4417 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4418 (org-at-planning-p)))
4419 ;; Correctly find planning attached to inlinetasks.
4420 (when (featurep 'org-inlinetask
)
4422 (org-test-with-temp-text
4423 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4424 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4426 (org-test-with-temp-text
4427 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4428 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4430 (org-test-with-temp-text
4431 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4432 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4434 (org-test-with-temp-text
4435 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4436 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4438 (ert-deftest test-org
/add-planning-info
()
4439 "Test `org-add-planning-info'."
4440 ;; Create deadline when `org-adapt-indentation' is non-nil.
4442 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4443 (org-test-with-temp-text "* H\nParagraph<point>"
4444 (let ((org-adapt-indentation t
))
4445 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4446 (replace-regexp-in-string
4447 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4449 ;; Create deadline when `org-adapt-indentation' is nil.
4451 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4452 (org-test-with-temp-text "* H\nParagraph<point>"
4453 (let ((org-adapt-indentation nil
))
4454 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4455 (replace-regexp-in-string
4456 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4458 ;; Update deadline when `org-adapt-indentation' is non-nil.
4460 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4461 (org-test-with-temp-text "\
4463 DEADLINE: <2015-06-24 Wed>
4465 (let ((org-adapt-indentation t
))
4466 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4467 (replace-regexp-in-string
4468 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4470 ;; Update deadline when `org-adapt-indentation' is nil.
4472 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4473 (org-test-with-temp-text "\
4475 DEADLINE: <2015-06-24 Wed>
4477 (let ((org-adapt-indentation nil
))
4478 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4479 (replace-regexp-in-string
4480 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4482 ;; Schedule when `org-adapt-indentation' is non-nil.
4484 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4485 (org-test-with-temp-text "* H\nParagraph<point>"
4486 (let ((org-adapt-indentation t
))
4487 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4488 (replace-regexp-in-string
4489 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4491 ;; Schedule when `org-adapt-indentation' is nil.
4493 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4494 (org-test-with-temp-text "* H\nParagraph<point>"
4495 (let ((org-adapt-indentation nil
))
4496 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4497 (replace-regexp-in-string
4498 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4500 ;; Add deadline when scheduled.
4504 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4506 (org-test-with-temp-text "\
4508 SCHEDULED: <2015-06-24 Wed>
4510 (let ((org-adapt-indentation t
))
4511 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4512 (replace-regexp-in-string
4513 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4515 ;; Remove middle entry.
4519 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4521 (org-test-with-temp-text "\
4523 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4525 (let ((org-adapt-indentation t
))
4526 (org-add-planning-info nil nil
'deadline
))
4527 (replace-regexp-in-string
4528 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4530 ;; Remove last entry and then middle entry (order should not
4535 CLOSED: [2015-06-24]
4537 (org-test-with-temp-text "\
4539 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4541 (let ((org-adapt-indentation t
))
4542 (org-add-planning-info nil nil
'scheduled
'deadline
))
4543 (replace-regexp-in-string
4544 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4546 ;; Remove closed when `org-adapt-indentation' is non-nil.
4548 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4549 (org-test-with-temp-text "\
4551 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4553 (let ((org-adapt-indentation t
))
4554 (org-add-planning-info nil nil
'closed
))
4555 (replace-regexp-in-string
4556 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4559 (equal "* H\n Paragraph"
4560 (org-test-with-temp-text "\
4562 CLOSED: [2015-06-25 Thu]
4564 (let ((org-adapt-indentation t
))
4565 (org-add-planning-info nil nil
'closed
))
4566 (replace-regexp-in-string
4567 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4569 ;; Remove closed when `org-adapt-indentation' is nil.
4571 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4572 (org-test-with-temp-text "\
4574 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4576 (let ((org-adapt-indentation nil
))
4577 (org-add-planning-info nil nil
'closed
))
4578 (replace-regexp-in-string
4579 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4582 (equal "* H\nParagraph"
4583 (org-test-with-temp-text "\
4585 CLOSED: [2015-06-25 Thu]
4587 (let ((org-adapt-indentation nil
))
4588 (org-add-planning-info nil nil
'closed
))
4589 (replace-regexp-in-string
4590 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4592 ;; Remove closed entry and delete empty line.
4597 (org-test-with-temp-text "\
4599 CLOSED: [2015-06-24 Wed]
4601 (let ((org-adapt-indentation t
))
4602 (org-add-planning-info nil nil
'closed
))
4603 (replace-regexp-in-string
4604 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4606 ;; Remove one entry and update another.
4608 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4609 (org-test-with-temp-text "\
4611 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4613 (let ((org-adapt-indentation t
))
4614 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4615 (replace-regexp-in-string
4616 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4619 (ert-deftest test-org
/deadline
()
4620 "Test `org-deadline' specifications."
4621 ;; Insert a new value or replace existing one.
4623 (equal "* H\nDEADLINE: <2012-03-29>\n"
4624 (org-test-with-temp-text "* H"
4625 (let ((org-adapt-indentation nil
)
4626 (org-last-inserted-timestamp nil
))
4627 (org-deadline nil
"<2012-03-29 Tue>"))
4628 (replace-regexp-in-string
4629 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4632 (equal "* H\nDEADLINE: <2014-03-04>"
4633 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4634 (let ((org-adapt-indentation nil
)
4635 (org-last-inserted-timestamp nil
))
4636 (org-deadline nil
"<2014-03-04 Thu>"))
4637 (replace-regexp-in-string
4638 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4640 ;; Accept delta time, e.g., "+2d".
4642 (equal "* H\nDEADLINE: <2015-03-04>\n"
4643 (org-test-at-time "2014-03-04"
4644 (org-test-with-temp-text "* H"
4645 (let ((org-adapt-indentation nil
)
4646 (org-last-inserted-timestamp nil
))
4647 (org-deadline nil
"+1y"))
4648 (replace-regexp-in-string
4649 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4650 ;; Preserve repeater.
4652 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4653 (org-test-with-temp-text "* H"
4654 (let ((org-adapt-indentation nil
)
4655 (org-last-inserted-timestamp nil
))
4656 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4657 (replace-regexp-in-string
4658 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4659 ;; Remove CLOSED keyword, if any.
4661 (equal "* H\nDEADLINE: <2012-03-29>"
4662 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4663 (let ((org-adapt-indentation nil
)
4664 (org-last-inserted-timestamp nil
))
4665 (org-deadline nil
"<2012-03-29 Tue>"))
4666 (replace-regexp-in-string
4667 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4668 ;; With C-u argument, remove DEADLINE keyword.
4671 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4672 (let ((org-adapt-indentation nil
)
4673 (org-last-inserted-timestamp nil
))
4674 (org-deadline '(4)))
4678 (org-test-with-temp-text "* H"
4679 (let ((org-adapt-indentation nil
)
4680 (org-last-inserted-timestamp nil
))
4681 (org-deadline '(4)))
4683 ;; With C-u C-u argument, prompt for a delay cookie.
4685 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4686 (cl-letf (((symbol-function 'org-read-date
)
4687 (lambda (&rest args
)
4688 (apply #'encode-time
4689 (org-parse-time-string "2014-03-04")))))
4690 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4691 (let ((org-adapt-indentation nil
)
4692 (org-last-inserted-timestamp nil
))
4693 (org-deadline '(16)))
4696 (cl-letf (((symbol-function 'org-read-date
)
4697 (lambda (&rest args
)
4698 (apply #'encode-time
4699 (org-parse-time-string "2014-03-04")))))
4700 (org-test-with-temp-text "* H"
4701 (let ((org-adapt-indentation nil
)
4702 (org-last-inserted-timestamp nil
))
4703 (org-deadline '(16)))
4705 ;; When a region is active and
4706 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4707 ;; same value in all headlines in region.
4709 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4710 (org-test-with-temp-text "* H1\n* H2"
4711 (let ((org-adapt-indentation nil
)
4712 (org-last-inserted-timestamp nil
)
4713 (org-loop-over-headlines-in-active-region t
))
4714 (transient-mark-mode 1)
4715 (push-mark (point) t t
)
4716 (goto-char (point-max))
4717 (org-deadline nil
"2012-03-29"))
4718 (replace-regexp-in-string
4719 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4721 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4722 (org-test-with-temp-text "* H1\n* H2"
4723 (let ((org-adapt-indentation nil
)
4724 (org-last-inserted-timestamp nil
)
4725 (org-loop-over-headlines-in-active-region nil
))
4726 (transient-mark-mode 1)
4727 (push-mark (point) t t
)
4728 (goto-char (point-max))
4729 (org-deadline nil
"2012-03-29"))
4730 (replace-regexp-in-string
4731 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4733 (ert-deftest test-org
/schedule
()
4734 "Test `org-schedule' specifications."
4735 ;; Insert a new value or replace existing one.
4737 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4738 (org-test-with-temp-text "* H"
4739 (let ((org-adapt-indentation nil
)
4740 (org-last-inserted-timestamp nil
))
4741 (org-schedule nil
"<2012-03-29 Tue>"))
4742 (replace-regexp-in-string
4743 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4746 (equal "* H\nSCHEDULED: <2014-03-04>"
4747 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4748 (let ((org-adapt-indentation nil
)
4749 (org-last-inserted-timestamp nil
))
4750 (org-schedule nil
"<2014-03-04 Thu>"))
4751 (replace-regexp-in-string
4752 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4754 ;; Accept delta time, e.g., "+2d".
4756 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4757 (org-test-at-time "2014-03-04"
4758 (org-test-with-temp-text "* H"
4759 (let ((org-adapt-indentation nil
)
4760 (org-last-inserted-timestamp nil
))
4761 (org-schedule nil
"+1y"))
4762 (replace-regexp-in-string
4763 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4764 ;; Preserve repeater.
4766 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4767 (org-test-with-temp-text "* H"
4768 (let ((org-adapt-indentation nil
)
4769 (org-last-inserted-timestamp nil
))
4770 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4771 (replace-regexp-in-string
4772 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4773 ;; Remove CLOSED keyword, if any.
4775 (equal "* H\nSCHEDULED: <2012-03-29>"
4776 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4777 (let ((org-adapt-indentation nil
)
4778 (org-last-inserted-timestamp nil
))
4779 (org-schedule nil
"<2012-03-29 Tue>"))
4780 (replace-regexp-in-string
4781 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4782 ;; With C-u argument, remove SCHEDULED keyword.
4785 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4786 (let ((org-adapt-indentation nil
)
4787 (org-last-inserted-timestamp nil
))
4788 (org-schedule '(4)))
4792 (org-test-with-temp-text "* H"
4793 (let ((org-adapt-indentation nil
)
4794 (org-last-inserted-timestamp nil
))
4795 (org-schedule '(4)))
4797 ;; With C-u C-u argument, prompt for a delay cookie.
4799 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4800 (cl-letf (((symbol-function 'org-read-date
)
4801 (lambda (&rest args
)
4802 (apply #'encode-time
4803 (org-parse-time-string "2014-03-04")))))
4804 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4805 (let ((org-adapt-indentation nil
)
4806 (org-last-inserted-timestamp nil
))
4807 (org-schedule '(16)))
4810 (cl-letf (((symbol-function 'org-read-date
)
4811 (lambda (&rest args
)
4812 (apply #'encode-time
4813 (org-parse-time-string "2014-03-04")))))
4814 (org-test-with-temp-text "* H"
4815 (let ((org-adapt-indentation nil
)
4816 (org-last-inserted-timestamp nil
))
4817 (org-schedule '(16)))
4819 ;; When a region is active and
4820 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4821 ;; same value in all headlines in region.
4823 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4824 (org-test-with-temp-text "* H1\n* H2"
4825 (let ((org-adapt-indentation nil
)
4826 (org-last-inserted-timestamp nil
)
4827 (org-loop-over-headlines-in-active-region t
))
4828 (transient-mark-mode 1)
4829 (push-mark (point) t t
)
4830 (goto-char (point-max))
4831 (org-schedule nil
"2012-03-29"))
4832 (replace-regexp-in-string
4833 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4835 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4836 (org-test-with-temp-text "* H1\n* H2"
4837 (let ((org-adapt-indentation nil
)
4838 (org-last-inserted-timestamp nil
)
4839 (org-loop-over-headlines-in-active-region nil
))
4840 (transient-mark-mode 1)
4841 (push-mark (point) t t
)
4842 (goto-char (point-max))
4843 (org-schedule nil
"2012-03-29"))
4844 (replace-regexp-in-string
4845 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4847 ;; check if a repeater survives re-scheduling.
4849 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4850 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4851 (let ((org-adapt-indentation nil
)
4852 (org-last-inserted-timestamp nil
))
4853 (org-schedule nil
"2017-02-01"))
4859 (ert-deftest test-org
/buffer-property-keys
()
4860 "Test `org-buffer-property-keys' specifications."
4861 ;; Retrieve properties accross siblings.
4864 (org-test-with-temp-text "
4873 (org-buffer-property-keys))))
4874 ;; Retrieve properties accross children.
4877 (org-test-with-temp-text "
4886 (org-buffer-property-keys))))
4887 ;; Retrieve muliple properties in the same drawer.
4890 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4891 (org-buffer-property-keys))))
4892 ;; Ignore extension symbol in property name.
4895 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4896 (org-buffer-property-keys))))
4897 ;; With non-nil COLUMNS, extract property names from columns.
4900 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4901 (org-buffer-property-keys nil nil t
))))
4903 (equal '("A" "B" "COLUMNS")
4904 (org-test-with-temp-text
4905 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4906 (org-buffer-property-keys nil nil t
))))
4907 ;; In COLUMNS, ignore title and summary-type.
4910 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4911 (org-buffer-property-keys nil nil t
))))
4914 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4915 (org-buffer-property-keys nil nil t
))))
4918 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4919 (org-buffer-property-keys nil nil t
)))))
4921 (ert-deftest test-org
/property-values
()
4922 "Test `org-property-values' specifications."
4926 (org-test-with-temp-text
4927 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4928 (org-property-values "A"))))
4929 ;; Ignore empty values.
4931 (org-test-with-temp-text
4932 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4933 (org-property-values "A")))
4934 ;; Take into consideration extended values.
4937 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4938 (org-property-values "A")))))
4940 (ert-deftest test-org
/find-property
()
4941 "Test `org-find-property' specifications."
4945 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4946 (org-find-property "prop"))))
4947 ;; Ignore false positives.
4950 (org-test-with-temp-text
4951 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4952 (org-find-property "A"))))
4953 ;; Return first entry found in buffer.
4956 (org-test-with-temp-text
4957 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4958 (org-find-property "A"))))
4959 ;; Only search visible part of the buffer.
4962 (org-test-with-temp-text
4963 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4964 (org-narrow-to-subtree)
4965 (org-find-property "A"))))
4966 ;; With optional argument, only find entries with a specific value.
4968 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4969 (org-find-property "A" "2")))
4972 (org-test-with-temp-text
4973 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4974 (org-find-property "A" "2"))))
4975 ;; Use "nil" for explicit nil values.
4978 (org-test-with-temp-text
4979 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4980 (org-find-property "A" "nil")))))
4982 (ert-deftest test-org
/entry-delete
()
4983 "Test `org-entry-delete' specifications."
4987 " *:PROPERTIES:\n *:B: +2\n *:END:"
4988 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4989 (org-entry-delete (point) "A")
4991 ;; Also remove accumulated properties.
4995 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4996 (org-entry-delete (point) "A")
4998 ;; When last property is removed, remove the property drawer.
5002 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5003 (org-entry-delete (point) "A")
5005 ;; Return a non-nil value when some property was removed.
5007 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5008 (org-entry-delete (point) "A")))
5010 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5011 (org-entry-delete (point) "C")))
5012 ;; Special properties cannot be located in a drawer. Allow to
5013 ;; remove them anyway, in case of user error.
5015 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5016 (org-entry-delete (point) "SCHEDULED"))))
5018 (ert-deftest test-org
/entry-get
()
5019 "Test `org-entry-get' specifications."
5023 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5024 (org-entry-get (point) "A"))))
5028 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5029 (org-entry-get (point) "a"))))
5030 ;; Handle extended values, both before and after base value.
5033 (org-test-with-temp-text
5034 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5035 (org-entry-get (point) "A"))))
5036 ;; Empty values are returned as the empty string.
5039 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5040 (org-entry-get (point) "A"))))
5041 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5042 ;; otherwise, return nil.
5044 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5045 (org-entry-get (point) "A")))
5048 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5049 (org-entry-get (point) "A" nil t
))))
5050 ;; Return nil when no property is found, independently on the
5051 ;; LITERAL-NIL argument.
5053 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5054 (org-entry-get (point) "B")))
5056 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5057 (org-entry-get (point) "B" nil t
)))
5058 ;; Handle inheritance, when allowed. Include extended values and
5059 ;; possibly global values.
5063 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5064 (org-entry-get (point) "A" t
))))
5068 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5069 (let ((org-use-property-inheritance t
))
5070 (org-entry-get (point) "A" 'selective
)))))
5072 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5073 (let ((org-use-property-inheritance nil
))
5074 (org-entry-get (point) "A" 'selective
))))
5078 (org-test-with-temp-text
5079 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5080 (org-entry-get (point-max) "A" t
))))
5083 (org-test-with-temp-text
5084 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5086 (org-entry-get (point-max) "A" t
))))
5089 (org-test-with-temp-text
5090 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5092 (org-entry-get (point-max) "A" t
)))))
5094 (ert-deftest test-org
/entry-properties
()
5095 "Test `org-entry-properties' specifications."
5096 ;; Get "ITEM" property.
5099 (org-test-with-temp-text "* TODO H"
5100 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5103 (org-test-with-temp-text "* TODO H"
5104 (cdr (assoc "ITEM" (org-entry-properties))))))
5105 ;; Get "TODO" property. TODO keywords are case sensitive.
5108 (org-test-with-temp-text "* TODO H"
5109 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5112 (org-test-with-temp-text "* TODO H"
5113 (cdr (assoc "TODO" (org-entry-properties))))))
5115 (org-test-with-temp-text "* H"
5116 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5118 (org-test-with-temp-text "* todo H"
5119 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5120 ;; Get "PRIORITY" property.
5123 (org-test-with-temp-text "* [#A] H"
5124 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5127 (org-test-with-temp-text "* [#A] H"
5128 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5130 (equal (char-to-string org-default-priority
)
5131 (org-test-with-temp-text "* H"
5132 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5133 ;; Get "FILE" property.
5135 (org-test-with-temp-text-in-file "* H\nParagraph"
5136 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5137 (buffer-file-name))))
5139 (org-test-with-temp-text-in-file "* H\nParagraph"
5140 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5141 (buffer-file-name))))
5143 (org-test-with-temp-text "* H\nParagraph"
5144 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5145 ;; Get "TAGS" property.
5147 (equal ":tag1:tag2:"
5148 (org-test-with-temp-text "* H :tag1:tag2:"
5149 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5151 (equal ":tag1:tag2:"
5152 (org-test-with-temp-text "* H :tag1:tag2:"
5153 (cdr (assoc "TAGS" (org-entry-properties))))))
5155 (org-test-with-temp-text "* H"
5156 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5157 ;; Get "ALLTAGS" property.
5159 (equal ":tag1:tag2:"
5160 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5161 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5163 (equal ":tag1:tag2:"
5164 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5165 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5167 (org-test-with-temp-text "* H"
5168 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5169 ;; Get "BLOCKED" property.
5172 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5173 (let ((org-enforce-todo-dependencies t
)
5175 '(org-block-todo-from-children-or-siblings-or-parent)))
5176 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5179 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5180 (let ((org-enforce-todo-dependencies t
)
5182 '(org-block-todo-from-children-or-siblings-or-parent)))
5183 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5184 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5188 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5189 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5193 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5194 (cdr (assoc "CLOSED" (org-entry-properties))))))
5196 (org-test-with-temp-text "* H"
5197 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5201 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5202 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5206 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5207 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5209 (org-test-with-temp-text "* H"
5210 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5214 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5215 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5219 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5220 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5222 (org-test-with-temp-text "* H"
5223 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5227 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5228 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5231 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5232 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5235 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5236 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5239 (org-test-with-temp-text
5240 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5242 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5243 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5244 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5246 (equal "<2012-03-29 thu.>"
5247 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5248 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5250 (equal "[2012-03-29 thu.]"
5251 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5252 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5254 (equal "<2012-03-29 thu.>"
5255 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5256 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5258 (equal "[2014-03-04 tue.]"
5259 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5260 (cdr (assoc "TIMESTAMP_IA"
5261 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5263 (equal "<2012-03-29 thu.>"
5264 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5265 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5266 ;; Get standard properties.
5269 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5270 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5271 ;; Handle extended properties.
5274 (org-test-with-temp-text
5275 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5276 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5279 (org-test-with-temp-text
5280 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5281 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5282 ;; Ignore forbidden (special) properties.
5284 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5285 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5287 (ert-deftest test-org
/entry-put
()
5288 "Test `org-entry-put' specifications."
5289 ;; Error when not a string or nil.
5291 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5292 (org-entry-put 1 "test" 2)))
5293 ;; Error when property name is invalid.
5295 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5296 (org-entry-put 1 "no space" "value")))
5298 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5299 (org-entry-put 1 "" "value")))
5300 ;; Set "TODO" property.
5302 (string-match (regexp-quote " TODO H")
5303 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5304 (org-entry-put (point) "TODO" "TODO")
5307 (string-match (regexp-quote "* H")
5308 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5309 (org-entry-put (point) "TODO" nil
)
5311 ;; Set "PRIORITY" property.
5314 (org-test-with-temp-text "* [#B] H"
5315 (org-entry-put (point) "PRIORITY" "A")
5319 (org-test-with-temp-text "* [#B] H"
5320 (org-entry-put (point) "PRIORITY" nil
)
5322 ;; Set "SCHEDULED" property.
5324 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5325 (org-test-with-temp-text "* H"
5326 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5330 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5331 (org-entry-put (point) "SCHEDULED" nil
)
5334 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5335 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5336 (org-entry-put (point) "SCHEDULED" "earlier")
5339 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5340 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5341 (org-entry-put (point) "SCHEDULED" "later")
5343 ;; Set "DEADLINE" property.
5345 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5346 (org-test-with-temp-text "* H"
5347 (org-entry-put (point) "DEADLINE" "2014-03-04")
5351 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5352 (org-entry-put (point) "DEADLINE" nil
)
5355 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5356 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5357 (org-entry-put (point) "DEADLINE" "earlier")
5360 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5361 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5362 (org-entry-put (point) "DEADLINE" "later")
5364 ;; Set "CATEGORY" property
5366 (string-match "^ *:CATEGORY: cat"
5367 (org-test-with-temp-text "* H"
5368 (org-entry-put (point) "CATEGORY" "cat")
5370 ;; Regular properties, with or without pre-existing drawer.
5372 (string-match "^ *:A: +2$"
5373 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5374 (org-entry-put (point) "A" "2")
5377 (string-match "^ *:A: +1$"
5378 (org-test-with-temp-text "* H"
5379 (org-entry-put (point) "A" "1")
5381 ;; Special case: two consecutive headlines.
5383 (string-match "\\* A\n *:PROPERTIES:"
5384 (org-test-with-temp-text "* A\n** B"
5385 (org-entry-put (point) "A" "1")
5388 (ert-deftest test-org
/refresh-properties
()
5389 "Test `org-refresh-properties' specifications."
5392 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5393 (org-refresh-properties "A" 'org-test
)
5394 (get-text-property (point) 'org-test
))))
5396 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5397 (org-refresh-properties "B" 'org-test
)
5398 (get-text-property (point) 'org-test
)))
5399 ;; Handle properties only defined with extension syntax, i.e.,
5403 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5404 (org-refresh-properties "A" 'org-test
)
5405 (get-text-property (point) 'org-test
))))
5406 ;; When property is inherited, add text property to the whole
5410 (org-test-with-temp-text
5411 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5412 (let ((org-use-property-inheritance t
))
5413 (org-refresh-properties "A" 'org-test
))
5414 (get-text-property (point) 'org-test
))))
5415 ;; When property is inherited, use global value across the whole
5416 ;; buffer. However local values have precedence.
5419 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5421 (let ((org-use-property-inheritance nil
))
5422 (org-refresh-properties "A" 'org-test
))
5423 (get-text-property (point) 'org-test
))))
5426 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5428 (let ((org-use-property-inheritance t
))
5429 (org-refresh-properties "A" 'org-test
))
5430 (get-text-property (point) 'org-test
))))
5433 (org-test-with-temp-text
5434 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5436 (let ((org-use-property-inheritance t
))
5437 (org-refresh-properties "A" 'org-test
))
5438 (get-text-property (point) 'org-test
)))))
5443 (ert-deftest test-org
/refile-get-targets
()
5444 "Test `org-refile-get-targets' specifications."
5445 ;; :maxlevel includes all headings above specified value.
5447 (equal '("H1" "H2" "H3")
5448 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5449 (let ((org-refile-use-outline-path nil
)
5450 (org-refile-targets `((nil :maxlevel .
3))))
5451 (mapcar #'car
(org-refile-get-targets))))))
5454 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5455 (let ((org-refile-use-outline-path nil
)
5456 (org-refile-targets `((nil :maxlevel .
2))))
5457 (mapcar #'car
(org-refile-get-targets))))))
5458 ;; :level limits targets to headlines with the specified level.
5461 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5462 (let ((org-refile-use-outline-path nil
)
5463 (org-refile-targets `((nil :level .
2))))
5464 (mapcar #'car
(org-refile-get-targets))))))
5465 ;; :tag limits targets to headlines with specified tag.
5468 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5469 (let ((org-refile-use-outline-path nil
)
5470 (org-refile-targets `((nil :tag .
"foo"))))
5471 (mapcar #'car
(org-refile-get-targets))))))
5472 ;; :todo limits targets to headlines with specified TODO keyword.
5475 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5476 (let ((org-refile-use-outline-path nil
)
5477 (org-refile-targets `((nil :todo .
"TODO"))))
5478 (mapcar #'car
(org-refile-get-targets))))))
5479 ;; :regexp filters targets matching provided regexp.
5482 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5483 (let ((org-refile-use-outline-path nil
)
5484 (org-refile-targets `((nil :regexp .
"F"))))
5485 (mapcar #'car
(org-refile-get-targets))))))
5486 ;; A nil `org-refile-targets' includes only top level headlines in
5490 (org-test-with-temp-text "* H1\n** S1\n* H2"
5491 (let ((org-refile-use-outline-path nil
)
5492 (org-refile-targets nil
))
5493 (mapcar #'car
(org-refile-get-targets))))))
5494 ;; Return value is the union of the targets according to all the
5495 ;; defined rules. However, prevent duplicates.
5497 (equal '("F2" "F3" "H1")
5498 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5499 (let ((org-refile-use-outline-path nil
)
5500 (org-refile-targets `((nil :regexp .
"F")
5501 (nil :todo .
"TODO"))))
5502 (mapcar #'car
(org-refile-get-targets))))))
5504 (equal '("F2" "F3" "H1")
5505 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5506 (let ((org-refile-use-outline-path nil
)
5507 (org-refile-targets `((nil :regexp .
"F")
5508 (nil :todo .
"TODO"))))
5509 (mapcar #'car
(org-refile-get-targets))))))
5510 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5513 (equal '("H1" "H1/H2" "H1/H2/H3")
5514 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5515 (let ((org-refile-use-outline-path t
)
5516 (org-refile-targets `((nil :maxlevel .
3))))
5517 (mapcar #'car
(org-refile-get-targets))))))
5518 ;; When providing targets as paths, escape forward slashes in
5519 ;; headings with backslashes.
5521 (equal '("H1\\/foo")
5522 (org-test-with-temp-text "* H1/foo"
5523 (let ((org-refile-use-outline-path t
)
5524 (org-refile-targets `((nil :maxlevel .
1))))
5525 (mapcar #'car
(org-refile-get-targets))))))
5526 ;; When `org-refile-use-outline-path' is `file', include file name
5527 ;; without directory in targets.
5529 (org-test-with-temp-text-in-file "* H1"
5530 (let* ((filename (buffer-file-name))
5531 (org-refile-use-outline-path 'file
)
5532 (org-refile-targets `(((,filename
) :level .
1))))
5533 (member (file-name-nondirectory filename
)
5534 (mapcar #'car
(org-refile-get-targets))))))
5535 ;; When `org-refile-use-outline-path' is `full-file-path', include
5538 (org-test-with-temp-text-in-file "* H1"
5539 (let* ((filename (file-truename (buffer-file-name)))
5540 (org-refile-use-outline-path 'full-file-path
)
5541 (org-refile-targets `(((,filename
) :level .
1))))
5542 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5543 ;; When `org-refile-use-outline-path' is `buffer-name', include
5546 (org-test-with-temp-text "* H1"
5547 (let* ((org-refile-use-outline-path 'buffer-name
)
5548 (org-refile-targets `((nil :level .
1))))
5549 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5555 (ert-deftest test-org
/match-sparse-tree
()
5556 "Test `org-match-sparse-tree' specifications."
5559 (org-test-with-temp-text "* H\n** H1 :tag:"
5560 (org-match-sparse-tree nil
"tag")
5561 (search-forward "H1")
5562 (org-invisible-p2)))
5564 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5565 (org-match-sparse-tree nil
"tag")
5566 (search-forward "H2")
5567 (org-invisible-p2)))
5568 ;; "-" operator for tags.
5570 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5571 (org-match-sparse-tree nil
"tag1-tag2")
5572 (search-forward "H1")
5573 (org-invisible-p2)))
5575 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5576 (org-match-sparse-tree nil
"tag1-tag2")
5577 (search-forward "H2")
5578 (org-invisible-p2)))
5579 ;; "&" operator for tags.
5581 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5582 (org-match-sparse-tree nil
"tag1&tag2")
5583 (search-forward "H1")
5584 (org-invisible-p2)))
5586 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5587 (org-match-sparse-tree nil
"tag1&tag2")
5588 (search-forward "H2")
5589 (org-invisible-p2)))
5590 ;; "|" operator for tags.
5592 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5593 (org-match-sparse-tree nil
"tag1|tag2")
5594 (search-forward "H1")
5595 (org-invisible-p2)))
5597 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5598 (org-match-sparse-tree nil
"tag1|tag2")
5599 (search-forward "H2")
5600 (org-invisible-p2)))
5601 ;; Regexp match on tags.
5603 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5604 (org-match-sparse-tree nil
"{^tag.*}")
5605 (search-forward "H1")
5606 (org-invisible-p2)))
5608 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5609 (org-match-sparse-tree nil
"{^tag.*}")
5610 (search-forward "H2")
5611 (org-invisible-p2)))
5612 ;; Match group tags.
5614 (org-test-with-temp-text
5615 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5616 (org-match-sparse-tree nil
"work")
5617 (search-forward "H1")
5618 (org-invisible-p2)))
5620 (org-test-with-temp-text
5621 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5622 (org-match-sparse-tree nil
"work")
5623 (search-forward "H2")
5624 (org-invisible-p2)))
5625 ;; Match group tags with hard brackets.
5627 (org-test-with-temp-text
5628 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5629 (org-match-sparse-tree nil
"work")
5630 (search-forward "H1")
5631 (org-invisible-p2)))
5633 (org-test-with-temp-text
5634 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5635 (org-match-sparse-tree nil
"work")
5636 (search-forward "H2")
5637 (org-invisible-p2)))
5638 ;; Match tags in hierarchies
5640 (org-test-with-temp-text
5641 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5642 #+TAGS: [ Lev_2 : Lev_3 ]\n
5643 #+TAGS: { Lev_3 : Lev_4 }\n
5644 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5645 (org-match-sparse-tree nil
"Lev_1")
5646 (search-forward "H4")
5647 (org-invisible-p2)))
5649 (org-test-with-temp-text
5650 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5651 #+TAGS: [ Lev_2 : Lev_3 ]\n
5652 #+TAGS: { Lev_3 : Lev_4 }\n
5653 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5654 (org-match-sparse-tree nil
"Lev_1+Lev_3")
5655 (search-forward "H4")
5656 (org-invisible-p2)))
5657 ;; Match regular expressions in tags
5659 (org-test-with-temp-text
5660 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5661 (org-match-sparse-tree nil
"Lev")
5662 (search-forward "H1")
5663 (org-invisible-p2)))
5665 (org-test-with-temp-text
5666 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5667 (org-match-sparse-tree nil
"Lev")
5668 (search-forward "H1")
5669 (org-invisible-p2)))
5670 ;; Match properties.
5672 (org-test-with-temp-text
5673 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5674 (org-match-sparse-tree nil
"A=\"1\"")
5675 (search-forward "H2")
5676 (org-invisible-p2)))
5678 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5679 (org-match-sparse-tree nil
"A=\"1\"")
5680 (search-forward "H2")
5681 (org-invisible-p2)))
5682 ;; Case is not significant when matching properties.
5684 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5685 (org-match-sparse-tree nil
"a=\"1\"")
5686 (search-forward "H2")
5687 (org-invisible-p2)))
5689 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5690 (org-match-sparse-tree nil
"A=\"1\"")
5691 (search-forward "H2")
5692 (org-invisible-p2)))
5693 ;; Match special LEVEL property.
5695 (org-test-with-temp-text "* H\n** H1\n*** H2"
5696 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5697 (search-forward "H1")
5698 (org-invisible-p2)))
5700 (org-test-with-temp-text "* H\n** H1\n*** H2"
5701 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5702 (search-forward "H2")
5703 (org-invisible-p2)))
5704 ;; Comparison operators when matching properties.
5706 (org-test-with-temp-text
5707 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5708 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5709 (search-forward "H1")
5710 (org-invisible-p2)))
5712 (org-test-with-temp-text
5713 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5714 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5715 (search-forward "H2")
5716 (org-invisible-p2)))
5717 ;; Regexp match on properties values.
5719 (org-test-with-temp-text
5720 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5721 (org-match-sparse-tree nil
"A={f.*}")
5722 (search-forward "H1")
5723 (org-invisible-p2)))
5725 (org-test-with-temp-text
5726 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5727 (org-match-sparse-tree nil
"A={f.*}")
5728 (search-forward "H2")
5729 (org-invisible-p2)))
5730 ;; With an optional argument, limit match to TODO entries.
5732 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5733 (org-match-sparse-tree t
"tag")
5734 (search-forward "H1")
5735 (org-invisible-p2)))
5737 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5738 (org-match-sparse-tree t
"tag")
5739 (search-forward "H2")
5740 (org-invisible-p2))))
5742 (ert-deftest test-org
/occur
()
5743 "Test `org-occur' specifications."
5744 ;; Count number of matches.
5747 (org-test-with-temp-text "* H\nA\n* H2"
5751 (org-test-with-temp-text "* H\nA\n* H2\nA"
5753 ;; Test CALLBACK optional argument.
5756 (org-test-with-temp-text "* H\nA\n* H2"
5757 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5760 (org-test-with-temp-text "* H\nA\n* H2\nA"
5761 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5762 ;; Case-fold searches according to `org-occur-case-fold-search'.
5765 (org-test-with-temp-text "Aa"
5766 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5769 (org-test-with-temp-text "Aa"
5770 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5773 (org-test-with-temp-text "Aa"
5774 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5777 (org-test-with-temp-text "Aa"
5778 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5781 (org-test-with-temp-text "Aa"
5782 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5785 (org-test-with-temp-text "Aa"
5786 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5791 (ert-deftest test-org
/tag-string-to-alist
()
5792 "Test `org-tag-string-to-alist' specifications."
5793 ;; Tag without selection key.
5794 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5795 ;; Tag with selection key.
5796 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5800 (org-tag-string-to-alist "[ group : t1 t2 ]")
5801 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5802 ;; Mutually exclusive tags.
5803 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5804 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5807 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5808 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5810 (ert-deftest test-org
/tag-alist-to-string
()
5811 "Test `org-tag-alist-to-string' specifications."
5812 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5813 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5816 (org-tag-alist-to-string
5817 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5818 "[ group : t1 t2 ]"))
5820 (equal (org-tag-alist-to-string
5821 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5825 (org-tag-alist-to-string
5826 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5827 "{ group : tag1 tag2 }")))
5829 (ert-deftest test-org
/tag-alist-to-groups
()
5830 "Test `org-tag-alist-to-groups' specifications."
5832 (equal (org-tag-alist-to-groups
5833 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5834 '(("group" "t1" "t2"))))
5837 (org-tag-alist-to-groups
5838 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5839 '(("group" "t1" "t2"))))
5841 (org-tag-alist-to-groups
5842 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5844 (ert-deftest test-org
/tag-align
()
5845 "Test tags alignment."
5846 ;; Test aligning tags with different display width.
5848 ;; 12345678901234567890
5849 (equal "* Test :abc:"
5850 (org-test-with-temp-text "* Test :abc:"
5851 (let ((org-tags-column -
20)
5852 (indent-tabs-mode nil
))
5853 (org-fix-tags-on-the-fly))
5856 ;; 12345678901234567890
5857 (equal "* Test :日本語:"
5858 (org-test-with-temp-text "* Test :日本語:"
5859 (let ((org-tags-column -
20)
5860 (indent-tabs-mode nil
))
5861 (org-fix-tags-on-the-fly))
5863 ;; Make sure aligning tags do not skip invisible text.
5865 (equal "* [[linkx]] :tag:"
5866 (org-test-with-temp-text "* [[link<point>]] :tag:"
5867 (let ((org-tags-column 0))
5868 (org-fix-tags-on-the-fly)
5871 ;; Aligning tags preserve position.
5873 (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
5874 (let ((org-tags-column 78)
5875 (indent-tabs-mode nil
))
5876 (org-fix-tags-on-the-fly))
5878 ;; Aligning all tags in visible buffer.
5880 ;; 12345678901234567890
5881 (equal (concat "* Level 1 :abc:\n"
5883 (org-test-with-temp-text (concat "* Level 1 :abc:\n"
5885 (let ((org-tags-column -
20)
5886 (indent-tabs-mode nil
))
5887 ;; (org-align-tags :all) must work even when the point
5888 ;; is at the end of the buffer.
5889 (goto-char (point-max))
5890 (org-align-tags :all
))
5893 (ert-deftest test-org
/get-tags
()
5894 "Test `org-get-tags' specifications."
5898 (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
5900 (equal '("foo" "bar")
5901 (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
5902 ;; Return nil when there is no tag.
5904 (org-test-with-temp-text "* Test" (org-get-tags)))
5905 ;; Tags are inherited from parent headlines.
5908 (let ((org-use-tag-inheritance t
))
5909 (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
5911 ;; Tags are inherited from `org-file-tags'.
5914 (org-test-with-temp-text "* H1"
5915 (let ((org-file-tags '("tag"))
5916 (org-use-tag-inheritance t
))
5918 ;; Only inherited tags have the `inherited' text property.
5920 (get-text-property 0 'inherited
5921 (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
5922 (let ((org-use-tag-inheritance t
))
5923 (assoc-string "foo" (org-get-tags))))))
5925 (get-text-property 0 'inherited
5926 (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
5927 (let ((org-use-tag-inheritance t
))
5928 (assoc-string "bar" (org-get-tags))))))
5929 ;; Obey to `org-use-tag-inheritance'.
5931 (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
5932 (let ((org-use-tag-inheritance nil
))
5933 (assoc-string "foo" (org-get-tags)))))
5935 (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
5936 (let ((org-use-tag-inheritance nil
)
5937 (org-file-tags '("foo")))
5938 (assoc-string "foo" (org-get-tags)))))
5940 (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
5941 (let ((org-use-tag-inheritance '("bar")))
5942 (assoc-string "foo" (org-get-tags)))))
5944 (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
5945 (let ((org-use-tag-inheritance '("bar")))
5946 (assoc-string "bar" (org-get-tags)))))
5948 (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
5949 (let ((org-use-tag-inheritance "b.*"))
5950 (assoc-string "foo" (org-get-tags)))))
5952 (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
5953 (let ((org-use-tag-inheritance "b.*"))
5954 (assoc-string "bar" (org-get-tags)))))
5955 ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
5958 (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
5959 (let ((org-use-tag-inheritance t
))
5960 (org-get-tags nil t
)))))
5961 ;; When optional argument POS is non-nil, get tags there instead.
5964 (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
5966 ;; Make sure tags excluded from inheritance are returned if local
5969 (org-test-with-temp-text "* Test :foo:"
5970 (let ((org-use-tag-inheritance t
)
5971 (org-tags-exclude-from-inheritance '("foo")))
5973 ;; Test the collection of tags from #+filetags and parent tags.
5975 (equal '("a" "b" "c" "d")
5976 (org-test-with-temp-text (concat "#+filetags: a\n"
5981 (let ((org-use-tag-inheritance t
))
5982 (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
5984 ;; Pathological case: tagged headline with an empty body.
5985 (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
5987 (ert-deftest test-org
/set-tags
()
5988 "Test `org-set-tags' specifications."
5989 ;; Throw an error on invalid data.
5991 (org-test-with-temp-text "* H"
5992 (org-set-tags 'foo
)))
5993 ;; `nil', an empty, and a blank string remove all tags.
5996 (org-test-with-temp-text "* H :tag1:tag2:"
6001 (org-test-with-temp-text "* H :tag1:tag2:"
6006 (org-test-with-temp-text "* H :tag1:tag2:"
6009 ;; If there's nothing to remove, just bail out.
6012 (org-test-with-temp-text "* H"
6017 (org-test-with-temp-text "* "
6020 ;; If DATA is a tag string, set current tags to it, even if it means
6021 ;; replacing old tags.
6024 (org-test-with-temp-text "* H :tag1:tag2:"
6025 (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
6029 (org-test-with-temp-text "* H"
6030 (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
6032 ;; If DATA is a list, set tags to this list, even if it means
6033 ;; replacing old tags.
6036 (org-test-with-temp-text "* H :tag1:tag2:"
6037 (let ((org-tags-column 1)) (org-set-tags '("tag0")))
6041 (org-test-with-temp-text "* H"
6042 (let ((org-tags-column 1)) (org-set-tags '("tag0")))
6044 ;; When set, apply `org-tags-sort-function'.
6047 (org-test-with-temp-text "* H"
6048 (let ((org-tags-column 1)
6049 (org-tags-sort-function #'string
<))
6050 (org-set-tags '("b" "a"))
6052 ;; When new tags are identical to the previous ones, still align.
6055 (org-test-with-temp-text "* H :foo:"
6056 (let ((org-tags-column 1))
6057 (org-set-tags '("foo"))
6059 ;; When tags have been changed, run `org-after-tags-change-hook'.
6062 (org-test-with-temp-text "* H :foo:"
6063 (let ((org-after-tags-change-hook (lambda () (throw :return t
))))
6064 (org-set-tags '("bar"))
6068 (org-test-with-temp-text "* H :foo:"
6069 (let ((org-after-tags-change-hook (lambda () (throw :return t
))))
6070 (org-set-tags '("foo"))
6072 ;; Special case: handle empty headlines.
6075 (org-test-with-temp-text "* "
6076 (let ((org-tags-column 1)) (org-set-tags '("tag0")))
6078 ;; Modify buffer only when a tag change happens or alignment is
6081 (org-test-with-temp-text "* H :foo:"
6082 (set-buffer-modified-p nil
)
6083 (let ((org-tags-column 1)) (org-set-tags '("foo")))
6084 (buffer-modified-p)))
6086 (org-test-with-temp-text "* H :foo:"
6087 (set-buffer-modified-p nil
)
6088 (let ((org-tags-column 10)) (org-set-tags '("foo")))
6089 (buffer-modified-p)))
6091 (org-test-with-temp-text "* H :foo:"
6092 (set-buffer-modified-p nil
)
6093 (let ((org-tags-column 10)) (org-set-tags '("bar")))
6094 (buffer-modified-p)))
6095 ;; Pathological case: when setting tags of a folded headline, do not
6096 ;; let new tags being sucked into invisibility.
6098 (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
6099 ;; Show only headlines
6101 ;; Set NEXT tag on current entry
6102 (org-set-tags ":NEXT:")
6103 ;; Move point to that NEXT tag
6104 (search-forward "NEXT") (backward-word)
6105 ;; And it should be visible (i.e. no overlays)
6106 (overlays-at (point)))))
6108 (ert-deftest test-org
/set-tags-command
()
6109 "Test `org-set-tags-command' specifications"
6110 ;; Set tags at current headline.
6113 (org-test-with-temp-text "* H1"
6114 (cl-letf (((symbol-function 'completing-read
)
6115 (lambda (&rest args
) ":foo:")))
6116 (let ((org-use-fast-tag-selection nil
)
6117 (org-tags-column 1))
6118 (org-set-tags-command)))
6120 ;; Preserve position when called from the section below.
6122 (equal "* H1 :foo:\nContents"
6123 (org-test-with-temp-text "* H1\n<point>Contents"
6124 (cl-letf (((symbol-function 'completing-read
)
6125 (lambda (&rest args
) ":foo:")))
6126 (let ((org-use-fast-tag-selection nil
)
6127 (org-tags-column 1))
6128 (org-set-tags-command)))
6131 (equal "* H1 :foo:\nContents2"
6132 (org-test-with-temp-text "* H1\n<point>Contents2"
6133 (cl-letf (((symbol-function 'completing-read
)
6134 (lambda (&rest args
) ":foo:")))
6135 (let ((org-use-fast-tag-selection nil
)
6136 (org-tags-column 1))
6137 (org-set-tags-command)))
6138 (org-at-heading-p))))
6139 ;; Strip all forbidden characters from user-entered tags.
6142 (org-test-with-temp-text "* H1"
6143 (cl-letf (((symbol-function 'completing-read
)
6144 (lambda (&rest args
) ": foo *:")))
6145 (let ((org-use-fast-tag-selection nil
)
6146 (org-tags-column 1))
6147 (org-set-tags-command)))
6149 ;; When a region is active and
6150 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
6151 ;; same value in all headlines in region.
6153 (equal "* H1 :foo:\nContents\n* H2 :foo:"
6154 (org-test-with-temp-text "* H1\nContents\n* H2"
6155 (cl-letf (((symbol-function 'completing-read
)
6156 (lambda (&rest args
) ":foo:")))
6157 (let ((org-use-fast-tag-selection nil
)
6158 (org-loop-over-headlines-in-active-region t
)
6159 (org-tags-column 1))
6160 (transient-mark-mode 1)
6161 (push-mark (point) t t
)
6162 (goto-char (point-max))
6163 (org-set-tags-command)))
6166 (equal "* H1\nContents\n* H2 :foo:"
6167 (org-test-with-temp-text "* H1\nContents\n* H2"
6168 (cl-letf (((symbol-function 'completing-read
)
6169 (lambda (&rest args
) ":foo:")))
6170 (let ((org-use-fast-tag-selection nil
)
6171 (org-loop-over-headlines-in-active-region nil
)
6172 (org-tags-column 1))
6173 (transient-mark-mode 1)
6174 (push-mark (point) t t
)
6175 (goto-char (point-max))
6176 (org-set-tags-command)))
6178 ;; With a C-u prefix argument, align all tags in the buffer.
6180 (equal "* H1 :foo:\n* H2 :bar:"
6181 (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
6182 (let ((org-tags-column 1)) (org-set-tags-command '(4)))
6185 (ert-deftest test-org
/toggle-tag
()
6186 "Test `org-toggle-tag' specifications."
6187 ;; Insert missing tag.
6190 (org-test-with-temp-text "* H"
6191 (let ((org-tags-column 1)) (org-toggle-tag "tag"))
6194 (equal "* H :tag1:tag2:"
6195 (org-test-with-temp-text "* H :tag1:"
6196 (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
6198 ;; Remove existing tag.
6201 (org-test-with-temp-text "* H :tag:"
6202 (org-toggle-tag "tag")
6206 (org-test-with-temp-text "* H :tag1:tag2:"
6207 (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
6211 (org-test-with-temp-text "* H :tag1:tag2:"
6212 (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
6214 ;; With optional argument ONOFF set to `on', try to insert the tag,
6215 ;; even if its already there.
6218 (org-test-with-temp-text "* H"
6219 (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on
))
6223 (org-test-with-temp-text "* H :tag:"
6224 (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on
))
6226 ;; With optional argument ONOFF set to `off', try to remove the tag,
6227 ;; even if its not there.
6230 (org-test-with-temp-text "* H :tag:"
6231 (org-toggle-tag "tag" 'off
)
6235 (org-test-with-temp-text "* H :tag:"
6236 (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off
))
6238 ;; Special case: Handle properly tag inheritance. In particular, do
6239 ;; not set inherited tags.
6241 (equal "* H1 :tag:\n** H2 :tag2:tag:"
6242 (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
6243 (let ((org-use-tag-inheritance t
)
6244 (org-tags-column 1))
6245 (org-toggle-tag "tag"))
6248 (equal "* H1 :tag1:tag2:\n** H2 :foo:"
6249 (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
6250 (let ((org-use-tag-inheritance t
)
6251 (org-tags-column 1))
6252 (org-toggle-tag "foo"))
6255 (ert-deftest test-org
/tags-expand
()
6256 "Test `org-tags-expand' specifications."
6257 ;; Expand tag groups as a regexp enclosed withing curly brackets.
6259 (equal "{\\<[ABC]\\>}"
6260 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6262 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "A")))))
6264 (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
6265 (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
6267 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "Aa")))))
6268 ;; Preserve operator before the regexp.
6270 (equal "+{\\<[ABC]\\>}"
6271 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6273 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "+A")))))
6275 (equal "-{\\<[ABC]\\>}"
6276 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6278 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "-A")))))
6279 ;; Handle "|" syntax.
6281 (equal "{\\<[ABC]\\>}|D"
6282 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6284 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "A|D")))))
6285 ;; Handle nested groups.
6287 (equal "{\\<[A-D]\\>}"
6288 (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
6290 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "A")))))
6291 ;; Expand multiple occurrences of the same group.
6293 (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
6294 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6296 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "A|A")))))
6297 ;; Preserve regexp matches.
6300 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
6302 (let ((org-tag-alist-for-agenda nil
)) (org-tags-expand "{A+}"))))))
6307 (ert-deftest test-org
/auto-repeat-maybe
()
6308 "Test `org-auto-repeat-maybe' specifications."
6309 ;; Do not auto repeat when there is no valid time stamp with
6310 ;; a repeater in the entry.
6314 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6315 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
6321 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6322 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
6325 ;; When switching to DONE state, switch back to first TODO keyword
6326 ;; in sequence, or the same keyword if they have different types.
6330 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6331 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6337 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6338 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6344 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
6345 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
6348 ;; If there was no TODO keyword in the first place, do not insert
6353 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6354 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6357 ;; Revert to REPEAT_TO_STATE, if set.
6361 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6362 (org-test-with-temp-text
6365 :REPEAT_TO_STATE: KWD2
6367 <2012-03-29 Thu +2y>"
6370 ;; When switching to DONE state, update base date. If there are
6371 ;; multiple repeated time stamps, update them all.
6374 "<2014-03-29 .* \\+2y>"
6375 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6376 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6381 "<2015-03-04 .* \\+1y>"
6382 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6383 (org-test-with-temp-text
6384 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6387 ;; Throw an error if repeater unit is the hour and no time is
6388 ;; provided in the time-stamp.
6390 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6391 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6394 ;; Do not repeat inactive time stamps with a repeater.
6397 "\\[2014-03-29 .* \\+2y\\]"
6398 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6399 (org-test-with-temp-text
6400 "* TODO H\n[2012-03-29 Thu. +2y]"
6403 ;; Do not repeat commented time stamps.
6406 "<2015-03-04 .* \\+1y>"
6407 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6408 (org-test-with-temp-text
6409 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6414 "<2015-03-04 .* \\+1y>"
6415 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6416 (org-test-with-temp-text
6418 <2012-03-29 Thu. +2y>
6420 <2014-03-04 Tue +1y>
6424 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6425 ;; entry, record time of last repeat.
6429 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6430 (org-log-repeat nil
))
6431 (cl-letf (((symbol-function 'org-add-log-setup
)
6432 (lambda (&rest args
) nil
)))
6433 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6435 (buffer-string))))))
6439 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6441 (cl-letf (((symbol-function 'org-add-log-setup
)
6442 (lambda (&rest args
) nil
)))
6443 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6445 (buffer-string))))))
6449 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6450 (cl-letf (((symbol-function 'org-add-log-setup
)
6451 (lambda (&rest args
) nil
)))
6452 (org-test-with-temp-text
6453 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6455 (buffer-string))))))
6456 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6457 ;; the entry as it is no longer relevant.
6461 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6462 (org-test-with-temp-text
6463 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6466 ;; Properly advance repeater even when a clock entry is specified
6467 ;; and `org-log-repeat' is nil.
6470 "SCHEDULED: <2014-03-29"
6471 (let ((org-log-repeat nil
)
6472 (org-todo-keywords '((sequence "TODO" "DONE"))))
6473 (org-test-with-temp-text
6475 SCHEDULED: <2012-03-29 Thu +2y>
6476 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6478 (buffer-string))))))
6483 (ert-deftest test-org
/at-timestamp-p
()
6484 "Test `org-at-timestamp-p' specifications."
6486 (org-test-with-temp-text "<2012-03-29 Thu>"
6487 (org-at-timestamp-p)))
6489 (org-test-with-temp-text "2012-03-29 Thu"
6490 (org-at-timestamp-p)))
6491 ;; Test return values.
6494 (org-test-with-temp-text "<2012-03-29 Thu>"
6495 (org-at-timestamp-p))))
6498 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6499 (org-at-timestamp-p))))
6502 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6503 (org-at-timestamp-p))))
6506 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6507 (org-at-timestamp-p))))
6510 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6511 (org-at-timestamp-p))))
6514 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6515 (org-at-timestamp-p))))
6518 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6519 (org-at-timestamp-p))))
6522 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6523 (org-at-timestamp-p))))
6524 ;; Test `inactive' optional argument.
6526 (org-test-with-temp-text "[2012-03-29 Thu]"
6527 (org-at-timestamp-p 'inactive
)))
6529 (org-test-with-temp-text "[2012-03-29 Thu]"
6530 (org-at-timestamp-p)))
6531 ;; When optional argument is `agenda', recognize time-stamps in
6532 ;; planning info line, property drawers and clocks.
6534 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6535 (org-at-timestamp-p 'agenda
)))
6537 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6538 (org-at-timestamp-p)))
6540 (org-test-with-temp-text
6541 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6542 (org-at-timestamp-p 'agenda
)))
6544 (org-test-with-temp-text
6545 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6546 (org-at-timestamp-p)))
6548 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6549 (let ((org-agenda-include-inactive-timestamps t
))
6550 (org-at-timestamp-p 'agenda
))))
6552 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6553 (let ((org-agenda-include-inactive-timestamps t
))
6554 (org-at-timestamp-p))))
6556 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6557 (let ((org-agenda-include-inactive-timestamps t
))
6558 (org-at-timestamp-p 'inactive
))))
6559 ;; When optional argument is `lax', match any part of the document
6560 ;; with Org timestamp syntax.
6562 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6563 (org-at-timestamp-p 'lax
)))
6565 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6566 (org-at-timestamp-p)))
6568 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6569 (org-at-timestamp-p 'lax
)))
6571 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6572 (org-at-timestamp-p)))
6574 (org-test-with-temp-text
6575 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6576 (org-at-timestamp-p 'lax
)))
6578 (org-test-with-temp-text
6579 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6580 (org-at-timestamp-p)))
6581 ;; Optional argument `lax' also matches inactive timestamps.
6583 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6584 (org-at-timestamp-p 'lax
))))
6586 (ert-deftest test-org
/time-stamp
()
6587 "Test `org-time-stamp' specifications."
6588 ;; Insert chosen time stamp at point.
6591 "Te<2014-03-04 .*?>xt"
6592 (org-test-with-temp-text "Te<point>xt"
6593 (cl-letf (((symbol-function 'org-read-date
)
6594 (lambda (&rest args
)
6595 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6596 (org-time-stamp nil
)
6598 ;; With a prefix argument, also insert time.
6601 "Te<2014-03-04 .*? 00:41>xt"
6602 (org-test-with-temp-text "Te<point>xt"
6603 (cl-letf (((symbol-function 'org-read-date
)
6604 (lambda (&rest args
)
6605 (apply #'encode-time
6606 (org-parse-time-string "2014-03-04 00:41")))))
6607 (org-time-stamp '(4))
6609 ;; With two universal prefix arguments, insert an active timestamp
6610 ;; with the current time without prompting the user.
6613 "Te<2014-03-04 .*? 00:41>xt"
6614 (org-test-with-temp-text "Te<point>xt"
6615 (org-test-at-time "2014-03-04 00:41"
6616 (org-time-stamp '(16))
6618 ;; When optional argument is non-nil, insert an inactive timestamp.
6621 "Te\\[2014-03-04 .*?\\]xt"
6622 (org-test-with-temp-text "Te<point>xt"
6623 (cl-letf (((symbol-function 'org-read-date
)
6624 (lambda (&rest args
)
6625 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6626 (org-time-stamp nil t
)
6628 ;; When called from a timestamp, replace existing one.
6632 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6633 (cl-letf (((symbol-function 'org-read-date
)
6634 (lambda (&rest args
)
6635 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6636 (org-time-stamp nil
)
6640 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6641 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6642 (cl-letf (((symbol-function 'org-read-date
)
6643 (lambda (&rest args
)
6644 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6645 (org-time-stamp nil
)
6647 ;; When replacing a timestamp, preserve repeater, if any.
6650 "<2014-03-04 .*? \\+2y>"
6651 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6652 (cl-letf (((symbol-function 'org-read-date
)
6653 (lambda (&rest args
)
6654 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6655 (org-time-stamp nil
)
6657 ;; When called twice in a raw, build a date range.
6660 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6661 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6662 (cl-letf (((symbol-function 'org-read-date
)
6663 (lambda (&rest args
)
6664 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6665 (let ((last-command 'org-time-stamp
)
6666 (this-command 'org-time-stamp
))
6667 (org-time-stamp nil
))
6668 (buffer-string))))))
6670 (ert-deftest test-org
/timestamp-has-time-p
()
6671 "Test `org-timestamp-has-time-p' specifications."
6674 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6675 (org-timestamp-has-time-p (org-element-context))))
6678 (org-test-with-temp-text "<2012-03-29 Thu>"
6679 (org-timestamp-has-time-p (org-element-context)))))
6681 (ert-deftest test-org
/get-repeat
()
6682 "Test `org-get-repeat' specifications."
6684 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6687 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6689 ;; Return proper repeat string.
6692 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6694 ;; Prevent false positive (commented or verbatim time stamps)
6696 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6699 (org-test-with-temp-text
6700 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6702 ;; Return nil when called before first heading.
6704 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6706 ;; When called with an optional argument, extract repeater from that
6708 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6709 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6711 (ert-deftest test-org
/timestamp-format
()
6712 "Test `org-timestamp-format' specifications."
6717 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6718 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6723 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6724 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6726 (ert-deftest test-org
/timestamp-split-range
()
6727 "Test `org-timestamp-split-range' specifications."
6728 ;; Extract range start (active).
6731 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6732 (let ((ts (org-timestamp-split-range (org-element-context))))
6733 (mapcar (lambda (p) (org-element-property p ts
))
6734 '(:year-end
:month-end
:day-end
))))))
6735 ;; Extract range start (inactive)
6738 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6739 (let ((ts (org-timestamp-split-range (org-element-context))))
6740 (mapcar (lambda (p) (org-element-property p ts
))
6741 '(:year-end
:month-end
:day-end
))))))
6742 ;; Extract range end (active).
6745 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6746 (let ((ts (org-timestamp-split-range
6747 (org-element-context) t
)))
6748 (mapcar (lambda (p) (org-element-property p ts
))
6749 '(:year-end
:month-end
:day-end
))))))
6750 ;; Extract range end (inactive)
6753 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6754 (let ((ts (org-timestamp-split-range
6755 (org-element-context) t
)))
6756 (mapcar (lambda (p) (org-element-property p ts
))
6757 '(:year-end
:month-end
:day-end
))))))
6758 ;; Return the timestamp if not a range.
6760 (org-test-with-temp-text "[2012-03-29 Thu]"
6761 (let* ((ts-orig (org-element-context))
6762 (ts-copy (org-timestamp-split-range ts-orig
)))
6763 (eq ts-orig ts-copy
))))
6765 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6766 (let* ((ts-orig (org-element-context))
6767 (ts-copy (org-timestamp-split-range ts-orig
)))
6768 (eq ts-orig ts-copy
)))))
6770 (ert-deftest test-org
/timestamp-translate
()
6771 "Test `org-timestamp-translate' specifications."
6772 ;; Translate whole date range.
6775 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6776 (let ((org-display-custom-times t
)
6777 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6778 (org-timestamp-translate (org-element-context))))))
6779 ;; Translate date range start.
6782 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6783 (let ((org-display-custom-times t
)
6784 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6785 (org-timestamp-translate (org-element-context) 'start
)))))
6786 ;; Translate date range end.
6789 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6790 (let ((org-display-custom-times t
)
6791 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6792 (org-timestamp-translate (org-element-context) 'end
)))))
6793 ;; Translate time range.
6796 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6797 (let ((org-display-custom-times t
)
6798 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6799 (org-timestamp-translate (org-element-context))))))
6800 ;; Translate non-range timestamp.
6803 (org-test-with-temp-text "<2012-03-29 Thu>"
6804 (let ((org-display-custom-times t
)
6805 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6806 (org-timestamp-translate (org-element-context))))))
6807 ;; Do not change `diary' timestamps.
6809 (equal "<%%(org-float t 4 2)>"
6810 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6811 (let ((org-display-custom-times t
)
6812 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6813 (org-timestamp-translate (org-element-context)))))))
6815 (ert-deftest test-org
/timestamp-from-string
()
6816 "Test `org-timestamp-from-string' specifications."
6817 ;; Return nil if argument is not a valid Org timestamp.
6818 (should-not (org-timestamp-from-string ""))
6819 (should-not (org-timestamp-from-string nil
))
6820 (should-not (org-timestamp-from-string "<2012-03-29"))
6821 ;; Otherwise, return a valid Org timestamp object.
6823 (equal "<2012-03-29 Thu>"
6824 (let ((system-time-locale "en_US"))
6825 (org-element-interpret-data
6826 (org-timestamp-from-string "<2012-03-29 Thu>")))))
6828 (equal "[2014-03-04 Tue]"
6829 (let ((system-time-locale "en_US"))
6830 (org-element-interpret-data
6831 (org-timestamp-from-string "[2014-03-04 Tue]"))))))
6833 (ert-deftest test-org
/timestamp-from-time
()
6834 "Test `org-timestamp-from-time' specifications."
6837 (equal "<2012-03-29 Thu>"
6838 (let ((system-time-locale "en_US"))
6839 (org-element-interpret-data
6840 (org-timestamp-from-time
6841 (apply #'encode-time
6842 (org-parse-time-string "<2012-03-29 Thu 16:40>")))))))
6843 ;; When optional argument WITH-TIME is non-nil, provide time
6846 (equal "<2012-03-29 Thu 16:40>"
6847 (let ((system-time-locale "en_US"))
6848 (org-element-interpret-data
6849 (org-timestamp-from-time
6850 (apply #'encode-time
6851 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6853 ;; When optional argument INACTIVE is non-nil, return an inactive
6856 (equal "[2012-03-29 Thu]"
6857 (let ((system-time-locale "en_US"))
6858 (org-element-interpret-data
6859 (org-timestamp-from-time
6860 (apply #'encode-time
6861 (org-parse-time-string "<2012-03-29 Thu 16:40>"))
6864 (ert-deftest test-org
/timestamp-to-time
()
6865 "Test `org-timestamp-to-time' specifications."
6870 (org-timestamp-to-time
6871 (org-timestamp-from-string "<2014-03-04 Tue>")))))
6876 (org-timestamp-to-time
6877 (org-timestamp-from-string "[2014-03-04 Tue]")))))
6879 (equal "2012-03-29 08:30"
6882 (org-timestamp-to-time
6883 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
6888 (org-timestamp-to-time
6889 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
6894 (org-timestamp-to-time
6895 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
6896 ;; When optional argument END is non-nil, use end of date range or
6899 (equal "2012-03-29 16:40"
6902 (org-timestamp-to-time
6903 (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
6909 (org-timestamp-to-time
6910 (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
6916 (org-timestamp-to-time
6917 (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
6923 (ert-deftest test-org
/flag-drawer
()
6924 "Test `org-flag-drawer' specifications."
6927 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6929 (get-char-property (line-end-position) 'invisible
)))
6932 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6934 (org-flag-drawer nil
)
6935 (get-char-property (line-end-position) 'invisible
)))
6936 ;; Test optional argument.
6938 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6939 (let ((drawer (save-excursion (search-forward ":D2")
6940 (org-element-at-point))))
6941 (org-flag-drawer t drawer
)
6942 (get-char-property (progn (search-forward ":D2") (line-end-position))
6945 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6946 (let ((drawer (save-excursion (search-forward ":D2")
6947 (org-element-at-point))))
6948 (org-flag-drawer t drawer
)
6949 (get-char-property (line-end-position) 'invisible
))))
6950 ;; Do not hide fake drawers.
6952 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6955 (get-char-property (line-end-position) 'invisible
)))
6956 ;; Do not hide incomplete drawers.
6958 (org-test-with-temp-text ":D:\nparagraph"
6961 (get-char-property (line-end-position) 'invisible
)))
6962 ;; Do not hide drawers when called from final blank lines.
6964 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6965 (goto-char (point-max))
6967 (goto-char (point-min))
6968 (get-char-property (line-end-position) 'invisible
)))
6969 ;; Don't leave point in an invisible part of the buffer when hiding
6972 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6973 (goto-char (point-max))
6975 (get-char-property (point) 'invisible
))))
6977 (ert-deftest test-org
/hide-block-toggle
()
6978 "Test `org-hide-block-toggle' specifications."
6979 ;; Error when not at a block.
6981 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6982 (org-hide-block-toggle 'off
)
6983 (get-char-property (line-end-position) 'invisible
)))
6986 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6987 (org-hide-block-toggle)
6988 (get-char-property (line-end-position) 'invisible
)))
6990 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6991 (org-hide-block-toggle)
6992 (get-char-property (line-end-position) 'invisible
)))
6993 ;; Show block unconditionally when optional argument is `off'.
6995 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6996 (org-hide-block-toggle)
6997 (org-hide-block-toggle 'off
)
6998 (get-char-property (line-end-position) 'invisible
)))
7000 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
7001 (org-hide-block-toggle 'off
)
7002 (get-char-property (line-end-position) 'invisible
)))
7003 ;; Hide block unconditionally when optional argument is non-nil.
7005 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
7006 (org-hide-block-toggle t
)
7007 (get-char-property (line-end-position) 'invisible
)))
7009 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
7010 (org-hide-block-toggle)
7011 (org-hide-block-toggle t
)
7012 (get-char-property (line-end-position) 'invisible
)))
7013 ;; Do not hide block when called from final blank lines.
7015 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
7016 (org-hide-block-toggle)
7017 (goto-char (point-min))
7018 (get-char-property (line-end-position) 'invisible
)))
7019 ;; Don't leave point in an invisible part of the buffer when hiding
7022 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
7023 (org-hide-block-toggle)
7024 (get-char-property (point) 'invisible
))))
7026 (ert-deftest test-org
/hide-block-toggle-maybe
()
7027 "Test `org-hide-block-toggle-maybe' specifications."
7029 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
7030 (org-hide-block-toggle-maybe)))
7032 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
7034 (ert-deftest test-org
/show-set-visibility
()
7035 "Test `org-show-set-visibility' specifications."
7036 ;; Do not throw an error before first heading.
7038 (org-test-with-temp-text "Preamble\n* Headline"
7039 (org-show-set-visibility 'tree
)
7041 ;; Test all visibility spans, both on headline and in entry.
7042 (let ((list-visible-lines
7043 (lambda (state headerp
)
7044 (org-test-with-temp-text "* Grandmother (0)
7055 **** The other child (11)
7060 (search-forward (if headerp
"Self" "Match"))
7061 (org-show-set-visibility state
)
7062 (goto-char (point-min))
7063 (let (result (line 0))
7065 (unless (org-invisible-p2) (push line result
))
7068 (nreverse result
))))))
7069 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
7070 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
7071 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
7072 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
7073 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
7074 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
7075 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
7076 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
7077 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
7078 (should (equal '(0 1 3 5 7 8 9 11 12 13)
7079 (funcall list-visible-lines
'tree nil
)))
7080 (should (equal '(0 1 3 4 5 7 12 13)
7081 (funcall list-visible-lines
'canonical t
)))
7082 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
7083 (funcall list-visible-lines
'canonical nil
))))
7084 ;; When point is hidden in a drawer or a block, make sure to make it
7087 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
7088 (org-hide-block-toggle)
7089 (search-forward "Text")
7090 (org-show-set-visibility 'minimal
)
7091 (org-invisible-p2)))
7093 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
7095 (search-forward "Text")
7096 (org-show-set-visibility 'minimal
)
7097 (org-invisible-p2)))
7099 (org-test-with-temp-text
7100 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
7103 (org-hide-block-toggle)
7104 (search-forward "Text")
7105 (org-show-set-visibility 'minimal
)
7106 (org-invisible-p2))))
7108 (defun test-org/copy-visible
()
7109 "Test `org-copy-visible' specifications."
7112 (org-test-with-temp-text "Foo"
7113 (let ((kill-ring nil
))
7114 (org-copy-visible (point-min) (point-max))
7115 (current-kill 0 t
)))))
7116 ;; Skip invisible characters by text property.
7119 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
7120 (let ((kill-ring nil
))
7121 (org-copy-visible (point-min) (point-max))
7122 (current-kill 0 t
)))))
7123 ;; Skip invisible characters by overlay.
7126 (org-test-with-temp-text "F<hidden>oo"
7127 (let ((o (make-overlay 2 10)))
7128 (overlay-put o
'invisible t
))
7129 (let ((kill-ring nil
))
7130 (org-copy-visible (point-min) (point-max))
7131 (current-kill 0 t
)))))
7132 ;; Handle invisible characters at the beginning and the end of the
7136 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
7137 (let ((kill-ring nil
))
7138 (org-copy-visible (point-min) (point-max))
7139 (current-kill 0 t
)))))
7142 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
7143 (let ((kill-ring nil
))
7144 (org-copy-visible (point-min) (point-max))
7145 (current-kill 0 t
)))))
7146 ;; Handle multiple visible parts.
7149 (org-test-with-temp-text
7150 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
7151 (let ((kill-ring nil
))
7152 (org-copy-visible (point-min) (point-max))
7153 (current-kill 0 t
))))))
7155 (ert-deftest test-org
/set-visibility-according-to-property
()
7156 "Test `org-set-visibility-according-to-property' specifications."
7159 (org-test-with-temp-text
7166 (org-set-visibility-according-to-property)
7167 (invisible-p (point))))
7168 ;; "children" state.
7170 (org-test-with-temp-text
7174 :VISIBILITY: children
7179 (org-set-visibility-according-to-property)
7180 (invisible-p (point))))
7182 (org-test-with-temp-text
7186 :VISIBILITY: children
7191 (org-set-visibility-according-to-property)
7192 (invisible-p (point))))
7195 (org-test-with-temp-text
7199 :VISIBILITY: content
7204 (org-set-visibility-according-to-property)
7205 (invisible-p (point))))
7207 (org-test-with-temp-text
7211 :VISIBILITY: content
7216 (org-set-visibility-according-to-property)
7217 (not (invisible-p (point)))))
7220 (org-test-with-temp-text
7224 :VISIBILITY: showall
7229 (org-set-visibility-according-to-property)
7230 (not (invisible-p (point)))))
7232 (org-test-with-temp-text
7236 :VISIBILITY: showall
7241 (org-set-visibility-according-to-property)
7242 (not (invisible-p (point)))))
7243 ;; When VISIBILITY properties are nested, ignore inner ones.
7245 (org-test-with-temp-text
7255 (org-set-visibility-according-to-property)
7256 (invisible-p (point)))))
7261 (ert-deftest test-org
/paste-subtree
()
7262 "Test `org-paste-subtree' specifications."
7263 ;; Return an error if text to yank is not a set of subtrees.
7264 (should-error (org-paste-subtree nil
"Text"))
7265 ;; Adjust level according to current one.
7267 (equal "* H\n* Text\n"
7268 (org-test-with-temp-text "* H\n<point>"
7269 (org-paste-subtree nil
"* Text")
7272 (equal "* H1\n** H2\n** Text\n"
7273 (org-test-with-temp-text "* H1\n** H2\n<point>"
7274 (org-paste-subtree nil
"* Text")
7276 ;; When not on a heading, move to next heading before yanking.
7278 (equal "* H1\nParagraph\n* Text\n* H2"
7279 (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
7280 (org-paste-subtree nil
"* Text")
7282 ;; If point is between two headings, use the deepest level.
7284 (equal "* H1\n\n* Text\n* H2"
7285 (org-test-with-temp-text "* H1\n<point>\n* H2"
7286 (org-paste-subtree nil
"* Text")
7289 (equal "** H1\n\n** Text\n* H2"
7290 (org-test-with-temp-text "** H1\n<point>\n* H2"
7291 (org-paste-subtree nil
"* Text")
7294 (equal "* H1\n\n** Text\n** H2"
7295 (org-test-with-temp-text "* H1\n<point>\n** H2"
7296 (org-paste-subtree nil
"* Text")
7298 ;; When on an empty heading, after the stars, deduce the new level
7299 ;; from the number of stars.
7302 (org-test-with-temp-text "*** <point>"
7303 (org-paste-subtree nil
"* Text")
7305 ;; Optional argument LEVEL forces a level for the subtree.
7307 (equal "* H\n*** Text\n"
7308 (org-test-with-temp-text "* H<point>"
7309 (org-paste-subtree 3 "* Text")
7312 (ert-deftest test-org
/cut-and-paste-subtree
()
7313 "Test `org-cut-subtree' and `org-paste-subtree'."
7320 (org-test-with-temp-text
7325 (call-interactively #'org-cut-subtree
)
7326 (goto-char (point-min))
7327 (call-interactively #'org-paste-subtree
)
7334 (org-test-with-temp-text
7338 (call-interactively #'org-cut-subtree
)
7340 (call-interactively #'org-paste-subtree
)
7345 ;;; test-org.el ends here