1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (progn (call-interactively 'comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (progn (call-interactively 'comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# Comment"
106 (progn (forward-line)
107 (let ((org-adapt-indentation t
))
108 (call-interactively 'comment-dwim
))
110 ;; Also recognize single # at column 0 as comments.
113 (org-test-with-temp-text "# Comment"
114 (progn (forward-line)
115 (call-interactively '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"
123 (transient-mark-mode 1)
124 (push-mark (point) t t
)
125 (goto-char (point-max))
126 (call-interactively 'comment-dwim
)
128 ;; Region selected without comments: comment all lines if
129 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
131 (equal "# Comment 1\n\n# Comment 2"
132 (org-test-with-temp-text "Comment 1\n\nComment 2"
134 (transient-mark-mode 1)
135 (push-mark (point) t t
)
136 (goto-char (point-max))
137 (let ((comment-empty-lines nil
))
138 (call-interactively 'comment-dwim
))
141 (equal "# Comment 1\n# \n# Comment 2"
142 (org-test-with-temp-text "Comment 1\n\nComment 2"
144 (transient-mark-mode 1)
145 (push-mark (point) t t
)
146 (goto-char (point-max))
147 (let ((comment-empty-lines t
))
148 (call-interactively 'comment-dwim
))
150 ;; In front of a keyword without region, insert a new comment.
152 (equal "# \n#+KEYWORD: value"
153 (org-test-with-temp-text "#+KEYWORD: value"
154 (progn (call-interactively 'comment-dwim
)
156 ;; In a source block, use appropriate syntax.
159 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively 'comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position) (point)))))
165 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
166 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
168 (transient-mark-mode 1)
169 (push-mark (point) t t
)
171 (let ((org-edit-src-content-indentation 2))
172 (call-interactively 'comment-dwim
))
177 ;;; Date and time analysis
179 (ert-deftest test-org
/org-read-date
()
180 "Test `org-read-date' specifications."
181 ;; Parse ISO date with abbreviated year and month.
182 (should (equal "2012-03-29 16:40"
183 (let ((org-time-was-given t
))
184 (org-read-date t nil
"12-3-29 16:40"))))
185 ;; Parse Europeans dates.
186 (should (equal "2012-03-29 16:40"
187 (let ((org-time-was-given t
))
188 (org-read-date t nil
"29.03.2012 16:40"))))
189 ;; Parse Europeans dates without year.
190 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
191 (let ((org-time-was-given t
))
192 (org-read-date t nil
"29.03. 16:40"))))
193 ;; Relative date applied to current time if there is single
194 ;; plus/minus, or to default date when there are two of them.
198 (cl-letf (((symbol-function 'current-time
)
200 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
203 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
207 (cl-letf (((symbol-function 'current-time
)
209 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (cl-letf (((symbol-function 'current-time
)
221 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
222 (let ((org-read-date-prefer-future t
))
223 (org-read-date t nil
"1")))))
227 (cl-letf (((symbol-function 'current-time
)
229 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
230 (let ((org-read-date-prefer-future t
))
231 (org-read-date t nil
"3-4")))))
235 (cl-letf (((symbol-function 'current-time
)
237 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
238 (let ((org-read-date-prefer-future nil
))
239 (org-read-date t nil
"3-4")))))
240 ;; When set to `org-read-date-prefer-future' is set to `time', read
241 ;; day is moved to tomorrow if specified hour is before current
242 ;; time. However, it only happens in no other part of the date is
247 (cl-letf (((symbol-function 'current-time
)
249 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
250 (let ((org-read-date-prefer-future 'time
))
251 (org-read-date t nil
"00:40" nil
)))))
255 (cl-letf (((symbol-function 'current-time
)
257 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
258 (let ((org-read-date-prefer-future 'time
))
259 (org-read-date t nil
"29 00:40" nil
)))))
260 ;; Caveat: `org-read-date-prefer-future' always refers to current
261 ;; time, not default time, when they differ.
265 (cl-letf (((symbol-function 'current-time
)
267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
268 (let ((org-read-date-prefer-future t
))
271 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
275 (cl-letf (((symbol-function 'current-time
)
277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
278 (let ((org-read-date-prefer-future t
))
281 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
283 (ert-deftest test-org
/org-parse-time-string
()
284 "Test `org-parse-time-string'."
285 (should (equal (org-parse-time-string "2012-03-29 16:40")
286 '(0 40 16 29 3 2012 nil nil nil
)))
287 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
288 '(0 40 16 29 3 2012 nil nil nil
)))
289 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
290 '(0 40 16 29 3 2012 nil nil nil
)))
291 (should (equal (org-parse-time-string "<2012-03-29>")
292 '(0 0 0 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>" t
)
294 '(0 nil nil
29 3 2012 nil nil nil
))))
296 (ert-deftest test-org
/closest-date
()
297 "Test `org-closest-date' specifications."
299 ;; Time stamps without a repeater are returned unchanged.
303 (calendar-gregorian-from-absolute
304 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
305 ;; Time stamps with a null repeater are returned unchanged.
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
311 ;; if PREFER is set to `past' always return a date before, or equal
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
323 ;; if PREFER is set to `future' always return a date before, or equal
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
333 (calendar-gregorian-from-absolute
334 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
335 ;; If PREFER is neither `past' nor `future', select closest date.
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
346 ;; Test "day" repeater.
349 (calendar-gregorian-from-absolute
350 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
355 ;; Test "month" repeater.
358 (calendar-gregorian-from-absolute
359 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
364 ;; Test "year" repeater.
367 (calendar-gregorian-from-absolute
368 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
371 (calendar-gregorian-from-absolute
372 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
374 (ert-deftest test-org
/deadline-close-p
()
375 "Test `org-deadline-close-p' specifications."
376 ;; Pretend that the current time is 2016-06-03 Fri 01:43
377 (cl-letf (((symbol-function 'current-time
)
380 (org-parse-time-string "2016-06-03 Fri 01:43")))))
381 ;; Timestamps are close if they are within `ndays' of lead time.
382 (org-test-with-temp-text "* Heading"
383 (should (org-deadline-close-p "2016-06-03 Fri" 0))
384 (should (org-deadline-close-p "2016-06-02 Thu" 0))
385 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
386 (should (org-deadline-close-p "2016-06-04 Sat" 1))
387 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
388 ;; Read `ndays' from timestamp if argument not given.
389 (org-test-with-temp-text "* H"
390 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
391 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
392 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
393 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
394 ;; Prefer `ndays' argument over lead time in timestamp.
395 (org-test-with-temp-text "* H"
396 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
397 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
398 ;; Completed tasks are never close.
399 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
400 (org-test-with-temp-text "* TODO Heading"
401 (should (org-deadline-close-p "2016-06-03")))
402 (org-test-with-temp-text "* DONE Heading"
403 (should-not (org-deadline-close-p "2016-06-03"))))))
408 (ert-deftest test-org
/insert-property-drawer
()
409 "Test `org-insert-property-drawer' specifications."
410 ;; Error before first headline.
411 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
412 ;; Insert drawer right after headline if there is no planning line,
413 ;; or after it otherwise.
415 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text "* H\nParagraph<point>"
417 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
420 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
421 (org-test-with-temp-text
422 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
423 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
425 ;; Indent inserted drawer.
427 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
428 (org-test-with-temp-text "* H\nParagraph<point>"
429 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
431 ;; Handle insertion at eob.
433 (equal "* H\n:PROPERTIES:\n:END:\n"
434 (org-test-with-temp-text "* H"
435 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
437 ;; Skip inlinetasks before point.
438 (when (featurep 'org-inlinetask
)
440 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
441 (org-test-with-temp-text
442 "* H\n*************** I\n*************** END\nP<point>"
443 (let ((org-adapt-indentation nil
)
444 (org-inlinetask-min-level 15))
445 (org-insert-property-drawer))
447 ;; Correctly set drawer in an inlinetask.
448 (when (featurep 'org-inlinetask
)
450 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
451 (org-test-with-temp-text
452 "* H\n*************** I\nP<point>\n*************** END"
453 (let ((org-adapt-indentation nil
)
454 (org-inlinetask-min-level 15))
455 (org-insert-property-drawer))
461 (ert-deftest test-org
/fill-element
()
462 "Test `org-fill-element' specifications."
463 ;; At an Org table, align it.
466 (org-test-with-temp-text "|a|"
470 (equal "#+name: table\n| a |\n"
471 (org-test-with-temp-text "#+name: table\n| a |\n"
474 ;; At a paragraph, preserve line breaks.
475 (org-test-with-temp-text "some \\\\\nlong\ntext"
476 (let ((fill-column 20))
478 (should (equal (buffer-string) "some \\\\\nlong text"))))
479 ;; Correctly fill a paragraph when point is at its very end.
482 (org-test-with-temp-text "A\nB"
483 (let ((fill-column 20))
484 (goto-char (point-max))
487 ;; Correctly fill the last paragraph of a greater element.
489 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
490 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
491 (let ((fill-column 8))
496 ;; Correctly fill an element in a narrowed buffer.
499 (org-test-with-temp-text "01234 6789"
500 (let ((fill-column 5))
501 (narrow-to-region 1 8)
504 ;; Handle `adaptive-fill-regexp' in paragraphs.
507 (org-test-with-temp-text "> a\n> b"
508 (let ((fill-column 5)
509 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
512 ;; Special case: Fill first paragraph when point is at an item or
513 ;; a plain-list or a footnote reference.
516 (org-test-with-temp-text "- A\n B"
517 (let ((fill-column 20))
522 (org-test-with-temp-text "[fn:1] A\nB"
523 (let ((fill-column 20))
526 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
527 (let ((fill-column 20))
529 (should (equal (buffer-string)
530 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
531 ;; Fill contents of `comment-block' elements.
534 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
535 (let ((fill-column 20))
539 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
540 ;; Fill `comment' elements.
543 (org-test-with-temp-text " # A\n # B"
544 (let ((fill-column 20))
547 ;; Do not mix consecutive comments when filling one of them.
549 (equal "# A B\n\n# C"
550 (org-test-with-temp-text "# A\n# B\n\n# C"
551 (let ((fill-column 20))
554 ;; Use commented empty lines as separators when filling comments.
556 (equal "# A B\n#\n# C"
557 (org-test-with-temp-text "# A\n# B\n#\n# C"
558 (let ((fill-column 20))
561 ;; Handle `adaptive-fill-regexp' in comments.
564 (org-test-with-temp-text "# > a\n# > b"
565 (let ((fill-column 20)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
569 ;; Do nothing at affiliated keywords.
571 (equal "#+NAME: para\nSome\ntext."
572 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
573 (let ((fill-column 20))
576 ;; Do not move point after table when filling a table.
578 (org-test-with-temp-text "| a | b |\n| c | d |\n"
582 ;; Do not fill "n" macro, with or without arguments, followed by
583 ;; a dot or a closing parenthesis since it could be confused with
584 ;; a numbered bullet.
586 (equal "123456789\n{{{n}}}."
587 (org-test-with-temp-text "123456789 {{{n}}}."
588 (let ((fill-column 10))
592 (equal "123456789\n{{{n}}}\)"
593 (org-test-with-temp-text "123456789 {{{n}}}\)"
594 (let ((fill-column 10))
598 (equal "123456789\n{{{n()}}}."
599 (org-test-with-temp-text "123456789 {{{n()}}}."
600 (let ((fill-column 10))
604 (equal "123456789\n{{{n(counter)}}}."
605 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
606 (let ((fill-column 10))
610 (ert-deftest test-org
/auto-fill-function
()
611 "Test auto-filling features."
612 ;; Auto fill paragraph.
615 (org-test-with-temp-text "12345 7890"
616 (let ((fill-column 5))
618 (org-auto-fill-function)
620 ;; Auto fill first paragraph in an item.
622 (equal "- 12345\n 7890"
623 (org-test-with-temp-text "- 12345 7890"
624 (let ((fill-column 7))
626 (org-auto-fill-function)
628 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
630 (equal "> 12345\n 7890"
631 (org-test-with-temp-text "> 12345 7890"
632 (let ((fill-column 10)
633 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
634 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
636 (org-auto-fill-function)
639 (equal "> 12345\n> 12345\n> 7890"
640 (org-test-with-temp-text "> 12345\n> 12345 7890"
641 (let ((fill-column 10)
642 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
643 (goto-char (point-max))
644 (org-auto-fill-function)
647 (equal " 12345\n *12345\n *12345"
648 (org-test-with-temp-text " 12345\n *12345 12345"
649 (let ((fill-column 10)
650 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
651 (goto-char (point-max))
652 (org-auto-fill-function)
654 ;; Auto fill comments.
656 (equal " # 12345\n # 7890"
657 (org-test-with-temp-text " # 12345 7890"
658 (let ((fill-column 10))
660 (org-auto-fill-function)
662 ;; A hash within a line isn't a comment.
664 (equal "12345 # 7890\n# 1"
665 (org-test-with-temp-text "12345 # 7890 1"
666 (let ((fill-column 12))
668 (org-auto-fill-function)
670 ;; Correctly interpret empty prefix.
672 (equal "# a\n# b\nRegular\n# paragraph"
673 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
674 (let ((fill-column 12))
676 (org-auto-fill-function)
678 ;; Comment block: auto fill contents.
680 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
681 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
682 (let ((fill-column 5))
685 (org-auto-fill-function)
688 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
689 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
690 (let ((fill-column 5))
693 (org-auto-fill-function)
695 ;; Do not fill if a new item could be created.
698 (org-test-with-temp-text "12345 - 90"
699 (let ((fill-column 5))
701 (org-auto-fill-function)
703 ;; Do not fill if a line break could be introduced.
705 (equal "123\\\\\n7890"
706 (org-test-with-temp-text "123\\\\ 7890"
707 (let ((fill-column 6))
709 (org-auto-fill-function)
711 ;; Do not fill affiliated keywords.
713 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
714 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
715 (let ((fill-column 20))
717 (org-auto-fill-function)
724 (ert-deftest test-org
/indent-line
()
725 "Test `org-indent-line' specifications."
726 ;; Do not indent diary sexps, footnote definitions or headlines.
729 (org-test-with-temp-text "%%(org-calendar-holiday)"
731 (org-get-indentation))))
734 (org-test-with-temp-text "[fn:1] fn"
735 (let ((org-adapt-indentation t
)) (org-indent-line))
736 (org-get-indentation))))
739 (org-test-with-temp-text "* H"
741 (org-get-indentation))))
742 ;; Do not indent before first headline.
745 (org-test-with-temp-text ""
747 (org-get-indentation))))
748 ;; Indent according to headline level otherwise, unless
749 ;; `org-adapt-indentation' is nil.
752 (org-test-with-temp-text "* H\n<point>A"
753 (let ((org-adapt-indentation t
)) (org-indent-line))
754 (org-get-indentation))))
757 (org-test-with-temp-text "* H\n<point>\nA"
758 (let ((org-adapt-indentation t
)) (org-indent-line))
759 (org-get-indentation))))
762 (org-test-with-temp-text "* H\n<point>A"
763 (let ((org-adapt-indentation nil
)) (org-indent-line))
764 (org-get-indentation))))
765 ;; Indenting preserves point position.
767 (org-test-with-temp-text "* H\nA<point>B"
768 (let ((org-adapt-indentation t
)) (org-indent-line))
770 ;; Do not change indentation at an item or a LaTeX environment.
773 (org-test-with-temp-text "* H\n<point> - A"
774 (let ((org-adapt-indentation t
)) (org-indent-line))
775 (org-get-indentation))))
778 (org-test-with-temp-text
779 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
781 (org-get-indentation))))
782 ;; On blank lines at the end of a list, indent like last element
783 ;; within it if the line is still in the list. If the last element
784 ;; is an item, indent like its contents. Otherwise, indent like the
788 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
789 (let ((org-adapt-indentation t
)) (org-indent-line))
790 (org-get-indentation))))
793 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
794 (let ((org-adapt-indentation t
)) (org-indent-line))
795 (org-get-indentation))))
798 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
799 (let ((org-adapt-indentation t
)) (org-indent-line))
800 (org-get-indentation))))
803 (org-test-with-temp-text "* H\n- A\n - \n<point>"
804 (let ((org-adapt-indentation t
)) (org-indent-line))
805 (org-get-indentation))))
808 (org-test-with-temp-text
809 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
810 (let ((org-adapt-indentation t
)) (org-indent-line))
811 (org-get-indentation))))
814 (org-test-with-temp-text "- A\n B\n\n<point>"
815 (let ((org-adapt-indentation nil
)) (org-indent-line))
816 (org-get-indentation))))
819 (org-test-with-temp-text
820 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
821 (let ((org-adapt-indentation nil
)) (org-indent-line))
822 (org-get-indentation))))
823 ;; Likewise, on a blank line at the end of a footnote definition,
824 ;; indent at column 0 if line belongs to the definition. Otherwise,
825 ;; indent like the definition itself.
828 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
829 (let ((org-adapt-indentation t
)) (org-indent-line))
830 (org-get-indentation))))
833 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
834 (let ((org-adapt-indentation t
)) (org-indent-line))
835 (org-get-indentation))))
836 ;; After the end of the contents of a greater element, indent like
837 ;; the beginning of the element.
840 (org-test-with-temp-text
841 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
843 (org-get-indentation))))
844 ;; On blank lines after a paragraph, indent like its last non-empty
848 (org-test-with-temp-text " Paragraph\n\n<point>"
850 (org-get-indentation))))
851 ;; At the first line of an element, indent like previous element's
852 ;; first line, ignoring footnotes definitions and inline tasks, or
853 ;; according to parent.
856 (org-test-with-temp-text "A\n\n B\n\nC<point>"
858 (org-get-indentation))))
861 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
863 (org-get-indentation))))
866 (org-test-with-temp-text
867 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
869 (org-get-indentation))))
870 ;; Within code part of a source block, use language major mode if
871 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
872 ;; according to line above.
875 (org-test-with-temp-text
876 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
877 (let ((org-src-tab-acts-natively t
)
878 (org-edit-src-content-indentation 0))
880 (org-get-indentation))))
883 (org-test-with-temp-text
884 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
885 (let ((org-src-tab-acts-natively nil
)
886 (org-edit-src-content-indentation 0))
888 (org-get-indentation))))
889 ;; Otherwise, indent like the first non-blank line above.
892 (org-test-with-temp-text
893 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
895 (org-get-indentation))))
896 ;; Align node properties according to `org-property-format'. Handle
897 ;; nicely empty values.
899 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
900 (org-test-with-temp-text
901 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
902 (let ((org-property-format "%-10s %s")) (org-indent-line))
905 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
906 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
907 (let ((org-property-format "%-10s %s")) (org-indent-line))
910 (ert-deftest test-org
/indent-region
()
911 "Test `org-indent-region' specifications."
915 (org-test-with-temp-text " A\nB\n C"
916 (org-indent-region (point-min) (point-max))
918 ;; Indent greater elements along with their contents.
920 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
921 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
922 (org-indent-region (point-min) (point-max))
924 ;; Ignore contents of verse blocks. Only indent block delimiters.
926 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
927 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
928 (org-indent-region (point-min) (point-max))
931 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
932 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
933 (org-indent-region (point-min) (point-max))
935 ;; Indent example blocks as a single block, unless indentation
936 ;; should be preserved. In this case only indent the block markers.
938 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
939 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
940 (org-indent-region (point-min) (point-max))
943 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
944 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
945 (org-indent-region (point-min) (point-max))
948 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
949 (org-test-with-temp-text
950 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
951 (org-indent-region (point-min) (point-max))
954 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
955 (org-test-with-temp-text
956 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
957 (let ((org-src-preserve-indentation t
))
958 (org-indent-region (point-min) (point-max)))
960 ;; Treat export blocks as a whole.
962 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
963 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
964 (org-indent-region (point-min) (point-max))
967 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
968 (org-test-with-temp-text
969 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
970 (org-indent-region (point-min) (point-max))
972 ;; Indent according to mode if `org-src-tab-acts-natively' is
973 ;; non-nil. Otherwise, do not indent code at all.
975 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
976 (org-test-with-temp-text
977 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
978 (let ((org-src-tab-acts-natively t
)
979 (org-edit-src-content-indentation 0))
980 (org-indent-region (point-min) (point-max)))
983 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
984 (org-test-with-temp-text
985 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
986 (let ((org-src-tab-acts-natively nil
)
987 (org-edit-src-content-indentation 0))
988 (org-indent-region (point-min) (point-max)))
990 ;; Align node properties according to `org-property-format'. Handle
991 ;; nicely empty values.
993 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
994 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
995 (let ((org-property-format "%-10s %s")
996 (org-adapt-indentation nil
))
997 (org-indent-region (point) (point-max)))
1000 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
1001 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
1002 (let ((org-property-format "%-10s %s")
1003 (org-adapt-indentation nil
))
1004 (org-indent-region (point) (point-max)))
1006 ;; Indent plain lists.
1008 (equal "- A\n B\n - C\n\n D"
1009 (org-test-with-temp-text "- A\n B\n - C\n\n D"
1010 (org-indent-region (point-min) (point-max))
1014 (org-test-with-temp-text " - A\n\n - B"
1015 (org-indent-region (point-min) (point-max))
1017 ;; Indent footnote definitions.
1019 (equal "[fn:1] Definition\n\nDefinition"
1020 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1021 (org-indent-region (point-min) (point-max))
1023 ;; Special case: Start indenting on a blank line.
1025 (equal "\nParagraph"
1026 (org-test-with-temp-text "\n Paragraph"
1027 (org-indent-region (point-min) (point-max))
1034 (ert-deftest test-org
/delete-indentation
()
1035 "Test `org-delete-indentation' specifications."
1037 (should (equal "foo bar"
1038 (org-test-with-temp-text
1040 (org-delete-indentation)
1042 ;; With optional argument.
1043 (should (equal "foo bar"
1044 (org-test-with-temp-text
1046 (org-delete-indentation t
)
1048 ;; At headline text should be appended to the headline text.
1050 (equal"* foo bar :tag:"
1051 (let (org-auto-align-tags)
1052 (org-test-with-temp-text
1053 "* foo :tag:\n bar<point>"
1054 (org-delete-indentation)
1057 (equal "* foo bar :tag:"
1058 (let (org-auto-align-tags)
1059 (org-test-with-temp-text
1060 "* foo <point>:tag:\n bar"
1061 (org-delete-indentation t
)
1062 (buffer-string))))))
1064 (ert-deftest test-org
/return
()
1065 "Test `org-return' specifications."
1068 (equal "Para\ngraph"
1069 (org-test-with-temp-text "Para<point>graph"
1072 ;; With optional argument, indent line.
1074 (equal " Para\n graph"
1075 (org-test-with-temp-text " Para<point>graph"
1078 ;; On a table, call `org-table-next-row'.
1080 (org-test-with-temp-text "| <point>a |\n| b |"
1082 (looking-at-p "b")))
1083 ;; Open link or timestamp under point when `org-return-follows-link'
1086 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1087 (let ((org-return-follows-link t
)
1088 (org-link-search-must-match-exact-headline nil
))
1090 (looking-at-p "<<target>>")))
1092 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1093 (let ((org-return-follows-link nil
)) (org-return))
1094 (looking-at-p "<<target>>")))
1096 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1097 (let ((org-return-follows-link t
)) (org-return))
1098 (looking-at-p "* b")))
1100 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1101 (let ((org-return-follows-link t
)
1102 (org-link-search-must-match-exact-headline nil
))
1104 (looking-at-p "<<target>>")))
1106 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1107 (let ((org-return-follows-link t
)
1108 (org-link-search-must-match-exact-headline nil
))
1110 (looking-at-p "<<target>>")))
1111 ;; When `org-return-follows-link' is non-nil, tolerate links and
1112 ;; timestamps in comments, node properties, etc.
1114 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1115 (let ((org-return-follows-link t
)
1116 (org-link-search-must-match-exact-headline nil
))
1118 (looking-at-p "<<target>>")))
1120 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1121 (let ((org-return-follows-link nil
)) (org-return))
1122 (looking-at-p "<<target>>")))
1124 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1125 (let ((org-return-follows-link t
)
1126 (org-link-search-must-match-exact-headline nil
))
1128 (looking-at-p "<<target>>")))
1129 ;; However, do not open link when point is in a table.
1131 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1132 (let ((org-return-follows-link t
)) (org-return))
1133 (looking-at-p "between")))
1134 ;; Special case: in a list, when indenting, do not break structure.
1137 (org-test-with-temp-text "- A <point>B"
1142 (org-test-with-temp-text "- A\n<point>- B"
1145 ;; On tags part of a headline, add a newline below it instead of
1148 (equal "* H :tag:\n"
1149 (org-test-with-temp-text "* H :<point>tag:"
1152 ;; Before headline text, add a newline below it instead of breaking
1155 (equal "* TODO H :tag:\n"
1156 (org-test-with-temp-text "* <point>TODO H :tag:"
1160 (equal "* TODO [#B] H :tag:\n"
1161 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1164 (should ;TODO are case-sensitive
1166 (org-test-with-temp-text "* <point>Todo"
1169 ;; At headline text, break headline text but preserve tags.
1171 (equal "* TODO [#B] foo :tag:\nbar"
1172 (let (org-auto-align-tags)
1173 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1176 ;; At bol of headline insert newline.
1179 (org-test-with-temp-text "<point>* h"
1182 ;; Refuse to leave invalid headline in buffer.
1185 (org-test-with-temp-text "*<point> h"
1189 (ert-deftest test-org
/meta-return
()
1190 "Test M-RET (`org-meta-return') specifications."
1191 ;; In a table field insert a row above.
1193 (org-test-with-temp-text "| a |"
1197 (looking-at "| |$")))
1198 ;; In a paragraph change current line into a header.
1200 (org-test-with-temp-text "a"
1203 (looking-at "\* a$")))
1204 ;; In an item insert an item, in this case above.
1206 (org-test-with-temp-text "- a"
1209 (looking-at "- $")))
1210 ;; In a drawer and item insert an item, in this case above.
1212 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1216 (looking-at "- $"))))
1218 (ert-deftest test-org
/insert-heading
()
1219 "Test `org-insert-heading' specifications."
1220 ;; In an empty buffer, insert a new headline.
1223 (org-test-with-temp-text ""
1224 (org-insert-heading)
1226 ;; At the beginning of a line, turn it into a headline.
1229 (org-test-with-temp-text "<point>P"
1230 (org-insert-heading)
1232 ;; In the middle of a line, split the line if allowed, otherwise,
1233 ;; insert the headline at its end.
1235 (equal "Para\n* graph"
1236 (org-test-with-temp-text "Para<point>graph"
1237 (let ((org-M-RET-may-split-line '((default . t
))))
1238 (org-insert-heading))
1241 (equal "Paragraph\n* "
1242 (org-test-with-temp-text "Para<point>graph"
1243 (let ((org-M-RET-may-split-line '((default . nil
))))
1244 (org-insert-heading))
1246 ;; At the beginning of a headline, create one above.
1249 (org-test-with-temp-text "* H"
1250 (org-insert-heading)
1252 ;; In the middle of a headline, split it if allowed.
1255 (org-test-with-temp-text "* H<point>1"
1256 (let ((org-M-RET-may-split-line '((headline . t
))))
1257 (org-insert-heading))
1261 (org-test-with-temp-text "* H<point>1"
1262 (let ((org-M-RET-may-split-line '((headline . nil
))))
1263 (org-insert-heading))
1265 ;; However, splitting cannot happen on TODO keywords, priorities or
1268 (equal "* TODO H1\n* \n"
1269 (org-test-with-temp-text "* TO<point>DO H1"
1270 (let ((org-M-RET-may-split-line '((headline . t
))))
1271 (org-insert-heading))
1274 (equal "* [#A] H1\n* \n"
1275 (org-test-with-temp-text "* [#<point>A] H1"
1276 (let ((org-M-RET-may-split-line '((headline . t
))))
1277 (org-insert-heading))
1280 (equal "* H1 :tag:\n* \n"
1281 (org-test-with-temp-text "* H1 :ta<point>g:"
1282 (let ((org-M-RET-may-split-line '((headline . t
))))
1283 (org-insert-heading))
1285 ;; New headline level depends on the level of the headline above.
1288 (org-test-with-temp-text "** H\n<point>P"
1289 (org-insert-heading)
1292 (equal "** H\nPara\n** graph"
1293 (org-test-with-temp-text "** H\nPara<point>graph"
1294 (let ((org-M-RET-may-split-line '((default . t
))))
1295 (org-insert-heading))
1299 (org-test-with-temp-text "** H"
1300 (org-insert-heading)
1302 ;; When called with one universal argument, insert a new headline at
1303 ;; the end of the current subtree, independently on the position of
1308 (org-test-with-temp-text "* H1\n** H2"
1309 (let ((org-insert-heading-respect-content nil
))
1310 (org-insert-heading '(4)))
1315 (org-test-with-temp-text "* H<point>1\n** H2"
1316 (let ((org-insert-heading-respect-content nil
))
1317 (org-insert-heading '(4)))
1319 ;; When called with two universal arguments, insert a new headline
1320 ;; at the end of the grandparent subtree.
1322 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1323 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1324 (let ((org-insert-heading-respect-content nil
))
1325 (org-insert-heading '(16)))
1327 ;; When optional TOP-LEVEL argument is non-nil, always insert
1328 ;; a level 1 heading.
1330 (equal "* H1\n** H2\n* \n"
1331 (org-test-with-temp-text "* H1\n** H2<point>"
1332 (org-insert-heading nil nil t
)
1335 (equal "* H1\n- item\n* "
1336 (org-test-with-temp-text "* H1\n- item<point>"
1337 (org-insert-heading nil nil t
)
1339 ;; Obey `org-blank-before-new-entry'.
1341 (equal "* H1\n\n* \n"
1342 (org-test-with-temp-text "* H1<point>"
1343 (let ((org-blank-before-new-entry '((heading . t
))))
1344 (org-insert-heading))
1348 (org-test-with-temp-text "* H1<point>"
1349 (let ((org-blank-before-new-entry '((heading . nil
))))
1350 (org-insert-heading))
1353 (equal "* H1\n* H2\n* \n"
1354 (org-test-with-temp-text "* H1\n* H2<point>"
1355 (let ((org-blank-before-new-entry '((heading . auto
))))
1356 (org-insert-heading))
1359 (equal "* H1\n\n* H2\n\n* \n"
1360 (org-test-with-temp-text "* H1\n\n* H2<point>"
1361 (let ((org-blank-before-new-entry '((heading . auto
))))
1362 (org-insert-heading))
1364 ;; Corner case: correctly insert a headline after an empty one.
1367 (org-test-with-temp-text "* <point>"
1368 (org-insert-heading)
1371 (org-test-with-temp-text "* <point>\n"
1372 (org-insert-heading)
1373 (looking-at-p "\n\\'")))
1374 ;; Do not insert spurious headlines when inserting a new headline.
1376 (equal "* H1\n* H2\n* \n"
1377 (org-test-with-temp-text "* H1\n* H2<point>\n"
1378 (org-insert-heading)
1380 ;; Preserve visibility at beginning of line. In particular, when
1381 ;; removing spurious blank lines, do not visually merge heading with
1382 ;; the line visible above.
1384 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1386 (let ((org-blank-before-new-entry '((heading . nil
))))
1387 (org-insert-heading '(4)))
1388 (invisible-p (line-end-position 0))))
1389 ;; Properly handle empty lines when forcing a headline below current
1392 (equal "* H1\n\n* H\n\n* \n"
1393 (org-test-with-temp-text "* H1\n\n* H<point>"
1394 (let ((org-blank-before-new-entry '((heading . t
))))
1395 (org-insert-heading '(4))
1396 (buffer-string))))))
1398 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1399 "Test `org-insert-todo-heading-respect-content' specifications."
1400 ;; Create a TODO heading.
1402 (org-test-with-temp-text "* H1\n Body"
1403 (org-insert-todo-heading-respect-content)
1404 (nth 2 (org-heading-components))))
1405 ;; Add headline at the end of the first subtree
1409 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1410 (org-insert-todo-heading-respect-content)
1411 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1412 ;; In a list, do not create a new item.
1416 (org-test-with-temp-text "* H\n- an item\n- another one"
1417 (search-forward "an ")
1418 (org-insert-todo-heading-respect-content)
1419 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1420 ;; Use the same TODO keyword as current heading.
1424 (org-test-with-temp-text "* TODO\n** WAITING\n"
1425 (org-insert-todo-heading-respect-content)
1426 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1428 (ert-deftest test-org
/clone-with-time-shift
()
1429 "Test `org-clone-subtree-with-time-shift'."
1430 ;; Raise an error before first heading.
1432 (org-test-with-temp-text ""
1433 (org-clone-subtree-with-time-shift 1)))
1434 ;; Raise an error on invalid number of clones.
1436 (org-test-with-temp-text "* Clone me"
1437 (org-clone-subtree-with-time-shift -
1)))
1438 ;; Clone non-repeating once.
1444 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1445 (org-clone-subtree-with-time-shift 1 "+2d")
1446 (replace-regexp-in-string
1447 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1449 ;; Clone repeating once.
1454 * H1\n<2015-06-25 +1w>
1456 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1457 (org-clone-subtree-with-time-shift 1 "+2d")
1458 (replace-regexp-in-string
1459 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1461 ;; Clone non-repeating zero times.
1466 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1467 (org-clone-subtree-with-time-shift 0 "+2d")
1468 (replace-regexp-in-string
1469 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1471 ;; Clone repeating "zero" times.
1475 * H1\n<2015-06-23 +1w>
1477 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1478 (org-clone-subtree-with-time-shift 0 "+2d")
1479 (replace-regexp-in-string
1480 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1482 ;; Clone with blank SHIFT argument.
1486 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1487 (org-clone-subtree-with-time-shift 1 "")
1488 (buffer-substring-no-properties (line-beginning-position 2)
1489 (line-end-position 2)))))
1490 ;; Find time stamps before point. If SHIFT is not specified, ask
1491 ;; for a time shift.
1495 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1496 (org-clone-subtree-with-time-shift 1 "+1d")
1497 (buffer-substring-no-properties (line-beginning-position 2)
1498 (line-end-position 2)))))
1502 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1503 (cl-letf (((symbol-function 'read-from-minibuffer
)
1504 (lambda (&rest args
) "+1d")))
1505 (org-clone-subtree-with-time-shift 1))
1506 (buffer-substring-no-properties (line-beginning-position 2)
1507 (line-end-position 2))))))
1510 ;;; Fixed-Width Areas
1512 (ert-deftest test-org
/toggle-fixed-width
()
1513 "Test `org-toggle-fixed-width' specifications."
1514 ;; No region: Toggle on fixed-width marker in paragraphs.
1517 (org-test-with-temp-text "A"
1518 (org-toggle-fixed-width)
1520 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1523 (org-test-with-temp-text ": A"
1524 (org-toggle-fixed-width)
1526 ;; No region: Toggle on marker in blank lines after elements or just
1527 ;; after a headline.
1530 (org-test-with-temp-text "* H\n"
1532 (org-toggle-fixed-width)
1535 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1536 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1537 (goto-char (point-max))
1538 (org-toggle-fixed-width)
1540 ;; No region: Toggle on marker in front of one line elements (e.g.,
1541 ;; headlines, clocks)
1543 (equal ": * Headline"
1544 (org-test-with-temp-text "* Headline"
1545 (org-toggle-fixed-width)
1548 (equal ": #+KEYWORD: value"
1549 (org-test-with-temp-text "#+KEYWORD: value"
1550 (org-toggle-fixed-width)
1552 ;; No region: error in other situations.
1554 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1556 (org-toggle-fixed-width)
1558 ;; No region: Indentation is preserved.
1561 (org-test-with-temp-text "- A\n B"
1563 (org-toggle-fixed-width)
1565 ;; Region: If it contains only fixed-width elements and blank lines,
1566 ;; toggle off fixed-width markup.
1569 (org-test-with-temp-text ": A\n\n: B"
1570 (transient-mark-mode 1)
1571 (push-mark (point) t t
)
1572 (goto-char (point-max))
1573 (org-toggle-fixed-width)
1575 ;; Region: If it contains anything else, toggle on fixed-width but
1576 ;; not on fixed-width areas.
1578 (equal ": A\n: \n: B\n: \n: C"
1579 (org-test-with-temp-text "A\n\n: B\n\nC"
1580 (transient-mark-mode 1)
1581 (push-mark (point) t t
)
1582 (goto-char (point-max))
1583 (org-toggle-fixed-width)
1585 ;; Region: Ignore blank lines at its end, unless it contains only
1589 (org-test-with-temp-text "A\n\n"
1590 (transient-mark-mode 1)
1591 (push-mark (point) t t
)
1592 (goto-char (point-max))
1593 (org-toggle-fixed-width)
1597 (org-test-with-temp-text "\n\n"
1598 (transient-mark-mode 1)
1599 (push-mark (point) t t
)
1600 (goto-char (point-max))
1601 (org-toggle-fixed-width)
1608 (ert-deftest test-org
/get-heading
()
1609 "Test `org-get-heading' specifications."
1610 ;; Return current heading, even if point is not on it.
1613 (org-test-with-temp-text "* H"
1614 (org-get-heading))))
1617 (org-test-with-temp-text "* H\nText<point>"
1618 (org-get-heading))))
1619 ;; Without any optional argument, return TODO keyword, priority
1620 ;; cookie, COMMENT keyword and tags.
1623 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1624 (org-get-heading))))
1627 (org-test-with-temp-text "* [#A] H"
1628 (org-get-heading))))
1631 (org-test-with-temp-text "* COMMENT H"
1632 (org-get-heading))))
1635 (org-test-with-temp-text "* H :tag:"
1636 (org-get-heading))))
1637 ;; With NO-TAGS argument, ignore tags.
1640 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1641 (org-get-heading t
))))
1644 (org-test-with-temp-text "* H :tag:"
1645 (org-get-heading t
))))
1646 ;; With NO-TODO, ignore TODO keyword.
1649 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1650 (org-get-heading nil t
))))
1653 (org-test-with-temp-text "* H :tag:"
1654 (org-get-heading nil t
))))
1655 ;; TODO keywords are case-sensitive.
1658 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1659 (org-get-heading nil t
))))
1660 ;; With NO-PRIORITY, ignore priority.
1663 (org-test-with-temp-text "* [#A] H"
1664 (org-get-heading nil nil t
))))
1667 (org-test-with-temp-text "* H"
1668 (org-get-heading nil nil t
))))
1671 (org-test-with-temp-text "* TODO [#A] H"
1672 (org-get-heading nil nil t
))))
1673 ;; With NO-COMMENT, ignore COMMENT keyword.
1676 (org-test-with-temp-text "* COMMENT H"
1677 (org-get-heading nil nil nil t
))))
1680 (org-test-with-temp-text "* H"
1681 (org-get-heading nil nil nil t
))))
1683 (equal "TODO [#A] H"
1684 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1685 (org-get-heading nil nil nil t
))))
1686 ;; On an empty headline, return value is consistent.
1687 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1688 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1689 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1690 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1692 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1694 (ert-deftest test-org
/in-commented-heading-p
()
1695 "Test `org-in-commented-heading-p' specifications."
1696 ;; Commented headline.
1698 (org-test-with-temp-text "* COMMENT Headline\nBody"
1699 (goto-char (point-max))
1700 (org-in-commented-heading-p)))
1701 ;; Commented ancestor.
1703 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1704 (goto-char (point-max))
1705 (org-in-commented-heading-p)))
1706 ;; Comment keyword is case-sensitive.
1708 (org-test-with-temp-text "* Comment Headline\nBody"
1709 (goto-char (point-max))
1710 (org-in-commented-heading-p)))
1711 ;; Keyword is standalone.
1713 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1714 (goto-char (point-max))
1715 (org-in-commented-heading-p)))
1716 ;; Optional argument.
1718 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1719 (goto-char (point-max))
1720 (org-in-commented-heading-p t
))))
1722 (ert-deftest test-org
/entry-blocked-p
()
1723 ;; Check other dependencies.
1725 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1726 (let ((org-enforce-todo-dependencies t
)
1728 '(org-block-todo-from-children-or-siblings-or-parent)))
1729 (org-entry-blocked-p))))
1731 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1732 (let ((org-enforce-todo-dependencies t
)
1734 '(org-block-todo-from-children-or-siblings-or-parent)))
1735 (org-entry-blocked-p))))
1736 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1739 (org-test-with-temp-text "* Blocked\n** TODO one"
1740 (let ((org-enforce-todo-dependencies t
)
1742 '(org-block-todo-from-children-or-siblings-or-parent)))
1743 (org-entry-blocked-p))))
1745 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1746 (let ((org-enforce-todo-dependencies t
)
1748 '(org-block-todo-from-children-or-siblings-or-parent)))
1749 (org-entry-blocked-p))))
1750 ;; Follow :ORDERED: specifications.
1752 (org-test-with-temp-text
1753 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1754 (let ((org-enforce-todo-dependencies t
)
1756 '(org-block-todo-from-children-or-siblings-or-parent)))
1757 (org-entry-blocked-p))))
1759 (org-test-with-temp-text
1760 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1761 (let ((org-enforce-todo-dependencies t
)
1763 '(org-block-todo-from-children-or-siblings-or-parent)))
1764 (org-entry-blocked-p)))))
1766 (ert-deftest test-org
/get-outline-path
()
1767 "Test `org-get-outline-path' specifications."
1768 ;; Top-level headlines have no outline path.
1770 (org-test-with-temp-text "* H"
1771 (org-get-outline-path)))
1772 ;; Otherwise, outline path is the path leading to the headline.
1775 (org-test-with-temp-text "* H\n** S<point>"
1776 (org-get-outline-path))))
1777 ;; Find path even when point is not on a headline.
1780 (org-test-with-temp-text "* H\n** S\nText<point>"
1781 (org-get-outline-path))))
1782 ;; TODO keywords, tags and statistics cookies are ignored.
1785 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1786 (org-get-outline-path))))
1787 ;; Links are replaced with their description or their path.
1790 (org-test-with-temp-text
1791 "* [[http://orgmode.org][Org]]\n** S<point>"
1792 (org-get-outline-path))))
1794 (equal '("http://orgmode.org")
1795 (org-test-with-temp-text
1796 "* [[http://orgmode.org]]\n** S<point>"
1797 (org-get-outline-path))))
1798 ;; When WITH-SELF is non-nil, include current heading.
1801 (org-test-with-temp-text "* H"
1802 (org-get-outline-path t
))))
1805 (org-test-with-temp-text "* H\n** S\nText<point>"
1806 (org-get-outline-path t
))))
1807 ;; Using cache is transparent to the user.
1810 (org-test-with-temp-text "* H\n** S<point>"
1811 (setq org-outline-path-cache nil
)
1812 (org-get-outline-path nil t
))))
1813 ;; Do not corrupt cache when finding outline path in distant part of
1817 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1818 (setq org-outline-path-cache nil
)
1819 (org-get-outline-path nil t
)
1820 (search-forward "S2")
1821 (org-get-outline-path nil t
))))
1822 ;; Do not choke on empty headlines.
1824 (org-test-with-temp-text "* H\n** <point>"
1825 (org-get-outline-path)))
1827 (org-test-with-temp-text "* \n** H<point>"
1828 (org-get-outline-path))))
1830 (ert-deftest test-org
/format-outline-path
()
1831 "Test `org-format-outline-path' specifications."
1833 (string= (org-format-outline-path (list "one" "two" "three"))
1837 (string= (org-format-outline-path '())
1840 (string= (org-format-outline-path '(nil))
1842 ;; Empty path and prefix.
1844 (string= (org-format-outline-path '() nil
">>")
1846 ;; Trailing whitespace in headings.
1848 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1850 ;; Non-default prefix and separators.
1852 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1853 ">>|one|two|three"))
1856 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1858 ;; Give a very narrow width.
1860 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1862 ;; Give a prefix that extends beyond the width.
1864 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1868 (ert-deftest test-org
/map-entries
()
1869 "Test `org-map-entries' specifications."
1873 (org-test-with-temp-text "* Level 1\n** Level 2"
1874 (org-map-entries #'point
))))
1878 (org-test-with-temp-text "* Level 1\n** Level 2"
1879 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1882 (org-test-with-temp-text "* Level 1\n** Level 2"
1883 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1887 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1888 (org-map-entries #'point
"yes"))))
1891 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1892 (org-map-entries #'point
"+yes-a"))))
1895 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1896 (org-map-entries #'point
"{yes?}"))))
1900 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1901 (org-map-entries #'point
"PRIORITY=\"A\""))))
1905 (org-test-with-temp-text "
1907 SCHEDULED: <2012-03-29 thu.>
1909 SCHEDULED: <2014-03-04 tue.>"
1910 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1913 (org-test-with-temp-text "
1915 SCHEDULED: <2012-03-29 thu.>
1917 SCHEDULED: <2014-03-04 tue.>"
1918 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1919 ;; Regular property match.
1922 (org-test-with-temp-text "
1931 (org-map-entries #'point
"TEST=1"))))
1932 ;; Multiple criteria.
1935 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1936 (let (org-odd-levels-only
1937 (org-use-tag-inheritance nil
))
1938 (org-map-entries #'point
"yes+LEVEL=1")))))
1942 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1943 (let (org-odd-levels-only)
1944 (org-map-entries #'point
"LEVEL=2|no")))))
1947 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1948 (let (org-odd-levels-only)
1949 (org-map-entries #'point
"yes|no")))))
1953 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1954 (let (org-odd-levels-only)
1955 (org-map-entries #'point
"yes&no"))))))
1957 (ert-deftest test-org
/edit-headline
()
1958 "Test `org-edit-headline' specifications."
1961 (org-test-with-temp-text "* A"
1962 (org-edit-headline "B")
1964 ;; Handle empty headings.
1967 (org-test-with-temp-text "* A"
1968 (org-edit-headline "")
1972 (org-test-with-temp-text "* "
1973 (org-edit-headline "A")
1975 ;; Handle TODO keywords and priority cookies.
1978 (org-test-with-temp-text "* TODO A"
1979 (org-edit-headline "B")
1983 (org-test-with-temp-text "* [#A] A"
1984 (org-edit-headline "B")
1987 (equal "* TODO [#A] B"
1988 (org-test-with-temp-text "* TODO [#A] A"
1989 (org-edit-headline "B")
1993 (org-test-with-temp-text "* A :tag:"
1994 (let ((org-tags-column 4)) (org-edit-headline "B"))
2001 (ert-deftest test-org
/set-regexps-and-options
()
2002 "Test `org-set-regexps-and-options' specifications."
2006 (let ((org-tag-alist '(("A")))
2007 (org-tag-persistent-alist nil
))
2008 (org-test-with-temp-text ""
2010 org-current-tag-alist
))))
2013 (let ((org-tag-alist '(("A")))
2014 (org-tag-persistent-alist nil
))
2015 (org-test-with-temp-text "#+TAGS: B"
2017 org-current-tag-alist
))))
2019 (equal '(("C") ("B"))
2020 (let ((org-tag-alist '(("A")))
2021 (org-tag-persistent-alist '(("C"))))
2022 (org-test-with-temp-text "#+TAGS: B"
2024 org-current-tag-alist
))))
2027 (let ((org-tag-alist '(("A")))
2028 (org-tag-persistent-alist '(("C"))))
2029 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2031 org-current-tag-alist
))))
2033 (equal '(("A" . ?a
) ("B") ("C"))
2034 (let ((org-tag-persistant-alist nil
))
2035 (org-test-with-temp-text "#+TAGS: A(a) B C"
2037 org-current-tag-alist
))))
2039 (equal '(("A") (:newline
) ("B"))
2040 (let ((org-tag-persistent-alist nil
))
2041 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2043 org-current-tag-alist
))))
2045 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2046 (let ((org-tag-persistent-alist nil
))
2047 (org-test-with-temp-text "#+TAGS: { A B } C"
2049 org-current-tag-alist
))))
2051 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2052 (let ((org-tag-persistent-alist nil
))
2053 (org-test-with-temp-text "#+TAGS: { A : B C }"
2055 org-current-tag-alist
))))
2057 (equal '(("A" "B" "C"))
2058 (let ((org-tag-persistent-alist nil
))
2059 (org-test-with-temp-text "#+TAGS: { A : B C }"
2061 org-tag-groups-alist
))))
2063 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2064 (let ((org-tag-persistent-alist nil
))
2065 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2067 org-current-tag-alist
))))
2069 (equal '(("A" "B" "C"))
2070 (let ((org-tag-persistent-alist nil
))
2071 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2073 org-tag-groups-alist
))))
2074 ;; FILETAGS keyword.
2076 (equal '("A" "B" "C")
2077 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2080 ;; PROPERTY keyword. Property names are case-insensitive.
2083 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2085 (cdr (assoc "var" org-file-properties
)))))
2089 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2091 (cdr (assoc "var" org-file-properties
)))))
2095 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2097 (cdr (assoc "var" org-file-properties
)))))
2101 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2103 org-archive-location
)))
2104 ;; CATEGORY keyword.
2107 (org-test-with-temp-text "#+CATEGORY: test"
2112 (org-test-with-temp-text "#+CATEGORY: test"
2114 (cdr (assoc "CATEGORY" org-file-properties
)))))
2117 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2118 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2120 org-columns-default-format
)))
2121 ;; CONSTANTS keyword. Constants names are case sensitive.
2123 (equal '("299792458." "3.14")
2124 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2127 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2131 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2133 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2136 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2138 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2143 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2145 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2147 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2151 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2153 (list org-highest-priority org-lowest-priority org-default-priority
))))
2157 (org-test-with-temp-text "#+PRIORITIES: X Z"
2159 (list org-highest-priority org-lowest-priority org-default-priority
))))
2163 (org-test-with-temp-text "#+STARTUP: fold odd"
2165 (list org-startup-folded org-odd-levels-only
))))
2168 (equal '(("A" "B") ("C"))
2169 (org-test-with-temp-text "#+TODO: A B | C"
2171 (list org-not-done-keywords org-done-keywords
))))
2173 (equal '(("A" "C") ("B" "D"))
2174 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2176 (list org-not-done-keywords org-done-keywords
))))
2178 (equal '(("A" "B") ("C"))
2179 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2181 (list org-not-done-keywords org-done-keywords
))))
2183 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2184 (org-test-with-temp-text "#+TODO: A(a)"
2186 org-todo-key-alist
)))
2188 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2189 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2191 org-todo-log-states
)))
2192 ;; Enter SETUPFILE keyword.
2195 (org-test-with-temp-text
2196 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2198 (cdr (assoc "a" org-file-properties
))))))
2206 (ert-deftest test-org
/coderef
()
2207 "Test coderef links specifications."
2209 (org-test-with-temp-text "
2210 #+BEGIN_SRC emacs-lisp
2215 (looking-at "(ref:sc)")))
2216 ;; Find coderef even with alternate label format.
2218 (org-test-with-temp-text "
2219 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2224 (looking-at "{ref:sc}"))))
2228 (ert-deftest test-org
/custom-id
()
2229 "Test custom ID links specifications."
2231 (org-test-with-temp-text
2232 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2234 (looking-at-p "\\* H1")))
2235 ;; Throw an error on false positives.
2237 (org-test-with-temp-text
2238 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2240 (looking-at-p "\\* H1"))))
2244 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2245 ;; a named element (#+name: text) and to headlines (* Text).
2247 (ert-deftest test-org
/fuzzy-links
()
2248 "Test fuzzy links specifications."
2249 ;; Fuzzy link goes in priority to a matching target.
2251 (org-test-with-temp-text
2252 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2253 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2254 (looking-at "<<Test>>")))
2255 ;; Then fuzzy link points to an element with a given name.
2257 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2258 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2259 (looking-at "#\\+NAME: Test")))
2260 ;; A target still lead to a matching headline otherwise.
2262 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2263 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2264 (looking-at "\\* Head2")))
2265 ;; With a leading star in link, enforce heading match.
2267 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2268 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2269 (looking-at "\\* Test")))
2270 ;; With a leading star in link, enforce exact heading match, even
2271 ;; with `org-link-search-must-match-exact-headline' set to nil.
2273 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2274 (let ((org-link-search-must-match-exact-headline nil
))
2275 (org-open-at-point))))
2276 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2278 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2279 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2280 (looking-at "\\* Test")))
2282 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2283 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2284 (looking-at "\\* Test")))
2285 ;; Heading match should not care about spaces, cookies, TODO
2286 ;; keywords, priorities, and tags. However, TODO keywords are
2290 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2291 (org-test-with-temp-text
2292 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2293 (let ((org-link-search-must-match-exact-headline nil
)
2294 (org-todo-regexp "TODO"))
2295 (org-open-at-point))
2296 (looking-at (regexp-quote first-line
)))))
2298 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2299 (let ((org-link-search-must-match-exact-headline nil
)
2300 (org-todo-regexp "TODO"))
2301 (org-open-at-point))))
2302 ;; Heading match should still be exact.
2304 (org-test-with-temp-text "
2305 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2308 (let ((org-link-search-must-match-exact-headline nil
)
2309 (org-todo-regexp "TODO"))
2310 (org-open-at-point))))
2312 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2313 (let ((org-link-search-must-match-exact-headline nil
)
2314 (org-todo-regexp "TODO"))
2315 (org-open-at-point))
2316 (looking-at-p (regexp-quote "** Test 1 2"))))
2317 ;; Heading match ignores COMMENT keyword.
2319 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2321 (looking-at "\\* COMMENT Test")))
2323 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2325 (looking-at "\\* TODO COMMENT Test")))
2326 ;; Correctly un-hexify fuzzy links.
2328 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2332 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2335 ;; Match search strings containing newline characters, including
2338 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2339 (let ((file (buffer-file-name)))
2340 (goto-char (point-max))
2341 (insert (format "[[file:%s::line1 line2]]" file
))
2343 (let ((org-link-search-must-match-exact-headline nil
))
2344 (org-open-at-point 0))
2345 (looking-at-p "line1"))))
2347 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2348 (let ((file (buffer-file-name)))
2349 (goto-char (point-max))
2350 (insert (format "[[file:%s::line1 line2]]" file
))
2352 (let ((org-link-search-must-match-exact-headline nil
))
2353 (org-open-at-point 0))
2354 (looking-at-p "line1")))))
2358 (ert-deftest test-org
/org-link-escape-ascii-character
()
2359 "Escape an ascii character."
2363 (org-link-escape "["))))
2365 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2366 "Escape an ascii control character."
2370 (org-link-escape "\t"))))
2372 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2373 "Escape an unicode multibyte character."
2377 (org-link-escape "€"))))
2379 (ert-deftest test-org
/org-link-escape-custom-table
()
2380 "Escape string with custom character table."
2384 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2386 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2387 "Escape string with custom table merged with default table."
2390 "%5BF%6F%6F%3A%42ar%0A%5D"
2391 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2393 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2394 "Unescape an ascii character."
2398 (org-link-unescape "%5B"))))
2400 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2401 "Unescpae an ascii control character."
2405 (org-link-unescape "%0A"))))
2407 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2408 "Unescape unicode multibyte character."
2412 (org-link-unescape "%E2%82%AC"))))
2414 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2415 "Unescape old style percent escaped character."
2418 "à âçèéêîôùû"
2419 (decode-coding-string
2420 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2422 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2423 "Escape and unescape a URL that includes an escaped char.
2424 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2427 "http://some.host.com/form?&id=blah%2Bblah25"
2429 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2433 (ert-deftest test-org
/open-at-point
/keyword
()
2434 "Does `org-open-at-point' open link in a keyword line?"
2436 (org-test-with-temp-text
2437 "<<top>>\n#+KEYWORD: <point>[[top]]"
2438 (org-open-at-point) t
))
2440 (org-test-with-temp-text
2441 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2442 (org-open-at-point) t
)))
2444 (ert-deftest test-org
/open-at-point
/property
()
2445 "Does `org-open-at-point' open link in property drawer?"
2447 (org-test-with-temp-text
2450 :URL: <point>[[*Headline]]
2452 (org-open-at-point) t
)))
2454 (ert-deftest test-org
/open-at-point
/comment
()
2455 "Does `org-open-at-point' open link in a commented line?"
2457 (org-test-with-temp-text
2458 "<<top>>\n# <point>[[top]]"
2459 (org-open-at-point) t
))
2461 (org-test-with-temp-text
2462 "* H\n<<top>>\n# <point>[[top]]"
2463 (org-open-at-point) t
)))
2465 (ert-deftest test-org
/open-at-point
/inline-image
()
2466 "Test `org-open-at-point' on nested links."
2468 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2472 (ert-deftest test-org
/open-at-point
/radio-target
()
2473 "Test `org-open-at-point' on radio targets."
2475 (org-test-with-temp-text "<<<target>>> <point>target"
2476 (org-update-radio-target-regexp)
2478 (eq (org-element-type (org-element-context)) 'radio-target
))))
2480 (ert-deftest test-org
/open-at-point
/tag
()
2481 "Test `org-open-at-point' on tags."
2483 (org-test-with-temp-text "* H :<point>tag:"
2485 (cl-letf (((symbol-function 'org-tags-view
)
2486 (lambda (&rest args
) (throw :result t
))))
2490 (org-test-with-temp-text-in-file "* H<point> :tag:"
2492 (cl-letf (((symbol-function 'org-tags-view
)
2493 (lambda (&rest args
) (throw :result t
))))
2499 (ert-deftest test-org
/store-link
()
2500 "Test `org-store-link' specifications."
2501 ;; On a headline, link to that headline. Use heading as the
2502 ;; description of the link.
2504 (let (org-store-link-props org-stored-links
)
2505 (org-test-with-temp-text-in-file "* H1"
2506 (let ((file (buffer-file-name)))
2507 (equal (format "[[file:%s::*H1][H1]]" file
)
2508 (org-store-link nil
))))))
2509 ;; On a headline, remove any link from description.
2511 (let (org-store-link-props org-stored-links
)
2512 (org-test-with-temp-text-in-file "* [[#l][d]]"
2513 (let ((file (buffer-file-name)))
2514 (equal (format "[[file:%s::*%s][d]]"
2516 (org-link-escape "[[#l][d]]"))
2517 (org-store-link nil
))))))
2519 (let (org-store-link-props org-stored-links
)
2520 (org-test-with-temp-text-in-file "* [[l]]"
2521 (let ((file (buffer-file-name)))
2522 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2523 (org-store-link nil
))))))
2525 (let (org-store-link-props org-stored-links
)
2526 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2527 (let ((file (buffer-file-name)))
2528 (equal (format "[[file:%s::*%s][d1 d2]]"
2530 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2531 (org-store-link nil
))))))
2532 ;; On a named element, link to that element.
2534 (let (org-store-link-props org-stored-links
)
2535 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2536 (let ((file (buffer-file-name)))
2537 (equal (format "[[file:%s::foo][foo]]" file
)
2538 (org-store-link nil
))))))
2539 ;; Store link to Org buffer, with context.
2541 (let ((org-stored-links nil
)
2542 (org-id-link-to-org-use-id nil
)
2543 (org-context-in-file-links t
))
2544 (org-test-with-temp-text-in-file "* h1"
2545 (let ((file (buffer-file-name)))
2546 (equal (format "[[file:%s::*h1][h1]]" file
)
2547 (org-store-link nil
))))))
2548 ;; Store link to Org buffer, without context.
2550 (let ((org-stored-links nil
)
2551 (org-id-link-to-org-use-id nil
)
2552 (org-context-in-file-links nil
))
2553 (org-test-with-temp-text-in-file "* h1"
2554 (let ((file (buffer-file-name)))
2555 (equal (format "[[file:%s][file:%s]]" file file
)
2556 (org-store-link nil
))))))
2557 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2559 (let ((org-stored-links nil
)
2560 (org-id-link-to-org-use-id nil
)
2561 (org-context-in-file-links nil
))
2562 (org-test-with-temp-text-in-file "* h1"
2563 (let ((file (buffer-file-name)))
2564 (equal (format "[[file:%s::*h1][h1]]" file
)
2565 (org-store-link '(4)))))))
2566 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2569 (let ((org-stored-links nil
)
2570 (org-id-link-to-org-use-id nil
)
2571 (org-context-in-file-links nil
))
2572 (org-test-with-temp-text-in-file "* h1"
2573 (let ((file (buffer-file-name)))
2574 (equal (format "[[file:%s][file:%s]]" file file
)
2575 (org-store-link '(16)))))))
2576 ;; Store file link to non-Org buffer, with context.
2578 (let ((org-stored-links nil
)
2579 (org-context-in-file-links t
))
2580 (org-test-with-temp-text-in-file "one\n<point>two"
2582 (let ((file (buffer-file-name)))
2583 (equal (format "[[file:%s::one]]" file
)
2584 (org-store-link nil
))))))
2585 ;; Store file link to non-Org buffer, without context.
2587 (let ((org-stored-links nil
)
2588 (org-context-in-file-links nil
))
2589 (org-test-with-temp-text-in-file "one\n<point>two"
2591 (let ((file (buffer-file-name)))
2592 (equal (format "[[file:%s][file:%s]]" file file
)
2593 (org-store-link nil
))))))
2594 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2597 (let ((org-stored-links nil
)
2598 (org-context-in-file-links nil
))
2599 (org-test-with-temp-text-in-file "one\n<point>two"
2601 (let ((file (buffer-file-name)))
2602 (equal (format "[[file:%s::one]]" file
)
2603 (org-store-link '(4)))))))
2604 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2607 (let ((org-stored-links nil
)
2608 (org-context-in-file-links nil
))
2609 (org-test-with-temp-text-in-file "one\n<point>two"
2611 (let ((file (buffer-file-name)))
2612 (equal (format "[[file:%s][file:%s]]" file file
)
2613 (org-store-link '(16))))))))
2618 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2619 "Ensure properties accumulate in subtree drawers."
2620 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2621 (org-babel-next-src-block)
2622 (should (equal '(2 1) (org-babel-execute-src-block)))))
2624 (ert-deftest test-org
/custom-properties
()
2625 "Test custom properties specifications."
2628 (let ((org-custom-properties '("FOO")))
2629 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2630 (org-toggle-custom-properties-visibility)
2631 (org-invisible-p2))))
2632 ;; Properties are case-insensitive.
2634 (let ((org-custom-properties '("FOO")))
2635 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2636 (org-toggle-custom-properties-visibility)
2637 (org-invisible-p2))))
2639 (let ((org-custom-properties '("foo")))
2640 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2641 (org-toggle-custom-properties-visibility)
2642 (org-invisible-p2))))
2643 ;; Multiple custom properties in the same drawer.
2645 (let ((org-custom-properties '("FOO" "BAR")))
2646 (org-test-with-temp-text
2647 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2648 (org-toggle-custom-properties-visibility)
2649 (and (org-invisible-p2)
2650 (not (progn (forward-line) (org-invisible-p2)))
2651 (progn (forward-line) (org-invisible-p2))))))
2652 ;; Hide custom properties with an empty value.
2654 (let ((org-custom-properties '("FOO")))
2655 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2656 (org-toggle-custom-properties-visibility)
2657 (org-invisible-p2))))
2658 ;; Do not hide fake properties.
2660 (let ((org-custom-properties '("FOO")))
2661 (org-test-with-temp-text ":FOO: val\n"
2662 (org-toggle-custom-properties-visibility)
2663 (org-invisible-p2))))
2665 (let ((org-custom-properties '("A")))
2666 (org-test-with-temp-text
2667 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2668 (org-toggle-custom-properties-visibility)
2669 (org-invisible-p2)))))
2675 (ert-deftest test-org
/mark-subtree
()
2676 "Test `org-mark-subtree' specifications."
2677 ;; Error when point is before first headline.
2679 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2680 (progn (transient-mark-mode 1)
2681 (org-mark-subtree))))
2682 ;; Without argument, mark current subtree.
2686 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2687 (progn (transient-mark-mode 1)
2690 (list (region-beginning) (region-end))))))
2691 ;; With an argument, move ARG up.
2695 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2696 (progn (transient-mark-mode 1)
2698 (org-mark-subtree 1)
2699 (list (region-beginning) (region-end))))))
2700 ;; Do not get fooled by inlinetasks.
2701 (when (featurep 'org-inlinetask
)
2704 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2705 (progn (transient-mark-mode 1)
2707 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2708 (region-beginning)))))))
2714 (ert-deftest test-org
/sort-entries
()
2715 "Test `org-sort-entries'."
2716 ;; Sort alphabetically.
2718 (equal "\n* abc\n* def\n* xyz\n"
2719 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2720 (org-sort-entries nil ?a
)
2723 (equal "\n* xyz\n* def\n* abc\n"
2724 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2725 (org-sort-entries nil ?A
)
2727 ;; Sort numerically.
2729 (equal "\n* 1\n* 2\n* 10\n"
2730 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2731 (org-sort-entries nil ?n
)
2734 (equal "\n* 10\n* 2\n* 1\n"
2735 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2736 (org-sort-entries nil ?N
)
2738 ;; Sort by custom function.
2740 (equal "\n* b\n* aa\n* ccc\n"
2741 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2742 (org-sort-entries nil ?f
2744 (length (buffer-substring (point-at-bol)
2749 (equal "\n* ccc\n* aa\n* b\n"
2750 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2751 (org-sort-entries nil ?F
2753 (length (buffer-substring (point-at-bol)
2757 ;; Sort by TODO keyword.
2759 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2760 (org-test-with-temp-text
2761 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2762 (org-sort-entries nil ?o
)
2765 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2766 (org-test-with-temp-text
2767 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2768 (org-sort-entries nil ?O
)
2770 ;; Sort by priority.
2772 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2773 (org-test-with-temp-text
2774 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2775 (org-sort-entries nil ?p
)
2778 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2779 (org-test-with-temp-text
2780 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2781 (org-sort-entries nil ?P
)
2783 ;; Sort by creation time.
2793 (org-test-with-temp-text
2802 (org-sort-entries nil ?c
)
2805 ;; Sort by scheduled date.
2809 SCHEDULED: <2017-05-06 Sat>
2811 SCHEDULED: <2017-05-08 Mon>
2813 DEADLINE: <2017-05-09 Tue>
2815 DEADLINE: <2017-05-07 Sun>
2817 (org-test-with-temp-text
2820 DEADLINE: <2017-05-09 Tue>
2822 DEADLINE: <2017-05-07 Sun>
2824 SCHEDULED: <2017-05-08 Mon>
2826 SCHEDULED: <2017-05-06 Sat>
2828 (org-sort-entries nil ?s
)
2830 ;; Sort by deadline date.
2834 DEADLINE: <2017-05-07 Sun>
2836 DEADLINE: <2017-05-09 Tue>
2838 SCHEDULED: <2017-05-08 Mon>
2840 SCHEDULED: <2017-05-06 Sat>
2842 (org-test-with-temp-text
2845 DEADLINE: <2017-05-09 Tue>
2847 DEADLINE: <2017-05-07 Sun>
2849 SCHEDULED: <2017-05-08 Mon>
2851 SCHEDULED: <2017-05-06 Sat>
2853 (org-sort-entries nil ?d
)
2855 ;; Sort by any date/time
2859 SCHEDULED: <2017-05-06 Sat>
2861 DEADLINE: <2017-05-07 Sun>
2863 SCHEDULED: <2017-05-08 Mon>
2865 DEADLINE: <2017-05-09 Tue>
2867 (org-test-with-temp-text
2870 DEADLINE: <2017-05-09 Tue>
2872 DEADLINE: <2017-05-07 Sun>
2874 SCHEDULED: <2017-05-08 Mon>
2876 SCHEDULED: <2017-05-06 Sat>
2878 (org-sort-entries nil ?t
)
2880 ;; Sort by clocking time.
2885 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2886 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2890 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2891 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2894 (org-test-with-temp-text
2898 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2899 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2903 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2904 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2907 (org-sort-entries nil ?k
)
2910 (ert-deftest test-org
/file-contents
()
2911 "Test `org-file-contents' specifications."
2914 (string= "#+BIND: variable value
2920 " (org-file-contents (expand-file-name "setupfile3.org"
2921 (concat org-test-dir
"examples/")))))
2922 ;; Throw error when trying to access an invalid file.
2923 (should-error (org-file-contents "this-file-must-not-exist"))
2924 ;; Try to access an invalid file, but do not throw an error.
2926 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2930 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2932 ;; Simulate successful retrieval of a URL.
2933 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2935 (with-current-buffer buffer
2936 (insert "HTTP/1.1 200 OK\n\nfoo"))
2938 (org-file-contents "http://some-valid-url"))
2939 (kill-buffer buffer
)))))
2940 ;; Throw error when trying to access an invalid URL.
2942 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2944 ;; Simulate unsuccessful retrieval of a URL.
2945 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2947 (with-current-buffer buffer
2948 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2950 (org-file-contents "http://this-url-must-not-exist"))
2951 (kill-buffer buffer
))))
2952 ;; Try to access an invalid URL, but do not throw an error.
2954 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2956 ;; Simulate unsuccessful retrieval of a URL.
2957 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2959 (with-current-buffer buffer
2960 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2962 (org-file-contents "http://this-url-must-not-exist"))
2963 (kill-buffer buffer
))))
2965 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2967 ;; Simulate unsuccessful retrieval of a URL.
2968 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2970 (with-current-buffer buffer
2971 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2973 (org-file-contents "http://this-url-must-not-exist" :noerror
))
2974 (kill-buffer buffer
))
2980 (ert-deftest test-org
/forward-heading-same-level
()
2981 "Test `org-forward-heading-same-level' specifications."
2982 ;; Test navigation at top level, forward and backward.
2985 (org-test-with-temp-text "* H1\n* H2"
2986 (org-forward-heading-same-level 1)
2987 (buffer-substring-no-properties (point) (line-end-position)))))
2990 (org-test-with-temp-text "* H1\n<point>* H2"
2991 (org-forward-heading-same-level -
1)
2992 (buffer-substring-no-properties (point) (line-end-position)))))
2993 ;; Test navigation in a sub-tree, forward and backward.
2996 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2997 (org-forward-heading-same-level 1)
2998 (buffer-substring-no-properties (point) (line-end-position)))))
3001 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3002 (org-forward-heading-same-level -
1)
3003 (buffer-substring-no-properties (point) (line-end-position)))))
3004 ;; Stop at first or last sub-heading.
3007 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3008 (org-forward-heading-same-level 1)
3009 (buffer-substring-no-properties (point) (line-end-position)))))
3012 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3013 (org-forward-heading-same-level -
1)
3014 (buffer-substring-no-properties (point) (line-end-position)))))
3015 ;; Allow multiple moves.
3018 (org-test-with-temp-text "* H1\n* H2\n* H3"
3019 (org-forward-heading-same-level 2)
3020 (buffer-substring-no-properties (point) (line-end-position)))))
3023 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3024 (org-forward-heading-same-level -
2)
3025 (buffer-substring-no-properties (point) (line-end-position)))))
3026 ;; Ignore spurious moves when first (or last) sibling is reached.
3029 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3030 (org-forward-heading-same-level 100)
3031 (buffer-substring-no-properties (point) (line-end-position)))))
3034 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3035 (org-forward-heading-same-level -
100)
3036 (buffer-substring-no-properties (point) (line-end-position))))))
3038 (ert-deftest test-org
/end-of-meta-data
()
3039 "Test `org-end-of-meta-data' specifications."
3040 ;; Skip planning line.
3042 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3043 (org-end-of-meta-data)
3045 ;; Skip properties drawer.
3047 (org-test-with-temp-text
3048 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3049 (org-end-of-meta-data)
3053 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3054 (org-end-of-meta-data)
3056 ;; Nothing to skip, go to first line.
3058 (org-test-with-temp-text "* Headline\nContents"
3059 (org-end-of-meta-data)
3060 (looking-at "Contents")))
3061 ;; With option argument, skip empty lines, regular drawers and
3064 (org-test-with-temp-text "* Headline\n\nContents"
3065 (org-end-of-meta-data t
)
3066 (looking-at "Contents")))
3068 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3069 (org-end-of-meta-data t
)
3070 (looking-at "Contents")))
3072 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3073 (org-end-of-meta-data t
)
3074 (looking-at "Contents")))
3075 ;; Special case: do not skip incomplete drawers.
3077 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3078 (org-end-of-meta-data t
)
3079 (looking-at ":LOGBOOK:")))
3080 ;; Special case: Be careful about consecutive headlines.
3082 (org-test-with-temp-text "* H1\n*H2\nContents"
3083 (org-end-of-meta-data t
)
3084 (looking-at "Contents"))))
3086 (ert-deftest test-org
/beginning-of-line
()
3087 "Test `org-beginning-of-line' specifications."
3088 ;; Move to beginning of line. If current line in invisible, move to
3089 ;; beginning of visible line instead.
3091 (org-test-with-temp-text "Some text\nSome other text<point>"
3092 (org-beginning-of-line)
3095 (org-test-with-temp-text "* H1\n** H2<point>"
3097 (org-beginning-of-line)
3098 (= (line-beginning-position) 1)))
3099 ;; With `visual-line-mode' active, move to beginning of visual line.
3101 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3103 (dotimes (i 1000) (insert "very "))
3104 (org-beginning-of-line)
3106 ;; In a wide headline, with `visual-line-mode', prefer going to the
3107 ;; beginning of a visual line than to the logical beginning of line,
3108 ;; even if special movement is active.
3110 (org-test-with-temp-text "* A <point>long headline"
3112 (dotimes (i 1000) (insert "very "))
3113 (goto-char (point-max))
3114 (org-beginning-of-line)
3117 (org-test-with-temp-text "* A <point>long headline"
3119 (dotimes (i 1000) (insert "very "))
3120 (goto-char (point-max))
3121 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3123 ;; At an headline with special movement, first move at beginning of
3124 ;; title, then at the beginning of line, rinse, repeat.
3126 (org-test-with-temp-text "* TODO Headline<point>"
3127 (let ((org-special-ctrl-a/e t
))
3128 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3129 (progn (org-beginning-of-line) (bolp))
3130 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3132 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3133 (let ((org-special-ctrl-a/e t
))
3134 (org-beginning-of-line)
3135 (looking-at "Headline"))))
3137 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3138 (let ((org-special-ctrl-a/e
'(t . nil
)))
3139 (org-beginning-of-line)
3140 (looking-at "Headline"))))
3142 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3143 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3144 (org-beginning-of-line)
3145 (looking-at "Headline"))))
3146 ;; At an headline with reversed movement, first move to beginning of
3147 ;; line, then to the beginning of title.
3149 (org-test-with-temp-text "* TODO Headline<point>"
3150 (let ((org-special-ctrl-a/e
'reversed
)
3151 (this-command last-command
))
3152 (and (progn (org-beginning-of-line) (bolp))
3153 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3155 (org-test-with-temp-text "* TODO Headline<point>"
3156 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3157 (this-command last-command
))
3158 (and (progn (org-beginning-of-line) (bolp))
3159 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3161 (org-test-with-temp-text "* TODO Headline<point>"
3162 (let ((org-special-ctrl-a/e
'(t . nil
))
3163 (this-command last-command
))
3164 (and (progn (org-beginning-of-line) (bolp))
3165 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3166 ;; At an item with special movement, first move after to beginning
3167 ;; of title, then to the beginning of line, rinse, repeat.
3169 (org-test-with-temp-text "- [ ] Item<point>"
3170 (let ((org-special-ctrl-a/e t
))
3171 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3172 (progn (org-beginning-of-line) (bolp))
3173 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3174 ;; At an item with reversed movement, first move to beginning of
3175 ;; line, then to the beginning of title.
3177 (org-test-with-temp-text "- [X] Item<point>"
3178 (let ((org-special-ctrl-a/e
'reversed
)
3179 (this-command last-command
))
3180 (and (progn (org-beginning-of-line) (bolp))
3181 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3182 ;; Leave point before invisible characters at column 0.
3184 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3185 (let ((org-special-ctrl-a/e nil
))
3186 (org-beginning-of-line)
3189 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3190 (let ((org-special-ctrl-a/e t
))
3191 (org-beginning-of-line)
3194 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3196 (org-beginning-of-line)
3198 ;; Special case: Do not error when the buffer contains only a single
3201 (org-test-with-temp-text "*<point>"
3202 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3204 (org-test-with-temp-text "*<point>"
3205 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3207 (ert-deftest test-org
/end-of-line
()
3208 "Test `org-end-of-line' specifications."
3211 (org-test-with-temp-text "Some text\nSome other text"
3214 ;; With `visual-line-mode' active, move to end of visible line.
3215 ;; However, never go past ellipsis.
3217 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3219 (dotimes (i 1000) (insert "very "))
3220 (goto-char (point-min))
3224 (org-test-with-temp-text "* A short headline\nSome contents"
3229 ;; In a wide headline, with `visual-line-mode', prefer going to end
3230 ;; of visible line if tags, or end of line, are farther.
3232 (org-test-with-temp-text "* A <point>long headline"
3234 (dotimes (i 1000) (insert "very "))
3235 (goto-char (point-min))
3239 (org-test-with-temp-text "* A <point>long headline :tag:"
3241 (dotimes (i 1000) (insert "very "))
3242 (goto-char (point-min))
3245 ;; At an headline without special movement, go to end of line.
3246 ;; However, never go past ellipsis.
3248 (org-test-with-temp-text "* Headline2b :tag:\n"
3249 (let ((org-special-ctrl-a/e nil
))
3250 (and (progn (org-end-of-line) (eolp))
3251 (progn (org-end-of-line) (eolp))))))
3253 (org-test-with-temp-text "* Headline2b :tag:\n"
3254 (let ((org-special-ctrl-a/e
'(t . nil
)))
3255 (and (progn (org-end-of-line) (eolp))
3256 (progn (org-end-of-line) (eolp))))))
3258 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3260 (let ((org-special-ctrl-a/e nil
))
3262 (= 1 (line-beginning-position)))))
3263 ;; At an headline with special movement, first move before tags,
3264 ;; then at the end of line, rinse, repeat. However, never go past
3267 (org-test-with-temp-text "* Headline1 :tag:\n"
3268 (let ((org-special-ctrl-a/e t
))
3269 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3270 (progn (org-end-of-line) (eolp))
3271 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3273 (org-test-with-temp-text "* Headline1 :tag:\n"
3274 (let ((org-special-ctrl-a/e
'(nil . t
)))
3275 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3276 (progn (org-end-of-line) (eolp))
3277 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3279 (org-test-with-temp-text "* Headline1 :tag:\n"
3280 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3281 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3282 (progn (org-end-of-line) (eolp))
3283 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3285 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3287 (let ((org-special-ctrl-a/e t
))
3290 (= 1 (line-beginning-position)))))
3291 ;; At an headline, with reversed movement, first go to end of line,
3292 ;; then before tags. However, never go past ellipsis.
3294 (org-test-with-temp-text "* Headline3 :tag:\n"
3295 (let ((org-special-ctrl-a/e
'reversed
)
3296 (this-command last-command
))
3297 (and (progn (org-end-of-line) (eolp))
3298 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3300 (org-test-with-temp-text "* Headline3 :tag:\n"
3301 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3302 (this-command last-command
))
3303 (and (progn (org-end-of-line) (eolp))
3304 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3306 (org-test-with-temp-text "* Headline3 :tag:\n"
3307 (let ((org-special-ctrl-a/e
'(nil . t
))
3308 (this-command last-command
))
3309 (and (progn (org-end-of-line) (eolp))
3310 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3312 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3314 (let ((org-special-ctrl-a/e
'reversed
))
3316 (= 1 (line-beginning-position)))))
3317 ;; At a block without hidden contents.
3319 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3320 (progn (org-end-of-line) (eolp))))
3321 ;; At a block with hidden contents.
3323 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3324 (let ((org-special-ctrl-a/e t
))
3325 (org-hide-block-toggle)
3328 ;; Get past invisible characters at the end of line.
3330 (org-test-with-temp-text "[[http://orgmode.org]]"
3334 (ert-deftest test-org
/open-line
()
3335 "Test `org-open-line' specifications."
3336 ;; Call `open-line' outside of tables.
3339 (org-test-with-temp-text "Text"
3342 ;; At a table, create a row above.
3344 (equal "\n| |\n| a |"
3345 (org-test-with-temp-text "\n<point>| a |"
3348 ;; At the very first character of the buffer, also call `open-line'.
3351 (org-test-with-temp-text "| a |"
3354 ;; Narrowing does not count.
3356 (equal "Text\n| |\n| a |"
3357 (org-test-with-temp-text "Text\n<point>| a |"
3358 (narrow-to-region (point) (point-max))
3363 (ert-deftest test-org
/forward-sentence
()
3364 "Test `org-forward-sentence' specifications."
3365 ;; At the end of a table cell, move to the end of the next one.
3367 (org-test-with-temp-text "| a<point> | b |"
3368 (org-forward-sentence)
3369 (looking-at " |$")))
3370 ;; Elsewhere in a cell, move to its end.
3372 (org-test-with-temp-text "| a<point>c | b |"
3373 (org-forward-sentence)
3374 (looking-at " | b |$")))
3375 ;; Otherwise, simply call `forward-sentence'.
3377 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3378 (org-forward-sentence)
3379 (looking-at " Sentence 2.")))
3381 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3382 (org-forward-sentence)
3383 (org-forward-sentence)
3385 ;; At the end of an element, jump to the next one, without stopping
3386 ;; on blank lines in-between.
3388 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3389 (org-forward-sentence)
3391 ;; Headlines are considered to be sentences by themselves, even if
3392 ;; they do not end with a full stop.
3396 (org-test-with-temp-text "* <point>Headline\nSentence."
3397 (org-forward-sentence)
3398 (buffer-substring-no-properties (line-beginning-position) (point)))))
3400 (org-test-with-temp-text "* Headline<point>\nSentence."
3401 (org-forward-sentence)
3404 (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
3405 (org-forward-sentence)
3406 (and (org-at-heading-p) (eolp)))))
3408 (ert-deftest test-org
/backward-sentence
()
3409 "Test `org-backward-sentence' specifications."
3410 ;; At the beginning of a table cell, move to the beginning of the
3413 (org-test-with-temp-text "| a | <point>b |"
3414 (org-backward-sentence)
3415 (looking-at "a | b |$")))
3416 ;; Elsewhere in a cell, move to its beginning.
3418 (org-test-with-temp-text "| a | b<point>c |"
3419 (org-backward-sentence)
3420 (looking-at "bc |$")))
3421 ;; Otherwise, simply call `backward-sentence'.
3423 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3424 (org-backward-sentence)
3425 (looking-at "Sentence 2.")))
3427 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3428 (org-backward-sentence)
3429 (org-backward-sentence)
3431 ;; Make sure to hit the beginning of a sentence on the same line as
3434 (org-test-with-temp-text "- Line 1\n line <point>2."
3435 (org-backward-sentence)
3436 (looking-at "Line 1"))))
3438 (ert-deftest test-org
/forward-paragraph
()
3439 "Test `org-forward-paragraph' specifications."
3440 ;; At end of buffer, do not return an error.
3442 (org-test-with-temp-text "Paragraph"
3443 (goto-char (point-max))
3444 (org-forward-paragraph)
3448 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3449 (org-forward-paragraph)
3453 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3454 (org-forward-paragraph)
3456 ;; Do not enter elements with invisible contents.
3458 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3459 (org-hide-block-toggle)
3460 (org-forward-paragraph)
3462 ;; On an affiliated keyword, jump to the beginning of the element.
3464 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3465 (org-forward-paragraph)
3466 (looking-at "Para")))
3467 ;; On an item or a footnote definition, move to the second element
3470 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3471 (org-forward-paragraph)
3472 (looking-at " Paragraph")))
3474 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3475 (org-forward-paragraph)
3476 (looking-at "Paragraph")))
3477 ;; On an item, or a footnote definition, when the first line is
3478 ;; empty, move to the first item.
3480 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3481 (org-forward-paragraph)
3482 (looking-at " Paragraph")))
3484 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3485 (org-forward-paragraph)
3486 (looking-at "Paragraph")))
3487 ;; On a table (resp. a property drawer) do not move through table
3488 ;; rows (resp. node properties).
3490 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3491 (org-forward-paragraph)
3492 (looking-at "Paragraph")))
3494 (org-test-with-temp-text
3495 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3496 (org-forward-paragraph)
3497 (looking-at "Paragraph")))
3498 ;; On a verse or source block, stop after blank lines.
3500 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3501 (org-forward-paragraph)
3504 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3505 (org-forward-paragraph)
3506 (looking-at "L2"))))
3508 (ert-deftest test-org
/backward-paragraph
()
3509 "Test `org-backward-paragraph' specifications."
3510 ;; Do not error at beginning of buffer.
3512 (org-test-with-temp-text "Paragraph"
3513 (org-backward-paragraph)
3517 (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
3518 (org-backward-paragraph)
3521 (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
3522 (org-backward-paragraph)
3523 (looking-at-p "P2")))
3526 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
3527 (org-backward-paragraph)
3528 (looking-at-p "P2")))
3529 ;; Ignore invisible elements.
3531 (org-test-with-temp-text "* H1\n P1\n* H2"
3533 (goto-char (point-max))
3535 (org-backward-paragraph)
3537 ;; On an affiliated keyword, jump to the first one.
3539 (org-test-with-temp-text
3540 "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
3541 (org-backward-paragraph)
3542 (looking-at-p "#\\+name")))
3543 ;; On the second element in an item or a footnote definition, jump
3544 ;; to item or the definition.
3546 (org-test-with-temp-text "- line1\n\n<point> line2"
3547 (org-backward-paragraph)
3548 (looking-at-p "- line1")))
3550 (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
3551 (org-backward-paragraph)
3552 (looking-at-p "\\[fn:1\\] line1")))
3553 ;; On a table (resp. a property drawer), ignore table rows
3554 ;; (resp. node properties).
3556 (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
3557 (org-backward-paragraph)
3560 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3561 (org-backward-paragraph)
3562 (looking-at-p ":PROPERTIES:")))
3563 ;; On a comment, example, src and verse blocks, stop before blank
3566 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
3567 (org-backward-paragraph)
3568 (looking-at-p "L2")))
3570 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
3571 (org-backward-paragraph)
3572 (looking-at-p "L2")))
3573 ;; In comment, example, export, src and verse blocks, stop below
3574 ;; opening line when called from within the block.
3576 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
3577 (org-backward-paragraph)
3578 (looking-at-p "L1")))
3580 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
3581 (org-backward-paragraph)
3582 (looking-at-p "L1")))
3583 ;; When called from the opening line itself, however, move to
3584 ;; beginning of block.
3586 (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
3587 (org-backward-paragraph)
3589 ;; Pathological case: on an empty heading, move to its beginning.
3591 (org-test-with-temp-text "* <point>H"
3592 (org-backward-paragraph)
3595 (ert-deftest test-org
/forward-element
()
3596 "Test `org-forward-element' specifications."
3597 ;; 1. At EOB: should error.
3598 (org-test-with-temp-text "Some text\n"
3599 (goto-char (point-max))
3600 (should-error (org-forward-element)))
3601 ;; 2. Standard move: expected to ignore blank lines.
3602 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3603 (org-forward-element)
3604 (should (looking-at (regexp-quote "Second paragraph."))))
3605 ;; 3. Headline tests.
3606 (org-test-with-temp-text "
3611 ;; 3.1. At an headline beginning: move to next headline at the
3614 (org-forward-element)
3615 (should (looking-at (regexp-quote "** Head 1.2")))
3616 ;; 3.2. At an headline beginning: move to parent headline if no
3617 ;; headline at the same level.
3619 (org-forward-element)
3620 (should (looking-at (regexp-quote "** Head 1.2"))))
3621 ;; 4. Greater element tests.
3622 (org-test-with-temp-text
3623 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3624 ;; 4.1. At a greater element: expected to skip contents.
3625 (org-forward-element)
3626 (should (looking-at (regexp-quote "Outside.")))
3627 ;; 4.2. At the end of greater element contents: expected to skip
3628 ;; to the end of the greater element.
3630 (org-forward-element)
3631 (should (looking-at (regexp-quote "Outside."))))
3633 (org-test-with-temp-text "
3647 ;; 5.1. At list top point: expected to move to the element after
3650 (org-forward-element)
3651 (should (looking-at (regexp-quote "Outside.")))
3652 ;; 5.2. Special case: at the first line of a sub-list, but not at
3653 ;; beginning of line, move to next item.
3656 (org-forward-element)
3657 (should (looking-at "- item2"))
3660 (org-forward-element)
3661 (should (looking-at " - sub2"))
3662 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3664 (org-forward-element)
3665 (should (looking-at (regexp-quote " Inner paragraph.")))
3666 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3668 (org-forward-element)
3669 (should (looking-at (regexp-quote " Inner paragraph.")))
3670 ;; 5.5. At an item: expected to move to next item, if any.
3672 (org-forward-element)
3673 (should (looking-at " - sub3"))))
3675 (ert-deftest test-org
/backward-element
()
3676 "Test `org-backward-element' specifications."
3677 ;; 1. Should error at BOB.
3678 (org-test-with-temp-text " \nParagraph."
3679 (should-error (org-backward-element)))
3680 ;; 2. Should move at BOB when called on the first element in buffer.
3682 (org-test-with-temp-text "\n#+TITLE: test"
3683 (progn (forward-line)
3684 (org-backward-element)
3686 ;; 3. Not at the beginning of an element: move at its beginning.
3687 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3690 (org-backward-element)
3691 (should (looking-at (regexp-quote "Paragraph2."))))
3692 ;; 4. Headline tests.
3693 (org-test-with-temp-text "
3698 ;; 4.1. At an headline beginning: move to previous headline at the
3701 (org-backward-element)
3702 (should (looking-at (regexp-quote "** Head 1.1")))
3703 ;; 4.2. At an headline beginning: move to parent headline if no
3704 ;; headline at the same level.
3706 (org-backward-element)
3707 (should (looking-at (regexp-quote "* Head 1")))
3708 ;; 4.3. At the first top-level headline: should error.
3710 (should-error (org-backward-element)))
3711 ;; 5. At beginning of first element inside a greater element:
3712 ;; expected to move to greater element's beginning.
3713 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3715 (org-backward-element)
3716 (should (looking-at "#\\+BEGIN_CENTER")))
3717 ;; 6. At the beginning of the first element in a section: should
3718 ;; move back to headline, if any.
3720 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3721 (progn (goto-char (point-max))
3723 (org-backward-element)
3724 (org-at-heading-p))))
3726 (org-test-with-temp-text "
3741 ;; 7.1. At beginning of sub-list: expected to move to the
3742 ;; paragraph before it.
3744 (org-backward-element)
3745 (should (looking-at "item1"))
3746 ;; 7.2. At an item in a list: expected to move at previous item.
3748 (org-backward-element)
3749 (should (looking-at " - sub2"))
3751 (org-backward-element)
3752 (should (looking-at "- item1"))
3753 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3756 (org-backward-element)
3757 (should (looking-at " - sub1"))
3759 (org-backward-element)
3760 (should (looking-at "- item1"))
3761 ;; 7.4. At blank-lines before list end: expected to move to top
3764 (org-backward-element)
3765 (should (looking-at "- item1"))))
3767 (ert-deftest test-org
/up-element
()
3768 "Test `org-up-element' specifications."
3769 ;; 1. At BOB or with no surrounding element: should error.
3770 (org-test-with-temp-text "Paragraph."
3771 (should-error (org-up-element)))
3772 (org-test-with-temp-text "* Head1\n* Head2"
3774 (should-error (org-up-element)))
3775 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3777 (should-error (org-up-element)))
3778 ;; 2. At an headline: move to parent headline.
3779 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3782 (should (looking-at "\\* Head1")))
3783 ;; 3. Inside a greater element: move to greater element beginning.
3784 (org-test-with-temp-text
3785 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3788 (should (looking-at "#\\+BEGIN_CENTER")))
3790 (org-test-with-temp-text "* Top
3797 Paragraph within sub2.
3800 ;; 4.1. Within an item: move to the item beginning.
3803 (should (looking-at " - sub2"))
3804 ;; 4.2. At an item in a sub-list: move to parent item.
3807 (should (looking-at "- item1"))
3808 ;; 4.3. At an item in top list: move to beginning of whole list.
3811 (should (looking-at "- item1"))
3812 ;; 4.4. Special case. At very top point: should move to parent of
3816 (should (looking-at "\\* Top"))))
3818 (ert-deftest test-org
/down-element
()
3819 "Test `org-down-element' specifications."
3820 ;; Error when the element hasn't got a recursive type.
3821 (org-test-with-temp-text "Paragraph."
3822 (should-error (org-down-element)))
3823 ;; Error when the element has no contents
3824 (org-test-with-temp-text "* Headline"
3825 (should-error (org-down-element)))
3826 ;; When at a plain-list, move to first item.
3827 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3830 (should (looking-at " - Item 1.1")))
3831 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3833 (should (looking-at " Item 1")))
3834 ;; When at a table, move to first row
3835 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3837 (should (looking-at " a | b |")))
3838 ;; Otherwise, move inside the greater element.
3839 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3841 (should (looking-at "Paragraph"))))
3843 (ert-deftest test-org
/drag-element-backward
()
3844 "Test `org-drag-element-backward' specifications."
3848 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3849 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3850 (org-drag-element-backward)
3854 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3855 (org-test-with-temp-text
3856 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3857 (org-drag-element-backward)
3859 ;; Preserve blank lines.
3861 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3862 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3863 (org-drag-element-backward)
3867 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3868 (org-drag-element-backward)
3869 (looking-at-p "2")))
3870 ;; Error when trying to move first element of buffer.
3872 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3873 (org-drag-element-backward))
3875 ;; Error when trying to swap nested elements.
3877 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3878 (org-drag-element-backward))
3880 ;; Error when trying to swap an headline element and a non-headline
3883 (org-test-with-temp-text "Test.\n<point>* Head 1"
3884 (org-drag-element-backward))
3886 ;; Error when called before first element.
3888 (org-test-with-temp-text "\n<point>"
3889 (org-drag-element-backward))
3891 ;; Preserve visibility of elements and their contents.
3893 (equal '((63 .
82) (26 .
48))
3894 (org-test-with-temp-text "
3902 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3903 (search-backward "- item 1")
3904 (org-drag-element-backward)
3905 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3906 (overlays-in (point-min) (point-max))))))
3907 ;; Pathological case: handle call with point in blank lines right
3908 ;; after a headline.
3910 (equal "* H2\n* H1\nText\n\n"
3911 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3912 (org-drag-element-backward)
3915 (ert-deftest test-org
/drag-element-forward
()
3916 "Test `org-drag-element-forward' specifications."
3917 ;; 1. Error when trying to move first element of buffer.
3918 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3920 (should-error (org-drag-element-forward)))
3921 ;; 2. Error when trying to swap nested elements.
3922 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3924 (should-error (org-drag-element-forward)))
3925 ;; 3. Error when trying to swap a non-headline element and an
3927 (org-test-with-temp-text "Test.\n* Head 1"
3928 (should-error (org-drag-element-forward)))
3929 ;; 4. Error when called before first element.
3931 (org-test-with-temp-text "\n"
3933 (org-drag-element-backward))
3935 ;; 5. Otherwise, swap elements, preserving column and blank lines
3936 ;; between elements.
3937 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3938 (search-forward "graph")
3939 (org-drag-element-forward)
3940 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3941 (should (looking-at " 1")))
3942 ;; 5. Preserve visibility of elements and their contents.
3943 (org-test-with-temp-text "
3951 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3952 (search-backward "#+BEGIN_CENTER")
3953 (org-drag-element-forward)
3956 '((63 .
82) (26 .
48))
3957 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3958 (overlays-in (point-min) (point-max)))))))
3960 (ert-deftest test-org
/next-block
()
3961 "Test `org-next-block' specifications."
3964 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3966 (looking-at "#\\+BEGIN_CENTER")))
3969 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3970 (let ((case-fold-search nil
))
3972 (looking-at "#\\+begin_center"))))
3973 ;; Ignore current line.
3975 (org-test-with-temp-text
3976 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3978 (looking-at "#\\+BEGIN_CENTER")))
3979 ;; Throw an error when no block is found.
3981 (org-test-with-temp-text "Paragraph"
3982 (org-next-block 1)))
3983 ;; With an argument, skip many blocks at once.
3985 (org-test-with-temp-text
3986 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3988 (looking-at "#\\+BEGIN_QUOTE")))
3989 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3991 (org-test-with-temp-text
3992 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3993 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3994 (looking-at "#\\+BEGIN_QUOTE")))
3995 ;; Optional argument is also case-insensitive.
3997 (org-test-with-temp-text
3998 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3999 (let ((case-fold-search nil
))
4000 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4001 (looking-at "#\\+begin_quote")))))
4003 (ert-deftest test-org
/insert-template
()
4004 "Test `org-insert-structure-template'."
4005 ;; Test in empty buffer.
4007 (string= "#+begin_foo\n#+end_foo\n"
4008 (org-test-with-temp-text ""
4009 (org-insert-structure-template "foo")
4011 ;; Test with multiple lines in buffer.
4013 (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
4014 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
4016 (org-insert-structure-template "foo")
4018 ;; Test with text in buffer, no region, no final newline.
4020 (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
4021 (org-test-with-temp-text "I'm a paragraph."
4023 (org-insert-structure-template "foo")
4025 ;; Test with text in buffer and region set.
4027 (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
4028 (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
4030 (goto-char (point-max))
4031 (org-insert-structure-template "foo")
4033 ;; Test with example escaping.
4035 (string= "#+begin_example\n,* Heading\n#+end_example\n"
4036 (org-test-with-temp-text "* Heading"
4038 (org-insert-structure-template "example")
4040 ;; Test with indentation.
4042 (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
4043 (org-test-with-temp-text " This is a paragraph"
4045 (org-insert-structure-template "foo")
4048 (ert-deftest test-org
/previous-block
()
4049 "Test `org-previous-block' specifications."
4052 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4053 (org-previous-block 1)
4054 (looking-at "#\\+BEGIN_CENTER")))
4057 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4058 (let ((case-fold-search nil
))
4059 (org-previous-block 1)
4060 (looking-at "#\\+begin_center"))))
4061 ;; Ignore current line.
4063 (org-test-with-temp-text
4064 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4065 (org-previous-block 1)
4066 (looking-at "#\\+BEGIN_QUOTE")))
4067 ;; Throw an error when no block is found.
4069 (org-test-with-temp-text "Paragraph<point>"
4070 (org-previous-block 1)))
4071 ;; With an argument, skip many blocks at once.
4073 (org-test-with-temp-text
4074 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4075 (org-previous-block 2)
4076 (looking-at "#\\+BEGIN_CENTER")))
4077 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4079 (org-test-with-temp-text
4080 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4081 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4082 (looking-at "#\\+BEGIN_QUOTE")))
4083 ;; Optional argument is also case-insensitive.
4085 (org-test-with-temp-text
4086 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4087 (let ((case-fold-search nil
))
4088 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4089 (looking-at "#\\+begin_quote")))))
4092 ;;; Outline structure
4094 (ert-deftest test-org
/demote
()
4095 "Test `org-demote' specifications."
4096 ;; Add correct number of stars according to `org-odd-levels-only'.
4099 (org-test-with-temp-text "* H"
4100 (let ((org-odd-levels-only nil
)) (org-demote))
4101 (org-current-level))))
4104 (org-test-with-temp-text "* H"
4105 (let ((org-odd-levels-only t
)) (org-demote))
4106 (org-current-level))))
4107 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4109 (org-test-with-temp-text "* H :tag:"
4110 (let ((org-tags-column 10)
4111 (org-auto-align-tags t
)
4112 (org-odd-levels-only nil
))
4114 (org-move-to-column 10)
4115 (looking-at-p ":tag:$")))
4117 (org-test-with-temp-text "* H :tag:"
4118 (let ((org-tags-column 10)
4119 (org-auto-align-tags nil
)
4120 (org-odd-levels-only nil
))
4122 (org-move-to-column 10)
4123 (looking-at-p ":tag:$")))
4124 ;; When `org-adapt-indentation' is non-nil, always indent planning
4125 ;; info and property drawers accordingly.
4128 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4129 (let ((org-odd-levels-only nil
)
4130 (org-adapt-indentation t
))
4133 (org-get-indentation))))
4136 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4137 (let ((org-odd-levels-only nil
)
4138 (org-adapt-indentation t
))
4141 (org-get-indentation))))
4144 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4145 (let ((org-odd-levels-only nil
)
4146 (org-adapt-indentation nil
))
4149 (org-get-indentation))))
4150 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4151 ;; section accordingly. Ignore, however, footnote definitions and
4152 ;; inlinetasks boundaries.
4155 (org-test-with-temp-text "* H\n Paragraph"
4156 (let ((org-odd-levels-only nil
)
4157 (org-adapt-indentation t
))
4160 (org-get-indentation))))
4163 (org-test-with-temp-text "* H\n Paragraph"
4164 (let ((org-odd-levels-only nil
)
4165 (org-adapt-indentation nil
))
4168 (org-get-indentation))))
4171 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4172 (let ((org-odd-levels-only nil
)
4173 (org-adapt-indentation t
))
4175 (goto-char (point-max))
4176 (org-get-indentation))))
4179 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4180 (let ((org-odd-levels-only nil
)
4181 (org-adapt-indentation t
))
4183 (goto-char (point-max))
4184 (org-get-indentation))))
4185 (when (featurep 'org-inlinetask
)
4188 (let ((org-inlinetask-min-level 5)
4189 (org-adapt-indentation t
))
4190 (org-test-with-temp-text "* H\n***** I\n***** END"
4193 (org-get-indentation))))))
4194 (when (featurep 'org-inlinetask
)
4197 (let ((org-inlinetask-min-level 5)
4198 (org-adapt-indentation t
))
4199 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4202 (org-get-indentation))))))
4203 ;; Ignore contents of source blocks or example blocks when
4204 ;; indentation should be preserved (through
4205 ;; `org-src-preserve-indentation' or "-i" flag).
4208 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4209 (let ((org-adapt-indentation t
)
4210 (org-src-preserve-indentation nil
))
4213 (org-get-indentation))))
4216 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4217 (let ((org-adapt-indentation t
)
4218 (org-src-preserve-indentation t
))
4221 (org-get-indentation))))
4224 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4225 (let ((org-adapt-indentation t
)
4226 (org-src-preserve-indentation t
))
4229 (org-get-indentation))))
4232 (org-test-with-temp-text
4233 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4234 (let ((org-adapt-indentation t
)
4235 (org-src-preserve-indentation nil
))
4238 (org-get-indentation)))))
4240 (ert-deftest test-org
/promote
()
4241 "Test `org-promote' specifications."
4242 ;; Return an error if headline is to be promoted to level 0, unless
4243 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4244 ;; headline becomes a comment.
4246 (org-test-with-temp-text "* H"
4247 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4250 (org-test-with-temp-text "* H"
4251 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4253 ;; Remove correct number of stars according to
4254 ;; `org-odd-levels-only'.
4257 (org-test-with-temp-text "*** H"
4258 (let ((org-odd-levels-only nil
)) (org-promote))
4259 (org-current-level))))
4262 (org-test-with-temp-text "*** H"
4263 (let ((org-odd-levels-only t
)) (org-promote))
4264 (org-current-level))))
4265 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4267 (org-test-with-temp-text "** H :tag:"
4268 (let ((org-tags-column 10)
4269 (org-auto-align-tags t
)
4270 (org-odd-levels-only nil
))
4272 (org-move-to-column 10)
4273 (looking-at-p ":tag:$")))
4275 (org-test-with-temp-text "** H :tag:"
4276 (let ((org-tags-column 10)
4277 (org-auto-align-tags nil
)
4278 (org-odd-levels-only nil
))
4280 (org-move-to-column 10)
4281 (looking-at-p ":tag:$")))
4282 ;; When `org-adapt-indentation' is non-nil, always indent planning
4283 ;; info and property drawers.
4286 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4287 (let ((org-odd-levels-only nil
)
4288 (org-adapt-indentation t
))
4291 (org-get-indentation))))
4294 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4295 (let ((org-odd-levels-only nil
)
4296 (org-adapt-indentation t
))
4299 (org-get-indentation))))
4302 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4303 (let ((org-odd-levels-only nil
)
4304 (org-adapt-indentation nil
))
4307 (org-get-indentation))))
4308 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4309 ;; section accordingly. Ignore, however, footnote definitions and
4310 ;; inlinetasks boundaries.
4313 (org-test-with-temp-text "** H\n Paragraph"
4314 (let ((org-odd-levels-only nil
)
4315 (org-adapt-indentation t
))
4318 (org-get-indentation))))
4321 (org-test-with-temp-text "** H\n Paragraph"
4322 (let ((org-odd-levels-only nil
)
4323 (org-adapt-indentation nil
))
4326 (org-get-indentation))))
4329 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4330 (let ((org-odd-levels-only nil
)
4331 (org-adapt-indentation t
))
4334 (org-get-indentation))))
4335 (when (featurep 'org-inlinetask
)
4338 (let ((org-inlinetask-min-level 5)
4339 (org-adapt-indentation t
))
4340 (org-test-with-temp-text "** H\n***** I\n***** END"
4343 (org-get-indentation))))))
4344 (when (featurep 'org-inlinetask
)
4347 (let ((org-inlinetask-min-level 5)
4348 (org-adapt-indentation t
))
4349 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4352 (org-get-indentation))))))
4353 ;; Give up shifting if it would break document's structure
4357 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4358 (let ((org-odd-levels-only nil
)
4359 (org-adapt-indentation t
))
4362 (org-get-indentation))))
4365 (org-test-with-temp-text "** H\n Paragraph\n * list."
4366 (let ((org-odd-levels-only nil
)
4367 (org-adapt-indentation t
))
4370 (org-get-indentation))))
4371 ;; Ignore contents of source blocks or example blocks when
4372 ;; indentation should be preserved (through
4373 ;; `org-src-preserve-indentation' or "-i" flag).
4376 (org-test-with-temp-text
4377 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4378 (let ((org-adapt-indentation t
)
4379 (org-src-preserve-indentation nil
)
4380 (org-odd-levels-only nil
))
4383 (org-get-indentation))))
4386 (org-test-with-temp-text
4387 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4388 (let ((org-adapt-indentation t
)
4389 (org-src-preserve-indentation t
)
4390 (org-odd-levels-only nil
))
4393 (org-get-indentation))))
4396 (org-test-with-temp-text
4397 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4398 (let ((org-adapt-indentation t
)
4399 (org-src-preserve-indentation t
)
4400 (org-odd-levels-only nil
))
4403 (org-get-indentation))))
4406 (org-test-with-temp-text
4407 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4408 (let ((org-adapt-indentation t
)
4409 (org-src-preserve-indentation nil
)
4410 (org-odd-levels-only nil
))
4413 (org-get-indentation)))))
4415 (ert-deftest test-org
/org-get-valid-level
()
4416 "Test function `org-get-valid-level' specifications."
4417 (let ((org-odd-levels-only nil
))
4418 (should (equal 1 (org-get-valid-level 0 0)))
4419 (should (equal 1 (org-get-valid-level 0 1)))
4420 (should (equal 2 (org-get-valid-level 0 2)))
4421 (should (equal 3 (org-get-valid-level 0 3)))
4422 (should (equal 1 (org-get-valid-level 1 0)))
4423 (should (equal 2 (org-get-valid-level 1 1)))
4424 (should (equal 23 (org-get-valid-level 1 22)))
4425 (should (equal 1 (org-get-valid-level 1 -
1)))
4426 (should (equal 1 (org-get-valid-level 2 -
1))))
4427 (let ((org-odd-levels-only t
))
4428 (should (equal 1 (org-get-valid-level 0 0)))
4429 (should (equal 1 (org-get-valid-level 0 1)))
4430 (should (equal 3 (org-get-valid-level 0 2)))
4431 (should (equal 5 (org-get-valid-level 0 3)))
4432 (should (equal 1 (org-get-valid-level 1 0)))
4433 (should (equal 3 (org-get-valid-level 1 1)))
4434 (should (equal 3 (org-get-valid-level 2 1)))
4435 (should (equal 5 (org-get-valid-level 3 1)))
4436 (should (equal 5 (org-get-valid-level 4 1)))
4437 (should (equal 43 (org-get-valid-level 1 21)))
4438 (should (equal 1 (org-get-valid-level 1 -
1)))
4439 (should (equal 1 (org-get-valid-level 2 -
1)))
4440 (should (equal 1 (org-get-valid-level 3 -
1)))
4441 (should (equal 3 (org-get-valid-level 4 -
1)))
4442 (should (equal 3 (org-get-valid-level 5 -
1)))))
4447 (ert-deftest test-org
/at-planning-p
()
4448 "Test `org-at-planning-p' specifications."
4451 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4452 (org-at-planning-p)))
4454 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4455 (org-at-planning-p)))
4456 ;; Correctly find planning attached to inlinetasks.
4457 (when (featurep 'org-inlinetask
)
4459 (org-test-with-temp-text
4460 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4461 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4463 (org-test-with-temp-text
4464 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4465 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4467 (org-test-with-temp-text
4468 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4469 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4471 (org-test-with-temp-text
4472 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4473 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4475 (ert-deftest test-org
/add-planning-info
()
4476 "Test `org-add-planning-info'."
4477 ;; Create deadline when `org-adapt-indentation' is non-nil.
4479 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4480 (org-test-with-temp-text "* H\nParagraph<point>"
4481 (let ((org-adapt-indentation t
))
4482 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4483 (replace-regexp-in-string
4484 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4486 ;; Create deadline when `org-adapt-indentation' is nil.
4488 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4489 (org-test-with-temp-text "* H\nParagraph<point>"
4490 (let ((org-adapt-indentation nil
))
4491 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4492 (replace-regexp-in-string
4493 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4495 ;; Update deadline when `org-adapt-indentation' is non-nil.
4497 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4498 (org-test-with-temp-text "\
4500 DEADLINE: <2015-06-24 Wed>
4502 (let ((org-adapt-indentation t
))
4503 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4504 (replace-regexp-in-string
4505 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4507 ;; Update deadline when `org-adapt-indentation' is nil.
4509 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4510 (org-test-with-temp-text "\
4512 DEADLINE: <2015-06-24 Wed>
4514 (let ((org-adapt-indentation nil
))
4515 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4516 (replace-regexp-in-string
4517 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4519 ;; Schedule when `org-adapt-indentation' is non-nil.
4521 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4522 (org-test-with-temp-text "* H\nParagraph<point>"
4523 (let ((org-adapt-indentation t
))
4524 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4525 (replace-regexp-in-string
4526 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4528 ;; Schedule when `org-adapt-indentation' is nil.
4530 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4531 (org-test-with-temp-text "* H\nParagraph<point>"
4532 (let ((org-adapt-indentation nil
))
4533 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4534 (replace-regexp-in-string
4535 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4537 ;; Add deadline when scheduled.
4541 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4543 (org-test-with-temp-text "\
4545 SCHEDULED: <2015-06-24 Wed>
4547 (let ((org-adapt-indentation t
))
4548 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4549 (replace-regexp-in-string
4550 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4552 ;; Remove middle entry.
4556 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4558 (org-test-with-temp-text "\
4560 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4562 (let ((org-adapt-indentation t
))
4563 (org-add-planning-info nil nil
'deadline
))
4564 (replace-regexp-in-string
4565 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4567 ;; Remove last entry and then middle entry (order should not
4572 CLOSED: [2015-06-24]
4574 (org-test-with-temp-text "\
4576 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4578 (let ((org-adapt-indentation t
))
4579 (org-add-planning-info nil nil
'scheduled
'deadline
))
4580 (replace-regexp-in-string
4581 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4583 ;; Remove closed when `org-adapt-indentation' is non-nil.
4585 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4586 (org-test-with-temp-text "\
4588 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4590 (let ((org-adapt-indentation t
))
4591 (org-add-planning-info nil nil
'closed
))
4592 (replace-regexp-in-string
4593 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4596 (equal "* H\n Paragraph"
4597 (org-test-with-temp-text "\
4599 CLOSED: [2015-06-25 Thu]
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 closed when `org-adapt-indentation' is nil.
4608 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4609 (org-test-with-temp-text "\
4611 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4613 (let ((org-adapt-indentation nil
))
4614 (org-add-planning-info nil nil
'closed
))
4615 (replace-regexp-in-string
4616 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4619 (equal "* H\nParagraph"
4620 (org-test-with-temp-text "\
4622 CLOSED: [2015-06-25 Thu]
4624 (let ((org-adapt-indentation nil
))
4625 (org-add-planning-info nil nil
'closed
))
4626 (replace-regexp-in-string
4627 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4629 ;; Remove closed entry and delete empty line.
4634 (org-test-with-temp-text "\
4636 CLOSED: [2015-06-24 Wed]
4638 (let ((org-adapt-indentation t
))
4639 (org-add-planning-info nil nil
'closed
))
4640 (replace-regexp-in-string
4641 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4643 ;; Remove one entry and update another.
4645 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4646 (org-test-with-temp-text "\
4648 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4650 (let ((org-adapt-indentation t
))
4651 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4652 (replace-regexp-in-string
4653 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4656 (ert-deftest test-org
/deadline
()
4657 "Test `org-deadline' specifications."
4658 ;; Insert a new value or replace existing one.
4660 (equal "* H\nDEADLINE: <2012-03-29>\n"
4661 (org-test-with-temp-text "* H"
4662 (let ((org-adapt-indentation nil
)
4663 (org-last-inserted-timestamp nil
))
4664 (org-deadline nil
"<2012-03-29 Tue>"))
4665 (replace-regexp-in-string
4666 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4669 (equal "* H\nDEADLINE: <2014-03-04>"
4670 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4671 (let ((org-adapt-indentation nil
)
4672 (org-last-inserted-timestamp nil
))
4673 (org-deadline nil
"<2014-03-04 Thu>"))
4674 (replace-regexp-in-string
4675 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4677 ;; Accept delta time, e.g., "+2d".
4679 (equal "* H\nDEADLINE: <2015-03-04>\n"
4680 (cl-letf (((symbol-function 'current-time
)
4681 (lambda (&rest args
)
4682 (apply #'encode-time
4683 (org-parse-time-string "2014-03-04")))))
4684 (org-test-with-temp-text "* H"
4685 (let ((org-adapt-indentation nil
)
4686 (org-last-inserted-timestamp nil
))
4687 (org-deadline nil
"+1y"))
4688 (replace-regexp-in-string
4689 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4690 ;; Preserve repeater.
4692 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4693 (org-test-with-temp-text "* H"
4694 (let ((org-adapt-indentation nil
)
4695 (org-last-inserted-timestamp nil
))
4696 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4697 (replace-regexp-in-string
4698 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4699 ;; Remove CLOSED keyword, if any.
4701 (equal "* H\nDEADLINE: <2012-03-29>"
4702 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4703 (let ((org-adapt-indentation nil
)
4704 (org-last-inserted-timestamp nil
))
4705 (org-deadline nil
"<2012-03-29 Tue>"))
4706 (replace-regexp-in-string
4707 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4708 ;; With C-u argument, remove DEADLINE keyword.
4711 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4712 (let ((org-adapt-indentation nil
)
4713 (org-last-inserted-timestamp nil
))
4714 (org-deadline '(4)))
4718 (org-test-with-temp-text "* H"
4719 (let ((org-adapt-indentation nil
)
4720 (org-last-inserted-timestamp nil
))
4721 (org-deadline '(4)))
4723 ;; With C-u C-u argument, prompt for a delay cookie.
4725 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4726 (cl-letf (((symbol-function 'org-read-date
)
4727 (lambda (&rest args
)
4728 (apply #'encode-time
4729 (org-parse-time-string "2014-03-04")))))
4730 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4731 (let ((org-adapt-indentation nil
)
4732 (org-last-inserted-timestamp nil
))
4733 (org-deadline '(16)))
4736 (cl-letf (((symbol-function 'org-read-date
)
4737 (lambda (&rest args
)
4738 (apply #'encode-time
4739 (org-parse-time-string "2014-03-04")))))
4740 (org-test-with-temp-text "* H"
4741 (let ((org-adapt-indentation nil
)
4742 (org-last-inserted-timestamp nil
))
4743 (org-deadline '(16)))
4745 ;; When a region is active and
4746 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4747 ;; same value in all headlines in region.
4749 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4750 (org-test-with-temp-text "* H1\n* H2"
4751 (let ((org-adapt-indentation nil
)
4752 (org-last-inserted-timestamp nil
)
4753 (org-loop-over-headlines-in-active-region t
))
4754 (transient-mark-mode 1)
4755 (push-mark (point) t t
)
4756 (goto-char (point-max))
4757 (org-deadline nil
"2012-03-29"))
4758 (replace-regexp-in-string
4759 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4761 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4762 (org-test-with-temp-text "* H1\n* H2"
4763 (let ((org-adapt-indentation nil
)
4764 (org-last-inserted-timestamp nil
)
4765 (org-loop-over-headlines-in-active-region nil
))
4766 (transient-mark-mode 1)
4767 (push-mark (point) t t
)
4768 (goto-char (point-max))
4769 (org-deadline nil
"2012-03-29"))
4770 (replace-regexp-in-string
4771 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4773 (ert-deftest test-org
/schedule
()
4774 "Test `org-schedule' specifications."
4775 ;; Insert a new value or replace existing one.
4777 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4778 (org-test-with-temp-text "* H"
4779 (let ((org-adapt-indentation nil
)
4780 (org-last-inserted-timestamp nil
))
4781 (org-schedule nil
"<2012-03-29 Tue>"))
4782 (replace-regexp-in-string
4783 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4786 (equal "* H\nSCHEDULED: <2014-03-04>"
4787 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4788 (let ((org-adapt-indentation nil
)
4789 (org-last-inserted-timestamp nil
))
4790 (org-schedule nil
"<2014-03-04 Thu>"))
4791 (replace-regexp-in-string
4792 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4794 ;; Accept delta time, e.g., "+2d".
4796 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4797 (cl-letf (((symbol-function 'current-time
)
4798 (lambda (&rest args
)
4799 (apply #'encode-time
4800 (org-parse-time-string "2014-03-04")))))
4801 (org-test-with-temp-text "* H"
4802 (let ((org-adapt-indentation nil
)
4803 (org-last-inserted-timestamp nil
))
4804 (org-schedule nil
"+1y"))
4805 (replace-regexp-in-string
4806 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4807 ;; Preserve repeater.
4809 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4810 (org-test-with-temp-text "* H"
4811 (let ((org-adapt-indentation nil
)
4812 (org-last-inserted-timestamp nil
))
4813 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4814 (replace-regexp-in-string
4815 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4816 ;; Remove CLOSED keyword, if any.
4818 (equal "* H\nSCHEDULED: <2012-03-29>"
4819 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4820 (let ((org-adapt-indentation nil
)
4821 (org-last-inserted-timestamp nil
))
4822 (org-schedule nil
"<2012-03-29 Tue>"))
4823 (replace-regexp-in-string
4824 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4825 ;; With C-u argument, remove SCHEDULED keyword.
4828 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4829 (let ((org-adapt-indentation nil
)
4830 (org-last-inserted-timestamp nil
))
4831 (org-schedule '(4)))
4835 (org-test-with-temp-text "* H"
4836 (let ((org-adapt-indentation nil
)
4837 (org-last-inserted-timestamp nil
))
4838 (org-schedule '(4)))
4840 ;; With C-u C-u argument, prompt for a delay cookie.
4842 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4843 (cl-letf (((symbol-function 'org-read-date
)
4844 (lambda (&rest args
)
4845 (apply #'encode-time
4846 (org-parse-time-string "2014-03-04")))))
4847 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4848 (let ((org-adapt-indentation nil
)
4849 (org-last-inserted-timestamp nil
))
4850 (org-schedule '(16)))
4853 (cl-letf (((symbol-function 'org-read-date
)
4854 (lambda (&rest args
)
4855 (apply #'encode-time
4856 (org-parse-time-string "2014-03-04")))))
4857 (org-test-with-temp-text "* H"
4858 (let ((org-adapt-indentation nil
)
4859 (org-last-inserted-timestamp nil
))
4860 (org-schedule '(16)))
4862 ;; When a region is active and
4863 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4864 ;; same value in all headlines in region.
4866 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4867 (org-test-with-temp-text "* H1\n* H2"
4868 (let ((org-adapt-indentation nil
)
4869 (org-last-inserted-timestamp nil
)
4870 (org-loop-over-headlines-in-active-region t
))
4871 (transient-mark-mode 1)
4872 (push-mark (point) t t
)
4873 (goto-char (point-max))
4874 (org-schedule nil
"2012-03-29"))
4875 (replace-regexp-in-string
4876 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4878 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4879 (org-test-with-temp-text "* H1\n* H2"
4880 (let ((org-adapt-indentation nil
)
4881 (org-last-inserted-timestamp nil
)
4882 (org-loop-over-headlines-in-active-region nil
))
4883 (transient-mark-mode 1)
4884 (push-mark (point) t t
)
4885 (goto-char (point-max))
4886 (org-schedule nil
"2012-03-29"))
4887 (replace-regexp-in-string
4888 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4890 ;; check if a repeater survives re-scheduling.
4892 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4893 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4894 (let ((org-adapt-indentation nil
)
4895 (org-last-inserted-timestamp nil
))
4896 (org-schedule nil
"2017-02-01"))
4902 (ert-deftest test-org
/buffer-property-keys
()
4903 "Test `org-buffer-property-keys' specifications."
4904 ;; Retrieve properties accross siblings.
4907 (org-test-with-temp-text "
4916 (org-buffer-property-keys))))
4917 ;; Retrieve properties accross children.
4920 (org-test-with-temp-text "
4929 (org-buffer-property-keys))))
4930 ;; Retrieve muliple properties in the same drawer.
4933 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4934 (org-buffer-property-keys))))
4935 ;; Ignore extension symbol in property name.
4938 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4939 (org-buffer-property-keys))))
4940 ;; With non-nil COLUMNS, extract property names from columns.
4943 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4944 (org-buffer-property-keys nil nil t
))))
4946 (equal '("A" "B" "COLUMNS")
4947 (org-test-with-temp-text
4948 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4949 (org-buffer-property-keys nil nil t
))))
4950 ;; In COLUMNS, ignore title and summary-type.
4953 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4954 (org-buffer-property-keys nil nil t
))))
4957 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4958 (org-buffer-property-keys nil nil t
))))
4961 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4962 (org-buffer-property-keys nil nil t
)))))
4964 (ert-deftest test-org
/property-values
()
4965 "Test `org-property-values' specifications."
4969 (org-test-with-temp-text
4970 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4971 (org-property-values "A"))))
4972 ;; Ignore empty values.
4974 (org-test-with-temp-text
4975 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4976 (org-property-values "A")))
4977 ;; Take into consideration extended values.
4980 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4981 (org-property-values "A")))))
4983 (ert-deftest test-org
/find-property
()
4984 "Test `org-find-property' specifications."
4988 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4989 (org-find-property "prop"))))
4990 ;; Ignore false positives.
4993 (org-test-with-temp-text
4994 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4995 (org-find-property "A"))))
4996 ;; Return first entry found in buffer.
4999 (org-test-with-temp-text
5000 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5001 (org-find-property "A"))))
5002 ;; Only search visible part of the buffer.
5005 (org-test-with-temp-text
5006 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
5007 (org-narrow-to-subtree)
5008 (org-find-property "A"))))
5009 ;; With optional argument, only find entries with a specific value.
5011 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5012 (org-find-property "A" "2")))
5015 (org-test-with-temp-text
5016 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
5017 (org-find-property "A" "2"))))
5018 ;; Use "nil" for explicit nil values.
5021 (org-test-with-temp-text
5022 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
5023 (org-find-property "A" "nil")))))
5025 (ert-deftest test-org
/entry-delete
()
5026 "Test `org-entry-delete' specifications."
5030 " *:PROPERTIES:\n *:B: +2\n *:END:"
5031 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5032 (org-entry-delete (point) "A")
5034 ;; Also remove accumulated properties.
5038 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5039 (org-entry-delete (point) "A")
5041 ;; When last property is removed, remove the property drawer.
5045 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5046 (org-entry-delete (point) "A")
5048 ;; Return a non-nil value when some property was removed.
5050 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5051 (org-entry-delete (point) "A")))
5053 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5054 (org-entry-delete (point) "C")))
5055 ;; Special properties cannot be located in a drawer. Allow to
5056 ;; remove them anyway, in case of user error.
5058 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5059 (org-entry-delete (point) "SCHEDULED"))))
5061 (ert-deftest test-org
/entry-get
()
5062 "Test `org-entry-get' specifications."
5066 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5067 (org-entry-get (point) "A"))))
5071 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5072 (org-entry-get (point) "a"))))
5073 ;; Handle extended values, both before and after base value.
5076 (org-test-with-temp-text
5077 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5078 (org-entry-get (point) "A"))))
5079 ;; Empty values are returned as the empty string.
5082 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5083 (org-entry-get (point) "A"))))
5084 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5085 ;; otherwise, return nil.
5087 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5088 (org-entry-get (point) "A")))
5091 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5092 (org-entry-get (point) "A" nil t
))))
5093 ;; Return nil when no property is found, independently on the
5094 ;; LITERAL-NIL argument.
5096 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5097 (org-entry-get (point) "B")))
5099 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5100 (org-entry-get (point) "B" nil t
)))
5101 ;; Handle inheritance, when allowed. Include extended values and
5102 ;; possibly global values.
5106 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5107 (org-entry-get (point) "A" t
))))
5111 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5112 (let ((org-use-property-inheritance t
))
5113 (org-entry-get (point) "A" 'selective
)))))
5115 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5116 (let ((org-use-property-inheritance nil
))
5117 (org-entry-get (point) "A" 'selective
))))
5121 (org-test-with-temp-text
5122 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5123 (org-entry-get (point-max) "A" t
))))
5126 (org-test-with-temp-text
5127 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5129 (org-entry-get (point-max) "A" t
))))
5132 (org-test-with-temp-text
5133 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5135 (org-entry-get (point-max) "A" t
)))))
5137 (ert-deftest test-org
/entry-properties
()
5138 "Test `org-entry-properties' specifications."
5139 ;; Get "ITEM" property.
5142 (org-test-with-temp-text "* TODO H"
5143 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5146 (org-test-with-temp-text "* TODO H"
5147 (cdr (assoc "ITEM" (org-entry-properties))))))
5148 ;; Get "TODO" property. TODO keywords are case sensitive.
5151 (org-test-with-temp-text "* TODO H"
5152 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5155 (org-test-with-temp-text "* TODO H"
5156 (cdr (assoc "TODO" (org-entry-properties))))))
5158 (org-test-with-temp-text "* H"
5159 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5161 (org-test-with-temp-text "* todo H"
5162 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5163 ;; Get "PRIORITY" property.
5166 (org-test-with-temp-text "* [#A] H"
5167 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5170 (org-test-with-temp-text "* [#A] H"
5171 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5173 (equal (char-to-string org-default-priority
)
5174 (org-test-with-temp-text "* H"
5175 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5176 ;; Get "FILE" property.
5178 (org-test-with-temp-text-in-file "* H\nParagraph"
5179 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5180 (buffer-file-name))))
5182 (org-test-with-temp-text-in-file "* H\nParagraph"
5183 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5184 (buffer-file-name))))
5186 (org-test-with-temp-text "* H\nParagraph"
5187 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5188 ;; Get "TAGS" property.
5190 (equal ":tag1:tag2:"
5191 (org-test-with-temp-text "* H :tag1:tag2:"
5192 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5194 (equal ":tag1:tag2:"
5195 (org-test-with-temp-text "* H :tag1:tag2:"
5196 (cdr (assoc "TAGS" (org-entry-properties))))))
5198 (org-test-with-temp-text "* H"
5199 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5200 ;; Get "ALLTAGS" property.
5202 (equal ":tag1:tag2:"
5203 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5204 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5206 (equal ":tag1:tag2:"
5207 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5208 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5210 (org-test-with-temp-text "* H"
5211 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5212 ;; Get "BLOCKED" property.
5215 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5216 (let ((org-enforce-todo-dependencies t
)
5218 '(org-block-todo-from-children-or-siblings-or-parent)))
5219 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5222 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5223 (let ((org-enforce-todo-dependencies t
)
5225 '(org-block-todo-from-children-or-siblings-or-parent)))
5226 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5227 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5231 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5232 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5236 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5237 (cdr (assoc "CLOSED" (org-entry-properties))))))
5239 (org-test-with-temp-text "* H"
5240 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5244 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5245 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5249 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5250 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5252 (org-test-with-temp-text "* H"
5253 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5257 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5258 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5262 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5263 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5265 (org-test-with-temp-text "* H"
5266 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5270 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5271 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5274 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5275 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5278 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5279 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5282 (org-test-with-temp-text
5283 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5285 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5286 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5287 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5289 (equal "<2012-03-29 thu.>"
5290 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5291 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5293 (equal "[2012-03-29 thu.]"
5294 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5295 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5297 (equal "<2012-03-29 thu.>"
5298 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5299 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5301 (equal "[2014-03-04 tue.]"
5302 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5303 (cdr (assoc "TIMESTAMP_IA"
5304 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5306 (equal "<2012-03-29 thu.>"
5307 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5308 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5309 ;; Get standard properties.
5312 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5313 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5314 ;; Handle extended properties.
5317 (org-test-with-temp-text
5318 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5319 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5322 (org-test-with-temp-text
5323 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5324 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5325 ;; Ignore forbidden (special) properties.
5327 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5328 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5330 (ert-deftest test-org
/entry-put
()
5331 "Test `org-entry-put' specifications."
5332 ;; Error when not a string or nil.
5334 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5335 (org-entry-put 1 "test" 2)))
5336 ;; Error when property name is invalid.
5338 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5339 (org-entry-put 1 "no space" "value")))
5341 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5342 (org-entry-put 1 "" "value")))
5343 ;; Set "TODO" property.
5345 (string-match (regexp-quote " TODO H")
5346 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5347 (org-entry-put (point) "TODO" "TODO")
5350 (string-match (regexp-quote "* H")
5351 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5352 (org-entry-put (point) "TODO" nil
)
5354 ;; Set "PRIORITY" property.
5357 (org-test-with-temp-text "* [#B] H"
5358 (org-entry-put (point) "PRIORITY" "A")
5362 (org-test-with-temp-text "* [#B] H"
5363 (org-entry-put (point) "PRIORITY" nil
)
5365 ;; Set "SCHEDULED" property.
5367 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5368 (org-test-with-temp-text "* H"
5369 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5373 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5374 (org-entry-put (point) "SCHEDULED" nil
)
5377 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5378 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5379 (org-entry-put (point) "SCHEDULED" "earlier")
5382 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5383 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5384 (org-entry-put (point) "SCHEDULED" "later")
5386 ;; Set "DEADLINE" property.
5388 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5389 (org-test-with-temp-text "* H"
5390 (org-entry-put (point) "DEADLINE" "2014-03-04")
5394 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5395 (org-entry-put (point) "DEADLINE" nil
)
5398 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5399 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5400 (org-entry-put (point) "DEADLINE" "earlier")
5403 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5404 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5405 (org-entry-put (point) "DEADLINE" "later")
5407 ;; Set "CATEGORY" property
5409 (string-match "^ *:CATEGORY: cat"
5410 (org-test-with-temp-text "* H"
5411 (org-entry-put (point) "CATEGORY" "cat")
5413 ;; Regular properties, with or without pre-existing drawer.
5415 (string-match "^ *:A: +2$"
5416 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5417 (org-entry-put (point) "A" "2")
5420 (string-match "^ *:A: +1$"
5421 (org-test-with-temp-text "* H"
5422 (org-entry-put (point) "A" "1")
5424 ;; Special case: two consecutive headlines.
5426 (string-match "\\* A\n *:PROPERTIES:"
5427 (org-test-with-temp-text "* A\n** B"
5428 (org-entry-put (point) "A" "1")
5431 (ert-deftest test-org
/refresh-properties
()
5432 "Test `org-refresh-properties' specifications."
5435 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5436 (org-refresh-properties "A" 'org-test
)
5437 (get-text-property (point) 'org-test
))))
5439 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5440 (org-refresh-properties "B" 'org-test
)
5441 (get-text-property (point) 'org-test
)))
5442 ;; Handle properties only defined with extension syntax, i.e.,
5446 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5447 (org-refresh-properties "A" 'org-test
)
5448 (get-text-property (point) 'org-test
))))
5449 ;; When property is inherited, add text property to the whole
5453 (org-test-with-temp-text
5454 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5455 (let ((org-use-property-inheritance t
))
5456 (org-refresh-properties "A" 'org-test
))
5457 (get-text-property (point) 'org-test
))))
5458 ;; When property is inherited, use global value across the whole
5459 ;; buffer. However local values have precedence.
5462 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5464 (let ((org-use-property-inheritance nil
))
5465 (org-refresh-properties "A" 'org-test
))
5466 (get-text-property (point) 'org-test
))))
5469 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5471 (let ((org-use-property-inheritance t
))
5472 (org-refresh-properties "A" 'org-test
))
5473 (get-text-property (point) 'org-test
))))
5476 (org-test-with-temp-text
5477 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5479 (let ((org-use-property-inheritance t
))
5480 (org-refresh-properties "A" 'org-test
))
5481 (get-text-property (point) 'org-test
)))))
5486 (ert-deftest test-org
/update-radio-target-regexp
()
5487 "Test `org-update-radio-target-regexp' specifications."
5488 ;; Properly update cache with no previous radio target regexp.
5491 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5492 (save-excursion (goto-char (point-max)) (org-element-context))
5494 (search-forward "o")
5496 (org-update-radio-target-regexp)
5497 (goto-char (point-max))
5498 (org-element-type (org-element-context)))))
5499 ;; Properly update cache with previous radio target regexp.
5502 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5503 (save-excursion (goto-char (point-max)) (org-element-context))
5505 (search-forward "o")
5507 (org-update-radio-target-regexp)
5508 (search-backward "r")
5511 (org-update-radio-target-regexp)
5512 (goto-char (point-max))
5513 (delete-region (line-beginning-position) (point))
5515 (org-element-type (org-element-context))))))
5520 (ert-deftest test-org
/refile-get-targets
()
5521 "Test `org-refile-get-targets' specifications."
5522 ;; :maxlevel includes all headings above specified value.
5524 (equal '("H1" "H2" "H3")
5525 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5526 (let ((org-refile-use-outline-path nil
)
5527 (org-refile-targets `((nil :maxlevel .
3))))
5528 (mapcar #'car
(org-refile-get-targets))))))
5531 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5532 (let ((org-refile-use-outline-path nil
)
5533 (org-refile-targets `((nil :maxlevel .
2))))
5534 (mapcar #'car
(org-refile-get-targets))))))
5535 ;; :level limits targets to headlines with the specified level.
5538 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5539 (let ((org-refile-use-outline-path nil
)
5540 (org-refile-targets `((nil :level .
2))))
5541 (mapcar #'car
(org-refile-get-targets))))))
5542 ;; :tag limits targets to headlines with specified tag.
5545 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5546 (let ((org-refile-use-outline-path nil
)
5547 (org-refile-targets `((nil :tag .
"foo"))))
5548 (mapcar #'car
(org-refile-get-targets))))))
5549 ;; :todo limits targets to headlines with specified TODO keyword.
5552 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5553 (let ((org-refile-use-outline-path nil
)
5554 (org-refile-targets `((nil :todo .
"TODO"))))
5555 (mapcar #'car
(org-refile-get-targets))))))
5556 ;; :regexp filters targets matching provided regexp.
5559 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5560 (let ((org-refile-use-outline-path nil
)
5561 (org-refile-targets `((nil :regexp .
"F"))))
5562 (mapcar #'car
(org-refile-get-targets))))))
5563 ;; A nil `org-refile-targets' includes only top level headlines in
5567 (org-test-with-temp-text "* H1\n** S1\n* H2"
5568 (let ((org-refile-use-outline-path nil
)
5569 (org-refile-targets nil
))
5570 (mapcar #'car
(org-refile-get-targets))))))
5571 ;; Return value is the union of the targets according to all the
5572 ;; defined rules. However, prevent duplicates.
5574 (equal '("F2" "F3" "H1")
5575 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5576 (let ((org-refile-use-outline-path nil
)
5577 (org-refile-targets `((nil :regexp .
"F")
5578 (nil :todo .
"TODO"))))
5579 (mapcar #'car
(org-refile-get-targets))))))
5581 (equal '("F2" "F3" "H1")
5582 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5583 (let ((org-refile-use-outline-path nil
)
5584 (org-refile-targets `((nil :regexp .
"F")
5585 (nil :todo .
"TODO"))))
5586 (mapcar #'car
(org-refile-get-targets))))))
5587 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5590 (equal '("H1" "H1/H2" "H1/H2/H3")
5591 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5592 (let ((org-refile-use-outline-path t
)
5593 (org-refile-targets `((nil :maxlevel .
3))))
5594 (mapcar #'car
(org-refile-get-targets))))))
5595 ;; When providing targets as paths, escape forward slashes in
5596 ;; headings with backslashes.
5598 (equal '("H1\\/foo")
5599 (org-test-with-temp-text "* H1/foo"
5600 (let ((org-refile-use-outline-path t
)
5601 (org-refile-targets `((nil :maxlevel .
1))))
5602 (mapcar #'car
(org-refile-get-targets))))))
5603 ;; When `org-refile-use-outline-path' is `file', include file name
5604 ;; without directory in targets.
5606 (org-test-with-temp-text-in-file "* H1"
5607 (let* ((filename (buffer-file-name))
5608 (org-refile-use-outline-path 'file
)
5609 (org-refile-targets `(((,filename
) :level .
1))))
5610 (member (file-name-nondirectory filename
)
5611 (mapcar #'car
(org-refile-get-targets))))))
5612 ;; When `org-refile-use-outline-path' is `full-file-path', include
5615 (org-test-with-temp-text-in-file "* H1"
5616 (let* ((filename (file-truename (buffer-file-name)))
5617 (org-refile-use-outline-path 'full-file-path
)
5618 (org-refile-targets `(((,filename
) :level .
1))))
5619 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5620 ;; When `org-refile-use-outline-path' is `buffer-name', include
5623 (org-test-with-temp-text "* H1"
5624 (let* ((org-refile-use-outline-path 'buffer-name
)
5625 (org-refile-targets `((nil :level .
1))))
5626 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5632 (ert-deftest test-org
/match-sparse-tree
()
5633 "Test `org-match-sparse-tree' specifications."
5636 (org-test-with-temp-text "* H\n** H1 :tag:"
5637 (org-match-sparse-tree nil
"tag")
5638 (search-forward "H1")
5639 (org-invisible-p2)))
5641 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5642 (org-match-sparse-tree nil
"tag")
5643 (search-forward "H2")
5644 (org-invisible-p2)))
5645 ;; "-" operator for tags.
5647 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5648 (org-match-sparse-tree nil
"tag1-tag2")
5649 (search-forward "H1")
5650 (org-invisible-p2)))
5652 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5653 (org-match-sparse-tree nil
"tag1-tag2")
5654 (search-forward "H2")
5655 (org-invisible-p2)))
5656 ;; "&" operator for tags.
5658 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5659 (org-match-sparse-tree nil
"tag1&tag2")
5660 (search-forward "H1")
5661 (org-invisible-p2)))
5663 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5664 (org-match-sparse-tree nil
"tag1&tag2")
5665 (search-forward "H2")
5666 (org-invisible-p2)))
5667 ;; "|" operator for tags.
5669 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5670 (org-match-sparse-tree nil
"tag1|tag2")
5671 (search-forward "H1")
5672 (org-invisible-p2)))
5674 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5675 (org-match-sparse-tree nil
"tag1|tag2")
5676 (search-forward "H2")
5677 (org-invisible-p2)))
5678 ;; Regexp match on tags.
5680 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5681 (org-match-sparse-tree nil
"{^tag.*}")
5682 (search-forward "H1")
5683 (org-invisible-p2)))
5685 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5686 (org-match-sparse-tree nil
"{^tag.*}")
5687 (search-forward "H2")
5688 (org-invisible-p2)))
5689 ;; Match group tags.
5691 (org-test-with-temp-text
5692 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5693 (org-match-sparse-tree nil
"work")
5694 (search-forward "H1")
5695 (org-invisible-p2)))
5697 (org-test-with-temp-text
5698 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5699 (org-match-sparse-tree nil
"work")
5700 (search-forward "H2")
5701 (org-invisible-p2)))
5702 ;; Match group tags with hard brackets.
5704 (org-test-with-temp-text
5705 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5706 (org-match-sparse-tree nil
"work")
5707 (search-forward "H1")
5708 (org-invisible-p2)))
5710 (org-test-with-temp-text
5711 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5712 (org-match-sparse-tree nil
"work")
5713 (search-forward "H2")
5714 (org-invisible-p2)))
5715 ;; Match tags in hierarchies
5717 (org-test-with-temp-text
5718 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5719 #+TAGS: [ Lev_2 : Lev_3 ]\n
5720 #+TAGS: { Lev_3 : Lev_4 }\n
5721 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5722 (org-match-sparse-tree nil
"Lev_1")
5723 (search-forward "H4")
5724 (org-invisible-p2)))
5725 ;; Match regular expressions in tags
5727 (org-test-with-temp-text
5728 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5729 (org-match-sparse-tree nil
"Lev")
5730 (search-forward "H1")
5731 (org-invisible-p2)))
5733 (org-test-with-temp-text
5734 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5735 (org-match-sparse-tree nil
"Lev")
5736 (search-forward "H1")
5737 (org-invisible-p2)))
5738 ;; Match properties.
5740 (org-test-with-temp-text
5741 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5742 (org-match-sparse-tree nil
"A=\"1\"")
5743 (search-forward "H2")
5744 (org-invisible-p2)))
5746 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5747 (org-match-sparse-tree nil
"A=\"1\"")
5748 (search-forward "H2")
5749 (org-invisible-p2)))
5750 ;; Case is not significant when matching properties.
5752 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5753 (org-match-sparse-tree nil
"a=\"1\"")
5754 (search-forward "H2")
5755 (org-invisible-p2)))
5757 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5758 (org-match-sparse-tree nil
"A=\"1\"")
5759 (search-forward "H2")
5760 (org-invisible-p2)))
5761 ;; Match special LEVEL property.
5763 (org-test-with-temp-text "* H\n** H1\n*** H2"
5764 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5765 (search-forward "H1")
5766 (org-invisible-p2)))
5768 (org-test-with-temp-text "* H\n** H1\n*** H2"
5769 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5770 (search-forward "H2")
5771 (org-invisible-p2)))
5772 ;; Comparison operators when matching properties.
5774 (org-test-with-temp-text
5775 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5776 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5777 (search-forward "H1")
5778 (org-invisible-p2)))
5780 (org-test-with-temp-text
5781 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5782 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5783 (search-forward "H2")
5784 (org-invisible-p2)))
5785 ;; Regexp match on properties values.
5787 (org-test-with-temp-text
5788 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5789 (org-match-sparse-tree nil
"A={f.*}")
5790 (search-forward "H1")
5791 (org-invisible-p2)))
5793 (org-test-with-temp-text
5794 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5795 (org-match-sparse-tree nil
"A={f.*}")
5796 (search-forward "H2")
5797 (org-invisible-p2)))
5798 ;; With an optional argument, limit match to TODO entries.
5800 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5801 (org-match-sparse-tree t
"tag")
5802 (search-forward "H1")
5803 (org-invisible-p2)))
5805 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5806 (org-match-sparse-tree t
"tag")
5807 (search-forward "H2")
5808 (org-invisible-p2))))
5810 (ert-deftest test-org
/occur
()
5811 "Test `org-occur' specifications."
5812 ;; Count number of matches.
5815 (org-test-with-temp-text "* H\nA\n* H2"
5819 (org-test-with-temp-text "* H\nA\n* H2\nA"
5821 ;; Test CALLBACK optional argument.
5824 (org-test-with-temp-text "* H\nA\n* H2"
5825 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5828 (org-test-with-temp-text "* H\nA\n* H2\nA"
5829 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5830 ;; Case-fold searches according to `org-occur-case-fold-search'.
5833 (org-test-with-temp-text "Aa"
5834 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5837 (org-test-with-temp-text "Aa"
5838 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5841 (org-test-with-temp-text "Aa"
5842 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5845 (org-test-with-temp-text "Aa"
5846 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5849 (org-test-with-temp-text "Aa"
5850 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5853 (org-test-with-temp-text "Aa"
5854 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5859 (ert-deftest test-org
/tag-string-to-alist
()
5860 "Test `org-tag-string-to-alist' specifications."
5861 ;; Tag without selection key.
5862 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5863 ;; Tag with selection key.
5864 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5868 (org-tag-string-to-alist "[ group : t1 t2 ]")
5869 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5870 ;; Mutually exclusive tags.
5871 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5872 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5875 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5876 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5878 (ert-deftest test-org
/tag-alist-to-string
()
5879 "Test `org-tag-alist-to-string' specifications."
5880 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5881 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5884 (org-tag-alist-to-string
5885 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5886 "[ group : t1 t2 ]"))
5888 (equal (org-tag-alist-to-string
5889 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5893 (org-tag-alist-to-string
5894 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5895 "{ group : tag1 tag2 }")))
5897 (ert-deftest test-org
/tag-alist-to-groups
()
5898 "Test `org-tag-alist-to-groups' specifications."
5900 (equal (org-tag-alist-to-groups
5901 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5902 '(("group" "t1" "t2"))))
5905 (org-tag-alist-to-groups
5906 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5907 '(("group" "t1" "t2"))))
5909 (org-tag-alist-to-groups
5910 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5912 (ert-deftest test-org
/tag-align
()
5913 "Test tags alignment."
5914 ;; Test aligning tags with different display width.
5916 ;; 12345678901234567890
5917 (equal "* Test :abc:"
5918 (org-test-with-temp-text "* Test :abc:"
5919 (let ((org-tags-column -
20)
5920 (indent-tabs-mode nil
))
5921 (org-fix-tags-on-the-fly))
5924 ;; 12345678901234567890
5925 (equal "* Test :日本語:"
5926 (org-test-with-temp-text "* Test :日本語:"
5927 (let ((org-tags-column -
20)
5928 (indent-tabs-mode nil
))
5929 (org-fix-tags-on-the-fly))
5931 ;; Make sure aligning tags do not skip invisible text.
5933 (equal "* [[linkx]] :tag:"
5934 (org-test-with-temp-text "* [[link<point>]] :tag:"
5935 (let ((org-tags-column 0))
5936 (org-fix-tags-on-the-fly)
5938 (buffer-string))))))
5940 (ert-deftest test-org
/tags-at
()
5942 (equal '("foo" "bar")
5943 (org-test-with-temp-text
5944 "* T<point>est :foo:bar:"
5945 (org-get-tags-at)))))
5950 (ert-deftest test-org
/auto-repeat-maybe
()
5951 "Test `org-auto-repeat-maybe' specifications."
5952 ;; Do not auto repeat when there is no valid time stamp with
5953 ;; a repeater in the entry.
5957 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5958 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5964 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5965 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5968 ;; When switching to DONE state, switch back to first TODO keyword
5969 ;; in sequence, or the same keyword if they have different types.
5973 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5974 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5980 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5981 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5987 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5988 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5991 ;; If there was no TODO keyword in the first place, do not insert
5996 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5997 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
6000 ;; Revert to REPEAT_TO_STATE, if set.
6004 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
6005 (org-test-with-temp-text
6008 :REPEAT_TO_STATE: KWD2
6010 <2012-03-29 Thu +2y>"
6013 ;; When switching to DONE state, update base date. If there are
6014 ;; multiple repeated time stamps, update them all.
6017 "<2014-03-29 .* \\+2y>"
6018 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6019 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6024 "<2015-03-04 .* \\+1y>"
6025 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6026 (org-test-with-temp-text
6027 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6030 ;; Throw an error if repeater unit is the hour and no time is
6031 ;; provided in the time-stamp.
6033 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6034 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6037 ;; Do not repeat commented time stamps.
6040 "<2015-03-04 .* \\+1y>"
6041 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6042 (org-test-with-temp-text
6043 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6048 "<2015-03-04 .* \\+1y>"
6049 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6050 (org-test-with-temp-text
6052 <2012-03-29 Thu. +2y>
6054 <2014-03-04 Tue +1y>
6058 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6059 ;; entry, record time of last repeat.
6063 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6064 (org-log-repeat nil
))
6065 (cl-letf (((symbol-function 'org-add-log-setup
)
6066 (lambda (&rest args
) nil
)))
6067 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6069 (buffer-string))))))
6073 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6075 (cl-letf (((symbol-function 'org-add-log-setup
)
6076 (lambda (&rest args
) nil
)))
6077 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6079 (buffer-string))))))
6083 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6084 (cl-letf (((symbol-function 'org-add-log-setup
)
6085 (lambda (&rest args
) nil
)))
6086 (org-test-with-temp-text
6087 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6089 (buffer-string))))))
6090 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6091 ;; the entry as it is no longer relevant.
6095 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6096 (org-test-with-temp-text
6097 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6100 ;; Properly advance repeater even when a clock entry is specified
6101 ;; and `org-log-repeat' is nil.
6104 "SCHEDULED: <2014-03-29"
6105 (let ((org-log-repeat nil
)
6106 (org-todo-keywords '((sequence "TODO" "DONE"))))
6107 (org-test-with-temp-text
6109 SCHEDULED: <2012-03-29 Thu +2y>
6110 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6112 (buffer-string))))))
6117 (ert-deftest test-org
/at-timestamp-p
()
6118 "Test `org-at-timestamp-p' specifications."
6120 (org-test-with-temp-text "<2012-03-29 Thu>"
6121 (org-at-timestamp-p)))
6123 (org-test-with-temp-text "2012-03-29 Thu"
6124 (org-at-timestamp-p)))
6125 ;; Test return values.
6128 (org-test-with-temp-text "<2012-03-29 Thu>"
6129 (org-at-timestamp-p))))
6132 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6133 (org-at-timestamp-p))))
6136 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6137 (org-at-timestamp-p))))
6140 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6141 (org-at-timestamp-p))))
6144 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6145 (org-at-timestamp-p))))
6148 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6149 (org-at-timestamp-p))))
6152 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6153 (org-at-timestamp-p))))
6156 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6157 (org-at-timestamp-p))))
6158 ;; Test `inactive' optional argument.
6160 (org-test-with-temp-text "[2012-03-29 Thu]"
6161 (org-at-timestamp-p 'inactive
)))
6163 (org-test-with-temp-text "[2012-03-29 Thu]"
6164 (org-at-timestamp-p)))
6165 ;; When optional argument is `agenda', recognize time-stamps in
6166 ;; planning info line, property drawers and clocks.
6168 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6169 (org-at-timestamp-p 'agenda
)))
6171 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6172 (org-at-timestamp-p)))
6174 (org-test-with-temp-text
6175 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6176 (org-at-timestamp-p 'agenda
)))
6178 (org-test-with-temp-text
6179 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6180 (org-at-timestamp-p)))
6182 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6183 (let ((org-agenda-include-inactive-timestamps t
))
6184 (org-at-timestamp-p 'agenda
))))
6186 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6187 (let ((org-agenda-include-inactive-timestamps t
))
6188 (org-at-timestamp-p))))
6190 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6191 (let ((org-agenda-include-inactive-timestamps t
))
6192 (org-at-timestamp-p 'inactive
))))
6193 ;; When optional argument is `lax', match any part of the document
6194 ;; with Org timestamp syntax.
6196 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6197 (org-at-timestamp-p 'lax
)))
6199 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6200 (org-at-timestamp-p)))
6202 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6203 (org-at-timestamp-p 'lax
)))
6205 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6206 (org-at-timestamp-p)))
6208 (org-test-with-temp-text
6209 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6210 (org-at-timestamp-p 'lax
)))
6212 (org-test-with-temp-text
6213 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6214 (org-at-timestamp-p)))
6215 ;; Optional argument `lax' also matches inactive timestamps.
6217 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6218 (org-at-timestamp-p 'lax
))))
6220 (ert-deftest test-org
/time-stamp
()
6221 "Test `org-time-stamp' specifications."
6222 ;; Insert chosen time stamp at point.
6225 "Te<2014-03-04 .*?>xt"
6226 (org-test-with-temp-text "Te<point>xt"
6227 (cl-letf (((symbol-function 'org-read-date
)
6228 (lambda (&rest args
)
6229 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6230 (org-time-stamp nil
)
6232 ;; With a prefix argument, also insert time.
6235 "Te<2014-03-04 .*? 00:41>xt"
6236 (org-test-with-temp-text "Te<point>xt"
6237 (cl-letf (((symbol-function 'org-read-date
)
6238 (lambda (&rest args
)
6239 (apply #'encode-time
6240 (org-parse-time-string "2014-03-04 00:41")))))
6241 (org-time-stamp '(4))
6243 ;; With two universal prefix arguments, insert an active timestamp
6244 ;; with the current time without prompting the user.
6247 "Te<2014-03-04 .*? 00:41>xt"
6248 (org-test-with-temp-text "Te<point>xt"
6249 (cl-letf (((symbol-function 'current-time
)
6251 (apply #'encode-time
6252 (org-parse-time-string "2014-03-04 00:41")))))
6253 (org-time-stamp '(16))
6255 ;; When optional argument is non-nil, insert an inactive timestamp.
6258 "Te\\[2014-03-04 .*?\\]xt"
6259 (org-test-with-temp-text "Te<point>xt"
6260 (cl-letf (((symbol-function 'org-read-date
)
6261 (lambda (&rest args
)
6262 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6263 (org-time-stamp nil t
)
6265 ;; When called from a timestamp, replace existing one.
6269 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6270 (cl-letf (((symbol-function 'org-read-date
)
6271 (lambda (&rest args
)
6272 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6273 (org-time-stamp nil
)
6277 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6278 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6279 (cl-letf (((symbol-function 'org-read-date
)
6280 (lambda (&rest args
)
6281 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6282 (org-time-stamp nil
)
6284 ;; When replacing a timestamp, preserve repeater, if any.
6287 "<2014-03-04 .*? \\+2y>"
6288 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6289 (cl-letf (((symbol-function 'org-read-date
)
6290 (lambda (&rest args
)
6291 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6292 (org-time-stamp nil
)
6294 ;; When called twice in a raw, build a date range.
6297 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6298 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6299 (cl-letf (((symbol-function 'org-read-date
)
6300 (lambda (&rest args
)
6301 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6302 (let ((last-command 'org-time-stamp
)
6303 (this-command 'org-time-stamp
))
6304 (org-time-stamp nil
))
6305 (buffer-string))))))
6307 (ert-deftest test-org
/timestamp-has-time-p
()
6308 "Test `org-timestamp-has-time-p' specifications."
6311 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6312 (org-timestamp-has-time-p (org-element-context))))
6315 (org-test-with-temp-text "<2012-03-29 Thu>"
6316 (org-timestamp-has-time-p (org-element-context)))))
6318 (ert-deftest test-org
/get-repeat
()
6319 "Test `org-get-repeat' specifications."
6321 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6324 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6326 ;; Return proper repeat string.
6329 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6331 ;; Prevent false positive (commented or verbatim time stamps)
6333 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6336 (org-test-with-temp-text
6337 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6339 ;; Return nil when called before first heading.
6341 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6343 ;; When called with an optional argument, extract repeater from that
6345 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6346 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6348 (ert-deftest test-org
/timestamp-format
()
6349 "Test `org-timestamp-format' specifications."
6354 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6355 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6360 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6361 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6363 (ert-deftest test-org
/timestamp-split-range
()
6364 "Test `org-timestamp-split-range' specifications."
6365 ;; Extract range start (active).
6368 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6369 (let ((ts (org-timestamp-split-range (org-element-context))))
6370 (mapcar (lambda (p) (org-element-property p ts
))
6371 '(:year-end
:month-end
:day-end
))))))
6372 ;; Extract range start (inactive)
6375 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6376 (let ((ts (org-timestamp-split-range (org-element-context))))
6377 (mapcar (lambda (p) (org-element-property p ts
))
6378 '(:year-end
:month-end
:day-end
))))))
6379 ;; Extract range end (active).
6382 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6383 (let ((ts (org-timestamp-split-range
6384 (org-element-context) t
)))
6385 (mapcar (lambda (p) (org-element-property p ts
))
6386 '(:year-end
:month-end
:day-end
))))))
6387 ;; Extract range end (inactive)
6390 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6391 (let ((ts (org-timestamp-split-range
6392 (org-element-context) t
)))
6393 (mapcar (lambda (p) (org-element-property p ts
))
6394 '(:year-end
:month-end
:day-end
))))))
6395 ;; Return the timestamp if not a range.
6397 (org-test-with-temp-text "[2012-03-29 Thu]"
6398 (let* ((ts-orig (org-element-context))
6399 (ts-copy (org-timestamp-split-range ts-orig
)))
6400 (eq ts-orig ts-copy
))))
6402 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6403 (let* ((ts-orig (org-element-context))
6404 (ts-copy (org-timestamp-split-range ts-orig
)))
6405 (eq ts-orig ts-copy
)))))
6407 (ert-deftest test-org
/timestamp-translate
()
6408 "Test `org-timestamp-translate' specifications."
6409 ;; Translate whole date range.
6412 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6413 (let ((org-display-custom-times t
)
6414 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6415 (org-timestamp-translate (org-element-context))))))
6416 ;; Translate date range start.
6419 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6420 (let ((org-display-custom-times t
)
6421 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6422 (org-timestamp-translate (org-element-context) 'start
)))))
6423 ;; Translate date range end.
6426 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6427 (let ((org-display-custom-times t
)
6428 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6429 (org-timestamp-translate (org-element-context) 'end
)))))
6430 ;; Translate time range.
6433 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6434 (let ((org-display-custom-times t
)
6435 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6436 (org-timestamp-translate (org-element-context))))))
6437 ;; Translate non-range timestamp.
6440 (org-test-with-temp-text "<2012-03-29 Thu>"
6441 (let ((org-display-custom-times t
)
6442 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6443 (org-timestamp-translate (org-element-context))))))
6444 ;; Do not change `diary' timestamps.
6446 (equal "<%%(org-float t 4 2)>"
6447 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6448 (let ((org-display-custom-times t
)
6449 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6450 (org-timestamp-translate (org-element-context)))))))
6456 (ert-deftest test-org
/flag-drawer
()
6457 "Test `org-flag-drawer' specifications."
6460 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6462 (get-char-property (line-end-position) 'invisible
)))
6465 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6467 (org-flag-drawer nil
)
6468 (get-char-property (line-end-position) 'invisible
)))
6469 ;; Test optional argument.
6471 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6472 (let ((drawer (save-excursion (search-forward ":D2")
6473 (org-element-at-point))))
6474 (org-flag-drawer t drawer
)
6475 (get-char-property (progn (search-forward ":D2") (line-end-position))
6478 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6479 (let ((drawer (save-excursion (search-forward ":D2")
6480 (org-element-at-point))))
6481 (org-flag-drawer t drawer
)
6482 (get-char-property (line-end-position) 'invisible
))))
6483 ;; Do not hide fake drawers.
6485 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6488 (get-char-property (line-end-position) 'invisible
)))
6489 ;; Do not hide incomplete drawers.
6491 (org-test-with-temp-text ":D:\nparagraph"
6494 (get-char-property (line-end-position) 'invisible
)))
6495 ;; Do not hide drawers when called from final blank lines.
6497 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6498 (goto-char (point-max))
6500 (goto-char (point-min))
6501 (get-char-property (line-end-position) 'invisible
)))
6502 ;; Don't leave point in an invisible part of the buffer when hiding
6505 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6506 (goto-char (point-max))
6508 (get-char-property (point) 'invisible
))))
6510 (ert-deftest test-org
/hide-block-toggle
()
6511 "Test `org-hide-block-toggle' specifications."
6512 ;; Error when not at a block.
6514 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6515 (org-hide-block-toggle 'off
)
6516 (get-char-property (line-end-position) 'invisible
)))
6519 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6520 (org-hide-block-toggle)
6521 (get-char-property (line-end-position) 'invisible
)))
6523 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6524 (org-hide-block-toggle)
6525 (get-char-property (line-end-position) 'invisible
)))
6526 ;; Show block unconditionally when optional argument is `off'.
6528 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6529 (org-hide-block-toggle)
6530 (org-hide-block-toggle 'off
)
6531 (get-char-property (line-end-position) 'invisible
)))
6533 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6534 (org-hide-block-toggle 'off
)
6535 (get-char-property (line-end-position) 'invisible
)))
6536 ;; Hide block unconditionally when optional argument is non-nil.
6538 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6539 (org-hide-block-toggle t
)
6540 (get-char-property (line-end-position) 'invisible
)))
6542 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6543 (org-hide-block-toggle)
6544 (org-hide-block-toggle t
)
6545 (get-char-property (line-end-position) 'invisible
)))
6546 ;; Do not hide block when called from final blank lines.
6548 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6549 (org-hide-block-toggle)
6550 (goto-char (point-min))
6551 (get-char-property (line-end-position) 'invisible
)))
6552 ;; Don't leave point in an invisible part of the buffer when hiding
6555 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6556 (org-hide-block-toggle)
6557 (get-char-property (point) 'invisible
))))
6559 (ert-deftest test-org
/hide-block-toggle-maybe
()
6560 "Test `org-hide-block-toggle-maybe' specifications."
6562 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6563 (org-hide-block-toggle-maybe)))
6565 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6567 (ert-deftest test-org
/set-tags
()
6568 "Test `org-set-tags' specifications."
6569 ;; Tags set via fast-tag-selection should be visible afterwards
6571 (let ((org-tag-alist '(("NEXT" . ?n
)))
6572 (org-fast-tag-selection-single-key t
))
6573 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6574 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6575 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6576 ;; Show only headlines
6578 ;; Set NEXT tag on current entry
6579 (org-set-tags nil nil
)
6580 ;; Move point to that NEXT tag
6581 (search-forward "NEXT") (backward-word)
6582 ;; And it should be visible (i.e. no overlays)
6583 (not (overlays-at (point))))))))
6585 (ert-deftest test-org
/show-set-visibility
()
6586 "Test `org-show-set-visibility' specifications."
6587 ;; Do not throw an error before first heading.
6589 (org-test-with-temp-text "Preamble\n* Headline"
6590 (org-show-set-visibility 'tree
)
6592 ;; Test all visibility spans, both on headline and in entry.
6593 (let ((list-visible-lines
6594 (lambda (state headerp
)
6595 (org-test-with-temp-text "* Grandmother (0)
6606 **** The other child (11)
6611 (search-forward (if headerp
"Self" "Match"))
6612 (org-show-set-visibility state
)
6613 (goto-char (point-min))
6614 (let (result (line 0))
6616 (unless (org-invisible-p2) (push line result
))
6619 (nreverse result
))))))
6620 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6621 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6622 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6623 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6624 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6625 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6626 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6627 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6628 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6629 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6630 (funcall list-visible-lines
'tree nil
)))
6631 (should (equal '(0 1 3 4 5 7 12 13)
6632 (funcall list-visible-lines
'canonical t
)))
6633 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6634 (funcall list-visible-lines
'canonical nil
))))
6635 ;; When point is hidden in a drawer or a block, make sure to make it
6638 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6639 (org-hide-block-toggle)
6640 (search-forward "Text")
6641 (org-show-set-visibility 'minimal
)
6642 (org-invisible-p2)))
6644 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6646 (search-forward "Text")
6647 (org-show-set-visibility 'minimal
)
6648 (org-invisible-p2)))
6650 (org-test-with-temp-text
6651 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6654 (org-hide-block-toggle)
6655 (search-forward "Text")
6656 (org-show-set-visibility 'minimal
)
6657 (org-invisible-p2))))
6659 (defun test-org/copy-visible
()
6660 "Test `org-copy-visible' specifications."
6663 (org-test-with-temp-text "Foo"
6664 (let ((kill-ring nil
))
6665 (org-copy-visible (point-min) (point-max))
6666 (current-kill 0 t
)))))
6667 ;; Skip invisible characters by text property.
6670 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6671 (let ((kill-ring nil
))
6672 (org-copy-visible (point-min) (point-max))
6673 (current-kill 0 t
)))))
6674 ;; Skip invisible characters by overlay.
6677 (org-test-with-temp-text "F<hidden>oo"
6678 (let ((o (make-overlay 2 10)))
6679 (overlay-put o
'invisible t
))
6680 (let ((kill-ring nil
))
6681 (org-copy-visible (point-min) (point-max))
6682 (current-kill 0 t
)))))
6683 ;; Handle invisible characters at the beginning and the end of the
6687 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6688 (let ((kill-ring nil
))
6689 (org-copy-visible (point-min) (point-max))
6690 (current-kill 0 t
)))))
6693 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6694 (let ((kill-ring nil
))
6695 (org-copy-visible (point-min) (point-max))
6696 (current-kill 0 t
)))))
6697 ;; Handle multiple visible parts.
6700 (org-test-with-temp-text
6701 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6702 (let ((kill-ring nil
))
6703 (org-copy-visible (point-min) (point-max))
6704 (current-kill 0 t
))))))
6709 ;;; test-org.el ends here