1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (progn (call-interactively 'comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (progn (call-interactively 'comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# Comment"
106 (progn (forward-line)
107 (let ((org-adapt-indentation t
))
108 (call-interactively 'comment-dwim
))
110 ;; Also recognize single # at column 0 as comments.
113 (org-test-with-temp-text "# Comment"
114 (progn (forward-line)
115 (call-interactively 'comment-dwim
)
117 ;; Region selected and only comments and blank lines within it:
118 ;; un-comment all commented lines.
120 (equal "Comment 1\n\nComment 2"
121 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
123 (transient-mark-mode 1)
124 (push-mark (point) t t
)
125 (goto-char (point-max))
126 (call-interactively 'comment-dwim
)
128 ;; Region selected without comments: comment all lines if
129 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
131 (equal "# Comment 1\n\n# Comment 2"
132 (org-test-with-temp-text "Comment 1\n\nComment 2"
134 (transient-mark-mode 1)
135 (push-mark (point) t t
)
136 (goto-char (point-max))
137 (let ((comment-empty-lines nil
))
138 (call-interactively 'comment-dwim
))
141 (equal "# Comment 1\n# \n# Comment 2"
142 (org-test-with-temp-text "Comment 1\n\nComment 2"
144 (transient-mark-mode 1)
145 (push-mark (point) t t
)
146 (goto-char (point-max))
147 (let ((comment-empty-lines t
))
148 (call-interactively 'comment-dwim
))
150 ;; In front of a keyword without region, insert a new comment.
152 (equal "# \n#+KEYWORD: value"
153 (org-test-with-temp-text "#+KEYWORD: value"
154 (progn (call-interactively 'comment-dwim
)
156 ;; In a source block, use appropriate syntax.
159 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively 'comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position) (point)))))
165 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
166 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
168 (transient-mark-mode 1)
169 (push-mark (point) t t
)
171 (let ((org-edit-src-content-indentation 2))
172 (call-interactively 'comment-dwim
))
177 ;;; Date and time analysis
179 (ert-deftest test-org
/org-read-date
()
180 "Test `org-read-date' specifications."
181 ;; Parse ISO date with abbreviated year and month.
182 (should (equal "2012-03-29 16:40"
183 (let ((org-time-was-given t
))
184 (org-read-date t nil
"12-3-29 16:40"))))
185 ;; Parse Europeans dates.
186 (should (equal "2012-03-29 16:40"
187 (let ((org-time-was-given t
))
188 (org-read-date t nil
"29.03.2012 16:40"))))
189 ;; Parse Europeans dates without year.
190 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
191 (let ((org-time-was-given t
))
192 (org-read-date t nil
"29.03. 16:40"))))
193 ;; Relative date applied to current time if there is single
194 ;; plus/minus, or to default date when there are two of them.
198 (cl-letf (((symbol-function 'current-time
)
200 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
203 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
207 (cl-letf (((symbol-function 'current-time
)
209 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (cl-letf (((symbol-function 'current-time
)
221 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
222 (let ((org-read-date-prefer-future t
))
223 (org-read-date t nil
"1")))))
227 (cl-letf (((symbol-function 'current-time
)
229 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
230 (let ((org-read-date-prefer-future t
))
231 (org-read-date t nil
"3-4")))))
235 (cl-letf (((symbol-function 'current-time
)
237 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
238 (let ((org-read-date-prefer-future nil
))
239 (org-read-date t nil
"3-4")))))
240 ;; When set to `org-read-date-prefer-future' is set to `time', read
241 ;; day is moved to tomorrow if specified hour is before current
242 ;; time. However, it only happens in no other part of the date is
247 (cl-letf (((symbol-function 'current-time
)
249 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
250 (let ((org-read-date-prefer-future 'time
))
251 (org-read-date t nil
"00:40" nil
)))))
255 (cl-letf (((symbol-function 'current-time
)
257 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
258 (let ((org-read-date-prefer-future 'time
))
259 (org-read-date t nil
"29 00:40" nil
)))))
260 ;; Caveat: `org-read-date-prefer-future' always refers to current
261 ;; time, not default time, when they differ.
265 (cl-letf (((symbol-function 'current-time
)
267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
268 (let ((org-read-date-prefer-future t
))
271 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
275 (cl-letf (((symbol-function 'current-time
)
277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
278 (let ((org-read-date-prefer-future t
))
281 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
283 (ert-deftest test-org
/org-parse-time-string
()
284 "Test `org-parse-time-string'."
285 (should (equal (org-parse-time-string "2012-03-29 16:40")
286 '(0 40 16 29 3 2012 nil nil nil
)))
287 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
288 '(0 40 16 29 3 2012 nil nil nil
)))
289 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
290 '(0 40 16 29 3 2012 nil nil nil
)))
291 (should (equal (org-parse-time-string "<2012-03-29>")
292 '(0 0 0 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>" t
)
294 '(0 nil nil
29 3 2012 nil nil nil
))))
296 (ert-deftest test-org
/closest-date
()
297 "Test `org-closest-date' specifications."
299 ;; Time stamps without a repeater are returned unchanged.
303 (calendar-gregorian-from-absolute
304 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
305 ;; Time stamps with a null repeater are returned unchanged.
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
311 ;; if PREFER is set to `past' always return a date before, or equal
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
323 ;; if PREFER is set to `future' always return a date before, or equal
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
333 (calendar-gregorian-from-absolute
334 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
335 ;; If PREFER is neither `past' nor `future', select closest date.
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
346 ;; Test "day" repeater.
349 (calendar-gregorian-from-absolute
350 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
355 ;; Test "month" repeater.
358 (calendar-gregorian-from-absolute
359 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
364 ;; Test "year" repeater.
367 (calendar-gregorian-from-absolute
368 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
371 (calendar-gregorian-from-absolute
372 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
374 (ert-deftest test-org
/deadline-close-p
()
375 "Test `org-deadline-close-p' specifications."
376 ;; Pretend that the current time is 2016-06-03 Fri 01:43
377 (cl-letf (((symbol-function 'current-time
)
378 (lambda () '(22353 6425 905205 644000))))
379 ;; Timestamps are close if they are within `ndays' of lead time.
380 (org-test-with-temp-text "* Heading"
381 (should (org-deadline-close-p "2016-06-03 Fri" 0))
382 (should (org-deadline-close-p "2016-06-02 Thu" 0))
383 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
384 (should (org-deadline-close-p "2016-06-04 Sat" 1))
385 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
386 ;; Read `ndays' from timestamp if argument not given.
387 (org-test-with-temp-text "* H"
388 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
389 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
390 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
391 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
392 ;; Prefer `ndays' argument over lead time in timestamp.
393 (org-test-with-temp-text "* H"
394 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
395 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
396 ;; Completed tasks are never close.
397 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
398 (org-test-with-temp-text "* TODO Heading"
399 (should (org-deadline-close-p "2016-06-03")))
400 (org-test-with-temp-text "* DONE Heading"
401 (should-not (org-deadline-close-p "2016-06-03"))))))
406 (ert-deftest test-org
/insert-property-drawer
()
407 "Test `org-insert-property-drawer' specifications."
408 ;; Error before first headline.
409 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
410 ;; Insert drawer right after headline if there is no planning line,
411 ;; or after it otherwise.
413 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
414 (org-test-with-temp-text "* H\nParagraph<point>"
415 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
418 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
419 (org-test-with-temp-text
420 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
421 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
423 ;; Indent inserted drawer.
425 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
426 (org-test-with-temp-text "* H\nParagraph<point>"
427 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
429 ;; Handle insertion at eob.
431 (equal "* H\n:PROPERTIES:\n:END:\n"
432 (org-test-with-temp-text "* H"
433 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
435 ;; Skip inlinetasks before point.
436 (when (featurep 'org-inlinetask
)
438 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
439 (org-test-with-temp-text
440 "* H\n*************** I\n*************** END\nP<point>"
441 (let ((org-adapt-indentation nil
)
442 (org-inlinetask-min-level 15))
443 (org-insert-property-drawer))
445 ;; Correctly set drawer in an inlinetask.
446 (when (featurep 'org-inlinetask
)
448 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
449 (org-test-with-temp-text
450 "* H\n*************** I\nP<point>\n*************** END"
451 (let ((org-adapt-indentation nil
)
452 (org-inlinetask-min-level 15))
453 (org-insert-property-drawer))
459 (ert-deftest test-org
/fill-paragraph
()
460 "Test `org-fill-paragraph' specifications."
461 ;; At an Org table, align it.
464 (org-test-with-temp-text "|a|"
468 (equal "#+name: table\n| a |\n"
469 (org-test-with-temp-text "#+name: table\n| a |\n"
472 ;; At a paragraph, preserve line breaks.
473 (org-test-with-temp-text "some \\\\\nlong\ntext"
474 (let ((fill-column 20))
476 (should (equal (buffer-string) "some \\\\\nlong text"))))
477 ;; Correctly fill a paragraph when point is at its very end.
480 (org-test-with-temp-text "A\nB"
481 (let ((fill-column 20))
482 (goto-char (point-max))
485 ;; Correctly fill the last paragraph of a greater element.
487 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
488 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
489 (let ((fill-column 8))
494 ;; Correctly fill an element in a narrowed buffer.
497 (org-test-with-temp-text "01234 6789"
498 (let ((fill-column 5))
499 (narrow-to-region 1 8)
502 ;; Handle `adaptive-fill-regexp' in paragraphs.
505 (org-test-with-temp-text "> a\n> b"
506 (let ((fill-column 5)
507 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
510 ;; Special case: Fill first paragraph when point is at an item or
511 ;; a plain-list or a footnote reference.
514 (org-test-with-temp-text "- A\n B"
515 (let ((fill-column 20))
520 (org-test-with-temp-text "[fn:1] A\nB"
521 (let ((fill-column 20))
524 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
525 (let ((fill-column 20))
527 (should (equal (buffer-string)
528 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
529 ;; Fill contents of `comment-block' elements.
532 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
533 (let ((fill-column 20))
537 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
538 ;; Fill `comment' elements.
541 (org-test-with-temp-text " # A\n # B"
542 (let ((fill-column 20))
545 ;; Do not mix consecutive comments when filling one of them.
547 (equal "# A B\n\n# C"
548 (org-test-with-temp-text "# A\n# B\n\n# C"
549 (let ((fill-column 20))
552 ;; Use commented empty lines as separators when filling comments.
554 (equal "# A B\n#\n# C"
555 (org-test-with-temp-text "# A\n# B\n#\n# C"
556 (let ((fill-column 20))
559 ;; Handle `adaptive-fill-regexp' in comments.
562 (org-test-with-temp-text "# > a\n# > b"
563 (let ((fill-column 20)
564 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
567 ;; Do nothing at affiliated keywords.
568 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
569 (let ((fill-column 20))
571 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
572 ;; Do not move point after table when filling a table.
574 (org-test-with-temp-text "| a | b |\n| c | d |\n"
579 (ert-deftest test-org
/auto-fill-function
()
580 "Test auto-filling features."
581 ;; Auto fill paragraph.
584 (org-test-with-temp-text "12345 7890"
585 (let ((fill-column 5))
587 (org-auto-fill-function)
589 ;; Auto fill first paragraph in an item.
591 (equal "- 12345\n 7890"
592 (org-test-with-temp-text "- 12345 7890"
593 (let ((fill-column 7))
595 (org-auto-fill-function)
597 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
599 (equal "> 12345\n 7890"
600 (org-test-with-temp-text "> 12345 7890"
601 (let ((fill-column 10)
602 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
603 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
605 (org-auto-fill-function)
608 (equal "> 12345\n> 12345\n> 7890"
609 (org-test-with-temp-text "> 12345\n> 12345 7890"
610 (let ((fill-column 10)
611 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
612 (goto-char (point-max))
613 (org-auto-fill-function)
616 (equal " 12345\n *12345\n *12345"
617 (org-test-with-temp-text " 12345\n *12345 12345"
618 (let ((fill-column 10)
619 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
620 (goto-char (point-max))
621 (org-auto-fill-function)
623 ;; Auto fill comments.
625 (equal " # 12345\n # 7890"
626 (org-test-with-temp-text " # 12345 7890"
627 (let ((fill-column 10))
629 (org-auto-fill-function)
631 ;; A hash within a line isn't a comment.
633 (equal "12345 # 7890\n# 1"
634 (org-test-with-temp-text "12345 # 7890 1"
635 (let ((fill-column 12))
637 (org-auto-fill-function)
639 ;; Correctly interpret empty prefix.
641 (equal "# a\n# b\nRegular\n# paragraph"
642 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
643 (let ((fill-column 12))
645 (org-auto-fill-function)
647 ;; Comment block: auto fill contents.
649 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
650 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
651 (let ((fill-column 5))
654 (org-auto-fill-function)
657 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
658 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
659 (let ((fill-column 5))
662 (org-auto-fill-function)
664 ;; Do not fill if a new item could be created.
667 (org-test-with-temp-text "12345 - 90"
668 (let ((fill-column 5))
670 (org-auto-fill-function)
672 ;; Do not fill if a line break could be introduced.
674 (equal "123\\\\\n7890"
675 (org-test-with-temp-text "123\\\\ 7890"
676 (let ((fill-column 6))
678 (org-auto-fill-function)
680 ;; Do not fill affiliated keywords.
682 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
683 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
684 (let ((fill-column 20))
686 (org-auto-fill-function)
693 (ert-deftest test-org
/indent-line
()
694 "Test `org-indent-line' specifications."
695 ;; Do not indent diary sexps, footnote definitions or headlines.
698 (org-test-with-temp-text "%%(org-calendar-holiday)"
700 (org-get-indentation))))
703 (org-test-with-temp-text "[fn:1] fn"
704 (let ((org-adapt-indentation t
)) (org-indent-line))
705 (org-get-indentation))))
708 (org-test-with-temp-text "* H"
710 (org-get-indentation))))
711 ;; Do not indent before first headline.
714 (org-test-with-temp-text ""
716 (org-get-indentation))))
717 ;; Indent according to headline level otherwise, unless
718 ;; `org-adapt-indentation' is nil.
721 (org-test-with-temp-text "* H\n<point>A"
722 (let ((org-adapt-indentation t
)) (org-indent-line))
723 (org-get-indentation))))
726 (org-test-with-temp-text "* H\n<point>\nA"
727 (let ((org-adapt-indentation t
)) (org-indent-line))
728 (org-get-indentation))))
731 (org-test-with-temp-text "* H\n<point>A"
732 (let ((org-adapt-indentation nil
)) (org-indent-line))
733 (org-get-indentation))))
734 ;; Indenting preserves point position.
736 (org-test-with-temp-text "* H\nA<point>B"
737 (let ((org-adapt-indentation t
)) (org-indent-line))
739 ;; Do not change indentation at an item or a LaTeX environment.
742 (org-test-with-temp-text "* H\n<point> - A"
743 (let ((org-adapt-indentation t
)) (org-indent-line))
744 (org-get-indentation))))
747 (org-test-with-temp-text
748 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
750 (org-get-indentation))))
751 ;; On blank lines at the end of a list, indent like last element
752 ;; within it if the line is still in the list. If the last element
753 ;; is an item, indent like its contents. Otherwise, indent like the
757 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
758 (let ((org-adapt-indentation t
)) (org-indent-line))
759 (org-get-indentation))))
762 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
763 (let ((org-adapt-indentation t
)) (org-indent-line))
764 (org-get-indentation))))
767 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
768 (let ((org-adapt-indentation t
)) (org-indent-line))
769 (org-get-indentation))))
772 (org-test-with-temp-text "* H\n- A\n - \n<point>"
773 (let ((org-adapt-indentation t
)) (org-indent-line))
774 (org-get-indentation))))
777 (org-test-with-temp-text
778 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
779 (let ((org-adapt-indentation t
)) (org-indent-line))
780 (org-get-indentation))))
783 (org-test-with-temp-text "- A\n B\n\n<point>"
784 (let ((org-adapt-indentation nil
)) (org-indent-line))
785 (org-get-indentation))))
786 ;; Likewise, on a blank line at the end of a footnote definition,
787 ;; indent at column 0 if line belongs to the definition. Otherwise,
788 ;; indent like the definition itself.
791 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
792 (goto-char (point-max))
793 (let ((org-adapt-indentation t
)) (org-indent-line))
794 (org-get-indentation))))
797 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
798 (goto-char (point-max))
799 (let ((org-adapt-indentation t
)) (org-indent-line))
800 (org-get-indentation))))
801 ;; After the end of the contents of a greater element, indent like
802 ;; the beginning of the element.
805 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
808 (org-get-indentation))))
809 ;; On blank lines after a paragraph, indent like its last non-empty
813 (org-test-with-temp-text " Paragraph\n\n<point>"
815 (org-get-indentation))))
816 ;; At the first line of an element, indent like previous element's
817 ;; first line, ignoring footnotes definitions and inline tasks, or
818 ;; according to parent.
821 (org-test-with-temp-text "A\n\n B\n\nC"
822 (goto-char (point-max))
824 (org-get-indentation))))
827 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
828 (goto-char (point-max))
830 (org-get-indentation))))
833 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
836 (org-get-indentation))))
837 ;; Within code part of a source block, use language major mode if
838 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
839 ;; according to line above.
842 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
844 (let ((org-src-tab-acts-natively t
)
845 (org-edit-src-content-indentation 0))
847 (org-get-indentation))))
850 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
852 (let ((org-src-tab-acts-natively nil
)
853 (org-edit-src-content-indentation 0))
855 (org-get-indentation))))
856 ;; Otherwise, indent like the first non-blank line above.
859 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
862 (org-get-indentation))))
863 ;; Align node properties according to `org-property-format'. Handle
864 ;; nicely empty values.
866 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
867 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
868 (let ((org-property-format "%-10s %s")) (org-indent-line))
871 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
872 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
873 (let ((org-property-format "%-10s %s")) (org-indent-line))
876 (ert-deftest test-org
/indent-region
()
877 "Test `org-indent-region' specifications."
881 (org-test-with-temp-text " A\nB\n C"
882 (org-indent-region (point-min) (point-max))
884 ;; Indent greater elements along with their contents.
886 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
887 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
888 (org-indent-region (point-min) (point-max))
890 ;; Ignore contents of verse blocks. Only indent block delimiters.
892 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
893 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
894 (org-indent-region (point-min) (point-max))
897 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
898 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
899 (org-indent-region (point-min) (point-max))
901 ;; Indent example blocks as a single block, unless indentation
902 ;; should be preserved. In this case only indent the block markers.
904 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
905 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
906 (org-indent-region (point-min) (point-max))
909 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
910 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
911 (org-indent-region (point-min) (point-max))
914 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
915 (org-test-with-temp-text
916 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
917 (org-indent-region (point-min) (point-max))
920 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
921 (org-test-with-temp-text
922 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
923 (let ((org-src-preserve-indentation t
))
924 (org-indent-region (point-min) (point-max)))
926 ;; Treat export blocks as a whole.
928 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
929 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
930 (org-indent-region (point-min) (point-max))
933 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
934 (org-test-with-temp-text
935 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
936 (org-indent-region (point-min) (point-max))
938 ;; Indent according to mode if `org-src-tab-acts-natively' is
939 ;; non-nil. Otherwise, do not indent code at all.
941 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
942 (org-test-with-temp-text
943 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
944 (let ((org-src-tab-acts-natively t
)
945 (org-edit-src-content-indentation 0))
946 (org-indent-region (point-min) (point-max)))
949 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
950 (org-test-with-temp-text
951 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
952 (let ((org-src-tab-acts-natively nil
)
953 (org-edit-src-content-indentation 0))
954 (org-indent-region (point-min) (point-max)))
956 ;; Align node properties according to `org-property-format'. Handle
957 ;; nicely empty values.
959 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
960 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
961 (let ((org-property-format "%-10s %s")
962 (org-adapt-indentation nil
))
963 (org-indent-region (point) (point-max)))
966 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
967 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
968 (let ((org-property-format "%-10s %s")
969 (org-adapt-indentation nil
))
970 (org-indent-region (point) (point-max)))
972 ;; Indent plain lists.
974 (equal "- A\n B\n - C\n\n D"
975 (org-test-with-temp-text "- A\n B\n - C\n\n D"
976 (org-indent-region (point-min) (point-max))
980 (org-test-with-temp-text " - A\n\n - B"
981 (org-indent-region (point-min) (point-max))
983 ;; Indent footnote definitions.
985 (equal "[fn:1] Definition\n\nDefinition"
986 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
987 (org-indent-region (point-min) (point-max))
989 ;; Special case: Start indenting on a blank line.
992 (org-test-with-temp-text "\n Paragraph"
993 (org-indent-region (point-min) (point-max))
1000 (ert-deftest test-org
/delete-indentation
()
1001 "Test `org-delete-indentation' specifications."
1003 (should (equal "foo bar"
1004 (org-test-with-temp-text
1006 (org-delete-indentation)
1008 ;; With optional argument.
1009 (should (equal "foo bar"
1010 (org-test-with-temp-text
1012 (org-delete-indentation t
)
1014 ;; At headline text should be appended to the headline text.
1016 (equal"* foo bar :tag:"
1017 (let (org-auto-align-tags)
1018 (org-test-with-temp-text
1019 "* foo :tag:\n bar<point>"
1020 (org-delete-indentation)
1023 (equal "* foo bar :tag:"
1024 (let (org-auto-align-tags)
1025 (org-test-with-temp-text
1026 "* foo <point>:tag:\n bar"
1027 (org-delete-indentation t
)
1028 (buffer-string))))))
1030 (ert-deftest test-org
/return
()
1031 "Test `org-return' specifications."
1034 (equal "Para\ngraph"
1035 (org-test-with-temp-text "Para<point>graph"
1038 ;; With optional argument, indent line.
1040 (equal " Para\n graph"
1041 (org-test-with-temp-text " Para<point>graph"
1044 ;; On a table, call `org-table-next-row'.
1046 (org-test-with-temp-text "| <point>a |\n| b |"
1048 (looking-at-p "b")))
1049 ;; Open link or timestamp under point when `org-return-follows-link'
1052 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1053 (let ((org-return-follows-link t
)
1054 (org-link-search-must-match-exact-headline nil
))
1056 (looking-at-p "<<target>>")))
1058 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1059 (let ((org-return-follows-link nil
)) (org-return))
1060 (looking-at-p "<<target>>")))
1062 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1063 (let ((org-return-follows-link t
)) (org-return))
1064 (looking-at-p "* b")))
1066 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1067 (let ((org-return-follows-link t
)
1068 (org-link-search-must-match-exact-headline nil
))
1070 (looking-at-p "<<target>>")))
1072 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1073 (let ((org-return-follows-link t
)
1074 (org-link-search-must-match-exact-headline nil
))
1076 (looking-at-p "<<target>>")))
1077 ;; When `org-return-follows-link' is non-nil, tolerate links and
1078 ;; timestamps in comments, node properties, etc.
1080 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1081 (let ((org-return-follows-link t
)
1082 (org-link-search-must-match-exact-headline nil
))
1084 (looking-at-p "<<target>>")))
1086 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1087 (let ((org-return-follows-link nil
)) (org-return))
1088 (looking-at-p "<<target>>")))
1090 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1091 (let ((org-return-follows-link t
)
1092 (org-link-search-must-match-exact-headline nil
))
1094 (looking-at-p "<<target>>")))
1095 ;; However, do not open link when point is in a table.
1097 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1098 (let ((org-return-follows-link t
)) (org-return))
1099 (looking-at-p "between")))
1100 ;; Special case: in a list, when indenting, do not break structure.
1103 (org-test-with-temp-text "- A <point>B"
1108 (org-test-with-temp-text "- A\n<point>- B"
1111 ;; On tags part of a headline, add a newline below it instead of
1114 (equal "* H :tag:\n"
1115 (org-test-with-temp-text "* H :<point>tag:"
1118 ;; Before headline text, add a newline below it instead of breaking
1121 (equal "* TODO H :tag:\n"
1122 (org-test-with-temp-text "* <point>TODO H :tag:"
1126 (equal "* TODO [#B] H :tag:\n"
1127 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1130 (should ;TODO are case-sensitive
1132 (org-test-with-temp-text "* <point>Todo"
1135 ;; At headline text, break headline text but preserve tags.
1137 (equal "* TODO [#B] foo :tag:\nbar"
1138 (let (org-auto-align-tags)
1139 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1142 ;; At bol of headline insert newline.
1145 (org-test-with-temp-text "<point>* h"
1148 ;; Refuse to leave invalid headline in buffer.
1151 (org-test-with-temp-text "*<point> h"
1155 (ert-deftest test-org
/meta-return
()
1156 "Test M-RET (`org-meta-return') specifications."
1157 ;; In a table field insert a row above.
1159 (org-test-with-temp-text "| a |"
1163 (looking-at "| |$")))
1164 ;; In a paragraph change current line into a header.
1166 (org-test-with-temp-text "a"
1169 (looking-at "\* a$")))
1170 ;; In an item insert an item, in this case above.
1172 (org-test-with-temp-text "- a"
1175 (looking-at "- $")))
1176 ;; In a drawer and item insert an item, in this case above.
1178 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1182 (looking-at "- $"))))
1184 (ert-deftest test-org
/insert-heading
()
1185 "Test `org-insert-heading' specifications."
1186 ;; In an empty buffer, insert a new headline.
1189 (org-test-with-temp-text ""
1190 (org-insert-heading)
1192 ;; At the beginning of a line, turn it into a headline.
1195 (org-test-with-temp-text "<point>P"
1196 (org-insert-heading)
1198 ;; In the middle of a line, split the line if allowed, otherwise,
1199 ;; insert the headline at its end.
1201 (equal "Para\n* graph"
1202 (org-test-with-temp-text "Para<point>graph"
1203 (let ((org-M-RET-may-split-line '((default . t
))))
1204 (org-insert-heading))
1207 (equal "Paragraph\n* "
1208 (org-test-with-temp-text "Para<point>graph"
1209 (let ((org-M-RET-may-split-line '((default . nil
))))
1210 (org-insert-heading))
1212 ;; At the beginning of a headline, create one above.
1215 (org-test-with-temp-text "* H"
1216 (org-insert-heading)
1218 ;; In the middle of a headline, split it if allowed.
1221 (org-test-with-temp-text "* H<point>1"
1222 (let ((org-M-RET-may-split-line '((headline . t
))))
1223 (org-insert-heading))
1227 (org-test-with-temp-text "* H<point>1"
1228 (let ((org-M-RET-may-split-line '((headline . nil
))))
1229 (org-insert-heading))
1231 ;; However, splitting cannot happen on TODO keywords, priorities or
1234 (equal "* TODO H1\n* \n"
1235 (org-test-with-temp-text "* TO<point>DO H1"
1236 (let ((org-M-RET-may-split-line '((headline . t
))))
1237 (org-insert-heading))
1240 (equal "* [#A] H1\n* \n"
1241 (org-test-with-temp-text "* [#<point>A] H1"
1242 (let ((org-M-RET-may-split-line '((headline . t
))))
1243 (org-insert-heading))
1246 (equal "* H1 :tag:\n* \n"
1247 (org-test-with-temp-text "* H1 :ta<point>g:"
1248 (let ((org-M-RET-may-split-line '((headline . t
))))
1249 (org-insert-heading))
1251 ;; New headline level depends on the level of the headline above.
1254 (org-test-with-temp-text "** H\n<point>P"
1255 (org-insert-heading)
1258 (equal "** H\nPara\n** graph"
1259 (org-test-with-temp-text "** H\nPara<point>graph"
1260 (let ((org-M-RET-may-split-line '((default . t
))))
1261 (org-insert-heading))
1265 (org-test-with-temp-text "** H"
1266 (org-insert-heading)
1268 ;; When called with one universal argument, insert a new headline at
1269 ;; the end of the current subtree, independently on the position of
1274 (org-test-with-temp-text "* H1\n** H2"
1275 (let ((org-insert-heading-respect-content nil
))
1276 (org-insert-heading '(4)))
1281 (org-test-with-temp-text "* H<point>1\n** H2"
1282 (let ((org-insert-heading-respect-content nil
))
1283 (org-insert-heading '(4)))
1285 ;; When called with two universal arguments, insert a new headline
1286 ;; at the end of the grandparent subtree.
1288 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1289 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1290 (let ((org-insert-heading-respect-content nil
))
1291 (org-insert-heading '(16)))
1293 ;; When optional TOP-LEVEL argument is non-nil, always insert
1294 ;; a level 1 heading.
1296 (equal "* H1\n** H2\n* \n"
1297 (org-test-with-temp-text "* H1\n** H2<point>"
1298 (org-insert-heading nil nil t
)
1301 (equal "* H1\n- item\n* "
1302 (org-test-with-temp-text "* H1\n- item<point>"
1303 (org-insert-heading nil nil t
)
1305 ;; Obey `org-blank-before-new-entry'.
1307 (equal "* H1\n\n* \n"
1308 (org-test-with-temp-text "* H1<point>"
1309 (let ((org-blank-before-new-entry '((heading . t
))))
1310 (org-insert-heading))
1314 (org-test-with-temp-text "* H1<point>"
1315 (let ((org-blank-before-new-entry '((heading . nil
))))
1316 (org-insert-heading))
1319 (equal "* H1\n* H2\n* \n"
1320 (org-test-with-temp-text "* H1\n* H2<point>"
1321 (let ((org-blank-before-new-entry '((heading . auto
))))
1322 (org-insert-heading))
1325 (equal "* H1\n\n* H2\n\n* \n"
1326 (org-test-with-temp-text "* H1\n\n* H2<point>"
1327 (let ((org-blank-before-new-entry '((heading . auto
))))
1328 (org-insert-heading))
1330 ;; Corner case: correctly insert a headline after an empty one.
1333 (org-test-with-temp-text "* <point>"
1334 (org-insert-heading)
1337 (org-test-with-temp-text "* <point>\n"
1338 (org-insert-heading)
1339 (looking-at-p "\n\\'")))
1340 ;; Do not insert spurious headlines when inserting a new headline.
1342 (equal "* H1\n* H2\n* \n"
1343 (org-test-with-temp-text "* H1\n* H2<point>\n"
1344 (org-insert-heading)
1347 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1348 "Test `org-insert-todo-heading-respect-content' specifications."
1349 ;; Create a TODO heading.
1351 (org-test-with-temp-text "* H1\n Body"
1352 (org-insert-todo-heading-respect-content)
1353 (nth 2 (org-heading-components))))
1354 ;; Add headline at the end of the first subtree
1358 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1359 (org-insert-todo-heading-respect-content)
1360 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1361 ;; In a list, do not create a new item.
1365 (org-test-with-temp-text "* H\n- an item\n- another one"
1366 (search-forward "an ")
1367 (org-insert-todo-heading-respect-content)
1368 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1370 (ert-deftest test-org
/clone-with-time-shift
()
1371 "Test `org-clone-subtree-with-time-shift'."
1372 ;; Raise an error before first heading.
1374 (org-test-with-temp-text ""
1375 (org-clone-subtree-with-time-shift 1)))
1376 ;; Raise an error on invalid number of clones.
1378 (org-test-with-temp-text "* Clone me"
1379 (org-clone-subtree-with-time-shift -
1)))
1380 ;; Clone non-repeating once.
1386 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1387 (org-clone-subtree-with-time-shift 1 "+2d")
1388 (replace-regexp-in-string
1389 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1391 ;; Clone repeating once.
1396 * H1\n<2015-06-25 +1w>
1398 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1399 (org-clone-subtree-with-time-shift 1 "+2d")
1400 (replace-regexp-in-string
1401 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1403 ;; Clone non-repeating zero times.
1408 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1409 (org-clone-subtree-with-time-shift 0 "+2d")
1410 (replace-regexp-in-string
1411 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1413 ;; Clone repeating "zero" times.
1417 * H1\n<2015-06-23 +1w>
1419 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1420 (org-clone-subtree-with-time-shift 0 "+2d")
1421 (replace-regexp-in-string
1422 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1424 ;; Clone with blank SHIFT argument.
1428 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1429 (org-clone-subtree-with-time-shift 1 "")
1430 (buffer-substring-no-properties (line-beginning-position 2)
1431 (line-end-position 2)))))
1432 ;; Find time stamps before point. If SHIFT is not specified, ask
1433 ;; for a time shift.
1437 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1438 (org-clone-subtree-with-time-shift 1 "+1d")
1439 (buffer-substring-no-properties (line-beginning-position 2)
1440 (line-end-position 2)))))
1444 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1445 (cl-letf (((symbol-function 'read-from-minibuffer
)
1446 (lambda (&rest args
) "+1d")))
1447 (org-clone-subtree-with-time-shift 1))
1448 (buffer-substring-no-properties (line-beginning-position 2)
1449 (line-end-position 2))))))
1452 ;;; Fixed-Width Areas
1454 (ert-deftest test-org
/toggle-fixed-width
()
1455 "Test `org-toggle-fixed-width' specifications."
1456 ;; No region: Toggle on fixed-width marker in paragraphs.
1459 (org-test-with-temp-text "A"
1460 (org-toggle-fixed-width)
1462 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1465 (org-test-with-temp-text ": A"
1466 (org-toggle-fixed-width)
1468 ;; No region: Toggle on marker in blank lines after elements or just
1469 ;; after a headline.
1472 (org-test-with-temp-text "* H\n"
1474 (org-toggle-fixed-width)
1477 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1478 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1479 (goto-char (point-max))
1480 (org-toggle-fixed-width)
1482 ;; No region: Toggle on marker in front of one line elements (e.g.,
1483 ;; headlines, clocks)
1485 (equal ": * Headline"
1486 (org-test-with-temp-text "* Headline"
1487 (org-toggle-fixed-width)
1490 (equal ": #+KEYWORD: value"
1491 (org-test-with-temp-text "#+KEYWORD: value"
1492 (org-toggle-fixed-width)
1494 ;; No region: error in other situations.
1496 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1498 (org-toggle-fixed-width)
1500 ;; No region: Indentation is preserved.
1503 (org-test-with-temp-text "- A\n B"
1505 (org-toggle-fixed-width)
1507 ;; Region: If it contains only fixed-width elements and blank lines,
1508 ;; toggle off fixed-width markup.
1511 (org-test-with-temp-text ": A\n\n: B"
1512 (transient-mark-mode 1)
1513 (push-mark (point) t t
)
1514 (goto-char (point-max))
1515 (org-toggle-fixed-width)
1517 ;; Region: If it contains anything else, toggle on fixed-width but
1518 ;; not on fixed-width areas.
1520 (equal ": A\n: \n: B\n: \n: C"
1521 (org-test-with-temp-text "A\n\n: B\n\nC"
1522 (transient-mark-mode 1)
1523 (push-mark (point) t t
)
1524 (goto-char (point-max))
1525 (org-toggle-fixed-width)
1527 ;; Region: Ignore blank lines at its end, unless it contains only
1531 (org-test-with-temp-text "A\n\n"
1532 (transient-mark-mode 1)
1533 (push-mark (point) t t
)
1534 (goto-char (point-max))
1535 (org-toggle-fixed-width)
1539 (org-test-with-temp-text "\n\n"
1540 (transient-mark-mode 1)
1541 (push-mark (point) t t
)
1542 (goto-char (point-max))
1543 (org-toggle-fixed-width)
1550 (ert-deftest test-org
/get-heading
()
1551 "Test `org-get-heading' specifications."
1552 ;; Return current heading, even if point is not on it.
1555 (org-test-with-temp-text "* H"
1556 (org-get-heading))))
1559 (org-test-with-temp-text "* H\nText<point>"
1560 (org-get-heading))))
1561 ;; Without any optional argument, return TODO keyword, priority
1562 ;; cookie, COMMENT keyword and tags.
1565 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1566 (org-get-heading))))
1569 (org-test-with-temp-text "* [#A] H"
1570 (org-get-heading))))
1573 (org-test-with-temp-text "* COMMENT H"
1574 (org-get-heading))))
1577 (org-test-with-temp-text "* H :tag:"
1578 (org-get-heading))))
1579 ;; With NO-TAGS argument, ignore tags.
1582 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1583 (org-get-heading t
))))
1586 (org-test-with-temp-text "* H :tag:"
1587 (org-get-heading t
))))
1588 ;; With NO-TODO, ignore TODO keyword.
1591 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1592 (org-get-heading nil t
))))
1595 (org-test-with-temp-text "* H :tag:"
1596 (org-get-heading nil t
))))
1597 ;; TODO keywords are case-sensitive.
1600 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1601 (org-get-heading nil t
))))
1602 ;; With NO-PRIORITY, ignore priority.
1605 (org-test-with-temp-text "* [#A] H"
1606 (org-get-heading nil nil t
))))
1609 (org-test-with-temp-text "* H"
1610 (org-get-heading nil nil t
))))
1613 (org-test-with-temp-text "* TODO [#A] H"
1614 (org-get-heading nil nil t
))))
1615 ;; With NO-COMMENT, ignore COMMENT keyword.
1618 (org-test-with-temp-text "* COMMENT H"
1619 (org-get-heading nil nil nil t
))))
1622 (org-test-with-temp-text "* H"
1623 (org-get-heading nil nil nil t
))))
1625 (equal "TODO [#A] H"
1626 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1627 (org-get-heading nil nil nil t
))))
1628 ;; On an empty headline, return value is consistent.
1629 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1630 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1631 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1632 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1634 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1636 (ert-deftest test-org
/in-commented-heading-p
()
1637 "Test `org-in-commented-heading-p' specifications."
1638 ;; Commented headline.
1640 (org-test-with-temp-text "* COMMENT Headline\nBody"
1641 (goto-char (point-max))
1642 (org-in-commented-heading-p)))
1643 ;; Commented ancestor.
1645 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1646 (goto-char (point-max))
1647 (org-in-commented-heading-p)))
1648 ;; Comment keyword is case-sensitive.
1650 (org-test-with-temp-text "* Comment Headline\nBody"
1651 (goto-char (point-max))
1652 (org-in-commented-heading-p)))
1653 ;; Keyword is standalone.
1655 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1656 (goto-char (point-max))
1657 (org-in-commented-heading-p)))
1658 ;; Optional argument.
1660 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1661 (goto-char (point-max))
1662 (org-in-commented-heading-p t
))))
1664 (ert-deftest test-org
/entry-blocked-p
()
1665 ;; Check other dependencies.
1667 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1668 (let ((org-enforce-todo-dependencies t
)
1670 '(org-block-todo-from-children-or-siblings-or-parent)))
1671 (org-entry-blocked-p))))
1673 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1674 (let ((org-enforce-todo-dependencies t
)
1676 '(org-block-todo-from-children-or-siblings-or-parent)))
1677 (org-entry-blocked-p))))
1678 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1681 (org-test-with-temp-text "* Blocked\n** TODO one"
1682 (let ((org-enforce-todo-dependencies t
)
1684 '(org-block-todo-from-children-or-siblings-or-parent)))
1685 (org-entry-blocked-p))))
1687 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1688 (let ((org-enforce-todo-dependencies t
)
1690 '(org-block-todo-from-children-or-siblings-or-parent)))
1691 (org-entry-blocked-p))))
1692 ;; Follow :ORDERED: specifications.
1694 (org-test-with-temp-text
1695 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1696 (let ((org-enforce-todo-dependencies t
)
1698 '(org-block-todo-from-children-or-siblings-or-parent)))
1699 (org-entry-blocked-p))))
1701 (org-test-with-temp-text
1702 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1703 (let ((org-enforce-todo-dependencies t
)
1705 '(org-block-todo-from-children-or-siblings-or-parent)))
1706 (org-entry-blocked-p)))))
1708 (ert-deftest test-org
/get-outline-path
()
1709 "Test `org-get-outline-path' specifications."
1710 ;; Top-level headlines have no outline path.
1712 (org-test-with-temp-text "* H"
1713 (org-get-outline-path)))
1714 ;; Otherwise, outline path is the path leading to the headline.
1717 (org-test-with-temp-text "* H\n** S<point>"
1718 (org-get-outline-path))))
1719 ;; Find path even when point is not on a headline.
1722 (org-test-with-temp-text "* H\n** S\nText<point>"
1723 (org-get-outline-path))))
1724 ;; TODO keywords, tags and statistics cookies are ignored.
1727 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1728 (org-get-outline-path))))
1729 ;; Links are replaced with their description or their path.
1732 (org-test-with-temp-text
1733 "* [[http://orgmode.org][Org]]\n** S<point>"
1734 (org-get-outline-path))))
1736 (equal '("http://orgmode.org")
1737 (org-test-with-temp-text
1738 "* [[http://orgmode.org]]\n** S<point>"
1739 (org-get-outline-path))))
1740 ;; When WITH-SELF is non-nil, include current heading.
1743 (org-test-with-temp-text "* H"
1744 (org-get-outline-path t
))))
1747 (org-test-with-temp-text "* H\n** S\nText<point>"
1748 (org-get-outline-path t
))))
1749 ;; Using cache is transparent to the user.
1752 (org-test-with-temp-text "* H\n** S<point>"
1753 (setq org-outline-path-cache nil
)
1754 (org-get-outline-path nil t
))))
1755 ;; Do not corrupt cache when finding outline path in distant part of
1759 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1760 (setq org-outline-path-cache nil
)
1761 (org-get-outline-path nil t
)
1762 (search-forward "S2")
1763 (org-get-outline-path nil t
))))
1764 ;; Do not choke on empty headlines.
1766 (org-test-with-temp-text "* H\n** <point>"
1767 (org-get-outline-path)))
1769 (org-test-with-temp-text "* \n** H<point>"
1770 (org-get-outline-path))))
1772 (ert-deftest test-org
/format-outline-path
()
1773 "Test `org-format-outline-path' specifications."
1775 (string= (org-format-outline-path (list "one" "two" "three"))
1779 (string= (org-format-outline-path '())
1782 (string= (org-format-outline-path '(nil))
1784 ;; Empty path and prefix.
1786 (string= (org-format-outline-path '() nil
">>")
1788 ;; Trailing whitespace in headings.
1790 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1792 ;; Non-default prefix and separators.
1794 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1795 ">>|one|two|three"))
1798 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1800 ;; Give a very narrow width.
1802 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1804 ;; Give a prefix that extends beyond the width.
1806 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1810 (ert-deftest test-org
/map-entries
()
1811 "Test `org-map-entries' specifications."
1815 (org-test-with-temp-text "* Level 1\n** Level 2"
1816 (org-map-entries #'point
))))
1820 (org-test-with-temp-text "* Level 1\n** Level 2"
1821 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1824 (org-test-with-temp-text "* Level 1\n** Level 2"
1825 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1829 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1830 (org-map-entries #'point
"yes"))))
1833 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1834 (org-map-entries #'point
"+yes-a"))))
1837 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1838 (org-map-entries #'point
"{yes?}"))))
1842 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1843 (org-map-entries #'point
"PRIORITY=\"A\""))))
1847 (org-test-with-temp-text "
1849 SCHEDULED: <2012-03-29 thu.>
1851 SCHEDULED: <2014-03-04 tue.>"
1852 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1855 (org-test-with-temp-text "
1857 SCHEDULED: <2012-03-29 thu.>
1859 SCHEDULED: <2014-03-04 tue.>"
1860 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1861 ;; Regular property match.
1864 (org-test-with-temp-text "
1873 (org-map-entries #'point
"TEST=1"))))
1874 ;; Multiple criteria.
1877 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1878 (let (org-odd-levels-only
1879 (org-use-tag-inheritance nil
))
1880 (org-map-entries #'point
"yes+LEVEL=1")))))
1884 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1885 (let (org-odd-levels-only)
1886 (org-map-entries #'point
"LEVEL=2|no")))))
1889 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1890 (let (org-odd-levels-only)
1891 (org-map-entries #'point
"yes|no")))))
1895 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1896 (let (org-odd-levels-only)
1897 (org-map-entries #'point
"yes&no"))))))
1899 (ert-deftest test-org
/edit-headline
()
1900 "Test `org-edit-headline' specifications."
1903 (org-test-with-temp-text "* A"
1904 (org-edit-headline "B")
1906 ;; Handle empty headings.
1909 (org-test-with-temp-text "* A"
1910 (org-edit-headline "")
1914 (org-test-with-temp-text "* "
1915 (org-edit-headline "A")
1917 ;; Handle TODO keywords and priority cookies.
1920 (org-test-with-temp-text "* TODO A"
1921 (org-edit-headline "B")
1925 (org-test-with-temp-text "* [#A] A"
1926 (org-edit-headline "B")
1929 (equal "* TODO [#A] B"
1930 (org-test-with-temp-text "* TODO [#A] A"
1931 (org-edit-headline "B")
1935 (org-test-with-temp-text "* A :tag:"
1936 (let ((org-tags-column 4)) (org-edit-headline "B"))
1943 (ert-deftest test-org
/set-regexps-and-options
()
1944 "Test `org-set-regexps-and-options' specifications."
1948 (let ((org-tag-alist '(("A")))
1949 (org-tag-persistent-alist nil
))
1950 (org-test-with-temp-text ""
1952 org-current-tag-alist
))))
1955 (let ((org-tag-alist '(("A")))
1956 (org-tag-persistent-alist nil
))
1957 (org-test-with-temp-text "#+TAGS: B"
1959 org-current-tag-alist
))))
1961 (equal '(("C") ("B"))
1962 (let ((org-tag-alist '(("A")))
1963 (org-tag-persistent-alist '(("C"))))
1964 (org-test-with-temp-text "#+TAGS: B"
1966 org-current-tag-alist
))))
1969 (let ((org-tag-alist '(("A")))
1970 (org-tag-persistent-alist '(("C"))))
1971 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1973 org-current-tag-alist
))))
1975 (equal '(("A" . ?a
) ("B") ("C"))
1976 (let ((org-tag-persistant-alist nil
))
1977 (org-test-with-temp-text "#+TAGS: A(a) B C"
1979 org-current-tag-alist
))))
1981 (equal '(("A") (:newline
) ("B"))
1982 (let ((org-tag-persistent-alist nil
))
1983 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1985 org-current-tag-alist
))))
1987 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1988 (let ((org-tag-persistent-alist nil
))
1989 (org-test-with-temp-text "#+TAGS: { A B } C"
1991 org-current-tag-alist
))))
1993 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1994 (let ((org-tag-persistent-alist nil
))
1995 (org-test-with-temp-text "#+TAGS: { A : B C }"
1997 org-current-tag-alist
))))
1999 (equal '(("A" "B" "C"))
2000 (let ((org-tag-persistent-alist nil
))
2001 (org-test-with-temp-text "#+TAGS: { A : B C }"
2003 org-tag-groups-alist
))))
2005 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2006 (let ((org-tag-persistent-alist nil
))
2007 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2009 org-current-tag-alist
))))
2011 (equal '(("A" "B" "C"))
2012 (let ((org-tag-persistent-alist nil
))
2013 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2015 org-tag-groups-alist
))))
2016 ;; FILETAGS keyword.
2018 (equal '("A" "B" "C")
2019 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2022 ;; PROPERTY keyword. Property names are case-insensitive.
2025 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2027 (cdr (assoc "var" org-file-properties
)))))
2031 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2033 (cdr (assoc "var" org-file-properties
)))))
2037 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2039 (cdr (assoc "var" org-file-properties
)))))
2043 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2045 org-archive-location
)))
2046 ;; CATEGORY keyword.
2049 (org-test-with-temp-text "#+CATEGORY: test"
2054 (org-test-with-temp-text "#+CATEGORY: test"
2056 (cdr (assoc "CATEGORY" org-file-properties
)))))
2059 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2060 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2062 org-columns-default-format
)))
2063 ;; CONSTANTS keyword. Constants names are case sensitive.
2065 (equal '("299792458." "3.14")
2066 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2069 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2073 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2075 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2078 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2080 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2085 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2087 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2089 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2093 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2095 (list org-highest-priority org-lowest-priority org-default-priority
))))
2099 (org-test-with-temp-text "#+PRIORITIES: X Z"
2101 (list org-highest-priority org-lowest-priority org-default-priority
))))
2105 (org-test-with-temp-text "#+STARTUP: fold odd"
2107 (list org-startup-folded org-odd-levels-only
))))
2110 (equal '(("A" "B") ("C"))
2111 (org-test-with-temp-text "#+TODO: A B | C"
2113 (list org-not-done-keywords org-done-keywords
))))
2115 (equal '(("A" "C") ("B" "D"))
2116 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2118 (list org-not-done-keywords org-done-keywords
))))
2120 (equal '(("A" "B") ("C"))
2121 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2123 (list org-not-done-keywords org-done-keywords
))))
2125 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2126 (org-test-with-temp-text "#+TODO: A(a)"
2128 org-todo-key-alist
)))
2130 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2131 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2133 org-todo-log-states
)))
2134 ;; Enter SETUPFILE keyword.
2137 (org-test-with-temp-text
2138 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2140 (cdr (assoc "a" org-file-properties
))))))
2148 (ert-deftest test-org
/coderef
()
2149 "Test coderef links specifications."
2151 (org-test-with-temp-text "
2152 #+BEGIN_SRC emacs-lisp
2157 (looking-at "(ref:sc)")))
2158 ;; Find coderef even with alternate label format.
2160 (org-test-with-temp-text "
2161 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2166 (looking-at "{ref:sc}"))))
2170 (ert-deftest test-org
/custom-id
()
2171 "Test custom ID links specifications."
2173 (org-test-with-temp-text
2174 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2176 (looking-at-p "\\* H1")))
2177 ;; Throw an error on false positives.
2179 (org-test-with-temp-text
2180 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2182 (looking-at-p "\\* H1"))))
2186 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2187 ;; a named element (#+name: text) and to headlines (* Text).
2189 (ert-deftest test-org
/fuzzy-links
()
2190 "Test fuzzy links specifications."
2191 ;; Fuzzy link goes in priority to a matching target.
2193 (org-test-with-temp-text
2194 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2195 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2196 (looking-at "<<Test>>")))
2197 ;; Then fuzzy link points to an element with a given name.
2199 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2200 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2201 (looking-at "#\\+NAME: Test")))
2202 ;; A target still lead to a matching headline otherwise.
2204 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2205 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2206 (looking-at "\\* Head2")))
2207 ;; With a leading star in link, enforce heading match.
2209 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2210 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2211 (looking-at "\\* Test")))
2212 ;; With a leading star in link, enforce exact heading match, even
2213 ;; with `org-link-search-must-match-exact-headline' set to nil.
2215 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2216 (let ((org-link-search-must-match-exact-headline nil
))
2217 (org-open-at-point))))
2218 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2220 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2221 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2222 (looking-at "\\* Test")))
2224 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2225 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2226 (looking-at "\\* Test")))
2227 ;; Heading match should not care about spaces, cookies, TODO
2228 ;; keywords, priorities, and tags. However, TODO keywords are
2232 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2233 (org-test-with-temp-text
2234 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2235 (let ((org-link-search-must-match-exact-headline nil
)
2236 (org-todo-regexp "TODO"))
2237 (org-open-at-point))
2238 (looking-at (regexp-quote first-line
)))))
2240 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2241 (let ((org-link-search-must-match-exact-headline nil
)
2242 (org-todo-regexp "TODO"))
2243 (org-open-at-point))))
2244 ;; Heading match should still be exact.
2246 (org-test-with-temp-text "
2247 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2250 (let ((org-link-search-must-match-exact-headline nil
)
2251 (org-todo-regexp "TODO"))
2252 (org-open-at-point))))
2254 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2255 (let ((org-link-search-must-match-exact-headline nil
)
2256 (org-todo-regexp "TODO"))
2257 (org-open-at-point))
2258 (looking-at-p (regexp-quote "** Test 1 2"))))
2259 ;; Heading match ignores COMMENT keyword.
2261 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2263 (looking-at "\\* COMMENT Test")))
2265 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2267 (looking-at "\\* TODO COMMENT Test")))
2268 ;; Correctly un-hexify fuzzy links.
2270 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2274 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2280 (ert-deftest test-org
/org-link-escape-ascii-character
()
2281 "Escape an ascii character."
2285 (org-link-escape "["))))
2287 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2288 "Escape an ascii control character."
2292 (org-link-escape "\t"))))
2294 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2295 "Escape an unicode multibyte character."
2299 (org-link-escape "€"))))
2301 (ert-deftest test-org
/org-link-escape-custom-table
()
2302 "Escape string with custom character table."
2306 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2308 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2309 "Escape string with custom table merged with default table."
2312 "%5BF%6F%6F%3A%42ar%0A%5D"
2313 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2315 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2316 "Unescape an ascii character."
2320 (org-link-unescape "%5B"))))
2322 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2323 "Unescpae an ascii control character."
2327 (org-link-unescape "%0A"))))
2329 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2330 "Unescape unicode multibyte character."
2334 (org-link-unescape "%E2%82%AC"))))
2336 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2337 "Unescape old style percent escaped character."
2340 "à âçèéêîôùû"
2341 (decode-coding-string
2342 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2344 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2345 "Escape and unescape a URL that includes an escaped char.
2346 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2349 "http://some.host.com/form?&id=blah%2Bblah25"
2351 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2355 (ert-deftest test-org
/open-at-point-in-keyword
()
2356 "Does `org-open-at-point' open link in a keyword line?"
2358 (org-test-with-temp-text
2359 "<<top>>\n#+KEYWORD: <point>[[top]]"
2360 (org-open-at-point) t
)))
2362 (ert-deftest test-org
/open-at-point-in-property
()
2363 "Does `org-open-at-point' open link in property drawer?"
2365 (org-test-with-temp-text
2368 :URL: <point>[[*Headline]]
2370 (org-open-at-point) t
)))
2372 (ert-deftest test-org
/open-at-point-in-comment
()
2373 "Does `org-open-at-point' open link in a commented line?"
2375 (org-test-with-temp-text
2376 "<<top>>\n# <point>[[top]]"
2377 (org-open-at-point) t
)))
2379 (ert-deftest test-org
/open-at-point
/inline-image
()
2380 "Test `org-open-at-point' on nested links."
2382 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2386 (ert-deftest test-org
/open-at-point
/radio-target
()
2387 "Test `org-open-at-point' on radio targets."
2389 (org-test-with-temp-text "<<<target>>> <point>target"
2390 (org-update-radio-target-regexp)
2392 (eq (org-element-type (org-element-context)) 'radio-target
))))
2396 (ert-deftest test-org
/store-link
()
2397 "Test `org-store-link' specifications."
2398 ;; On a headline, link to that headline. Use heading as the
2399 ;; description of the link.
2401 (let (org-store-link-props org-stored-links
)
2402 (org-test-with-temp-text-in-file "* H1"
2403 (let ((file (buffer-file-name)))
2404 (equal (format "[[file:%s::*H1][H1]]" file
)
2405 (org-store-link nil
))))))
2406 ;; On a headline, remove any link from description.
2408 (let (org-store-link-props org-stored-links
)
2409 (org-test-with-temp-text-in-file "* [[#l][d]]"
2410 (let ((file (buffer-file-name)))
2411 (equal (format "[[file:%s::*%s][d]]"
2413 (org-link-escape "[[#l][d]]"))
2414 (org-store-link nil
))))))
2416 (let (org-store-link-props org-stored-links
)
2417 (org-test-with-temp-text-in-file "* [[l]]"
2418 (let ((file (buffer-file-name)))
2419 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2420 (org-store-link nil
))))))
2422 (let (org-store-link-props org-stored-links
)
2423 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2424 (let ((file (buffer-file-name)))
2425 (equal (format "[[file:%s::*%s][d1 d2]]"
2427 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2428 (org-store-link nil
))))))
2429 ;; On a named element, link to that element.
2431 (let (org-store-link-props org-stored-links
)
2432 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2433 (let ((file (buffer-file-name)))
2434 (equal (format "[[file:%s::foo][foo]]" file
)
2435 (org-store-link nil
)))))))
2440 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2441 "Ensure properties accumulate in subtree drawers."
2442 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2443 (org-babel-next-src-block)
2444 (should (equal '(2 1) (org-babel-execute-src-block)))))
2446 (ert-deftest test-org
/custom-properties
()
2447 "Test custom properties specifications."
2450 (let ((org-custom-properties '("FOO")))
2451 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2452 (org-toggle-custom-properties-visibility)
2453 (org-invisible-p2))))
2454 ;; Properties are case-insensitive.
2456 (let ((org-custom-properties '("FOO")))
2457 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2458 (org-toggle-custom-properties-visibility)
2459 (org-invisible-p2))))
2461 (let ((org-custom-properties '("foo")))
2462 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2463 (org-toggle-custom-properties-visibility)
2464 (org-invisible-p2))))
2465 ;; Multiple custom properties in the same drawer.
2467 (let ((org-custom-properties '("FOO" "BAR")))
2468 (org-test-with-temp-text
2469 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2470 (org-toggle-custom-properties-visibility)
2471 (and (org-invisible-p2)
2472 (not (progn (forward-line) (org-invisible-p2)))
2473 (progn (forward-line) (org-invisible-p2))))))
2474 ;; Hide custom properties with an empty value.
2476 (let ((org-custom-properties '("FOO")))
2477 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2478 (org-toggle-custom-properties-visibility)
2479 (org-invisible-p2))))
2480 ;; Do not hide fake properties.
2482 (let ((org-custom-properties '("FOO")))
2483 (org-test-with-temp-text ":FOO: val\n"
2484 (org-toggle-custom-properties-visibility)
2485 (org-invisible-p2))))
2487 (let ((org-custom-properties '("A")))
2488 (org-test-with-temp-text
2489 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2490 (org-toggle-custom-properties-visibility)
2491 (org-invisible-p2)))))
2497 (ert-deftest test-org
/mark-subtree
()
2498 "Test `org-mark-subtree' specifications."
2499 ;; Error when point is before first headline.
2501 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2502 (progn (transient-mark-mode 1)
2503 (org-mark-subtree))))
2504 ;; Without argument, mark current subtree.
2508 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2509 (progn (transient-mark-mode 1)
2512 (list (region-beginning) (region-end))))))
2513 ;; With an argument, move ARG up.
2517 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2518 (progn (transient-mark-mode 1)
2520 (org-mark-subtree 1)
2521 (list (region-beginning) (region-end))))))
2522 ;; Do not get fooled by inlinetasks.
2523 (when (featurep 'org-inlinetask
)
2526 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2527 (progn (transient-mark-mode 1)
2529 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2530 (region-beginning)))))))
2536 (ert-deftest test-org
/in-regexp
()
2537 "Test `org-in-regexp' specifications."
2540 (org-test-with-temp-text "xx ab<point>c xx"
2541 (org-in-regexp "abc")))
2543 (org-test-with-temp-text "xx abc <point>xx"
2544 (org-in-regexp "abc")))
2545 ;; Return non-nil even with multiple matching regexps in the same
2548 (org-test-with-temp-text "abc xx ab<point>c xx"
2549 (org-in-regexp "abc")))
2550 ;; With optional argument NLINES, check extra lines around point.
2552 (org-test-with-temp-text "A\nB<point>\nC"
2553 (org-in-regexp "A\nB\nC")))
2555 (org-test-with-temp-text "A\nB<point>\nC"
2556 (org-in-regexp "A\nB\nC" 1)))
2558 (org-test-with-temp-text "A\nB\nC<point>"
2559 (org-in-regexp "A\nB\nC" 1)))
2560 ;; When optional argument VISUALLY is non-nil, return nil if at
2561 ;; regexp boundaries.
2563 (org-test-with-temp-text "xx abc<point> xx"
2564 (org-in-regexp "abc")))
2566 (org-test-with-temp-text "xx abc<point> xx"
2567 (org-in-regexp "abc" nil t
))))
2572 (ert-deftest test-org
/end-of-meta-data
()
2573 "Test `org-end-of-meta-data' specifications."
2574 ;; Skip planning line.
2576 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2577 (org-end-of-meta-data)
2579 ;; Skip properties drawer.
2581 (org-test-with-temp-text
2582 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2583 (org-end-of-meta-data)
2587 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2588 (org-end-of-meta-data)
2590 ;; Nothing to skip, go to first line.
2592 (org-test-with-temp-text "* Headline\nContents"
2593 (org-end-of-meta-data)
2594 (looking-at "Contents")))
2595 ;; With option argument, skip empty lines, regular drawers and
2598 (org-test-with-temp-text "* Headline\n\nContents"
2599 (org-end-of-meta-data t
)
2600 (looking-at "Contents")))
2602 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2603 (org-end-of-meta-data t
)
2604 (looking-at "Contents")))
2606 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2607 (org-end-of-meta-data t
)
2608 (looking-at "Contents")))
2609 ;; Special case: do not skip incomplete drawers.
2611 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2612 (org-end-of-meta-data t
)
2613 (looking-at ":LOGBOOK:")))
2614 ;; Special case: Be careful about consecutive headlines.
2616 (org-test-with-temp-text "* H1\n*H2\nContents"
2617 (org-end-of-meta-data t
)
2618 (looking-at "Contents"))))
2620 (ert-deftest test-org
/beginning-of-line
()
2621 "Test `org-beginning-of-line' specifications."
2622 ;; Move to beginning of line. If current line in invisible, move to
2623 ;; beginning of visible line instead.
2625 (org-test-with-temp-text "Some text\nSome other text<point>"
2626 (org-beginning-of-line)
2629 (org-test-with-temp-text "* H1\n** H2<point>"
2631 (org-beginning-of-line)
2632 (= (line-beginning-position) 1)))
2633 ;; With `visual-line-mode' active, move to beginning of visual line.
2635 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2637 (dotimes (i 1000) (insert "very "))
2638 (org-beginning-of-line)
2640 ;; In a wide headline, with `visual-line-mode', prefer going to the
2641 ;; beginning of a visual line than to the logical beginning of line,
2642 ;; even if special movement is active.
2644 (org-test-with-temp-text "* A <point>long headline"
2646 (dotimes (i 1000) (insert "very "))
2647 (goto-char (point-max))
2648 (org-beginning-of-line)
2651 (org-test-with-temp-text "* A <point>long headline"
2653 (dotimes (i 1000) (insert "very "))
2654 (goto-char (point-max))
2655 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2657 ;; At an headline with special movement, first move at beginning of
2658 ;; title, then at the beginning of line, rinse, repeat.
2660 (org-test-with-temp-text "* TODO Headline<point>"
2661 (let ((org-special-ctrl-a/e t
))
2662 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2663 (progn (org-beginning-of-line) (bolp))
2664 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2666 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2667 (let ((org-special-ctrl-a/e t
))
2668 (org-beginning-of-line)
2669 (looking-at "Headline"))))
2671 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2672 (let ((org-special-ctrl-a/e
'(t . nil
)))
2673 (org-beginning-of-line)
2674 (looking-at "Headline"))))
2676 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2677 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2678 (org-beginning-of-line)
2679 (looking-at "Headline"))))
2680 ;; At an headline with reversed movement, first move to beginning of
2681 ;; line, then to the beginning of title.
2683 (org-test-with-temp-text "* TODO Headline<point>"
2684 (let ((org-special-ctrl-a/e
'reversed
)
2685 (this-command last-command
))
2686 (and (progn (org-beginning-of-line) (bolp))
2687 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2689 (org-test-with-temp-text "* TODO Headline<point>"
2690 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2691 (this-command last-command
))
2692 (and (progn (org-beginning-of-line) (bolp))
2693 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2695 (org-test-with-temp-text "* TODO Headline<point>"
2696 (let ((org-special-ctrl-a/e
'(t . nil
))
2697 (this-command last-command
))
2698 (and (progn (org-beginning-of-line) (bolp))
2699 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2700 ;; At an item with special movement, first move after to beginning
2701 ;; of title, then to the beginning of line, rinse, repeat.
2703 (org-test-with-temp-text "- [ ] Item<point>"
2704 (let ((org-special-ctrl-a/e t
))
2705 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2706 (progn (org-beginning-of-line) (bolp))
2707 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2708 ;; At an item with reversed movement, first move to beginning of
2709 ;; line, then to the beginning of title.
2711 (org-test-with-temp-text "- [X] Item<point>"
2712 (let ((org-special-ctrl-a/e
'reversed
)
2713 (this-command last-command
))
2714 (and (progn (org-beginning-of-line) (bolp))
2715 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2716 ;; Leave point before invisible characters at column 0.
2718 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2719 (let ((org-special-ctrl-a/e nil
))
2720 (org-beginning-of-line)
2723 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2724 (let ((org-special-ctrl-a/e t
))
2725 (org-beginning-of-line)
2728 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2730 (org-beginning-of-line)
2732 ;; Special case: Do not error when the buffer contains only a single
2735 (org-test-with-temp-text "*<point>"
2736 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2738 (org-test-with-temp-text "*<point>"
2739 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2741 (ert-deftest test-org
/end-of-line
()
2742 "Test `org-end-of-line' specifications."
2745 (org-test-with-temp-text "Some text\nSome other text"
2748 ;; With `visual-line-mode' active, move to end of visible line.
2749 ;; However, never go past ellipsis.
2751 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2753 (dotimes (i 1000) (insert "very "))
2754 (goto-char (point-min))
2758 (org-test-with-temp-text "* A short headline\nSome contents"
2763 ;; In a wide headline, with `visual-line-mode', prefer going to end
2764 ;; of visible line if tags, or end of line, are farther.
2766 (org-test-with-temp-text "* A <point>long headline"
2768 (dotimes (i 1000) (insert "very "))
2769 (goto-char (point-min))
2773 (org-test-with-temp-text "* A <point>long headline :tag:"
2775 (dotimes (i 1000) (insert "very "))
2776 (goto-char (point-min))
2779 ;; At an headline without special movement, go to end of line.
2780 ;; However, never go past ellipsis.
2782 (org-test-with-temp-text "* Headline2b :tag:\n"
2783 (let ((org-special-ctrl-a/e nil
))
2784 (and (progn (org-end-of-line) (eolp))
2785 (progn (org-end-of-line) (eolp))))))
2787 (org-test-with-temp-text "* Headline2b :tag:\n"
2788 (let ((org-special-ctrl-a/e
'(t . nil
)))
2789 (and (progn (org-end-of-line) (eolp))
2790 (progn (org-end-of-line) (eolp))))))
2792 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2794 (let ((org-special-ctrl-a/e nil
))
2796 (= 1 (line-beginning-position)))))
2797 ;; At an headline with special movement, first move before tags,
2798 ;; then at the end of line, rinse, repeat. However, never go past
2801 (org-test-with-temp-text "* Headline1 :tag:\n"
2802 (let ((org-special-ctrl-a/e t
))
2803 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2804 (progn (org-end-of-line) (eolp))
2805 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2807 (org-test-with-temp-text "* Headline1 :tag:\n"
2808 (let ((org-special-ctrl-a/e
'(nil . t
)))
2809 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2810 (progn (org-end-of-line) (eolp))
2811 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2813 (org-test-with-temp-text "* Headline1 :tag:\n"
2814 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2815 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2816 (progn (org-end-of-line) (eolp))
2817 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2819 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2821 (let ((org-special-ctrl-a/e t
))
2824 (= 1 (line-beginning-position)))))
2825 ;; At an headline, with reversed movement, first go to end of line,
2826 ;; then before tags. However, never go past ellipsis.
2828 (org-test-with-temp-text "* Headline3 :tag:\n"
2829 (let ((org-special-ctrl-a/e
'reversed
)
2830 (this-command last-command
))
2831 (and (progn (org-end-of-line) (eolp))
2832 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2834 (org-test-with-temp-text "* Headline3 :tag:\n"
2835 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2836 (this-command last-command
))
2837 (and (progn (org-end-of-line) (eolp))
2838 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2840 (org-test-with-temp-text "* Headline3 :tag:\n"
2841 (let ((org-special-ctrl-a/e
'(nil . t
))
2842 (this-command last-command
))
2843 (and (progn (org-end-of-line) (eolp))
2844 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2846 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2848 (let ((org-special-ctrl-a/e
'reversed
))
2850 (= 1 (line-beginning-position)))))
2851 ;; At a block without hidden contents.
2853 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2854 (progn (org-end-of-line) (eolp))))
2855 ;; At a block with hidden contents.
2857 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2858 (let ((org-special-ctrl-a/e t
))
2859 (org-hide-block-toggle)
2862 ;; Get past invisible characters at the end of line.
2864 (org-test-with-temp-text "[[http://orgmode.org]]"
2868 (ert-deftest test-org
/open-line
()
2869 "Test `org-open-line' specifications."
2870 ;; Call `open-line' outside of tables.
2873 (org-test-with-temp-text "Text"
2876 ;; At a table, create a row above.
2878 (equal "\n| |\n| a |"
2879 (org-test-with-temp-text "\n<point>| a |"
2882 ;; At the very first character of the buffer, also call `open-line'.
2885 (org-test-with-temp-text "| a |"
2888 ;; Narrowing does not count.
2890 (equal "Text\n| |\n| a |"
2891 (org-test-with-temp-text "Text\n<point>| a |"
2892 (narrow-to-region (point) (point-max))
2897 (ert-deftest test-org
/forward-sentence
()
2898 "Test `org-forward-sentence' specifications."
2899 ;; At the end of a table cell, move to the end of the next one.
2901 (org-test-with-temp-text "| a<point> | b |"
2902 (org-forward-sentence)
2903 (looking-at " |$")))
2904 ;; Elsewhere in a cell, move to its end.
2906 (org-test-with-temp-text "| a<point>c | b |"
2907 (org-forward-sentence)
2908 (looking-at " | b |$")))
2909 ;; Otherwise, simply call `forward-sentence'.
2911 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2912 (org-forward-sentence)
2913 (looking-at " Sentence 2.")))
2915 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2916 (org-forward-sentence)
2917 (org-forward-sentence)
2919 ;; At the end of an element, jump to the next one, without stopping
2920 ;; on blank lines in-between.
2922 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2923 (org-forward-sentence)
2926 (ert-deftest test-org
/backward-sentence
()
2927 "Test `org-backward-sentence' specifications."
2928 ;; At the beginning of a table cell, move to the beginning of the
2931 (org-test-with-temp-text "| a | <point>b |"
2932 (org-backward-sentence)
2933 (looking-at "a | b |$")))
2934 ;; Elsewhere in a cell, move to its beginning.
2936 (org-test-with-temp-text "| a | b<point>c |"
2937 (org-backward-sentence)
2938 (looking-at "bc |$")))
2939 ;; Otherwise, simply call `backward-sentence'.
2941 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2942 (org-backward-sentence)
2943 (looking-at "Sentence 2.")))
2945 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2946 (org-backward-sentence)
2947 (org-backward-sentence)
2949 ;; Make sure to hit the beginning of a sentence on the same line as
2952 (org-test-with-temp-text "- Line 1\n line <point>2."
2953 (org-backward-sentence)
2954 (looking-at "Line 1"))))
2956 (ert-deftest test-org
/forward-paragraph
()
2957 "Test `org-forward-paragraph' specifications."
2958 ;; At end of buffer, return an error.
2960 (org-test-with-temp-text "Paragraph"
2961 (goto-char (point-max))
2962 (org-forward-paragraph)))
2965 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2966 (org-forward-paragraph)
2970 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2971 (org-forward-paragraph)
2973 ;; Do not enter elements with invisible contents.
2975 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2976 (org-hide-block-toggle)
2977 (org-forward-paragraph)
2979 ;; On an affiliated keyword, jump to the beginning of the element.
2981 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2982 (org-forward-paragraph)
2983 (looking-at "Para")))
2984 ;; On an item or a footnote definition, move to the second element
2987 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2988 (org-forward-paragraph)
2989 (looking-at " Paragraph")))
2991 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2992 (org-forward-paragraph)
2993 (looking-at "Paragraph")))
2994 ;; On an item, or a footnote definition, when the first line is
2995 ;; empty, move to the first item.
2997 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2998 (org-forward-paragraph)
2999 (looking-at " Paragraph")))
3001 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3002 (org-forward-paragraph)
3003 (looking-at "Paragraph")))
3004 ;; On a table (resp. a property drawer) do not move through table
3005 ;; rows (resp. node properties).
3007 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3008 (org-forward-paragraph)
3009 (looking-at "Paragraph")))
3011 (org-test-with-temp-text
3012 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3013 (org-forward-paragraph)
3014 (looking-at "Paragraph")))
3015 ;; On a verse or source block, stop after blank lines.
3017 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3018 (org-forward-paragraph)
3021 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3022 (org-forward-paragraph)
3023 (looking-at "L2"))))
3025 (ert-deftest test-org
/backward-paragraph
()
3026 "Test `org-backward-paragraph' specifications."
3027 ;; Error at beginning of buffer.
3029 (org-test-with-temp-text "Paragraph"
3030 (org-backward-paragraph)))
3033 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3034 (goto-char (point-max))
3035 (org-backward-paragraph)
3038 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3039 (goto-char (point-max))
3041 (org-backward-paragraph)
3045 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3046 (goto-char (point-max))
3048 (org-backward-paragraph)
3050 ;; Ignore invisible elements.
3052 (org-test-with-temp-text "* H1\n P1\n* H2"
3054 (goto-char (point-max))
3056 (org-backward-paragraph)
3058 ;; On an affiliated keyword, jump to the first one.
3060 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3061 (search-forward "c2")
3062 (org-backward-paragraph)
3063 (looking-at "#\\+name")))
3064 ;; On the second element in an item or a footnote definition, jump
3065 ;; to item or the definition.
3067 (org-test-with-temp-text "- line1\n\n line2"
3068 (goto-char (point-max))
3070 (org-backward-paragraph)
3071 (looking-at "- line1")))
3073 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3074 (goto-char (point-max))
3076 (org-backward-paragraph)
3077 (looking-at "\\[fn:1\\] line1")))
3078 ;; On a table (resp. a property drawer), ignore table rows
3079 ;; (resp. node properties).
3081 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3082 (goto-char (point-max))
3084 (org-backward-paragraph)
3087 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3088 (org-backward-paragraph)
3089 (looking-at ":PROPERTIES:")))
3090 ;; On a source or verse block, stop before blank lines.
3092 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3093 (search-forward "L3")
3095 (org-backward-paragraph)
3098 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3099 (search-forward "L3")
3101 (org-backward-paragraph)
3102 (looking-at "L2"))))
3104 (ert-deftest test-org
/forward-element
()
3105 "Test `org-forward-element' specifications."
3106 ;; 1. At EOB: should error.
3107 (org-test-with-temp-text "Some text\n"
3108 (goto-char (point-max))
3109 (should-error (org-forward-element)))
3110 ;; 2. Standard move: expected to ignore blank lines.
3111 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3112 (org-forward-element)
3113 (should (looking-at (regexp-quote "Second paragraph."))))
3114 ;; 3. Headline tests.
3115 (org-test-with-temp-text "
3120 ;; 3.1. At an headline beginning: move to next headline at the
3123 (org-forward-element)
3124 (should (looking-at (regexp-quote "** Head 1.2")))
3125 ;; 3.2. At an headline beginning: move to parent headline if no
3126 ;; headline at the same level.
3128 (org-forward-element)
3129 (should (looking-at (regexp-quote "** Head 1.2"))))
3130 ;; 4. Greater element tests.
3131 (org-test-with-temp-text
3132 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3133 ;; 4.1. At a greater element: expected to skip contents.
3134 (org-forward-element)
3135 (should (looking-at (regexp-quote "Outside.")))
3136 ;; 4.2. At the end of greater element contents: expected to skip
3137 ;; to the end of the greater element.
3139 (org-forward-element)
3140 (should (looking-at (regexp-quote "Outside."))))
3142 (org-test-with-temp-text "
3156 ;; 5.1. At list top point: expected to move to the element after
3159 (org-forward-element)
3160 (should (looking-at (regexp-quote "Outside.")))
3161 ;; 5.2. Special case: at the first line of a sub-list, but not at
3162 ;; beginning of line, move to next item.
3165 (org-forward-element)
3166 (should (looking-at "- item2"))
3169 (org-forward-element)
3170 (should (looking-at " - sub2"))
3171 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3173 (org-forward-element)
3174 (should (looking-at (regexp-quote " Inner paragraph.")))
3175 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3177 (org-forward-element)
3178 (should (looking-at (regexp-quote " Inner paragraph.")))
3179 ;; 5.5. At an item: expected to move to next item, if any.
3181 (org-forward-element)
3182 (should (looking-at " - sub3"))))
3184 (ert-deftest test-org
/backward-element
()
3185 "Test `org-backward-element' specifications."
3186 ;; 1. Should error at BOB.
3187 (org-test-with-temp-text " \nParagraph."
3188 (should-error (org-backward-element)))
3189 ;; 2. Should move at BOB when called on the first element in buffer.
3191 (org-test-with-temp-text "\n#+TITLE: test"
3192 (progn (forward-line)
3193 (org-backward-element)
3195 ;; 3. Not at the beginning of an element: move at its beginning.
3196 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3199 (org-backward-element)
3200 (should (looking-at (regexp-quote "Paragraph2."))))
3201 ;; 4. Headline tests.
3202 (org-test-with-temp-text "
3207 ;; 4.1. At an headline beginning: move to previous headline at the
3210 (org-backward-element)
3211 (should (looking-at (regexp-quote "** Head 1.1")))
3212 ;; 4.2. At an headline beginning: move to parent headline if no
3213 ;; headline at the same level.
3215 (org-backward-element)
3216 (should (looking-at (regexp-quote "* Head 1")))
3217 ;; 4.3. At the first top-level headline: should error.
3219 (should-error (org-backward-element)))
3220 ;; 5. At beginning of first element inside a greater element:
3221 ;; expected to move to greater element's beginning.
3222 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3224 (org-backward-element)
3225 (should (looking-at "#\\+BEGIN_CENTER")))
3226 ;; 6. At the beginning of the first element in a section: should
3227 ;; move back to headline, if any.
3229 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3230 (progn (goto-char (point-max))
3232 (org-backward-element)
3233 (org-at-heading-p))))
3235 (org-test-with-temp-text "
3250 ;; 7.1. At beginning of sub-list: expected to move to the
3251 ;; paragraph before it.
3253 (org-backward-element)
3254 (should (looking-at "item1"))
3255 ;; 7.2. At an item in a list: expected to move at previous item.
3257 (org-backward-element)
3258 (should (looking-at " - sub2"))
3260 (org-backward-element)
3261 (should (looking-at "- item1"))
3262 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3265 (org-backward-element)
3266 (should (looking-at " - sub1"))
3268 (org-backward-element)
3269 (should (looking-at "- item1"))
3270 ;; 7.4. At blank-lines before list end: expected to move to top
3273 (org-backward-element)
3274 (should (looking-at "- item1"))))
3276 (ert-deftest test-org
/up-element
()
3277 "Test `org-up-element' specifications."
3278 ;; 1. At BOB or with no surrounding element: should error.
3279 (org-test-with-temp-text "Paragraph."
3280 (should-error (org-up-element)))
3281 (org-test-with-temp-text "* Head1\n* Head2"
3283 (should-error (org-up-element)))
3284 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3286 (should-error (org-up-element)))
3287 ;; 2. At an headline: move to parent headline.
3288 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3291 (should (looking-at "\\* Head1")))
3292 ;; 3. Inside a greater element: move to greater element beginning.
3293 (org-test-with-temp-text
3294 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3297 (should (looking-at "#\\+BEGIN_CENTER")))
3299 (org-test-with-temp-text "* Top
3306 Paragraph within sub2.
3309 ;; 4.1. Within an item: move to the item beginning.
3312 (should (looking-at " - sub2"))
3313 ;; 4.2. At an item in a sub-list: move to parent item.
3316 (should (looking-at "- item1"))
3317 ;; 4.3. At an item in top list: move to beginning of whole list.
3320 (should (looking-at "- item1"))
3321 ;; 4.4. Special case. At very top point: should move to parent of
3325 (should (looking-at "\\* Top"))))
3327 (ert-deftest test-org
/down-element
()
3328 "Test `org-down-element' specifications."
3329 ;; Error when the element hasn't got a recursive type.
3330 (org-test-with-temp-text "Paragraph."
3331 (should-error (org-down-element)))
3332 ;; Error when the element has no contents
3333 (org-test-with-temp-text "* Headline"
3334 (should-error (org-down-element)))
3335 ;; When at a plain-list, move to first item.
3336 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3339 (should (looking-at " - Item 1.1")))
3340 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3342 (should (looking-at " Item 1")))
3343 ;; When at a table, move to first row
3344 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3346 (should (looking-at " a | b |")))
3347 ;; Otherwise, move inside the greater element.
3348 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3350 (should (looking-at "Paragraph"))))
3352 (ert-deftest test-org
/drag-element-backward
()
3353 "Test `org-drag-element-backward' specifications."
3357 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3358 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3359 (org-drag-element-backward)
3363 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3364 (org-test-with-temp-text
3365 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3366 (org-drag-element-backward)
3368 ;; Preserve blank lines.
3370 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3371 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3372 (org-drag-element-backward)
3376 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3377 (org-drag-element-backward)
3378 (looking-at-p "2")))
3379 ;; Error when trying to move first element of buffer.
3381 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3382 (org-drag-element-backward))
3384 ;; Error when trying to swap nested elements.
3386 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3387 (org-drag-element-backward))
3389 ;; Error when trying to swap an headline element and a non-headline
3392 (org-test-with-temp-text "Test.\n<point>* Head 1"
3393 (org-drag-element-backward))
3395 ;; Error when called before first element.
3397 (org-test-with-temp-text "\n<point>"
3398 (org-drag-element-backward))
3400 ;; Preserve visibility of elements and their contents.
3402 (equal '((63 .
82) (26 .
48))
3403 (org-test-with-temp-text "
3411 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3412 (search-backward "- item 1")
3413 (org-drag-element-backward)
3414 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3415 (overlays-in (point-min) (point-max))))))
3416 ;; Pathological case: handle call with point in blank lines right
3417 ;; after a headline.
3419 (equal "* H2\n* H1\nText\n\n"
3420 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3421 (org-drag-element-backward)
3424 (ert-deftest test-org
/drag-element-forward
()
3425 "Test `org-drag-element-forward' specifications."
3426 ;; 1. Error when trying to move first element of buffer.
3427 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3429 (should-error (org-drag-element-forward)))
3430 ;; 2. Error when trying to swap nested elements.
3431 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3433 (should-error (org-drag-element-forward)))
3434 ;; 3. Error when trying to swap a non-headline element and an
3436 (org-test-with-temp-text "Test.\n* Head 1"
3437 (should-error (org-drag-element-forward)))
3438 ;; 4. Error when called before first element.
3440 (org-test-with-temp-text "\n"
3442 (org-drag-element-backward))
3444 ;; 5. Otherwise, swap elements, preserving column and blank lines
3445 ;; between elements.
3446 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3447 (search-forward "graph")
3448 (org-drag-element-forward)
3449 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3450 (should (looking-at " 1")))
3451 ;; 5. Preserve visibility of elements and their contents.
3452 (org-test-with-temp-text "
3460 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3461 (search-backward "#+BEGIN_CENTER")
3462 (org-drag-element-forward)
3465 '((63 .
82) (26 .
48))
3466 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3467 (overlays-in (point-min) (point-max)))))))
3469 (ert-deftest test-org
/next-block
()
3470 "Test `org-next-block' specifications."
3473 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3475 (looking-at "#\\+BEGIN_CENTER")))
3478 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3479 (let ((case-fold-search nil
))
3481 (looking-at "#\\+begin_center"))))
3482 ;; Ignore current line.
3484 (org-test-with-temp-text
3485 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3487 (looking-at "#\\+BEGIN_CENTER")))
3488 ;; Throw an error when no block is found.
3490 (org-test-with-temp-text "Paragraph"
3491 (org-next-block 1)))
3492 ;; With an argument, skip many blocks at once.
3494 (org-test-with-temp-text
3495 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3497 (looking-at "#\\+BEGIN_QUOTE")))
3498 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3500 (org-test-with-temp-text
3501 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3502 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3503 (looking-at "#\\+BEGIN_QUOTE")))
3504 ;; Optional argument is also case-insensitive.
3506 (org-test-with-temp-text
3507 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3508 (let ((case-fold-search nil
))
3509 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3510 (looking-at "#\\+begin_quote")))))
3512 (ert-deftest test-org
/previous-block
()
3513 "Test `org-previous-block' specifications."
3516 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3517 (org-previous-block 1)
3518 (looking-at "#\\+BEGIN_CENTER")))
3521 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3522 (let ((case-fold-search nil
))
3523 (org-previous-block 1)
3524 (looking-at "#\\+begin_center"))))
3525 ;; Ignore current line.
3527 (org-test-with-temp-text
3528 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3529 (org-previous-block 1)
3530 (looking-at "#\\+BEGIN_QUOTE")))
3531 ;; Throw an error when no block is found.
3533 (org-test-with-temp-text "Paragraph<point>"
3534 (org-previous-block 1)))
3535 ;; With an argument, skip many blocks at once.
3537 (org-test-with-temp-text
3538 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3539 (org-previous-block 2)
3540 (looking-at "#\\+BEGIN_CENTER")))
3541 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3543 (org-test-with-temp-text
3544 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3545 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3546 (looking-at "#\\+BEGIN_QUOTE")))
3547 ;; Optional argument is also case-insensitive.
3549 (org-test-with-temp-text
3550 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3551 (let ((case-fold-search nil
))
3552 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3553 (looking-at "#\\+begin_quote")))))
3556 ;;; Outline structure
3558 (ert-deftest test-org
/demote
()
3559 "Test `org-demote' specifications."
3560 ;; Add correct number of stars according to `org-odd-levels-only'.
3563 (org-test-with-temp-text "* H"
3564 (let ((org-odd-levels-only nil
)) (org-demote))
3565 (org-current-level))))
3568 (org-test-with-temp-text "* H"
3569 (let ((org-odd-levels-only t
)) (org-demote))
3570 (org-current-level))))
3571 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3573 (org-test-with-temp-text "* H :tag:"
3574 (let ((org-tags-column 10)
3575 (org-auto-align-tags t
)
3576 (org-odd-levels-only nil
))
3578 (org-move-to-column 10)
3579 (looking-at-p ":tag:$")))
3581 (org-test-with-temp-text "* H :tag:"
3582 (let ((org-tags-column 10)
3583 (org-auto-align-tags nil
)
3584 (org-odd-levels-only nil
))
3586 (org-move-to-column 10)
3587 (looking-at-p ":tag:$")))
3588 ;; When `org-adapt-indentation' is non-nil, always indent planning
3589 ;; info and property drawers accordingly.
3592 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3593 (let ((org-odd-levels-only nil
)
3594 (org-adapt-indentation t
))
3597 (org-get-indentation))))
3600 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3601 (let ((org-odd-levels-only nil
)
3602 (org-adapt-indentation t
))
3605 (org-get-indentation))))
3608 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3609 (let ((org-odd-levels-only nil
)
3610 (org-adapt-indentation nil
))
3613 (org-get-indentation))))
3614 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3615 ;; section accordingly. Ignore, however, footnote definitions and
3616 ;; inlinetasks boundaries.
3619 (org-test-with-temp-text "* H\n Paragraph"
3620 (let ((org-odd-levels-only nil
)
3621 (org-adapt-indentation t
))
3624 (org-get-indentation))))
3627 (org-test-with-temp-text "* H\n Paragraph"
3628 (let ((org-odd-levels-only nil
)
3629 (org-adapt-indentation nil
))
3632 (org-get-indentation))))
3635 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3636 (let ((org-odd-levels-only nil
)
3637 (org-adapt-indentation t
))
3639 (goto-char (point-max))
3640 (org-get-indentation))))
3643 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3644 (let ((org-odd-levels-only nil
)
3645 (org-adapt-indentation t
))
3647 (goto-char (point-max))
3648 (org-get-indentation))))
3649 (when (featurep 'org-inlinetask
)
3652 (let ((org-inlinetask-min-level 5)
3653 (org-adapt-indentation t
))
3654 (org-test-with-temp-text "* H\n***** I\n***** END"
3657 (org-get-indentation))))))
3658 (when (featurep 'org-inlinetask
)
3661 (let ((org-inlinetask-min-level 5)
3662 (org-adapt-indentation t
))
3663 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3666 (org-get-indentation))))))
3667 ;; Ignore contents of source blocks or example blocks when
3668 ;; indentation should be preserved (through
3669 ;; `org-src-preserve-indentation' or "-i" flag).
3672 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3673 (let ((org-adapt-indentation t
)
3674 (org-src-preserve-indentation nil
))
3677 (org-get-indentation))))
3680 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3681 (let ((org-adapt-indentation t
)
3682 (org-src-preserve-indentation t
))
3685 (org-get-indentation))))
3688 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3689 (let ((org-adapt-indentation t
)
3690 (org-src-preserve-indentation t
))
3693 (org-get-indentation))))
3696 (org-test-with-temp-text
3697 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3698 (let ((org-adapt-indentation t
)
3699 (org-src-preserve-indentation nil
))
3702 (org-get-indentation)))))
3704 (ert-deftest test-org
/promote
()
3705 "Test `org-promote' specifications."
3706 ;; Return an error if headline is to be promoted to level 0, unless
3707 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3708 ;; headline becomes a comment.
3710 (org-test-with-temp-text "* H"
3711 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3714 (org-test-with-temp-text "* H"
3715 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3717 ;; Remove correct number of stars according to
3718 ;; `org-odd-levels-only'.
3721 (org-test-with-temp-text "*** H"
3722 (let ((org-odd-levels-only nil
)) (org-promote))
3723 (org-current-level))))
3726 (org-test-with-temp-text "*** H"
3727 (let ((org-odd-levels-only t
)) (org-promote))
3728 (org-current-level))))
3729 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3731 (org-test-with-temp-text "** H :tag:"
3732 (let ((org-tags-column 10)
3733 (org-auto-align-tags t
)
3734 (org-odd-levels-only nil
))
3736 (org-move-to-column 10)
3737 (looking-at-p ":tag:$")))
3739 (org-test-with-temp-text "** H :tag:"
3740 (let ((org-tags-column 10)
3741 (org-auto-align-tags nil
)
3742 (org-odd-levels-only nil
))
3744 (org-move-to-column 10)
3745 (looking-at-p ":tag:$")))
3746 ;; When `org-adapt-indentation' is non-nil, always indent planning
3747 ;; info and property drawers.
3750 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3751 (let ((org-odd-levels-only nil
)
3752 (org-adapt-indentation t
))
3755 (org-get-indentation))))
3758 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3759 (let ((org-odd-levels-only nil
)
3760 (org-adapt-indentation t
))
3763 (org-get-indentation))))
3766 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3767 (let ((org-odd-levels-only nil
)
3768 (org-adapt-indentation nil
))
3771 (org-get-indentation))))
3772 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3773 ;; section accordingly. Ignore, however, footnote definitions and
3774 ;; inlinetasks boundaries.
3777 (org-test-with-temp-text "** H\n Paragraph"
3778 (let ((org-odd-levels-only nil
)
3779 (org-adapt-indentation t
))
3782 (org-get-indentation))))
3785 (org-test-with-temp-text "** H\n Paragraph"
3786 (let ((org-odd-levels-only nil
)
3787 (org-adapt-indentation nil
))
3790 (org-get-indentation))))
3793 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3794 (let ((org-odd-levels-only nil
)
3795 (org-adapt-indentation t
))
3798 (org-get-indentation))))
3799 (when (featurep 'org-inlinetask
)
3802 (let ((org-inlinetask-min-level 5)
3803 (org-adapt-indentation t
))
3804 (org-test-with-temp-text "** H\n***** I\n***** END"
3807 (org-get-indentation))))))
3808 (when (featurep 'org-inlinetask
)
3811 (let ((org-inlinetask-min-level 5)
3812 (org-adapt-indentation t
))
3813 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3816 (org-get-indentation))))))
3817 ;; Give up shifting if it would break document's structure
3821 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3822 (let ((org-odd-levels-only nil
)
3823 (org-adapt-indentation t
))
3826 (org-get-indentation))))
3829 (org-test-with-temp-text "** H\n Paragraph\n * list."
3830 (let ((org-odd-levels-only nil
)
3831 (org-adapt-indentation t
))
3834 (org-get-indentation))))
3835 ;; Ignore contents of source blocks or example blocks when
3836 ;; indentation should be preserved (through
3837 ;; `org-src-preserve-indentation' or "-i" flag).
3840 (org-test-with-temp-text
3841 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3842 (let ((org-adapt-indentation t
)
3843 (org-src-preserve-indentation nil
)
3844 (org-odd-levels-only nil
))
3847 (org-get-indentation))))
3850 (org-test-with-temp-text
3851 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3852 (let ((org-adapt-indentation t
)
3853 (org-src-preserve-indentation t
)
3854 (org-odd-levels-only nil
))
3857 (org-get-indentation))))
3860 (org-test-with-temp-text
3861 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3862 (let ((org-adapt-indentation t
)
3863 (org-src-preserve-indentation t
)
3864 (org-odd-levels-only nil
))
3867 (org-get-indentation))))
3870 (org-test-with-temp-text
3871 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3872 (let ((org-adapt-indentation t
)
3873 (org-src-preserve-indentation nil
)
3874 (org-odd-levels-only nil
))
3877 (org-get-indentation)))))
3879 (ert-deftest test-org
/org-get-valid-level
()
3880 "Test function `org-get-valid-level' specifications."
3881 (let ((org-odd-levels-only nil
))
3882 (should (equal 1 (org-get-valid-level 0 0)))
3883 (should (equal 1 (org-get-valid-level 0 1)))
3884 (should (equal 2 (org-get-valid-level 0 2)))
3885 (should (equal 3 (org-get-valid-level 0 3)))
3886 (should (equal 1 (org-get-valid-level 1 0)))
3887 (should (equal 2 (org-get-valid-level 1 1)))
3888 (should (equal 23 (org-get-valid-level 1 22)))
3889 (should (equal 1 (org-get-valid-level 1 -
1)))
3890 (should (equal 1 (org-get-valid-level 2 -
1))))
3891 (let ((org-odd-levels-only t
))
3892 (should (equal 1 (org-get-valid-level 0 0)))
3893 (should (equal 1 (org-get-valid-level 0 1)))
3894 (should (equal 3 (org-get-valid-level 0 2)))
3895 (should (equal 5 (org-get-valid-level 0 3)))
3896 (should (equal 1 (org-get-valid-level 1 0)))
3897 (should (equal 3 (org-get-valid-level 1 1)))
3898 (should (equal 3 (org-get-valid-level 2 1)))
3899 (should (equal 5 (org-get-valid-level 3 1)))
3900 (should (equal 5 (org-get-valid-level 4 1)))
3901 (should (equal 43 (org-get-valid-level 1 21)))
3902 (should (equal 1 (org-get-valid-level 1 -
1)))
3903 (should (equal 1 (org-get-valid-level 2 -
1)))
3904 (should (equal 1 (org-get-valid-level 3 -
1)))
3905 (should (equal 3 (org-get-valid-level 4 -
1)))
3906 (should (equal 3 (org-get-valid-level 5 -
1)))))
3911 (ert-deftest test-org
/at-planning-p
()
3912 "Test `org-at-planning-p' specifications."
3915 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3916 (org-at-planning-p)))
3918 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3919 (org-at-planning-p)))
3920 ;; Correctly find planning attached to inlinetasks.
3921 (when (featurep 'org-inlinetask
)
3923 (org-test-with-temp-text
3924 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3925 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3927 (org-test-with-temp-text
3928 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3929 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3931 (org-test-with-temp-text
3932 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3933 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3935 (org-test-with-temp-text
3936 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3937 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3939 (ert-deftest test-org
/add-planning-info
()
3940 "Test `org-add-planning-info'."
3941 ;; Create deadline when `org-adapt-indentation' is non-nil.
3943 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3944 (org-test-with-temp-text "* H\nParagraph<point>"
3945 (let ((org-adapt-indentation t
))
3946 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3947 (replace-regexp-in-string
3948 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3950 ;; Create deadline when `org-adapt-indentation' is nil.
3952 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3953 (org-test-with-temp-text "* H\nParagraph<point>"
3954 (let ((org-adapt-indentation nil
))
3955 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3956 (replace-regexp-in-string
3957 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3959 ;; Update deadline when `org-adapt-indentation' is non-nil.
3961 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3962 (org-test-with-temp-text "\
3964 DEADLINE: <2015-06-24 Wed>
3966 (let ((org-adapt-indentation t
))
3967 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3968 (replace-regexp-in-string
3969 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3971 ;; Update deadline when `org-adapt-indentation' is nil.
3973 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3974 (org-test-with-temp-text "\
3976 DEADLINE: <2015-06-24 Wed>
3978 (let ((org-adapt-indentation nil
))
3979 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3980 (replace-regexp-in-string
3981 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3983 ;; Schedule when `org-adapt-indentation' is non-nil.
3985 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3986 (org-test-with-temp-text "* H\nParagraph<point>"
3987 (let ((org-adapt-indentation t
))
3988 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3989 (replace-regexp-in-string
3990 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3992 ;; Schedule when `org-adapt-indentation' is nil.
3994 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3995 (org-test-with-temp-text "* H\nParagraph<point>"
3996 (let ((org-adapt-indentation nil
))
3997 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3998 (replace-regexp-in-string
3999 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4001 ;; Add deadline when scheduled.
4005 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4007 (org-test-with-temp-text "\
4009 SCHEDULED: <2015-06-24 Wed>
4011 (let ((org-adapt-indentation t
))
4012 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4013 (replace-regexp-in-string
4014 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4016 ;; Remove middle entry.
4020 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4022 (org-test-with-temp-text "\
4024 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4026 (let ((org-adapt-indentation t
))
4027 (org-add-planning-info nil nil
'deadline
))
4028 (replace-regexp-in-string
4029 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4031 ;; Remove last entry and then middle entry (order should not
4036 CLOSED: [2015-06-24]
4038 (org-test-with-temp-text "\
4040 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4042 (let ((org-adapt-indentation t
))
4043 (org-add-planning-info nil nil
'scheduled
'deadline
))
4044 (replace-regexp-in-string
4045 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4047 ;; Remove closed when `org-adapt-indentation' is non-nil.
4049 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4050 (org-test-with-temp-text "\
4052 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4054 (let ((org-adapt-indentation t
))
4055 (org-add-planning-info nil nil
'closed
))
4056 (replace-regexp-in-string
4057 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4060 (equal "* H\n Paragraph"
4061 (org-test-with-temp-text "\
4063 CLOSED: [2015-06-25 Thu]
4065 (let ((org-adapt-indentation t
))
4066 (org-add-planning-info nil nil
'closed
))
4067 (replace-regexp-in-string
4068 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4070 ;; Remove closed when `org-adapt-indentation' is nil.
4072 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4073 (org-test-with-temp-text "\
4075 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4077 (let ((org-adapt-indentation nil
))
4078 (org-add-planning-info nil nil
'closed
))
4079 (replace-regexp-in-string
4080 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4083 (equal "* H\nParagraph"
4084 (org-test-with-temp-text "\
4086 CLOSED: [2015-06-25 Thu]
4088 (let ((org-adapt-indentation nil
))
4089 (org-add-planning-info nil nil
'closed
))
4090 (replace-regexp-in-string
4091 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4093 ;; Remove closed entry and delete empty line.
4098 (org-test-with-temp-text "\
4100 CLOSED: [2015-06-24 Wed]
4102 (let ((org-adapt-indentation t
))
4103 (org-add-planning-info nil nil
'closed
))
4104 (replace-regexp-in-string
4105 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4107 ;; Remove one entry and update another.
4109 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4110 (org-test-with-temp-text "\
4112 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4114 (let ((org-adapt-indentation t
))
4115 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4116 (replace-regexp-in-string
4117 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4120 (ert-deftest test-org
/deadline
()
4121 "Test `org-deadline' specifications."
4122 ;; Insert a new value or replace existing one.
4124 (equal "* H\nDEADLINE: <2012-03-29>\n"
4125 (org-test-with-temp-text "* H"
4126 (let ((org-adapt-indentation nil
)
4127 (org-last-inserted-timestamp nil
))
4128 (org-deadline nil
"<2012-03-29 Tue>"))
4129 (replace-regexp-in-string
4130 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4133 (equal "* H\nDEADLINE: <2014-03-04>"
4134 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4135 (let ((org-adapt-indentation nil
)
4136 (org-last-inserted-timestamp nil
))
4137 (org-deadline nil
"<2014-03-04 Thu>"))
4138 (replace-regexp-in-string
4139 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4141 ;; Accept delta time, e.g., "+2d".
4143 (equal "* H\nDEADLINE: <2015-03-04>\n"
4144 (cl-letf (((symbol-function 'current-time
)
4145 (lambda (&rest args
)
4146 (apply #'encode-time
4147 (org-parse-time-string "2014-03-04")))))
4148 (org-test-with-temp-text "* H"
4149 (let ((org-adapt-indentation nil
)
4150 (org-last-inserted-timestamp nil
))
4151 (org-deadline nil
"+1y"))
4152 (replace-regexp-in-string
4153 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4154 ;; Preserve repeater.
4156 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4157 (org-test-with-temp-text "* H"
4158 (let ((org-adapt-indentation nil
)
4159 (org-last-inserted-timestamp nil
))
4160 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4161 (replace-regexp-in-string
4162 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4163 ;; Remove CLOSED keyword, if any.
4165 (equal "* H\nDEADLINE: <2012-03-29>"
4166 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4167 (let ((org-adapt-indentation nil
)
4168 (org-last-inserted-timestamp nil
))
4169 (org-deadline nil
"<2012-03-29 Tue>"))
4170 (replace-regexp-in-string
4171 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4172 ;; With C-u argument, remove DEADLINE keyword.
4175 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4176 (let ((org-adapt-indentation nil
)
4177 (org-last-inserted-timestamp nil
))
4178 (org-deadline '(4)))
4182 (org-test-with-temp-text "* H"
4183 (let ((org-adapt-indentation nil
)
4184 (org-last-inserted-timestamp nil
))
4185 (org-deadline '(4)))
4187 ;; With C-u C-u argument, prompt for a delay cookie.
4189 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4190 (cl-letf (((symbol-function 'org-read-date
)
4191 (lambda (&rest args
)
4192 (apply #'encode-time
4193 (org-parse-time-string "2014-03-04")))))
4194 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4195 (let ((org-adapt-indentation nil
)
4196 (org-last-inserted-timestamp nil
))
4197 (org-deadline '(16)))
4200 (cl-letf (((symbol-function 'org-read-date
)
4201 (lambda (&rest args
)
4202 (apply #'encode-time
4203 (org-parse-time-string "2014-03-04")))))
4204 (org-test-with-temp-text "* H"
4205 (let ((org-adapt-indentation nil
)
4206 (org-last-inserted-timestamp nil
))
4207 (org-deadline '(16)))
4209 ;; When a region is active and
4210 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4211 ;; same value in all headlines in region.
4213 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4214 (org-test-with-temp-text "* H1\n* H2"
4215 (let ((org-adapt-indentation nil
)
4216 (org-last-inserted-timestamp nil
)
4217 (org-loop-over-headlines-in-active-region t
))
4218 (transient-mark-mode 1)
4219 (push-mark (point) t t
)
4220 (goto-char (point-max))
4221 (org-deadline nil
"2012-03-29"))
4222 (replace-regexp-in-string
4223 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4225 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4226 (org-test-with-temp-text "* H1\n* H2"
4227 (let ((org-adapt-indentation nil
)
4228 (org-last-inserted-timestamp nil
)
4229 (org-loop-over-headlines-in-active-region nil
))
4230 (transient-mark-mode 1)
4231 (push-mark (point) t t
)
4232 (goto-char (point-max))
4233 (org-deadline nil
"2012-03-29"))
4234 (replace-regexp-in-string
4235 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4237 (ert-deftest test-org
/schedule
()
4238 "Test `org-schedule' specifications."
4239 ;; Insert a new value or replace existing one.
4241 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4242 (org-test-with-temp-text "* H"
4243 (let ((org-adapt-indentation nil
)
4244 (org-last-inserted-timestamp nil
))
4245 (org-schedule nil
"<2012-03-29 Tue>"))
4246 (replace-regexp-in-string
4247 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4250 (equal "* H\nSCHEDULED: <2014-03-04>"
4251 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4252 (let ((org-adapt-indentation nil
)
4253 (org-last-inserted-timestamp nil
))
4254 (org-schedule nil
"<2014-03-04 Thu>"))
4255 (replace-regexp-in-string
4256 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4258 ;; Accept delta time, e.g., "+2d".
4260 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4261 (cl-letf (((symbol-function 'current-time
)
4262 (lambda (&rest args
)
4263 (apply #'encode-time
4264 (org-parse-time-string "2014-03-04")))))
4265 (org-test-with-temp-text "* H"
4266 (let ((org-adapt-indentation nil
)
4267 (org-last-inserted-timestamp nil
))
4268 (org-schedule nil
"+1y"))
4269 (replace-regexp-in-string
4270 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4271 ;; Preserve repeater.
4273 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4274 (org-test-with-temp-text "* H"
4275 (let ((org-adapt-indentation nil
)
4276 (org-last-inserted-timestamp nil
))
4277 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4278 (replace-regexp-in-string
4279 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4280 ;; Remove CLOSED keyword, if any.
4282 (equal "* H\nSCHEDULED: <2012-03-29>"
4283 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4284 (let ((org-adapt-indentation nil
)
4285 (org-last-inserted-timestamp nil
))
4286 (org-schedule nil
"<2012-03-29 Tue>"))
4287 (replace-regexp-in-string
4288 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4289 ;; With C-u argument, remove SCHEDULED keyword.
4292 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4293 (let ((org-adapt-indentation nil
)
4294 (org-last-inserted-timestamp nil
))
4295 (org-schedule '(4)))
4299 (org-test-with-temp-text "* H"
4300 (let ((org-adapt-indentation nil
)
4301 (org-last-inserted-timestamp nil
))
4302 (org-schedule '(4)))
4304 ;; With C-u C-u argument, prompt for a delay cookie.
4306 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4307 (cl-letf (((symbol-function 'org-read-date
)
4308 (lambda (&rest args
)
4309 (apply #'encode-time
4310 (org-parse-time-string "2014-03-04")))))
4311 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4312 (let ((org-adapt-indentation nil
)
4313 (org-last-inserted-timestamp nil
))
4314 (org-schedule '(16)))
4317 (cl-letf (((symbol-function 'org-read-date
)
4318 (lambda (&rest args
)
4319 (apply #'encode-time
4320 (org-parse-time-string "2014-03-04")))))
4321 (org-test-with-temp-text "* H"
4322 (let ((org-adapt-indentation nil
)
4323 (org-last-inserted-timestamp nil
))
4324 (org-schedule '(16)))
4326 ;; When a region is active and
4327 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4328 ;; same value in all headlines in region.
4330 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4331 (org-test-with-temp-text "* H1\n* H2"
4332 (let ((org-adapt-indentation nil
)
4333 (org-last-inserted-timestamp nil
)
4334 (org-loop-over-headlines-in-active-region t
))
4335 (transient-mark-mode 1)
4336 (push-mark (point) t t
)
4337 (goto-char (point-max))
4338 (org-schedule nil
"2012-03-29"))
4339 (replace-regexp-in-string
4340 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4342 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4343 (org-test-with-temp-text "* H1\n* H2"
4344 (let ((org-adapt-indentation nil
)
4345 (org-last-inserted-timestamp nil
)
4346 (org-loop-over-headlines-in-active-region nil
))
4347 (transient-mark-mode 1)
4348 (push-mark (point) t t
)
4349 (goto-char (point-max))
4350 (org-schedule nil
"2012-03-29"))
4351 (replace-regexp-in-string
4352 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4354 ;; check if a repeater survives re-scheduling.
4356 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4357 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4358 (let ((org-adapt-indentation nil
)
4359 (org-last-inserted-timestamp nil
))
4360 (org-schedule nil
"2017-02-01"))
4366 (ert-deftest test-org
/buffer-property-keys
()
4367 "Test `org-buffer-property-keys' specifications."
4368 ;; Retrieve properties accross siblings.
4371 (org-test-with-temp-text "
4380 (org-buffer-property-keys))))
4381 ;; Retrieve properties accross children.
4384 (org-test-with-temp-text "
4393 (org-buffer-property-keys))))
4394 ;; Retrieve muliple properties in the same drawer.
4397 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4398 (org-buffer-property-keys))))
4399 ;; Ignore extension symbol in property name.
4402 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4403 (org-buffer-property-keys))))
4404 ;; With non-nil COLUMNS, extract property names from columns.
4407 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4408 (org-buffer-property-keys nil nil t
))))
4410 (equal '("A" "B" "COLUMNS")
4411 (org-test-with-temp-text
4412 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4413 (org-buffer-property-keys nil nil t
))))
4414 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4417 (org-test-with-temp-text
4418 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4419 (org-buffer-property-keys nil nil nil t
)))))
4421 (ert-deftest test-org
/property-values
()
4422 "Test `org-property-values' specifications."
4426 (org-test-with-temp-text
4427 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4428 (org-property-values "A"))))
4429 ;; Ignore empty values.
4431 (org-test-with-temp-text
4432 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4433 (org-property-values "A")))
4434 ;; Take into consideration extended values.
4437 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4438 (org-property-values "A")))))
4440 (ert-deftest test-org
/find-property
()
4441 "Test `org-find-property' specifications."
4445 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4446 (org-find-property "prop"))))
4447 ;; Ignore false positives.
4450 (org-test-with-temp-text
4451 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4452 (org-find-property "A"))))
4453 ;; Return first entry found in buffer.
4456 (org-test-with-temp-text
4457 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4458 (org-find-property "A"))))
4459 ;; Only search visible part of the buffer.
4462 (org-test-with-temp-text
4463 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4464 (org-narrow-to-subtree)
4465 (org-find-property "A"))))
4466 ;; With optional argument, only find entries with a specific value.
4468 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4469 (org-find-property "A" "2")))
4472 (org-test-with-temp-text
4473 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4474 (org-find-property "A" "2"))))
4475 ;; Use "nil" for explicit nil values.
4478 (org-test-with-temp-text
4479 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4480 (org-find-property "A" "nil")))))
4482 (ert-deftest test-org
/entry-delete
()
4483 "Test `org-entry-delete' specifications."
4487 " *:PROPERTIES:\n *:B: +2\n *:END:"
4488 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4489 (org-entry-delete (point) "A")
4491 ;; Also remove accumulated properties.
4495 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4496 (org-entry-delete (point) "A")
4498 ;; When last property is removed, remove the property drawer.
4502 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4503 (org-entry-delete (point) "A")
4505 ;; Return a non-nil value when some property was removed.
4507 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4508 (org-entry-delete (point) "A")))
4510 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4511 (org-entry-delete (point) "C")))
4512 ;; Special properties cannot be located in a drawer. Allow to
4513 ;; remove them anyway, in case of user error.
4515 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4516 (org-entry-delete (point) "SCHEDULED"))))
4518 (ert-deftest test-org
/entry-get
()
4519 "Test `org-entry-get' specifications."
4523 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4524 (org-entry-get (point) "A"))))
4528 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4529 (org-entry-get (point) "a"))))
4530 ;; Handle extended values, both before and after base value.
4533 (org-test-with-temp-text
4534 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4535 (org-entry-get (point) "A"))))
4536 ;; Empty values are returned as the empty string.
4539 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4540 (org-entry-get (point) "A"))))
4541 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4542 ;; otherwise, return nil.
4544 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4545 (org-entry-get (point) "A")))
4548 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4549 (org-entry-get (point) "A" nil t
))))
4550 ;; Return nil when no property is found, independently on the
4551 ;; LITERAL-NIL argument.
4553 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4554 (org-entry-get (point) "B")))
4556 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4557 (org-entry-get (point) "B" nil t
)))
4558 ;; Handle inheritance, when allowed. Include extended values and
4559 ;; possibly global values.
4563 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4564 (org-entry-get (point) "A" t
))))
4568 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4569 (let ((org-use-property-inheritance t
))
4570 (org-entry-get (point) "A" 'selective
)))))
4572 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4573 (let ((org-use-property-inheritance nil
))
4574 (org-entry-get (point) "A" 'selective
))))
4578 (org-test-with-temp-text
4579 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4580 (org-entry-get (point-max) "A" t
))))
4583 (org-test-with-temp-text
4584 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4586 (org-entry-get (point-max) "A" t
))))
4589 (org-test-with-temp-text
4590 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4592 (org-entry-get (point-max) "A" t
)))))
4594 (ert-deftest test-org
/entry-properties
()
4595 "Test `org-entry-properties' specifications."
4596 ;; Get "ITEM" property.
4599 (org-test-with-temp-text "* TODO H"
4600 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4603 (org-test-with-temp-text "* TODO H"
4604 (cdr (assoc "ITEM" (org-entry-properties))))))
4605 ;; Get "TODO" property. TODO keywords are case sensitive.
4608 (org-test-with-temp-text "* TODO H"
4609 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4612 (org-test-with-temp-text "* TODO H"
4613 (cdr (assoc "TODO" (org-entry-properties))))))
4615 (org-test-with-temp-text "* H"
4616 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4618 (org-test-with-temp-text "* todo H"
4619 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4620 ;; Get "PRIORITY" property.
4623 (org-test-with-temp-text "* [#A] H"
4624 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4627 (org-test-with-temp-text "* [#A] H"
4628 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4630 (equal (char-to-string org-default-priority
)
4631 (org-test-with-temp-text "* H"
4632 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4633 ;; Get "FILE" property.
4635 (org-test-with-temp-text-in-file "* H\nParagraph"
4636 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4637 (buffer-file-name))))
4639 (org-test-with-temp-text-in-file "* H\nParagraph"
4640 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4641 (buffer-file-name))))
4643 (org-test-with-temp-text "* H\nParagraph"
4644 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4645 ;; Get "TAGS" property.
4647 (equal ":tag1:tag2:"
4648 (org-test-with-temp-text "* H :tag1:tag2:"
4649 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4651 (equal ":tag1:tag2:"
4652 (org-test-with-temp-text "* H :tag1:tag2:"
4653 (cdr (assoc "TAGS" (org-entry-properties))))))
4655 (org-test-with-temp-text "* H"
4656 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4657 ;; Get "ALLTAGS" property.
4659 (equal ":tag1:tag2:"
4660 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4661 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4663 (equal ":tag1:tag2:"
4664 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4665 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4667 (org-test-with-temp-text "* H"
4668 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4669 ;; Get "BLOCKED" property.
4672 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4673 (let ((org-enforce-todo-dependencies t
)
4675 '(org-block-todo-from-children-or-siblings-or-parent)))
4676 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4679 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4680 (let ((org-enforce-todo-dependencies t
)
4682 '(org-block-todo-from-children-or-siblings-or-parent)))
4683 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4684 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4688 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4689 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4693 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4694 (cdr (assoc "CLOSED" (org-entry-properties))))))
4696 (org-test-with-temp-text "* H"
4697 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4701 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4702 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4706 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4707 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4709 (org-test-with-temp-text "* H"
4710 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4714 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4715 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4719 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4720 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4722 (org-test-with-temp-text "* H"
4723 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4727 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4728 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4731 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4732 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4735 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4736 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4739 (org-test-with-temp-text
4740 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4742 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4743 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4744 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4746 (equal "<2012-03-29 thu.>"
4747 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4748 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4750 (equal "[2012-03-29 thu.]"
4751 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4752 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4754 (equal "<2012-03-29 thu.>"
4755 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4756 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4758 (equal "[2014-03-04 tue.]"
4759 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4760 (cdr (assoc "TIMESTAMP_IA"
4761 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4763 (equal "<2012-03-29 thu.>"
4764 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4765 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4766 ;; Get standard properties.
4769 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4770 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4771 ;; Handle extended properties.
4774 (org-test-with-temp-text
4775 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4776 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4779 (org-test-with-temp-text
4780 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4781 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4782 ;; Ignore forbidden (special) properties.
4784 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4785 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4787 (ert-deftest test-org
/entry-put
()
4788 "Test `org-entry-put' specifications."
4789 ;; Error when not a string or nil.
4791 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4792 (org-entry-put 1 "test" 2)))
4793 ;; Error when property name is invalid.
4795 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4796 (org-entry-put 1 "no space" "value")))
4798 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4799 (org-entry-put 1 "" "value")))
4800 ;; Set "TODO" property.
4802 (string-match (regexp-quote " TODO H")
4803 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4804 (org-entry-put (point) "TODO" "TODO")
4807 (string-match (regexp-quote "* H")
4808 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4809 (org-entry-put (point) "TODO" nil
)
4811 ;; Set "PRIORITY" property.
4814 (org-test-with-temp-text "* [#B] H"
4815 (org-entry-put (point) "PRIORITY" "A")
4819 (org-test-with-temp-text "* [#B] H"
4820 (org-entry-put (point) "PRIORITY" nil
)
4822 ;; Set "SCHEDULED" property.
4824 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4825 (org-test-with-temp-text "* H"
4826 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4830 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4831 (org-entry-put (point) "SCHEDULED" nil
)
4834 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4835 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4836 (org-entry-put (point) "SCHEDULED" "earlier")
4839 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4840 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4841 (org-entry-put (point) "SCHEDULED" "later")
4843 ;; Set "DEADLINE" property.
4845 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4846 (org-test-with-temp-text "* H"
4847 (org-entry-put (point) "DEADLINE" "2014-03-04")
4851 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4852 (org-entry-put (point) "DEADLINE" nil
)
4855 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4856 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4857 (org-entry-put (point) "DEADLINE" "earlier")
4860 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4861 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4862 (org-entry-put (point) "DEADLINE" "later")
4864 ;; Set "CATEGORY" property
4866 (string-match "^ *:CATEGORY: cat"
4867 (org-test-with-temp-text "* H"
4868 (org-entry-put (point) "CATEGORY" "cat")
4870 ;; Regular properties, with or without pre-existing drawer.
4872 (string-match "^ *:A: +2$"
4873 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4874 (org-entry-put (point) "A" "2")
4877 (string-match "^ *:A: +1$"
4878 (org-test-with-temp-text "* H"
4879 (org-entry-put (point) "A" "1")
4881 ;; Special case: two consecutive headlines.
4883 (string-match "\\* A\n *:PROPERTIES:"
4884 (org-test-with-temp-text "* A\n** B"
4885 (org-entry-put (point) "A" "1")
4888 (ert-deftest test-org
/refresh-properties
()
4889 "Test `org-refresh-properties' specifications."
4892 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4893 (org-refresh-properties "A" 'org-test
)
4894 (get-text-property (point) 'org-test
))))
4896 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4897 (org-refresh-properties "B" 'org-test
)
4898 (get-text-property (point) 'org-test
)))
4899 ;; Handle properties only defined with extension syntax, i.e.,
4903 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4904 (org-refresh-properties "A" 'org-test
)
4905 (get-text-property (point) 'org-test
))))
4906 ;; When property is inherited, add text property to the whole
4910 (org-test-with-temp-text
4911 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4912 (let ((org-use-property-inheritance t
))
4913 (org-refresh-properties "A" 'org-test
))
4914 (get-text-property (point) 'org-test
))))
4915 ;; When property is inherited, use global value across the whole
4916 ;; buffer. However local values have precedence.
4919 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4921 (let ((org-use-property-inheritance nil
))
4922 (org-refresh-properties "A" 'org-test
))
4923 (get-text-property (point) 'org-test
))))
4926 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4928 (let ((org-use-property-inheritance t
))
4929 (org-refresh-properties "A" 'org-test
))
4930 (get-text-property (point) 'org-test
))))
4933 (org-test-with-temp-text
4934 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4936 (let ((org-use-property-inheritance t
))
4937 (org-refresh-properties "A" 'org-test
))
4938 (get-text-property (point) 'org-test
)))))
4943 (ert-deftest test-org
/update-radio-target-regexp
()
4944 "Test `org-update-radio-target-regexp' specifications."
4945 ;; Properly update cache with no previous radio target regexp.
4948 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4949 (save-excursion (goto-char (point-max)) (org-element-context))
4951 (search-forward "o")
4953 (org-update-radio-target-regexp)
4954 (goto-char (point-max))
4955 (org-element-type (org-element-context)))))
4956 ;; Properly update cache with previous radio target regexp.
4959 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4960 (save-excursion (goto-char (point-max)) (org-element-context))
4962 (search-forward "o")
4964 (org-update-radio-target-regexp)
4965 (search-backward "r")
4968 (org-update-radio-target-regexp)
4969 (goto-char (point-max))
4970 (delete-region (line-beginning-position) (point))
4972 (org-element-type (org-element-context))))))
4977 (ert-deftest test-org
/match-sparse-tree
()
4978 "Test `org-match-sparse-tree' specifications."
4981 (org-test-with-temp-text "* H\n** H1 :tag:"
4982 (org-match-sparse-tree nil
"tag")
4983 (search-forward "H1")
4984 (org-invisible-p2)))
4986 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4987 (org-match-sparse-tree nil
"tag")
4988 (search-forward "H2")
4989 (org-invisible-p2)))
4990 ;; "-" operator for tags.
4992 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4993 (org-match-sparse-tree nil
"tag1-tag2")
4994 (search-forward "H1")
4995 (org-invisible-p2)))
4997 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4998 (org-match-sparse-tree nil
"tag1-tag2")
4999 (search-forward "H2")
5000 (org-invisible-p2)))
5001 ;; "&" operator for tags.
5003 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5004 (org-match-sparse-tree nil
"tag1&tag2")
5005 (search-forward "H1")
5006 (org-invisible-p2)))
5008 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5009 (org-match-sparse-tree nil
"tag1&tag2")
5010 (search-forward "H2")
5011 (org-invisible-p2)))
5012 ;; "|" operator for tags.
5014 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5015 (org-match-sparse-tree nil
"tag1|tag2")
5016 (search-forward "H1")
5017 (org-invisible-p2)))
5019 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5020 (org-match-sparse-tree nil
"tag1|tag2")
5021 (search-forward "H2")
5022 (org-invisible-p2)))
5023 ;; Regexp match on tags.
5025 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5026 (org-match-sparse-tree nil
"{^tag.*}")
5027 (search-forward "H1")
5028 (org-invisible-p2)))
5030 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5031 (org-match-sparse-tree nil
"{^tag.*}")
5032 (search-forward "H2")
5033 (org-invisible-p2)))
5034 ;; Match group tags.
5036 (org-test-with-temp-text
5037 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5038 (org-match-sparse-tree nil
"work")
5039 (search-forward "H1")
5040 (org-invisible-p2)))
5042 (org-test-with-temp-text
5043 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5044 (org-match-sparse-tree nil
"work")
5045 (search-forward "H2")
5046 (org-invisible-p2)))
5047 ;; Match group tags with hard brackets.
5049 (org-test-with-temp-text
5050 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5051 (org-match-sparse-tree nil
"work")
5052 (search-forward "H1")
5053 (org-invisible-p2)))
5055 (org-test-with-temp-text
5056 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5057 (org-match-sparse-tree nil
"work")
5058 (search-forward "H2")
5059 (org-invisible-p2)))
5060 ;; Match tags in hierarchies
5062 (org-test-with-temp-text
5063 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5064 #+TAGS: [ Lev_2 : Lev_3 ]\n
5065 #+TAGS: { Lev_3 : Lev_4 }\n
5066 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5067 (org-match-sparse-tree nil
"Lev_1")
5068 (search-forward "H4")
5069 (org-invisible-p2)))
5070 ;; Match regular expressions in tags
5072 (org-test-with-temp-text
5073 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5074 (org-match-sparse-tree nil
"Lev")
5075 (search-forward "H1")
5076 (org-invisible-p2)))
5078 (org-test-with-temp-text
5079 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5080 (org-match-sparse-tree nil
"Lev")
5081 (search-forward "H1")
5082 (org-invisible-p2)))
5083 ;; Match properties.
5085 (org-test-with-temp-text
5086 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5087 (org-match-sparse-tree nil
"A=\"1\"")
5088 (search-forward "H2")
5089 (org-invisible-p2)))
5091 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5092 (org-match-sparse-tree nil
"A=\"1\"")
5093 (search-forward "H2")
5094 (org-invisible-p2)))
5095 ;; Case is not significant when matching properties.
5097 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5098 (org-match-sparse-tree nil
"a=\"1\"")
5099 (search-forward "H2")
5100 (org-invisible-p2)))
5102 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5103 (org-match-sparse-tree nil
"A=\"1\"")
5104 (search-forward "H2")
5105 (org-invisible-p2)))
5106 ;; Match special LEVEL property.
5108 (org-test-with-temp-text "* H\n** H1\n*** H2"
5109 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5110 (search-forward "H1")
5111 (org-invisible-p2)))
5113 (org-test-with-temp-text "* H\n** H1\n*** H2"
5114 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5115 (search-forward "H2")
5116 (org-invisible-p2)))
5117 ;; Comparison operators when matching properties.
5119 (org-test-with-temp-text
5120 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5121 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5122 (search-forward "H1")
5123 (org-invisible-p2)))
5125 (org-test-with-temp-text
5126 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5127 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5128 (search-forward "H2")
5129 (org-invisible-p2)))
5130 ;; Regexp match on properties values.
5132 (org-test-with-temp-text
5133 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5134 (org-match-sparse-tree nil
"A={f.*}")
5135 (search-forward "H1")
5136 (org-invisible-p2)))
5138 (org-test-with-temp-text
5139 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5140 (org-match-sparse-tree nil
"A={f.*}")
5141 (search-forward "H2")
5142 (org-invisible-p2)))
5143 ;; With an optional argument, limit match to TODO entries.
5145 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5146 (org-match-sparse-tree t
"tag")
5147 (search-forward "H1")
5148 (org-invisible-p2)))
5150 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5151 (org-match-sparse-tree t
"tag")
5152 (search-forward "H2")
5153 (org-invisible-p2))))
5155 (ert-deftest test-org
/occur
()
5156 "Test `org-occur' specifications."
5157 ;; Count number of matches.
5160 (org-test-with-temp-text "* H\nA\n* H2"
5164 (org-test-with-temp-text "* H\nA\n* H2\nA"
5166 ;; Test CALLBACK optional argument.
5169 (org-test-with-temp-text "* H\nA\n* H2"
5170 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5173 (org-test-with-temp-text "* H\nA\n* H2\nA"
5174 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5175 ;; Case-fold searches according to `org-occur-case-fold-search'.
5178 (org-test-with-temp-text "Aa"
5179 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5182 (org-test-with-temp-text "Aa"
5183 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5186 (org-test-with-temp-text "Aa"
5187 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5190 (org-test-with-temp-text "Aa"
5191 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5194 (org-test-with-temp-text "Aa"
5195 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5198 (org-test-with-temp-text "Aa"
5199 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5204 (ert-deftest test-org
/tag-string-to-alist
()
5205 "Test `org-tag-string-to-alist' specifications."
5206 ;; Tag without selection key.
5207 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5208 ;; Tag with selection key.
5209 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5213 (org-tag-string-to-alist "[ group : t1 t2 ]")
5214 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5215 ;; Mutually exclusive tags.
5216 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5217 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5220 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5221 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5223 (ert-deftest test-org
/tag-alist-to-string
()
5224 "Test `org-tag-alist-to-string' specifications."
5225 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5226 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5229 (org-tag-alist-to-string
5230 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5231 "[ group : t1 t2 ]"))
5233 (equal (org-tag-alist-to-string
5234 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5238 (org-tag-alist-to-string
5239 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5240 "{ group : tag1 tag2 }")))
5242 (ert-deftest test-org
/tag-alist-to-groups
()
5243 "Test `org-tag-alist-to-groups' specifications."
5245 (equal (org-tag-alist-to-groups
5246 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5247 '(("group" "t1" "t2"))))
5250 (org-tag-alist-to-groups
5251 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5252 '(("group" "t1" "t2"))))
5254 (org-tag-alist-to-groups
5255 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5257 (ert-deftest test-org
/tag-align
()
5258 "Test tags alignment."
5259 ;; Test aligning tags with different display width.
5261 ;; 12345678901234567890
5262 (equal "* Test :abc:"
5263 (org-test-with-temp-text "* Test :abc:"
5264 (let ((org-tags-column -
20)
5265 (indent-tabs-mode nil
))
5266 (org-fix-tags-on-the-fly))
5269 ;; 12345678901234567890
5270 (equal "* Test :日本語:"
5271 (org-test-with-temp-text "* Test :日本語:"
5272 (let ((org-tags-column -
20)
5273 (indent-tabs-mode nil
))
5274 (org-fix-tags-on-the-fly))
5276 ;; Make sure aligning tags do not skip invisible text.
5278 (equal "* [[linkx]] :tag:"
5279 (org-test-with-temp-text "* [[link<point>]] :tag:"
5280 (let ((org-tags-column 0))
5281 (org-fix-tags-on-the-fly)
5283 (buffer-string))))))
5285 (ert-deftest test-org
/tags-at
()
5287 (equal '("foo" "bar")
5288 (org-test-with-temp-text
5289 "* T<point>est :foo:bar:"
5290 (org-get-tags-at)))))
5295 (ert-deftest test-org
/auto-repeat-maybe
()
5296 "Test `org-auto-repeat-maybe' specifications."
5297 ;; Do not auto repeat when there is no valid time stamp with
5298 ;; a repeater in the entry.
5302 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5303 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5309 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5310 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5313 ;; When switching to DONE state, switch back to first TODO keyword
5314 ;; in sequence, or the same keyword if they have different types.
5318 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5319 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5325 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5326 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5332 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5333 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5336 ;; If there was no TODO keyword in the first place, do not insert
5341 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5342 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5345 ;; Revert to REPEAT_TO_STATE, if set.
5349 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5350 (org-test-with-temp-text
5353 :REPEAT_TO_STATE: KWD2
5355 <2012-03-29 Thu +2y>"
5358 ;; When switching to DONE state, update base date. If there are
5359 ;; multiple repeated time stamps, update them all.
5362 "<2014-03-29 .* \\+2y>"
5363 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5364 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5369 "<2015-03-04 .* \\+1y>"
5370 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5371 (org-test-with-temp-text
5372 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5375 ;; Throw an error if repeater unit is the hour and no time is
5376 ;; provided in the time-stamp.
5378 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5379 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5382 ;; Do not repeat commented time stamps.
5385 "<2015-03-04 .* \\+1y>"
5386 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5387 (org-test-with-temp-text
5388 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5393 "<2015-03-04 .* \\+1y>"
5394 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5395 (org-test-with-temp-text
5397 <2012-03-29 Thu. +2y>
5399 <2014-03-04 Tue +1y>
5403 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5404 ;; entry, record time of last repeat.
5408 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5409 (org-log-repeat nil
))
5410 (cl-letf (((symbol-function 'org-add-log-setup
)
5411 (lambda (&rest args
) nil
)))
5412 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5414 (buffer-string))))))
5418 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5420 (cl-letf (((symbol-function 'org-add-log-setup
)
5421 (lambda (&rest args
) nil
)))
5422 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5424 (buffer-string))))))
5428 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5429 (cl-letf (((symbol-function 'org-add-log-setup
)
5430 (lambda (&rest args
) nil
)))
5431 (org-test-with-temp-text
5432 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5434 (buffer-string))))))
5435 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5436 ;; the entry as it is no longer relevant.
5440 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5441 (org-test-with-temp-text
5442 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5444 (buffer-string))))))
5449 (ert-deftest test-org
/at-timestamp-p
()
5450 "Test `org-at-timestamp-p' specifications."
5452 (org-test-with-temp-text "<2012-03-29 Thu>"
5453 (org-at-timestamp-p)))
5455 (org-test-with-temp-text "2012-03-29 Thu"
5456 (org-at-timestamp-p)))
5457 ;; Test return values.
5460 (org-test-with-temp-text "<2012-03-29 Thu>"
5461 (org-at-timestamp-p))))
5464 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5465 (org-at-timestamp-p))))
5468 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5469 (org-at-timestamp-p))))
5472 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5473 (org-at-timestamp-p))))
5476 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5477 (org-at-timestamp-p))))
5480 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5481 (org-at-timestamp-p))))
5484 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5485 (org-at-timestamp-p))))
5488 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5489 (org-at-timestamp-p))))
5490 ;; Test optional argument.
5492 (org-test-with-temp-text "[2012-03-29 Thu]"
5493 (org-at-timestamp-p t
)))
5495 (org-test-with-temp-text "[2012-03-29 Thu]"
5496 (org-at-timestamp-p)))
5497 ;; Unlike `org-element-context', recognize time-stamps in planning
5498 ;; info line, property drawers and clocks.
5500 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5501 (org-at-timestamp-p)))
5503 (org-test-with-temp-text
5504 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5505 (org-at-timestamp-p)))
5507 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5508 (org-at-timestamp-p t
))))
5510 (ert-deftest test-org
/time-stamp
()
5511 "Test `org-time-stamp' specifications."
5512 ;; Insert chosen time stamp at point.
5515 "Te<2014-03-04 .*?>xt"
5516 (org-test-with-temp-text "Te<point>xt"
5517 (cl-letf (((symbol-function 'org-read-date
)
5518 (lambda (&rest args
)
5519 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5520 (org-time-stamp nil
)
5522 ;; With a prefix argument, also insert time.
5525 "Te<2014-03-04 .*? 00:41>xt"
5526 (org-test-with-temp-text "Te<point>xt"
5527 (cl-letf (((symbol-function 'org-read-date
)
5528 (lambda (&rest args
)
5529 (apply #'encode-time
5530 (org-parse-time-string "2014-03-04 00:41")))))
5531 (org-time-stamp '(4))
5533 ;; With two universal prefix arguments, insert an active timestamp
5534 ;; with the current time without prompting the user.
5537 "Te<2014-03-04 .*? 00:41>xt"
5538 (org-test-with-temp-text "Te<point>xt"
5539 (cl-letf (((symbol-function 'current-time
)
5541 (apply #'encode-time
5542 (org-parse-time-string "2014-03-04 00:41")))))
5543 (org-time-stamp '(16))
5545 ;; When optional argument is non-nil, insert an inactive timestamp.
5548 "Te\\[2014-03-04 .*?\\]xt"
5549 (org-test-with-temp-text "Te<point>xt"
5550 (cl-letf (((symbol-function 'org-read-date
)
5551 (lambda (&rest args
)
5552 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5553 (org-time-stamp nil t
)
5555 ;; When called from a timestamp, replace existing one.
5559 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5560 (cl-letf (((symbol-function 'org-read-date
)
5561 (lambda (&rest args
)
5562 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5563 (org-time-stamp nil
)
5567 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5568 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5569 (cl-letf (((symbol-function 'org-read-date
)
5570 (lambda (&rest args
)
5571 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5572 (org-time-stamp nil
)
5574 ;; When replacing a timestamp, preserve repeater, if any.
5577 "<2014-03-04 .*? \\+2y>"
5578 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5579 (cl-letf (((symbol-function 'org-read-date
)
5580 (lambda (&rest args
)
5581 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5582 (org-time-stamp nil
)
5584 ;; When called twice in a raw, build a date range.
5587 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5588 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5589 (cl-letf (((symbol-function 'org-read-date
)
5590 (lambda (&rest args
)
5591 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5592 (let ((last-command 'org-time-stamp
)
5593 (this-command 'org-time-stamp
))
5594 (org-time-stamp nil
))
5595 (buffer-string))))))
5597 (ert-deftest test-org
/timestamp-has-time-p
()
5598 "Test `org-timestamp-has-time-p' specifications."
5601 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5602 (org-timestamp-has-time-p (org-element-context))))
5605 (org-test-with-temp-text "<2012-03-29 Thu>"
5606 (org-timestamp-has-time-p (org-element-context)))))
5608 (ert-deftest test-org
/get-repeat
()
5609 "Test `org-get-repeat' specifications."
5611 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
5614 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
5616 ;; Return proper repeat string.
5619 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
5621 ;; Prevent false positive (commented or verbatim time stamps)
5623 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
5626 (org-test-with-temp-text
5627 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
5629 ;; Return nil when called before first heading.
5631 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
5633 ;; When called with an optional argument, extract repeater from that
5635 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
5636 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
5638 (ert-deftest test-org
/timestamp-format
()
5639 "Test `org-timestamp-format' specifications."
5644 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5645 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5650 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5651 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5653 (ert-deftest test-org
/timestamp-split-range
()
5654 "Test `org-timestamp-split-range' specifications."
5655 ;; Extract range start (active).
5658 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5659 (let ((ts (org-timestamp-split-range (org-element-context))))
5660 (mapcar (lambda (p) (org-element-property p ts
))
5661 '(:year-end
:month-end
:day-end
))))))
5662 ;; Extract range start (inactive)
5665 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5666 (let ((ts (org-timestamp-split-range (org-element-context))))
5667 (mapcar (lambda (p) (org-element-property p ts
))
5668 '(:year-end
:month-end
:day-end
))))))
5669 ;; Extract range end (active).
5672 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5673 (let ((ts (org-timestamp-split-range
5674 (org-element-context) t
)))
5675 (mapcar (lambda (p) (org-element-property p ts
))
5676 '(:year-end
:month-end
:day-end
))))))
5677 ;; Extract range end (inactive)
5680 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5681 (let ((ts (org-timestamp-split-range
5682 (org-element-context) t
)))
5683 (mapcar (lambda (p) (org-element-property p ts
))
5684 '(:year-end
:month-end
:day-end
))))))
5685 ;; Return the timestamp if not a range.
5687 (org-test-with-temp-text "[2012-03-29 Thu]"
5688 (let* ((ts-orig (org-element-context))
5689 (ts-copy (org-timestamp-split-range ts-orig
)))
5690 (eq ts-orig ts-copy
))))
5692 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5693 (let* ((ts-orig (org-element-context))
5694 (ts-copy (org-timestamp-split-range ts-orig
)))
5695 (eq ts-orig ts-copy
)))))
5697 (ert-deftest test-org
/timestamp-translate
()
5698 "Test `org-timestamp-translate' specifications."
5699 ;; Translate whole date range.
5702 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5703 (let ((org-display-custom-times t
)
5704 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5705 (org-timestamp-translate (org-element-context))))))
5706 ;; Translate date range start.
5709 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5710 (let ((org-display-custom-times t
)
5711 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5712 (org-timestamp-translate (org-element-context) 'start
)))))
5713 ;; Translate date range end.
5716 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5717 (let ((org-display-custom-times t
)
5718 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5719 (org-timestamp-translate (org-element-context) 'end
)))))
5720 ;; Translate time range.
5723 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5724 (let ((org-display-custom-times t
)
5725 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5726 (org-timestamp-translate (org-element-context))))))
5727 ;; Translate non-range timestamp.
5730 (org-test-with-temp-text "<2012-03-29 Thu>"
5731 (let ((org-display-custom-times t
)
5732 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5733 (org-timestamp-translate (org-element-context))))))
5734 ;; Do not change `diary' timestamps.
5736 (equal "<%%(org-float t 4 2)>"
5737 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5738 (let ((org-display-custom-times t
)
5739 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5740 (org-timestamp-translate (org-element-context)))))))
5746 (ert-deftest test-org
/flag-drawer
()
5747 "Test `org-flag-drawer' specifications."
5750 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5752 (get-char-property (line-end-position) 'invisible
)))
5755 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5757 (org-flag-drawer nil
)
5758 (get-char-property (line-end-position) 'invisible
)))
5759 ;; Test optional argument.
5761 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5762 (let ((drawer (save-excursion (search-forward ":D2")
5763 (org-element-at-point))))
5764 (org-flag-drawer t drawer
)
5765 (get-char-property (progn (search-forward ":D2") (line-end-position))
5768 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5769 (let ((drawer (save-excursion (search-forward ":D2")
5770 (org-element-at-point))))
5771 (org-flag-drawer t drawer
)
5772 (get-char-property (line-end-position) 'invisible
))))
5773 ;; Do not hide fake drawers.
5775 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5778 (get-char-property (line-end-position) 'invisible
)))
5779 ;; Do not hide incomplete drawers.
5781 (org-test-with-temp-text ":D:\nparagraph"
5784 (get-char-property (line-end-position) 'invisible
)))
5785 ;; Do not hide drawers when called from final blank lines.
5787 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5788 (goto-char (point-max))
5790 (goto-char (point-min))
5791 (get-char-property (line-end-position) 'invisible
)))
5792 ;; Don't leave point in an invisible part of the buffer when hiding
5795 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5796 (goto-char (point-max))
5798 (get-char-property (point) 'invisible
))))
5800 (ert-deftest test-org
/hide-block-toggle
()
5801 "Test `org-hide-block-toggle' specifications."
5802 ;; Error when not at a block.
5804 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5805 (org-hide-block-toggle 'off
)
5806 (get-char-property (line-end-position) 'invisible
)))
5809 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5810 (org-hide-block-toggle)
5811 (get-char-property (line-end-position) 'invisible
)))
5813 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5814 (org-hide-block-toggle)
5815 (get-char-property (line-end-position) 'invisible
)))
5816 ;; Show block unconditionally when optional argument is `off'.
5818 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5819 (org-hide-block-toggle)
5820 (org-hide-block-toggle 'off
)
5821 (get-char-property (line-end-position) 'invisible
)))
5823 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5824 (org-hide-block-toggle 'off
)
5825 (get-char-property (line-end-position) 'invisible
)))
5826 ;; Hide block unconditionally when optional argument is non-nil.
5828 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5829 (org-hide-block-toggle t
)
5830 (get-char-property (line-end-position) 'invisible
)))
5832 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5833 (org-hide-block-toggle)
5834 (org-hide-block-toggle t
)
5835 (get-char-property (line-end-position) 'invisible
)))
5836 ;; Do not hide block when called from final blank lines.
5838 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5839 (org-hide-block-toggle)
5840 (goto-char (point-min))
5841 (get-char-property (line-end-position) 'invisible
)))
5842 ;; Don't leave point in an invisible part of the buffer when hiding
5845 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5846 (org-hide-block-toggle)
5847 (get-char-property (point) 'invisible
))))
5849 (ert-deftest test-org
/hide-block-toggle-maybe
()
5850 "Test `org-hide-block-toggle-maybe' specifications."
5852 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5853 (org-hide-block-toggle-maybe)))
5855 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5857 (ert-deftest test-org
/set-tags
()
5858 "Test `org-set-tags' specifications."
5859 ;; Tags set via fast-tag-selection should be visible afterwards
5861 (let ((org-tag-alist '(("NEXT" . ?n
)))
5862 (org-fast-tag-selection-single-key t
))
5863 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5864 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5865 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5866 ;; Show only headlines
5868 ;; Set NEXT tag on current entry
5869 (org-set-tags nil nil
)
5870 ;; Move point to that NEXT tag
5871 (search-forward "NEXT") (backward-word)
5872 ;; And it should be visible (i.e. no overlays)
5873 (not (overlays-at (point))))))))
5875 (ert-deftest test-org
/show-set-visibility
()
5876 "Test `org-show-set-visibility' specifications."
5877 ;; Do not throw an error before first heading.
5879 (org-test-with-temp-text "Preamble\n* Headline"
5880 (org-show-set-visibility 'tree
)
5882 ;; Test all visibility spans, both on headline and in entry.
5883 (let ((list-visible-lines
5884 (lambda (state headerp
)
5885 (org-test-with-temp-text "* Grandmother (0)
5896 **** The other child (11)
5901 (search-forward (if headerp
"Self" "Match"))
5902 (org-show-set-visibility state
)
5903 (goto-char (point-min))
5904 (let (result (line 0))
5906 (unless (org-invisible-p2) (push line result
))
5909 (nreverse result
))))))
5910 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5911 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5912 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5913 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5914 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5915 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5916 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5917 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5918 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5919 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5920 (funcall list-visible-lines
'tree nil
)))
5921 (should (equal '(0 1 3 4 5 7 12 13)
5922 (funcall list-visible-lines
'canonical t
)))
5923 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5924 (funcall list-visible-lines
'canonical nil
))))
5925 ;; When point is hidden in a drawer or a block, make sure to make it
5928 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5929 (org-hide-block-toggle)
5930 (search-forward "Text")
5931 (org-show-set-visibility 'minimal
)
5932 (org-invisible-p2)))
5934 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5936 (search-forward "Text")
5937 (org-show-set-visibility 'minimal
)
5938 (org-invisible-p2)))
5940 (org-test-with-temp-text
5941 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5944 (org-hide-block-toggle)
5945 (search-forward "Text")
5946 (org-show-set-visibility 'minimal
)
5947 (org-invisible-p2))))
5952 ;;; test-org.el ends here