1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (progn (call-interactively 'comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (progn (call-interactively 'comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# Comment"
106 (progn (forward-line)
107 (let ((org-adapt-indentation t
))
108 (call-interactively 'comment-dwim
))
110 ;; Also recognize single # at column 0 as comments.
113 (org-test-with-temp-text "# Comment"
114 (progn (forward-line)
115 (call-interactively 'comment-dwim
)
117 ;; Region selected and only comments and blank lines within it:
118 ;; un-comment all commented lines.
120 (equal "Comment 1\n\nComment 2"
121 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
123 (transient-mark-mode 1)
124 (push-mark (point) t t
)
125 (goto-char (point-max))
126 (call-interactively 'comment-dwim
)
128 ;; Region selected without comments: comment all lines if
129 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
131 (equal "# Comment 1\n\n# Comment 2"
132 (org-test-with-temp-text "Comment 1\n\nComment 2"
134 (transient-mark-mode 1)
135 (push-mark (point) t t
)
136 (goto-char (point-max))
137 (let ((comment-empty-lines nil
))
138 (call-interactively 'comment-dwim
))
141 (equal "# Comment 1\n# \n# Comment 2"
142 (org-test-with-temp-text "Comment 1\n\nComment 2"
144 (transient-mark-mode 1)
145 (push-mark (point) t t
)
146 (goto-char (point-max))
147 (let ((comment-empty-lines t
))
148 (call-interactively 'comment-dwim
))
150 ;; In front of a keyword without region, insert a new comment.
152 (equal "# \n#+KEYWORD: value"
153 (org-test-with-temp-text "#+KEYWORD: value"
154 (progn (call-interactively 'comment-dwim
)
156 ;; In a source block, use appropriate syntax.
159 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively 'comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position) (point)))))
165 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
166 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
168 (transient-mark-mode 1)
169 (push-mark (point) t t
)
171 (let ((org-edit-src-content-indentation 2))
172 (call-interactively 'comment-dwim
))
177 ;;; Date and time analysis
179 (ert-deftest test-org
/org-read-date
()
180 "Test `org-read-date' specifications."
181 ;; Parse ISO date with abbreviated year and month.
182 (should (equal "2012-03-29 16:40"
183 (let ((org-time-was-given t
))
184 (org-read-date t nil
"12-3-29 16:40"))))
185 ;; Parse Europeans dates.
186 (should (equal "2012-03-29 16:40"
187 (let ((org-time-was-given t
))
188 (org-read-date t nil
"29.03.2012 16:40"))))
189 ;; Parse Europeans dates without year.
190 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
191 (let ((org-time-was-given t
))
192 (org-read-date t nil
"29.03. 16:40"))))
193 ;; Relative date applied to current time if there is single
194 ;; plus/minus, or to default date when there are two of them.
198 (cl-letf (((symbol-function 'current-time
)
200 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
203 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
207 (cl-letf (((symbol-function 'current-time
)
209 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (cl-letf (((symbol-function 'current-time
)
221 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
222 (let ((org-read-date-prefer-future t
))
223 (org-read-date t nil
"1")))))
227 (cl-letf (((symbol-function 'current-time
)
229 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
230 (let ((org-read-date-prefer-future t
))
231 (org-read-date t nil
"3-4")))))
235 (cl-letf (((symbol-function 'current-time
)
237 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
238 (let ((org-read-date-prefer-future nil
))
239 (org-read-date t nil
"3-4")))))
240 ;; When set to `org-read-date-prefer-future' is set to `time', read
241 ;; day is moved to tomorrow if specified hour is before current
242 ;; time. However, it only happens in no other part of the date is
247 (cl-letf (((symbol-function 'current-time
)
249 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
250 (let ((org-read-date-prefer-future 'time
))
251 (org-read-date t nil
"00:40" nil
)))))
255 (cl-letf (((symbol-function 'current-time
)
257 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
258 (let ((org-read-date-prefer-future 'time
))
259 (org-read-date t nil
"29 00:40" nil
)))))
260 ;; Caveat: `org-read-date-prefer-future' always refers to current
261 ;; time, not default time, when they differ.
265 (cl-letf (((symbol-function 'current-time
)
267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
268 (let ((org-read-date-prefer-future t
))
271 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
275 (cl-letf (((symbol-function 'current-time
)
277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
278 (let ((org-read-date-prefer-future t
))
281 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
283 (ert-deftest test-org
/org-parse-time-string
()
284 "Test `org-parse-time-string'."
285 (should (equal (org-parse-time-string "2012-03-29 16:40")
286 '(0 40 16 29 3 2012 nil nil nil
)))
287 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
288 '(0 40 16 29 3 2012 nil nil nil
)))
289 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
290 '(0 40 16 29 3 2012 nil nil nil
)))
291 (should (equal (org-parse-time-string "<2012-03-29>")
292 '(0 0 0 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>" t
)
294 '(0 nil nil
29 3 2012 nil nil nil
))))
296 (ert-deftest test-org
/closest-date
()
297 "Test `org-closest-date' specifications."
299 ;; Time stamps without a repeater are returned unchanged.
303 (calendar-gregorian-from-absolute
304 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
305 ;; Time stamps with a null repeater are returned unchanged.
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
311 ;; if PREFER is set to `past' always return a date before, or equal
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
323 ;; if PREFER is set to `future' always return a date before, or equal
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
333 (calendar-gregorian-from-absolute
334 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
335 ;; If PREFER is neither `past' nor `future', select closest date.
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
346 ;; Test "day" repeater.
349 (calendar-gregorian-from-absolute
350 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
355 ;; Test "month" repeater.
358 (calendar-gregorian-from-absolute
359 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
364 ;; Test "year" repeater.
367 (calendar-gregorian-from-absolute
368 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
371 (calendar-gregorian-from-absolute
372 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
374 (ert-deftest test-org
/deadline-close-p
()
375 "Test `org-deadline-close-p' specifications."
376 ;; Pretend that the current time is 2016-06-03 Fri 01:43
377 (cl-letf (((symbol-function 'current-time
)
380 (org-parse-time-string "2016-06-03 Fri 01:43")))))
381 ;; Timestamps are close if they are within `ndays' of lead time.
382 (org-test-with-temp-text "* Heading"
383 (should (org-deadline-close-p "2016-06-03 Fri" 0))
384 (should (org-deadline-close-p "2016-06-02 Thu" 0))
385 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
386 (should (org-deadline-close-p "2016-06-04 Sat" 1))
387 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
388 ;; Read `ndays' from timestamp if argument not given.
389 (org-test-with-temp-text "* H"
390 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
391 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
392 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
393 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
394 ;; Prefer `ndays' argument over lead time in timestamp.
395 (org-test-with-temp-text "* H"
396 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
397 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
398 ;; Completed tasks are never close.
399 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
400 (org-test-with-temp-text "* TODO Heading"
401 (should (org-deadline-close-p "2016-06-03")))
402 (org-test-with-temp-text "* DONE Heading"
403 (should-not (org-deadline-close-p "2016-06-03"))))))
408 (ert-deftest test-org
/insert-property-drawer
()
409 "Test `org-insert-property-drawer' specifications."
410 ;; Error before first headline.
411 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
412 ;; Insert drawer right after headline if there is no planning line,
413 ;; or after it otherwise.
415 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text "* H\nParagraph<point>"
417 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
420 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
421 (org-test-with-temp-text
422 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
423 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
425 ;; Indent inserted drawer.
427 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
428 (org-test-with-temp-text "* H\nParagraph<point>"
429 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
431 ;; Handle insertion at eob.
433 (equal "* H\n:PROPERTIES:\n:END:\n"
434 (org-test-with-temp-text "* H"
435 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
437 ;; Skip inlinetasks before point.
438 (when (featurep 'org-inlinetask
)
440 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
441 (org-test-with-temp-text
442 "* H\n*************** I\n*************** END\nP<point>"
443 (let ((org-adapt-indentation nil
)
444 (org-inlinetask-min-level 15))
445 (org-insert-property-drawer))
447 ;; Correctly set drawer in an inlinetask.
448 (when (featurep 'org-inlinetask
)
450 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
451 (org-test-with-temp-text
452 "* H\n*************** I\nP<point>\n*************** END"
453 (let ((org-adapt-indentation nil
)
454 (org-inlinetask-min-level 15))
455 (org-insert-property-drawer))
461 (ert-deftest test-org
/fill-element
()
462 "Test `org-fill-element' specifications."
463 ;; At an Org table, align it.
466 (org-test-with-temp-text "|a|"
470 (equal "#+name: table\n| a |\n"
471 (org-test-with-temp-text "#+name: table\n| a |\n"
474 ;; At a paragraph, preserve line breaks.
475 (org-test-with-temp-text "some \\\\\nlong\ntext"
476 (let ((fill-column 20))
478 (should (equal (buffer-string) "some \\\\\nlong text"))))
479 ;; Correctly fill a paragraph when point is at its very end.
482 (org-test-with-temp-text "A\nB"
483 (let ((fill-column 20))
484 (goto-char (point-max))
487 ;; Correctly fill the last paragraph of a greater element.
489 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
490 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
491 (let ((fill-column 8))
496 ;; Correctly fill an element in a narrowed buffer.
499 (org-test-with-temp-text "01234 6789"
500 (let ((fill-column 5))
501 (narrow-to-region 1 8)
504 ;; Handle `adaptive-fill-regexp' in paragraphs.
507 (org-test-with-temp-text "> a\n> b"
508 (let ((fill-column 5)
509 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
512 ;; Special case: Fill first paragraph when point is at an item or
513 ;; a plain-list or a footnote reference.
516 (org-test-with-temp-text "- A\n B"
517 (let ((fill-column 20))
522 (org-test-with-temp-text "[fn:1] A\nB"
523 (let ((fill-column 20))
526 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
527 (let ((fill-column 20))
529 (should (equal (buffer-string)
530 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
531 ;; Fill contents of `comment-block' elements.
534 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
535 (let ((fill-column 20))
539 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
540 ;; Fill `comment' elements.
543 (org-test-with-temp-text " # A\n # B"
544 (let ((fill-column 20))
547 ;; Do not mix consecutive comments when filling one of them.
549 (equal "# A B\n\n# C"
550 (org-test-with-temp-text "# A\n# B\n\n# C"
551 (let ((fill-column 20))
554 ;; Use commented empty lines as separators when filling comments.
556 (equal "# A B\n#\n# C"
557 (org-test-with-temp-text "# A\n# B\n#\n# C"
558 (let ((fill-column 20))
561 ;; Handle `adaptive-fill-regexp' in comments.
564 (org-test-with-temp-text "# > a\n# > b"
565 (let ((fill-column 20)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
569 ;; Do nothing at affiliated keywords.
571 (equal "#+NAME: para\nSome\ntext."
572 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
573 (let ((fill-column 20))
576 ;; Do not move point after table when filling a table.
578 (org-test-with-temp-text "| a | b |\n| c | d |\n"
582 ;; Do not fill "n" macro, with or without arguments, followed by
583 ;; a dot or a closing parenthesis since it could be confused with
584 ;; a numbered bullet.
586 (equal "123456789\n{{{n}}}."
587 (org-test-with-temp-text "123456789 {{{n}}}."
588 (let ((fill-column 10))
592 (equal "123456789\n{{{n}}}\)"
593 (org-test-with-temp-text "123456789 {{{n}}}\)"
594 (let ((fill-column 10))
598 (equal "123456789\n{{{n()}}}."
599 (org-test-with-temp-text "123456789 {{{n()}}}."
600 (let ((fill-column 10))
604 (equal "123456789\n{{{n(counter)}}}."
605 (org-test-with-temp-text "123456789 {{{n(counter)}}}."
606 (let ((fill-column 10))
610 (ert-deftest test-org
/auto-fill-function
()
611 "Test auto-filling features."
612 ;; Auto fill paragraph.
615 (org-test-with-temp-text "12345 7890"
616 (let ((fill-column 5))
618 (org-auto-fill-function)
620 ;; Auto fill first paragraph in an item.
622 (equal "- 12345\n 7890"
623 (org-test-with-temp-text "- 12345 7890"
624 (let ((fill-column 7))
626 (org-auto-fill-function)
628 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
630 (equal "> 12345\n 7890"
631 (org-test-with-temp-text "> 12345 7890"
632 (let ((fill-column 10)
633 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
634 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
636 (org-auto-fill-function)
639 (equal "> 12345\n> 12345\n> 7890"
640 (org-test-with-temp-text "> 12345\n> 12345 7890"
641 (let ((fill-column 10)
642 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
643 (goto-char (point-max))
644 (org-auto-fill-function)
647 (equal " 12345\n *12345\n *12345"
648 (org-test-with-temp-text " 12345\n *12345 12345"
649 (let ((fill-column 10)
650 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
651 (goto-char (point-max))
652 (org-auto-fill-function)
654 ;; Auto fill comments.
656 (equal " # 12345\n # 7890"
657 (org-test-with-temp-text " # 12345 7890"
658 (let ((fill-column 10))
660 (org-auto-fill-function)
662 ;; A hash within a line isn't a comment.
664 (equal "12345 # 7890\n# 1"
665 (org-test-with-temp-text "12345 # 7890 1"
666 (let ((fill-column 12))
668 (org-auto-fill-function)
670 ;; Correctly interpret empty prefix.
672 (equal "# a\n# b\nRegular\n# paragraph"
673 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
674 (let ((fill-column 12))
676 (org-auto-fill-function)
678 ;; Comment block: auto fill contents.
680 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
681 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
682 (let ((fill-column 5))
685 (org-auto-fill-function)
688 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
689 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
690 (let ((fill-column 5))
693 (org-auto-fill-function)
695 ;; Do not fill if a new item could be created.
698 (org-test-with-temp-text "12345 - 90"
699 (let ((fill-column 5))
701 (org-auto-fill-function)
703 ;; Do not fill if a line break could be introduced.
705 (equal "123\\\\\n7890"
706 (org-test-with-temp-text "123\\\\ 7890"
707 (let ((fill-column 6))
709 (org-auto-fill-function)
711 ;; Do not fill affiliated keywords.
713 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
714 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
715 (let ((fill-column 20))
717 (org-auto-fill-function)
724 (ert-deftest test-org
/indent-line
()
725 "Test `org-indent-line' specifications."
726 ;; Do not indent diary sexps, footnote definitions or headlines.
729 (org-test-with-temp-text "%%(org-calendar-holiday)"
731 (org-get-indentation))))
734 (org-test-with-temp-text "[fn:1] fn"
735 (let ((org-adapt-indentation t
)) (org-indent-line))
736 (org-get-indentation))))
739 (org-test-with-temp-text "* H"
741 (org-get-indentation))))
742 ;; Do not indent before first headline.
745 (org-test-with-temp-text ""
747 (org-get-indentation))))
748 ;; Indent according to headline level otherwise, unless
749 ;; `org-adapt-indentation' is nil.
752 (org-test-with-temp-text "* H\n<point>A"
753 (let ((org-adapt-indentation t
)) (org-indent-line))
754 (org-get-indentation))))
757 (org-test-with-temp-text "* H\n<point>\nA"
758 (let ((org-adapt-indentation t
)) (org-indent-line))
759 (org-get-indentation))))
762 (org-test-with-temp-text "* H\n<point>A"
763 (let ((org-adapt-indentation nil
)) (org-indent-line))
764 (org-get-indentation))))
765 ;; Indenting preserves point position.
767 (org-test-with-temp-text "* H\nA<point>B"
768 (let ((org-adapt-indentation t
)) (org-indent-line))
770 ;; Do not change indentation at an item or a LaTeX environment.
773 (org-test-with-temp-text "* H\n<point> - A"
774 (let ((org-adapt-indentation t
)) (org-indent-line))
775 (org-get-indentation))))
778 (org-test-with-temp-text
779 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
781 (org-get-indentation))))
782 ;; On blank lines at the end of a list, indent like last element
783 ;; within it if the line is still in the list. If the last element
784 ;; is an item, indent like its contents. Otherwise, indent like the
788 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
789 (let ((org-adapt-indentation t
)) (org-indent-line))
790 (org-get-indentation))))
793 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
794 (let ((org-adapt-indentation t
)) (org-indent-line))
795 (org-get-indentation))))
798 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
799 (let ((org-adapt-indentation t
)) (org-indent-line))
800 (org-get-indentation))))
803 (org-test-with-temp-text "* H\n- A\n - \n<point>"
804 (let ((org-adapt-indentation t
)) (org-indent-line))
805 (org-get-indentation))))
808 (org-test-with-temp-text
809 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
810 (let ((org-adapt-indentation t
)) (org-indent-line))
811 (org-get-indentation))))
814 (org-test-with-temp-text "- A\n B\n\n<point>"
815 (let ((org-adapt-indentation nil
)) (org-indent-line))
816 (org-get-indentation))))
819 (org-test-with-temp-text
820 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
821 (let ((org-adapt-indentation nil
)) (org-indent-line))
822 (org-get-indentation))))
823 ;; Likewise, on a blank line at the end of a footnote definition,
824 ;; indent at column 0 if line belongs to the definition. Otherwise,
825 ;; indent like the definition itself.
828 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
829 (let ((org-adapt-indentation t
)) (org-indent-line))
830 (org-get-indentation))))
833 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
834 (let ((org-adapt-indentation t
)) (org-indent-line))
835 (org-get-indentation))))
836 ;; After the end of the contents of a greater element, indent like
837 ;; the beginning of the element.
840 (org-test-with-temp-text
841 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
843 (org-get-indentation))))
844 ;; On blank lines after a paragraph, indent like its last non-empty
848 (org-test-with-temp-text " Paragraph\n\n<point>"
850 (org-get-indentation))))
851 ;; At the first line of an element, indent like previous element's
852 ;; first line, ignoring footnotes definitions and inline tasks, or
853 ;; according to parent.
856 (org-test-with-temp-text "A\n\n B\n\nC<point>"
858 (org-get-indentation))))
861 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
863 (org-get-indentation))))
866 (org-test-with-temp-text
867 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
869 (org-get-indentation))))
870 ;; Within code part of a source block, use language major mode if
871 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
872 ;; according to line above.
875 (org-test-with-temp-text
876 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
877 (let ((org-src-tab-acts-natively t
)
878 (org-edit-src-content-indentation 0))
880 (org-get-indentation))))
883 (org-test-with-temp-text
884 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
885 (let ((org-src-tab-acts-natively nil
)
886 (org-edit-src-content-indentation 0))
888 (org-get-indentation))))
889 ;; Otherwise, indent like the first non-blank line above.
892 (org-test-with-temp-text
893 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
895 (org-get-indentation))))
896 ;; Align node properties according to `org-property-format'. Handle
897 ;; nicely empty values.
899 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
900 (org-test-with-temp-text
901 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
902 (let ((org-property-format "%-10s %s")) (org-indent-line))
905 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
906 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
907 (let ((org-property-format "%-10s %s")) (org-indent-line))
910 (ert-deftest test-org
/indent-region
()
911 "Test `org-indent-region' specifications."
915 (org-test-with-temp-text " A\nB\n C"
916 (org-indent-region (point-min) (point-max))
918 ;; Indent greater elements along with their contents.
920 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
921 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
922 (org-indent-region (point-min) (point-max))
924 ;; Ignore contents of verse blocks. Only indent block delimiters.
926 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
927 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
928 (org-indent-region (point-min) (point-max))
931 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
932 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
933 (org-indent-region (point-min) (point-max))
935 ;; Indent example blocks as a single block, unless indentation
936 ;; should be preserved. In this case only indent the block markers.
938 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
939 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
940 (org-indent-region (point-min) (point-max))
943 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
944 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
945 (org-indent-region (point-min) (point-max))
948 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
949 (org-test-with-temp-text
950 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
951 (org-indent-region (point-min) (point-max))
954 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
955 (org-test-with-temp-text
956 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
957 (let ((org-src-preserve-indentation t
))
958 (org-indent-region (point-min) (point-max)))
960 ;; Treat export blocks as a whole.
962 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
963 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
964 (org-indent-region (point-min) (point-max))
967 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
968 (org-test-with-temp-text
969 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
970 (org-indent-region (point-min) (point-max))
972 ;; Indent according to mode if `org-src-tab-acts-natively' is
973 ;; non-nil. Otherwise, do not indent code at all.
975 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
976 (org-test-with-temp-text
977 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
978 (let ((org-src-tab-acts-natively t
)
979 (org-edit-src-content-indentation 0))
980 (org-indent-region (point-min) (point-max)))
983 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
984 (org-test-with-temp-text
985 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
986 (let ((org-src-tab-acts-natively nil
)
987 (org-edit-src-content-indentation 0))
988 (org-indent-region (point-min) (point-max)))
990 ;; Align node properties according to `org-property-format'. Handle
991 ;; nicely empty values.
993 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
994 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
995 (let ((org-property-format "%-10s %s")
996 (org-adapt-indentation nil
))
997 (org-indent-region (point) (point-max)))
1000 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
1001 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
1002 (let ((org-property-format "%-10s %s")
1003 (org-adapt-indentation nil
))
1004 (org-indent-region (point) (point-max)))
1006 ;; Indent plain lists.
1008 (equal "- A\n B\n - C\n\n D"
1009 (org-test-with-temp-text "- A\n B\n - C\n\n D"
1010 (org-indent-region (point-min) (point-max))
1014 (org-test-with-temp-text " - A\n\n - B"
1015 (org-indent-region (point-min) (point-max))
1017 ;; Indent footnote definitions.
1019 (equal "[fn:1] Definition\n\nDefinition"
1020 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
1021 (org-indent-region (point-min) (point-max))
1023 ;; Special case: Start indenting on a blank line.
1025 (equal "\nParagraph"
1026 (org-test-with-temp-text "\n Paragraph"
1027 (org-indent-region (point-min) (point-max))
1034 (ert-deftest test-org
/delete-indentation
()
1035 "Test `org-delete-indentation' specifications."
1037 (should (equal "foo bar"
1038 (org-test-with-temp-text
1040 (org-delete-indentation)
1042 ;; With optional argument.
1043 (should (equal "foo bar"
1044 (org-test-with-temp-text
1046 (org-delete-indentation t
)
1048 ;; At headline text should be appended to the headline text.
1050 (equal"* foo bar :tag:"
1051 (let (org-auto-align-tags)
1052 (org-test-with-temp-text
1053 "* foo :tag:\n bar<point>"
1054 (org-delete-indentation)
1057 (equal "* foo bar :tag:"
1058 (let (org-auto-align-tags)
1059 (org-test-with-temp-text
1060 "* foo <point>:tag:\n bar"
1061 (org-delete-indentation t
)
1062 (buffer-string))))))
1064 (ert-deftest test-org
/return
()
1065 "Test `org-return' specifications."
1068 (equal "Para\ngraph"
1069 (org-test-with-temp-text "Para<point>graph"
1072 ;; With optional argument, indent line.
1074 (equal " Para\n graph"
1075 (org-test-with-temp-text " Para<point>graph"
1078 ;; On a table, call `org-table-next-row'.
1080 (org-test-with-temp-text "| <point>a |\n| b |"
1082 (looking-at-p "b")))
1083 ;; Open link or timestamp under point when `org-return-follows-link'
1086 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1087 (let ((org-return-follows-link t
)
1088 (org-link-search-must-match-exact-headline nil
))
1090 (looking-at-p "<<target>>")))
1092 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1093 (let ((org-return-follows-link nil
)) (org-return))
1094 (looking-at-p "<<target>>")))
1096 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1097 (let ((org-return-follows-link t
)) (org-return))
1098 (looking-at-p "* b")))
1100 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1101 (let ((org-return-follows-link t
)
1102 (org-link-search-must-match-exact-headline nil
))
1104 (looking-at-p "<<target>>")))
1106 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1107 (let ((org-return-follows-link t
)
1108 (org-link-search-must-match-exact-headline nil
))
1110 (looking-at-p "<<target>>")))
1111 ;; When `org-return-follows-link' is non-nil, tolerate links and
1112 ;; timestamps in comments, node properties, etc.
1114 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1115 (let ((org-return-follows-link t
)
1116 (org-link-search-must-match-exact-headline nil
))
1118 (looking-at-p "<<target>>")))
1120 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1121 (let ((org-return-follows-link nil
)) (org-return))
1122 (looking-at-p "<<target>>")))
1124 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1125 (let ((org-return-follows-link t
)
1126 (org-link-search-must-match-exact-headline nil
))
1128 (looking-at-p "<<target>>")))
1129 ;; However, do not open link when point is in a table.
1131 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1132 (let ((org-return-follows-link t
)) (org-return))
1133 (looking-at-p "between")))
1134 ;; Special case: in a list, when indenting, do not break structure.
1137 (org-test-with-temp-text "- A <point>B"
1142 (org-test-with-temp-text "- A\n<point>- B"
1145 ;; On tags part of a headline, add a newline below it instead of
1148 (equal "* H :tag:\n"
1149 (org-test-with-temp-text "* H :<point>tag:"
1152 ;; Before headline text, add a newline below it instead of breaking
1155 (equal "* TODO H :tag:\n"
1156 (org-test-with-temp-text "* <point>TODO H :tag:"
1160 (equal "* TODO [#B] H :tag:\n"
1161 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1164 (should ;TODO are case-sensitive
1166 (org-test-with-temp-text "* <point>Todo"
1169 ;; At headline text, break headline text but preserve tags.
1171 (equal "* TODO [#B] foo :tag:\nbar"
1172 (let (org-auto-align-tags)
1173 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1176 ;; At bol of headline insert newline.
1179 (org-test-with-temp-text "<point>* h"
1182 ;; Refuse to leave invalid headline in buffer.
1185 (org-test-with-temp-text "*<point> h"
1189 (ert-deftest test-org
/meta-return
()
1190 "Test M-RET (`org-meta-return') specifications."
1191 ;; In a table field insert a row above.
1193 (org-test-with-temp-text "| a |"
1197 (looking-at "| |$")))
1198 ;; In a paragraph change current line into a header.
1200 (org-test-with-temp-text "a"
1203 (looking-at "\* a$")))
1204 ;; In an item insert an item, in this case above.
1206 (org-test-with-temp-text "- a"
1209 (looking-at "- $")))
1210 ;; In a drawer and item insert an item, in this case above.
1212 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1216 (looking-at "- $"))))
1218 (ert-deftest test-org
/insert-heading
()
1219 "Test `org-insert-heading' specifications."
1220 ;; In an empty buffer, insert a new headline.
1223 (org-test-with-temp-text ""
1224 (org-insert-heading)
1226 ;; At the beginning of a line, turn it into a headline.
1229 (org-test-with-temp-text "<point>P"
1230 (org-insert-heading)
1232 ;; In the middle of a line, split the line if allowed, otherwise,
1233 ;; insert the headline at its end.
1235 (equal "Para\n* graph"
1236 (org-test-with-temp-text "Para<point>graph"
1237 (let ((org-M-RET-may-split-line '((default . t
))))
1238 (org-insert-heading))
1241 (equal "Paragraph\n* "
1242 (org-test-with-temp-text "Para<point>graph"
1243 (let ((org-M-RET-may-split-line '((default . nil
))))
1244 (org-insert-heading))
1246 ;; At the beginning of a headline, create one above.
1249 (org-test-with-temp-text "* H"
1250 (org-insert-heading)
1252 ;; In the middle of a headline, split it if allowed.
1255 (org-test-with-temp-text "* H<point>1"
1256 (let ((org-M-RET-may-split-line '((headline . t
))))
1257 (org-insert-heading))
1261 (org-test-with-temp-text "* H<point>1"
1262 (let ((org-M-RET-may-split-line '((headline . nil
))))
1263 (org-insert-heading))
1265 ;; However, splitting cannot happen on TODO keywords, priorities or
1268 (equal "* TODO H1\n* \n"
1269 (org-test-with-temp-text "* TO<point>DO H1"
1270 (let ((org-M-RET-may-split-line '((headline . t
))))
1271 (org-insert-heading))
1274 (equal "* [#A] H1\n* \n"
1275 (org-test-with-temp-text "* [#<point>A] H1"
1276 (let ((org-M-RET-may-split-line '((headline . t
))))
1277 (org-insert-heading))
1280 (equal "* H1 :tag:\n* \n"
1281 (org-test-with-temp-text "* H1 :ta<point>g:"
1282 (let ((org-M-RET-may-split-line '((headline . t
))))
1283 (org-insert-heading))
1285 ;; New headline level depends on the level of the headline above.
1288 (org-test-with-temp-text "** H\n<point>P"
1289 (org-insert-heading)
1292 (equal "** H\nPara\n** graph"
1293 (org-test-with-temp-text "** H\nPara<point>graph"
1294 (let ((org-M-RET-may-split-line '((default . t
))))
1295 (org-insert-heading))
1299 (org-test-with-temp-text "** H"
1300 (org-insert-heading)
1302 ;; When called with one universal argument, insert a new headline at
1303 ;; the end of the current subtree, independently on the position of
1308 (org-test-with-temp-text "* H1\n** H2"
1309 (let ((org-insert-heading-respect-content nil
))
1310 (org-insert-heading '(4)))
1315 (org-test-with-temp-text "* H<point>1\n** H2"
1316 (let ((org-insert-heading-respect-content nil
))
1317 (org-insert-heading '(4)))
1319 ;; When called with two universal arguments, insert a new headline
1320 ;; at the end of the grandparent subtree.
1322 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1323 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1324 (let ((org-insert-heading-respect-content nil
))
1325 (org-insert-heading '(16)))
1327 ;; When optional TOP-LEVEL argument is non-nil, always insert
1328 ;; a level 1 heading.
1330 (equal "* H1\n** H2\n* \n"
1331 (org-test-with-temp-text "* H1\n** H2<point>"
1332 (org-insert-heading nil nil t
)
1335 (equal "* H1\n- item\n* "
1336 (org-test-with-temp-text "* H1\n- item<point>"
1337 (org-insert-heading nil nil t
)
1339 ;; Obey `org-blank-before-new-entry'.
1341 (equal "* H1\n\n* \n"
1342 (org-test-with-temp-text "* H1<point>"
1343 (let ((org-blank-before-new-entry '((heading . t
))))
1344 (org-insert-heading))
1348 (org-test-with-temp-text "* H1<point>"
1349 (let ((org-blank-before-new-entry '((heading . nil
))))
1350 (org-insert-heading))
1353 (equal "* H1\n* H2\n* \n"
1354 (org-test-with-temp-text "* H1\n* H2<point>"
1355 (let ((org-blank-before-new-entry '((heading . auto
))))
1356 (org-insert-heading))
1359 (equal "* H1\n\n* H2\n\n* \n"
1360 (org-test-with-temp-text "* H1\n\n* H2<point>"
1361 (let ((org-blank-before-new-entry '((heading . auto
))))
1362 (org-insert-heading))
1364 ;; Corner case: correctly insert a headline after an empty one.
1367 (org-test-with-temp-text "* <point>"
1368 (org-insert-heading)
1371 (org-test-with-temp-text "* <point>\n"
1372 (org-insert-heading)
1373 (looking-at-p "\n\\'")))
1374 ;; Do not insert spurious headlines when inserting a new headline.
1376 (equal "* H1\n* H2\n* \n"
1377 (org-test-with-temp-text "* H1\n* H2<point>\n"
1378 (org-insert-heading)
1380 ;; Preserve visibility at beginning of line. In particular, when
1381 ;; removing spurious blank lines, do not visually merge heading with
1382 ;; the line visible above.
1384 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1386 (let ((org-blank-before-new-entry '((heading . nil
))))
1387 (org-insert-heading '(4)))
1388 (invisible-p (line-end-position 0))))
1389 ;; Properly handle empty lines when forcing a headline below current
1392 (equal "* H1\n\n* H\n\n* \n"
1393 (org-test-with-temp-text "* H1\n\n* H<point>"
1394 (let ((org-blank-before-new-entry '((heading . t
))))
1395 (org-insert-heading '(4))
1396 (buffer-string))))))
1398 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1399 "Test `org-insert-todo-heading-respect-content' specifications."
1400 ;; Create a TODO heading.
1402 (org-test-with-temp-text "* H1\n Body"
1403 (org-insert-todo-heading-respect-content)
1404 (nth 2 (org-heading-components))))
1405 ;; Add headline at the end of the first subtree
1409 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1410 (org-insert-todo-heading-respect-content)
1411 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1412 ;; In a list, do not create a new item.
1416 (org-test-with-temp-text "* H\n- an item\n- another one"
1417 (search-forward "an ")
1418 (org-insert-todo-heading-respect-content)
1419 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1421 (ert-deftest test-org
/clone-with-time-shift
()
1422 "Test `org-clone-subtree-with-time-shift'."
1423 ;; Raise an error before first heading.
1425 (org-test-with-temp-text ""
1426 (org-clone-subtree-with-time-shift 1)))
1427 ;; Raise an error on invalid number of clones.
1429 (org-test-with-temp-text "* Clone me"
1430 (org-clone-subtree-with-time-shift -
1)))
1431 ;; Clone non-repeating once.
1437 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1438 (org-clone-subtree-with-time-shift 1 "+2d")
1439 (replace-regexp-in-string
1440 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1442 ;; Clone repeating once.
1447 * H1\n<2015-06-25 +1w>
1449 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1450 (org-clone-subtree-with-time-shift 1 "+2d")
1451 (replace-regexp-in-string
1452 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1454 ;; Clone non-repeating zero times.
1459 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1460 (org-clone-subtree-with-time-shift 0 "+2d")
1461 (replace-regexp-in-string
1462 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1464 ;; Clone repeating "zero" times.
1468 * H1\n<2015-06-23 +1w>
1470 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1471 (org-clone-subtree-with-time-shift 0 "+2d")
1472 (replace-regexp-in-string
1473 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1475 ;; Clone with blank SHIFT argument.
1479 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1480 (org-clone-subtree-with-time-shift 1 "")
1481 (buffer-substring-no-properties (line-beginning-position 2)
1482 (line-end-position 2)))))
1483 ;; Find time stamps before point. If SHIFT is not specified, ask
1484 ;; for a time shift.
1488 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1489 (org-clone-subtree-with-time-shift 1 "+1d")
1490 (buffer-substring-no-properties (line-beginning-position 2)
1491 (line-end-position 2)))))
1495 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1496 (cl-letf (((symbol-function 'read-from-minibuffer
)
1497 (lambda (&rest args
) "+1d")))
1498 (org-clone-subtree-with-time-shift 1))
1499 (buffer-substring-no-properties (line-beginning-position 2)
1500 (line-end-position 2))))))
1503 ;;; Fixed-Width Areas
1505 (ert-deftest test-org
/toggle-fixed-width
()
1506 "Test `org-toggle-fixed-width' specifications."
1507 ;; No region: Toggle on fixed-width marker in paragraphs.
1510 (org-test-with-temp-text "A"
1511 (org-toggle-fixed-width)
1513 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1516 (org-test-with-temp-text ": A"
1517 (org-toggle-fixed-width)
1519 ;; No region: Toggle on marker in blank lines after elements or just
1520 ;; after a headline.
1523 (org-test-with-temp-text "* H\n"
1525 (org-toggle-fixed-width)
1528 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1529 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1530 (goto-char (point-max))
1531 (org-toggle-fixed-width)
1533 ;; No region: Toggle on marker in front of one line elements (e.g.,
1534 ;; headlines, clocks)
1536 (equal ": * Headline"
1537 (org-test-with-temp-text "* Headline"
1538 (org-toggle-fixed-width)
1541 (equal ": #+KEYWORD: value"
1542 (org-test-with-temp-text "#+KEYWORD: value"
1543 (org-toggle-fixed-width)
1545 ;; No region: error in other situations.
1547 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1549 (org-toggle-fixed-width)
1551 ;; No region: Indentation is preserved.
1554 (org-test-with-temp-text "- A\n B"
1556 (org-toggle-fixed-width)
1558 ;; Region: If it contains only fixed-width elements and blank lines,
1559 ;; toggle off fixed-width markup.
1562 (org-test-with-temp-text ": A\n\n: B"
1563 (transient-mark-mode 1)
1564 (push-mark (point) t t
)
1565 (goto-char (point-max))
1566 (org-toggle-fixed-width)
1568 ;; Region: If it contains anything else, toggle on fixed-width but
1569 ;; not on fixed-width areas.
1571 (equal ": A\n: \n: B\n: \n: C"
1572 (org-test-with-temp-text "A\n\n: B\n\nC"
1573 (transient-mark-mode 1)
1574 (push-mark (point) t t
)
1575 (goto-char (point-max))
1576 (org-toggle-fixed-width)
1578 ;; Region: Ignore blank lines at its end, unless it contains only
1582 (org-test-with-temp-text "A\n\n"
1583 (transient-mark-mode 1)
1584 (push-mark (point) t t
)
1585 (goto-char (point-max))
1586 (org-toggle-fixed-width)
1590 (org-test-with-temp-text "\n\n"
1591 (transient-mark-mode 1)
1592 (push-mark (point) t t
)
1593 (goto-char (point-max))
1594 (org-toggle-fixed-width)
1601 (ert-deftest test-org
/get-heading
()
1602 "Test `org-get-heading' specifications."
1603 ;; Return current heading, even if point is not on it.
1606 (org-test-with-temp-text "* H"
1607 (org-get-heading))))
1610 (org-test-with-temp-text "* H\nText<point>"
1611 (org-get-heading))))
1612 ;; Without any optional argument, return TODO keyword, priority
1613 ;; cookie, COMMENT keyword and tags.
1616 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1617 (org-get-heading))))
1620 (org-test-with-temp-text "* [#A] H"
1621 (org-get-heading))))
1624 (org-test-with-temp-text "* COMMENT H"
1625 (org-get-heading))))
1628 (org-test-with-temp-text "* H :tag:"
1629 (org-get-heading))))
1630 ;; With NO-TAGS argument, ignore tags.
1633 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1634 (org-get-heading t
))))
1637 (org-test-with-temp-text "* H :tag:"
1638 (org-get-heading t
))))
1639 ;; With NO-TODO, ignore TODO keyword.
1642 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1643 (org-get-heading nil t
))))
1646 (org-test-with-temp-text "* H :tag:"
1647 (org-get-heading nil t
))))
1648 ;; TODO keywords are case-sensitive.
1651 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1652 (org-get-heading nil t
))))
1653 ;; With NO-PRIORITY, ignore priority.
1656 (org-test-with-temp-text "* [#A] H"
1657 (org-get-heading nil nil t
))))
1660 (org-test-with-temp-text "* H"
1661 (org-get-heading nil nil t
))))
1664 (org-test-with-temp-text "* TODO [#A] H"
1665 (org-get-heading nil nil t
))))
1666 ;; With NO-COMMENT, ignore COMMENT keyword.
1669 (org-test-with-temp-text "* COMMENT H"
1670 (org-get-heading nil nil nil t
))))
1673 (org-test-with-temp-text "* H"
1674 (org-get-heading nil nil nil t
))))
1676 (equal "TODO [#A] H"
1677 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1678 (org-get-heading nil nil nil t
))))
1679 ;; On an empty headline, return value is consistent.
1680 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1681 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1682 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1683 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1685 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1687 (ert-deftest test-org
/in-commented-heading-p
()
1688 "Test `org-in-commented-heading-p' specifications."
1689 ;; Commented headline.
1691 (org-test-with-temp-text "* COMMENT Headline\nBody"
1692 (goto-char (point-max))
1693 (org-in-commented-heading-p)))
1694 ;; Commented ancestor.
1696 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1697 (goto-char (point-max))
1698 (org-in-commented-heading-p)))
1699 ;; Comment keyword is case-sensitive.
1701 (org-test-with-temp-text "* Comment Headline\nBody"
1702 (goto-char (point-max))
1703 (org-in-commented-heading-p)))
1704 ;; Keyword is standalone.
1706 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1707 (goto-char (point-max))
1708 (org-in-commented-heading-p)))
1709 ;; Optional argument.
1711 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1712 (goto-char (point-max))
1713 (org-in-commented-heading-p t
))))
1715 (ert-deftest test-org
/entry-blocked-p
()
1716 ;; Check other dependencies.
1718 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1719 (let ((org-enforce-todo-dependencies t
)
1721 '(org-block-todo-from-children-or-siblings-or-parent)))
1722 (org-entry-blocked-p))))
1724 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1725 (let ((org-enforce-todo-dependencies t
)
1727 '(org-block-todo-from-children-or-siblings-or-parent)))
1728 (org-entry-blocked-p))))
1729 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1732 (org-test-with-temp-text "* Blocked\n** TODO one"
1733 (let ((org-enforce-todo-dependencies t
)
1735 '(org-block-todo-from-children-or-siblings-or-parent)))
1736 (org-entry-blocked-p))))
1738 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1739 (let ((org-enforce-todo-dependencies t
)
1741 '(org-block-todo-from-children-or-siblings-or-parent)))
1742 (org-entry-blocked-p))))
1743 ;; Follow :ORDERED: specifications.
1745 (org-test-with-temp-text
1746 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1747 (let ((org-enforce-todo-dependencies t
)
1749 '(org-block-todo-from-children-or-siblings-or-parent)))
1750 (org-entry-blocked-p))))
1752 (org-test-with-temp-text
1753 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1754 (let ((org-enforce-todo-dependencies t
)
1756 '(org-block-todo-from-children-or-siblings-or-parent)))
1757 (org-entry-blocked-p)))))
1759 (ert-deftest test-org
/get-outline-path
()
1760 "Test `org-get-outline-path' specifications."
1761 ;; Top-level headlines have no outline path.
1763 (org-test-with-temp-text "* H"
1764 (org-get-outline-path)))
1765 ;; Otherwise, outline path is the path leading to the headline.
1768 (org-test-with-temp-text "* H\n** S<point>"
1769 (org-get-outline-path))))
1770 ;; Find path even when point is not on a headline.
1773 (org-test-with-temp-text "* H\n** S\nText<point>"
1774 (org-get-outline-path))))
1775 ;; TODO keywords, tags and statistics cookies are ignored.
1778 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1779 (org-get-outline-path))))
1780 ;; Links are replaced with their description or their path.
1783 (org-test-with-temp-text
1784 "* [[http://orgmode.org][Org]]\n** S<point>"
1785 (org-get-outline-path))))
1787 (equal '("http://orgmode.org")
1788 (org-test-with-temp-text
1789 "* [[http://orgmode.org]]\n** S<point>"
1790 (org-get-outline-path))))
1791 ;; When WITH-SELF is non-nil, include current heading.
1794 (org-test-with-temp-text "* H"
1795 (org-get-outline-path t
))))
1798 (org-test-with-temp-text "* H\n** S\nText<point>"
1799 (org-get-outline-path t
))))
1800 ;; Using cache is transparent to the user.
1803 (org-test-with-temp-text "* H\n** S<point>"
1804 (setq org-outline-path-cache nil
)
1805 (org-get-outline-path nil t
))))
1806 ;; Do not corrupt cache when finding outline path in distant part of
1810 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1811 (setq org-outline-path-cache nil
)
1812 (org-get-outline-path nil t
)
1813 (search-forward "S2")
1814 (org-get-outline-path nil t
))))
1815 ;; Do not choke on empty headlines.
1817 (org-test-with-temp-text "* H\n** <point>"
1818 (org-get-outline-path)))
1820 (org-test-with-temp-text "* \n** H<point>"
1821 (org-get-outline-path))))
1823 (ert-deftest test-org
/format-outline-path
()
1824 "Test `org-format-outline-path' specifications."
1826 (string= (org-format-outline-path (list "one" "two" "three"))
1830 (string= (org-format-outline-path '())
1833 (string= (org-format-outline-path '(nil))
1835 ;; Empty path and prefix.
1837 (string= (org-format-outline-path '() nil
">>")
1839 ;; Trailing whitespace in headings.
1841 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1843 ;; Non-default prefix and separators.
1845 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1846 ">>|one|two|three"))
1849 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1851 ;; Give a very narrow width.
1853 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1855 ;; Give a prefix that extends beyond the width.
1857 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1861 (ert-deftest test-org
/map-entries
()
1862 "Test `org-map-entries' specifications."
1866 (org-test-with-temp-text "* Level 1\n** Level 2"
1867 (org-map-entries #'point
))))
1871 (org-test-with-temp-text "* Level 1\n** Level 2"
1872 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1875 (org-test-with-temp-text "* Level 1\n** Level 2"
1876 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1880 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1881 (org-map-entries #'point
"yes"))))
1884 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1885 (org-map-entries #'point
"+yes-a"))))
1888 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1889 (org-map-entries #'point
"{yes?}"))))
1893 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1894 (org-map-entries #'point
"PRIORITY=\"A\""))))
1898 (org-test-with-temp-text "
1900 SCHEDULED: <2012-03-29 thu.>
1902 SCHEDULED: <2014-03-04 tue.>"
1903 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1906 (org-test-with-temp-text "
1908 SCHEDULED: <2012-03-29 thu.>
1910 SCHEDULED: <2014-03-04 tue.>"
1911 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1912 ;; Regular property match.
1915 (org-test-with-temp-text "
1924 (org-map-entries #'point
"TEST=1"))))
1925 ;; Multiple criteria.
1928 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1929 (let (org-odd-levels-only
1930 (org-use-tag-inheritance nil
))
1931 (org-map-entries #'point
"yes+LEVEL=1")))))
1935 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1936 (let (org-odd-levels-only)
1937 (org-map-entries #'point
"LEVEL=2|no")))))
1940 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1941 (let (org-odd-levels-only)
1942 (org-map-entries #'point
"yes|no")))))
1946 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1947 (let (org-odd-levels-only)
1948 (org-map-entries #'point
"yes&no"))))))
1950 (ert-deftest test-org
/edit-headline
()
1951 "Test `org-edit-headline' specifications."
1954 (org-test-with-temp-text "* A"
1955 (org-edit-headline "B")
1957 ;; Handle empty headings.
1960 (org-test-with-temp-text "* A"
1961 (org-edit-headline "")
1965 (org-test-with-temp-text "* "
1966 (org-edit-headline "A")
1968 ;; Handle TODO keywords and priority cookies.
1971 (org-test-with-temp-text "* TODO A"
1972 (org-edit-headline "B")
1976 (org-test-with-temp-text "* [#A] A"
1977 (org-edit-headline "B")
1980 (equal "* TODO [#A] B"
1981 (org-test-with-temp-text "* TODO [#A] A"
1982 (org-edit-headline "B")
1986 (org-test-with-temp-text "* A :tag:"
1987 (let ((org-tags-column 4)) (org-edit-headline "B"))
1994 (ert-deftest test-org
/set-regexps-and-options
()
1995 "Test `org-set-regexps-and-options' specifications."
1999 (let ((org-tag-alist '(("A")))
2000 (org-tag-persistent-alist nil
))
2001 (org-test-with-temp-text ""
2003 org-current-tag-alist
))))
2006 (let ((org-tag-alist '(("A")))
2007 (org-tag-persistent-alist nil
))
2008 (org-test-with-temp-text "#+TAGS: B"
2010 org-current-tag-alist
))))
2012 (equal '(("C") ("B"))
2013 (let ((org-tag-alist '(("A")))
2014 (org-tag-persistent-alist '(("C"))))
2015 (org-test-with-temp-text "#+TAGS: B"
2017 org-current-tag-alist
))))
2020 (let ((org-tag-alist '(("A")))
2021 (org-tag-persistent-alist '(("C"))))
2022 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
2024 org-current-tag-alist
))))
2026 (equal '(("A" . ?a
) ("B") ("C"))
2027 (let ((org-tag-persistant-alist nil
))
2028 (org-test-with-temp-text "#+TAGS: A(a) B C"
2030 org-current-tag-alist
))))
2032 (equal '(("A") (:newline
) ("B"))
2033 (let ((org-tag-persistent-alist nil
))
2034 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2036 org-current-tag-alist
))))
2038 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2039 (let ((org-tag-persistent-alist nil
))
2040 (org-test-with-temp-text "#+TAGS: { A B } C"
2042 org-current-tag-alist
))))
2044 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2045 (let ((org-tag-persistent-alist nil
))
2046 (org-test-with-temp-text "#+TAGS: { A : B C }"
2048 org-current-tag-alist
))))
2050 (equal '(("A" "B" "C"))
2051 (let ((org-tag-persistent-alist nil
))
2052 (org-test-with-temp-text "#+TAGS: { A : B C }"
2054 org-tag-groups-alist
))))
2056 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2057 (let ((org-tag-persistent-alist nil
))
2058 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2060 org-current-tag-alist
))))
2062 (equal '(("A" "B" "C"))
2063 (let ((org-tag-persistent-alist nil
))
2064 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2066 org-tag-groups-alist
))))
2067 ;; FILETAGS keyword.
2069 (equal '("A" "B" "C")
2070 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2073 ;; PROPERTY keyword. Property names are case-insensitive.
2076 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2078 (cdr (assoc "var" org-file-properties
)))))
2082 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2084 (cdr (assoc "var" org-file-properties
)))))
2088 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2090 (cdr (assoc "var" org-file-properties
)))))
2094 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2096 org-archive-location
)))
2097 ;; CATEGORY keyword.
2100 (org-test-with-temp-text "#+CATEGORY: test"
2105 (org-test-with-temp-text "#+CATEGORY: test"
2107 (cdr (assoc "CATEGORY" org-file-properties
)))))
2110 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2111 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2113 org-columns-default-format
)))
2114 ;; CONSTANTS keyword. Constants names are case sensitive.
2116 (equal '("299792458." "3.14")
2117 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2120 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2124 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2126 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2129 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2131 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2136 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2138 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2140 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2144 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2146 (list org-highest-priority org-lowest-priority org-default-priority
))))
2150 (org-test-with-temp-text "#+PRIORITIES: X Z"
2152 (list org-highest-priority org-lowest-priority org-default-priority
))))
2156 (org-test-with-temp-text "#+STARTUP: fold odd"
2158 (list org-startup-folded org-odd-levels-only
))))
2161 (equal '(("A" "B") ("C"))
2162 (org-test-with-temp-text "#+TODO: A B | C"
2164 (list org-not-done-keywords org-done-keywords
))))
2166 (equal '(("A" "C") ("B" "D"))
2167 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2169 (list org-not-done-keywords org-done-keywords
))))
2171 (equal '(("A" "B") ("C"))
2172 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2174 (list org-not-done-keywords org-done-keywords
))))
2176 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2177 (org-test-with-temp-text "#+TODO: A(a)"
2179 org-todo-key-alist
)))
2181 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2182 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2184 org-todo-log-states
)))
2185 ;; Enter SETUPFILE keyword.
2188 (org-test-with-temp-text
2189 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2191 (cdr (assoc "a" org-file-properties
))))))
2199 (ert-deftest test-org
/coderef
()
2200 "Test coderef links specifications."
2202 (org-test-with-temp-text "
2203 #+BEGIN_SRC emacs-lisp
2208 (looking-at "(ref:sc)")))
2209 ;; Find coderef even with alternate label format.
2211 (org-test-with-temp-text "
2212 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2217 (looking-at "{ref:sc}"))))
2221 (ert-deftest test-org
/custom-id
()
2222 "Test custom ID links specifications."
2224 (org-test-with-temp-text
2225 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2227 (looking-at-p "\\* H1")))
2228 ;; Throw an error on false positives.
2230 (org-test-with-temp-text
2231 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2233 (looking-at-p "\\* H1"))))
2237 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2238 ;; a named element (#+name: text) and to headlines (* Text).
2240 (ert-deftest test-org
/fuzzy-links
()
2241 "Test fuzzy links specifications."
2242 ;; Fuzzy link goes in priority to a matching target.
2244 (org-test-with-temp-text
2245 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2246 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2247 (looking-at "<<Test>>")))
2248 ;; Then fuzzy link points to an element with a given name.
2250 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2251 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2252 (looking-at "#\\+NAME: Test")))
2253 ;; A target still lead to a matching headline otherwise.
2255 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2256 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2257 (looking-at "\\* Head2")))
2258 ;; With a leading star in link, enforce heading match.
2260 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2261 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2262 (looking-at "\\* Test")))
2263 ;; With a leading star in link, enforce exact heading match, even
2264 ;; with `org-link-search-must-match-exact-headline' set to nil.
2266 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2267 (let ((org-link-search-must-match-exact-headline nil
))
2268 (org-open-at-point))))
2269 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2271 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2272 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2273 (looking-at "\\* Test")))
2275 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2276 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2277 (looking-at "\\* Test")))
2278 ;; Heading match should not care about spaces, cookies, TODO
2279 ;; keywords, priorities, and tags. However, TODO keywords are
2283 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2284 (org-test-with-temp-text
2285 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2286 (let ((org-link-search-must-match-exact-headline nil
)
2287 (org-todo-regexp "TODO"))
2288 (org-open-at-point))
2289 (looking-at (regexp-quote first-line
)))))
2291 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2292 (let ((org-link-search-must-match-exact-headline nil
)
2293 (org-todo-regexp "TODO"))
2294 (org-open-at-point))))
2295 ;; Heading match should still be exact.
2297 (org-test-with-temp-text "
2298 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2301 (let ((org-link-search-must-match-exact-headline nil
)
2302 (org-todo-regexp "TODO"))
2303 (org-open-at-point))))
2305 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2306 (let ((org-link-search-must-match-exact-headline nil
)
2307 (org-todo-regexp "TODO"))
2308 (org-open-at-point))
2309 (looking-at-p (regexp-quote "** Test 1 2"))))
2310 ;; Heading match ignores COMMENT keyword.
2312 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2314 (looking-at "\\* COMMENT Test")))
2316 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2318 (looking-at "\\* TODO COMMENT Test")))
2319 ;; Correctly un-hexify fuzzy links.
2321 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2325 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2328 ;; Match search strings containing newline characters, including
2331 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2332 (let ((file (buffer-file-name)))
2333 (goto-char (point-max))
2334 (insert (format "[[file:%s::line1 line2]]" file
))
2336 (let ((org-link-search-must-match-exact-headline nil
))
2337 (org-open-at-point 0))
2338 (looking-at-p "line1"))))
2340 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2341 (let ((file (buffer-file-name)))
2342 (goto-char (point-max))
2343 (insert (format "[[file:%s::line1 line2]]" file
))
2345 (let ((org-link-search-must-match-exact-headline nil
))
2346 (org-open-at-point 0))
2347 (looking-at-p "line1")))))
2351 (ert-deftest test-org
/org-link-escape-ascii-character
()
2352 "Escape an ascii character."
2356 (org-link-escape "["))))
2358 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2359 "Escape an ascii control character."
2363 (org-link-escape "\t"))))
2365 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2366 "Escape an unicode multibyte character."
2370 (org-link-escape "€"))))
2372 (ert-deftest test-org
/org-link-escape-custom-table
()
2373 "Escape string with custom character table."
2377 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2379 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2380 "Escape string with custom table merged with default table."
2383 "%5BF%6F%6F%3A%42ar%0A%5D"
2384 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2386 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2387 "Unescape an ascii character."
2391 (org-link-unescape "%5B"))))
2393 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2394 "Unescpae an ascii control character."
2398 (org-link-unescape "%0A"))))
2400 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2401 "Unescape unicode multibyte character."
2405 (org-link-unescape "%E2%82%AC"))))
2407 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2408 "Unescape old style percent escaped character."
2411 "à âçèéêîôùû"
2412 (decode-coding-string
2413 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2415 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2416 "Escape and unescape a URL that includes an escaped char.
2417 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2420 "http://some.host.com/form?&id=blah%2Bblah25"
2422 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2426 (ert-deftest test-org
/open-at-point
/keyword
()
2427 "Does `org-open-at-point' open link in a keyword line?"
2429 (org-test-with-temp-text
2430 "<<top>>\n#+KEYWORD: <point>[[top]]"
2431 (org-open-at-point) t
))
2433 (org-test-with-temp-text
2434 "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
2435 (org-open-at-point) t
)))
2437 (ert-deftest test-org
/open-at-point
/property
()
2438 "Does `org-open-at-point' open link in property drawer?"
2440 (org-test-with-temp-text
2443 :URL: <point>[[*Headline]]
2445 (org-open-at-point) t
)))
2447 (ert-deftest test-org
/open-at-point
/comment
()
2448 "Does `org-open-at-point' open link in a commented line?"
2450 (org-test-with-temp-text
2451 "<<top>>\n# <point>[[top]]"
2452 (org-open-at-point) t
))
2454 (org-test-with-temp-text
2455 "* H\n<<top>>\n# <point>[[top]]"
2456 (org-open-at-point) t
)))
2458 (ert-deftest test-org
/open-at-point
/inline-image
()
2459 "Test `org-open-at-point' on nested links."
2461 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2465 (ert-deftest test-org
/open-at-point
/radio-target
()
2466 "Test `org-open-at-point' on radio targets."
2468 (org-test-with-temp-text "<<<target>>> <point>target"
2469 (org-update-radio-target-regexp)
2471 (eq (org-element-type (org-element-context)) 'radio-target
))))
2473 (ert-deftest test-org
/open-at-point
/tag
()
2474 "Test `org-open-at-point' on tags."
2476 (org-test-with-temp-text "* H :<point>tag:"
2478 (cl-letf (((symbol-function 'org-tags-view
)
2479 (lambda (&rest args
) (throw :result t
))))
2483 (org-test-with-temp-text-in-file "* H<point> :tag:"
2485 (cl-letf (((symbol-function 'org-tags-view
)
2486 (lambda (&rest args
) (throw :result t
))))
2492 (ert-deftest test-org
/store-link
()
2493 "Test `org-store-link' specifications."
2494 ;; On a headline, link to that headline. Use heading as the
2495 ;; description of the link.
2497 (let (org-store-link-props org-stored-links
)
2498 (org-test-with-temp-text-in-file "* H1"
2499 (let ((file (buffer-file-name)))
2500 (equal (format "[[file:%s::*H1][H1]]" file
)
2501 (org-store-link nil
))))))
2502 ;; On a headline, remove any link from description.
2504 (let (org-store-link-props org-stored-links
)
2505 (org-test-with-temp-text-in-file "* [[#l][d]]"
2506 (let ((file (buffer-file-name)))
2507 (equal (format "[[file:%s::*%s][d]]"
2509 (org-link-escape "[[#l][d]]"))
2510 (org-store-link nil
))))))
2512 (let (org-store-link-props org-stored-links
)
2513 (org-test-with-temp-text-in-file "* [[l]]"
2514 (let ((file (buffer-file-name)))
2515 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2516 (org-store-link nil
))))))
2518 (let (org-store-link-props org-stored-links
)
2519 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2520 (let ((file (buffer-file-name)))
2521 (equal (format "[[file:%s::*%s][d1 d2]]"
2523 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2524 (org-store-link nil
))))))
2525 ;; On a named element, link to that element.
2527 (let (org-store-link-props org-stored-links
)
2528 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2529 (let ((file (buffer-file-name)))
2530 (equal (format "[[file:%s::foo][foo]]" file
)
2531 (org-store-link nil
))))))
2532 ;; Store link to Org buffer, with context.
2534 (let ((org-stored-links nil
)
2535 (org-id-link-to-org-use-id nil
)
2536 (org-context-in-file-links t
))
2537 (org-test-with-temp-text-in-file "* h1"
2538 (let ((file (buffer-file-name)))
2539 (equal (format "[[file:%s::*h1][h1]]" file
)
2540 (org-store-link nil
))))))
2541 ;; Store link to Org buffer, without context.
2543 (let ((org-stored-links nil
)
2544 (org-id-link-to-org-use-id nil
)
2545 (org-context-in-file-links nil
))
2546 (org-test-with-temp-text-in-file "* h1"
2547 (let ((file (buffer-file-name)))
2548 (equal (format "[[file:%s][file:%s]]" file file
)
2549 (org-store-link nil
))))))
2550 ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
2552 (let ((org-stored-links nil
)
2553 (org-id-link-to-org-use-id nil
)
2554 (org-context-in-file-links nil
))
2555 (org-test-with-temp-text-in-file "* h1"
2556 (let ((file (buffer-file-name)))
2557 (equal (format "[[file:%s::*h1][h1]]" file
)
2558 (org-store-link '(4)))))))
2559 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
2562 (let ((org-stored-links nil
)
2563 (org-id-link-to-org-use-id nil
)
2564 (org-context-in-file-links nil
))
2565 (org-test-with-temp-text-in-file "* h1"
2566 (let ((file (buffer-file-name)))
2567 (equal (format "[[file:%s][file:%s]]" file file
)
2568 (org-store-link '(16)))))))
2569 ;; Store file link to non-Org buffer, with context.
2571 (let ((org-stored-links nil
)
2572 (org-context-in-file-links t
))
2573 (org-test-with-temp-text-in-file "one\n<point>two"
2575 (let ((file (buffer-file-name)))
2576 (equal (format "[[file:%s::one]]" file
)
2577 (org-store-link nil
))))))
2578 ;; Store file link to non-Org buffer, without context.
2580 (let ((org-stored-links nil
)
2581 (org-context-in-file-links nil
))
2582 (org-test-with-temp-text-in-file "one\n<point>two"
2584 (let ((file (buffer-file-name)))
2585 (equal (format "[[file:%s][file:%s]]" file file
)
2586 (org-store-link nil
))))))
2587 ;; C-u prefix reverses `org-context-in-file-links' in non-Org
2590 (let ((org-stored-links nil
)
2591 (org-context-in-file-links nil
))
2592 (org-test-with-temp-text-in-file "one\n<point>two"
2594 (let ((file (buffer-file-name)))
2595 (equal (format "[[file:%s::one]]" file
)
2596 (org-store-link '(4)))))))
2597 ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
2600 (let ((org-stored-links nil
)
2601 (org-context-in-file-links nil
))
2602 (org-test-with-temp-text-in-file "one\n<point>two"
2604 (let ((file (buffer-file-name)))
2605 (equal (format "[[file:%s][file:%s]]" file file
)
2606 (org-store-link '(16))))))))
2611 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2612 "Ensure properties accumulate in subtree drawers."
2613 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2614 (org-babel-next-src-block)
2615 (should (equal '(2 1) (org-babel-execute-src-block)))))
2617 (ert-deftest test-org
/custom-properties
()
2618 "Test custom properties specifications."
2621 (let ((org-custom-properties '("FOO")))
2622 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2623 (org-toggle-custom-properties-visibility)
2624 (org-invisible-p2))))
2625 ;; Properties are case-insensitive.
2627 (let ((org-custom-properties '("FOO")))
2628 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2629 (org-toggle-custom-properties-visibility)
2630 (org-invisible-p2))))
2632 (let ((org-custom-properties '("foo")))
2633 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2634 (org-toggle-custom-properties-visibility)
2635 (org-invisible-p2))))
2636 ;; Multiple custom properties in the same drawer.
2638 (let ((org-custom-properties '("FOO" "BAR")))
2639 (org-test-with-temp-text
2640 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2641 (org-toggle-custom-properties-visibility)
2642 (and (org-invisible-p2)
2643 (not (progn (forward-line) (org-invisible-p2)))
2644 (progn (forward-line) (org-invisible-p2))))))
2645 ;; Hide custom properties with an empty value.
2647 (let ((org-custom-properties '("FOO")))
2648 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2649 (org-toggle-custom-properties-visibility)
2650 (org-invisible-p2))))
2651 ;; Do not hide fake properties.
2653 (let ((org-custom-properties '("FOO")))
2654 (org-test-with-temp-text ":FOO: val\n"
2655 (org-toggle-custom-properties-visibility)
2656 (org-invisible-p2))))
2658 (let ((org-custom-properties '("A")))
2659 (org-test-with-temp-text
2660 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2661 (org-toggle-custom-properties-visibility)
2662 (org-invisible-p2)))))
2668 (ert-deftest test-org
/mark-subtree
()
2669 "Test `org-mark-subtree' specifications."
2670 ;; Error when point is before first headline.
2672 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2673 (progn (transient-mark-mode 1)
2674 (org-mark-subtree))))
2675 ;; Without argument, mark current subtree.
2679 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2680 (progn (transient-mark-mode 1)
2683 (list (region-beginning) (region-end))))))
2684 ;; With an argument, move ARG up.
2688 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2689 (progn (transient-mark-mode 1)
2691 (org-mark-subtree 1)
2692 (list (region-beginning) (region-end))))))
2693 ;; Do not get fooled by inlinetasks.
2694 (when (featurep 'org-inlinetask
)
2697 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2698 (progn (transient-mark-mode 1)
2700 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2701 (region-beginning)))))))
2707 (ert-deftest test-org
/in-regexp
()
2708 "Test `org-in-regexp' specifications."
2711 (org-test-with-temp-text "xx ab<point>c xx"
2712 (org-in-regexp "abc")))
2714 (org-test-with-temp-text "xx abc <point>xx"
2715 (org-in-regexp "abc")))
2716 ;; Return non-nil even with multiple matching regexps in the same
2719 (org-test-with-temp-text "abc xx ab<point>c xx"
2720 (org-in-regexp "abc")))
2721 ;; With optional argument NLINES, check extra lines around point.
2723 (org-test-with-temp-text "A\nB<point>\nC"
2724 (org-in-regexp "A\nB\nC")))
2726 (org-test-with-temp-text "A\nB<point>\nC"
2727 (org-in-regexp "A\nB\nC" 1)))
2729 (org-test-with-temp-text "A\nB\nC<point>"
2730 (org-in-regexp "A\nB\nC" 1)))
2731 ;; When optional argument VISUALLY is non-nil, return nil if at
2732 ;; regexp boundaries.
2734 (org-test-with-temp-text "xx abc<point> xx"
2735 (org-in-regexp "abc")))
2737 (org-test-with-temp-text "xx abc<point> xx"
2738 (org-in-regexp "abc" nil t
))))
2740 (ert-deftest test-org
/sort-entries
()
2741 "Test `org-sort-entries'."
2742 ;; Sort alphabetically.
2744 (equal "\n* abc\n* def\n* xyz\n"
2745 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2746 (org-sort-entries nil ?a
)
2749 (equal "\n* xyz\n* def\n* abc\n"
2750 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2751 (org-sort-entries nil ?A
)
2753 ;; Sort numerically.
2755 (equal "\n* 1\n* 2\n* 10\n"
2756 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2757 (org-sort-entries nil ?n
)
2760 (equal "\n* 10\n* 2\n* 1\n"
2761 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2762 (org-sort-entries nil ?N
)
2764 ;; Sort by custom function.
2766 (equal "\n* b\n* aa\n* ccc\n"
2767 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2768 (org-sort-entries nil ?f
2770 (length (buffer-substring (point-at-bol)
2775 (equal "\n* ccc\n* aa\n* b\n"
2776 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2777 (org-sort-entries nil ?F
2779 (length (buffer-substring (point-at-bol)
2783 ;; Sort by TODO keyword.
2785 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2786 (org-test-with-temp-text
2787 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2788 (org-sort-entries nil ?o
)
2791 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2792 (org-test-with-temp-text
2793 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2794 (org-sort-entries nil ?O
)
2796 ;; Sort by priority.
2798 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2799 (org-test-with-temp-text
2800 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2801 (org-sort-entries nil ?p
)
2804 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2805 (org-test-with-temp-text
2806 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2807 (org-sort-entries nil ?P
)
2809 ;; Sort by creation time.
2819 (org-test-with-temp-text
2828 (org-sort-entries nil ?c
)
2831 ;; Sort by scheduled date.
2835 SCHEDULED: <2017-05-06 Sat>
2837 SCHEDULED: <2017-05-08 Mon>
2839 DEADLINE: <2017-05-09 Tue>
2841 DEADLINE: <2017-05-07 Sun>
2843 (org-test-with-temp-text
2846 DEADLINE: <2017-05-09 Tue>
2848 DEADLINE: <2017-05-07 Sun>
2850 SCHEDULED: <2017-05-08 Mon>
2852 SCHEDULED: <2017-05-06 Sat>
2854 (org-sort-entries nil ?s
)
2856 ;; Sort by deadline date.
2860 DEADLINE: <2017-05-07 Sun>
2862 DEADLINE: <2017-05-09 Tue>
2864 SCHEDULED: <2017-05-08 Mon>
2866 SCHEDULED: <2017-05-06 Sat>
2868 (org-test-with-temp-text
2871 DEADLINE: <2017-05-09 Tue>
2873 DEADLINE: <2017-05-07 Sun>
2875 SCHEDULED: <2017-05-08 Mon>
2877 SCHEDULED: <2017-05-06 Sat>
2879 (org-sort-entries nil ?d
)
2881 ;; Sort by any date/time
2885 SCHEDULED: <2017-05-06 Sat>
2887 DEADLINE: <2017-05-07 Sun>
2889 SCHEDULED: <2017-05-08 Mon>
2891 DEADLINE: <2017-05-09 Tue>
2893 (org-test-with-temp-text
2896 DEADLINE: <2017-05-09 Tue>
2898 DEADLINE: <2017-05-07 Sun>
2900 SCHEDULED: <2017-05-08 Mon>
2902 SCHEDULED: <2017-05-06 Sat>
2904 (org-sort-entries nil ?t
)
2906 ;; Sort by clocking time.
2911 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2912 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2916 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2917 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2920 (org-test-with-temp-text
2924 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2925 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2929 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2930 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2933 (org-sort-entries nil ?k
)
2936 (ert-deftest test-org
/file-contents
()
2937 "Test `org-file-contents' specifications."
2940 (string= "#+BIND: variable value
2946 " (org-file-contents (expand-file-name "setupfile3.org"
2947 (concat org-test-dir
"examples/")))))
2948 ;; Throw error when trying to access an invalid file.
2949 (should-error (org-file-contents "this-file-must-not-exist"))
2950 ;; Try to access an invalid file, but do not throw an error.
2952 (progn (org-file-contents "this-file-must-not-exist" :noerror
) t
))
2956 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2958 ;; Simulate successful retrieval of a URL.
2959 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2961 (with-current-buffer buffer
2962 (insert "HTTP/1.1 200 OK\n\nfoo"))
2964 (org-file-contents "http://some-valid-url"))
2965 (kill-buffer buffer
)))))
2966 ;; Throw error when trying to access an invalid URL.
2968 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2970 ;; Simulate unsuccessful retrieval of a URL.
2971 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2973 (with-current-buffer buffer
2974 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2976 (org-file-contents "http://this-url-must-not-exist"))
2977 (kill-buffer buffer
))))
2978 ;; Try to access an invalid URL, but do not throw an error.
2980 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2982 ;; Simulate unsuccessful retrieval of a URL.
2983 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2985 (with-current-buffer buffer
2986 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2988 (org-file-contents "http://this-url-must-not-exist"))
2989 (kill-buffer buffer
))))
2991 (let ((buffer (generate-new-buffer "url-retrieve-output")))
2993 ;; Simulate unsuccessful retrieval of a URL.
2994 (cl-letf (((symbol-function 'url-retrieve-synchronously
)
2996 (with-current-buffer buffer
2997 (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
2999 (org-file-contents "http://this-url-must-not-exist" :noerror
))
3000 (kill-buffer buffer
))
3006 (ert-deftest test-org
/forward-heading-same-level
()
3007 "Test `org-forward-heading-same-level' specifications."
3008 ;; Test navigation at top level, forward and backward.
3011 (org-test-with-temp-text "* H1\n* H2"
3012 (org-forward-heading-same-level 1)
3013 (buffer-substring-no-properties (point) (line-end-position)))))
3016 (org-test-with-temp-text "* H1\n<point>* H2"
3017 (org-forward-heading-same-level -
1)
3018 (buffer-substring-no-properties (point) (line-end-position)))))
3019 ;; Test navigation in a sub-tree, forward and backward.
3022 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
3023 (org-forward-heading-same-level 1)
3024 (buffer-substring-no-properties (point) (line-end-position)))))
3027 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
3028 (org-forward-heading-same-level -
1)
3029 (buffer-substring-no-properties (point) (line-end-position)))))
3030 ;; Stop at first or last sub-heading.
3033 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
3034 (org-forward-heading-same-level 1)
3035 (buffer-substring-no-properties (point) (line-end-position)))))
3038 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
3039 (org-forward-heading-same-level -
1)
3040 (buffer-substring-no-properties (point) (line-end-position)))))
3041 ;; Allow multiple moves.
3044 (org-test-with-temp-text "* H1\n* H2\n* H3"
3045 (org-forward-heading-same-level 2)
3046 (buffer-substring-no-properties (point) (line-end-position)))))
3049 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
3050 (org-forward-heading-same-level -
2)
3051 (buffer-substring-no-properties (point) (line-end-position)))))
3052 ;; Ignore spurious moves when first (or last) sibling is reached.
3055 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
3056 (org-forward-heading-same-level 100)
3057 (buffer-substring-no-properties (point) (line-end-position)))))
3060 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
3061 (org-forward-heading-same-level -
100)
3062 (buffer-substring-no-properties (point) (line-end-position))))))
3064 (ert-deftest test-org
/end-of-meta-data
()
3065 "Test `org-end-of-meta-data' specifications."
3066 ;; Skip planning line.
3068 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
3069 (org-end-of-meta-data)
3071 ;; Skip properties drawer.
3073 (org-test-with-temp-text
3074 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
3075 (org-end-of-meta-data)
3079 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
3080 (org-end-of-meta-data)
3082 ;; Nothing to skip, go to first line.
3084 (org-test-with-temp-text "* Headline\nContents"
3085 (org-end-of-meta-data)
3086 (looking-at "Contents")))
3087 ;; With option argument, skip empty lines, regular drawers and
3090 (org-test-with-temp-text "* Headline\n\nContents"
3091 (org-end-of-meta-data t
)
3092 (looking-at "Contents")))
3094 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
3095 (org-end-of-meta-data t
)
3096 (looking-at "Contents")))
3098 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
3099 (org-end-of-meta-data t
)
3100 (looking-at "Contents")))
3101 ;; Special case: do not skip incomplete drawers.
3103 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
3104 (org-end-of-meta-data t
)
3105 (looking-at ":LOGBOOK:")))
3106 ;; Special case: Be careful about consecutive headlines.
3108 (org-test-with-temp-text "* H1\n*H2\nContents"
3109 (org-end-of-meta-data t
)
3110 (looking-at "Contents"))))
3112 (ert-deftest test-org
/beginning-of-line
()
3113 "Test `org-beginning-of-line' specifications."
3114 ;; Move to beginning of line. If current line in invisible, move to
3115 ;; beginning of visible line instead.
3117 (org-test-with-temp-text "Some text\nSome other text<point>"
3118 (org-beginning-of-line)
3121 (org-test-with-temp-text "* H1\n** H2<point>"
3123 (org-beginning-of-line)
3124 (= (line-beginning-position) 1)))
3125 ;; With `visual-line-mode' active, move to beginning of visual line.
3127 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3129 (dotimes (i 1000) (insert "very "))
3130 (org-beginning-of-line)
3132 ;; In a wide headline, with `visual-line-mode', prefer going to the
3133 ;; beginning of a visual line than to the logical beginning of line,
3134 ;; even if special movement is active.
3136 (org-test-with-temp-text "* A <point>long headline"
3138 (dotimes (i 1000) (insert "very "))
3139 (goto-char (point-max))
3140 (org-beginning-of-line)
3143 (org-test-with-temp-text "* A <point>long headline"
3145 (dotimes (i 1000) (insert "very "))
3146 (goto-char (point-max))
3147 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
3149 ;; At an headline with special movement, first move at beginning of
3150 ;; title, then at the beginning of line, rinse, repeat.
3152 (org-test-with-temp-text "* TODO Headline<point>"
3153 (let ((org-special-ctrl-a/e t
))
3154 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
3155 (progn (org-beginning-of-line) (bolp))
3156 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3158 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3159 (let ((org-special-ctrl-a/e t
))
3160 (org-beginning-of-line)
3161 (looking-at "Headline"))))
3163 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3164 (let ((org-special-ctrl-a/e
'(t . nil
)))
3165 (org-beginning-of-line)
3166 (looking-at "Headline"))))
3168 (org-test-with-temp-text "* TODO [#A] Headline<point>"
3169 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3170 (org-beginning-of-line)
3171 (looking-at "Headline"))))
3172 ;; At an headline with reversed movement, first move to beginning of
3173 ;; line, then to the beginning of title.
3175 (org-test-with-temp-text "* TODO Headline<point>"
3176 (let ((org-special-ctrl-a/e
'reversed
)
3177 (this-command last-command
))
3178 (and (progn (org-beginning-of-line) (bolp))
3179 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3181 (org-test-with-temp-text "* TODO Headline<point>"
3182 (let ((org-special-ctrl-a/e
'(reversed . nil
))
3183 (this-command last-command
))
3184 (and (progn (org-beginning-of-line) (bolp))
3185 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3187 (org-test-with-temp-text "* TODO Headline<point>"
3188 (let ((org-special-ctrl-a/e
'(t . nil
))
3189 (this-command last-command
))
3190 (and (progn (org-beginning-of-line) (bolp))
3191 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
3192 ;; At an item with special movement, first move after to beginning
3193 ;; of title, then to the beginning of line, rinse, repeat.
3195 (org-test-with-temp-text "- [ ] Item<point>"
3196 (let ((org-special-ctrl-a/e t
))
3197 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3198 (progn (org-beginning-of-line) (bolp))
3199 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3200 ;; At an item with reversed movement, first move to beginning of
3201 ;; line, then to the beginning of title.
3203 (org-test-with-temp-text "- [X] Item<point>"
3204 (let ((org-special-ctrl-a/e
'reversed
)
3205 (this-command last-command
))
3206 (and (progn (org-beginning-of-line) (bolp))
3207 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3208 ;; Leave point before invisible characters at column 0.
3210 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3211 (let ((org-special-ctrl-a/e nil
))
3212 (org-beginning-of-line)
3215 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3216 (let ((org-special-ctrl-a/e t
))
3217 (org-beginning-of-line)
3220 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3222 (org-beginning-of-line)
3224 ;; Special case: Do not error when the buffer contains only a single
3227 (org-test-with-temp-text "*<point>"
3228 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3230 (org-test-with-temp-text "*<point>"
3231 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3233 (ert-deftest test-org
/end-of-line
()
3234 "Test `org-end-of-line' specifications."
3237 (org-test-with-temp-text "Some text\nSome other text"
3240 ;; With `visual-line-mode' active, move to end of visible line.
3241 ;; However, never go past ellipsis.
3243 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3245 (dotimes (i 1000) (insert "very "))
3246 (goto-char (point-min))
3250 (org-test-with-temp-text "* A short headline\nSome contents"
3255 ;; In a wide headline, with `visual-line-mode', prefer going to end
3256 ;; of visible line if tags, or end of line, are farther.
3258 (org-test-with-temp-text "* A <point>long headline"
3260 (dotimes (i 1000) (insert "very "))
3261 (goto-char (point-min))
3265 (org-test-with-temp-text "* A <point>long headline :tag:"
3267 (dotimes (i 1000) (insert "very "))
3268 (goto-char (point-min))
3271 ;; At an headline without special movement, go to end of line.
3272 ;; However, never go past ellipsis.
3274 (org-test-with-temp-text "* Headline2b :tag:\n"
3275 (let ((org-special-ctrl-a/e nil
))
3276 (and (progn (org-end-of-line) (eolp))
3277 (progn (org-end-of-line) (eolp))))))
3279 (org-test-with-temp-text "* Headline2b :tag:\n"
3280 (let ((org-special-ctrl-a/e
'(t . nil
)))
3281 (and (progn (org-end-of-line) (eolp))
3282 (progn (org-end-of-line) (eolp))))))
3284 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3286 (let ((org-special-ctrl-a/e nil
))
3288 (= 1 (line-beginning-position)))))
3289 ;; At an headline with special movement, first move before tags,
3290 ;; then at the end of line, rinse, repeat. However, never go past
3293 (org-test-with-temp-text "* Headline1 :tag:\n"
3294 (let ((org-special-ctrl-a/e t
))
3295 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3296 (progn (org-end-of-line) (eolp))
3297 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3299 (org-test-with-temp-text "* Headline1 :tag:\n"
3300 (let ((org-special-ctrl-a/e
'(nil . t
)))
3301 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3302 (progn (org-end-of-line) (eolp))
3303 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3305 (org-test-with-temp-text "* Headline1 :tag:\n"
3306 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3307 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3308 (progn (org-end-of-line) (eolp))
3309 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3311 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3313 (let ((org-special-ctrl-a/e t
))
3316 (= 1 (line-beginning-position)))))
3317 ;; At an headline, with reversed movement, first go to end of line,
3318 ;; then before tags. However, never go past ellipsis.
3320 (org-test-with-temp-text "* Headline3 :tag:\n"
3321 (let ((org-special-ctrl-a/e
'reversed
)
3322 (this-command last-command
))
3323 (and (progn (org-end-of-line) (eolp))
3324 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3326 (org-test-with-temp-text "* Headline3 :tag:\n"
3327 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3328 (this-command last-command
))
3329 (and (progn (org-end-of-line) (eolp))
3330 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3332 (org-test-with-temp-text "* Headline3 :tag:\n"
3333 (let ((org-special-ctrl-a/e
'(nil . t
))
3334 (this-command last-command
))
3335 (and (progn (org-end-of-line) (eolp))
3336 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3338 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3340 (let ((org-special-ctrl-a/e
'reversed
))
3342 (= 1 (line-beginning-position)))))
3343 ;; At a block without hidden contents.
3345 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3346 (progn (org-end-of-line) (eolp))))
3347 ;; At a block with hidden contents.
3349 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3350 (let ((org-special-ctrl-a/e t
))
3351 (org-hide-block-toggle)
3354 ;; Get past invisible characters at the end of line.
3356 (org-test-with-temp-text "[[http://orgmode.org]]"
3360 (ert-deftest test-org
/open-line
()
3361 "Test `org-open-line' specifications."
3362 ;; Call `open-line' outside of tables.
3365 (org-test-with-temp-text "Text"
3368 ;; At a table, create a row above.
3370 (equal "\n| |\n| a |"
3371 (org-test-with-temp-text "\n<point>| a |"
3374 ;; At the very first character of the buffer, also call `open-line'.
3377 (org-test-with-temp-text "| a |"
3380 ;; Narrowing does not count.
3382 (equal "Text\n| |\n| a |"
3383 (org-test-with-temp-text "Text\n<point>| a |"
3384 (narrow-to-region (point) (point-max))
3389 (ert-deftest test-org
/forward-sentence
()
3390 "Test `org-forward-sentence' specifications."
3391 ;; At the end of a table cell, move to the end of the next one.
3393 (org-test-with-temp-text "| a<point> | b |"
3394 (org-forward-sentence)
3395 (looking-at " |$")))
3396 ;; Elsewhere in a cell, move to its end.
3398 (org-test-with-temp-text "| a<point>c | b |"
3399 (org-forward-sentence)
3400 (looking-at " | b |$")))
3401 ;; Otherwise, simply call `forward-sentence'.
3403 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3404 (org-forward-sentence)
3405 (looking-at " Sentence 2.")))
3407 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3408 (org-forward-sentence)
3409 (org-forward-sentence)
3411 ;; At the end of an element, jump to the next one, without stopping
3412 ;; on blank lines in-between.
3414 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3415 (org-forward-sentence)
3417 ;; On a headline, stop at the end of the line, unless point is
3422 (org-test-with-temp-text "* <point>Headline\nSentence."
3423 (org-forward-sentence)
3424 (buffer-substring-no-properties (line-beginning-position) (point)))))
3426 (org-test-with-temp-text "* Headline<point>\nSentence."
3427 (org-forward-sentence)
3430 (ert-deftest test-org
/backward-sentence
()
3431 "Test `org-backward-sentence' specifications."
3432 ;; At the beginning of a table cell, move to the beginning of the
3435 (org-test-with-temp-text "| a | <point>b |"
3436 (org-backward-sentence)
3437 (looking-at "a | b |$")))
3438 ;; Elsewhere in a cell, move to its beginning.
3440 (org-test-with-temp-text "| a | b<point>c |"
3441 (org-backward-sentence)
3442 (looking-at "bc |$")))
3443 ;; Otherwise, simply call `backward-sentence'.
3445 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3446 (org-backward-sentence)
3447 (looking-at "Sentence 2.")))
3449 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3450 (org-backward-sentence)
3451 (org-backward-sentence)
3453 ;; Make sure to hit the beginning of a sentence on the same line as
3456 (org-test-with-temp-text "- Line 1\n line <point>2."
3457 (org-backward-sentence)
3458 (looking-at "Line 1"))))
3460 (ert-deftest test-org
/forward-paragraph
()
3461 "Test `org-forward-paragraph' specifications."
3462 ;; At end of buffer, do not return an error.
3464 (org-test-with-temp-text "Paragraph"
3465 (goto-char (point-max))
3466 (org-forward-paragraph)
3470 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3471 (org-forward-paragraph)
3475 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3476 (org-forward-paragraph)
3478 ;; Do not enter elements with invisible contents.
3480 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3481 (org-hide-block-toggle)
3482 (org-forward-paragraph)
3484 ;; On an affiliated keyword, jump to the beginning of the element.
3486 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3487 (org-forward-paragraph)
3488 (looking-at "Para")))
3489 ;; On an item or a footnote definition, move to the second element
3492 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3493 (org-forward-paragraph)
3494 (looking-at " Paragraph")))
3496 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3497 (org-forward-paragraph)
3498 (looking-at "Paragraph")))
3499 ;; On an item, or a footnote definition, when the first line is
3500 ;; empty, move to the first item.
3502 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3503 (org-forward-paragraph)
3504 (looking-at " Paragraph")))
3506 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3507 (org-forward-paragraph)
3508 (looking-at "Paragraph")))
3509 ;; On a table (resp. a property drawer) do not move through table
3510 ;; rows (resp. node properties).
3512 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3513 (org-forward-paragraph)
3514 (looking-at "Paragraph")))
3516 (org-test-with-temp-text
3517 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3518 (org-forward-paragraph)
3519 (looking-at "Paragraph")))
3520 ;; On a verse or source block, stop after blank lines.
3522 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3523 (org-forward-paragraph)
3526 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3527 (org-forward-paragraph)
3528 (looking-at "L2"))))
3530 (ert-deftest test-org
/backward-paragraph
()
3531 "Test `org-backward-paragraph' specifications."
3532 ;; Do not error at beginning of buffer.
3534 (org-test-with-temp-text "Paragraph"
3535 (org-backward-paragraph)
3539 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3540 (goto-char (point-max))
3541 (org-backward-paragraph)
3544 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3545 (goto-char (point-max))
3547 (org-backward-paragraph)
3551 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3552 (goto-char (point-max))
3554 (org-backward-paragraph)
3556 ;; Ignore invisible elements.
3558 (org-test-with-temp-text "* H1\n P1\n* H2"
3560 (goto-char (point-max))
3562 (org-backward-paragraph)
3564 ;; On an affiliated keyword, jump to the first one.
3566 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3567 (search-forward "c2")
3568 (org-backward-paragraph)
3569 (looking-at "#\\+name")))
3570 ;; On the second element in an item or a footnote definition, jump
3571 ;; to item or the definition.
3573 (org-test-with-temp-text "- line1\n\n line2"
3574 (goto-char (point-max))
3576 (org-backward-paragraph)
3577 (looking-at "- line1")))
3579 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3580 (goto-char (point-max))
3582 (org-backward-paragraph)
3583 (looking-at "\\[fn:1\\] line1")))
3584 ;; On a table (resp. a property drawer), ignore table rows
3585 ;; (resp. node properties).
3587 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3588 (goto-char (point-max))
3590 (org-backward-paragraph)
3593 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3594 (org-backward-paragraph)
3595 (looking-at ":PROPERTIES:")))
3596 ;; On a source or verse block, stop before blank lines.
3598 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3599 (search-forward "L3")
3601 (org-backward-paragraph)
3604 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3605 (search-forward "L3")
3607 (org-backward-paragraph)
3608 (looking-at "L2"))))
3610 (ert-deftest test-org
/forward-element
()
3611 "Test `org-forward-element' specifications."
3612 ;; 1. At EOB: should error.
3613 (org-test-with-temp-text "Some text\n"
3614 (goto-char (point-max))
3615 (should-error (org-forward-element)))
3616 ;; 2. Standard move: expected to ignore blank lines.
3617 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3618 (org-forward-element)
3619 (should (looking-at (regexp-quote "Second paragraph."))))
3620 ;; 3. Headline tests.
3621 (org-test-with-temp-text "
3626 ;; 3.1. At an headline beginning: move to next headline at the
3629 (org-forward-element)
3630 (should (looking-at (regexp-quote "** Head 1.2")))
3631 ;; 3.2. At an headline beginning: move to parent headline if no
3632 ;; headline at the same level.
3634 (org-forward-element)
3635 (should (looking-at (regexp-quote "** Head 1.2"))))
3636 ;; 4. Greater element tests.
3637 (org-test-with-temp-text
3638 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3639 ;; 4.1. At a greater element: expected to skip contents.
3640 (org-forward-element)
3641 (should (looking-at (regexp-quote "Outside.")))
3642 ;; 4.2. At the end of greater element contents: expected to skip
3643 ;; to the end of the greater element.
3645 (org-forward-element)
3646 (should (looking-at (regexp-quote "Outside."))))
3648 (org-test-with-temp-text "
3662 ;; 5.1. At list top point: expected to move to the element after
3665 (org-forward-element)
3666 (should (looking-at (regexp-quote "Outside.")))
3667 ;; 5.2. Special case: at the first line of a sub-list, but not at
3668 ;; beginning of line, move to next item.
3671 (org-forward-element)
3672 (should (looking-at "- item2"))
3675 (org-forward-element)
3676 (should (looking-at " - sub2"))
3677 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3679 (org-forward-element)
3680 (should (looking-at (regexp-quote " Inner paragraph.")))
3681 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3683 (org-forward-element)
3684 (should (looking-at (regexp-quote " Inner paragraph.")))
3685 ;; 5.5. At an item: expected to move to next item, if any.
3687 (org-forward-element)
3688 (should (looking-at " - sub3"))))
3690 (ert-deftest test-org
/backward-element
()
3691 "Test `org-backward-element' specifications."
3692 ;; 1. Should error at BOB.
3693 (org-test-with-temp-text " \nParagraph."
3694 (should-error (org-backward-element)))
3695 ;; 2. Should move at BOB when called on the first element in buffer.
3697 (org-test-with-temp-text "\n#+TITLE: test"
3698 (progn (forward-line)
3699 (org-backward-element)
3701 ;; 3. Not at the beginning of an element: move at its beginning.
3702 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3705 (org-backward-element)
3706 (should (looking-at (regexp-quote "Paragraph2."))))
3707 ;; 4. Headline tests.
3708 (org-test-with-temp-text "
3713 ;; 4.1. At an headline beginning: move to previous headline at the
3716 (org-backward-element)
3717 (should (looking-at (regexp-quote "** Head 1.1")))
3718 ;; 4.2. At an headline beginning: move to parent headline if no
3719 ;; headline at the same level.
3721 (org-backward-element)
3722 (should (looking-at (regexp-quote "* Head 1")))
3723 ;; 4.3. At the first top-level headline: should error.
3725 (should-error (org-backward-element)))
3726 ;; 5. At beginning of first element inside a greater element:
3727 ;; expected to move to greater element's beginning.
3728 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3730 (org-backward-element)
3731 (should (looking-at "#\\+BEGIN_CENTER")))
3732 ;; 6. At the beginning of the first element in a section: should
3733 ;; move back to headline, if any.
3735 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3736 (progn (goto-char (point-max))
3738 (org-backward-element)
3739 (org-at-heading-p))))
3741 (org-test-with-temp-text "
3756 ;; 7.1. At beginning of sub-list: expected to move to the
3757 ;; paragraph before it.
3759 (org-backward-element)
3760 (should (looking-at "item1"))
3761 ;; 7.2. At an item in a list: expected to move at previous item.
3763 (org-backward-element)
3764 (should (looking-at " - sub2"))
3766 (org-backward-element)
3767 (should (looking-at "- item1"))
3768 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3771 (org-backward-element)
3772 (should (looking-at " - sub1"))
3774 (org-backward-element)
3775 (should (looking-at "- item1"))
3776 ;; 7.4. At blank-lines before list end: expected to move to top
3779 (org-backward-element)
3780 (should (looking-at "- item1"))))
3782 (ert-deftest test-org
/up-element
()
3783 "Test `org-up-element' specifications."
3784 ;; 1. At BOB or with no surrounding element: should error.
3785 (org-test-with-temp-text "Paragraph."
3786 (should-error (org-up-element)))
3787 (org-test-with-temp-text "* Head1\n* Head2"
3789 (should-error (org-up-element)))
3790 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3792 (should-error (org-up-element)))
3793 ;; 2. At an headline: move to parent headline.
3794 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3797 (should (looking-at "\\* Head1")))
3798 ;; 3. Inside a greater element: move to greater element beginning.
3799 (org-test-with-temp-text
3800 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3803 (should (looking-at "#\\+BEGIN_CENTER")))
3805 (org-test-with-temp-text "* Top
3812 Paragraph within sub2.
3815 ;; 4.1. Within an item: move to the item beginning.
3818 (should (looking-at " - sub2"))
3819 ;; 4.2. At an item in a sub-list: move to parent item.
3822 (should (looking-at "- item1"))
3823 ;; 4.3. At an item in top list: move to beginning of whole list.
3826 (should (looking-at "- item1"))
3827 ;; 4.4. Special case. At very top point: should move to parent of
3831 (should (looking-at "\\* Top"))))
3833 (ert-deftest test-org
/down-element
()
3834 "Test `org-down-element' specifications."
3835 ;; Error when the element hasn't got a recursive type.
3836 (org-test-with-temp-text "Paragraph."
3837 (should-error (org-down-element)))
3838 ;; Error when the element has no contents
3839 (org-test-with-temp-text "* Headline"
3840 (should-error (org-down-element)))
3841 ;; When at a plain-list, move to first item.
3842 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3845 (should (looking-at " - Item 1.1")))
3846 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3848 (should (looking-at " Item 1")))
3849 ;; When at a table, move to first row
3850 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3852 (should (looking-at " a | b |")))
3853 ;; Otherwise, move inside the greater element.
3854 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3856 (should (looking-at "Paragraph"))))
3858 (ert-deftest test-org
/drag-element-backward
()
3859 "Test `org-drag-element-backward' specifications."
3863 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3864 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3865 (org-drag-element-backward)
3869 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3870 (org-test-with-temp-text
3871 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3872 (org-drag-element-backward)
3874 ;; Preserve blank lines.
3876 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3877 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3878 (org-drag-element-backward)
3882 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3883 (org-drag-element-backward)
3884 (looking-at-p "2")))
3885 ;; Error when trying to move first element of buffer.
3887 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3888 (org-drag-element-backward))
3890 ;; Error when trying to swap nested elements.
3892 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3893 (org-drag-element-backward))
3895 ;; Error when trying to swap an headline element and a non-headline
3898 (org-test-with-temp-text "Test.\n<point>* Head 1"
3899 (org-drag-element-backward))
3901 ;; Error when called before first element.
3903 (org-test-with-temp-text "\n<point>"
3904 (org-drag-element-backward))
3906 ;; Preserve visibility of elements and their contents.
3908 (equal '((63 .
82) (26 .
48))
3909 (org-test-with-temp-text "
3917 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3918 (search-backward "- item 1")
3919 (org-drag-element-backward)
3920 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3921 (overlays-in (point-min) (point-max))))))
3922 ;; Pathological case: handle call with point in blank lines right
3923 ;; after a headline.
3925 (equal "* H2\n* H1\nText\n\n"
3926 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3927 (org-drag-element-backward)
3930 (ert-deftest test-org
/drag-element-forward
()
3931 "Test `org-drag-element-forward' specifications."
3932 ;; 1. Error when trying to move first element of buffer.
3933 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3935 (should-error (org-drag-element-forward)))
3936 ;; 2. Error when trying to swap nested elements.
3937 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3939 (should-error (org-drag-element-forward)))
3940 ;; 3. Error when trying to swap a non-headline element and an
3942 (org-test-with-temp-text "Test.\n* Head 1"
3943 (should-error (org-drag-element-forward)))
3944 ;; 4. Error when called before first element.
3946 (org-test-with-temp-text "\n"
3948 (org-drag-element-backward))
3950 ;; 5. Otherwise, swap elements, preserving column and blank lines
3951 ;; between elements.
3952 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3953 (search-forward "graph")
3954 (org-drag-element-forward)
3955 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3956 (should (looking-at " 1")))
3957 ;; 5. Preserve visibility of elements and their contents.
3958 (org-test-with-temp-text "
3966 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3967 (search-backward "#+BEGIN_CENTER")
3968 (org-drag-element-forward)
3971 '((63 .
82) (26 .
48))
3972 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3973 (overlays-in (point-min) (point-max)))))))
3975 (ert-deftest test-org
/next-block
()
3976 "Test `org-next-block' specifications."
3979 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3981 (looking-at "#\\+BEGIN_CENTER")))
3984 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3985 (let ((case-fold-search nil
))
3987 (looking-at "#\\+begin_center"))))
3988 ;; Ignore current line.
3990 (org-test-with-temp-text
3991 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3993 (looking-at "#\\+BEGIN_CENTER")))
3994 ;; Throw an error when no block is found.
3996 (org-test-with-temp-text "Paragraph"
3997 (org-next-block 1)))
3998 ;; With an argument, skip many blocks at once.
4000 (org-test-with-temp-text
4001 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4003 (looking-at "#\\+BEGIN_QUOTE")))
4004 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4006 (org-test-with-temp-text
4007 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
4008 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4009 (looking-at "#\\+BEGIN_QUOTE")))
4010 ;; Optional argument is also case-insensitive.
4012 (org-test-with-temp-text
4013 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
4014 (let ((case-fold-search nil
))
4015 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
4016 (looking-at "#\\+begin_quote")))))
4018 (ert-deftest test-org
/previous-block
()
4019 "Test `org-previous-block' specifications."
4022 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
4023 (org-previous-block 1)
4024 (looking-at "#\\+BEGIN_CENTER")))
4027 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
4028 (let ((case-fold-search nil
))
4029 (org-previous-block 1)
4030 (looking-at "#\\+begin_center"))))
4031 ;; Ignore current line.
4033 (org-test-with-temp-text
4034 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
4035 (org-previous-block 1)
4036 (looking-at "#\\+BEGIN_QUOTE")))
4037 ;; Throw an error when no block is found.
4039 (org-test-with-temp-text "Paragraph<point>"
4040 (org-previous-block 1)))
4041 ;; With an argument, skip many blocks at once.
4043 (org-test-with-temp-text
4044 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4045 (org-previous-block 2)
4046 (looking-at "#\\+BEGIN_CENTER")))
4047 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
4049 (org-test-with-temp-text
4050 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
4051 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4052 (looking-at "#\\+BEGIN_QUOTE")))
4053 ;; Optional argument is also case-insensitive.
4055 (org-test-with-temp-text
4056 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
4057 (let ((case-fold-search nil
))
4058 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
4059 (looking-at "#\\+begin_quote")))))
4062 ;;; Outline structure
4064 (ert-deftest test-org
/demote
()
4065 "Test `org-demote' specifications."
4066 ;; Add correct number of stars according to `org-odd-levels-only'.
4069 (org-test-with-temp-text "* H"
4070 (let ((org-odd-levels-only nil
)) (org-demote))
4071 (org-current-level))))
4074 (org-test-with-temp-text "* H"
4075 (let ((org-odd-levels-only t
)) (org-demote))
4076 (org-current-level))))
4077 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4079 (org-test-with-temp-text "* H :tag:"
4080 (let ((org-tags-column 10)
4081 (org-auto-align-tags t
)
4082 (org-odd-levels-only nil
))
4084 (org-move-to-column 10)
4085 (looking-at-p ":tag:$")))
4087 (org-test-with-temp-text "* H :tag:"
4088 (let ((org-tags-column 10)
4089 (org-auto-align-tags nil
)
4090 (org-odd-levels-only nil
))
4092 (org-move-to-column 10)
4093 (looking-at-p ":tag:$")))
4094 ;; When `org-adapt-indentation' is non-nil, always indent planning
4095 ;; info and property drawers accordingly.
4098 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4099 (let ((org-odd-levels-only nil
)
4100 (org-adapt-indentation t
))
4103 (org-get-indentation))))
4106 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4107 (let ((org-odd-levels-only nil
)
4108 (org-adapt-indentation t
))
4111 (org-get-indentation))))
4114 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
4115 (let ((org-odd-levels-only nil
)
4116 (org-adapt-indentation nil
))
4119 (org-get-indentation))))
4120 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4121 ;; section accordingly. Ignore, however, footnote definitions and
4122 ;; inlinetasks boundaries.
4125 (org-test-with-temp-text "* H\n Paragraph"
4126 (let ((org-odd-levels-only nil
)
4127 (org-adapt-indentation t
))
4130 (org-get-indentation))))
4133 (org-test-with-temp-text "* H\n Paragraph"
4134 (let ((org-odd-levels-only nil
)
4135 (org-adapt-indentation nil
))
4138 (org-get-indentation))))
4141 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
4142 (let ((org-odd-levels-only nil
)
4143 (org-adapt-indentation t
))
4145 (goto-char (point-max))
4146 (org-get-indentation))))
4149 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
4150 (let ((org-odd-levels-only nil
)
4151 (org-adapt-indentation t
))
4153 (goto-char (point-max))
4154 (org-get-indentation))))
4155 (when (featurep 'org-inlinetask
)
4158 (let ((org-inlinetask-min-level 5)
4159 (org-adapt-indentation t
))
4160 (org-test-with-temp-text "* H\n***** I\n***** END"
4163 (org-get-indentation))))))
4164 (when (featurep 'org-inlinetask
)
4167 (let ((org-inlinetask-min-level 5)
4168 (org-adapt-indentation t
))
4169 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
4172 (org-get-indentation))))))
4173 ;; Ignore contents of source blocks or example blocks when
4174 ;; indentation should be preserved (through
4175 ;; `org-src-preserve-indentation' or "-i" flag).
4178 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4179 (let ((org-adapt-indentation t
)
4180 (org-src-preserve-indentation nil
))
4183 (org-get-indentation))))
4186 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
4187 (let ((org-adapt-indentation t
)
4188 (org-src-preserve-indentation t
))
4191 (org-get-indentation))))
4194 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
4195 (let ((org-adapt-indentation t
)
4196 (org-src-preserve-indentation t
))
4199 (org-get-indentation))))
4202 (org-test-with-temp-text
4203 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
4204 (let ((org-adapt-indentation t
)
4205 (org-src-preserve-indentation nil
))
4208 (org-get-indentation)))))
4210 (ert-deftest test-org
/promote
()
4211 "Test `org-promote' specifications."
4212 ;; Return an error if headline is to be promoted to level 0, unless
4213 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4214 ;; headline becomes a comment.
4216 (org-test-with-temp-text "* H"
4217 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4220 (org-test-with-temp-text "* H"
4221 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4223 ;; Remove correct number of stars according to
4224 ;; `org-odd-levels-only'.
4227 (org-test-with-temp-text "*** H"
4228 (let ((org-odd-levels-only nil
)) (org-promote))
4229 (org-current-level))))
4232 (org-test-with-temp-text "*** H"
4233 (let ((org-odd-levels-only t
)) (org-promote))
4234 (org-current-level))))
4235 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4237 (org-test-with-temp-text "** H :tag:"
4238 (let ((org-tags-column 10)
4239 (org-auto-align-tags t
)
4240 (org-odd-levels-only nil
))
4242 (org-move-to-column 10)
4243 (looking-at-p ":tag:$")))
4245 (org-test-with-temp-text "** H :tag:"
4246 (let ((org-tags-column 10)
4247 (org-auto-align-tags nil
)
4248 (org-odd-levels-only nil
))
4250 (org-move-to-column 10)
4251 (looking-at-p ":tag:$")))
4252 ;; When `org-adapt-indentation' is non-nil, always indent planning
4253 ;; info and property drawers.
4256 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4257 (let ((org-odd-levels-only nil
)
4258 (org-adapt-indentation t
))
4261 (org-get-indentation))))
4264 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4265 (let ((org-odd-levels-only nil
)
4266 (org-adapt-indentation t
))
4269 (org-get-indentation))))
4272 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4273 (let ((org-odd-levels-only nil
)
4274 (org-adapt-indentation nil
))
4277 (org-get-indentation))))
4278 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4279 ;; section accordingly. Ignore, however, footnote definitions and
4280 ;; inlinetasks boundaries.
4283 (org-test-with-temp-text "** H\n Paragraph"
4284 (let ((org-odd-levels-only nil
)
4285 (org-adapt-indentation t
))
4288 (org-get-indentation))))
4291 (org-test-with-temp-text "** H\n Paragraph"
4292 (let ((org-odd-levels-only nil
)
4293 (org-adapt-indentation nil
))
4296 (org-get-indentation))))
4299 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4300 (let ((org-odd-levels-only nil
)
4301 (org-adapt-indentation t
))
4304 (org-get-indentation))))
4305 (when (featurep 'org-inlinetask
)
4308 (let ((org-inlinetask-min-level 5)
4309 (org-adapt-indentation t
))
4310 (org-test-with-temp-text "** H\n***** I\n***** END"
4313 (org-get-indentation))))))
4314 (when (featurep 'org-inlinetask
)
4317 (let ((org-inlinetask-min-level 5)
4318 (org-adapt-indentation t
))
4319 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4322 (org-get-indentation))))))
4323 ;; Give up shifting if it would break document's structure
4327 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4328 (let ((org-odd-levels-only nil
)
4329 (org-adapt-indentation t
))
4332 (org-get-indentation))))
4335 (org-test-with-temp-text "** H\n Paragraph\n * list."
4336 (let ((org-odd-levels-only nil
)
4337 (org-adapt-indentation t
))
4340 (org-get-indentation))))
4341 ;; Ignore contents of source blocks or example blocks when
4342 ;; indentation should be preserved (through
4343 ;; `org-src-preserve-indentation' or "-i" flag).
4346 (org-test-with-temp-text
4347 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4348 (let ((org-adapt-indentation t
)
4349 (org-src-preserve-indentation nil
)
4350 (org-odd-levels-only nil
))
4353 (org-get-indentation))))
4356 (org-test-with-temp-text
4357 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4358 (let ((org-adapt-indentation t
)
4359 (org-src-preserve-indentation t
)
4360 (org-odd-levels-only nil
))
4363 (org-get-indentation))))
4366 (org-test-with-temp-text
4367 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4368 (let ((org-adapt-indentation t
)
4369 (org-src-preserve-indentation t
)
4370 (org-odd-levels-only nil
))
4373 (org-get-indentation))))
4376 (org-test-with-temp-text
4377 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4378 (let ((org-adapt-indentation t
)
4379 (org-src-preserve-indentation nil
)
4380 (org-odd-levels-only nil
))
4383 (org-get-indentation)))))
4385 (ert-deftest test-org
/org-get-valid-level
()
4386 "Test function `org-get-valid-level' specifications."
4387 (let ((org-odd-levels-only nil
))
4388 (should (equal 1 (org-get-valid-level 0 0)))
4389 (should (equal 1 (org-get-valid-level 0 1)))
4390 (should (equal 2 (org-get-valid-level 0 2)))
4391 (should (equal 3 (org-get-valid-level 0 3)))
4392 (should (equal 1 (org-get-valid-level 1 0)))
4393 (should (equal 2 (org-get-valid-level 1 1)))
4394 (should (equal 23 (org-get-valid-level 1 22)))
4395 (should (equal 1 (org-get-valid-level 1 -
1)))
4396 (should (equal 1 (org-get-valid-level 2 -
1))))
4397 (let ((org-odd-levels-only t
))
4398 (should (equal 1 (org-get-valid-level 0 0)))
4399 (should (equal 1 (org-get-valid-level 0 1)))
4400 (should (equal 3 (org-get-valid-level 0 2)))
4401 (should (equal 5 (org-get-valid-level 0 3)))
4402 (should (equal 1 (org-get-valid-level 1 0)))
4403 (should (equal 3 (org-get-valid-level 1 1)))
4404 (should (equal 3 (org-get-valid-level 2 1)))
4405 (should (equal 5 (org-get-valid-level 3 1)))
4406 (should (equal 5 (org-get-valid-level 4 1)))
4407 (should (equal 43 (org-get-valid-level 1 21)))
4408 (should (equal 1 (org-get-valid-level 1 -
1)))
4409 (should (equal 1 (org-get-valid-level 2 -
1)))
4410 (should (equal 1 (org-get-valid-level 3 -
1)))
4411 (should (equal 3 (org-get-valid-level 4 -
1)))
4412 (should (equal 3 (org-get-valid-level 5 -
1)))))
4417 (ert-deftest test-org
/at-planning-p
()
4418 "Test `org-at-planning-p' specifications."
4421 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4422 (org-at-planning-p)))
4424 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4425 (org-at-planning-p)))
4426 ;; Correctly find planning attached to inlinetasks.
4427 (when (featurep 'org-inlinetask
)
4429 (org-test-with-temp-text
4430 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4431 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4433 (org-test-with-temp-text
4434 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4435 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4437 (org-test-with-temp-text
4438 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4439 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4441 (org-test-with-temp-text
4442 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4443 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4445 (ert-deftest test-org
/add-planning-info
()
4446 "Test `org-add-planning-info'."
4447 ;; Create deadline when `org-adapt-indentation' is non-nil.
4449 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4450 (org-test-with-temp-text "* H\nParagraph<point>"
4451 (let ((org-adapt-indentation t
))
4452 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4453 (replace-regexp-in-string
4454 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4456 ;; Create deadline when `org-adapt-indentation' is nil.
4458 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4459 (org-test-with-temp-text "* H\nParagraph<point>"
4460 (let ((org-adapt-indentation nil
))
4461 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4462 (replace-regexp-in-string
4463 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4465 ;; Update deadline when `org-adapt-indentation' is non-nil.
4467 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4468 (org-test-with-temp-text "\
4470 DEADLINE: <2015-06-24 Wed>
4472 (let ((org-adapt-indentation t
))
4473 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4474 (replace-regexp-in-string
4475 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4477 ;; Update deadline when `org-adapt-indentation' is nil.
4479 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4480 (org-test-with-temp-text "\
4482 DEADLINE: <2015-06-24 Wed>
4484 (let ((org-adapt-indentation nil
))
4485 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4486 (replace-regexp-in-string
4487 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4489 ;; Schedule when `org-adapt-indentation' is non-nil.
4491 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4492 (org-test-with-temp-text "* H\nParagraph<point>"
4493 (let ((org-adapt-indentation t
))
4494 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4495 (replace-regexp-in-string
4496 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4498 ;; Schedule when `org-adapt-indentation' is nil.
4500 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4501 (org-test-with-temp-text "* H\nParagraph<point>"
4502 (let ((org-adapt-indentation nil
))
4503 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4504 (replace-regexp-in-string
4505 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4507 ;; Add deadline when scheduled.
4511 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4513 (org-test-with-temp-text "\
4515 SCHEDULED: <2015-06-24 Wed>
4517 (let ((org-adapt-indentation t
))
4518 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4519 (replace-regexp-in-string
4520 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4522 ;; Remove middle entry.
4526 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4528 (org-test-with-temp-text "\
4530 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4532 (let ((org-adapt-indentation t
))
4533 (org-add-planning-info nil nil
'deadline
))
4534 (replace-regexp-in-string
4535 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4537 ;; Remove last entry and then middle entry (order should not
4542 CLOSED: [2015-06-24]
4544 (org-test-with-temp-text "\
4546 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4548 (let ((org-adapt-indentation t
))
4549 (org-add-planning-info nil nil
'scheduled
'deadline
))
4550 (replace-regexp-in-string
4551 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4553 ;; Remove closed when `org-adapt-indentation' is non-nil.
4555 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4556 (org-test-with-temp-text "\
4558 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4560 (let ((org-adapt-indentation t
))
4561 (org-add-planning-info nil nil
'closed
))
4562 (replace-regexp-in-string
4563 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4566 (equal "* H\n Paragraph"
4567 (org-test-with-temp-text "\
4569 CLOSED: [2015-06-25 Thu]
4571 (let ((org-adapt-indentation t
))
4572 (org-add-planning-info nil nil
'closed
))
4573 (replace-regexp-in-string
4574 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4576 ;; Remove closed when `org-adapt-indentation' is nil.
4578 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4579 (org-test-with-temp-text "\
4581 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4583 (let ((org-adapt-indentation nil
))
4584 (org-add-planning-info nil nil
'closed
))
4585 (replace-regexp-in-string
4586 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4589 (equal "* H\nParagraph"
4590 (org-test-with-temp-text "\
4592 CLOSED: [2015-06-25 Thu]
4594 (let ((org-adapt-indentation nil
))
4595 (org-add-planning-info nil nil
'closed
))
4596 (replace-regexp-in-string
4597 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4599 ;; Remove closed entry and delete empty line.
4604 (org-test-with-temp-text "\
4606 CLOSED: [2015-06-24 Wed]
4608 (let ((org-adapt-indentation t
))
4609 (org-add-planning-info nil nil
'closed
))
4610 (replace-regexp-in-string
4611 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4613 ;; Remove one entry and update another.
4615 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4616 (org-test-with-temp-text "\
4618 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4620 (let ((org-adapt-indentation t
))
4621 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4622 (replace-regexp-in-string
4623 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4626 (ert-deftest test-org
/deadline
()
4627 "Test `org-deadline' specifications."
4628 ;; Insert a new value or replace existing one.
4630 (equal "* H\nDEADLINE: <2012-03-29>\n"
4631 (org-test-with-temp-text "* H"
4632 (let ((org-adapt-indentation nil
)
4633 (org-last-inserted-timestamp nil
))
4634 (org-deadline nil
"<2012-03-29 Tue>"))
4635 (replace-regexp-in-string
4636 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4639 (equal "* H\nDEADLINE: <2014-03-04>"
4640 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4641 (let ((org-adapt-indentation nil
)
4642 (org-last-inserted-timestamp nil
))
4643 (org-deadline nil
"<2014-03-04 Thu>"))
4644 (replace-regexp-in-string
4645 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4647 ;; Accept delta time, e.g., "+2d".
4649 (equal "* H\nDEADLINE: <2015-03-04>\n"
4650 (cl-letf (((symbol-function 'current-time
)
4651 (lambda (&rest args
)
4652 (apply #'encode-time
4653 (org-parse-time-string "2014-03-04")))))
4654 (org-test-with-temp-text "* H"
4655 (let ((org-adapt-indentation nil
)
4656 (org-last-inserted-timestamp nil
))
4657 (org-deadline nil
"+1y"))
4658 (replace-regexp-in-string
4659 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4660 ;; Preserve repeater.
4662 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4663 (org-test-with-temp-text "* H"
4664 (let ((org-adapt-indentation nil
)
4665 (org-last-inserted-timestamp nil
))
4666 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4667 (replace-regexp-in-string
4668 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4669 ;; Remove CLOSED keyword, if any.
4671 (equal "* H\nDEADLINE: <2012-03-29>"
4672 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4673 (let ((org-adapt-indentation nil
)
4674 (org-last-inserted-timestamp nil
))
4675 (org-deadline nil
"<2012-03-29 Tue>"))
4676 (replace-regexp-in-string
4677 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4678 ;; With C-u argument, remove DEADLINE keyword.
4681 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4682 (let ((org-adapt-indentation nil
)
4683 (org-last-inserted-timestamp nil
))
4684 (org-deadline '(4)))
4688 (org-test-with-temp-text "* H"
4689 (let ((org-adapt-indentation nil
)
4690 (org-last-inserted-timestamp nil
))
4691 (org-deadline '(4)))
4693 ;; With C-u C-u argument, prompt for a delay cookie.
4695 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4696 (cl-letf (((symbol-function 'org-read-date
)
4697 (lambda (&rest args
)
4698 (apply #'encode-time
4699 (org-parse-time-string "2014-03-04")))))
4700 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4701 (let ((org-adapt-indentation nil
)
4702 (org-last-inserted-timestamp nil
))
4703 (org-deadline '(16)))
4706 (cl-letf (((symbol-function 'org-read-date
)
4707 (lambda (&rest args
)
4708 (apply #'encode-time
4709 (org-parse-time-string "2014-03-04")))))
4710 (org-test-with-temp-text "* H"
4711 (let ((org-adapt-indentation nil
)
4712 (org-last-inserted-timestamp nil
))
4713 (org-deadline '(16)))
4715 ;; When a region is active and
4716 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4717 ;; same value in all headlines in region.
4719 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4720 (org-test-with-temp-text "* H1\n* H2"
4721 (let ((org-adapt-indentation nil
)
4722 (org-last-inserted-timestamp nil
)
4723 (org-loop-over-headlines-in-active-region t
))
4724 (transient-mark-mode 1)
4725 (push-mark (point) t t
)
4726 (goto-char (point-max))
4727 (org-deadline nil
"2012-03-29"))
4728 (replace-regexp-in-string
4729 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4731 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4732 (org-test-with-temp-text "* H1\n* H2"
4733 (let ((org-adapt-indentation nil
)
4734 (org-last-inserted-timestamp nil
)
4735 (org-loop-over-headlines-in-active-region nil
))
4736 (transient-mark-mode 1)
4737 (push-mark (point) t t
)
4738 (goto-char (point-max))
4739 (org-deadline nil
"2012-03-29"))
4740 (replace-regexp-in-string
4741 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4743 (ert-deftest test-org
/schedule
()
4744 "Test `org-schedule' specifications."
4745 ;; Insert a new value or replace existing one.
4747 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4748 (org-test-with-temp-text "* H"
4749 (let ((org-adapt-indentation nil
)
4750 (org-last-inserted-timestamp nil
))
4751 (org-schedule nil
"<2012-03-29 Tue>"))
4752 (replace-regexp-in-string
4753 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4756 (equal "* H\nSCHEDULED: <2014-03-04>"
4757 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4758 (let ((org-adapt-indentation nil
)
4759 (org-last-inserted-timestamp nil
))
4760 (org-schedule nil
"<2014-03-04 Thu>"))
4761 (replace-regexp-in-string
4762 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4764 ;; Accept delta time, e.g., "+2d".
4766 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4767 (cl-letf (((symbol-function 'current-time
)
4768 (lambda (&rest args
)
4769 (apply #'encode-time
4770 (org-parse-time-string "2014-03-04")))))
4771 (org-test-with-temp-text "* H"
4772 (let ((org-adapt-indentation nil
)
4773 (org-last-inserted-timestamp nil
))
4774 (org-schedule nil
"+1y"))
4775 (replace-regexp-in-string
4776 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4777 ;; Preserve repeater.
4779 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4780 (org-test-with-temp-text "* H"
4781 (let ((org-adapt-indentation nil
)
4782 (org-last-inserted-timestamp nil
))
4783 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4784 (replace-regexp-in-string
4785 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4786 ;; Remove CLOSED keyword, if any.
4788 (equal "* H\nSCHEDULED: <2012-03-29>"
4789 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4790 (let ((org-adapt-indentation nil
)
4791 (org-last-inserted-timestamp nil
))
4792 (org-schedule nil
"<2012-03-29 Tue>"))
4793 (replace-regexp-in-string
4794 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4795 ;; With C-u argument, remove SCHEDULED keyword.
4798 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4799 (let ((org-adapt-indentation nil
)
4800 (org-last-inserted-timestamp nil
))
4801 (org-schedule '(4)))
4805 (org-test-with-temp-text "* H"
4806 (let ((org-adapt-indentation nil
)
4807 (org-last-inserted-timestamp nil
))
4808 (org-schedule '(4)))
4810 ;; With C-u C-u argument, prompt for a delay cookie.
4812 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4813 (cl-letf (((symbol-function 'org-read-date
)
4814 (lambda (&rest args
)
4815 (apply #'encode-time
4816 (org-parse-time-string "2014-03-04")))))
4817 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4818 (let ((org-adapt-indentation nil
)
4819 (org-last-inserted-timestamp nil
))
4820 (org-schedule '(16)))
4823 (cl-letf (((symbol-function 'org-read-date
)
4824 (lambda (&rest args
)
4825 (apply #'encode-time
4826 (org-parse-time-string "2014-03-04")))))
4827 (org-test-with-temp-text "* H"
4828 (let ((org-adapt-indentation nil
)
4829 (org-last-inserted-timestamp nil
))
4830 (org-schedule '(16)))
4832 ;; When a region is active and
4833 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4834 ;; same value in all headlines in region.
4836 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4837 (org-test-with-temp-text "* H1\n* H2"
4838 (let ((org-adapt-indentation nil
)
4839 (org-last-inserted-timestamp nil
)
4840 (org-loop-over-headlines-in-active-region t
))
4841 (transient-mark-mode 1)
4842 (push-mark (point) t t
)
4843 (goto-char (point-max))
4844 (org-schedule nil
"2012-03-29"))
4845 (replace-regexp-in-string
4846 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4848 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4849 (org-test-with-temp-text "* H1\n* H2"
4850 (let ((org-adapt-indentation nil
)
4851 (org-last-inserted-timestamp nil
)
4852 (org-loop-over-headlines-in-active-region nil
))
4853 (transient-mark-mode 1)
4854 (push-mark (point) t t
)
4855 (goto-char (point-max))
4856 (org-schedule nil
"2012-03-29"))
4857 (replace-regexp-in-string
4858 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4860 ;; check if a repeater survives re-scheduling.
4862 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4863 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4864 (let ((org-adapt-indentation nil
)
4865 (org-last-inserted-timestamp nil
))
4866 (org-schedule nil
"2017-02-01"))
4872 (ert-deftest test-org
/buffer-property-keys
()
4873 "Test `org-buffer-property-keys' specifications."
4874 ;; Retrieve properties accross siblings.
4877 (org-test-with-temp-text "
4886 (org-buffer-property-keys))))
4887 ;; Retrieve properties accross children.
4890 (org-test-with-temp-text "
4899 (org-buffer-property-keys))))
4900 ;; Retrieve muliple properties in the same drawer.
4903 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4904 (org-buffer-property-keys))))
4905 ;; Ignore extension symbol in property name.
4908 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4909 (org-buffer-property-keys))))
4910 ;; With non-nil COLUMNS, extract property names from columns.
4913 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4914 (org-buffer-property-keys nil nil t
))))
4916 (equal '("A" "B" "COLUMNS")
4917 (org-test-with-temp-text
4918 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4919 (org-buffer-property-keys nil nil t
))))
4920 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4923 (org-test-with-temp-text
4924 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4925 (org-buffer-property-keys nil nil nil t
))))
4926 ;; In COLUMNS, ignore label title and summary-type.
4929 (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
4930 (org-buffer-property-keys nil nil t
))))
4933 (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
4934 (org-buffer-property-keys nil nil t
))))
4937 (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
4938 (org-buffer-property-keys nil nil t
)))))
4940 (ert-deftest test-org
/property-values
()
4941 "Test `org-property-values' specifications."
4945 (org-test-with-temp-text
4946 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4947 (org-property-values "A"))))
4948 ;; Ignore empty values.
4950 (org-test-with-temp-text
4951 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4952 (org-property-values "A")))
4953 ;; Take into consideration extended values.
4956 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4957 (org-property-values "A")))))
4959 (ert-deftest test-org
/find-property
()
4960 "Test `org-find-property' specifications."
4964 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4965 (org-find-property "prop"))))
4966 ;; Ignore false positives.
4969 (org-test-with-temp-text
4970 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4971 (org-find-property "A"))))
4972 ;; Return first entry found in buffer.
4975 (org-test-with-temp-text
4976 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4977 (org-find-property "A"))))
4978 ;; Only search visible part of the buffer.
4981 (org-test-with-temp-text
4982 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4983 (org-narrow-to-subtree)
4984 (org-find-property "A"))))
4985 ;; With optional argument, only find entries with a specific value.
4987 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4988 (org-find-property "A" "2")))
4991 (org-test-with-temp-text
4992 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4993 (org-find-property "A" "2"))))
4994 ;; Use "nil" for explicit nil values.
4997 (org-test-with-temp-text
4998 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4999 (org-find-property "A" "nil")))))
5001 (ert-deftest test-org
/entry-delete
()
5002 "Test `org-entry-delete' specifications."
5006 " *:PROPERTIES:\n *:B: +2\n *:END:"
5007 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5008 (org-entry-delete (point) "A")
5010 ;; Also remove accumulated properties.
5014 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
5015 (org-entry-delete (point) "A")
5017 ;; When last property is removed, remove the property drawer.
5021 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
5022 (org-entry-delete (point) "A")
5024 ;; Return a non-nil value when some property was removed.
5026 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5027 (org-entry-delete (point) "A")))
5029 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
5030 (org-entry-delete (point) "C")))
5031 ;; Special properties cannot be located in a drawer. Allow to
5032 ;; remove them anyway, in case of user error.
5034 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
5035 (org-entry-delete (point) "SCHEDULED"))))
5037 (ert-deftest test-org
/entry-get
()
5038 "Test `org-entry-get' specifications."
5042 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5043 (org-entry-get (point) "A"))))
5047 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5048 (org-entry-get (point) "a"))))
5049 ;; Handle extended values, both before and after base value.
5052 (org-test-with-temp-text
5053 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5054 (org-entry-get (point) "A"))))
5055 ;; Empty values are returned as the empty string.
5058 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
5059 (org-entry-get (point) "A"))))
5060 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
5061 ;; otherwise, return nil.
5063 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5064 (org-entry-get (point) "A")))
5067 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
5068 (org-entry-get (point) "A" nil t
))))
5069 ;; Return nil when no property is found, independently on the
5070 ;; LITERAL-NIL argument.
5072 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5073 (org-entry-get (point) "B")))
5075 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5076 (org-entry-get (point) "B" nil t
)))
5077 ;; Handle inheritance, when allowed. Include extended values and
5078 ;; possibly global values.
5082 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5083 (org-entry-get (point) "A" t
))))
5087 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5088 (let ((org-use-property-inheritance t
))
5089 (org-entry-get (point) "A" 'selective
)))))
5091 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
5092 (let ((org-use-property-inheritance nil
))
5093 (org-entry-get (point) "A" 'selective
))))
5097 (org-test-with-temp-text
5098 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
5099 (org-entry-get (point-max) "A" t
))))
5102 (org-test-with-temp-text
5103 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
5105 (org-entry-get (point-max) "A" t
))))
5108 (org-test-with-temp-text
5109 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
5111 (org-entry-get (point-max) "A" t
)))))
5113 (ert-deftest test-org
/entry-properties
()
5114 "Test `org-entry-properties' specifications."
5115 ;; Get "ITEM" property.
5118 (org-test-with-temp-text "* TODO H"
5119 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
5122 (org-test-with-temp-text "* TODO H"
5123 (cdr (assoc "ITEM" (org-entry-properties))))))
5124 ;; Get "TODO" property. TODO keywords are case sensitive.
5127 (org-test-with-temp-text "* TODO H"
5128 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
5131 (org-test-with-temp-text "* TODO H"
5132 (cdr (assoc "TODO" (org-entry-properties))))))
5134 (org-test-with-temp-text "* H"
5135 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5137 (org-test-with-temp-text "* todo H"
5138 (assoc "TODO" (org-entry-properties nil
"TODO"))))
5139 ;; Get "PRIORITY" property.
5142 (org-test-with-temp-text "* [#A] H"
5143 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5146 (org-test-with-temp-text "* [#A] H"
5147 (cdr (assoc "PRIORITY" (org-entry-properties))))))
5149 (equal (char-to-string org-default-priority
)
5150 (org-test-with-temp-text "* H"
5151 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
5152 ;; Get "FILE" property.
5154 (org-test-with-temp-text-in-file "* H\nParagraph"
5155 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
5156 (buffer-file-name))))
5158 (org-test-with-temp-text-in-file "* H\nParagraph"
5159 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
5160 (buffer-file-name))))
5162 (org-test-with-temp-text "* H\nParagraph"
5163 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
5164 ;; Get "TAGS" property.
5166 (equal ":tag1:tag2:"
5167 (org-test-with-temp-text "* H :tag1:tag2:"
5168 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
5170 (equal ":tag1:tag2:"
5171 (org-test-with-temp-text "* H :tag1:tag2:"
5172 (cdr (assoc "TAGS" (org-entry-properties))))))
5174 (org-test-with-temp-text "* H"
5175 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
5176 ;; Get "ALLTAGS" property.
5178 (equal ":tag1:tag2:"
5179 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5180 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
5182 (equal ":tag1:tag2:"
5183 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
5184 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
5186 (org-test-with-temp-text "* H"
5187 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
5188 ;; Get "BLOCKED" property.
5191 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
5192 (let ((org-enforce-todo-dependencies t
)
5194 '(org-block-todo-from-children-or-siblings-or-parent)))
5195 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5198 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
5199 (let ((org-enforce-todo-dependencies t
)
5201 '(org-block-todo-from-children-or-siblings-or-parent)))
5202 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
5203 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
5207 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5208 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
5212 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
5213 (cdr (assoc "CLOSED" (org-entry-properties))))))
5215 (org-test-with-temp-text "* H"
5216 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
5220 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5221 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5225 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5226 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5228 (org-test-with-temp-text "* H"
5229 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5233 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5234 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5238 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5239 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5241 (org-test-with-temp-text "* H"
5242 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5246 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5247 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5250 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5251 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5254 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5255 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5258 (org-test-with-temp-text
5259 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5261 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5262 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5263 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5265 (equal "<2012-03-29 thu.>"
5266 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5267 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5269 (equal "[2012-03-29 thu.]"
5270 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5271 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5273 (equal "<2012-03-29 thu.>"
5274 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5275 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5277 (equal "[2014-03-04 tue.]"
5278 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5279 (cdr (assoc "TIMESTAMP_IA"
5280 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5282 (equal "<2012-03-29 thu.>"
5283 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5284 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5285 ;; Get standard properties.
5288 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5289 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5290 ;; Handle extended properties.
5293 (org-test-with-temp-text
5294 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5295 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5298 (org-test-with-temp-text
5299 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5300 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5301 ;; Ignore forbidden (special) properties.
5303 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5304 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5306 (ert-deftest test-org
/entry-put
()
5307 "Test `org-entry-put' specifications."
5308 ;; Error when not a string or nil.
5310 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5311 (org-entry-put 1 "test" 2)))
5312 ;; Error when property name is invalid.
5314 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5315 (org-entry-put 1 "no space" "value")))
5317 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5318 (org-entry-put 1 "" "value")))
5319 ;; Set "TODO" property.
5321 (string-match (regexp-quote " TODO H")
5322 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5323 (org-entry-put (point) "TODO" "TODO")
5326 (string-match (regexp-quote "* H")
5327 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5328 (org-entry-put (point) "TODO" nil
)
5330 ;; Set "PRIORITY" property.
5333 (org-test-with-temp-text "* [#B] H"
5334 (org-entry-put (point) "PRIORITY" "A")
5338 (org-test-with-temp-text "* [#B] H"
5339 (org-entry-put (point) "PRIORITY" nil
)
5341 ;; Set "SCHEDULED" property.
5343 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5344 (org-test-with-temp-text "* H"
5345 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5349 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5350 (org-entry-put (point) "SCHEDULED" nil
)
5353 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5354 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5355 (org-entry-put (point) "SCHEDULED" "earlier")
5358 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5359 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5360 (org-entry-put (point) "SCHEDULED" "later")
5362 ;; Set "DEADLINE" property.
5364 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5365 (org-test-with-temp-text "* H"
5366 (org-entry-put (point) "DEADLINE" "2014-03-04")
5370 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5371 (org-entry-put (point) "DEADLINE" nil
)
5374 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5375 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5376 (org-entry-put (point) "DEADLINE" "earlier")
5379 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5380 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5381 (org-entry-put (point) "DEADLINE" "later")
5383 ;; Set "CATEGORY" property
5385 (string-match "^ *:CATEGORY: cat"
5386 (org-test-with-temp-text "* H"
5387 (org-entry-put (point) "CATEGORY" "cat")
5389 ;; Regular properties, with or without pre-existing drawer.
5391 (string-match "^ *:A: +2$"
5392 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5393 (org-entry-put (point) "A" "2")
5396 (string-match "^ *:A: +1$"
5397 (org-test-with-temp-text "* H"
5398 (org-entry-put (point) "A" "1")
5400 ;; Special case: two consecutive headlines.
5402 (string-match "\\* A\n *:PROPERTIES:"
5403 (org-test-with-temp-text "* A\n** B"
5404 (org-entry-put (point) "A" "1")
5407 (ert-deftest test-org
/refresh-properties
()
5408 "Test `org-refresh-properties' specifications."
5411 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5412 (org-refresh-properties "A" 'org-test
)
5413 (get-text-property (point) 'org-test
))))
5415 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5416 (org-refresh-properties "B" 'org-test
)
5417 (get-text-property (point) 'org-test
)))
5418 ;; Handle properties only defined with extension syntax, i.e.,
5422 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5423 (org-refresh-properties "A" 'org-test
)
5424 (get-text-property (point) 'org-test
))))
5425 ;; When property is inherited, add text property to the whole
5429 (org-test-with-temp-text
5430 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5431 (let ((org-use-property-inheritance t
))
5432 (org-refresh-properties "A" 'org-test
))
5433 (get-text-property (point) 'org-test
))))
5434 ;; When property is inherited, use global value across the whole
5435 ;; buffer. However local values have precedence.
5438 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5440 (let ((org-use-property-inheritance nil
))
5441 (org-refresh-properties "A" 'org-test
))
5442 (get-text-property (point) 'org-test
))))
5445 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5447 (let ((org-use-property-inheritance t
))
5448 (org-refresh-properties "A" 'org-test
))
5449 (get-text-property (point) 'org-test
))))
5452 (org-test-with-temp-text
5453 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5455 (let ((org-use-property-inheritance t
))
5456 (org-refresh-properties "A" 'org-test
))
5457 (get-text-property (point) 'org-test
)))))
5462 (ert-deftest test-org
/update-radio-target-regexp
()
5463 "Test `org-update-radio-target-regexp' specifications."
5464 ;; Properly update cache with no previous radio target regexp.
5467 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5468 (save-excursion (goto-char (point-max)) (org-element-context))
5470 (search-forward "o")
5472 (org-update-radio-target-regexp)
5473 (goto-char (point-max))
5474 (org-element-type (org-element-context)))))
5475 ;; Properly update cache with previous radio target regexp.
5478 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5479 (save-excursion (goto-char (point-max)) (org-element-context))
5481 (search-forward "o")
5483 (org-update-radio-target-regexp)
5484 (search-backward "r")
5487 (org-update-radio-target-regexp)
5488 (goto-char (point-max))
5489 (delete-region (line-beginning-position) (point))
5491 (org-element-type (org-element-context))))))
5496 (ert-deftest test-org
/refile-get-targets
()
5497 "Test `org-refile-get-targets' specifications."
5498 ;; :maxlevel includes all headings above specified value.
5500 (equal '("H1" "H2" "H3")
5501 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5502 (let ((org-refile-use-outline-path nil
)
5503 (org-refile-targets `((nil :maxlevel .
3))))
5504 (mapcar #'car
(org-refile-get-targets))))))
5507 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5508 (let ((org-refile-use-outline-path nil
)
5509 (org-refile-targets `((nil :maxlevel .
2))))
5510 (mapcar #'car
(org-refile-get-targets))))))
5511 ;; :level limits targets to headlines with the specified level.
5514 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5515 (let ((org-refile-use-outline-path nil
)
5516 (org-refile-targets `((nil :level .
2))))
5517 (mapcar #'car
(org-refile-get-targets))))))
5518 ;; :tag limits targets to headlines with specified tag.
5521 (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
5522 (let ((org-refile-use-outline-path nil
)
5523 (org-refile-targets `((nil :tag .
"foo"))))
5524 (mapcar #'car
(org-refile-get-targets))))))
5525 ;; :todo limits targets to headlines with specified TODO keyword.
5528 (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
5529 (let ((org-refile-use-outline-path nil
)
5530 (org-refile-targets `((nil :todo .
"TODO"))))
5531 (mapcar #'car
(org-refile-get-targets))))))
5532 ;; :regexp filters targets matching provided regexp.
5535 (org-test-with-temp-text "* H1\n** F2\n*** F3"
5536 (let ((org-refile-use-outline-path nil
)
5537 (org-refile-targets `((nil :regexp .
"F"))))
5538 (mapcar #'car
(org-refile-get-targets))))))
5539 ;; A nil `org-refile-targets' includes only top level headlines in
5543 (org-test-with-temp-text "* H1\n** S1\n* H2"
5544 (let ((org-refile-use-outline-path nil
)
5545 (org-refile-targets nil
))
5546 (mapcar #'car
(org-refile-get-targets))))))
5547 ;; Return value is the union of the targets according to all the
5548 ;; defined rules. However, prevent duplicates.
5550 (equal '("F2" "F3" "H1")
5551 (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
5552 (let ((org-refile-use-outline-path nil
)
5553 (org-refile-targets `((nil :regexp .
"F")
5554 (nil :todo .
"TODO"))))
5555 (mapcar #'car
(org-refile-get-targets))))))
5557 (equal '("F2" "F3" "H1")
5558 (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
5559 (let ((org-refile-use-outline-path nil
)
5560 (org-refile-targets `((nil :regexp .
"F")
5561 (nil :todo .
"TODO"))))
5562 (mapcar #'car
(org-refile-get-targets))))))
5563 ;; When `org-refile-use-outline-path' is non-nil, provide targets as
5566 (equal '("H1" "H1/H2" "H1/H2/H3")
5567 (org-test-with-temp-text "* H1\n** H2\n*** H3"
5568 (let ((org-refile-use-outline-path t
)
5569 (org-refile-targets `((nil :maxlevel .
3))))
5570 (mapcar #'car
(org-refile-get-targets))))))
5571 ;; When providing targets as paths, escape forward slashes in
5572 ;; headings with backslashes.
5574 (equal '("H1\\/foo")
5575 (org-test-with-temp-text "* H1/foo"
5576 (let ((org-refile-use-outline-path t
)
5577 (org-refile-targets `((nil :maxlevel .
1))))
5578 (mapcar #'car
(org-refile-get-targets))))))
5579 ;; When `org-refile-use-outline-path' is `file', include file name
5580 ;; without directory in targets.
5582 (org-test-with-temp-text-in-file "* H1"
5583 (let* ((filename (buffer-file-name))
5584 (org-refile-use-outline-path 'file
)
5585 (org-refile-targets `(((,filename
) :level .
1))))
5586 (member (file-name-nondirectory filename
)
5587 (mapcar #'car
(org-refile-get-targets))))))
5588 ;; When `org-refile-use-outline-path' is `full-file-path', include
5591 (org-test-with-temp-text-in-file "* H1"
5592 (let* ((filename (file-truename (buffer-file-name)))
5593 (org-refile-use-outline-path 'full-file-path
)
5594 (org-refile-targets `(((,filename
) :level .
1))))
5595 (member filename
(mapcar #'car
(org-refile-get-targets))))))
5596 ;; When `org-refile-use-outline-path' is `buffer-name', include
5599 (org-test-with-temp-text "* H1"
5600 (let* ((org-refile-use-outline-path 'buffer-name
)
5601 (org-refile-targets `((nil :level .
1))))
5602 (member (buffer-name) (mapcar #'car
(org-refile-get-targets)))))))
5608 (ert-deftest test-org
/match-sparse-tree
()
5609 "Test `org-match-sparse-tree' specifications."
5612 (org-test-with-temp-text "* H\n** H1 :tag:"
5613 (org-match-sparse-tree nil
"tag")
5614 (search-forward "H1")
5615 (org-invisible-p2)))
5617 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5618 (org-match-sparse-tree nil
"tag")
5619 (search-forward "H2")
5620 (org-invisible-p2)))
5621 ;; "-" operator for tags.
5623 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5624 (org-match-sparse-tree nil
"tag1-tag2")
5625 (search-forward "H1")
5626 (org-invisible-p2)))
5628 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5629 (org-match-sparse-tree nil
"tag1-tag2")
5630 (search-forward "H2")
5631 (org-invisible-p2)))
5632 ;; "&" operator for tags.
5634 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5635 (org-match-sparse-tree nil
"tag1&tag2")
5636 (search-forward "H1")
5637 (org-invisible-p2)))
5639 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5640 (org-match-sparse-tree nil
"tag1&tag2")
5641 (search-forward "H2")
5642 (org-invisible-p2)))
5643 ;; "|" operator for tags.
5645 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5646 (org-match-sparse-tree nil
"tag1|tag2")
5647 (search-forward "H1")
5648 (org-invisible-p2)))
5650 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5651 (org-match-sparse-tree nil
"tag1|tag2")
5652 (search-forward "H2")
5653 (org-invisible-p2)))
5654 ;; Regexp match on tags.
5656 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5657 (org-match-sparse-tree nil
"{^tag.*}")
5658 (search-forward "H1")
5659 (org-invisible-p2)))
5661 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5662 (org-match-sparse-tree nil
"{^tag.*}")
5663 (search-forward "H2")
5664 (org-invisible-p2)))
5665 ;; Match group tags.
5667 (org-test-with-temp-text
5668 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5669 (org-match-sparse-tree nil
"work")
5670 (search-forward "H1")
5671 (org-invisible-p2)))
5673 (org-test-with-temp-text
5674 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5675 (org-match-sparse-tree nil
"work")
5676 (search-forward "H2")
5677 (org-invisible-p2)))
5678 ;; Match group tags with hard brackets.
5680 (org-test-with-temp-text
5681 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5682 (org-match-sparse-tree nil
"work")
5683 (search-forward "H1")
5684 (org-invisible-p2)))
5686 (org-test-with-temp-text
5687 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5688 (org-match-sparse-tree nil
"work")
5689 (search-forward "H2")
5690 (org-invisible-p2)))
5691 ;; Match tags in hierarchies
5693 (org-test-with-temp-text
5694 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5695 #+TAGS: [ Lev_2 : Lev_3 ]\n
5696 #+TAGS: { Lev_3 : Lev_4 }\n
5697 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5698 (org-match-sparse-tree nil
"Lev_1")
5699 (search-forward "H4")
5700 (org-invisible-p2)))
5701 ;; Match regular expressions in tags
5703 (org-test-with-temp-text
5704 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5705 (org-match-sparse-tree nil
"Lev")
5706 (search-forward "H1")
5707 (org-invisible-p2)))
5709 (org-test-with-temp-text
5710 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5711 (org-match-sparse-tree nil
"Lev")
5712 (search-forward "H1")
5713 (org-invisible-p2)))
5714 ;; Match properties.
5716 (org-test-with-temp-text
5717 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5718 (org-match-sparse-tree nil
"A=\"1\"")
5719 (search-forward "H2")
5720 (org-invisible-p2)))
5722 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5723 (org-match-sparse-tree nil
"A=\"1\"")
5724 (search-forward "H2")
5725 (org-invisible-p2)))
5726 ;; Case is not significant when matching properties.
5728 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5729 (org-match-sparse-tree nil
"a=\"1\"")
5730 (search-forward "H2")
5731 (org-invisible-p2)))
5733 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5734 (org-match-sparse-tree nil
"A=\"1\"")
5735 (search-forward "H2")
5736 (org-invisible-p2)))
5737 ;; Match special LEVEL property.
5739 (org-test-with-temp-text "* H\n** H1\n*** H2"
5740 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5741 (search-forward "H1")
5742 (org-invisible-p2)))
5744 (org-test-with-temp-text "* H\n** H1\n*** H2"
5745 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5746 (search-forward "H2")
5747 (org-invisible-p2)))
5748 ;; Comparison operators when matching properties.
5750 (org-test-with-temp-text
5751 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5752 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5753 (search-forward "H1")
5754 (org-invisible-p2)))
5756 (org-test-with-temp-text
5757 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5758 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5759 (search-forward "H2")
5760 (org-invisible-p2)))
5761 ;; Regexp match on properties values.
5763 (org-test-with-temp-text
5764 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5765 (org-match-sparse-tree nil
"A={f.*}")
5766 (search-forward "H1")
5767 (org-invisible-p2)))
5769 (org-test-with-temp-text
5770 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5771 (org-match-sparse-tree nil
"A={f.*}")
5772 (search-forward "H2")
5773 (org-invisible-p2)))
5774 ;; With an optional argument, limit match to TODO entries.
5776 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5777 (org-match-sparse-tree t
"tag")
5778 (search-forward "H1")
5779 (org-invisible-p2)))
5781 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5782 (org-match-sparse-tree t
"tag")
5783 (search-forward "H2")
5784 (org-invisible-p2))))
5786 (ert-deftest test-org
/occur
()
5787 "Test `org-occur' specifications."
5788 ;; Count number of matches.
5791 (org-test-with-temp-text "* H\nA\n* H2"
5795 (org-test-with-temp-text "* H\nA\n* H2\nA"
5797 ;; Test CALLBACK optional argument.
5800 (org-test-with-temp-text "* H\nA\n* H2"
5801 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5804 (org-test-with-temp-text "* H\nA\n* H2\nA"
5805 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5806 ;; Case-fold searches according to `org-occur-case-fold-search'.
5809 (org-test-with-temp-text "Aa"
5810 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5813 (org-test-with-temp-text "Aa"
5814 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5817 (org-test-with-temp-text "Aa"
5818 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5821 (org-test-with-temp-text "Aa"
5822 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5825 (org-test-with-temp-text "Aa"
5826 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5829 (org-test-with-temp-text "Aa"
5830 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5835 (ert-deftest test-org
/tag-string-to-alist
()
5836 "Test `org-tag-string-to-alist' specifications."
5837 ;; Tag without selection key.
5838 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5839 ;; Tag with selection key.
5840 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5844 (org-tag-string-to-alist "[ group : t1 t2 ]")
5845 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5846 ;; Mutually exclusive tags.
5847 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5848 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5851 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5852 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5854 (ert-deftest test-org
/tag-alist-to-string
()
5855 "Test `org-tag-alist-to-string' specifications."
5856 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5857 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5860 (org-tag-alist-to-string
5861 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5862 "[ group : t1 t2 ]"))
5864 (equal (org-tag-alist-to-string
5865 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5869 (org-tag-alist-to-string
5870 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5871 "{ group : tag1 tag2 }")))
5873 (ert-deftest test-org
/tag-alist-to-groups
()
5874 "Test `org-tag-alist-to-groups' specifications."
5876 (equal (org-tag-alist-to-groups
5877 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5878 '(("group" "t1" "t2"))))
5881 (org-tag-alist-to-groups
5882 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5883 '(("group" "t1" "t2"))))
5885 (org-tag-alist-to-groups
5886 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5888 (ert-deftest test-org
/tag-align
()
5889 "Test tags alignment."
5890 ;; Test aligning tags with different display width.
5892 ;; 12345678901234567890
5893 (equal "* Test :abc:"
5894 (org-test-with-temp-text "* Test :abc:"
5895 (let ((org-tags-column -
20)
5896 (indent-tabs-mode nil
))
5897 (org-fix-tags-on-the-fly))
5900 ;; 12345678901234567890
5901 (equal "* Test :日本語:"
5902 (org-test-with-temp-text "* Test :日本語:"
5903 (let ((org-tags-column -
20)
5904 (indent-tabs-mode nil
))
5905 (org-fix-tags-on-the-fly))
5907 ;; Make sure aligning tags do not skip invisible text.
5909 (equal "* [[linkx]] :tag:"
5910 (org-test-with-temp-text "* [[link<point>]] :tag:"
5911 (let ((org-tags-column 0))
5912 (org-fix-tags-on-the-fly)
5914 (buffer-string))))))
5916 (ert-deftest test-org
/tags-at
()
5918 (equal '("foo" "bar")
5919 (org-test-with-temp-text
5920 "* T<point>est :foo:bar:"
5921 (org-get-tags-at)))))
5926 (ert-deftest test-org
/auto-repeat-maybe
()
5927 "Test `org-auto-repeat-maybe' specifications."
5928 ;; Do not auto repeat when there is no valid time stamp with
5929 ;; a repeater in the entry.
5933 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5934 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5940 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5941 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5944 ;; When switching to DONE state, switch back to first TODO keyword
5945 ;; in sequence, or the same keyword if they have different types.
5949 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5950 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5956 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5957 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5963 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5964 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5967 ;; If there was no TODO keyword in the first place, do not insert
5972 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5973 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5976 ;; Revert to REPEAT_TO_STATE, if set.
5980 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5981 (org-test-with-temp-text
5984 :REPEAT_TO_STATE: KWD2
5986 <2012-03-29 Thu +2y>"
5989 ;; When switching to DONE state, update base date. If there are
5990 ;; multiple repeated time stamps, update them all.
5993 "<2014-03-29 .* \\+2y>"
5994 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5995 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
6000 "<2015-03-04 .* \\+1y>"
6001 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6002 (org-test-with-temp-text
6003 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
6006 ;; Throw an error if repeater unit is the hour and no time is
6007 ;; provided in the time-stamp.
6009 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6010 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
6013 ;; Do not repeat commented time stamps.
6016 "<2015-03-04 .* \\+1y>"
6017 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6018 (org-test-with-temp-text
6019 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
6024 "<2015-03-04 .* \\+1y>"
6025 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6026 (org-test-with-temp-text
6028 <2012-03-29 Thu. +2y>
6030 <2014-03-04 Tue +1y>
6034 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
6035 ;; entry, record time of last repeat.
6039 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6040 (org-log-repeat nil
))
6041 (cl-letf (((symbol-function 'org-add-log-setup
)
6042 (lambda (&rest args
) nil
)))
6043 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6045 (buffer-string))))))
6049 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
6051 (cl-letf (((symbol-function 'org-add-log-setup
)
6052 (lambda (&rest args
) nil
)))
6053 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
6055 (buffer-string))))))
6059 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6060 (cl-letf (((symbol-function 'org-add-log-setup
)
6061 (lambda (&rest args
) nil
)))
6062 (org-test-with-temp-text
6063 "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
6065 (buffer-string))))))
6066 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
6067 ;; the entry as it is no longer relevant.
6071 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
6072 (org-test-with-temp-text
6073 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
6076 ;; Properly advance repeater even when a clock entry is specified
6077 ;; and `org-log-repeat' is nil.
6080 "SCHEDULED: <2014-03-29"
6081 (let ((org-log-repeat nil
)
6082 (org-todo-keywords '((sequence "TODO" "DONE"))))
6083 (org-test-with-temp-text
6085 SCHEDULED: <2012-03-29 Thu +2y>
6086 CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
6088 (buffer-string))))))
6093 (ert-deftest test-org
/at-timestamp-p
()
6094 "Test `org-at-timestamp-p' specifications."
6096 (org-test-with-temp-text "<2012-03-29 Thu>"
6097 (org-at-timestamp-p)))
6099 (org-test-with-temp-text "2012-03-29 Thu"
6100 (org-at-timestamp-p)))
6101 ;; Test return values.
6104 (org-test-with-temp-text "<2012-03-29 Thu>"
6105 (org-at-timestamp-p))))
6108 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
6109 (org-at-timestamp-p))))
6112 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
6113 (org-at-timestamp-p))))
6116 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
6117 (org-at-timestamp-p))))
6120 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
6121 (org-at-timestamp-p))))
6124 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
6125 (org-at-timestamp-p))))
6128 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
6129 (org-at-timestamp-p))))
6132 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
6133 (org-at-timestamp-p))))
6134 ;; Test `inactive' optional argument.
6136 (org-test-with-temp-text "[2012-03-29 Thu]"
6137 (org-at-timestamp-p 'inactive
)))
6139 (org-test-with-temp-text "[2012-03-29 Thu]"
6140 (org-at-timestamp-p)))
6141 ;; When optional argument is `agenda', recognize time-stamps in
6142 ;; planning info line, property drawers and clocks.
6144 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6145 (org-at-timestamp-p 'agenda
)))
6147 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
6148 (org-at-timestamp-p)))
6150 (org-test-with-temp-text
6151 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6152 (org-at-timestamp-p 'agenda
)))
6154 (org-test-with-temp-text
6155 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
6156 (org-at-timestamp-p)))
6158 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6159 (let ((org-agenda-include-inactive-timestamps t
))
6160 (org-at-timestamp-p 'agenda
))))
6162 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6163 (let ((org-agenda-include-inactive-timestamps t
))
6164 (org-at-timestamp-p))))
6166 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
6167 (let ((org-agenda-include-inactive-timestamps t
))
6168 (org-at-timestamp-p 'inactive
))))
6169 ;; When optional argument is `lax', match any part of the document
6170 ;; with Org timestamp syntax.
6172 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6173 (org-at-timestamp-p 'lax
)))
6175 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
6176 (org-at-timestamp-p)))
6178 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6179 (org-at-timestamp-p 'lax
)))
6181 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
6182 (org-at-timestamp-p)))
6184 (org-test-with-temp-text
6185 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6186 (org-at-timestamp-p 'lax
)))
6188 (org-test-with-temp-text
6189 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
6190 (org-at-timestamp-p)))
6191 ;; Optional argument `lax' also matches inactive timestamps.
6193 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
6194 (org-at-timestamp-p 'lax
))))
6196 (ert-deftest test-org
/time-stamp
()
6197 "Test `org-time-stamp' specifications."
6198 ;; Insert chosen time stamp at point.
6201 "Te<2014-03-04 .*?>xt"
6202 (org-test-with-temp-text "Te<point>xt"
6203 (cl-letf (((symbol-function 'org-read-date
)
6204 (lambda (&rest args
)
6205 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6206 (org-time-stamp nil
)
6208 ;; With a prefix argument, also insert time.
6211 "Te<2014-03-04 .*? 00:41>xt"
6212 (org-test-with-temp-text "Te<point>xt"
6213 (cl-letf (((symbol-function 'org-read-date
)
6214 (lambda (&rest args
)
6215 (apply #'encode-time
6216 (org-parse-time-string "2014-03-04 00:41")))))
6217 (org-time-stamp '(4))
6219 ;; With two universal prefix arguments, insert an active timestamp
6220 ;; with the current time without prompting the user.
6223 "Te<2014-03-04 .*? 00:41>xt"
6224 (org-test-with-temp-text "Te<point>xt"
6225 (cl-letf (((symbol-function 'current-time
)
6227 (apply #'encode-time
6228 (org-parse-time-string "2014-03-04 00:41")))))
6229 (org-time-stamp '(16))
6231 ;; When optional argument is non-nil, insert an inactive timestamp.
6234 "Te\\[2014-03-04 .*?\\]xt"
6235 (org-test-with-temp-text "Te<point>xt"
6236 (cl-letf (((symbol-function 'org-read-date
)
6237 (lambda (&rest args
)
6238 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6239 (org-time-stamp nil t
)
6241 ;; When called from a timestamp, replace existing one.
6245 (org-test-with-temp-text "<2012-03-29<point> thu.>"
6246 (cl-letf (((symbol-function 'org-read-date
)
6247 (lambda (&rest args
)
6248 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6249 (org-time-stamp nil
)
6253 "<2014-03-04 .*?>--<2014-03-04 .*?>"
6254 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
6255 (cl-letf (((symbol-function 'org-read-date
)
6256 (lambda (&rest args
)
6257 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6258 (org-time-stamp nil
)
6260 ;; When replacing a timestamp, preserve repeater, if any.
6263 "<2014-03-04 .*? \\+2y>"
6264 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
6265 (cl-letf (((symbol-function 'org-read-date
)
6266 (lambda (&rest args
)
6267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6268 (org-time-stamp nil
)
6270 ;; When called twice in a raw, build a date range.
6273 "<2012-03-29 .*?>--<2014-03-04 .*?>"
6274 (org-test-with-temp-text "<2012-03-29 thu.><point>"
6275 (cl-letf (((symbol-function 'org-read-date
)
6276 (lambda (&rest args
)
6277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
6278 (let ((last-command 'org-time-stamp
)
6279 (this-command 'org-time-stamp
))
6280 (org-time-stamp nil
))
6281 (buffer-string))))))
6283 (ert-deftest test-org
/timestamp-has-time-p
()
6284 "Test `org-timestamp-has-time-p' specifications."
6287 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6288 (org-timestamp-has-time-p (org-element-context))))
6291 (org-test-with-temp-text "<2012-03-29 Thu>"
6292 (org-timestamp-has-time-p (org-element-context)))))
6294 (ert-deftest test-org
/get-repeat
()
6295 "Test `org-get-repeat' specifications."
6297 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
6300 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
6302 ;; Return proper repeat string.
6305 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
6307 ;; Prevent false positive (commented or verbatim time stamps)
6309 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
6312 (org-test-with-temp-text
6313 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
6315 ;; Return nil when called before first heading.
6317 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
6319 ;; When called with an optional argument, extract repeater from that
6321 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
6322 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
6324 (ert-deftest test-org
/timestamp-format
()
6325 "Test `org-timestamp-format' specifications."
6330 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
6331 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
6336 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
6337 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
6339 (ert-deftest test-org
/timestamp-split-range
()
6340 "Test `org-timestamp-split-range' specifications."
6341 ;; Extract range start (active).
6344 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6345 (let ((ts (org-timestamp-split-range (org-element-context))))
6346 (mapcar (lambda (p) (org-element-property p ts
))
6347 '(:year-end
:month-end
:day-end
))))))
6348 ;; Extract range start (inactive)
6351 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6352 (let ((ts (org-timestamp-split-range (org-element-context))))
6353 (mapcar (lambda (p) (org-element-property p ts
))
6354 '(:year-end
:month-end
:day-end
))))))
6355 ;; Extract range end (active).
6358 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6359 (let ((ts (org-timestamp-split-range
6360 (org-element-context) t
)))
6361 (mapcar (lambda (p) (org-element-property p ts
))
6362 '(:year-end
:month-end
:day-end
))))))
6363 ;; Extract range end (inactive)
6366 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6367 (let ((ts (org-timestamp-split-range
6368 (org-element-context) t
)))
6369 (mapcar (lambda (p) (org-element-property p ts
))
6370 '(:year-end
:month-end
:day-end
))))))
6371 ;; Return the timestamp if not a range.
6373 (org-test-with-temp-text "[2012-03-29 Thu]"
6374 (let* ((ts-orig (org-element-context))
6375 (ts-copy (org-timestamp-split-range ts-orig
)))
6376 (eq ts-orig ts-copy
))))
6378 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6379 (let* ((ts-orig (org-element-context))
6380 (ts-copy (org-timestamp-split-range ts-orig
)))
6381 (eq ts-orig ts-copy
)))))
6383 (ert-deftest test-org
/timestamp-translate
()
6384 "Test `org-timestamp-translate' specifications."
6385 ;; Translate whole date range.
6388 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6389 (let ((org-display-custom-times t
)
6390 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6391 (org-timestamp-translate (org-element-context))))))
6392 ;; Translate date range start.
6395 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6396 (let ((org-display-custom-times t
)
6397 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6398 (org-timestamp-translate (org-element-context) 'start
)))))
6399 ;; Translate date range end.
6402 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6403 (let ((org-display-custom-times t
)
6404 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6405 (org-timestamp-translate (org-element-context) 'end
)))))
6406 ;; Translate time range.
6409 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6410 (let ((org-display-custom-times t
)
6411 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6412 (org-timestamp-translate (org-element-context))))))
6413 ;; Translate non-range timestamp.
6416 (org-test-with-temp-text "<2012-03-29 Thu>"
6417 (let ((org-display-custom-times t
)
6418 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6419 (org-timestamp-translate (org-element-context))))))
6420 ;; Do not change `diary' timestamps.
6422 (equal "<%%(org-float t 4 2)>"
6423 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6424 (let ((org-display-custom-times t
)
6425 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6426 (org-timestamp-translate (org-element-context)))))))
6432 (ert-deftest test-org
/flag-drawer
()
6433 "Test `org-flag-drawer' specifications."
6436 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6438 (get-char-property (line-end-position) 'invisible
)))
6441 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6443 (org-flag-drawer nil
)
6444 (get-char-property (line-end-position) 'invisible
)))
6445 ;; Test optional argument.
6447 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6448 (let ((drawer (save-excursion (search-forward ":D2")
6449 (org-element-at-point))))
6450 (org-flag-drawer t drawer
)
6451 (get-char-property (progn (search-forward ":D2") (line-end-position))
6454 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6455 (let ((drawer (save-excursion (search-forward ":D2")
6456 (org-element-at-point))))
6457 (org-flag-drawer t drawer
)
6458 (get-char-property (line-end-position) 'invisible
))))
6459 ;; Do not hide fake drawers.
6461 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6464 (get-char-property (line-end-position) 'invisible
)))
6465 ;; Do not hide incomplete drawers.
6467 (org-test-with-temp-text ":D:\nparagraph"
6470 (get-char-property (line-end-position) 'invisible
)))
6471 ;; Do not hide drawers when called from final blank lines.
6473 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6474 (goto-char (point-max))
6476 (goto-char (point-min))
6477 (get-char-property (line-end-position) 'invisible
)))
6478 ;; Don't leave point in an invisible part of the buffer when hiding
6481 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6482 (goto-char (point-max))
6484 (get-char-property (point) 'invisible
))))
6486 (ert-deftest test-org
/hide-block-toggle
()
6487 "Test `org-hide-block-toggle' specifications."
6488 ;; Error when not at a block.
6490 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6491 (org-hide-block-toggle 'off
)
6492 (get-char-property (line-end-position) 'invisible
)))
6495 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6496 (org-hide-block-toggle)
6497 (get-char-property (line-end-position) 'invisible
)))
6499 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6500 (org-hide-block-toggle)
6501 (get-char-property (line-end-position) 'invisible
)))
6502 ;; Show block unconditionally when optional argument is `off'.
6504 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6505 (org-hide-block-toggle)
6506 (org-hide-block-toggle 'off
)
6507 (get-char-property (line-end-position) 'invisible
)))
6509 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6510 (org-hide-block-toggle 'off
)
6511 (get-char-property (line-end-position) 'invisible
)))
6512 ;; Hide block unconditionally when optional argument is non-nil.
6514 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6515 (org-hide-block-toggle t
)
6516 (get-char-property (line-end-position) 'invisible
)))
6518 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6519 (org-hide-block-toggle)
6520 (org-hide-block-toggle t
)
6521 (get-char-property (line-end-position) 'invisible
)))
6522 ;; Do not hide block when called from final blank lines.
6524 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6525 (org-hide-block-toggle)
6526 (goto-char (point-min))
6527 (get-char-property (line-end-position) 'invisible
)))
6528 ;; Don't leave point in an invisible part of the buffer when hiding
6531 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6532 (org-hide-block-toggle)
6533 (get-char-property (point) 'invisible
))))
6535 (ert-deftest test-org
/hide-block-toggle-maybe
()
6536 "Test `org-hide-block-toggle-maybe' specifications."
6538 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6539 (org-hide-block-toggle-maybe)))
6541 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6543 (ert-deftest test-org
/set-tags
()
6544 "Test `org-set-tags' specifications."
6545 ;; Tags set via fast-tag-selection should be visible afterwards
6547 (let ((org-tag-alist '(("NEXT" . ?n
)))
6548 (org-fast-tag-selection-single-key t
))
6549 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6550 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6551 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6552 ;; Show only headlines
6554 ;; Set NEXT tag on current entry
6555 (org-set-tags nil nil
)
6556 ;; Move point to that NEXT tag
6557 (search-forward "NEXT") (backward-word)
6558 ;; And it should be visible (i.e. no overlays)
6559 (not (overlays-at (point))))))))
6561 (ert-deftest test-org
/show-set-visibility
()
6562 "Test `org-show-set-visibility' specifications."
6563 ;; Do not throw an error before first heading.
6565 (org-test-with-temp-text "Preamble\n* Headline"
6566 (org-show-set-visibility 'tree
)
6568 ;; Test all visibility spans, both on headline and in entry.
6569 (let ((list-visible-lines
6570 (lambda (state headerp
)
6571 (org-test-with-temp-text "* Grandmother (0)
6582 **** The other child (11)
6587 (search-forward (if headerp
"Self" "Match"))
6588 (org-show-set-visibility state
)
6589 (goto-char (point-min))
6590 (let (result (line 0))
6592 (unless (org-invisible-p2) (push line result
))
6595 (nreverse result
))))))
6596 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6597 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6598 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6599 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6600 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6601 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6602 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6603 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6604 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6605 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6606 (funcall list-visible-lines
'tree nil
)))
6607 (should (equal '(0 1 3 4 5 7 12 13)
6608 (funcall list-visible-lines
'canonical t
)))
6609 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6610 (funcall list-visible-lines
'canonical nil
))))
6611 ;; When point is hidden in a drawer or a block, make sure to make it
6614 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6615 (org-hide-block-toggle)
6616 (search-forward "Text")
6617 (org-show-set-visibility 'minimal
)
6618 (org-invisible-p2)))
6620 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6622 (search-forward "Text")
6623 (org-show-set-visibility 'minimal
)
6624 (org-invisible-p2)))
6626 (org-test-with-temp-text
6627 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6630 (org-hide-block-toggle)
6631 (search-forward "Text")
6632 (org-show-set-visibility 'minimal
)
6633 (org-invisible-p2))))
6635 (defun test-org/copy-visible
()
6636 "Test `org-copy-visible' specifications."
6639 (org-test-with-temp-text "Foo"
6640 (let ((kill-ring nil
))
6641 (org-copy-visible (point-min) (point-max))
6642 (current-kill 0 t
)))))
6643 ;; Skip invisible characters by text property.
6646 (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t
))
6647 (let ((kill-ring nil
))
6648 (org-copy-visible (point-min) (point-max))
6649 (current-kill 0 t
)))))
6650 ;; Skip invisible characters by overlay.
6653 (org-test-with-temp-text "F<hidden>oo"
6654 (let ((o (make-overlay 2 10)))
6655 (overlay-put o
'invisible t
))
6656 (let ((kill-ring nil
))
6657 (org-copy-visible (point-min) (point-max))
6658 (current-kill 0 t
)))))
6659 ;; Handle invisible characters at the beginning and the end of the
6663 (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t
))
6664 (let ((kill-ring nil
))
6665 (org-copy-visible (point-min) (point-max))
6666 (current-kill 0 t
)))))
6669 (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t
))
6670 (let ((kill-ring nil
))
6671 (org-copy-visible (point-min) (point-max))
6672 (current-kill 0 t
)))))
6673 ;; Handle multiple visible parts.
6676 (org-test-with-temp-text
6677 #("aXbXc" 1 2 (invisible t
) 3 4 (invisible t
))
6678 (let ((kill-ring nil
))
6679 (org-copy-visible (point-min) (point-max))
6680 (current-kill 0 t
))))))
6685 ;;; test-org.el ends here