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
)
378 (lambda () '(22353 6425 905205 644000))))
379 ;; Timestamps are close if they are within `ndays' of lead time.
380 (org-test-with-temp-text "* Heading"
381 (should (org-deadline-close-p "2016-06-03 Fri" 0))
382 (should (org-deadline-close-p "2016-06-02 Thu" 0))
383 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
384 (should (org-deadline-close-p "2016-06-04 Sat" 1))
385 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
386 ;; Read `ndays' from timestamp if argument not given.
387 (org-test-with-temp-text "* H"
388 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
389 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
390 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
391 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
392 ;; Prefer `ndays' argument over lead time in timestamp.
393 (org-test-with-temp-text "* H"
394 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
395 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
396 ;; Completed tasks are never close.
397 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
398 (org-test-with-temp-text "* TODO Heading"
399 (should (org-deadline-close-p "2016-06-03")))
400 (org-test-with-temp-text "* DONE Heading"
401 (should-not (org-deadline-close-p "2016-06-03"))))))
406 (ert-deftest test-org
/insert-property-drawer
()
407 "Test `org-insert-property-drawer' specifications."
408 ;; Error before first headline.
409 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
410 ;; Insert drawer right after headline if there is no planning line,
411 ;; or after it otherwise.
413 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
414 (org-test-with-temp-text "* H\nParagraph<point>"
415 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
418 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
419 (org-test-with-temp-text
420 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
421 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
423 ;; Indent inserted drawer.
425 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
426 (org-test-with-temp-text "* H\nParagraph<point>"
427 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
429 ;; Handle insertion at eob.
431 (equal "* H\n:PROPERTIES:\n:END:\n"
432 (org-test-with-temp-text "* H"
433 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
435 ;; Skip inlinetasks before point.
436 (when (featurep 'org-inlinetask
)
438 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
439 (org-test-with-temp-text
440 "* H\n*************** I\n*************** END\nP<point>"
441 (let ((org-adapt-indentation nil
)
442 (org-inlinetask-min-level 15))
443 (org-insert-property-drawer))
445 ;; Correctly set drawer in an inlinetask.
446 (when (featurep 'org-inlinetask
)
448 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
449 (org-test-with-temp-text
450 "* H\n*************** I\nP<point>\n*************** END"
451 (let ((org-adapt-indentation nil
)
452 (org-inlinetask-min-level 15))
453 (org-insert-property-drawer))
459 (ert-deftest test-org
/fill-element
()
460 "Test `org-fill-element' specifications."
461 ;; At an Org table, align it.
464 (org-test-with-temp-text "|a|"
468 (equal "#+name: table\n| a |\n"
469 (org-test-with-temp-text "#+name: table\n| a |\n"
472 ;; At a paragraph, preserve line breaks.
473 (org-test-with-temp-text "some \\\\\nlong\ntext"
474 (let ((fill-column 20))
476 (should (equal (buffer-string) "some \\\\\nlong text"))))
477 ;; Correctly fill a paragraph when point is at its very end.
480 (org-test-with-temp-text "A\nB"
481 (let ((fill-column 20))
482 (goto-char (point-max))
485 ;; Correctly fill the last paragraph of a greater element.
487 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
488 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
489 (let ((fill-column 8))
494 ;; Correctly fill an element in a narrowed buffer.
497 (org-test-with-temp-text "01234 6789"
498 (let ((fill-column 5))
499 (narrow-to-region 1 8)
502 ;; Handle `adaptive-fill-regexp' in paragraphs.
505 (org-test-with-temp-text "> a\n> b"
506 (let ((fill-column 5)
507 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
510 ;; Special case: Fill first paragraph when point is at an item or
511 ;; a plain-list or a footnote reference.
514 (org-test-with-temp-text "- A\n B"
515 (let ((fill-column 20))
520 (org-test-with-temp-text "[fn:1] A\nB"
521 (let ((fill-column 20))
524 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
525 (let ((fill-column 20))
527 (should (equal (buffer-string)
528 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
529 ;; Fill contents of `comment-block' elements.
532 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
533 (let ((fill-column 20))
537 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
538 ;; Fill `comment' elements.
541 (org-test-with-temp-text " # A\n # B"
542 (let ((fill-column 20))
545 ;; Do not mix consecutive comments when filling one of them.
547 (equal "# A B\n\n# C"
548 (org-test-with-temp-text "# A\n# B\n\n# C"
549 (let ((fill-column 20))
552 ;; Use commented empty lines as separators when filling comments.
554 (equal "# A B\n#\n# C"
555 (org-test-with-temp-text "# A\n# B\n#\n# C"
556 (let ((fill-column 20))
559 ;; Handle `adaptive-fill-regexp' in comments.
562 (org-test-with-temp-text "# > a\n# > b"
563 (let ((fill-column 20)
564 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
567 ;; Do nothing at affiliated keywords.
569 (equal "#+NAME: para\nSome\ntext."
570 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
571 (let ((fill-column 20))
574 ;; Do not move point after table when filling a table.
576 (org-test-with-temp-text "| a | b |\n| c | d |\n"
580 ;; Do not fill "n" macro, with or without arguments, followed by
581 ;; a dot or a closing parenthesis since it could be confused with
582 ;; a numbered bullet.
584 (equal "123456789\n{{{n}}}."
585 (org-test-with-temp-text "123456789 {{{n}}}."
586 (let ((fill-column 10))
590 (equal "123456789\n{{{n}}}\)"
591 (org-test-with-temp-text "123456789 {{{n}}}\)"
592 (let ((fill-column 10))
596 (equal "123456789\n{{{n()}}}."
597 (org-test-with-temp-text "123456789 {{{n()}}}."
598 (let ((fill-column 10))
602 (equal "123456789\n{{{n(counter)}}}."
603 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
604 (let ((fill-column 10))
608 (ert-deftest test-org
/auto-fill-function
()
609 "Test auto-filling features."
610 ;; Auto fill paragraph.
613 (org-test-with-temp-text "12345 7890"
614 (let ((fill-column 5))
616 (org-auto-fill-function)
618 ;; Auto fill first paragraph in an item.
620 (equal "- 12345\n 7890"
621 (org-test-with-temp-text "- 12345 7890"
622 (let ((fill-column 7))
624 (org-auto-fill-function)
626 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
628 (equal "> 12345\n 7890"
629 (org-test-with-temp-text "> 12345 7890"
630 (let ((fill-column 10)
631 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
632 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
634 (org-auto-fill-function)
637 (equal "> 12345\n> 12345\n> 7890"
638 (org-test-with-temp-text "> 12345\n> 12345 7890"
639 (let ((fill-column 10)
640 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
641 (goto-char (point-max))
642 (org-auto-fill-function)
645 (equal " 12345\n *12345\n *12345"
646 (org-test-with-temp-text " 12345\n *12345 12345"
647 (let ((fill-column 10)
648 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
649 (goto-char (point-max))
650 (org-auto-fill-function)
652 ;; Auto fill comments.
654 (equal " # 12345\n # 7890"
655 (org-test-with-temp-text " # 12345 7890"
656 (let ((fill-column 10))
658 (org-auto-fill-function)
660 ;; A hash within a line isn't a comment.
662 (equal "12345 # 7890\n# 1"
663 (org-test-with-temp-text "12345 # 7890 1"
664 (let ((fill-column 12))
666 (org-auto-fill-function)
668 ;; Correctly interpret empty prefix.
670 (equal "# a\n# b\nRegular\n# paragraph"
671 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
672 (let ((fill-column 12))
674 (org-auto-fill-function)
676 ;; Comment block: auto fill contents.
678 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
679 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
680 (let ((fill-column 5))
683 (org-auto-fill-function)
686 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
687 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
688 (let ((fill-column 5))
691 (org-auto-fill-function)
693 ;; Do not fill if a new item could be created.
696 (org-test-with-temp-text "12345 - 90"
697 (let ((fill-column 5))
699 (org-auto-fill-function)
701 ;; Do not fill if a line break could be introduced.
703 (equal "123\\\\\n7890"
704 (org-test-with-temp-text "123\\\\ 7890"
705 (let ((fill-column 6))
707 (org-auto-fill-function)
709 ;; Do not fill affiliated keywords.
711 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
712 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
713 (let ((fill-column 20))
715 (org-auto-fill-function)
722 (ert-deftest test-org
/indent-line
()
723 "Test `org-indent-line' specifications."
724 ;; Do not indent diary sexps, footnote definitions or headlines.
727 (org-test-with-temp-text "%%(org-calendar-holiday)"
729 (org-get-indentation))))
732 (org-test-with-temp-text "[fn:1] fn"
733 (let ((org-adapt-indentation t
)) (org-indent-line))
734 (org-get-indentation))))
737 (org-test-with-temp-text "* H"
739 (org-get-indentation))))
740 ;; Do not indent before first headline.
743 (org-test-with-temp-text ""
745 (org-get-indentation))))
746 ;; Indent according to headline level otherwise, unless
747 ;; `org-adapt-indentation' is nil.
750 (org-test-with-temp-text "* H\n<point>A"
751 (let ((org-adapt-indentation t
)) (org-indent-line))
752 (org-get-indentation))))
755 (org-test-with-temp-text "* H\n<point>\nA"
756 (let ((org-adapt-indentation t
)) (org-indent-line))
757 (org-get-indentation))))
760 (org-test-with-temp-text "* H\n<point>A"
761 (let ((org-adapt-indentation nil
)) (org-indent-line))
762 (org-get-indentation))))
763 ;; Indenting preserves point position.
765 (org-test-with-temp-text "* H\nA<point>B"
766 (let ((org-adapt-indentation t
)) (org-indent-line))
768 ;; Do not change indentation at an item or a LaTeX environment.
771 (org-test-with-temp-text "* H\n<point> - A"
772 (let ((org-adapt-indentation t
)) (org-indent-line))
773 (org-get-indentation))))
776 (org-test-with-temp-text
777 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
779 (org-get-indentation))))
780 ;; On blank lines at the end of a list, indent like last element
781 ;; within it if the line is still in the list. If the last element
782 ;; is an item, indent like its contents. Otherwise, indent like the
786 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
787 (let ((org-adapt-indentation t
)) (org-indent-line))
788 (org-get-indentation))))
791 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
792 (let ((org-adapt-indentation t
)) (org-indent-line))
793 (org-get-indentation))))
796 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
797 (let ((org-adapt-indentation t
)) (org-indent-line))
798 (org-get-indentation))))
801 (org-test-with-temp-text "* H\n- A\n - \n<point>"
802 (let ((org-adapt-indentation t
)) (org-indent-line))
803 (org-get-indentation))))
806 (org-test-with-temp-text
807 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
808 (let ((org-adapt-indentation t
)) (org-indent-line))
809 (org-get-indentation))))
812 (org-test-with-temp-text "- A\n B\n\n<point>"
813 (let ((org-adapt-indentation nil
)) (org-indent-line))
814 (org-get-indentation))))
817 (org-test-with-temp-text
818 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
819 (let ((org-adapt-indentation nil
)) (org-indent-line))
820 (org-get-indentation))))
821 ;; Likewise, on a blank line at the end of a footnote definition,
822 ;; indent at column 0 if line belongs to the definition. Otherwise,
823 ;; indent like the definition itself.
826 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
827 (let ((org-adapt-indentation t
)) (org-indent-line))
828 (org-get-indentation))))
831 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
832 (let ((org-adapt-indentation t
)) (org-indent-line))
833 (org-get-indentation))))
834 ;; After the end of the contents of a greater element, indent like
835 ;; the beginning of the element.
838 (org-test-with-temp-text
839 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
841 (org-get-indentation))))
842 ;; On blank lines after a paragraph, indent like its last non-empty
846 (org-test-with-temp-text " Paragraph\n\n<point>"
848 (org-get-indentation))))
849 ;; At the first line of an element, indent like previous element's
850 ;; first line, ignoring footnotes definitions and inline tasks, or
851 ;; according to parent.
854 (org-test-with-temp-text "A\n\n B\n\nC<point>"
856 (org-get-indentation))))
859 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
861 (org-get-indentation))))
864 (org-test-with-temp-text
865 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
867 (org-get-indentation))))
868 ;; Within code part of a source block, use language major mode if
869 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
870 ;; according to line above.
873 (org-test-with-temp-text
874 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
875 (let ((org-src-tab-acts-natively t
)
876 (org-edit-src-content-indentation 0))
878 (org-get-indentation))))
881 (org-test-with-temp-text
882 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
883 (let ((org-src-tab-acts-natively nil
)
884 (org-edit-src-content-indentation 0))
886 (org-get-indentation))))
887 ;; Otherwise, indent like the first non-blank line above.
890 (org-test-with-temp-text
891 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
893 (org-get-indentation))))
894 ;; Align node properties according to `org-property-format'. Handle
895 ;; nicely empty values.
897 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
898 (org-test-with-temp-text
899 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
900 (let ((org-property-format "%-10s %s")) (org-indent-line))
903 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
904 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
905 (let ((org-property-format "%-10s %s")) (org-indent-line))
908 (ert-deftest test-org
/indent-region
()
909 "Test `org-indent-region' specifications."
913 (org-test-with-temp-text " A\nB\n C"
914 (org-indent-region (point-min) (point-max))
916 ;; Indent greater elements along with their contents.
918 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
919 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
920 (org-indent-region (point-min) (point-max))
922 ;; Ignore contents of verse blocks. Only indent block delimiters.
924 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
925 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
926 (org-indent-region (point-min) (point-max))
929 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
930 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
931 (org-indent-region (point-min) (point-max))
933 ;; Indent example blocks as a single block, unless indentation
934 ;; should be preserved. In this case only indent the block markers.
936 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
937 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
938 (org-indent-region (point-min) (point-max))
941 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
942 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
943 (org-indent-region (point-min) (point-max))
946 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
947 (org-test-with-temp-text
948 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
949 (org-indent-region (point-min) (point-max))
952 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
953 (org-test-with-temp-text
954 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
955 (let ((org-src-preserve-indentation t
))
956 (org-indent-region (point-min) (point-max)))
958 ;; Treat export blocks as a whole.
960 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
961 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
962 (org-indent-region (point-min) (point-max))
965 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
966 (org-test-with-temp-text
967 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
968 (org-indent-region (point-min) (point-max))
970 ;; Indent according to mode if `org-src-tab-acts-natively' is
971 ;; non-nil. Otherwise, do not indent code at all.
973 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
974 (org-test-with-temp-text
975 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
976 (let ((org-src-tab-acts-natively t
)
977 (org-edit-src-content-indentation 0))
978 (org-indent-region (point-min) (point-max)))
981 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
982 (org-test-with-temp-text
983 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
984 (let ((org-src-tab-acts-natively nil
)
985 (org-edit-src-content-indentation 0))
986 (org-indent-region (point-min) (point-max)))
988 ;; Align node properties according to `org-property-format'. Handle
989 ;; nicely empty values.
991 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
992 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
993 (let ((org-property-format "%-10s %s")
994 (org-adapt-indentation nil
))
995 (org-indent-region (point) (point-max)))
998 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
999 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
1000 (let ((org-property-format "%-10s %s")
1001 (org-adapt-indentation nil
))
1002 (org-indent-region (point) (point-max)))
1004 ;; Indent plain lists.
1006 (equal "- A\n B\n - C\n\n D"
1007 (org-test-with-temp-text "- A\n B\n - C\n\n D"
1008 (org-indent-region (point-min) (point-max))
1012 (org-test-with-temp-text " - A\n\n - B"
1013 (org-indent-region (point-min) (point-max))
1015 ;; Indent footnote definitions.
1017 (equal "[fn:1] Definition\n\nDefinition"
1018 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1019 (org-indent-region (point-min) (point-max))
1021 ;; Special case: Start indenting on a blank line.
1023 (equal "\nParagraph"
1024 (org-test-with-temp-text "\n Paragraph"
1025 (org-indent-region (point-min) (point-max))
1032 (ert-deftest test-org
/delete-indentation
()
1033 "Test `org-delete-indentation' specifications."
1035 (should (equal "foo bar"
1036 (org-test-with-temp-text
1038 (org-delete-indentation)
1040 ;; With optional argument.
1041 (should (equal "foo bar"
1042 (org-test-with-temp-text
1044 (org-delete-indentation t
)
1046 ;; At headline text should be appended to the headline text.
1048 (equal"* foo bar :tag:"
1049 (let (org-auto-align-tags)
1050 (org-test-with-temp-text
1051 "* foo :tag:\n bar<point>"
1052 (org-delete-indentation)
1055 (equal "* foo bar :tag:"
1056 (let (org-auto-align-tags)
1057 (org-test-with-temp-text
1058 "* foo <point>:tag:\n bar"
1059 (org-delete-indentation t
)
1060 (buffer-string))))))
1062 (ert-deftest test-org
/return
()
1063 "Test `org-return' specifications."
1066 (equal "Para\ngraph"
1067 (org-test-with-temp-text "Para<point>graph"
1070 ;; With optional argument, indent line.
1072 (equal " Para\n graph"
1073 (org-test-with-temp-text " Para<point>graph"
1076 ;; On a table, call `org-table-next-row'.
1078 (org-test-with-temp-text "| <point>a |\n| b |"
1080 (looking-at-p "b")))
1081 ;; Open link or timestamp under point when `org-return-follows-link'
1084 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1085 (let ((org-return-follows-link t
)
1086 (org-link-search-must-match-exact-headline nil
))
1088 (looking-at-p "<<target>>")))
1090 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1091 (let ((org-return-follows-link nil
)) (org-return))
1092 (looking-at-p "<<target>>")))
1094 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1095 (let ((org-return-follows-link t
)) (org-return))
1096 (looking-at-p "* b")))
1098 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1099 (let ((org-return-follows-link t
)
1100 (org-link-search-must-match-exact-headline nil
))
1102 (looking-at-p "<<target>>")))
1104 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1105 (let ((org-return-follows-link t
)
1106 (org-link-search-must-match-exact-headline nil
))
1108 (looking-at-p "<<target>>")))
1109 ;; When `org-return-follows-link' is non-nil, tolerate links and
1110 ;; timestamps in comments, node properties, etc.
1112 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1113 (let ((org-return-follows-link t
)
1114 (org-link-search-must-match-exact-headline nil
))
1116 (looking-at-p "<<target>>")))
1118 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1119 (let ((org-return-follows-link nil
)) (org-return))
1120 (looking-at-p "<<target>>")))
1122 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1123 (let ((org-return-follows-link t
)
1124 (org-link-search-must-match-exact-headline nil
))
1126 (looking-at-p "<<target>>")))
1127 ;; However, do not open link when point is in a table.
1129 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1130 (let ((org-return-follows-link t
)) (org-return))
1131 (looking-at-p "between")))
1132 ;; Special case: in a list, when indenting, do not break structure.
1135 (org-test-with-temp-text "- A <point>B"
1140 (org-test-with-temp-text "- A\n<point>- B"
1143 ;; On tags part of a headline, add a newline below it instead of
1146 (equal "* H :tag:\n"
1147 (org-test-with-temp-text "* H :<point>tag:"
1150 ;; Before headline text, add a newline below it instead of breaking
1153 (equal "* TODO H :tag:\n"
1154 (org-test-with-temp-text "* <point>TODO H :tag:"
1158 (equal "* TODO [#B] H :tag:\n"
1159 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1162 (should ;TODO are case-sensitive
1164 (org-test-with-temp-text "* <point>Todo"
1167 ;; At headline text, break headline text but preserve tags.
1169 (equal "* TODO [#B] foo :tag:\nbar"
1170 (let (org-auto-align-tags)
1171 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1174 ;; At bol of headline insert newline.
1177 (org-test-with-temp-text "<point>* h"
1180 ;; Refuse to leave invalid headline in buffer.
1183 (org-test-with-temp-text "*<point> h"
1187 (ert-deftest test-org
/meta-return
()
1188 "Test M-RET (`org-meta-return') specifications."
1189 ;; In a table field insert a row above.
1191 (org-test-with-temp-text "| a |"
1195 (looking-at "| |$")))
1196 ;; In a paragraph change current line into a header.
1198 (org-test-with-temp-text "a"
1201 (looking-at "\* a$")))
1202 ;; In an item insert an item, in this case above.
1204 (org-test-with-temp-text "- a"
1207 (looking-at "- $")))
1208 ;; In a drawer and item insert an item, in this case above.
1210 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1214 (looking-at "- $"))))
1216 (ert-deftest test-org
/insert-heading
()
1217 "Test `org-insert-heading' specifications."
1218 ;; In an empty buffer, insert a new headline.
1221 (org-test-with-temp-text ""
1222 (org-insert-heading)
1224 ;; At the beginning of a line, turn it into a headline.
1227 (org-test-with-temp-text "<point>P"
1228 (org-insert-heading)
1230 ;; In the middle of a line, split the line if allowed, otherwise,
1231 ;; insert the headline at its end.
1233 (equal "Para\n* graph"
1234 (org-test-with-temp-text "Para<point>graph"
1235 (let ((org-M-RET-may-split-line '((default . t
))))
1236 (org-insert-heading))
1239 (equal "Paragraph\n* "
1240 (org-test-with-temp-text "Para<point>graph"
1241 (let ((org-M-RET-may-split-line '((default . nil
))))
1242 (org-insert-heading))
1244 ;; At the beginning of a headline, create one above.
1247 (org-test-with-temp-text "* H"
1248 (org-insert-heading)
1250 ;; In the middle of a headline, split it if allowed.
1253 (org-test-with-temp-text "* H<point>1"
1254 (let ((org-M-RET-may-split-line '((headline . t
))))
1255 (org-insert-heading))
1259 (org-test-with-temp-text "* H<point>1"
1260 (let ((org-M-RET-may-split-line '((headline . nil
))))
1261 (org-insert-heading))
1263 ;; However, splitting cannot happen on TODO keywords, priorities or
1266 (equal "* TODO H1\n* \n"
1267 (org-test-with-temp-text "* TO<point>DO H1"
1268 (let ((org-M-RET-may-split-line '((headline . t
))))
1269 (org-insert-heading))
1272 (equal "* [#A] H1\n* \n"
1273 (org-test-with-temp-text "* [#<point>A] H1"
1274 (let ((org-M-RET-may-split-line '((headline . t
))))
1275 (org-insert-heading))
1278 (equal "* H1 :tag:\n* \n"
1279 (org-test-with-temp-text "* H1 :ta<point>g:"
1280 (let ((org-M-RET-may-split-line '((headline . t
))))
1281 (org-insert-heading))
1283 ;; New headline level depends on the level of the headline above.
1286 (org-test-with-temp-text "** H\n<point>P"
1287 (org-insert-heading)
1290 (equal "** H\nPara\n** graph"
1291 (org-test-with-temp-text "** H\nPara<point>graph"
1292 (let ((org-M-RET-may-split-line '((default . t
))))
1293 (org-insert-heading))
1297 (org-test-with-temp-text "** H"
1298 (org-insert-heading)
1300 ;; When called with one universal argument, insert a new headline at
1301 ;; the end of the current subtree, independently on the position of
1306 (org-test-with-temp-text "* H1\n** H2"
1307 (let ((org-insert-heading-respect-content nil
))
1308 (org-insert-heading '(4)))
1313 (org-test-with-temp-text "* H<point>1\n** H2"
1314 (let ((org-insert-heading-respect-content nil
))
1315 (org-insert-heading '(4)))
1317 ;; When called with two universal arguments, insert a new headline
1318 ;; at the end of the grandparent subtree.
1320 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1321 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1322 (let ((org-insert-heading-respect-content nil
))
1323 (org-insert-heading '(16)))
1325 ;; When optional TOP-LEVEL argument is non-nil, always insert
1326 ;; a level 1 heading.
1328 (equal "* H1\n** H2\n* \n"
1329 (org-test-with-temp-text "* H1\n** H2<point>"
1330 (org-insert-heading nil nil t
)
1333 (equal "* H1\n- item\n* "
1334 (org-test-with-temp-text "* H1\n- item<point>"
1335 (org-insert-heading nil nil t
)
1337 ;; Obey `org-blank-before-new-entry'.
1339 (equal "* H1\n\n* \n"
1340 (org-test-with-temp-text "* H1<point>"
1341 (let ((org-blank-before-new-entry '((heading . t
))))
1342 (org-insert-heading))
1346 (org-test-with-temp-text "* H1<point>"
1347 (let ((org-blank-before-new-entry '((heading . nil
))))
1348 (org-insert-heading))
1351 (equal "* H1\n* H2\n* \n"
1352 (org-test-with-temp-text "* H1\n* H2<point>"
1353 (let ((org-blank-before-new-entry '((heading . auto
))))
1354 (org-insert-heading))
1357 (equal "* H1\n\n* H2\n\n* \n"
1358 (org-test-with-temp-text "* H1\n\n* H2<point>"
1359 (let ((org-blank-before-new-entry '((heading . auto
))))
1360 (org-insert-heading))
1362 ;; Corner case: correctly insert a headline after an empty one.
1365 (org-test-with-temp-text "* <point>"
1366 (org-insert-heading)
1369 (org-test-with-temp-text "* <point>\n"
1370 (org-insert-heading)
1371 (looking-at-p "\n\\'")))
1372 ;; Do not insert spurious headlines when inserting a new headline.
1374 (equal "* H1\n* H2\n* \n"
1375 (org-test-with-temp-text "* H1\n* H2<point>\n"
1376 (org-insert-heading)
1378 ;; Preserve visibility at beginning of line. In particular, when
1379 ;; removing spurious blank lines, do not visually merge heading with
1380 ;; the line visible above.
1382 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1384 (let ((org-blank-before-new-entry '((heading . nil
))))
1385 (org-insert-heading '(4)))
1386 (invisible-p (line-end-position 0))))
1387 ;; Properly handle empty lines when forcing a headline below current
1390 (equal "* H1\n\n* H\n\n* \n"
1391 (org-test-with-temp-text "* H1\n\n* H<point>"
1392 (let ((org-blank-before-new-entry '((heading . t
))))
1393 (org-insert-heading '(4))
1394 (buffer-string))))))
1396 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1397 "Test `org-insert-todo-heading-respect-content' specifications."
1398 ;; Create a TODO heading.
1400 (org-test-with-temp-text "* H1\n Body"
1401 (org-insert-todo-heading-respect-content)
1402 (nth 2 (org-heading-components))))
1403 ;; Add headline at the end of the first subtree
1407 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1408 (org-insert-todo-heading-respect-content)
1409 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1410 ;; In a list, do not create a new item.
1414 (org-test-with-temp-text "* H\n- an item\n- another one"
1415 (search-forward "an ")
1416 (org-insert-todo-heading-respect-content)
1417 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1419 (ert-deftest test-org
/clone-with-time-shift
()
1420 "Test `org-clone-subtree-with-time-shift'."
1421 ;; Raise an error before first heading.
1423 (org-test-with-temp-text ""
1424 (org-clone-subtree-with-time-shift 1)))
1425 ;; Raise an error on invalid number of clones.
1427 (org-test-with-temp-text "* Clone me"
1428 (org-clone-subtree-with-time-shift -
1)))
1429 ;; Clone non-repeating once.
1435 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1436 (org-clone-subtree-with-time-shift 1 "+2d")
1437 (replace-regexp-in-string
1438 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1440 ;; Clone repeating once.
1445 * H1\n<2015-06-25 +1w>
1447 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1448 (org-clone-subtree-with-time-shift 1 "+2d")
1449 (replace-regexp-in-string
1450 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1452 ;; Clone non-repeating zero times.
1457 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1458 (org-clone-subtree-with-time-shift 0 "+2d")
1459 (replace-regexp-in-string
1460 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1462 ;; Clone repeating "zero" times.
1466 * H1\n<2015-06-23 +1w>
1468 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1469 (org-clone-subtree-with-time-shift 0 "+2d")
1470 (replace-regexp-in-string
1471 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1473 ;; Clone with blank SHIFT argument.
1477 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1478 (org-clone-subtree-with-time-shift 1 "")
1479 (buffer-substring-no-properties (line-beginning-position 2)
1480 (line-end-position 2)))))
1481 ;; Find time stamps before point. If SHIFT is not specified, ask
1482 ;; for a time shift.
1486 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1487 (org-clone-subtree-with-time-shift 1 "+1d")
1488 (buffer-substring-no-properties (line-beginning-position 2)
1489 (line-end-position 2)))))
1493 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1494 (cl-letf (((symbol-function 'read-from-minibuffer
)
1495 (lambda (&rest args
) "+1d")))
1496 (org-clone-subtree-with-time-shift 1))
1497 (buffer-substring-no-properties (line-beginning-position 2)
1498 (line-end-position 2))))))
1501 ;;; Fixed-Width Areas
1503 (ert-deftest test-org
/toggle-fixed-width
()
1504 "Test `org-toggle-fixed-width' specifications."
1505 ;; No region: Toggle on fixed-width marker in paragraphs.
1508 (org-test-with-temp-text "A"
1509 (org-toggle-fixed-width)
1511 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1514 (org-test-with-temp-text ": A"
1515 (org-toggle-fixed-width)
1517 ;; No region: Toggle on marker in blank lines after elements or just
1518 ;; after a headline.
1521 (org-test-with-temp-text "* H\n"
1523 (org-toggle-fixed-width)
1526 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1527 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1528 (goto-char (point-max))
1529 (org-toggle-fixed-width)
1531 ;; No region: Toggle on marker in front of one line elements (e.g.,
1532 ;; headlines, clocks)
1534 (equal ": * Headline"
1535 (org-test-with-temp-text "* Headline"
1536 (org-toggle-fixed-width)
1539 (equal ": #+KEYWORD: value"
1540 (org-test-with-temp-text "#+KEYWORD: value"
1541 (org-toggle-fixed-width)
1543 ;; No region: error in other situations.
1545 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1547 (org-toggle-fixed-width)
1549 ;; No region: Indentation is preserved.
1552 (org-test-with-temp-text "- A\n B"
1554 (org-toggle-fixed-width)
1556 ;; Region: If it contains only fixed-width elements and blank lines,
1557 ;; toggle off fixed-width markup.
1560 (org-test-with-temp-text ": A\n\n: B"
1561 (transient-mark-mode 1)
1562 (push-mark (point) t t
)
1563 (goto-char (point-max))
1564 (org-toggle-fixed-width)
1566 ;; Region: If it contains anything else, toggle on fixed-width but
1567 ;; not on fixed-width areas.
1569 (equal ": A\n: \n: B\n: \n: C"
1570 (org-test-with-temp-text "A\n\n: B\n\nC"
1571 (transient-mark-mode 1)
1572 (push-mark (point) t t
)
1573 (goto-char (point-max))
1574 (org-toggle-fixed-width)
1576 ;; Region: Ignore blank lines at its end, unless it contains only
1580 (org-test-with-temp-text "A\n\n"
1581 (transient-mark-mode 1)
1582 (push-mark (point) t t
)
1583 (goto-char (point-max))
1584 (org-toggle-fixed-width)
1588 (org-test-with-temp-text "\n\n"
1589 (transient-mark-mode 1)
1590 (push-mark (point) t t
)
1591 (goto-char (point-max))
1592 (org-toggle-fixed-width)
1599 (ert-deftest test-org
/get-heading
()
1600 "Test `org-get-heading' specifications."
1601 ;; Return current heading, even if point is not on it.
1604 (org-test-with-temp-text "* H"
1605 (org-get-heading))))
1608 (org-test-with-temp-text "* H\nText<point>"
1609 (org-get-heading))))
1610 ;; Without any optional argument, return TODO keyword, priority
1611 ;; cookie, COMMENT keyword and tags.
1614 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1615 (org-get-heading))))
1618 (org-test-with-temp-text "* [#A] H"
1619 (org-get-heading))))
1622 (org-test-with-temp-text "* COMMENT H"
1623 (org-get-heading))))
1626 (org-test-with-temp-text "* H :tag:"
1627 (org-get-heading))))
1628 ;; With NO-TAGS argument, ignore tags.
1631 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1632 (org-get-heading t
))))
1635 (org-test-with-temp-text "* H :tag:"
1636 (org-get-heading t
))))
1637 ;; With NO-TODO, ignore TODO keyword.
1640 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1641 (org-get-heading nil t
))))
1644 (org-test-with-temp-text "* H :tag:"
1645 (org-get-heading nil t
))))
1646 ;; TODO keywords are case-sensitive.
1649 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1650 (org-get-heading nil t
))))
1651 ;; With NO-PRIORITY, ignore priority.
1654 (org-test-with-temp-text "* [#A] H"
1655 (org-get-heading nil nil t
))))
1658 (org-test-with-temp-text "* H"
1659 (org-get-heading nil nil t
))))
1662 (org-test-with-temp-text "* TODO [#A] H"
1663 (org-get-heading nil nil t
))))
1664 ;; With NO-COMMENT, ignore COMMENT keyword.
1667 (org-test-with-temp-text "* COMMENT H"
1668 (org-get-heading nil nil nil t
))))
1671 (org-test-with-temp-text "* H"
1672 (org-get-heading nil nil nil t
))))
1674 (equal "TODO [#A] H"
1675 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1676 (org-get-heading nil nil nil t
))))
1677 ;; On an empty headline, return value is consistent.
1678 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1679 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1680 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1681 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1683 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1685 (ert-deftest test-org
/in-commented-heading-p
()
1686 "Test `org-in-commented-heading-p' specifications."
1687 ;; Commented headline.
1689 (org-test-with-temp-text "* COMMENT Headline\nBody"
1690 (goto-char (point-max))
1691 (org-in-commented-heading-p)))
1692 ;; Commented ancestor.
1694 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1695 (goto-char (point-max))
1696 (org-in-commented-heading-p)))
1697 ;; Comment keyword is case-sensitive.
1699 (org-test-with-temp-text "* Comment Headline\nBody"
1700 (goto-char (point-max))
1701 (org-in-commented-heading-p)))
1702 ;; Keyword is standalone.
1704 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1705 (goto-char (point-max))
1706 (org-in-commented-heading-p)))
1707 ;; Optional argument.
1709 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1710 (goto-char (point-max))
1711 (org-in-commented-heading-p t
))))
1713 (ert-deftest test-org
/entry-blocked-p
()
1714 ;; Check other dependencies.
1716 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1717 (let ((org-enforce-todo-dependencies t
)
1719 '(org-block-todo-from-children-or-siblings-or-parent)))
1720 (org-entry-blocked-p))))
1722 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1723 (let ((org-enforce-todo-dependencies t
)
1725 '(org-block-todo-from-children-or-siblings-or-parent)))
1726 (org-entry-blocked-p))))
1727 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1730 (org-test-with-temp-text "* Blocked\n** TODO one"
1731 (let ((org-enforce-todo-dependencies t
)
1733 '(org-block-todo-from-children-or-siblings-or-parent)))
1734 (org-entry-blocked-p))))
1736 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1737 (let ((org-enforce-todo-dependencies t
)
1739 '(org-block-todo-from-children-or-siblings-or-parent)))
1740 (org-entry-blocked-p))))
1741 ;; Follow :ORDERED: specifications.
1743 (org-test-with-temp-text
1744 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1745 (let ((org-enforce-todo-dependencies t
)
1747 '(org-block-todo-from-children-or-siblings-or-parent)))
1748 (org-entry-blocked-p))))
1750 (org-test-with-temp-text
1751 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1752 (let ((org-enforce-todo-dependencies t
)
1754 '(org-block-todo-from-children-or-siblings-or-parent)))
1755 (org-entry-blocked-p)))))
1757 (ert-deftest test-org
/get-outline-path
()
1758 "Test `org-get-outline-path' specifications."
1759 ;; Top-level headlines have no outline path.
1761 (org-test-with-temp-text "* H"
1762 (org-get-outline-path)))
1763 ;; Otherwise, outline path is the path leading to the headline.
1766 (org-test-with-temp-text "* H\n** S<point>"
1767 (org-get-outline-path))))
1768 ;; Find path even when point is not on a headline.
1771 (org-test-with-temp-text "* H\n** S\nText<point>"
1772 (org-get-outline-path))))
1773 ;; TODO keywords, tags and statistics cookies are ignored.
1776 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1777 (org-get-outline-path))))
1778 ;; Links are replaced with their description or their path.
1781 (org-test-with-temp-text
1782 "* [[http://orgmode.org][Org]]\n** S<point>"
1783 (org-get-outline-path))))
1785 (equal '("http://orgmode.org")
1786 (org-test-with-temp-text
1787 "* [[http://orgmode.org]]\n** S<point>"
1788 (org-get-outline-path))))
1789 ;; When WITH-SELF is non-nil, include current heading.
1792 (org-test-with-temp-text "* H"
1793 (org-get-outline-path t
))))
1796 (org-test-with-temp-text "* H\n** S\nText<point>"
1797 (org-get-outline-path t
))))
1798 ;; Using cache is transparent to the user.
1801 (org-test-with-temp-text "* H\n** S<point>"
1802 (setq org-outline-path-cache nil
)
1803 (org-get-outline-path nil t
))))
1804 ;; Do not corrupt cache when finding outline path in distant part of
1808 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1809 (setq org-outline-path-cache nil
)
1810 (org-get-outline-path nil t
)
1811 (search-forward "S2")
1812 (org-get-outline-path nil t
))))
1813 ;; Do not choke on empty headlines.
1815 (org-test-with-temp-text "* H\n** <point>"
1816 (org-get-outline-path)))
1818 (org-test-with-temp-text "* \n** H<point>"
1819 (org-get-outline-path))))
1821 (ert-deftest test-org
/format-outline-path
()
1822 "Test `org-format-outline-path' specifications."
1824 (string= (org-format-outline-path (list "one" "two" "three"))
1828 (string= (org-format-outline-path '())
1831 (string= (org-format-outline-path '(nil))
1833 ;; Empty path and prefix.
1835 (string= (org-format-outline-path '() nil
">>")
1837 ;; Trailing whitespace in headings.
1839 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1841 ;; Non-default prefix and separators.
1843 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1844 ">>|one|two|three"))
1847 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1849 ;; Give a very narrow width.
1851 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1853 ;; Give a prefix that extends beyond the width.
1855 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1859 (ert-deftest test-org
/map-entries
()
1860 "Test `org-map-entries' specifications."
1864 (org-test-with-temp-text "* Level 1\n** Level 2"
1865 (org-map-entries #'point
))))
1869 (org-test-with-temp-text "* Level 1\n** Level 2"
1870 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1873 (org-test-with-temp-text "* Level 1\n** Level 2"
1874 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1878 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1879 (org-map-entries #'point
"yes"))))
1882 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1883 (org-map-entries #'point
"+yes-a"))))
1886 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1887 (org-map-entries #'point
"{yes?}"))))
1891 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1892 (org-map-entries #'point
"PRIORITY=\"A\""))))
1896 (org-test-with-temp-text "
1898 SCHEDULED: <2012-03-29 thu.>
1900 SCHEDULED: <2014-03-04 tue.>"
1901 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1904 (org-test-with-temp-text "
1906 SCHEDULED: <2012-03-29 thu.>
1908 SCHEDULED: <2014-03-04 tue.>"
1909 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1910 ;; Regular property match.
1913 (org-test-with-temp-text "
1922 (org-map-entries #'point
"TEST=1"))))
1923 ;; Multiple criteria.
1926 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1927 (let (org-odd-levels-only
1928 (org-use-tag-inheritance nil
))
1929 (org-map-entries #'point
"yes+LEVEL=1")))))
1933 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1934 (let (org-odd-levels-only)
1935 (org-map-entries #'point
"LEVEL=2|no")))))
1938 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1939 (let (org-odd-levels-only)
1940 (org-map-entries #'point
"yes|no")))))
1944 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1945 (let (org-odd-levels-only)
1946 (org-map-entries #'point
"yes&no"))))))
1948 (ert-deftest test-org
/edit-headline
()
1949 "Test `org-edit-headline' specifications."
1952 (org-test-with-temp-text "* A"
1953 (org-edit-headline "B")
1955 ;; Handle empty headings.
1958 (org-test-with-temp-text "* A"
1959 (org-edit-headline "")
1963 (org-test-with-temp-text "* "
1964 (org-edit-headline "A")
1966 ;; Handle TODO keywords and priority cookies.
1969 (org-test-with-temp-text "* TODO A"
1970 (org-edit-headline "B")
1974 (org-test-with-temp-text "* [#A] A"
1975 (org-edit-headline "B")
1978 (equal "* TODO [#A] B"
1979 (org-test-with-temp-text "* TODO [#A] A"
1980 (org-edit-headline "B")
1984 (org-test-with-temp-text "* A :tag:"
1985 (let ((org-tags-column 4)) (org-edit-headline "B"))
1992 (ert-deftest test-org
/set-regexps-and-options
()
1993 "Test `org-set-regexps-and-options' specifications."
1997 (let ((org-tag-alist '(("A")))
1998 (org-tag-persistent-alist nil
))
1999 (org-test-with-temp-text ""
2001 org-current-tag-alist
))))
2004 (let ((org-tag-alist '(("A")))
2005 (org-tag-persistent-alist nil
))
2006 (org-test-with-temp-text "#+TAGS: B"
2008 org-current-tag-alist
))))
2010 (equal '(("C") ("B"))
2011 (let ((org-tag-alist '(("A")))
2012 (org-tag-persistent-alist '(("C"))))
2013 (org-test-with-temp-text "#+TAGS: B"
2015 org-current-tag-alist
))))
2018 (let ((org-tag-alist '(("A")))
2019 (org-tag-persistent-alist '(("C"))))
2020 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2022 org-current-tag-alist
))))
2024 (equal '(("A" . ?a
) ("B") ("C"))
2025 (let ((org-tag-persistant-alist nil
))
2026 (org-test-with-temp-text "#+TAGS: A(a) B C"
2028 org-current-tag-alist
))))
2030 (equal '(("A") (:newline
) ("B"))
2031 (let ((org-tag-persistent-alist nil
))
2032 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2034 org-current-tag-alist
))))
2036 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2037 (let ((org-tag-persistent-alist nil
))
2038 (org-test-with-temp-text "#+TAGS: { A B } C"
2040 org-current-tag-alist
))))
2042 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2043 (let ((org-tag-persistent-alist nil
))
2044 (org-test-with-temp-text "#+TAGS: { A : B C }"
2046 org-current-tag-alist
))))
2048 (equal '(("A" "B" "C"))
2049 (let ((org-tag-persistent-alist nil
))
2050 (org-test-with-temp-text "#+TAGS: { A : B C }"
2052 org-tag-groups-alist
))))
2054 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2055 (let ((org-tag-persistent-alist nil
))
2056 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2058 org-current-tag-alist
))))
2060 (equal '(("A" "B" "C"))
2061 (let ((org-tag-persistent-alist nil
))
2062 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2064 org-tag-groups-alist
))))
2065 ;; FILETAGS keyword.
2067 (equal '("A" "B" "C")
2068 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2071 ;; PROPERTY keyword. Property names are case-insensitive.
2074 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2076 (cdr (assoc "var" org-file-properties
)))))
2080 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2082 (cdr (assoc "var" org-file-properties
)))))
2086 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2088 (cdr (assoc "var" org-file-properties
)))))
2092 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2094 org-archive-location
)))
2095 ;; CATEGORY keyword.
2098 (org-test-with-temp-text "#+CATEGORY: test"
2103 (org-test-with-temp-text "#+CATEGORY: test"
2105 (cdr (assoc "CATEGORY" org-file-properties
)))))
2108 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2109 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2111 org-columns-default-format
)))
2112 ;; CONSTANTS keyword. Constants names are case sensitive.
2114 (equal '("299792458." "3.14")
2115 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2118 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2122 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2124 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2127 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2129 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2134 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2136 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2138 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2142 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2144 (list org-highest-priority org-lowest-priority org-default-priority
))))
2148 (org-test-with-temp-text "#+PRIORITIES: X Z"
2150 (list org-highest-priority org-lowest-priority org-default-priority
))))
2154 (org-test-with-temp-text "#+STARTUP: fold odd"
2156 (list org-startup-folded org-odd-levels-only
))))
2159 (equal '(("A" "B") ("C"))
2160 (org-test-with-temp-text "#+TODO: A B | C"
2162 (list org-not-done-keywords org-done-keywords
))))
2164 (equal '(("A" "C") ("B" "D"))
2165 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2167 (list org-not-done-keywords org-done-keywords
))))
2169 (equal '(("A" "B") ("C"))
2170 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2172 (list org-not-done-keywords org-done-keywords
))))
2174 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2175 (org-test-with-temp-text "#+TODO: A(a)"
2177 org-todo-key-alist
)))
2179 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2180 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2182 org-todo-log-states
)))
2183 ;; Enter SETUPFILE keyword.
2186 (org-test-with-temp-text
2187 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2189 (cdr (assoc "a" org-file-properties
))))))
2197 (ert-deftest test-org
/coderef
()
2198 "Test coderef links specifications."
2200 (org-test-with-temp-text "
2201 #+BEGIN_SRC emacs-lisp
2206 (looking-at "(ref:sc)")))
2207 ;; Find coderef even with alternate label format.
2209 (org-test-with-temp-text "
2210 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2215 (looking-at "{ref:sc}"))))
2219 (ert-deftest test-org
/custom-id
()
2220 "Test custom ID links specifications."
2222 (org-test-with-temp-text
2223 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2225 (looking-at-p "\\* H1")))
2226 ;; Throw an error on false positives.
2228 (org-test-with-temp-text
2229 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2231 (looking-at-p "\\* H1"))))
2235 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2236 ;; a named element (#+name: text) and to headlines (* Text).
2238 (ert-deftest test-org
/fuzzy-links
()
2239 "Test fuzzy links specifications."
2240 ;; Fuzzy link goes in priority to a matching target.
2242 (org-test-with-temp-text
2243 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2244 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2245 (looking-at "<<Test>>")))
2246 ;; Then fuzzy link points to an element with a given name.
2248 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2249 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2250 (looking-at "#\\+NAME: Test")))
2251 ;; A target still lead to a matching headline otherwise.
2253 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2254 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2255 (looking-at "\\* Head2")))
2256 ;; With a leading star in link, enforce heading match.
2258 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2259 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2260 (looking-at "\\* Test")))
2261 ;; With a leading star in link, enforce exact heading match, even
2262 ;; with `org-link-search-must-match-exact-headline' set to nil.
2264 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2265 (let ((org-link-search-must-match-exact-headline nil
))
2266 (org-open-at-point))))
2267 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2269 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2270 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2271 (looking-at "\\* Test")))
2273 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2274 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2275 (looking-at "\\* Test")))
2276 ;; Heading match should not care about spaces, cookies, TODO
2277 ;; keywords, priorities, and tags. However, TODO keywords are
2281 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2282 (org-test-with-temp-text
2283 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2284 (let ((org-link-search-must-match-exact-headline nil
)
2285 (org-todo-regexp "TODO"))
2286 (org-open-at-point))
2287 (looking-at (regexp-quote first-line
)))))
2289 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2290 (let ((org-link-search-must-match-exact-headline nil
)
2291 (org-todo-regexp "TODO"))
2292 (org-open-at-point))))
2293 ;; Heading match should still be exact.
2295 (org-test-with-temp-text "
2296 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2299 (let ((org-link-search-must-match-exact-headline nil
)
2300 (org-todo-regexp "TODO"))
2301 (org-open-at-point))))
2303 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2304 (let ((org-link-search-must-match-exact-headline nil
)
2305 (org-todo-regexp "TODO"))
2306 (org-open-at-point))
2307 (looking-at-p (regexp-quote "** Test 1 2"))))
2308 ;; Heading match ignores COMMENT keyword.
2310 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2312 (looking-at "\\* COMMENT Test")))
2314 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2316 (looking-at "\\* TODO COMMENT Test")))
2317 ;; Correctly un-hexify fuzzy links.
2319 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2323 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2326 ;; Match search strings containing newline characters, including
2329 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2330 (let ((file (buffer-file-name)))
2331 (goto-char (point-max))
2332 (insert (format "[[file:%s::line1 line2]]" file
))
2334 (let ((org-link-search-must-match-exact-headline nil
))
2335 (org-open-at-point 0))
2336 (looking-at-p "line1"))))
2338 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\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")))))
2349 (ert-deftest test-org
/org-link-escape-ascii-character
()
2350 "Escape an ascii character."
2354 (org-link-escape "["))))
2356 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2357 "Escape an ascii control character."
2361 (org-link-escape "\t"))))
2363 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2364 "Escape an unicode multibyte character."
2368 (org-link-escape "€"))))
2370 (ert-deftest test-org
/org-link-escape-custom-table
()
2371 "Escape string with custom character table."
2375 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2377 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2378 "Escape string with custom table merged with default table."
2381 "%5BF%6F%6F%3A%42ar%0A%5D"
2382 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2384 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2385 "Unescape an ascii character."
2389 (org-link-unescape "%5B"))))
2391 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2392 "Unescpae an ascii control character."
2396 (org-link-unescape "%0A"))))
2398 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2399 "Unescape unicode multibyte character."
2403 (org-link-unescape "%E2%82%AC"))))
2405 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2406 "Unescape old style percent escaped character."
2409 "à âçèéêîôùû"
2410 (decode-coding-string
2411 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2413 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2414 "Escape and unescape a URL that includes an escaped char.
2415 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2418 "http://some.host.com/form?&id=blah%2Bblah25"
2420 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2424 (ert-deftest test-org
/open-at-point-in-keyword
()
2425 "Does `org-open-at-point' open link in a keyword line?"
2427 (org-test-with-temp-text
2428 "<<top>>\n#+KEYWORD: <point>[[top]]"
2429 (org-open-at-point) t
)))
2431 (ert-deftest test-org
/open-at-point-in-property
()
2432 "Does `org-open-at-point' open link in property drawer?"
2434 (org-test-with-temp-text
2437 :URL: <point>[[*Headline]]
2439 (org-open-at-point) t
)))
2441 (ert-deftest test-org
/open-at-point-in-comment
()
2442 "Does `org-open-at-point' open link in a commented line?"
2444 (org-test-with-temp-text
2445 "<<top>>\n# <point>[[top]]"
2446 (org-open-at-point) t
)))
2448 (ert-deftest test-org
/open-at-point
/inline-image
()
2449 "Test `org-open-at-point' on nested links."
2451 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2455 (ert-deftest test-org
/open-at-point
/radio-target
()
2456 "Test `org-open-at-point' on radio targets."
2458 (org-test-with-temp-text "<<<target>>> <point>target"
2459 (org-update-radio-target-regexp)
2461 (eq (org-element-type (org-element-context)) 'radio-target
))))
2465 (ert-deftest test-org
/store-link
()
2466 "Test `org-store-link' specifications."
2467 ;; On a headline, link to that headline. Use heading as the
2468 ;; description of the link.
2470 (let (org-store-link-props org-stored-links
)
2471 (org-test-with-temp-text-in-file "* H1"
2472 (let ((file (buffer-file-name)))
2473 (equal (format "[[file:%s::*H1][H1]]" file
)
2474 (org-store-link nil
))))))
2475 ;; On a headline, remove any link from description.
2477 (let (org-store-link-props org-stored-links
)
2478 (org-test-with-temp-text-in-file "* [[#l][d]]"
2479 (let ((file (buffer-file-name)))
2480 (equal (format "[[file:%s::*%s][d]]"
2482 (org-link-escape "[[#l][d]]"))
2483 (org-store-link nil
))))))
2485 (let (org-store-link-props org-stored-links
)
2486 (org-test-with-temp-text-in-file "* [[l]]"
2487 (let ((file (buffer-file-name)))
2488 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2489 (org-store-link nil
))))))
2491 (let (org-store-link-props org-stored-links
)
2492 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2493 (let ((file (buffer-file-name)))
2494 (equal (format "[[file:%s::*%s][d1 d2]]"
2496 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2497 (org-store-link nil
))))))
2498 ;; On a named element, link to that element.
2500 (let (org-store-link-props org-stored-links
)
2501 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2502 (let ((file (buffer-file-name)))
2503 (equal (format "[[file:%s::foo][foo]]" file
)
2504 (org-store-link nil
))))))
2505 ;; Store link to Org buffer, with context.
2507 (let ((org-stored-links nil
)
2508 (org-id-link-to-org-use-id nil
)
2509 (org-context-in-file-links t
))
2510 (org-test-with-temp-text-in-file "* h1"
2511 (let ((file (buffer-file-name)))
2512 (equal (format "[[file:%s::*h1][h1]]" file
)
2513 (org-store-link nil
))))))
2514 ;; Store link to Org buffer, without context.
2516 (let ((org-stored-links nil
)
2517 (org-id-link-to-org-use-id nil
)
2518 (org-context-in-file-links nil
))
2519 (org-test-with-temp-text-in-file "* h1"
2520 (let ((file (buffer-file-name)))
2521 (equal (format "[[file:%s][file:%s]]" file file
)
2522 (org-store-link nil
))))))
2523 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2525 (let ((org-stored-links nil
)
2526 (org-id-link-to-org-use-id nil
)
2527 (org-context-in-file-links nil
))
2528 (org-test-with-temp-text-in-file "* h1"
2529 (let ((file (buffer-file-name)))
2530 (equal (format "[[file:%s::*h1][h1]]" file
)
2531 (org-store-link '(4)))))))
2532 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2535 (let ((org-stored-links nil
)
2536 (org-id-link-to-org-use-id nil
)
2537 (org-context-in-file-links nil
))
2538 (org-test-with-temp-text-in-file "* h1"
2539 (let ((file (buffer-file-name)))
2540 (equal (format "[[file:%s][file:%s]]" file file
)
2541 (org-store-link '(16)))))))
2542 ;; Store file link to non-Org buffer, with context.
2544 (let ((org-stored-links nil
)
2545 (org-context-in-file-links t
))
2546 (org-test-with-temp-text-in-file "one\n<point>two"
2548 (let ((file (buffer-file-name)))
2549 (equal (format "[[file:%s::one]]" file
)
2550 (org-store-link nil
))))))
2551 ;; Store file link to non-Org buffer, without context.
2553 (let ((org-stored-links nil
)
2554 (org-context-in-file-links nil
))
2555 (org-test-with-temp-text-in-file "one\n<point>two"
2557 (let ((file (buffer-file-name)))
2558 (equal (format "[[file:%s][file:%s]]" file file
)
2559 (org-store-link nil
))))))
2560 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2563 (let ((org-stored-links nil
)
2564 (org-context-in-file-links nil
))
2565 (org-test-with-temp-text-in-file "one\n<point>two"
2567 (let ((file (buffer-file-name)))
2568 (equal (format "[[file:%s::one]]" file
)
2569 (org-store-link '(4)))))))
2570 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2573 (let ((org-stored-links nil
)
2574 (org-context-in-file-links nil
))
2575 (org-test-with-temp-text-in-file "one\n<point>two"
2577 (let ((file (buffer-file-name)))
2578 (equal (format "[[file:%s][file:%s]]" file file
)
2579 (org-store-link '(16))))))))
2584 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2585 "Ensure properties accumulate in subtree drawers."
2586 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2587 (org-babel-next-src-block)
2588 (should (equal '(2 1) (org-babel-execute-src-block)))))
2590 (ert-deftest test-org
/custom-properties
()
2591 "Test custom properties specifications."
2594 (let ((org-custom-properties '("FOO")))
2595 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2596 (org-toggle-custom-properties-visibility)
2597 (org-invisible-p2))))
2598 ;; Properties are case-insensitive.
2600 (let ((org-custom-properties '("FOO")))
2601 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2602 (org-toggle-custom-properties-visibility)
2603 (org-invisible-p2))))
2605 (let ((org-custom-properties '("foo")))
2606 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2607 (org-toggle-custom-properties-visibility)
2608 (org-invisible-p2))))
2609 ;; Multiple custom properties in the same drawer.
2611 (let ((org-custom-properties '("FOO" "BAR")))
2612 (org-test-with-temp-text
2613 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2614 (org-toggle-custom-properties-visibility)
2615 (and (org-invisible-p2)
2616 (not (progn (forward-line) (org-invisible-p2)))
2617 (progn (forward-line) (org-invisible-p2))))))
2618 ;; Hide custom properties with an empty value.
2620 (let ((org-custom-properties '("FOO")))
2621 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2622 (org-toggle-custom-properties-visibility)
2623 (org-invisible-p2))))
2624 ;; Do not hide fake properties.
2626 (let ((org-custom-properties '("FOO")))
2627 (org-test-with-temp-text ":FOO: val\n"
2628 (org-toggle-custom-properties-visibility)
2629 (org-invisible-p2))))
2631 (let ((org-custom-properties '("A")))
2632 (org-test-with-temp-text
2633 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2634 (org-toggle-custom-properties-visibility)
2635 (org-invisible-p2)))))
2641 (ert-deftest test-org
/mark-subtree
()
2642 "Test `org-mark-subtree' specifications."
2643 ;; Error when point is before first headline.
2645 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2646 (progn (transient-mark-mode 1)
2647 (org-mark-subtree))))
2648 ;; Without argument, mark current subtree.
2652 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2653 (progn (transient-mark-mode 1)
2656 (list (region-beginning) (region-end))))))
2657 ;; With an argument, move ARG up.
2661 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2662 (progn (transient-mark-mode 1)
2664 (org-mark-subtree 1)
2665 (list (region-beginning) (region-end))))))
2666 ;; Do not get fooled by inlinetasks.
2667 (when (featurep 'org-inlinetask
)
2670 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2671 (progn (transient-mark-mode 1)
2673 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2674 (region-beginning)))))))
2680 (ert-deftest test-org
/in-regexp
()
2681 "Test `org-in-regexp' specifications."
2684 (org-test-with-temp-text "xx ab<point>c xx"
2685 (org-in-regexp "abc")))
2687 (org-test-with-temp-text "xx abc <point>xx"
2688 (org-in-regexp "abc")))
2689 ;; Return non-nil even with multiple matching regexps in the same
2692 (org-test-with-temp-text "abc xx ab<point>c xx"
2693 (org-in-regexp "abc")))
2694 ;; With optional argument NLINES, check extra lines around point.
2696 (org-test-with-temp-text "A\nB<point>\nC"
2697 (org-in-regexp "A\nB\nC")))
2699 (org-test-with-temp-text "A\nB<point>\nC"
2700 (org-in-regexp "A\nB\nC" 1)))
2702 (org-test-with-temp-text "A\nB\nC<point>"
2703 (org-in-regexp "A\nB\nC" 1)))
2704 ;; When optional argument VISUALLY is non-nil, return nil if at
2705 ;; regexp boundaries.
2707 (org-test-with-temp-text "xx abc<point> xx"
2708 (org-in-regexp "abc")))
2710 (org-test-with-temp-text "xx abc<point> xx"
2711 (org-in-regexp "abc" nil t
))))
2713 (ert-deftest test-org
/sort-entries
()
2714 "Test `org-sort-entries'."
2715 ;; Sort alphabetically.
2717 (equal "\n* abc\n* def\n* xyz\n"
2718 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2719 (org-sort-entries nil ?a
)
2722 (equal "\n* xyz\n* def\n* abc\n"
2723 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2724 (org-sort-entries nil ?A
)
2726 ;; Sort numerically.
2728 (equal "\n* 1\n* 2\n* 10\n"
2729 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2730 (org-sort-entries nil ?n
)
2733 (equal "\n* 10\n* 2\n* 1\n"
2734 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2735 (org-sort-entries nil ?N
)
2737 ;; Sort by custom function.
2739 (equal "\n* b\n* aa\n* ccc\n"
2740 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2741 (org-sort-entries nil ?f
2743 (length (buffer-substring (point-at-bol)
2748 (equal "\n* ccc\n* aa\n* b\n"
2749 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2750 (org-sort-entries nil ?F
2752 (length (buffer-substring (point-at-bol)
2756 ;; Sort by TODO keyword.
2758 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2759 (org-test-with-temp-text
2760 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2761 (org-sort-entries nil ?o
)
2764 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2765 (org-test-with-temp-text
2766 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2767 (org-sort-entries nil ?O
)
2769 ;; Sort by priority.
2771 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2772 (org-test-with-temp-text
2773 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2774 (org-sort-entries nil ?p
)
2777 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2778 (org-test-with-temp-text
2779 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2780 (org-sort-entries nil ?P
)
2782 ;; Sort by creation time.
2792 (org-test-with-temp-text
2801 (org-sort-entries nil ?c
)
2804 ;; Sort by scheduled date.
2808 SCHEDULED: <2017-05-06 Sat>
2810 SCHEDULED: <2017-05-08 Mon>
2812 DEADLINE: <2017-05-09 Tue>
2814 DEADLINE: <2017-05-07 Sun>
2816 (org-test-with-temp-text
2819 DEADLINE: <2017-05-09 Tue>
2821 DEADLINE: <2017-05-07 Sun>
2823 SCHEDULED: <2017-05-08 Mon>
2825 SCHEDULED: <2017-05-06 Sat>
2827 (org-sort-entries nil ?s
)
2829 ;; Sort by deadline date.
2833 DEADLINE: <2017-05-07 Sun>
2835 DEADLINE: <2017-05-09 Tue>
2837 SCHEDULED: <2017-05-08 Mon>
2839 SCHEDULED: <2017-05-06 Sat>
2841 (org-test-with-temp-text
2844 DEADLINE: <2017-05-09 Tue>
2846 DEADLINE: <2017-05-07 Sun>
2848 SCHEDULED: <2017-05-08 Mon>
2850 SCHEDULED: <2017-05-06 Sat>
2852 (org-sort-entries nil ?d
)
2854 ;; Sort by any date/time
2858 SCHEDULED: <2017-05-06 Sat>
2860 DEADLINE: <2017-05-07 Sun>
2862 SCHEDULED: <2017-05-08 Mon>
2864 DEADLINE: <2017-05-09 Tue>
2866 (org-test-with-temp-text
2869 DEADLINE: <2017-05-09 Tue>
2871 DEADLINE: <2017-05-07 Sun>
2873 SCHEDULED: <2017-05-08 Mon>
2875 SCHEDULED: <2017-05-06 Sat>
2877 (org-sort-entries nil ?t
)
2879 ;; Sort by clocking time.
2884 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2885 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2889 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2890 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2893 (org-test-with-temp-text
2897 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2898 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2902 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2903 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2906 (org-sort-entries nil ?k
)
2912 (ert-deftest test-org
/forward-heading-same-level
()
2913 "Test `org-forward-heading-same-level' specifications."
2914 ;; Test navigation at top level, forward and backward.
2917 (org-test-with-temp-text "* H1\n* H2"
2918 (org-forward-heading-same-level 1)
2919 (buffer-substring-no-properties (point) (line-end-position)))))
2922 (org-test-with-temp-text "* H1\n<point>* H2"
2923 (org-forward-heading-same-level -
1)
2924 (buffer-substring-no-properties (point) (line-end-position)))))
2925 ;; Test navigation in a sub-tree, forward and backward.
2928 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2929 (org-forward-heading-same-level 1)
2930 (buffer-substring-no-properties (point) (line-end-position)))))
2933 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
2934 (org-forward-heading-same-level -
1)
2935 (buffer-substring-no-properties (point) (line-end-position)))))
2936 ;; Stop at first or last sub-heading.
2939 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
2940 (org-forward-heading-same-level 1)
2941 (buffer-substring-no-properties (point) (line-end-position)))))
2944 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
2945 (org-forward-heading-same-level -
1)
2946 (buffer-substring-no-properties (point) (line-end-position)))))
2947 ;; Allow multiple moves.
2950 (org-test-with-temp-text "* H1\n* H2\n* H3"
2951 (org-forward-heading-same-level 2)
2952 (buffer-substring-no-properties (point) (line-end-position)))))
2955 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
2956 (org-forward-heading-same-level -
2)
2957 (buffer-substring-no-properties (point) (line-end-position)))))
2958 ;; Ignore spurious moves when first (or last) sibling is reached.
2961 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
2962 (org-forward-heading-same-level 100)
2963 (buffer-substring-no-properties (point) (line-end-position)))))
2966 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
2967 (org-forward-heading-same-level -
100)
2968 (buffer-substring-no-properties (point) (line-end-position))))))
2970 (ert-deftest test-org
/end-of-meta-data
()
2971 "Test `org-end-of-meta-data' specifications."
2972 ;; Skip planning line.
2974 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2975 (org-end-of-meta-data)
2977 ;; Skip properties drawer.
2979 (org-test-with-temp-text
2980 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2981 (org-end-of-meta-data)
2985 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2986 (org-end-of-meta-data)
2988 ;; Nothing to skip, go to first line.
2990 (org-test-with-temp-text "* Headline\nContents"
2991 (org-end-of-meta-data)
2992 (looking-at "Contents")))
2993 ;; With option argument, skip empty lines, regular drawers and
2996 (org-test-with-temp-text "* Headline\n\nContents"
2997 (org-end-of-meta-data t
)
2998 (looking-at "Contents")))
3000 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3001 (org-end-of-meta-data t
)
3002 (looking-at "Contents")))
3004 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3005 (org-end-of-meta-data t
)
3006 (looking-at "Contents")))
3007 ;; Special case: do not skip incomplete drawers.
3009 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3010 (org-end-of-meta-data t
)
3011 (looking-at ":LOGBOOK:")))
3012 ;; Special case: Be careful about consecutive headlines.
3014 (org-test-with-temp-text "* H1\n*H2\nContents"
3015 (org-end-of-meta-data t
)
3016 (looking-at "Contents"))))
3018 (ert-deftest test-org
/beginning-of-line
()
3019 "Test `org-beginning-of-line' specifications."
3020 ;; Move to beginning of line. If current line in invisible, move to
3021 ;; beginning of visible line instead.
3023 (org-test-with-temp-text "Some text\nSome other text<point>"
3024 (org-beginning-of-line)
3027 (org-test-with-temp-text "* H1\n** H2<point>"
3029 (org-beginning-of-line)
3030 (= (line-beginning-position) 1)))
3031 ;; With `visual-line-mode' active, move to beginning of visual line.
3033 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3035 (dotimes (i 1000) (insert "very "))
3036 (org-beginning-of-line)
3038 ;; In a wide headline, with `visual-line-mode', prefer going to the
3039 ;; beginning of a visual line than to the logical beginning of line,
3040 ;; even if special movement is active.
3042 (org-test-with-temp-text "* A <point>long headline"
3044 (dotimes (i 1000) (insert "very "))
3045 (goto-char (point-max))
3046 (org-beginning-of-line)
3049 (org-test-with-temp-text "* A <point>long headline"
3051 (dotimes (i 1000) (insert "very "))
3052 (goto-char (point-max))
3053 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3055 ;; At an headline with special movement, first move at beginning of
3056 ;; title, then at the beginning of line, rinse, repeat.
3058 (org-test-with-temp-text "* TODO Headline<point>"
3059 (let ((org-special-ctrl-a/e t
))
3060 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3061 (progn (org-beginning-of-line) (bolp))
3062 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3064 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3065 (let ((org-special-ctrl-a/e t
))
3066 (org-beginning-of-line)
3067 (looking-at "Headline"))))
3069 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3070 (let ((org-special-ctrl-a/e
'(t . nil
)))
3071 (org-beginning-of-line)
3072 (looking-at "Headline"))))
3074 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3075 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3076 (org-beginning-of-line)
3077 (looking-at "Headline"))))
3078 ;; At an headline with reversed movement, first move to beginning of
3079 ;; line, then to the beginning of title.
3081 (org-test-with-temp-text "* TODO Headline<point>"
3082 (let ((org-special-ctrl-a/e
'reversed
)
3083 (this-command last-command
))
3084 (and (progn (org-beginning-of-line) (bolp))
3085 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3087 (org-test-with-temp-text "* TODO Headline<point>"
3088 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3089 (this-command last-command
))
3090 (and (progn (org-beginning-of-line) (bolp))
3091 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3093 (org-test-with-temp-text "* TODO Headline<point>"
3094 (let ((org-special-ctrl-a/e
'(t . nil
))
3095 (this-command last-command
))
3096 (and (progn (org-beginning-of-line) (bolp))
3097 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3098 ;; At an item with special movement, first move after to beginning
3099 ;; of title, then to the beginning of line, rinse, repeat.
3101 (org-test-with-temp-text "- [ ] Item<point>"
3102 (let ((org-special-ctrl-a/e t
))
3103 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3104 (progn (org-beginning-of-line) (bolp))
3105 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3106 ;; At an item with reversed movement, first move to beginning of
3107 ;; line, then to the beginning of title.
3109 (org-test-with-temp-text "- [X] Item<point>"
3110 (let ((org-special-ctrl-a/e
'reversed
)
3111 (this-command last-command
))
3112 (and (progn (org-beginning-of-line) (bolp))
3113 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3114 ;; Leave point before invisible characters at column 0.
3116 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3117 (let ((org-special-ctrl-a/e nil
))
3118 (org-beginning-of-line)
3121 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3122 (let ((org-special-ctrl-a/e t
))
3123 (org-beginning-of-line)
3126 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3128 (org-beginning-of-line)
3130 ;; Special case: Do not error when the buffer contains only a single
3133 (org-test-with-temp-text "*<point>"
3134 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3136 (org-test-with-temp-text "*<point>"
3137 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3139 (ert-deftest test-org
/end-of-line
()
3140 "Test `org-end-of-line' specifications."
3143 (org-test-with-temp-text "Some text\nSome other text"
3146 ;; With `visual-line-mode' active, move to end of visible line.
3147 ;; However, never go past ellipsis.
3149 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3151 (dotimes (i 1000) (insert "very "))
3152 (goto-char (point-min))
3156 (org-test-with-temp-text "* A short headline\nSome contents"
3161 ;; In a wide headline, with `visual-line-mode', prefer going to end
3162 ;; of visible line if tags, or end of line, are farther.
3164 (org-test-with-temp-text "* A <point>long headline"
3166 (dotimes (i 1000) (insert "very "))
3167 (goto-char (point-min))
3171 (org-test-with-temp-text "* A <point>long headline :tag:"
3173 (dotimes (i 1000) (insert "very "))
3174 (goto-char (point-min))
3177 ;; At an headline without special movement, go to end of line.
3178 ;; However, never go past ellipsis.
3180 (org-test-with-temp-text "* Headline2b :tag:\n"
3181 (let ((org-special-ctrl-a/e nil
))
3182 (and (progn (org-end-of-line) (eolp))
3183 (progn (org-end-of-line) (eolp))))))
3185 (org-test-with-temp-text "* Headline2b :tag:\n"
3186 (let ((org-special-ctrl-a/e
'(t . nil
)))
3187 (and (progn (org-end-of-line) (eolp))
3188 (progn (org-end-of-line) (eolp))))))
3190 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3192 (let ((org-special-ctrl-a/e nil
))
3194 (= 1 (line-beginning-position)))))
3195 ;; At an headline with special movement, first move before tags,
3196 ;; then at the end of line, rinse, repeat. However, never go past
3199 (org-test-with-temp-text "* Headline1 :tag:\n"
3200 (let ((org-special-ctrl-a/e t
))
3201 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3202 (progn (org-end-of-line) (eolp))
3203 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3205 (org-test-with-temp-text "* Headline1 :tag:\n"
3206 (let ((org-special-ctrl-a/e
'(nil . t
)))
3207 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3208 (progn (org-end-of-line) (eolp))
3209 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3211 (org-test-with-temp-text "* Headline1 :tag:\n"
3212 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3213 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3214 (progn (org-end-of-line) (eolp))
3215 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3217 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3219 (let ((org-special-ctrl-a/e t
))
3222 (= 1 (line-beginning-position)))))
3223 ;; At an headline, with reversed movement, first go to end of line,
3224 ;; then before tags. However, never go past ellipsis.
3226 (org-test-with-temp-text "* Headline3 :tag:\n"
3227 (let ((org-special-ctrl-a/e
'reversed
)
3228 (this-command last-command
))
3229 (and (progn (org-end-of-line) (eolp))
3230 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3232 (org-test-with-temp-text "* Headline3 :tag:\n"
3233 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3234 (this-command last-command
))
3235 (and (progn (org-end-of-line) (eolp))
3236 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3238 (org-test-with-temp-text "* Headline3 :tag:\n"
3239 (let ((org-special-ctrl-a/e
'(nil . t
))
3240 (this-command last-command
))
3241 (and (progn (org-end-of-line) (eolp))
3242 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3244 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3246 (let ((org-special-ctrl-a/e
'reversed
))
3248 (= 1 (line-beginning-position)))))
3249 ;; At a block without hidden contents.
3251 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3252 (progn (org-end-of-line) (eolp))))
3253 ;; At a block with hidden contents.
3255 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3256 (let ((org-special-ctrl-a/e t
))
3257 (org-hide-block-toggle)
3260 ;; Get past invisible characters at the end of line.
3262 (org-test-with-temp-text "[[http://orgmode.org]]"
3266 (ert-deftest test-org
/open-line
()
3267 "Test `org-open-line' specifications."
3268 ;; Call `open-line' outside of tables.
3271 (org-test-with-temp-text "Text"
3274 ;; At a table, create a row above.
3276 (equal "\n| |\n| a |"
3277 (org-test-with-temp-text "\n<point>| a |"
3280 ;; At the very first character of the buffer, also call `open-line'.
3283 (org-test-with-temp-text "| a |"
3286 ;; Narrowing does not count.
3288 (equal "Text\n| |\n| a |"
3289 (org-test-with-temp-text "Text\n<point>| a |"
3290 (narrow-to-region (point) (point-max))
3295 (ert-deftest test-org
/forward-sentence
()
3296 "Test `org-forward-sentence' specifications."
3297 ;; At the end of a table cell, move to the end of the next one.
3299 (org-test-with-temp-text "| a<point> | b |"
3300 (org-forward-sentence)
3301 (looking-at " |$")))
3302 ;; Elsewhere in a cell, move to its end.
3304 (org-test-with-temp-text "| a<point>c | b |"
3305 (org-forward-sentence)
3306 (looking-at " | b |$")))
3307 ;; Otherwise, simply call `forward-sentence'.
3309 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3310 (org-forward-sentence)
3311 (looking-at " Sentence 2.")))
3313 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3314 (org-forward-sentence)
3315 (org-forward-sentence)
3317 ;; At the end of an element, jump to the next one, without stopping
3318 ;; on blank lines in-between.
3320 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3321 (org-forward-sentence)
3324 (ert-deftest test-org
/backward-sentence
()
3325 "Test `org-backward-sentence' specifications."
3326 ;; At the beginning of a table cell, move to the beginning of the
3329 (org-test-with-temp-text "| a | <point>b |"
3330 (org-backward-sentence)
3331 (looking-at "a | b |$")))
3332 ;; Elsewhere in a cell, move to its beginning.
3334 (org-test-with-temp-text "| a | b<point>c |"
3335 (org-backward-sentence)
3336 (looking-at "bc |$")))
3337 ;; Otherwise, simply call `backward-sentence'.
3339 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3340 (org-backward-sentence)
3341 (looking-at "Sentence 2.")))
3343 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3344 (org-backward-sentence)
3345 (org-backward-sentence)
3347 ;; Make sure to hit the beginning of a sentence on the same line as
3350 (org-test-with-temp-text "- Line 1\n line <point>2."
3351 (org-backward-sentence)
3352 (looking-at "Line 1"))))
3354 (ert-deftest test-org
/forward-paragraph
()
3355 "Test `org-forward-paragraph' specifications."
3356 ;; At end of buffer, return an error.
3358 (org-test-with-temp-text "Paragraph"
3359 (goto-char (point-max))
3360 (org-forward-paragraph)))
3363 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3364 (org-forward-paragraph)
3368 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3369 (org-forward-paragraph)
3371 ;; Do not enter elements with invisible contents.
3373 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3374 (org-hide-block-toggle)
3375 (org-forward-paragraph)
3377 ;; On an affiliated keyword, jump to the beginning of the element.
3379 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3380 (org-forward-paragraph)
3381 (looking-at "Para")))
3382 ;; On an item or a footnote definition, move to the second element
3385 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3386 (org-forward-paragraph)
3387 (looking-at " Paragraph")))
3389 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3390 (org-forward-paragraph)
3391 (looking-at "Paragraph")))
3392 ;; On an item, or a footnote definition, when the first line is
3393 ;; empty, move to the first item.
3395 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3396 (org-forward-paragraph)
3397 (looking-at " Paragraph")))
3399 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3400 (org-forward-paragraph)
3401 (looking-at "Paragraph")))
3402 ;; On a table (resp. a property drawer) do not move through table
3403 ;; rows (resp. node properties).
3405 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3406 (org-forward-paragraph)
3407 (looking-at "Paragraph")))
3409 (org-test-with-temp-text
3410 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3411 (org-forward-paragraph)
3412 (looking-at "Paragraph")))
3413 ;; On a verse or source block, stop after blank lines.
3415 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3416 (org-forward-paragraph)
3419 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3420 (org-forward-paragraph)
3421 (looking-at "L2"))))
3423 (ert-deftest test-org
/backward-paragraph
()
3424 "Test `org-backward-paragraph' specifications."
3425 ;; Error at beginning of buffer.
3427 (org-test-with-temp-text "Paragraph"
3428 (org-backward-paragraph)))
3431 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3432 (goto-char (point-max))
3433 (org-backward-paragraph)
3436 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3437 (goto-char (point-max))
3439 (org-backward-paragraph)
3443 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3444 (goto-char (point-max))
3446 (org-backward-paragraph)
3448 ;; Ignore invisible elements.
3450 (org-test-with-temp-text "* H1\n P1\n* H2"
3452 (goto-char (point-max))
3454 (org-backward-paragraph)
3456 ;; On an affiliated keyword, jump to the first one.
3458 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3459 (search-forward "c2")
3460 (org-backward-paragraph)
3461 (looking-at "#\\+name")))
3462 ;; On the second element in an item or a footnote definition, jump
3463 ;; to item or the definition.
3465 (org-test-with-temp-text "- line1\n\n line2"
3466 (goto-char (point-max))
3468 (org-backward-paragraph)
3469 (looking-at "- line1")))
3471 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3472 (goto-char (point-max))
3474 (org-backward-paragraph)
3475 (looking-at "\\[fn:1\\] line1")))
3476 ;; On a table (resp. a property drawer), ignore table rows
3477 ;; (resp. node properties).
3479 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3480 (goto-char (point-max))
3482 (org-backward-paragraph)
3485 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3486 (org-backward-paragraph)
3487 (looking-at ":PROPERTIES:")))
3488 ;; On a source or verse block, stop before blank lines.
3490 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3491 (search-forward "L3")
3493 (org-backward-paragraph)
3496 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3497 (search-forward "L3")
3499 (org-backward-paragraph)
3500 (looking-at "L2"))))
3502 (ert-deftest test-org
/forward-element
()
3503 "Test `org-forward-element' specifications."
3504 ;; 1. At EOB: should error.
3505 (org-test-with-temp-text "Some text\n"
3506 (goto-char (point-max))
3507 (should-error (org-forward-element)))
3508 ;; 2. Standard move: expected to ignore blank lines.
3509 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3510 (org-forward-element)
3511 (should (looking-at (regexp-quote "Second paragraph."))))
3512 ;; 3. Headline tests.
3513 (org-test-with-temp-text "
3518 ;; 3.1. At an headline beginning: move to next headline at the
3521 (org-forward-element)
3522 (should (looking-at (regexp-quote "** Head 1.2")))
3523 ;; 3.2. At an headline beginning: move to parent headline if no
3524 ;; headline at the same level.
3526 (org-forward-element)
3527 (should (looking-at (regexp-quote "** Head 1.2"))))
3528 ;; 4. Greater element tests.
3529 (org-test-with-temp-text
3530 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3531 ;; 4.1. At a greater element: expected to skip contents.
3532 (org-forward-element)
3533 (should (looking-at (regexp-quote "Outside.")))
3534 ;; 4.2. At the end of greater element contents: expected to skip
3535 ;; to the end of the greater element.
3537 (org-forward-element)
3538 (should (looking-at (regexp-quote "Outside."))))
3540 (org-test-with-temp-text "
3554 ;; 5.1. At list top point: expected to move to the element after
3557 (org-forward-element)
3558 (should (looking-at (regexp-quote "Outside.")))
3559 ;; 5.2. Special case: at the first line of a sub-list, but not at
3560 ;; beginning of line, move to next item.
3563 (org-forward-element)
3564 (should (looking-at "- item2"))
3567 (org-forward-element)
3568 (should (looking-at " - sub2"))
3569 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3571 (org-forward-element)
3572 (should (looking-at (regexp-quote " Inner paragraph.")))
3573 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3575 (org-forward-element)
3576 (should (looking-at (regexp-quote " Inner paragraph.")))
3577 ;; 5.5. At an item: expected to move to next item, if any.
3579 (org-forward-element)
3580 (should (looking-at " - sub3"))))
3582 (ert-deftest test-org
/backward-element
()
3583 "Test `org-backward-element' specifications."
3584 ;; 1. Should error at BOB.
3585 (org-test-with-temp-text " \nParagraph."
3586 (should-error (org-backward-element)))
3587 ;; 2. Should move at BOB when called on the first element in buffer.
3589 (org-test-with-temp-text "\n#+TITLE: test"
3590 (progn (forward-line)
3591 (org-backward-element)
3593 ;; 3. Not at the beginning of an element: move at its beginning.
3594 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3597 (org-backward-element)
3598 (should (looking-at (regexp-quote "Paragraph2."))))
3599 ;; 4. Headline tests.
3600 (org-test-with-temp-text "
3605 ;; 4.1. At an headline beginning: move to previous headline at the
3608 (org-backward-element)
3609 (should (looking-at (regexp-quote "** Head 1.1")))
3610 ;; 4.2. At an headline beginning: move to parent headline if no
3611 ;; headline at the same level.
3613 (org-backward-element)
3614 (should (looking-at (regexp-quote "* Head 1")))
3615 ;; 4.3. At the first top-level headline: should error.
3617 (should-error (org-backward-element)))
3618 ;; 5. At beginning of first element inside a greater element:
3619 ;; expected to move to greater element's beginning.
3620 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3622 (org-backward-element)
3623 (should (looking-at "#\\+BEGIN_CENTER")))
3624 ;; 6. At the beginning of the first element in a section: should
3625 ;; move back to headline, if any.
3627 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3628 (progn (goto-char (point-max))
3630 (org-backward-element)
3631 (org-at-heading-p))))
3633 (org-test-with-temp-text "
3648 ;; 7.1. At beginning of sub-list: expected to move to the
3649 ;; paragraph before it.
3651 (org-backward-element)
3652 (should (looking-at "item1"))
3653 ;; 7.2. At an item in a list: expected to move at previous item.
3655 (org-backward-element)
3656 (should (looking-at " - sub2"))
3658 (org-backward-element)
3659 (should (looking-at "- item1"))
3660 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3663 (org-backward-element)
3664 (should (looking-at " - sub1"))
3666 (org-backward-element)
3667 (should (looking-at "- item1"))
3668 ;; 7.4. At blank-lines before list end: expected to move to top
3671 (org-backward-element)
3672 (should (looking-at "- item1"))))
3674 (ert-deftest test-org
/up-element
()
3675 "Test `org-up-element' specifications."
3676 ;; 1. At BOB or with no surrounding element: should error.
3677 (org-test-with-temp-text "Paragraph."
3678 (should-error (org-up-element)))
3679 (org-test-with-temp-text "* Head1\n* Head2"
3681 (should-error (org-up-element)))
3682 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3684 (should-error (org-up-element)))
3685 ;; 2. At an headline: move to parent headline.
3686 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3689 (should (looking-at "\\* Head1")))
3690 ;; 3. Inside a greater element: move to greater element beginning.
3691 (org-test-with-temp-text
3692 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3695 (should (looking-at "#\\+BEGIN_CENTER")))
3697 (org-test-with-temp-text "* Top
3704 Paragraph within sub2.
3707 ;; 4.1. Within an item: move to the item beginning.
3710 (should (looking-at " - sub2"))
3711 ;; 4.2. At an item in a sub-list: move to parent item.
3714 (should (looking-at "- item1"))
3715 ;; 4.3. At an item in top list: move to beginning of whole list.
3718 (should (looking-at "- item1"))
3719 ;; 4.4. Special case. At very top point: should move to parent of
3723 (should (looking-at "\\* Top"))))
3725 (ert-deftest test-org
/down-element
()
3726 "Test `org-down-element' specifications."
3727 ;; Error when the element hasn't got a recursive type.
3728 (org-test-with-temp-text "Paragraph."
3729 (should-error (org-down-element)))
3730 ;; Error when the element has no contents
3731 (org-test-with-temp-text "* Headline"
3732 (should-error (org-down-element)))
3733 ;; When at a plain-list, move to first item.
3734 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3737 (should (looking-at " - Item 1.1")))
3738 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3740 (should (looking-at " Item 1")))
3741 ;; When at a table, move to first row
3742 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3744 (should (looking-at " a | b |")))
3745 ;; Otherwise, move inside the greater element.
3746 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3748 (should (looking-at "Paragraph"))))
3750 (ert-deftest test-org
/drag-element-backward
()
3751 "Test `org-drag-element-backward' specifications."
3755 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3756 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3757 (org-drag-element-backward)
3761 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3762 (org-test-with-temp-text
3763 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3764 (org-drag-element-backward)
3766 ;; Preserve blank lines.
3768 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3769 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3770 (org-drag-element-backward)
3774 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3775 (org-drag-element-backward)
3776 (looking-at-p "2")))
3777 ;; Error when trying to move first element of buffer.
3779 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3780 (org-drag-element-backward))
3782 ;; Error when trying to swap nested elements.
3784 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3785 (org-drag-element-backward))
3787 ;; Error when trying to swap an headline element and a non-headline
3790 (org-test-with-temp-text "Test.\n<point>* Head 1"
3791 (org-drag-element-backward))
3793 ;; Error when called before first element.
3795 (org-test-with-temp-text "\n<point>"
3796 (org-drag-element-backward))
3798 ;; Preserve visibility of elements and their contents.
3800 (equal '((63 .
82) (26 .
48))
3801 (org-test-with-temp-text "
3809 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3810 (search-backward "- item 1")
3811 (org-drag-element-backward)
3812 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3813 (overlays-in (point-min) (point-max))))))
3814 ;; Pathological case: handle call with point in blank lines right
3815 ;; after a headline.
3817 (equal "* H2\n* H1\nText\n\n"
3818 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3819 (org-drag-element-backward)
3822 (ert-deftest test-org
/drag-element-forward
()
3823 "Test `org-drag-element-forward' specifications."
3824 ;; 1. Error when trying to move first element of buffer.
3825 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3827 (should-error (org-drag-element-forward)))
3828 ;; 2. Error when trying to swap nested elements.
3829 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3831 (should-error (org-drag-element-forward)))
3832 ;; 3. Error when trying to swap a non-headline element and an
3834 (org-test-with-temp-text "Test.\n* Head 1"
3835 (should-error (org-drag-element-forward)))
3836 ;; 4. Error when called before first element.
3838 (org-test-with-temp-text "\n"
3840 (org-drag-element-backward))
3842 ;; 5. Otherwise, swap elements, preserving column and blank lines
3843 ;; between elements.
3844 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3845 (search-forward "graph")
3846 (org-drag-element-forward)
3847 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3848 (should (looking-at " 1")))
3849 ;; 5. Preserve visibility of elements and their contents.
3850 (org-test-with-temp-text "
3858 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3859 (search-backward "#+BEGIN_CENTER")
3860 (org-drag-element-forward)
3863 '((63 .
82) (26 .
48))
3864 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3865 (overlays-in (point-min) (point-max)))))))
3867 (ert-deftest test-org
/next-block
()
3868 "Test `org-next-block' specifications."
3871 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3873 (looking-at "#\\+BEGIN_CENTER")))
3876 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3877 (let ((case-fold-search nil
))
3879 (looking-at "#\\+begin_center"))))
3880 ;; Ignore current line.
3882 (org-test-with-temp-text
3883 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3885 (looking-at "#\\+BEGIN_CENTER")))
3886 ;; Throw an error when no block is found.
3888 (org-test-with-temp-text "Paragraph"
3889 (org-next-block 1)))
3890 ;; With an argument, skip many blocks at once.
3892 (org-test-with-temp-text
3893 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3895 (looking-at "#\\+BEGIN_QUOTE")))
3896 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3898 (org-test-with-temp-text
3899 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3900 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3901 (looking-at "#\\+BEGIN_QUOTE")))
3902 ;; Optional argument is also case-insensitive.
3904 (org-test-with-temp-text
3905 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3906 (let ((case-fold-search nil
))
3907 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3908 (looking-at "#\\+begin_quote")))))
3910 (ert-deftest test-org
/previous-block
()
3911 "Test `org-previous-block' specifications."
3914 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3915 (org-previous-block 1)
3916 (looking-at "#\\+BEGIN_CENTER")))
3919 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3920 (let ((case-fold-search nil
))
3921 (org-previous-block 1)
3922 (looking-at "#\\+begin_center"))))
3923 ;; Ignore current line.
3925 (org-test-with-temp-text
3926 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3927 (org-previous-block 1)
3928 (looking-at "#\\+BEGIN_QUOTE")))
3929 ;; Throw an error when no block is found.
3931 (org-test-with-temp-text "Paragraph<point>"
3932 (org-previous-block 1)))
3933 ;; With an argument, skip many blocks at once.
3935 (org-test-with-temp-text
3936 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3937 (org-previous-block 2)
3938 (looking-at "#\\+BEGIN_CENTER")))
3939 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3941 (org-test-with-temp-text
3942 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3943 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3944 (looking-at "#\\+BEGIN_QUOTE")))
3945 ;; Optional argument is also case-insensitive.
3947 (org-test-with-temp-text
3948 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3949 (let ((case-fold-search nil
))
3950 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3951 (looking-at "#\\+begin_quote")))))
3954 ;;; Outline structure
3956 (ert-deftest test-org
/demote
()
3957 "Test `org-demote' specifications."
3958 ;; Add correct number of stars according to `org-odd-levels-only'.
3961 (org-test-with-temp-text "* H"
3962 (let ((org-odd-levels-only nil
)) (org-demote))
3963 (org-current-level))))
3966 (org-test-with-temp-text "* H"
3967 (let ((org-odd-levels-only t
)) (org-demote))
3968 (org-current-level))))
3969 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3971 (org-test-with-temp-text "* H :tag:"
3972 (let ((org-tags-column 10)
3973 (org-auto-align-tags t
)
3974 (org-odd-levels-only nil
))
3976 (org-move-to-column 10)
3977 (looking-at-p ":tag:$")))
3979 (org-test-with-temp-text "* H :tag:"
3980 (let ((org-tags-column 10)
3981 (org-auto-align-tags nil
)
3982 (org-odd-levels-only nil
))
3984 (org-move-to-column 10)
3985 (looking-at-p ":tag:$")))
3986 ;; When `org-adapt-indentation' is non-nil, always indent planning
3987 ;; info and property drawers accordingly.
3990 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3991 (let ((org-odd-levels-only nil
)
3992 (org-adapt-indentation t
))
3995 (org-get-indentation))))
3998 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3999 (let ((org-odd-levels-only nil
)
4000 (org-adapt-indentation t
))
4003 (org-get-indentation))))
4006 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4007 (let ((org-odd-levels-only nil
)
4008 (org-adapt-indentation nil
))
4011 (org-get-indentation))))
4012 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4013 ;; section accordingly. Ignore, however, footnote definitions and
4014 ;; inlinetasks boundaries.
4017 (org-test-with-temp-text "* H\n Paragraph"
4018 (let ((org-odd-levels-only nil
)
4019 (org-adapt-indentation t
))
4022 (org-get-indentation))))
4025 (org-test-with-temp-text "* H\n Paragraph"
4026 (let ((org-odd-levels-only nil
)
4027 (org-adapt-indentation nil
))
4030 (org-get-indentation))))
4033 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4034 (let ((org-odd-levels-only nil
)
4035 (org-adapt-indentation t
))
4037 (goto-char (point-max))
4038 (org-get-indentation))))
4041 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4042 (let ((org-odd-levels-only nil
)
4043 (org-adapt-indentation t
))
4045 (goto-char (point-max))
4046 (org-get-indentation))))
4047 (when (featurep 'org-inlinetask
)
4050 (let ((org-inlinetask-min-level 5)
4051 (org-adapt-indentation t
))
4052 (org-test-with-temp-text "* H\n***** I\n***** END"
4055 (org-get-indentation))))))
4056 (when (featurep 'org-inlinetask
)
4059 (let ((org-inlinetask-min-level 5)
4060 (org-adapt-indentation t
))
4061 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4064 (org-get-indentation))))))
4065 ;; Ignore contents of source blocks or example blocks when
4066 ;; indentation should be preserved (through
4067 ;; `org-src-preserve-indentation' or "-i" flag).
4070 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4071 (let ((org-adapt-indentation t
)
4072 (org-src-preserve-indentation nil
))
4075 (org-get-indentation))))
4078 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4079 (let ((org-adapt-indentation t
)
4080 (org-src-preserve-indentation t
))
4083 (org-get-indentation))))
4086 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4087 (let ((org-adapt-indentation t
)
4088 (org-src-preserve-indentation t
))
4091 (org-get-indentation))))
4094 (org-test-with-temp-text
4095 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4096 (let ((org-adapt-indentation t
)
4097 (org-src-preserve-indentation nil
))
4100 (org-get-indentation)))))
4102 (ert-deftest test-org
/promote
()
4103 "Test `org-promote' specifications."
4104 ;; Return an error if headline is to be promoted to level 0, unless
4105 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4106 ;; headline becomes a comment.
4108 (org-test-with-temp-text "* H"
4109 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4112 (org-test-with-temp-text "* H"
4113 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4115 ;; Remove correct number of stars according to
4116 ;; `org-odd-levels-only'.
4119 (org-test-with-temp-text "*** H"
4120 (let ((org-odd-levels-only nil
)) (org-promote))
4121 (org-current-level))))
4124 (org-test-with-temp-text "*** H"
4125 (let ((org-odd-levels-only t
)) (org-promote))
4126 (org-current-level))))
4127 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4129 (org-test-with-temp-text "** H :tag:"
4130 (let ((org-tags-column 10)
4131 (org-auto-align-tags t
)
4132 (org-odd-levels-only nil
))
4134 (org-move-to-column 10)
4135 (looking-at-p ":tag:$")))
4137 (org-test-with-temp-text "** H :tag:"
4138 (let ((org-tags-column 10)
4139 (org-auto-align-tags nil
)
4140 (org-odd-levels-only nil
))
4142 (org-move-to-column 10)
4143 (looking-at-p ":tag:$")))
4144 ;; When `org-adapt-indentation' is non-nil, always indent planning
4145 ;; info and property drawers.
4148 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4149 (let ((org-odd-levels-only nil
)
4150 (org-adapt-indentation t
))
4153 (org-get-indentation))))
4156 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4157 (let ((org-odd-levels-only nil
)
4158 (org-adapt-indentation t
))
4161 (org-get-indentation))))
4164 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4165 (let ((org-odd-levels-only nil
)
4166 (org-adapt-indentation nil
))
4169 (org-get-indentation))))
4170 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4171 ;; section accordingly. Ignore, however, footnote definitions and
4172 ;; inlinetasks boundaries.
4175 (org-test-with-temp-text "** H\n Paragraph"
4176 (let ((org-odd-levels-only nil
)
4177 (org-adapt-indentation t
))
4180 (org-get-indentation))))
4183 (org-test-with-temp-text "** H\n Paragraph"
4184 (let ((org-odd-levels-only nil
)
4185 (org-adapt-indentation nil
))
4188 (org-get-indentation))))
4191 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4192 (let ((org-odd-levels-only nil
)
4193 (org-adapt-indentation t
))
4196 (org-get-indentation))))
4197 (when (featurep 'org-inlinetask
)
4200 (let ((org-inlinetask-min-level 5)
4201 (org-adapt-indentation t
))
4202 (org-test-with-temp-text "** H\n***** I\n***** END"
4205 (org-get-indentation))))))
4206 (when (featurep 'org-inlinetask
)
4209 (let ((org-inlinetask-min-level 5)
4210 (org-adapt-indentation t
))
4211 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4214 (org-get-indentation))))))
4215 ;; Give up shifting if it would break document's structure
4219 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4220 (let ((org-odd-levels-only nil
)
4221 (org-adapt-indentation t
))
4224 (org-get-indentation))))
4227 (org-test-with-temp-text "** H\n Paragraph\n * list."
4228 (let ((org-odd-levels-only nil
)
4229 (org-adapt-indentation t
))
4232 (org-get-indentation))))
4233 ;; Ignore contents of source blocks or example blocks when
4234 ;; indentation should be preserved (through
4235 ;; `org-src-preserve-indentation' or "-i" flag).
4238 (org-test-with-temp-text
4239 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4240 (let ((org-adapt-indentation t
)
4241 (org-src-preserve-indentation nil
)
4242 (org-odd-levels-only nil
))
4245 (org-get-indentation))))
4248 (org-test-with-temp-text
4249 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4250 (let ((org-adapt-indentation t
)
4251 (org-src-preserve-indentation t
)
4252 (org-odd-levels-only nil
))
4255 (org-get-indentation))))
4258 (org-test-with-temp-text
4259 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4260 (let ((org-adapt-indentation t
)
4261 (org-src-preserve-indentation t
)
4262 (org-odd-levels-only nil
))
4265 (org-get-indentation))))
4268 (org-test-with-temp-text
4269 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4270 (let ((org-adapt-indentation t
)
4271 (org-src-preserve-indentation nil
)
4272 (org-odd-levels-only nil
))
4275 (org-get-indentation)))))
4277 (ert-deftest test-org
/org-get-valid-level
()
4278 "Test function `org-get-valid-level' specifications."
4279 (let ((org-odd-levels-only nil
))
4280 (should (equal 1 (org-get-valid-level 0 0)))
4281 (should (equal 1 (org-get-valid-level 0 1)))
4282 (should (equal 2 (org-get-valid-level 0 2)))
4283 (should (equal 3 (org-get-valid-level 0 3)))
4284 (should (equal 1 (org-get-valid-level 1 0)))
4285 (should (equal 2 (org-get-valid-level 1 1)))
4286 (should (equal 23 (org-get-valid-level 1 22)))
4287 (should (equal 1 (org-get-valid-level 1 -
1)))
4288 (should (equal 1 (org-get-valid-level 2 -
1))))
4289 (let ((org-odd-levels-only t
))
4290 (should (equal 1 (org-get-valid-level 0 0)))
4291 (should (equal 1 (org-get-valid-level 0 1)))
4292 (should (equal 3 (org-get-valid-level 0 2)))
4293 (should (equal 5 (org-get-valid-level 0 3)))
4294 (should (equal 1 (org-get-valid-level 1 0)))
4295 (should (equal 3 (org-get-valid-level 1 1)))
4296 (should (equal 3 (org-get-valid-level 2 1)))
4297 (should (equal 5 (org-get-valid-level 3 1)))
4298 (should (equal 5 (org-get-valid-level 4 1)))
4299 (should (equal 43 (org-get-valid-level 1 21)))
4300 (should (equal 1 (org-get-valid-level 1 -
1)))
4301 (should (equal 1 (org-get-valid-level 2 -
1)))
4302 (should (equal 1 (org-get-valid-level 3 -
1)))
4303 (should (equal 3 (org-get-valid-level 4 -
1)))
4304 (should (equal 3 (org-get-valid-level 5 -
1)))))
4309 (ert-deftest test-org
/at-planning-p
()
4310 "Test `org-at-planning-p' specifications."
4313 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4314 (org-at-planning-p)))
4316 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4317 (org-at-planning-p)))
4318 ;; Correctly find planning attached to inlinetasks.
4319 (when (featurep 'org-inlinetask
)
4321 (org-test-with-temp-text
4322 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4323 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4325 (org-test-with-temp-text
4326 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4327 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4329 (org-test-with-temp-text
4330 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4331 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4333 (org-test-with-temp-text
4334 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4335 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4337 (ert-deftest test-org
/add-planning-info
()
4338 "Test `org-add-planning-info'."
4339 ;; Create deadline when `org-adapt-indentation' is non-nil.
4341 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4342 (org-test-with-temp-text "* H\nParagraph<point>"
4343 (let ((org-adapt-indentation t
))
4344 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4345 (replace-regexp-in-string
4346 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4348 ;; Create deadline when `org-adapt-indentation' is nil.
4350 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4351 (org-test-with-temp-text "* H\nParagraph<point>"
4352 (let ((org-adapt-indentation nil
))
4353 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4354 (replace-regexp-in-string
4355 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4357 ;; Update deadline when `org-adapt-indentation' is non-nil.
4359 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4360 (org-test-with-temp-text "\
4362 DEADLINE: <2015-06-24 Wed>
4364 (let ((org-adapt-indentation t
))
4365 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4366 (replace-regexp-in-string
4367 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4369 ;; Update deadline when `org-adapt-indentation' is nil.
4371 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4372 (org-test-with-temp-text "\
4374 DEADLINE: <2015-06-24 Wed>
4376 (let ((org-adapt-indentation nil
))
4377 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4378 (replace-regexp-in-string
4379 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4381 ;; Schedule when `org-adapt-indentation' is non-nil.
4383 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4384 (org-test-with-temp-text "* H\nParagraph<point>"
4385 (let ((org-adapt-indentation t
))
4386 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4387 (replace-regexp-in-string
4388 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4390 ;; Schedule when `org-adapt-indentation' is nil.
4392 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4393 (org-test-with-temp-text "* H\nParagraph<point>"
4394 (let ((org-adapt-indentation nil
))
4395 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4396 (replace-regexp-in-string
4397 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4399 ;; Add deadline when scheduled.
4403 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4405 (org-test-with-temp-text "\
4407 SCHEDULED: <2015-06-24 Wed>
4409 (let ((org-adapt-indentation t
))
4410 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4411 (replace-regexp-in-string
4412 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4414 ;; Remove middle entry.
4418 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4420 (org-test-with-temp-text "\
4422 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4424 (let ((org-adapt-indentation t
))
4425 (org-add-planning-info nil nil
'deadline
))
4426 (replace-regexp-in-string
4427 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4429 ;; Remove last entry and then middle entry (order should not
4434 CLOSED: [2015-06-24]
4436 (org-test-with-temp-text "\
4438 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4440 (let ((org-adapt-indentation t
))
4441 (org-add-planning-info nil nil
'scheduled
'deadline
))
4442 (replace-regexp-in-string
4443 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4445 ;; Remove closed when `org-adapt-indentation' is non-nil.
4447 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4448 (org-test-with-temp-text "\
4450 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4452 (let ((org-adapt-indentation t
))
4453 (org-add-planning-info nil nil
'closed
))
4454 (replace-regexp-in-string
4455 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4458 (equal "* H\n Paragraph"
4459 (org-test-with-temp-text "\
4461 CLOSED: [2015-06-25 Thu]
4463 (let ((org-adapt-indentation t
))
4464 (org-add-planning-info nil nil
'closed
))
4465 (replace-regexp-in-string
4466 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4468 ;; Remove closed when `org-adapt-indentation' is nil.
4470 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4471 (org-test-with-temp-text "\
4473 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4475 (let ((org-adapt-indentation nil
))
4476 (org-add-planning-info nil nil
'closed
))
4477 (replace-regexp-in-string
4478 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4481 (equal "* H\nParagraph"
4482 (org-test-with-temp-text "\
4484 CLOSED: [2015-06-25 Thu]
4486 (let ((org-adapt-indentation nil
))
4487 (org-add-planning-info nil nil
'closed
))
4488 (replace-regexp-in-string
4489 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4491 ;; Remove closed entry and delete empty line.
4496 (org-test-with-temp-text "\
4498 CLOSED: [2015-06-24 Wed]
4500 (let ((org-adapt-indentation t
))
4501 (org-add-planning-info nil nil
'closed
))
4502 (replace-regexp-in-string
4503 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4505 ;; Remove one entry and update another.
4507 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4508 (org-test-with-temp-text "\
4510 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4512 (let ((org-adapt-indentation t
))
4513 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4514 (replace-regexp-in-string
4515 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4518 (ert-deftest test-org
/deadline
()
4519 "Test `org-deadline' specifications."
4520 ;; Insert a new value or replace existing one.
4522 (equal "* H\nDEADLINE: <2012-03-29>\n"
4523 (org-test-with-temp-text "* H"
4524 (let ((org-adapt-indentation nil
)
4525 (org-last-inserted-timestamp nil
))
4526 (org-deadline nil
"<2012-03-29 Tue>"))
4527 (replace-regexp-in-string
4528 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4531 (equal "* H\nDEADLINE: <2014-03-04>"
4532 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4533 (let ((org-adapt-indentation nil
)
4534 (org-last-inserted-timestamp nil
))
4535 (org-deadline nil
"<2014-03-04 Thu>"))
4536 (replace-regexp-in-string
4537 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4539 ;; Accept delta time, e.g., "+2d".
4541 (equal "* H\nDEADLINE: <2015-03-04>\n"
4542 (cl-letf (((symbol-function 'current-time
)
4543 (lambda (&rest args
)
4544 (apply #'encode-time
4545 (org-parse-time-string "2014-03-04")))))
4546 (org-test-with-temp-text "* H"
4547 (let ((org-adapt-indentation nil
)
4548 (org-last-inserted-timestamp nil
))
4549 (org-deadline nil
"+1y"))
4550 (replace-regexp-in-string
4551 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4552 ;; Preserve repeater.
4554 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4555 (org-test-with-temp-text "* H"
4556 (let ((org-adapt-indentation nil
)
4557 (org-last-inserted-timestamp nil
))
4558 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4559 (replace-regexp-in-string
4560 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4561 ;; Remove CLOSED keyword, if any.
4563 (equal "* H\nDEADLINE: <2012-03-29>"
4564 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4565 (let ((org-adapt-indentation nil
)
4566 (org-last-inserted-timestamp nil
))
4567 (org-deadline nil
"<2012-03-29 Tue>"))
4568 (replace-regexp-in-string
4569 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4570 ;; With C-u argument, remove DEADLINE keyword.
4573 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4574 (let ((org-adapt-indentation nil
)
4575 (org-last-inserted-timestamp nil
))
4576 (org-deadline '(4)))
4580 (org-test-with-temp-text "* H"
4581 (let ((org-adapt-indentation nil
)
4582 (org-last-inserted-timestamp nil
))
4583 (org-deadline '(4)))
4585 ;; With C-u C-u argument, prompt for a delay cookie.
4587 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4588 (cl-letf (((symbol-function 'org-read-date
)
4589 (lambda (&rest args
)
4590 (apply #'encode-time
4591 (org-parse-time-string "2014-03-04")))))
4592 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4593 (let ((org-adapt-indentation nil
)
4594 (org-last-inserted-timestamp nil
))
4595 (org-deadline '(16)))
4598 (cl-letf (((symbol-function 'org-read-date
)
4599 (lambda (&rest args
)
4600 (apply #'encode-time
4601 (org-parse-time-string "2014-03-04")))))
4602 (org-test-with-temp-text "* H"
4603 (let ((org-adapt-indentation nil
)
4604 (org-last-inserted-timestamp nil
))
4605 (org-deadline '(16)))
4607 ;; When a region is active and
4608 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4609 ;; same value in all headlines in region.
4611 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4612 (org-test-with-temp-text "* H1\n* H2"
4613 (let ((org-adapt-indentation nil
)
4614 (org-last-inserted-timestamp nil
)
4615 (org-loop-over-headlines-in-active-region t
))
4616 (transient-mark-mode 1)
4617 (push-mark (point) t t
)
4618 (goto-char (point-max))
4619 (org-deadline nil
"2012-03-29"))
4620 (replace-regexp-in-string
4621 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4623 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4624 (org-test-with-temp-text "* H1\n* H2"
4625 (let ((org-adapt-indentation nil
)
4626 (org-last-inserted-timestamp nil
)
4627 (org-loop-over-headlines-in-active-region nil
))
4628 (transient-mark-mode 1)
4629 (push-mark (point) t t
)
4630 (goto-char (point-max))
4631 (org-deadline nil
"2012-03-29"))
4632 (replace-regexp-in-string
4633 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4635 (ert-deftest test-org
/schedule
()
4636 "Test `org-schedule' specifications."
4637 ;; Insert a new value or replace existing one.
4639 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4640 (org-test-with-temp-text "* H"
4641 (let ((org-adapt-indentation nil
)
4642 (org-last-inserted-timestamp nil
))
4643 (org-schedule nil
"<2012-03-29 Tue>"))
4644 (replace-regexp-in-string
4645 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4648 (equal "* H\nSCHEDULED: <2014-03-04>"
4649 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4650 (let ((org-adapt-indentation nil
)
4651 (org-last-inserted-timestamp nil
))
4652 (org-schedule nil
"<2014-03-04 Thu>"))
4653 (replace-regexp-in-string
4654 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4656 ;; Accept delta time, e.g., "+2d".
4658 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4659 (cl-letf (((symbol-function 'current-time
)
4660 (lambda (&rest args
)
4661 (apply #'encode-time
4662 (org-parse-time-string "2014-03-04")))))
4663 (org-test-with-temp-text "* H"
4664 (let ((org-adapt-indentation nil
)
4665 (org-last-inserted-timestamp nil
))
4666 (org-schedule nil
"+1y"))
4667 (replace-regexp-in-string
4668 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4669 ;; Preserve repeater.
4671 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4672 (org-test-with-temp-text "* H"
4673 (let ((org-adapt-indentation nil
)
4674 (org-last-inserted-timestamp nil
))
4675 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4676 (replace-regexp-in-string
4677 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4678 ;; Remove CLOSED keyword, if any.
4680 (equal "* H\nSCHEDULED: <2012-03-29>"
4681 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4682 (let ((org-adapt-indentation nil
)
4683 (org-last-inserted-timestamp nil
))
4684 (org-schedule nil
"<2012-03-29 Tue>"))
4685 (replace-regexp-in-string
4686 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4687 ;; With C-u argument, remove SCHEDULED keyword.
4690 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4691 (let ((org-adapt-indentation nil
)
4692 (org-last-inserted-timestamp nil
))
4693 (org-schedule '(4)))
4697 (org-test-with-temp-text "* H"
4698 (let ((org-adapt-indentation nil
)
4699 (org-last-inserted-timestamp nil
))
4700 (org-schedule '(4)))
4702 ;; With C-u C-u argument, prompt for a delay cookie.
4704 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4705 (cl-letf (((symbol-function 'org-read-date
)
4706 (lambda (&rest args
)
4707 (apply #'encode-time
4708 (org-parse-time-string "2014-03-04")))))
4709 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4710 (let ((org-adapt-indentation nil
)
4711 (org-last-inserted-timestamp nil
))
4712 (org-schedule '(16)))
4715 (cl-letf (((symbol-function 'org-read-date
)
4716 (lambda (&rest args
)
4717 (apply #'encode-time
4718 (org-parse-time-string "2014-03-04")))))
4719 (org-test-with-temp-text "* H"
4720 (let ((org-adapt-indentation nil
)
4721 (org-last-inserted-timestamp nil
))
4722 (org-schedule '(16)))
4724 ;; When a region is active and
4725 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4726 ;; same value in all headlines in region.
4728 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4729 (org-test-with-temp-text "* H1\n* H2"
4730 (let ((org-adapt-indentation nil
)
4731 (org-last-inserted-timestamp nil
)
4732 (org-loop-over-headlines-in-active-region t
))
4733 (transient-mark-mode 1)
4734 (push-mark (point) t t
)
4735 (goto-char (point-max))
4736 (org-schedule nil
"2012-03-29"))
4737 (replace-regexp-in-string
4738 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4740 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4741 (org-test-with-temp-text "* H1\n* H2"
4742 (let ((org-adapt-indentation nil
)
4743 (org-last-inserted-timestamp nil
)
4744 (org-loop-over-headlines-in-active-region nil
))
4745 (transient-mark-mode 1)
4746 (push-mark (point) t t
)
4747 (goto-char (point-max))
4748 (org-schedule nil
"2012-03-29"))
4749 (replace-regexp-in-string
4750 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4752 ;; check if a repeater survives re-scheduling.
4754 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4755 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4756 (let ((org-adapt-indentation nil
)
4757 (org-last-inserted-timestamp nil
))
4758 (org-schedule nil
"2017-02-01"))
4764 (ert-deftest test-org
/buffer-property-keys
()
4765 "Test `org-buffer-property-keys' specifications."
4766 ;; Retrieve properties accross siblings.
4769 (org-test-with-temp-text "
4778 (org-buffer-property-keys))))
4779 ;; Retrieve properties accross children.
4782 (org-test-with-temp-text "
4791 (org-buffer-property-keys))))
4792 ;; Retrieve muliple properties in the same drawer.
4795 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4796 (org-buffer-property-keys))))
4797 ;; Ignore extension symbol in property name.
4800 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4801 (org-buffer-property-keys))))
4802 ;; With non-nil COLUMNS, extract property names from columns.
4805 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4806 (org-buffer-property-keys nil nil t
))))
4808 (equal '("A" "B" "COLUMNS")
4809 (org-test-with-temp-text
4810 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4811 (org-buffer-property-keys nil nil t
))))
4812 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4815 (org-test-with-temp-text
4816 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4817 (org-buffer-property-keys nil nil nil t
)))))
4819 (ert-deftest test-org
/property-values
()
4820 "Test `org-property-values' specifications."
4824 (org-test-with-temp-text
4825 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4826 (org-property-values "A"))))
4827 ;; Ignore empty values.
4829 (org-test-with-temp-text
4830 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4831 (org-property-values "A")))
4832 ;; Take into consideration extended values.
4835 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4836 (org-property-values "A")))))
4838 (ert-deftest test-org
/find-property
()
4839 "Test `org-find-property' specifications."
4843 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4844 (org-find-property "prop"))))
4845 ;; Ignore false positives.
4848 (org-test-with-temp-text
4849 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4850 (org-find-property "A"))))
4851 ;; Return first entry found in buffer.
4854 (org-test-with-temp-text
4855 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4856 (org-find-property "A"))))
4857 ;; Only search visible part of the buffer.
4860 (org-test-with-temp-text
4861 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4862 (org-narrow-to-subtree)
4863 (org-find-property "A"))))
4864 ;; With optional argument, only find entries with a specific value.
4866 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4867 (org-find-property "A" "2")))
4870 (org-test-with-temp-text
4871 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4872 (org-find-property "A" "2"))))
4873 ;; Use "nil" for explicit nil values.
4876 (org-test-with-temp-text
4877 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4878 (org-find-property "A" "nil")))))
4880 (ert-deftest test-org
/entry-delete
()
4881 "Test `org-entry-delete' specifications."
4885 " *:PROPERTIES:\n *:B: +2\n *:END:"
4886 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4887 (org-entry-delete (point) "A")
4889 ;; Also remove accumulated properties.
4893 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4894 (org-entry-delete (point) "A")
4896 ;; When last property is removed, remove the property drawer.
4900 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4901 (org-entry-delete (point) "A")
4903 ;; Return a non-nil value when some property was removed.
4905 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4906 (org-entry-delete (point) "A")))
4908 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4909 (org-entry-delete (point) "C")))
4910 ;; Special properties cannot be located in a drawer. Allow to
4911 ;; remove them anyway, in case of user error.
4913 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4914 (org-entry-delete (point) "SCHEDULED"))))
4916 (ert-deftest test-org
/entry-get
()
4917 "Test `org-entry-get' specifications."
4921 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4922 (org-entry-get (point) "A"))))
4926 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4927 (org-entry-get (point) "a"))))
4928 ;; Handle extended values, both before and after base value.
4931 (org-test-with-temp-text
4932 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4933 (org-entry-get (point) "A"))))
4934 ;; Empty values are returned as the empty string.
4937 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4938 (org-entry-get (point) "A"))))
4939 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4940 ;; otherwise, return nil.
4942 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4943 (org-entry-get (point) "A")))
4946 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4947 (org-entry-get (point) "A" nil t
))))
4948 ;; Return nil when no property is found, independently on the
4949 ;; LITERAL-NIL argument.
4951 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4952 (org-entry-get (point) "B")))
4954 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4955 (org-entry-get (point) "B" nil t
)))
4956 ;; Handle inheritance, when allowed. Include extended values and
4957 ;; possibly global values.
4961 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4962 (org-entry-get (point) "A" t
))))
4966 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4967 (let ((org-use-property-inheritance t
))
4968 (org-entry-get (point) "A" 'selective
)))))
4970 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4971 (let ((org-use-property-inheritance nil
))
4972 (org-entry-get (point) "A" 'selective
))))
4976 (org-test-with-temp-text
4977 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4978 (org-entry-get (point-max) "A" t
))))
4981 (org-test-with-temp-text
4982 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4984 (org-entry-get (point-max) "A" t
))))
4987 (org-test-with-temp-text
4988 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4990 (org-entry-get (point-max) "A" t
)))))
4992 (ert-deftest test-org
/entry-properties
()
4993 "Test `org-entry-properties' specifications."
4994 ;; Get "ITEM" property.
4997 (org-test-with-temp-text "* TODO H"
4998 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5001 (org-test-with-temp-text "* TODO H"
5002 (cdr (assoc "ITEM" (org-entry-properties))))))
5003 ;; Get "TODO" property. TODO keywords are case sensitive.
5006 (org-test-with-temp-text "* TODO H"
5007 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5010 (org-test-with-temp-text "* TODO H"
5011 (cdr (assoc "TODO" (org-entry-properties))))))
5013 (org-test-with-temp-text "* H"
5014 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5016 (org-test-with-temp-text "* todo H"
5017 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5018 ;; Get "PRIORITY" property.
5021 (org-test-with-temp-text "* [#A] H"
5022 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5025 (org-test-with-temp-text "* [#A] H"
5026 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5028 (equal (char-to-string org-default-priority
)
5029 (org-test-with-temp-text "* H"
5030 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5031 ;; Get "FILE" property.
5033 (org-test-with-temp-text-in-file "* H\nParagraph"
5034 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5035 (buffer-file-name))))
5037 (org-test-with-temp-text-in-file "* H\nParagraph"
5038 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5039 (buffer-file-name))))
5041 (org-test-with-temp-text "* H\nParagraph"
5042 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5043 ;; Get "TAGS" property.
5045 (equal ":tag1:tag2:"
5046 (org-test-with-temp-text "* H :tag1:tag2:"
5047 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5049 (equal ":tag1:tag2:"
5050 (org-test-with-temp-text "* H :tag1:tag2:"
5051 (cdr (assoc "TAGS" (org-entry-properties))))))
5053 (org-test-with-temp-text "* H"
5054 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5055 ;; Get "ALLTAGS" property.
5057 (equal ":tag1:tag2:"
5058 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5059 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5061 (equal ":tag1:tag2:"
5062 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5063 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5065 (org-test-with-temp-text "* H"
5066 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5067 ;; Get "BLOCKED" property.
5070 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5071 (let ((org-enforce-todo-dependencies t
)
5073 '(org-block-todo-from-children-or-siblings-or-parent)))
5074 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5077 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5078 (let ((org-enforce-todo-dependencies t
)
5080 '(org-block-todo-from-children-or-siblings-or-parent)))
5081 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5082 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5086 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5087 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5091 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5092 (cdr (assoc "CLOSED" (org-entry-properties))))))
5094 (org-test-with-temp-text "* H"
5095 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5099 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5100 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5104 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5105 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5107 (org-test-with-temp-text "* H"
5108 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5112 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5113 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5117 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5118 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5120 (org-test-with-temp-text "* H"
5121 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5125 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5126 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5129 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5130 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5133 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5134 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5137 (org-test-with-temp-text
5138 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5140 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5141 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5142 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5144 (equal "<2012-03-29 thu.>"
5145 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5146 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5148 (equal "[2012-03-29 thu.]"
5149 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5150 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5152 (equal "<2012-03-29 thu.>"
5153 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5154 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5156 (equal "[2014-03-04 tue.]"
5157 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5158 (cdr (assoc "TIMESTAMP_IA"
5159 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5161 (equal "<2012-03-29 thu.>"
5162 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5163 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5164 ;; Get standard properties.
5167 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5168 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5169 ;; Handle extended properties.
5172 (org-test-with-temp-text
5173 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5174 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5177 (org-test-with-temp-text
5178 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5179 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5180 ;; Ignore forbidden (special) properties.
5182 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5183 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5185 (ert-deftest test-org
/entry-put
()
5186 "Test `org-entry-put' specifications."
5187 ;; Error when not a string or nil.
5189 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5190 (org-entry-put 1 "test" 2)))
5191 ;; Error when property name is invalid.
5193 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5194 (org-entry-put 1 "no space" "value")))
5196 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5197 (org-entry-put 1 "" "value")))
5198 ;; Set "TODO" property.
5200 (string-match (regexp-quote " TODO H")
5201 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5202 (org-entry-put (point) "TODO" "TODO")
5205 (string-match (regexp-quote "* H")
5206 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5207 (org-entry-put (point) "TODO" nil
)
5209 ;; Set "PRIORITY" property.
5212 (org-test-with-temp-text "* [#B] H"
5213 (org-entry-put (point) "PRIORITY" "A")
5217 (org-test-with-temp-text "* [#B] H"
5218 (org-entry-put (point) "PRIORITY" nil
)
5220 ;; Set "SCHEDULED" property.
5222 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5223 (org-test-with-temp-text "* H"
5224 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5228 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5229 (org-entry-put (point) "SCHEDULED" nil
)
5232 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5233 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5234 (org-entry-put (point) "SCHEDULED" "earlier")
5237 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5238 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5239 (org-entry-put (point) "SCHEDULED" "later")
5241 ;; Set "DEADLINE" property.
5243 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5244 (org-test-with-temp-text "* H"
5245 (org-entry-put (point) "DEADLINE" "2014-03-04")
5249 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5250 (org-entry-put (point) "DEADLINE" nil
)
5253 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5254 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5255 (org-entry-put (point) "DEADLINE" "earlier")
5258 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5259 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5260 (org-entry-put (point) "DEADLINE" "later")
5262 ;; Set "CATEGORY" property
5264 (string-match "^ *:CATEGORY: cat"
5265 (org-test-with-temp-text "* H"
5266 (org-entry-put (point) "CATEGORY" "cat")
5268 ;; Regular properties, with or without pre-existing drawer.
5270 (string-match "^ *:A: +2$"
5271 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5272 (org-entry-put (point) "A" "2")
5275 (string-match "^ *:A: +1$"
5276 (org-test-with-temp-text "* H"
5277 (org-entry-put (point) "A" "1")
5279 ;; Special case: two consecutive headlines.
5281 (string-match "\\* A\n *:PROPERTIES:"
5282 (org-test-with-temp-text "* A\n** B"
5283 (org-entry-put (point) "A" "1")
5286 (ert-deftest test-org
/refresh-properties
()
5287 "Test `org-refresh-properties' specifications."
5290 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5291 (org-refresh-properties "A" 'org-test
)
5292 (get-text-property (point) 'org-test
))))
5294 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5295 (org-refresh-properties "B" 'org-test
)
5296 (get-text-property (point) 'org-test
)))
5297 ;; Handle properties only defined with extension syntax, i.e.,
5301 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5302 (org-refresh-properties "A" 'org-test
)
5303 (get-text-property (point) 'org-test
))))
5304 ;; When property is inherited, add text property to the whole
5308 (org-test-with-temp-text
5309 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5310 (let ((org-use-property-inheritance t
))
5311 (org-refresh-properties "A" 'org-test
))
5312 (get-text-property (point) 'org-test
))))
5313 ;; When property is inherited, use global value across the whole
5314 ;; buffer. However local values have precedence.
5317 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5319 (let ((org-use-property-inheritance nil
))
5320 (org-refresh-properties "A" 'org-test
))
5321 (get-text-property (point) 'org-test
))))
5324 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5326 (let ((org-use-property-inheritance t
))
5327 (org-refresh-properties "A" 'org-test
))
5328 (get-text-property (point) 'org-test
))))
5331 (org-test-with-temp-text
5332 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5334 (let ((org-use-property-inheritance t
))
5335 (org-refresh-properties "A" 'org-test
))
5336 (get-text-property (point) 'org-test
)))))
5341 (ert-deftest test-org
/update-radio-target-regexp
()
5342 "Test `org-update-radio-target-regexp' specifications."
5343 ;; Properly update cache with no previous radio target regexp.
5346 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5347 (save-excursion (goto-char (point-max)) (org-element-context))
5349 (search-forward "o")
5351 (org-update-radio-target-regexp)
5352 (goto-char (point-max))
5353 (org-element-type (org-element-context)))))
5354 ;; Properly update cache with previous radio target regexp.
5357 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5358 (save-excursion (goto-char (point-max)) (org-element-context))
5360 (search-forward "o")
5362 (org-update-radio-target-regexp)
5363 (search-backward "r")
5366 (org-update-radio-target-regexp)
5367 (goto-char (point-max))
5368 (delete-region (line-beginning-position) (point))
5370 (org-element-type (org-element-context))))))
5375 (ert-deftest test-org
/refile-get-targets
()
5376 "Test `org-refile-get-targets' specifications."
5377 ;; :maxlevel includes all headings above specified value.
5379 (equal '("H1" "H2" "H3")
5380 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5381 (let ((org-refile-use-outline-path nil
)
5382 (org-refile-targets `((nil :maxlevel .
3))))
5383 (mapcar #'car
(org-refile-get-targets))))))
5386 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5387 (let ((org-refile-use-outline-path nil
)
5388 (org-refile-targets `((nil :maxlevel .
2))))
5389 (mapcar #'car
(org-refile-get-targets))))))
5390 ;; :level limits targets to headlines with the specified level.
5393 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5394 (let ((org-refile-use-outline-path nil
)
5395 (org-refile-targets `((nil :level .
2))))
5396 (mapcar #'car
(org-refile-get-targets))))))
5397 ;; :tag limits targets to headlines with specified tag.
5400 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5401 (let ((org-refile-use-outline-path nil
)
5402 (org-refile-targets `((nil :tag .
"foo"))))
5403 (mapcar #'car
(org-refile-get-targets))))))
5404 ;; :todo limits targets to headlines with specified TODO keyword.
5407 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5408 (let ((org-refile-use-outline-path nil
)
5409 (org-refile-targets `((nil :todo .
"TODO"))))
5410 (mapcar #'car
(org-refile-get-targets))))))
5411 ;; :regexp filters targets matching provided regexp.
5414 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5415 (let ((org-refile-use-outline-path nil
)
5416 (org-refile-targets `((nil :regexp .
"F"))))
5417 (mapcar #'car
(org-refile-get-targets))))))
5418 ;; A nil `org-refile-targets' includes only top level headlines in
5422 (org-test-with-temp-text "* H1\n** S1\n* H2"
5423 (let ((org-refile-use-outline-path nil
)
5424 (org-refile-targets nil
))
5425 (mapcar #'car
(org-refile-get-targets))))))
5426 ;; Return value is the union of the targets according to all the
5427 ;; defined rules. However, prevent duplicates.
5429 (equal '("F2" "F3" "H1")
5430 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5431 (let ((org-refile-use-outline-path nil
)
5432 (org-refile-targets `((nil :regexp .
"F")
5433 (nil :todo .
"TODO"))))
5434 (mapcar #'car
(org-refile-get-targets))))))
5436 (equal '("F2" "F3" "H1")
5437 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5438 (let ((org-refile-use-outline-path nil
)
5439 (org-refile-targets `((nil :regexp .
"F")
5440 (nil :todo .
"TODO"))))
5441 (mapcar #'car
(org-refile-get-targets))))))
5442 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5445 (equal '("H1" "H1/H2" "H1/H2/H3")
5446 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5447 (let ((org-refile-use-outline-path t
)
5448 (org-refile-targets `((nil :maxlevel .
3))))
5449 (mapcar #'car
(org-refile-get-targets))))))
5450 ;; When providing targets as paths, escape forward slashes in
5451 ;; headings with backslashes.
5453 (equal '("H1\\/foo")
5454 (org-test-with-temp-text "* H1/foo"
5455 (let ((org-refile-use-outline-path t
)
5456 (org-refile-targets `((nil :maxlevel .
1))))
5457 (mapcar #'car
(org-refile-get-targets))))))
5458 ;; When `org-refile-use-outline-path' is `file', include file name
5459 ;; without directory in targets.
5461 (org-test-with-temp-text-in-file "* H1"
5462 (let* ((filename (buffer-file-name))
5463 (org-refile-use-outline-path 'file
)
5464 (org-refile-targets `(((,filename
) :level .
1))))
5465 (member (file-name-nondirectory filename
)
5466 (mapcar #'car
(org-refile-get-targets))))))
5467 ;; When `org-refile-use-outline-path' is `full-file-path', include
5470 (org-test-with-temp-text-in-file "* H1"
5471 (let* ((filename (buffer-file-name))
5472 (org-refile-use-outline-path 'full-file-path
)
5473 (org-refile-targets `(((,filename
) :level .
1))))
5474 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5475 ;; When `org-refile-use-outline-path' is `buffer-name', include
5478 (org-test-with-temp-text "* H1"
5479 (let* ((org-refile-use-outline-path 'buffer-name
)
5480 (org-refile-targets `((nil :level .
1))))
5481 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5487 (ert-deftest test-org
/match-sparse-tree
()
5488 "Test `org-match-sparse-tree' specifications."
5491 (org-test-with-temp-text "* H\n** H1 :tag:"
5492 (org-match-sparse-tree nil
"tag")
5493 (search-forward "H1")
5494 (org-invisible-p2)))
5496 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5497 (org-match-sparse-tree nil
"tag")
5498 (search-forward "H2")
5499 (org-invisible-p2)))
5500 ;; "-" operator for tags.
5502 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5503 (org-match-sparse-tree nil
"tag1-tag2")
5504 (search-forward "H1")
5505 (org-invisible-p2)))
5507 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5508 (org-match-sparse-tree nil
"tag1-tag2")
5509 (search-forward "H2")
5510 (org-invisible-p2)))
5511 ;; "&" operator for tags.
5513 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5514 (org-match-sparse-tree nil
"tag1&tag2")
5515 (search-forward "H1")
5516 (org-invisible-p2)))
5518 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5519 (org-match-sparse-tree nil
"tag1&tag2")
5520 (search-forward "H2")
5521 (org-invisible-p2)))
5522 ;; "|" operator for tags.
5524 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5525 (org-match-sparse-tree nil
"tag1|tag2")
5526 (search-forward "H1")
5527 (org-invisible-p2)))
5529 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5530 (org-match-sparse-tree nil
"tag1|tag2")
5531 (search-forward "H2")
5532 (org-invisible-p2)))
5533 ;; Regexp match on tags.
5535 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5536 (org-match-sparse-tree nil
"{^tag.*}")
5537 (search-forward "H1")
5538 (org-invisible-p2)))
5540 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5541 (org-match-sparse-tree nil
"{^tag.*}")
5542 (search-forward "H2")
5543 (org-invisible-p2)))
5544 ;; Match group tags.
5546 (org-test-with-temp-text
5547 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5548 (org-match-sparse-tree nil
"work")
5549 (search-forward "H1")
5550 (org-invisible-p2)))
5552 (org-test-with-temp-text
5553 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5554 (org-match-sparse-tree nil
"work")
5555 (search-forward "H2")
5556 (org-invisible-p2)))
5557 ;; Match group tags with hard brackets.
5559 (org-test-with-temp-text
5560 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5561 (org-match-sparse-tree nil
"work")
5562 (search-forward "H1")
5563 (org-invisible-p2)))
5565 (org-test-with-temp-text
5566 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5567 (org-match-sparse-tree nil
"work")
5568 (search-forward "H2")
5569 (org-invisible-p2)))
5570 ;; Match tags in hierarchies
5572 (org-test-with-temp-text
5573 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5574 #+TAGS: [ Lev_2 : Lev_3 ]\n
5575 #+TAGS: { Lev_3 : Lev_4 }\n
5576 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5577 (org-match-sparse-tree nil
"Lev_1")
5578 (search-forward "H4")
5579 (org-invisible-p2)))
5580 ;; Match regular expressions in tags
5582 (org-test-with-temp-text
5583 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5584 (org-match-sparse-tree nil
"Lev")
5585 (search-forward "H1")
5586 (org-invisible-p2)))
5588 (org-test-with-temp-text
5589 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5590 (org-match-sparse-tree nil
"Lev")
5591 (search-forward "H1")
5592 (org-invisible-p2)))
5593 ;; Match properties.
5595 (org-test-with-temp-text
5596 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5597 (org-match-sparse-tree nil
"A=\"1\"")
5598 (search-forward "H2")
5599 (org-invisible-p2)))
5601 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5602 (org-match-sparse-tree nil
"A=\"1\"")
5603 (search-forward "H2")
5604 (org-invisible-p2)))
5605 ;; Case is not significant when matching properties.
5607 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5608 (org-match-sparse-tree nil
"a=\"1\"")
5609 (search-forward "H2")
5610 (org-invisible-p2)))
5612 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5613 (org-match-sparse-tree nil
"A=\"1\"")
5614 (search-forward "H2")
5615 (org-invisible-p2)))
5616 ;; Match special LEVEL property.
5618 (org-test-with-temp-text "* H\n** H1\n*** H2"
5619 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5620 (search-forward "H1")
5621 (org-invisible-p2)))
5623 (org-test-with-temp-text "* H\n** H1\n*** H2"
5624 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5625 (search-forward "H2")
5626 (org-invisible-p2)))
5627 ;; Comparison operators when matching properties.
5629 (org-test-with-temp-text
5630 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5631 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5632 (search-forward "H1")
5633 (org-invisible-p2)))
5635 (org-test-with-temp-text
5636 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5637 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5638 (search-forward "H2")
5639 (org-invisible-p2)))
5640 ;; Regexp match on properties values.
5642 (org-test-with-temp-text
5643 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5644 (org-match-sparse-tree nil
"A={f.*}")
5645 (search-forward "H1")
5646 (org-invisible-p2)))
5648 (org-test-with-temp-text
5649 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5650 (org-match-sparse-tree nil
"A={f.*}")
5651 (search-forward "H2")
5652 (org-invisible-p2)))
5653 ;; With an optional argument, limit match to TODO entries.
5655 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5656 (org-match-sparse-tree t
"tag")
5657 (search-forward "H1")
5658 (org-invisible-p2)))
5660 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5661 (org-match-sparse-tree t
"tag")
5662 (search-forward "H2")
5663 (org-invisible-p2))))
5665 (ert-deftest test-org
/occur
()
5666 "Test `org-occur' specifications."
5667 ;; Count number of matches.
5670 (org-test-with-temp-text "* H\nA\n* H2"
5674 (org-test-with-temp-text "* H\nA\n* H2\nA"
5676 ;; Test CALLBACK optional argument.
5679 (org-test-with-temp-text "* H\nA\n* H2"
5680 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5683 (org-test-with-temp-text "* H\nA\n* H2\nA"
5684 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5685 ;; Case-fold searches according to `org-occur-case-fold-search'.
5688 (org-test-with-temp-text "Aa"
5689 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5692 (org-test-with-temp-text "Aa"
5693 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5696 (org-test-with-temp-text "Aa"
5697 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5700 (org-test-with-temp-text "Aa"
5701 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5704 (org-test-with-temp-text "Aa"
5705 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5708 (org-test-with-temp-text "Aa"
5709 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5714 (ert-deftest test-org
/tag-string-to-alist
()
5715 "Test `org-tag-string-to-alist' specifications."
5716 ;; Tag without selection key.
5717 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5718 ;; Tag with selection key.
5719 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5723 (org-tag-string-to-alist "[ group : t1 t2 ]")
5724 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5725 ;; Mutually exclusive tags.
5726 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5727 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5730 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5731 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5733 (ert-deftest test-org
/tag-alist-to-string
()
5734 "Test `org-tag-alist-to-string' specifications."
5735 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5736 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5739 (org-tag-alist-to-string
5740 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5741 "[ group : t1 t2 ]"))
5743 (equal (org-tag-alist-to-string
5744 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5748 (org-tag-alist-to-string
5749 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5750 "{ group : tag1 tag2 }")))
5752 (ert-deftest test-org
/tag-alist-to-groups
()
5753 "Test `org-tag-alist-to-groups' specifications."
5755 (equal (org-tag-alist-to-groups
5756 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5757 '(("group" "t1" "t2"))))
5760 (org-tag-alist-to-groups
5761 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5762 '(("group" "t1" "t2"))))
5764 (org-tag-alist-to-groups
5765 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5767 (ert-deftest test-org
/tag-align
()
5768 "Test tags alignment."
5769 ;; Test aligning tags with different display width.
5771 ;; 12345678901234567890
5772 (equal "* Test :abc:"
5773 (org-test-with-temp-text "* Test :abc:"
5774 (let ((org-tags-column -
20)
5775 (indent-tabs-mode nil
))
5776 (org-fix-tags-on-the-fly))
5779 ;; 12345678901234567890
5780 (equal "* Test :日本語:"
5781 (org-test-with-temp-text "* Test :日本語:"
5782 (let ((org-tags-column -
20)
5783 (indent-tabs-mode nil
))
5784 (org-fix-tags-on-the-fly))
5786 ;; Make sure aligning tags do not skip invisible text.
5788 (equal "* [[linkx]] :tag:"
5789 (org-test-with-temp-text "* [[link<point>]] :tag:"
5790 (let ((org-tags-column 0))
5791 (org-fix-tags-on-the-fly)
5793 (buffer-string))))))
5795 (ert-deftest test-org
/tags-at
()
5797 (equal '("foo" "bar")
5798 (org-test-with-temp-text
5799 "* T<point>est :foo:bar:"
5800 (org-get-tags-at)))))
5805 (ert-deftest test-org
/auto-repeat-maybe
()
5806 "Test `org-auto-repeat-maybe' specifications."
5807 ;; Do not auto repeat when there is no valid time stamp with
5808 ;; a repeater in the entry.
5812 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5813 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5819 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5820 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5823 ;; When switching to DONE state, switch back to first TODO keyword
5824 ;; in sequence, or the same keyword if they have different types.
5828 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5829 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5835 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5836 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5842 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5843 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5846 ;; If there was no TODO keyword in the first place, do not insert
5851 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5852 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5855 ;; Revert to REPEAT_TO_STATE, if set.
5859 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5860 (org-test-with-temp-text
5863 :REPEAT_TO_STATE: KWD2
5865 <2012-03-29 Thu +2y>"
5868 ;; When switching to DONE state, update base date. If there are
5869 ;; multiple repeated time stamps, update them all.
5872 "<2014-03-29 .* \\+2y>"
5873 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5874 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5879 "<2015-03-04 .* \\+1y>"
5880 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5881 (org-test-with-temp-text
5882 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5885 ;; Throw an error if repeater unit is the hour and no time is
5886 ;; provided in the time-stamp.
5888 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5889 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5892 ;; Do not repeat commented time stamps.
5895 "<2015-03-04 .* \\+1y>"
5896 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5897 (org-test-with-temp-text
5898 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5903 "<2015-03-04 .* \\+1y>"
5904 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5905 (org-test-with-temp-text
5907 <2012-03-29 Thu. +2y>
5909 <2014-03-04 Tue +1y>
5913 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5914 ;; entry, record time of last repeat.
5918 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5919 (org-log-repeat nil
))
5920 (cl-letf (((symbol-function 'org-add-log-setup
)
5921 (lambda (&rest args
) nil
)))
5922 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5924 (buffer-string))))))
5928 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5930 (cl-letf (((symbol-function 'org-add-log-setup
)
5931 (lambda (&rest args
) nil
)))
5932 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5934 (buffer-string))))))
5938 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5939 (cl-letf (((symbol-function 'org-add-log-setup
)
5940 (lambda (&rest args
) nil
)))
5941 (org-test-with-temp-text
5942 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5944 (buffer-string))))))
5945 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5946 ;; the entry as it is no longer relevant.
5950 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5951 (org-test-with-temp-text
5952 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5954 (buffer-string))))))
5959 (ert-deftest test-org
/at-timestamp-p
()
5960 "Test `org-at-timestamp-p' specifications."
5962 (org-test-with-temp-text "<2012-03-29 Thu>"
5963 (org-at-timestamp-p)))
5965 (org-test-with-temp-text "2012-03-29 Thu"
5966 (org-at-timestamp-p)))
5967 ;; Test return values.
5970 (org-test-with-temp-text "<2012-03-29 Thu>"
5971 (org-at-timestamp-p))))
5974 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5975 (org-at-timestamp-p))))
5978 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5979 (org-at-timestamp-p))))
5982 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5983 (org-at-timestamp-p))))
5986 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5987 (org-at-timestamp-p))))
5990 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5991 (org-at-timestamp-p))))
5994 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5995 (org-at-timestamp-p))))
5998 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5999 (org-at-timestamp-p))))
6000 ;; Test `inactive' optional argument.
6002 (org-test-with-temp-text "[2012-03-29 Thu]"
6003 (org-at-timestamp-p 'inactive
)))
6005 (org-test-with-temp-text "[2012-03-29 Thu]"
6006 (org-at-timestamp-p)))
6007 ;; When optional argument is `agenda', recognize time-stamps in
6008 ;; planning info line, property drawers and clocks.
6010 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6011 (org-at-timestamp-p 'agenda
)))
6013 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6014 (org-at-timestamp-p)))
6016 (org-test-with-temp-text
6017 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6018 (org-at-timestamp-p 'agenda
)))
6020 (org-test-with-temp-text
6021 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6022 (org-at-timestamp-p)))
6024 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6025 (let ((org-agenda-include-inactive-timestamps t
))
6026 (org-at-timestamp-p 'agenda
))))
6028 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6029 (let ((org-agenda-include-inactive-timestamps t
))
6030 (org-at-timestamp-p))))
6032 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6033 (let ((org-agenda-include-inactive-timestamps t
))
6034 (org-at-timestamp-p 'inactive
))))
6035 ;; When optional argument is `lax', match any part of the document
6036 ;; with Org timestamp syntax.
6038 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6039 (org-at-timestamp-p 'lax
)))
6041 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6042 (org-at-timestamp-p)))
6044 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6045 (org-at-timestamp-p 'lax
)))
6047 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6048 (org-at-timestamp-p)))
6050 (org-test-with-temp-text
6051 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6052 (org-at-timestamp-p 'lax
)))
6054 (org-test-with-temp-text
6055 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6056 (org-at-timestamp-p)))
6057 ;; Optional argument `lax' also matches inactive timestamps.
6059 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6060 (org-at-timestamp-p 'lax
))))
6062 (ert-deftest test-org
/time-stamp
()
6063 "Test `org-time-stamp' specifications."
6064 ;; Insert chosen time stamp at point.
6067 "Te<2014-03-04 .*?>xt"
6068 (org-test-with-temp-text "Te<point>xt"
6069 (cl-letf (((symbol-function 'org-read-date
)
6070 (lambda (&rest args
)
6071 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6072 (org-time-stamp nil
)
6074 ;; With a prefix argument, also insert time.
6077 "Te<2014-03-04 .*? 00:41>xt"
6078 (org-test-with-temp-text "Te<point>xt"
6079 (cl-letf (((symbol-function 'org-read-date
)
6080 (lambda (&rest args
)
6081 (apply #'encode-time
6082 (org-parse-time-string "2014-03-04 00:41")))))
6083 (org-time-stamp '(4))
6085 ;; With two universal prefix arguments, insert an active timestamp
6086 ;; with the current time without prompting the user.
6089 "Te<2014-03-04 .*? 00:41>xt"
6090 (org-test-with-temp-text "Te<point>xt"
6091 (cl-letf (((symbol-function 'current-time
)
6093 (apply #'encode-time
6094 (org-parse-time-string "2014-03-04 00:41")))))
6095 (org-time-stamp '(16))
6097 ;; When optional argument is non-nil, insert an inactive timestamp.
6100 "Te\\[2014-03-04 .*?\\]xt"
6101 (org-test-with-temp-text "Te<point>xt"
6102 (cl-letf (((symbol-function 'org-read-date
)
6103 (lambda (&rest args
)
6104 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6105 (org-time-stamp nil t
)
6107 ;; When called from a timestamp, replace existing one.
6111 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6112 (cl-letf (((symbol-function 'org-read-date
)
6113 (lambda (&rest args
)
6114 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6115 (org-time-stamp nil
)
6119 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6120 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6121 (cl-letf (((symbol-function 'org-read-date
)
6122 (lambda (&rest args
)
6123 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6124 (org-time-stamp nil
)
6126 ;; When replacing a timestamp, preserve repeater, if any.
6129 "<2014-03-04 .*? \\+2y>"
6130 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6131 (cl-letf (((symbol-function 'org-read-date
)
6132 (lambda (&rest args
)
6133 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6134 (org-time-stamp nil
)
6136 ;; When called twice in a raw, build a date range.
6139 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6140 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6141 (cl-letf (((symbol-function 'org-read-date
)
6142 (lambda (&rest args
)
6143 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6144 (let ((last-command 'org-time-stamp
)
6145 (this-command 'org-time-stamp
))
6146 (org-time-stamp nil
))
6147 (buffer-string))))))
6149 (ert-deftest test-org
/timestamp-has-time-p
()
6150 "Test `org-timestamp-has-time-p' specifications."
6153 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6154 (org-timestamp-has-time-p (org-element-context))))
6157 (org-test-with-temp-text "<2012-03-29 Thu>"
6158 (org-timestamp-has-time-p (org-element-context)))))
6160 (ert-deftest test-org
/get-repeat
()
6161 "Test `org-get-repeat' specifications."
6163 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6166 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6168 ;; Return proper repeat string.
6171 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6173 ;; Prevent false positive (commented or verbatim time stamps)
6175 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6178 (org-test-with-temp-text
6179 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6181 ;; Return nil when called before first heading.
6183 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6185 ;; When called with an optional argument, extract repeater from that
6187 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6188 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6190 (ert-deftest test-org
/timestamp-format
()
6191 "Test `org-timestamp-format' specifications."
6196 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6197 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6202 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6203 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6205 (ert-deftest test-org
/timestamp-split-range
()
6206 "Test `org-timestamp-split-range' specifications."
6207 ;; Extract range start (active).
6210 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6211 (let ((ts (org-timestamp-split-range (org-element-context))))
6212 (mapcar (lambda (p) (org-element-property p ts
))
6213 '(:year-end
:month-end
:day-end
))))))
6214 ;; Extract range start (inactive)
6217 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6218 (let ((ts (org-timestamp-split-range (org-element-context))))
6219 (mapcar (lambda (p) (org-element-property p ts
))
6220 '(:year-end
:month-end
:day-end
))))))
6221 ;; Extract range end (active).
6224 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6225 (let ((ts (org-timestamp-split-range
6226 (org-element-context) t
)))
6227 (mapcar (lambda (p) (org-element-property p ts
))
6228 '(:year-end
:month-end
:day-end
))))))
6229 ;; Extract range end (inactive)
6232 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6233 (let ((ts (org-timestamp-split-range
6234 (org-element-context) t
)))
6235 (mapcar (lambda (p) (org-element-property p ts
))
6236 '(:year-end
:month-end
:day-end
))))))
6237 ;; Return the timestamp if not a range.
6239 (org-test-with-temp-text "[2012-03-29 Thu]"
6240 (let* ((ts-orig (org-element-context))
6241 (ts-copy (org-timestamp-split-range ts-orig
)))
6242 (eq ts-orig ts-copy
))))
6244 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6245 (let* ((ts-orig (org-element-context))
6246 (ts-copy (org-timestamp-split-range ts-orig
)))
6247 (eq ts-orig ts-copy
)))))
6249 (ert-deftest test-org
/timestamp-translate
()
6250 "Test `org-timestamp-translate' specifications."
6251 ;; Translate whole date range.
6254 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6255 (let ((org-display-custom-times t
)
6256 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6257 (org-timestamp-translate (org-element-context))))))
6258 ;; Translate date range start.
6261 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6262 (let ((org-display-custom-times t
)
6263 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6264 (org-timestamp-translate (org-element-context) 'start
)))))
6265 ;; Translate date range end.
6268 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6269 (let ((org-display-custom-times t
)
6270 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6271 (org-timestamp-translate (org-element-context) 'end
)))))
6272 ;; Translate time range.
6275 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6276 (let ((org-display-custom-times t
)
6277 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6278 (org-timestamp-translate (org-element-context))))))
6279 ;; Translate non-range timestamp.
6282 (org-test-with-temp-text "<2012-03-29 Thu>"
6283 (let ((org-display-custom-times t
)
6284 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6285 (org-timestamp-translate (org-element-context))))))
6286 ;; Do not change `diary' timestamps.
6288 (equal "<%%(org-float t 4 2)>"
6289 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6290 (let ((org-display-custom-times t
)
6291 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6292 (org-timestamp-translate (org-element-context)))))))
6298 (ert-deftest test-org
/flag-drawer
()
6299 "Test `org-flag-drawer' specifications."
6302 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6304 (get-char-property (line-end-position) 'invisible
)))
6307 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6309 (org-flag-drawer nil
)
6310 (get-char-property (line-end-position) 'invisible
)))
6311 ;; Test optional argument.
6313 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6314 (let ((drawer (save-excursion (search-forward ":D2")
6315 (org-element-at-point))))
6316 (org-flag-drawer t drawer
)
6317 (get-char-property (progn (search-forward ":D2") (line-end-position))
6320 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6321 (let ((drawer (save-excursion (search-forward ":D2")
6322 (org-element-at-point))))
6323 (org-flag-drawer t drawer
)
6324 (get-char-property (line-end-position) 'invisible
))))
6325 ;; Do not hide fake drawers.
6327 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6330 (get-char-property (line-end-position) 'invisible
)))
6331 ;; Do not hide incomplete drawers.
6333 (org-test-with-temp-text ":D:\nparagraph"
6336 (get-char-property (line-end-position) 'invisible
)))
6337 ;; Do not hide drawers when called from final blank lines.
6339 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6340 (goto-char (point-max))
6342 (goto-char (point-min))
6343 (get-char-property (line-end-position) 'invisible
)))
6344 ;; Don't leave point in an invisible part of the buffer when hiding
6347 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6348 (goto-char (point-max))
6350 (get-char-property (point) 'invisible
))))
6352 (ert-deftest test-org
/hide-block-toggle
()
6353 "Test `org-hide-block-toggle' specifications."
6354 ;; Error when not at a block.
6356 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6357 (org-hide-block-toggle 'off
)
6358 (get-char-property (line-end-position) 'invisible
)))
6361 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6362 (org-hide-block-toggle)
6363 (get-char-property (line-end-position) 'invisible
)))
6365 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6366 (org-hide-block-toggle)
6367 (get-char-property (line-end-position) 'invisible
)))
6368 ;; Show block unconditionally when optional argument is `off'.
6370 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6371 (org-hide-block-toggle)
6372 (org-hide-block-toggle 'off
)
6373 (get-char-property (line-end-position) 'invisible
)))
6375 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6376 (org-hide-block-toggle 'off
)
6377 (get-char-property (line-end-position) 'invisible
)))
6378 ;; Hide block unconditionally when optional argument is non-nil.
6380 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6381 (org-hide-block-toggle t
)
6382 (get-char-property (line-end-position) 'invisible
)))
6384 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6385 (org-hide-block-toggle)
6386 (org-hide-block-toggle t
)
6387 (get-char-property (line-end-position) 'invisible
)))
6388 ;; Do not hide block when called from final blank lines.
6390 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6391 (org-hide-block-toggle)
6392 (goto-char (point-min))
6393 (get-char-property (line-end-position) 'invisible
)))
6394 ;; Don't leave point in an invisible part of the buffer when hiding
6397 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6398 (org-hide-block-toggle)
6399 (get-char-property (point) 'invisible
))))
6401 (ert-deftest test-org
/hide-block-toggle-maybe
()
6402 "Test `org-hide-block-toggle-maybe' specifications."
6404 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6405 (org-hide-block-toggle-maybe)))
6407 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6409 (ert-deftest test-org
/set-tags
()
6410 "Test `org-set-tags' specifications."
6411 ;; Tags set via fast-tag-selection should be visible afterwards
6413 (let ((org-tag-alist '(("NEXT" . ?n
)))
6414 (org-fast-tag-selection-single-key t
))
6415 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6416 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6417 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6418 ;; Show only headlines
6420 ;; Set NEXT tag on current entry
6421 (org-set-tags nil nil
)
6422 ;; Move point to that NEXT tag
6423 (search-forward "NEXT") (backward-word)
6424 ;; And it should be visible (i.e. no overlays)
6425 (not (overlays-at (point))))))))
6427 (ert-deftest test-org
/show-set-visibility
()
6428 "Test `org-show-set-visibility' specifications."
6429 ;; Do not throw an error before first heading.
6431 (org-test-with-temp-text "Preamble\n* Headline"
6432 (org-show-set-visibility 'tree
)
6434 ;; Test all visibility spans, both on headline and in entry.
6435 (let ((list-visible-lines
6436 (lambda (state headerp
)
6437 (org-test-with-temp-text "* Grandmother (0)
6448 **** The other child (11)
6453 (search-forward (if headerp
"Self" "Match"))
6454 (org-show-set-visibility state
)
6455 (goto-char (point-min))
6456 (let (result (line 0))
6458 (unless (org-invisible-p2) (push line result
))
6461 (nreverse result
))))))
6462 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6463 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6464 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6465 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6466 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6467 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6468 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6469 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6470 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6471 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6472 (funcall list-visible-lines
'tree nil
)))
6473 (should (equal '(0 1 3 4 5 7 12 13)
6474 (funcall list-visible-lines
'canonical t
)))
6475 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6476 (funcall list-visible-lines
'canonical nil
))))
6477 ;; When point is hidden in a drawer or a block, make sure to make it
6480 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6481 (org-hide-block-toggle)
6482 (search-forward "Text")
6483 (org-show-set-visibility 'minimal
)
6484 (org-invisible-p2)))
6486 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6488 (search-forward "Text")
6489 (org-show-set-visibility 'minimal
)
6490 (org-invisible-p2)))
6492 (org-test-with-temp-text
6493 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6496 (org-hide-block-toggle)
6497 (search-forward "Text")
6498 (org-show-set-visibility 'minimal
)
6499 (org-invisible-p2))))
6501 (ert-deftest test-org
/org-file-contents-file
()
6502 "Test `org-file-contents' with a file as input."
6504 (string= "#+BIND: variable value
6510 " (org-file-contents (expand-file-name "setupfile3.org"
6511 (concat org-test-dir
"examples/")))))
6513 (let ((invalid-file "this-file-must-not-exist"))
6514 ;; Throw error when trying to access an invalid file.
6516 (org-file-contents invalid-file
))
6517 ;; Try to access an invalid file, but do not throw an error.
6519 (string-match-p "\\`Opening input file: No such file or directory"
6520 (org-file-contents invalid-file
:noerror
)))))
6522 (ert-deftest test-org
/org-file-contents-url
()
6523 "Test `org-file-contents' with a URL as input."
6526 (let ((buffer (generate-new-buffer "url-retrieve-output")))
6528 ;; Simulate successful retrieval of a URL.
6529 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
6531 (with-current-buffer buffer
6532 (insert "HTTP/1.1 200 OK\n\nfoo"))
6534 (org-file-contents "http://some-valid-url"))
6535 (kill-buffer buffer
)))))
6537 (let ((invalid-url "http://this-url-must-not-exist"))
6538 ;; Throw error when trying to access an invalid URL.
6540 (let ((buffer (generate-new-buffer "url-retrieve-output")))
6542 ;; Simulate unsuccessful retrieval of a URL.
6543 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
6545 (with-current-buffer buffer
6546 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
6548 (org-file-contents invalid-url
))
6549 (kill-buffer buffer
))))
6550 ;; Try to access an invalid URL, but do not throw an error.
6552 (let ((buffer (generate-new-buffer "url-retrieve-output")))
6554 ;; Simulate unsuccessful retrieval of a URL.
6555 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
6557 (with-current-buffer buffer
6558 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
6560 (org-file-contents invalid-url
))
6561 (kill-buffer buffer
))))
6564 (format "Unable to fetch file from \"%s\"" invalid-url
)
6565 (let ((buffer (generate-new-buffer "url-retrieve-output")))
6567 ;; Simulate unsuccessful retrieval of a URL.
6568 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
6570 (with-current-buffer buffer
6571 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
6573 (org-file-contents invalid-url
:noerror
))
6574 (kill-buffer buffer
)))))))
6579 ;;; test-org.el ends here