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 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1338 "Test `org-insert-todo-heading-respect-content' specifications."
1339 ;; Create a TODO heading.
1341 (org-test-with-temp-text "* H1\n Body"
1342 (org-insert-todo-heading-respect-content)
1343 (nth 2 (org-heading-components))))
1344 ;; Add headline at the end of the first subtree
1348 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1349 (org-insert-todo-heading-respect-content)
1350 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1351 ;; In a list, do not create a new item.
1355 (org-test-with-temp-text "* H\n- an item\n- another one"
1356 (search-forward "an ")
1357 (org-insert-todo-heading-respect-content)
1358 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1360 (ert-deftest test-org
/clone-with-time-shift
()
1361 "Test `org-clone-subtree-with-time-shift'."
1362 ;; Raise an error before first heading.
1364 (org-test-with-temp-text ""
1365 (org-clone-subtree-with-time-shift 1)))
1366 ;; Raise an error on invalid number of clones.
1368 (org-test-with-temp-text "* Clone me"
1369 (org-clone-subtree-with-time-shift -
1)))
1370 ;; Clone non-repeating once.
1376 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1377 (org-clone-subtree-with-time-shift 1 "+2d")
1378 (replace-regexp-in-string
1379 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1381 ;; Clone repeating once.
1386 * H1\n<2015-06-25 +1w>
1388 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1389 (org-clone-subtree-with-time-shift 1 "+2d")
1390 (replace-regexp-in-string
1391 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1393 ;; Clone non-repeating zero times.
1398 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1399 (org-clone-subtree-with-time-shift 0 "+2d")
1400 (replace-regexp-in-string
1401 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1403 ;; Clone repeating "zero" times.
1407 * H1\n<2015-06-23 +1w>
1409 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1410 (org-clone-subtree-with-time-shift 0 "+2d")
1411 (replace-regexp-in-string
1412 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1414 ;; Clone with blank SHIFT argument.
1418 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1419 (org-clone-subtree-with-time-shift 1 "")
1420 (buffer-substring-no-properties (line-beginning-position 2)
1421 (line-end-position 2)))))
1422 ;; Find time stamps before point. If SHIFT is not specified, ask
1423 ;; for a time shift.
1427 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1428 (org-clone-subtree-with-time-shift 1 "+1d")
1429 (buffer-substring-no-properties (line-beginning-position 2)
1430 (line-end-position 2)))))
1434 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1435 (cl-letf (((symbol-function 'read-from-minibuffer
)
1436 (lambda (&rest args
) "+1d")))
1437 (org-clone-subtree-with-time-shift 1))
1438 (buffer-substring-no-properties (line-beginning-position 2)
1439 (line-end-position 2))))))
1442 ;;; Fixed-Width Areas
1444 (ert-deftest test-org
/toggle-fixed-width
()
1445 "Test `org-toggle-fixed-width' specifications."
1446 ;; No region: Toggle on fixed-width marker in paragraphs.
1449 (org-test-with-temp-text "A"
1450 (org-toggle-fixed-width)
1452 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1455 (org-test-with-temp-text ": A"
1456 (org-toggle-fixed-width)
1458 ;; No region: Toggle on marker in blank lines after elements or just
1459 ;; after a headline.
1462 (org-test-with-temp-text "* H\n"
1464 (org-toggle-fixed-width)
1467 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1468 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1469 (goto-char (point-max))
1470 (org-toggle-fixed-width)
1472 ;; No region: Toggle on marker in front of one line elements (e.g.,
1473 ;; headlines, clocks)
1475 (equal ": * Headline"
1476 (org-test-with-temp-text "* Headline"
1477 (org-toggle-fixed-width)
1480 (equal ": #+KEYWORD: value"
1481 (org-test-with-temp-text "#+KEYWORD: value"
1482 (org-toggle-fixed-width)
1484 ;; No region: error in other situations.
1486 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1488 (org-toggle-fixed-width)
1490 ;; No region: Indentation is preserved.
1493 (org-test-with-temp-text "- A\n B"
1495 (org-toggle-fixed-width)
1497 ;; Region: If it contains only fixed-width elements and blank lines,
1498 ;; toggle off fixed-width markup.
1501 (org-test-with-temp-text ": A\n\n: B"
1502 (transient-mark-mode 1)
1503 (push-mark (point) t t
)
1504 (goto-char (point-max))
1505 (org-toggle-fixed-width)
1507 ;; Region: If it contains anything else, toggle on fixed-width but
1508 ;; not on fixed-width areas.
1510 (equal ": A\n: \n: B\n: \n: C"
1511 (org-test-with-temp-text "A\n\n: B\n\nC"
1512 (transient-mark-mode 1)
1513 (push-mark (point) t t
)
1514 (goto-char (point-max))
1515 (org-toggle-fixed-width)
1517 ;; Region: Ignore blank lines at its end, unless it contains only
1521 (org-test-with-temp-text "A\n\n"
1522 (transient-mark-mode 1)
1523 (push-mark (point) t t
)
1524 (goto-char (point-max))
1525 (org-toggle-fixed-width)
1529 (org-test-with-temp-text "\n\n"
1530 (transient-mark-mode 1)
1531 (push-mark (point) t t
)
1532 (goto-char (point-max))
1533 (org-toggle-fixed-width)
1540 (ert-deftest test-org
/get-heading
()
1541 "Test `org-get-heading' specifications."
1542 ;; Return current heading, even if point is not on it.
1545 (org-test-with-temp-text "* H"
1546 (org-get-heading))))
1549 (org-test-with-temp-text "* H\nText<point>"
1550 (org-get-heading))))
1551 ;; Without any optional argument, return TODO keyword, priority
1552 ;; cookie, COMMENT keyword and tags.
1555 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1556 (org-get-heading))))
1559 (org-test-with-temp-text "* [#A] H"
1560 (org-get-heading))))
1563 (org-test-with-temp-text "* COMMENT H"
1564 (org-get-heading))))
1567 (org-test-with-temp-text "* H :tag:"
1568 (org-get-heading))))
1569 ;; With NO-TAGS argument, ignore tags.
1572 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1573 (org-get-heading t
))))
1576 (org-test-with-temp-text "* H :tag:"
1577 (org-get-heading t
))))
1578 ;; With NO-TODO, ignore TODO keyword.
1581 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1582 (org-get-heading nil t
))))
1585 (org-test-with-temp-text "* H :tag:"
1586 (org-get-heading nil t
))))
1587 ;; TODO keywords are case-sensitive.
1590 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1591 (org-get-heading nil t
))))
1592 ;; With NO-PRIORITY, ignore priority.
1595 (org-test-with-temp-text "* [#A] H"
1596 (org-get-heading nil nil t
))))
1599 (org-test-with-temp-text "* H"
1600 (org-get-heading nil nil t
))))
1603 (org-test-with-temp-text "* TODO [#A] H"
1604 (org-get-heading nil nil t
))))
1605 ;; With NO-COMMENT, ignore COMMENT keyword.
1608 (org-test-with-temp-text "* COMMENT H"
1609 (org-get-heading nil nil nil t
))))
1612 (org-test-with-temp-text "* H"
1613 (org-get-heading nil nil nil t
))))
1615 (equal "TODO [#A] H"
1616 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1617 (org-get-heading nil nil nil t
))))
1618 ;; On an empty headline, return value is consistent.
1619 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1620 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1621 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1622 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1624 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1626 (ert-deftest test-org
/in-commented-heading-p
()
1627 "Test `org-in-commented-heading-p' specifications."
1628 ;; Commented headline.
1630 (org-test-with-temp-text "* COMMENT Headline\nBody"
1631 (goto-char (point-max))
1632 (org-in-commented-heading-p)))
1633 ;; Commented ancestor.
1635 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1636 (goto-char (point-max))
1637 (org-in-commented-heading-p)))
1638 ;; Comment keyword is case-sensitive.
1640 (org-test-with-temp-text "* Comment Headline\nBody"
1641 (goto-char (point-max))
1642 (org-in-commented-heading-p)))
1643 ;; Keyword is standalone.
1645 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1646 (goto-char (point-max))
1647 (org-in-commented-heading-p)))
1648 ;; Optional argument.
1650 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1651 (goto-char (point-max))
1652 (org-in-commented-heading-p t
))))
1654 (ert-deftest test-org
/entry-blocked-p
()
1655 ;; Check other dependencies.
1657 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1658 (let ((org-enforce-todo-dependencies t
)
1660 '(org-block-todo-from-children-or-siblings-or-parent)))
1661 (org-entry-blocked-p))))
1663 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1664 (let ((org-enforce-todo-dependencies t
)
1666 '(org-block-todo-from-children-or-siblings-or-parent)))
1667 (org-entry-blocked-p))))
1668 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1671 (org-test-with-temp-text "* Blocked\n** TODO one"
1672 (let ((org-enforce-todo-dependencies t
)
1674 '(org-block-todo-from-children-or-siblings-or-parent)))
1675 (org-entry-blocked-p))))
1677 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1678 (let ((org-enforce-todo-dependencies t
)
1680 '(org-block-todo-from-children-or-siblings-or-parent)))
1681 (org-entry-blocked-p))))
1682 ;; Follow :ORDERED: specifications.
1684 (org-test-with-temp-text
1685 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1686 (let ((org-enforce-todo-dependencies t
)
1688 '(org-block-todo-from-children-or-siblings-or-parent)))
1689 (org-entry-blocked-p))))
1691 (org-test-with-temp-text
1692 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1693 (let ((org-enforce-todo-dependencies t
)
1695 '(org-block-todo-from-children-or-siblings-or-parent)))
1696 (org-entry-blocked-p)))))
1698 (ert-deftest test-org
/get-outline-path
()
1699 "Test `org-get-outline-path' specifications."
1700 ;; Top-level headlines have no outline path.
1702 (org-test-with-temp-text "* H"
1703 (org-get-outline-path)))
1704 ;; Otherwise, outline path is the path leading to the headline.
1707 (org-test-with-temp-text "* H\n** S<point>"
1708 (org-get-outline-path))))
1709 ;; Find path even when point is not on a headline.
1712 (org-test-with-temp-text "* H\n** S\nText<point>"
1713 (org-get-outline-path))))
1714 ;; TODO keywords, tags and statistics cookies are ignored.
1717 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1718 (org-get-outline-path))))
1719 ;; Links are replaced with their description or their path.
1722 (org-test-with-temp-text
1723 "* [[http://orgmode.org][Org]]\n** S<point>"
1724 (org-get-outline-path))))
1726 (equal '("http://orgmode.org")
1727 (org-test-with-temp-text
1728 "* [[http://orgmode.org]]\n** S<point>"
1729 (org-get-outline-path))))
1730 ;; When WITH-SELF is non-nil, include current heading.
1733 (org-test-with-temp-text "* H"
1734 (org-get-outline-path t
))))
1737 (org-test-with-temp-text "* H\n** S\nText<point>"
1738 (org-get-outline-path t
))))
1739 ;; Using cache is transparent to the user.
1742 (org-test-with-temp-text "* H\n** S<point>"
1743 (setq org-outline-path-cache nil
)
1744 (org-get-outline-path nil t
))))
1745 ;; Do not corrupt cache when finding outline path in distant part of
1749 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1750 (setq org-outline-path-cache nil
)
1751 (org-get-outline-path nil t
)
1752 (search-forward "S2")
1753 (org-get-outline-path nil t
))))
1754 ;; Do not choke on empty headlines.
1756 (org-test-with-temp-text "* H\n** <point>"
1757 (org-get-outline-path)))
1759 (org-test-with-temp-text "* \n** H<point>"
1760 (org-get-outline-path))))
1762 (ert-deftest test-org
/format-outline-path
()
1763 "Test `org-format-outline-path' specifications."
1765 (string= (org-format-outline-path (list "one" "two" "three"))
1769 (string= (org-format-outline-path '())
1772 (string= (org-format-outline-path '(nil))
1774 ;; Empty path and prefix.
1776 (string= (org-format-outline-path '() nil
">>")
1778 ;; Trailing whitespace in headings.
1780 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1782 ;; Non-default prefix and separators.
1784 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1785 ">>|one|two|three"))
1788 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1790 ;; Give a very narrow width.
1792 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1794 ;; Give a prefix that extends beyond the width.
1796 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1800 (ert-deftest test-org
/map-entries
()
1801 "Test `org-map-entries' specifications."
1805 (org-test-with-temp-text "* Level 1\n** Level 2"
1806 (org-map-entries #'point
))))
1810 (org-test-with-temp-text "* Level 1\n** Level 2"
1811 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1814 (org-test-with-temp-text "* Level 1\n** Level 2"
1815 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1819 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1820 (org-map-entries #'point
"yes"))))
1823 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1824 (org-map-entries #'point
"+yes-a"))))
1827 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1828 (org-map-entries #'point
"{yes?}"))))
1832 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1833 (org-map-entries #'point
"PRIORITY=\"A\""))))
1837 (org-test-with-temp-text "
1839 SCHEDULED: <2012-03-29 thu.>
1841 SCHEDULED: <2014-03-04 tue.>"
1842 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1845 (org-test-with-temp-text "
1847 SCHEDULED: <2012-03-29 thu.>
1849 SCHEDULED: <2014-03-04 tue.>"
1850 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1851 ;; Regular property match.
1854 (org-test-with-temp-text "
1863 (org-map-entries #'point
"TEST=1"))))
1864 ;; Multiple criteria.
1867 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1868 (let (org-odd-levels-only
1869 (org-use-tag-inheritance nil
))
1870 (org-map-entries #'point
"yes+LEVEL=1")))))
1874 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1875 (let (org-odd-levels-only)
1876 (org-map-entries #'point
"LEVEL=2|no")))))
1879 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1880 (let (org-odd-levels-only)
1881 (org-map-entries #'point
"yes|no")))))
1885 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1886 (let (org-odd-levels-only)
1887 (org-map-entries #'point
"yes&no"))))))
1889 (ert-deftest test-org
/edit-headline
()
1890 "Test `org-edit-headline' specifications."
1893 (org-test-with-temp-text "* A"
1894 (org-edit-headline "B")
1896 ;; Handle empty headings.
1899 (org-test-with-temp-text "* A"
1900 (org-edit-headline "")
1904 (org-test-with-temp-text "* "
1905 (org-edit-headline "A")
1907 ;; Handle TODO keywords and priority cookies.
1910 (org-test-with-temp-text "* TODO A"
1911 (org-edit-headline "B")
1915 (org-test-with-temp-text "* [#A] A"
1916 (org-edit-headline "B")
1919 (equal "* TODO [#A] B"
1920 (org-test-with-temp-text "* TODO [#A] A"
1921 (org-edit-headline "B")
1925 (org-test-with-temp-text "* A :tag:"
1926 (let ((org-tags-column 4)) (org-edit-headline "B"))
1933 (ert-deftest test-org
/set-regexps-and-options
()
1934 "Test `org-set-regexps-and-options' specifications."
1938 (let ((org-tag-alist '(("A")))
1939 (org-tag-persistent-alist nil
))
1940 (org-test-with-temp-text ""
1942 org-current-tag-alist
))))
1945 (let ((org-tag-alist '(("A")))
1946 (org-tag-persistent-alist nil
))
1947 (org-test-with-temp-text "#+TAGS: B"
1949 org-current-tag-alist
))))
1951 (equal '(("C") ("B"))
1952 (let ((org-tag-alist '(("A")))
1953 (org-tag-persistent-alist '(("C"))))
1954 (org-test-with-temp-text "#+TAGS: B"
1956 org-current-tag-alist
))))
1959 (let ((org-tag-alist '(("A")))
1960 (org-tag-persistent-alist '(("C"))))
1961 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1963 org-current-tag-alist
))))
1965 (equal '(("A" . ?a
) ("B") ("C"))
1966 (let ((org-tag-persistant-alist nil
))
1967 (org-test-with-temp-text "#+TAGS: A(a) B C"
1969 org-current-tag-alist
))))
1971 (equal '(("A") (:newline
) ("B"))
1972 (let ((org-tag-persistent-alist nil
))
1973 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1975 org-current-tag-alist
))))
1977 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1978 (let ((org-tag-persistent-alist nil
))
1979 (org-test-with-temp-text "#+TAGS: { A B } C"
1981 org-current-tag-alist
))))
1983 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1984 (let ((org-tag-persistent-alist nil
))
1985 (org-test-with-temp-text "#+TAGS: { A : B C }"
1987 org-current-tag-alist
))))
1989 (equal '(("A" "B" "C"))
1990 (let ((org-tag-persistent-alist nil
))
1991 (org-test-with-temp-text "#+TAGS: { A : B C }"
1993 org-tag-groups-alist
))))
1995 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1996 (let ((org-tag-persistent-alist nil
))
1997 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1999 org-current-tag-alist
))))
2001 (equal '(("A" "B" "C"))
2002 (let ((org-tag-persistent-alist nil
))
2003 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2005 org-tag-groups-alist
))))
2006 ;; FILETAGS keyword.
2008 (equal '("A" "B" "C")
2009 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2012 ;; PROPERTY keyword. Property names are case-insensitive.
2015 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2017 (cdr (assoc "var" org-file-properties
)))))
2021 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2023 (cdr (assoc "var" org-file-properties
)))))
2027 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2029 (cdr (assoc "var" org-file-properties
)))))
2033 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2035 org-archive-location
)))
2036 ;; CATEGORY keyword.
2039 (org-test-with-temp-text "#+CATEGORY: test"
2044 (org-test-with-temp-text "#+CATEGORY: test"
2046 (cdr (assoc "CATEGORY" org-file-properties
)))))
2049 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2050 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2052 org-columns-default-format
)))
2053 ;; CONSTANTS keyword. Constants names are case sensitive.
2055 (equal '("299792458." "3.14")
2056 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2059 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2063 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2065 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2068 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2070 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2075 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2077 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2079 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2083 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2085 (list org-highest-priority org-lowest-priority org-default-priority
))))
2089 (org-test-with-temp-text "#+PRIORITIES: X Z"
2091 (list org-highest-priority org-lowest-priority org-default-priority
))))
2095 (org-test-with-temp-text "#+STARTUP: fold odd"
2097 (list org-startup-folded org-odd-levels-only
))))
2100 (equal '(("A" "B") ("C"))
2101 (org-test-with-temp-text "#+TODO: A B | C"
2103 (list org-not-done-keywords org-done-keywords
))))
2105 (equal '(("A" "C") ("B" "D"))
2106 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2108 (list org-not-done-keywords org-done-keywords
))))
2110 (equal '(("A" "B") ("C"))
2111 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2113 (list org-not-done-keywords org-done-keywords
))))
2115 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2116 (org-test-with-temp-text "#+TODO: A(a)"
2118 org-todo-key-alist
)))
2120 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2121 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2123 org-todo-log-states
)))
2124 ;; Enter SETUPFILE keyword.
2127 (org-test-with-temp-text
2128 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2130 (cdr (assoc "a" org-file-properties
))))))
2138 (ert-deftest test-org
/coderef
()
2139 "Test coderef links specifications."
2141 (org-test-with-temp-text "
2142 #+BEGIN_SRC emacs-lisp
2147 (looking-at "(ref:sc)")))
2148 ;; Find coderef even with alternate label format.
2150 (org-test-with-temp-text "
2151 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2156 (looking-at "{ref:sc}"))))
2160 (ert-deftest test-org
/custom-id
()
2161 "Test custom ID links specifications."
2163 (org-test-with-temp-text
2164 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2166 (looking-at-p "\\* H1")))
2167 ;; Throw an error on false positives.
2169 (org-test-with-temp-text
2170 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2172 (looking-at-p "\\* H1"))))
2176 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2177 ;; a named element (#+name: text) and to headlines (* Text).
2179 (ert-deftest test-org
/fuzzy-links
()
2180 "Test fuzzy links specifications."
2181 ;; Fuzzy link goes in priority to a matching target.
2183 (org-test-with-temp-text
2184 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2185 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2186 (looking-at "<<Test>>")))
2187 ;; Then fuzzy link points to an element with a given name.
2189 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2190 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2191 (looking-at "#\\+NAME: Test")))
2192 ;; A target still lead to a matching headline otherwise.
2194 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2195 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2196 (looking-at "\\* Head2")))
2197 ;; With a leading star in link, enforce heading match.
2199 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2200 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2201 (looking-at "\\* Test")))
2202 ;; With a leading star in link, enforce exact heading match, even
2203 ;; with `org-link-search-must-match-exact-headline' set to nil.
2205 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2206 (let ((org-link-search-must-match-exact-headline nil
))
2207 (org-open-at-point))))
2208 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2210 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2211 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2212 (looking-at "\\* Test")))
2214 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2215 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2216 (looking-at "\\* Test")))
2217 ;; Heading match should not care about spaces, cookies, TODO
2218 ;; keywords, priorities, and tags. However, TODO keywords are
2222 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2223 (org-test-with-temp-text
2224 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2225 (let ((org-link-search-must-match-exact-headline nil
)
2226 (org-todo-regexp "TODO"))
2227 (org-open-at-point))
2228 (looking-at (regexp-quote first-line
)))))
2230 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2231 (let ((org-link-search-must-match-exact-headline nil
)
2232 (org-todo-regexp "TODO"))
2233 (org-open-at-point))))
2234 ;; Heading match should still be exact.
2236 (org-test-with-temp-text "
2237 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2240 (let ((org-link-search-must-match-exact-headline nil
)
2241 (org-todo-regexp "TODO"))
2242 (org-open-at-point))))
2244 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2245 (let ((org-link-search-must-match-exact-headline nil
)
2246 (org-todo-regexp "TODO"))
2247 (org-open-at-point))
2248 (looking-at-p (regexp-quote "** Test 1 2"))))
2249 ;; Heading match ignores COMMENT keyword.
2251 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2253 (looking-at "\\* COMMENT Test")))
2255 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2257 (looking-at "\\* TODO COMMENT Test")))
2258 ;; Correctly un-hexify fuzzy links.
2260 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2264 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2270 (ert-deftest test-org
/org-link-escape-ascii-character
()
2271 "Escape an ascii character."
2275 (org-link-escape "["))))
2277 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2278 "Escape an ascii control character."
2282 (org-link-escape "\t"))))
2284 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2285 "Escape an unicode multibyte character."
2289 (org-link-escape "€"))))
2291 (ert-deftest test-org
/org-link-escape-custom-table
()
2292 "Escape string with custom character table."
2296 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2298 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2299 "Escape string with custom table merged with default table."
2302 "%5BF%6F%6F%3A%42ar%0A%5D"
2303 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2305 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2306 "Unescape an ascii character."
2310 (org-link-unescape "%5B"))))
2312 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2313 "Unescpae an ascii control character."
2317 (org-link-unescape "%0A"))))
2319 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2320 "Unescape unicode multibyte character."
2324 (org-link-unescape "%E2%82%AC"))))
2326 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2327 "Unescape old style percent escaped character."
2330 "à âçèéêîôùû"
2331 (decode-coding-string
2332 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2334 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2335 "Escape and unescape a URL that includes an escaped char.
2336 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2339 "http://some.host.com/form?&id=blah%2Bblah25"
2341 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2345 (ert-deftest test-org
/open-at-point-in-keyword
()
2346 "Does `org-open-at-point' open link in a keyword line?"
2348 (org-test-with-temp-text
2349 "<<top>>\n#+KEYWORD: <point>[[top]]"
2350 (org-open-at-point) t
)))
2352 (ert-deftest test-org
/open-at-point-in-property
()
2353 "Does `org-open-at-point' open link in property drawer?"
2355 (org-test-with-temp-text
2358 :URL: <point>[[*Headline]]
2360 (org-open-at-point) t
)))
2362 (ert-deftest test-org
/open-at-point-in-comment
()
2363 "Does `org-open-at-point' open link in a commented line?"
2365 (org-test-with-temp-text
2366 "<<top>>\n# <point>[[top]]"
2367 (org-open-at-point) t
)))
2369 (ert-deftest test-org
/open-at-point
/inline-image
()
2370 "Test `org-open-at-point' on nested links."
2372 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2376 (ert-deftest test-org
/open-at-point
/radio-target
()
2377 "Test `org-open-at-point' on radio targets."
2379 (org-test-with-temp-text "<<<target>>> <point>target"
2380 (org-update-radio-target-regexp)
2382 (eq (org-element-type (org-element-context)) 'radio-target
))))
2386 (ert-deftest test-org
/store-link
()
2387 "Test `org-store-link' specifications."
2388 ;; On a headline, link to that headline. Use heading as the
2389 ;; description of the link.
2391 (let (org-store-link-props org-stored-links
)
2392 (org-test-with-temp-text-in-file "* H1"
2393 (let ((file (buffer-file-name)))
2394 (equal (format "[[file:%s::*H1][H1]]" file
)
2395 (org-store-link nil
))))))
2396 ;; On a headline, remove any link from description.
2398 (let (org-store-link-props org-stored-links
)
2399 (org-test-with-temp-text-in-file "* [[#l][d]]"
2400 (let ((file (buffer-file-name)))
2401 (equal (format "[[file:%s::*%s][d]]"
2403 (org-link-escape "[[#l][d]]"))
2404 (org-store-link nil
))))))
2406 (let (org-store-link-props org-stored-links
)
2407 (org-test-with-temp-text-in-file "* [[l]]"
2408 (let ((file (buffer-file-name)))
2409 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2410 (org-store-link nil
))))))
2412 (let (org-store-link-props org-stored-links
)
2413 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2414 (let ((file (buffer-file-name)))
2415 (equal (format "[[file:%s::*%s][d1 d2]]"
2417 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2418 (org-store-link nil
))))))
2419 ;; On a named element, link to that element.
2421 (let (org-store-link-props org-stored-links
)
2422 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2423 (let ((file (buffer-file-name)))
2424 (equal (format "[[file:%s::foo][foo]]" file
)
2425 (org-store-link nil
)))))))
2430 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2431 "Ensure properties accumulate in subtree drawers."
2432 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2433 (org-babel-next-src-block)
2434 (should (equal '(2 1) (org-babel-execute-src-block)))))
2436 (ert-deftest test-org
/custom-properties
()
2437 "Test custom properties specifications."
2440 (let ((org-custom-properties '("FOO")))
2441 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2442 (org-toggle-custom-properties-visibility)
2443 (org-invisible-p2))))
2444 ;; Properties are case-insensitive.
2446 (let ((org-custom-properties '("FOO")))
2447 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2448 (org-toggle-custom-properties-visibility)
2449 (org-invisible-p2))))
2451 (let ((org-custom-properties '("foo")))
2452 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2453 (org-toggle-custom-properties-visibility)
2454 (org-invisible-p2))))
2455 ;; Multiple custom properties in the same drawer.
2457 (let ((org-custom-properties '("FOO" "BAR")))
2458 (org-test-with-temp-text
2459 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2460 (org-toggle-custom-properties-visibility)
2461 (and (org-invisible-p2)
2462 (not (progn (forward-line) (org-invisible-p2)))
2463 (progn (forward-line) (org-invisible-p2))))))
2464 ;; Hide custom properties with an empty value.
2466 (let ((org-custom-properties '("FOO")))
2467 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2468 (org-toggle-custom-properties-visibility)
2469 (org-invisible-p2))))
2470 ;; Do not hide fake properties.
2472 (let ((org-custom-properties '("FOO")))
2473 (org-test-with-temp-text ":FOO: val\n"
2474 (org-toggle-custom-properties-visibility)
2475 (org-invisible-p2))))
2477 (let ((org-custom-properties '("A")))
2478 (org-test-with-temp-text
2479 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2480 (org-toggle-custom-properties-visibility)
2481 (org-invisible-p2)))))
2487 (ert-deftest test-org
/mark-subtree
()
2488 "Test `org-mark-subtree' specifications."
2489 ;; Error when point is before first headline.
2491 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2492 (progn (transient-mark-mode 1)
2493 (org-mark-subtree))))
2494 ;; Without argument, mark current subtree.
2498 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2499 (progn (transient-mark-mode 1)
2502 (list (region-beginning) (region-end))))))
2503 ;; With an argument, move ARG up.
2507 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2508 (progn (transient-mark-mode 1)
2510 (org-mark-subtree 1)
2511 (list (region-beginning) (region-end))))))
2512 ;; Do not get fooled by inlinetasks.
2513 (when (featurep 'org-inlinetask
)
2516 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2517 (progn (transient-mark-mode 1)
2519 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2520 (region-beginning)))))))
2526 (ert-deftest test-org
/in-regexp
()
2527 "Test `org-in-regexp' specifications."
2530 (org-test-with-temp-text "xx ab<point>c xx"
2531 (org-in-regexp "abc")))
2533 (org-test-with-temp-text "xx abc <point>xx"
2534 (org-in-regexp "abc")))
2535 ;; Return non-nil even with multiple matching regexps in the same
2538 (org-test-with-temp-text "abc xx ab<point>c xx"
2539 (org-in-regexp "abc")))
2540 ;; With optional argument NLINES, check extra lines around point.
2542 (org-test-with-temp-text "A\nB<point>\nC"
2543 (org-in-regexp "A\nB\nC")))
2545 (org-test-with-temp-text "A\nB<point>\nC"
2546 (org-in-regexp "A\nB\nC" 1)))
2548 (org-test-with-temp-text "A\nB\nC<point>"
2549 (org-in-regexp "A\nB\nC" 1)))
2550 ;; When optional argument VISUALLY is non-nil, return nil if at
2551 ;; regexp boundaries.
2553 (org-test-with-temp-text "xx abc<point> xx"
2554 (org-in-regexp "abc")))
2556 (org-test-with-temp-text "xx abc<point> xx"
2557 (org-in-regexp "abc" nil t
))))
2562 (ert-deftest test-org
/end-of-meta-data
()
2563 "Test `org-end-of-meta-data' specifications."
2564 ;; Skip planning line.
2566 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2567 (org-end-of-meta-data)
2569 ;; Skip properties drawer.
2571 (org-test-with-temp-text
2572 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2573 (org-end-of-meta-data)
2577 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2578 (org-end-of-meta-data)
2580 ;; Nothing to skip, go to first line.
2582 (org-test-with-temp-text "* Headline\nContents"
2583 (org-end-of-meta-data)
2584 (looking-at "Contents")))
2585 ;; With option argument, skip empty lines, regular drawers and
2588 (org-test-with-temp-text "* Headline\n\nContents"
2589 (org-end-of-meta-data t
)
2590 (looking-at "Contents")))
2592 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2593 (org-end-of-meta-data t
)
2594 (looking-at "Contents")))
2596 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2597 (org-end-of-meta-data t
)
2598 (looking-at "Contents")))
2599 ;; Special case: do not skip incomplete drawers.
2601 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2602 (org-end-of-meta-data t
)
2603 (looking-at ":LOGBOOK:")))
2604 ;; Special case: Be careful about consecutive headlines.
2606 (org-test-with-temp-text "* H1\n*H2\nContents"
2607 (org-end-of-meta-data t
)
2608 (looking-at "Contents"))))
2610 (ert-deftest test-org
/beginning-of-line
()
2611 "Test `org-beginning-of-line' specifications."
2612 ;; Move to beginning of line. If current line in invisible, move to
2613 ;; beginning of visible line instead.
2615 (org-test-with-temp-text "Some text\nSome other text<point>"
2616 (org-beginning-of-line)
2619 (org-test-with-temp-text "* H1\n** H2<point>"
2621 (org-beginning-of-line)
2622 (= (line-beginning-position) 1)))
2623 ;; With `visual-line-mode' active, move to beginning of visual line.
2625 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2627 (dotimes (i 1000) (insert "very "))
2628 (org-beginning-of-line)
2630 ;; In a wide headline, with `visual-line-mode', prefer going to the
2631 ;; beginning of a visual line than to the logical beginning of line,
2632 ;; even if special movement is active.
2634 (org-test-with-temp-text "* A <point>long headline"
2636 (dotimes (i 1000) (insert "very "))
2637 (goto-char (point-max))
2638 (org-beginning-of-line)
2641 (org-test-with-temp-text "* A <point>long headline"
2643 (dotimes (i 1000) (insert "very "))
2644 (goto-char (point-max))
2645 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2647 ;; At an headline with special movement, first move at beginning of
2648 ;; title, then at the beginning of line, rinse, repeat.
2650 (org-test-with-temp-text "* TODO Headline<point>"
2651 (let ((org-special-ctrl-a/e t
))
2652 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2653 (progn (org-beginning-of-line) (bolp))
2654 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2656 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2657 (let ((org-special-ctrl-a/e t
))
2658 (org-beginning-of-line)
2659 (looking-at "Headline"))))
2661 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2662 (let ((org-special-ctrl-a/e
'(t . nil
)))
2663 (org-beginning-of-line)
2664 (looking-at "Headline"))))
2666 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2667 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2668 (org-beginning-of-line)
2669 (looking-at "Headline"))))
2670 ;; At an headline with reversed movement, first move to beginning of
2671 ;; line, then to the beginning of title.
2673 (org-test-with-temp-text "* TODO Headline<point>"
2674 (let ((org-special-ctrl-a/e
'reversed
)
2675 (this-command last-command
))
2676 (and (progn (org-beginning-of-line) (bolp))
2677 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2679 (org-test-with-temp-text "* TODO Headline<point>"
2680 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2681 (this-command last-command
))
2682 (and (progn (org-beginning-of-line) (bolp))
2683 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2685 (org-test-with-temp-text "* TODO Headline<point>"
2686 (let ((org-special-ctrl-a/e
'(t . nil
))
2687 (this-command last-command
))
2688 (and (progn (org-beginning-of-line) (bolp))
2689 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2690 ;; At an item with special movement, first move after to beginning
2691 ;; of title, then to the beginning of line, rinse, repeat.
2693 (org-test-with-temp-text "- [ ] Item<point>"
2694 (let ((org-special-ctrl-a/e t
))
2695 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2696 (progn (org-beginning-of-line) (bolp))
2697 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2698 ;; At an item with reversed movement, first move to beginning of
2699 ;; line, then to the beginning of title.
2701 (org-test-with-temp-text "- [X] Item<point>"
2702 (let ((org-special-ctrl-a/e
'reversed
)
2703 (this-command last-command
))
2704 (and (progn (org-beginning-of-line) (bolp))
2705 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2706 ;; Leave point before invisible characters at column 0.
2708 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2709 (let ((org-special-ctrl-a/e nil
))
2710 (org-beginning-of-line)
2713 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2714 (let ((org-special-ctrl-a/e t
))
2715 (org-beginning-of-line)
2718 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2720 (org-beginning-of-line)
2722 ;; Special case: Do not error when the buffer contains only a single
2725 (org-test-with-temp-text "*<point>"
2726 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2728 (org-test-with-temp-text "*<point>"
2729 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2731 (ert-deftest test-org
/end-of-line
()
2732 "Test `org-end-of-line' specifications."
2735 (org-test-with-temp-text "Some text\nSome other text"
2738 ;; With `visual-line-mode' active, move to end of visible line.
2739 ;; However, never go past ellipsis.
2741 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2743 (dotimes (i 1000) (insert "very "))
2744 (goto-char (point-min))
2748 (org-test-with-temp-text "* A short headline\nSome contents"
2753 ;; In a wide headline, with `visual-line-mode', prefer going to end
2754 ;; of visible line if tags, or end of line, are farther.
2756 (org-test-with-temp-text "* A <point>long headline"
2758 (dotimes (i 1000) (insert "very "))
2759 (goto-char (point-min))
2763 (org-test-with-temp-text "* A <point>long headline :tag:"
2765 (dotimes (i 1000) (insert "very "))
2766 (goto-char (point-min))
2769 ;; At an headline without special movement, go to end of line.
2770 ;; However, never go past ellipsis.
2772 (org-test-with-temp-text "* Headline2b :tag:\n"
2773 (let ((org-special-ctrl-a/e nil
))
2774 (and (progn (org-end-of-line) (eolp))
2775 (progn (org-end-of-line) (eolp))))))
2777 (org-test-with-temp-text "* Headline2b :tag:\n"
2778 (let ((org-special-ctrl-a/e
'(t . nil
)))
2779 (and (progn (org-end-of-line) (eolp))
2780 (progn (org-end-of-line) (eolp))))))
2782 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2784 (let ((org-special-ctrl-a/e nil
))
2786 (= 1 (line-beginning-position)))))
2787 ;; At an headline with special movement, first move before tags,
2788 ;; then at the end of line, rinse, repeat. However, never go past
2791 (org-test-with-temp-text "* Headline1 :tag:\n"
2792 (let ((org-special-ctrl-a/e t
))
2793 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2794 (progn (org-end-of-line) (eolp))
2795 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2797 (org-test-with-temp-text "* Headline1 :tag:\n"
2798 (let ((org-special-ctrl-a/e
'(nil . t
)))
2799 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2800 (progn (org-end-of-line) (eolp))
2801 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2803 (org-test-with-temp-text "* Headline1 :tag:\n"
2804 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2805 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2806 (progn (org-end-of-line) (eolp))
2807 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2809 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2811 (let ((org-special-ctrl-a/e t
))
2814 (= 1 (line-beginning-position)))))
2815 ;; At an headline, with reversed movement, first go to end of line,
2816 ;; then before tags. However, never go past ellipsis.
2818 (org-test-with-temp-text "* Headline3 :tag:\n"
2819 (let ((org-special-ctrl-a/e
'reversed
)
2820 (this-command last-command
))
2821 (and (progn (org-end-of-line) (eolp))
2822 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2824 (org-test-with-temp-text "* Headline3 :tag:\n"
2825 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2826 (this-command last-command
))
2827 (and (progn (org-end-of-line) (eolp))
2828 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2830 (org-test-with-temp-text "* Headline3 :tag:\n"
2831 (let ((org-special-ctrl-a/e
'(nil . t
))
2832 (this-command last-command
))
2833 (and (progn (org-end-of-line) (eolp))
2834 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2836 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2838 (let ((org-special-ctrl-a/e
'reversed
))
2840 (= 1 (line-beginning-position)))))
2841 ;; At a block without hidden contents.
2843 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2844 (progn (org-end-of-line) (eolp))))
2845 ;; At a block with hidden contents.
2847 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2848 (let ((org-special-ctrl-a/e t
))
2849 (org-hide-block-toggle)
2852 ;; Get past invisible characters at the end of line.
2854 (org-test-with-temp-text "[[http://orgmode.org]]"
2858 (ert-deftest test-org
/open-line
()
2859 "Test `org-open-line' specifications."
2860 ;; Call `open-line' outside of tables.
2863 (org-test-with-temp-text "Text"
2866 ;; At a table, create a row above.
2868 (equal "\n| |\n| a |"
2869 (org-test-with-temp-text "\n<point>| a |"
2872 ;; At the very first character of the buffer, also call `open-line'.
2875 (org-test-with-temp-text "| a |"
2878 ;; Narrowing does not count.
2880 (equal "Text\n| |\n| a |"
2881 (org-test-with-temp-text "Text\n<point>| a |"
2882 (narrow-to-region (point) (point-max))
2887 (ert-deftest test-org
/forward-sentence
()
2888 "Test `org-forward-sentence' specifications."
2889 ;; At the end of a table cell, move to the end of the next one.
2891 (org-test-with-temp-text "| a<point> | b |"
2892 (org-forward-sentence)
2893 (looking-at " |$")))
2894 ;; Elsewhere in a cell, move to its end.
2896 (org-test-with-temp-text "| a<point>c | b |"
2897 (org-forward-sentence)
2898 (looking-at " | b |$")))
2899 ;; Otherwise, simply call `forward-sentence'.
2901 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2902 (org-forward-sentence)
2903 (looking-at " Sentence 2.")))
2905 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2906 (org-forward-sentence)
2907 (org-forward-sentence)
2909 ;; At the end of an element, jump to the next one, without stopping
2910 ;; on blank lines in-between.
2912 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2913 (org-forward-sentence)
2916 (ert-deftest test-org
/backward-sentence
()
2917 "Test `org-backward-sentence' specifications."
2918 ;; At the beginning of a table cell, move to the beginning of the
2921 (org-test-with-temp-text "| a | <point>b |"
2922 (org-backward-sentence)
2923 (looking-at "a | b |$")))
2924 ;; Elsewhere in a cell, move to its beginning.
2926 (org-test-with-temp-text "| a | b<point>c |"
2927 (org-backward-sentence)
2928 (looking-at "bc |$")))
2929 ;; Otherwise, simply call `backward-sentence'.
2931 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2932 (org-backward-sentence)
2933 (looking-at "Sentence 2.")))
2935 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2936 (org-backward-sentence)
2937 (org-backward-sentence)
2939 ;; Make sure to hit the beginning of a sentence on the same line as
2942 (org-test-with-temp-text "- Line 1\n line <point>2."
2943 (org-backward-sentence)
2944 (looking-at "Line 1"))))
2946 (ert-deftest test-org
/forward-paragraph
()
2947 "Test `org-forward-paragraph' specifications."
2948 ;; At end of buffer, return an error.
2950 (org-test-with-temp-text "Paragraph"
2951 (goto-char (point-max))
2952 (org-forward-paragraph)))
2955 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2956 (org-forward-paragraph)
2960 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2961 (org-forward-paragraph)
2963 ;; Do not enter elements with invisible contents.
2965 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2966 (org-hide-block-toggle)
2967 (org-forward-paragraph)
2969 ;; On an affiliated keyword, jump to the beginning of the element.
2971 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2972 (org-forward-paragraph)
2973 (looking-at "Para")))
2974 ;; On an item or a footnote definition, move to the second element
2977 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2978 (org-forward-paragraph)
2979 (looking-at " Paragraph")))
2981 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2982 (org-forward-paragraph)
2983 (looking-at "Paragraph")))
2984 ;; On an item, or a footnote definition, when the first line is
2985 ;; empty, move to the first item.
2987 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2988 (org-forward-paragraph)
2989 (looking-at " Paragraph")))
2991 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2992 (org-forward-paragraph)
2993 (looking-at "Paragraph")))
2994 ;; On a table (resp. a property drawer) do not move through table
2995 ;; rows (resp. node properties).
2997 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2998 (org-forward-paragraph)
2999 (looking-at "Paragraph")))
3001 (org-test-with-temp-text
3002 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3003 (org-forward-paragraph)
3004 (looking-at "Paragraph")))
3005 ;; On a verse or source block, stop after blank lines.
3007 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3008 (org-forward-paragraph)
3011 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3012 (org-forward-paragraph)
3013 (looking-at "L2"))))
3015 (ert-deftest test-org
/backward-paragraph
()
3016 "Test `org-backward-paragraph' specifications."
3017 ;; Error at beginning of buffer.
3019 (org-test-with-temp-text "Paragraph"
3020 (org-backward-paragraph)))
3023 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3024 (goto-char (point-max))
3025 (org-backward-paragraph)
3028 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3029 (goto-char (point-max))
3031 (org-backward-paragraph)
3035 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3036 (goto-char (point-max))
3038 (org-backward-paragraph)
3040 ;; Ignore invisible elements.
3042 (org-test-with-temp-text "* H1\n P1\n* H2"
3044 (goto-char (point-max))
3046 (org-backward-paragraph)
3048 ;; On an affiliated keyword, jump to the first one.
3050 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3051 (search-forward "c2")
3052 (org-backward-paragraph)
3053 (looking-at "#\\+name")))
3054 ;; On the second element in an item or a footnote definition, jump
3055 ;; to item or the definition.
3057 (org-test-with-temp-text "- line1\n\n line2"
3058 (goto-char (point-max))
3060 (org-backward-paragraph)
3061 (looking-at "- line1")))
3063 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3064 (goto-char (point-max))
3066 (org-backward-paragraph)
3067 (looking-at "\\[fn:1\\] line1")))
3068 ;; On a table (resp. a property drawer), ignore table rows
3069 ;; (resp. node properties).
3071 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3072 (goto-char (point-max))
3074 (org-backward-paragraph)
3077 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3078 (org-backward-paragraph)
3079 (looking-at ":PROPERTIES:")))
3080 ;; On a source or verse block, stop before blank lines.
3082 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3083 (search-forward "L3")
3085 (org-backward-paragraph)
3088 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3089 (search-forward "L3")
3091 (org-backward-paragraph)
3092 (looking-at "L2"))))
3094 (ert-deftest test-org
/forward-element
()
3095 "Test `org-forward-element' specifications."
3096 ;; 1. At EOB: should error.
3097 (org-test-with-temp-text "Some text\n"
3098 (goto-char (point-max))
3099 (should-error (org-forward-element)))
3100 ;; 2. Standard move: expected to ignore blank lines.
3101 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3102 (org-forward-element)
3103 (should (looking-at (regexp-quote "Second paragraph."))))
3104 ;; 3. Headline tests.
3105 (org-test-with-temp-text "
3110 ;; 3.1. At an headline beginning: move to next headline at the
3113 (org-forward-element)
3114 (should (looking-at (regexp-quote "** Head 1.2")))
3115 ;; 3.2. At an headline beginning: move to parent headline if no
3116 ;; headline at the same level.
3118 (org-forward-element)
3119 (should (looking-at (regexp-quote "** Head 1.2"))))
3120 ;; 4. Greater element tests.
3121 (org-test-with-temp-text
3122 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3123 ;; 4.1. At a greater element: expected to skip contents.
3124 (org-forward-element)
3125 (should (looking-at (regexp-quote "Outside.")))
3126 ;; 4.2. At the end of greater element contents: expected to skip
3127 ;; to the end of the greater element.
3129 (org-forward-element)
3130 (should (looking-at (regexp-quote "Outside."))))
3132 (org-test-with-temp-text "
3146 ;; 5.1. At list top point: expected to move to the element after
3149 (org-forward-element)
3150 (should (looking-at (regexp-quote "Outside.")))
3151 ;; 5.2. Special case: at the first line of a sub-list, but not at
3152 ;; beginning of line, move to next item.
3155 (org-forward-element)
3156 (should (looking-at "- item2"))
3159 (org-forward-element)
3160 (should (looking-at " - sub2"))
3161 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3163 (org-forward-element)
3164 (should (looking-at (regexp-quote " Inner paragraph.")))
3165 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3167 (org-forward-element)
3168 (should (looking-at (regexp-quote " Inner paragraph.")))
3169 ;; 5.5. At an item: expected to move to next item, if any.
3171 (org-forward-element)
3172 (should (looking-at " - sub3"))))
3174 (ert-deftest test-org
/backward-element
()
3175 "Test `org-backward-element' specifications."
3176 ;; 1. Should error at BOB.
3177 (org-test-with-temp-text " \nParagraph."
3178 (should-error (org-backward-element)))
3179 ;; 2. Should move at BOB when called on the first element in buffer.
3181 (org-test-with-temp-text "\n#+TITLE: test"
3182 (progn (forward-line)
3183 (org-backward-element)
3185 ;; 3. Not at the beginning of an element: move at its beginning.
3186 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3189 (org-backward-element)
3190 (should (looking-at (regexp-quote "Paragraph2."))))
3191 ;; 4. Headline tests.
3192 (org-test-with-temp-text "
3197 ;; 4.1. At an headline beginning: move to previous headline at the
3200 (org-backward-element)
3201 (should (looking-at (regexp-quote "** Head 1.1")))
3202 ;; 4.2. At an headline beginning: move to parent headline if no
3203 ;; headline at the same level.
3205 (org-backward-element)
3206 (should (looking-at (regexp-quote "* Head 1")))
3207 ;; 4.3. At the first top-level headline: should error.
3209 (should-error (org-backward-element)))
3210 ;; 5. At beginning of first element inside a greater element:
3211 ;; expected to move to greater element's beginning.
3212 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3214 (org-backward-element)
3215 (should (looking-at "#\\+BEGIN_CENTER")))
3216 ;; 6. At the beginning of the first element in a section: should
3217 ;; move back to headline, if any.
3219 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3220 (progn (goto-char (point-max))
3222 (org-backward-element)
3223 (org-at-heading-p))))
3225 (org-test-with-temp-text "
3240 ;; 7.1. At beginning of sub-list: expected to move to the
3241 ;; paragraph before it.
3243 (org-backward-element)
3244 (should (looking-at "item1"))
3245 ;; 7.2. At an item in a list: expected to move at previous item.
3247 (org-backward-element)
3248 (should (looking-at " - sub2"))
3250 (org-backward-element)
3251 (should (looking-at "- item1"))
3252 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3255 (org-backward-element)
3256 (should (looking-at " - sub1"))
3258 (org-backward-element)
3259 (should (looking-at "- item1"))
3260 ;; 7.4. At blank-lines before list end: expected to move to top
3263 (org-backward-element)
3264 (should (looking-at "- item1"))))
3266 (ert-deftest test-org
/up-element
()
3267 "Test `org-up-element' specifications."
3268 ;; 1. At BOB or with no surrounding element: should error.
3269 (org-test-with-temp-text "Paragraph."
3270 (should-error (org-up-element)))
3271 (org-test-with-temp-text "* Head1\n* Head2"
3273 (should-error (org-up-element)))
3274 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3276 (should-error (org-up-element)))
3277 ;; 2. At an headline: move to parent headline.
3278 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3281 (should (looking-at "\\* Head1")))
3282 ;; 3. Inside a greater element: move to greater element beginning.
3283 (org-test-with-temp-text
3284 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3287 (should (looking-at "#\\+BEGIN_CENTER")))
3289 (org-test-with-temp-text "* Top
3296 Paragraph within sub2.
3299 ;; 4.1. Within an item: move to the item beginning.
3302 (should (looking-at " - sub2"))
3303 ;; 4.2. At an item in a sub-list: move to parent item.
3306 (should (looking-at "- item1"))
3307 ;; 4.3. At an item in top list: move to beginning of whole list.
3310 (should (looking-at "- item1"))
3311 ;; 4.4. Special case. At very top point: should move to parent of
3315 (should (looking-at "\\* Top"))))
3317 (ert-deftest test-org
/down-element
()
3318 "Test `org-down-element' specifications."
3319 ;; Error when the element hasn't got a recursive type.
3320 (org-test-with-temp-text "Paragraph."
3321 (should-error (org-down-element)))
3322 ;; Error when the element has no contents
3323 (org-test-with-temp-text "* Headline"
3324 (should-error (org-down-element)))
3325 ;; When at a plain-list, move to first item.
3326 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3329 (should (looking-at " - Item 1.1")))
3330 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3332 (should (looking-at " Item 1")))
3333 ;; When at a table, move to first row
3334 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3336 (should (looking-at " a | b |")))
3337 ;; Otherwise, move inside the greater element.
3338 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3340 (should (looking-at "Paragraph"))))
3342 (ert-deftest test-org
/drag-element-backward
()
3343 "Test `org-drag-element-backward' specifications."
3347 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3348 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3349 (org-drag-element-backward)
3353 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3354 (org-test-with-temp-text
3355 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3356 (org-drag-element-backward)
3358 ;; Preserve blank lines.
3360 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3361 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3362 (org-drag-element-backward)
3366 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3367 (org-drag-element-backward)
3368 (looking-at-p "2")))
3369 ;; Error when trying to move first element of buffer.
3371 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3372 (org-drag-element-backward))
3374 ;; Error when trying to swap nested elements.
3376 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3377 (org-drag-element-backward))
3379 ;; Error when trying to swap an headline element and a non-headline
3382 (org-test-with-temp-text "Test.\n<point>* Head 1"
3383 (org-drag-element-backward))
3385 ;; Error when called before first element.
3387 (org-test-with-temp-text "\n<point>"
3388 (org-drag-element-backward))
3390 ;; Preserve visibility of elements and their contents.
3392 (equal '((63 .
82) (26 .
48))
3393 (org-test-with-temp-text "
3401 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3402 (search-backward "- item 1")
3403 (org-drag-element-backward)
3404 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3405 (overlays-in (point-min) (point-max))))))
3406 ;; Pathological case: handle call with point in blank lines right
3407 ;; after a headline.
3409 (equal "* H2\n* H1\nText\n\n"
3410 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3411 (org-drag-element-backward)
3414 (ert-deftest test-org
/drag-element-forward
()
3415 "Test `org-drag-element-forward' specifications."
3416 ;; 1. Error when trying to move first element of buffer.
3417 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3419 (should-error (org-drag-element-forward)))
3420 ;; 2. Error when trying to swap nested elements.
3421 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3423 (should-error (org-drag-element-forward)))
3424 ;; 3. Error when trying to swap a non-headline element and an
3426 (org-test-with-temp-text "Test.\n* Head 1"
3427 (should-error (org-drag-element-forward)))
3428 ;; 4. Error when called before first element.
3430 (org-test-with-temp-text "\n"
3432 (org-drag-element-backward))
3434 ;; 5. Otherwise, swap elements, preserving column and blank lines
3435 ;; between elements.
3436 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3437 (search-forward "graph")
3438 (org-drag-element-forward)
3439 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3440 (should (looking-at " 1")))
3441 ;; 5. Preserve visibility of elements and their contents.
3442 (org-test-with-temp-text "
3450 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3451 (search-backward "#+BEGIN_CENTER")
3452 (org-drag-element-forward)
3455 '((63 .
82) (26 .
48))
3456 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3457 (overlays-in (point-min) (point-max)))))))
3459 (ert-deftest test-org
/next-block
()
3460 "Test `org-next-block' specifications."
3463 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3465 (looking-at "#\\+BEGIN_CENTER")))
3468 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3469 (let ((case-fold-search nil
))
3471 (looking-at "#\\+begin_center"))))
3472 ;; Ignore current line.
3474 (org-test-with-temp-text
3475 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3477 (looking-at "#\\+BEGIN_CENTER")))
3478 ;; Throw an error when no block is found.
3480 (org-test-with-temp-text "Paragraph"
3481 (org-next-block 1)))
3482 ;; With an argument, skip many blocks at once.
3484 (org-test-with-temp-text
3485 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3487 (looking-at "#\\+BEGIN_QUOTE")))
3488 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3490 (org-test-with-temp-text
3491 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3492 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3493 (looking-at "#\\+BEGIN_QUOTE")))
3494 ;; Optional argument is also case-insensitive.
3496 (org-test-with-temp-text
3497 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3498 (let ((case-fold-search nil
))
3499 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3500 (looking-at "#\\+begin_quote")))))
3502 (ert-deftest test-org
/previous-block
()
3503 "Test `org-previous-block' specifications."
3506 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3507 (org-previous-block 1)
3508 (looking-at "#\\+BEGIN_CENTER")))
3511 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3512 (let ((case-fold-search nil
))
3513 (org-previous-block 1)
3514 (looking-at "#\\+begin_center"))))
3515 ;; Ignore current line.
3517 (org-test-with-temp-text
3518 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3519 (org-previous-block 1)
3520 (looking-at "#\\+BEGIN_QUOTE")))
3521 ;; Throw an error when no block is found.
3523 (org-test-with-temp-text "Paragraph<point>"
3524 (org-previous-block 1)))
3525 ;; With an argument, skip many blocks at once.
3527 (org-test-with-temp-text
3528 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3529 (org-previous-block 2)
3530 (looking-at "#\\+BEGIN_CENTER")))
3531 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3533 (org-test-with-temp-text
3534 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3535 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3536 (looking-at "#\\+BEGIN_QUOTE")))
3537 ;; Optional argument is also case-insensitive.
3539 (org-test-with-temp-text
3540 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3541 (let ((case-fold-search nil
))
3542 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3543 (looking-at "#\\+begin_quote")))))
3546 ;;; Outline structure
3548 (ert-deftest test-org
/demote
()
3549 "Test `org-demote' specifications."
3550 ;; Add correct number of stars according to `org-odd-levels-only'.
3553 (org-test-with-temp-text "* H"
3554 (let ((org-odd-levels-only nil
)) (org-demote))
3555 (org-current-level))))
3558 (org-test-with-temp-text "* H"
3559 (let ((org-odd-levels-only t
)) (org-demote))
3560 (org-current-level))))
3561 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3563 (org-test-with-temp-text "* H :tag:"
3564 (let ((org-tags-column 10)
3565 (org-auto-align-tags t
)
3566 (org-odd-levels-only nil
))
3568 (org-move-to-column 10)
3569 (looking-at-p ":tag:$")))
3571 (org-test-with-temp-text "* H :tag:"
3572 (let ((org-tags-column 10)
3573 (org-auto-align-tags nil
)
3574 (org-odd-levels-only nil
))
3576 (org-move-to-column 10)
3577 (looking-at-p ":tag:$")))
3578 ;; When `org-adapt-indentation' is non-nil, always indent planning
3579 ;; info and property drawers accordingly.
3582 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3583 (let ((org-odd-levels-only nil
)
3584 (org-adapt-indentation t
))
3587 (org-get-indentation))))
3590 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3591 (let ((org-odd-levels-only nil
)
3592 (org-adapt-indentation t
))
3595 (org-get-indentation))))
3598 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3599 (let ((org-odd-levels-only nil
)
3600 (org-adapt-indentation nil
))
3603 (org-get-indentation))))
3604 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3605 ;; section accordingly. Ignore, however, footnote definitions and
3606 ;; inlinetasks boundaries.
3609 (org-test-with-temp-text "* H\n Paragraph"
3610 (let ((org-odd-levels-only nil
)
3611 (org-adapt-indentation t
))
3614 (org-get-indentation))))
3617 (org-test-with-temp-text "* H\n Paragraph"
3618 (let ((org-odd-levels-only nil
)
3619 (org-adapt-indentation nil
))
3622 (org-get-indentation))))
3625 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3626 (let ((org-odd-levels-only nil
)
3627 (org-adapt-indentation t
))
3629 (goto-char (point-max))
3630 (org-get-indentation))))
3633 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3634 (let ((org-odd-levels-only nil
)
3635 (org-adapt-indentation t
))
3637 (goto-char (point-max))
3638 (org-get-indentation))))
3639 (when (featurep 'org-inlinetask
)
3642 (let ((org-inlinetask-min-level 5)
3643 (org-adapt-indentation t
))
3644 (org-test-with-temp-text "* H\n***** I\n***** END"
3647 (org-get-indentation))))))
3648 (when (featurep 'org-inlinetask
)
3651 (let ((org-inlinetask-min-level 5)
3652 (org-adapt-indentation t
))
3653 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3656 (org-get-indentation))))))
3657 ;; Ignore contents of source blocks or example blocks when
3658 ;; indentation should be preserved (through
3659 ;; `org-src-preserve-indentation' or "-i" flag).
3662 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3663 (let ((org-adapt-indentation t
)
3664 (org-src-preserve-indentation nil
))
3667 (org-get-indentation))))
3670 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3671 (let ((org-adapt-indentation t
)
3672 (org-src-preserve-indentation t
))
3675 (org-get-indentation))))
3678 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3679 (let ((org-adapt-indentation t
)
3680 (org-src-preserve-indentation t
))
3683 (org-get-indentation))))
3686 (org-test-with-temp-text
3687 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3688 (let ((org-adapt-indentation t
)
3689 (org-src-preserve-indentation nil
))
3692 (org-get-indentation)))))
3694 (ert-deftest test-org
/promote
()
3695 "Test `org-promote' specifications."
3696 ;; Return an error if headline is to be promoted to level 0, unless
3697 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3698 ;; headline becomes a comment.
3700 (org-test-with-temp-text "* H"
3701 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3704 (org-test-with-temp-text "* H"
3705 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3707 ;; Remove correct number of stars according to
3708 ;; `org-odd-levels-only'.
3711 (org-test-with-temp-text "*** H"
3712 (let ((org-odd-levels-only nil
)) (org-promote))
3713 (org-current-level))))
3716 (org-test-with-temp-text "*** H"
3717 (let ((org-odd-levels-only t
)) (org-promote))
3718 (org-current-level))))
3719 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3721 (org-test-with-temp-text "** H :tag:"
3722 (let ((org-tags-column 10)
3723 (org-auto-align-tags t
)
3724 (org-odd-levels-only nil
))
3726 (org-move-to-column 10)
3727 (looking-at-p ":tag:$")))
3729 (org-test-with-temp-text "** H :tag:"
3730 (let ((org-tags-column 10)
3731 (org-auto-align-tags nil
)
3732 (org-odd-levels-only nil
))
3734 (org-move-to-column 10)
3735 (looking-at-p ":tag:$")))
3736 ;; When `org-adapt-indentation' is non-nil, always indent planning
3737 ;; info and property drawers.
3740 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3741 (let ((org-odd-levels-only nil
)
3742 (org-adapt-indentation t
))
3745 (org-get-indentation))))
3748 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3749 (let ((org-odd-levels-only nil
)
3750 (org-adapt-indentation t
))
3753 (org-get-indentation))))
3756 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3757 (let ((org-odd-levels-only nil
)
3758 (org-adapt-indentation nil
))
3761 (org-get-indentation))))
3762 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3763 ;; section accordingly. Ignore, however, footnote definitions and
3764 ;; inlinetasks boundaries.
3767 (org-test-with-temp-text "** H\n Paragraph"
3768 (let ((org-odd-levels-only nil
)
3769 (org-adapt-indentation t
))
3772 (org-get-indentation))))
3775 (org-test-with-temp-text "** H\n Paragraph"
3776 (let ((org-odd-levels-only nil
)
3777 (org-adapt-indentation nil
))
3780 (org-get-indentation))))
3783 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3784 (let ((org-odd-levels-only nil
)
3785 (org-adapt-indentation t
))
3788 (org-get-indentation))))
3789 (when (featurep 'org-inlinetask
)
3792 (let ((org-inlinetask-min-level 5)
3793 (org-adapt-indentation t
))
3794 (org-test-with-temp-text "** H\n***** I\n***** END"
3797 (org-get-indentation))))))
3798 (when (featurep 'org-inlinetask
)
3801 (let ((org-inlinetask-min-level 5)
3802 (org-adapt-indentation t
))
3803 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3806 (org-get-indentation))))))
3807 ;; Give up shifting if it would break document's structure
3811 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3812 (let ((org-odd-levels-only nil
)
3813 (org-adapt-indentation t
))
3816 (org-get-indentation))))
3819 (org-test-with-temp-text "** H\n Paragraph\n * list."
3820 (let ((org-odd-levels-only nil
)
3821 (org-adapt-indentation t
))
3824 (org-get-indentation))))
3825 ;; Ignore contents of source blocks or example blocks when
3826 ;; indentation should be preserved (through
3827 ;; `org-src-preserve-indentation' or "-i" flag).
3830 (org-test-with-temp-text
3831 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3832 (let ((org-adapt-indentation t
)
3833 (org-src-preserve-indentation nil
)
3834 (org-odd-levels-only nil
))
3837 (org-get-indentation))))
3840 (org-test-with-temp-text
3841 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3842 (let ((org-adapt-indentation t
)
3843 (org-src-preserve-indentation t
)
3844 (org-odd-levels-only nil
))
3847 (org-get-indentation))))
3850 (org-test-with-temp-text
3851 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
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 -i\n(+ 1 1)\n #+END_SRC"
3862 (let ((org-adapt-indentation t
)
3863 (org-src-preserve-indentation nil
)
3864 (org-odd-levels-only nil
))
3867 (org-get-indentation)))))
3869 (ert-deftest test-org
/org-get-valid-level
()
3870 "Test function `org-get-valid-level' specifications."
3871 (let ((org-odd-levels-only nil
))
3872 (should (equal 1 (org-get-valid-level 0 0)))
3873 (should (equal 1 (org-get-valid-level 0 1)))
3874 (should (equal 2 (org-get-valid-level 0 2)))
3875 (should (equal 3 (org-get-valid-level 0 3)))
3876 (should (equal 1 (org-get-valid-level 1 0)))
3877 (should (equal 2 (org-get-valid-level 1 1)))
3878 (should (equal 23 (org-get-valid-level 1 22)))
3879 (should (equal 1 (org-get-valid-level 1 -
1)))
3880 (should (equal 1 (org-get-valid-level 2 -
1))))
3881 (let ((org-odd-levels-only t
))
3882 (should (equal 1 (org-get-valid-level 0 0)))
3883 (should (equal 1 (org-get-valid-level 0 1)))
3884 (should (equal 3 (org-get-valid-level 0 2)))
3885 (should (equal 5 (org-get-valid-level 0 3)))
3886 (should (equal 1 (org-get-valid-level 1 0)))
3887 (should (equal 3 (org-get-valid-level 1 1)))
3888 (should (equal 3 (org-get-valid-level 2 1)))
3889 (should (equal 5 (org-get-valid-level 3 1)))
3890 (should (equal 5 (org-get-valid-level 4 1)))
3891 (should (equal 43 (org-get-valid-level 1 21)))
3892 (should (equal 1 (org-get-valid-level 1 -
1)))
3893 (should (equal 1 (org-get-valid-level 2 -
1)))
3894 (should (equal 1 (org-get-valid-level 3 -
1)))
3895 (should (equal 3 (org-get-valid-level 4 -
1)))
3896 (should (equal 3 (org-get-valid-level 5 -
1)))))
3901 (ert-deftest test-org
/at-planning-p
()
3902 "Test `org-at-planning-p' specifications."
3905 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3906 (org-at-planning-p)))
3908 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3909 (org-at-planning-p)))
3910 ;; Correctly find planning attached to inlinetasks.
3911 (when (featurep 'org-inlinetask
)
3913 (org-test-with-temp-text
3914 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3915 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3917 (org-test-with-temp-text
3918 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3919 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3921 (org-test-with-temp-text
3922 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3923 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3925 (org-test-with-temp-text
3926 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3927 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3929 (ert-deftest test-org
/add-planning-info
()
3930 "Test `org-add-planning-info'."
3931 ;; Create deadline when `org-adapt-indentation' is non-nil.
3933 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3934 (org-test-with-temp-text "* H\nParagraph<point>"
3935 (let ((org-adapt-indentation t
))
3936 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3937 (replace-regexp-in-string
3938 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3940 ;; Create deadline when `org-adapt-indentation' is nil.
3942 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3943 (org-test-with-temp-text "* H\nParagraph<point>"
3944 (let ((org-adapt-indentation nil
))
3945 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3946 (replace-regexp-in-string
3947 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3949 ;; Update deadline when `org-adapt-indentation' is non-nil.
3951 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3952 (org-test-with-temp-text "\
3954 DEADLINE: <2015-06-24 Wed>
3956 (let ((org-adapt-indentation t
))
3957 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3958 (replace-regexp-in-string
3959 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3961 ;; Update deadline when `org-adapt-indentation' is nil.
3963 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3964 (org-test-with-temp-text "\
3966 DEADLINE: <2015-06-24 Wed>
3968 (let ((org-adapt-indentation nil
))
3969 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3970 (replace-regexp-in-string
3971 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3973 ;; Schedule when `org-adapt-indentation' is non-nil.
3975 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3976 (org-test-with-temp-text "* H\nParagraph<point>"
3977 (let ((org-adapt-indentation t
))
3978 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3979 (replace-regexp-in-string
3980 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3982 ;; Schedule when `org-adapt-indentation' is nil.
3984 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3985 (org-test-with-temp-text "* H\nParagraph<point>"
3986 (let ((org-adapt-indentation nil
))
3987 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3988 (replace-regexp-in-string
3989 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3991 ;; Add deadline when scheduled.
3995 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3997 (org-test-with-temp-text "\
3999 SCHEDULED: <2015-06-24 Wed>
4001 (let ((org-adapt-indentation t
))
4002 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4003 (replace-regexp-in-string
4004 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4006 ;; Remove middle entry.
4010 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4012 (org-test-with-temp-text "\
4014 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4016 (let ((org-adapt-indentation t
))
4017 (org-add-planning-info nil nil
'deadline
))
4018 (replace-regexp-in-string
4019 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4021 ;; Remove last entry and then middle entry (order should not
4026 CLOSED: [2015-06-24]
4028 (org-test-with-temp-text "\
4030 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4032 (let ((org-adapt-indentation t
))
4033 (org-add-planning-info nil nil
'scheduled
'deadline
))
4034 (replace-regexp-in-string
4035 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4037 ;; Remove closed when `org-adapt-indentation' is non-nil.
4039 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4040 (org-test-with-temp-text "\
4042 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4044 (let ((org-adapt-indentation t
))
4045 (org-add-planning-info nil nil
'closed
))
4046 (replace-regexp-in-string
4047 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4050 (equal "* H\n Paragraph"
4051 (org-test-with-temp-text "\
4053 CLOSED: [2015-06-25 Thu]
4055 (let ((org-adapt-indentation t
))
4056 (org-add-planning-info nil nil
'closed
))
4057 (replace-regexp-in-string
4058 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4060 ;; Remove closed when `org-adapt-indentation' is nil.
4062 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4063 (org-test-with-temp-text "\
4065 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4067 (let ((org-adapt-indentation nil
))
4068 (org-add-planning-info nil nil
'closed
))
4069 (replace-regexp-in-string
4070 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4073 (equal "* H\nParagraph"
4074 (org-test-with-temp-text "\
4076 CLOSED: [2015-06-25 Thu]
4078 (let ((org-adapt-indentation nil
))
4079 (org-add-planning-info nil nil
'closed
))
4080 (replace-regexp-in-string
4081 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4083 ;; Remove closed entry and delete empty line.
4088 (org-test-with-temp-text "\
4090 CLOSED: [2015-06-24 Wed]
4092 (let ((org-adapt-indentation t
))
4093 (org-add-planning-info nil nil
'closed
))
4094 (replace-regexp-in-string
4095 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4097 ;; Remove one entry and update another.
4099 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4100 (org-test-with-temp-text "\
4102 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4104 (let ((org-adapt-indentation t
))
4105 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4106 (replace-regexp-in-string
4107 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4110 (ert-deftest test-org
/deadline
()
4111 "Test `org-deadline' specifications."
4112 ;; Insert a new value or replace existing one.
4114 (equal "* H\nDEADLINE: <2012-03-29>\n"
4115 (org-test-with-temp-text "* H"
4116 (let ((org-adapt-indentation nil
)
4117 (org-last-inserted-timestamp nil
))
4118 (org-deadline nil
"<2012-03-29 Tue>"))
4119 (replace-regexp-in-string
4120 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4123 (equal "* H\nDEADLINE: <2014-03-04>"
4124 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4125 (let ((org-adapt-indentation nil
)
4126 (org-last-inserted-timestamp nil
))
4127 (org-deadline nil
"<2014-03-04 Thu>"))
4128 (replace-regexp-in-string
4129 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4131 ;; Accept delta time, e.g., "+2d".
4133 (equal "* H\nDEADLINE: <2015-03-04>\n"
4134 (cl-letf (((symbol-function 'current-time
)
4135 (lambda (&rest args
)
4136 (apply #'encode-time
4137 (org-parse-time-string "2014-03-04")))))
4138 (org-test-with-temp-text "* H"
4139 (let ((org-adapt-indentation nil
)
4140 (org-last-inserted-timestamp nil
))
4141 (org-deadline nil
"+1y"))
4142 (replace-regexp-in-string
4143 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4144 ;; Preserve repeater.
4146 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4147 (org-test-with-temp-text "* H"
4148 (let ((org-adapt-indentation nil
)
4149 (org-last-inserted-timestamp nil
))
4150 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4151 (replace-regexp-in-string
4152 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4153 ;; Remove CLOSED keyword, if any.
4155 (equal "* H\nDEADLINE: <2012-03-29>"
4156 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4157 (let ((org-adapt-indentation nil
)
4158 (org-last-inserted-timestamp nil
))
4159 (org-deadline nil
"<2012-03-29 Tue>"))
4160 (replace-regexp-in-string
4161 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4162 ;; With C-u argument, remove DEADLINE keyword.
4165 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4166 (let ((org-adapt-indentation nil
)
4167 (org-last-inserted-timestamp nil
))
4168 (org-deadline '(4)))
4172 (org-test-with-temp-text "* H"
4173 (let ((org-adapt-indentation nil
)
4174 (org-last-inserted-timestamp nil
))
4175 (org-deadline '(4)))
4177 ;; With C-u C-u argument, prompt for a delay cookie.
4179 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4180 (cl-letf (((symbol-function 'org-read-date
)
4181 (lambda (&rest args
)
4182 (apply #'encode-time
4183 (org-parse-time-string "2014-03-04")))))
4184 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4185 (let ((org-adapt-indentation nil
)
4186 (org-last-inserted-timestamp nil
))
4187 (org-deadline '(16)))
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"
4195 (let ((org-adapt-indentation nil
)
4196 (org-last-inserted-timestamp nil
))
4197 (org-deadline '(16)))
4199 ;; When a region is active and
4200 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4201 ;; same value in all headlines in region.
4203 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4204 (org-test-with-temp-text "* H1\n* H2"
4205 (let ((org-adapt-indentation nil
)
4206 (org-last-inserted-timestamp nil
)
4207 (org-loop-over-headlines-in-active-region t
))
4208 (transient-mark-mode 1)
4209 (push-mark (point) t t
)
4210 (goto-char (point-max))
4211 (org-deadline nil
"2012-03-29"))
4212 (replace-regexp-in-string
4213 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4215 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4216 (org-test-with-temp-text "* H1\n* H2"
4217 (let ((org-adapt-indentation nil
)
4218 (org-last-inserted-timestamp nil
)
4219 (org-loop-over-headlines-in-active-region nil
))
4220 (transient-mark-mode 1)
4221 (push-mark (point) t t
)
4222 (goto-char (point-max))
4223 (org-deadline nil
"2012-03-29"))
4224 (replace-regexp-in-string
4225 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4227 (ert-deftest test-org
/schedule
()
4228 "Test `org-schedule' specifications."
4229 ;; Insert a new value or replace existing one.
4231 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4232 (org-test-with-temp-text "* H"
4233 (let ((org-adapt-indentation nil
)
4234 (org-last-inserted-timestamp nil
))
4235 (org-schedule nil
"<2012-03-29 Tue>"))
4236 (replace-regexp-in-string
4237 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4240 (equal "* H\nSCHEDULED: <2014-03-04>"
4241 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4242 (let ((org-adapt-indentation nil
)
4243 (org-last-inserted-timestamp nil
))
4244 (org-schedule nil
"<2014-03-04 Thu>"))
4245 (replace-regexp-in-string
4246 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4248 ;; Accept delta time, e.g., "+2d".
4250 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4251 (cl-letf (((symbol-function 'current-time
)
4252 (lambda (&rest args
)
4253 (apply #'encode-time
4254 (org-parse-time-string "2014-03-04")))))
4255 (org-test-with-temp-text "* H"
4256 (let ((org-adapt-indentation nil
)
4257 (org-last-inserted-timestamp nil
))
4258 (org-schedule nil
"+1y"))
4259 (replace-regexp-in-string
4260 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4261 ;; Preserve repeater.
4263 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4264 (org-test-with-temp-text "* H"
4265 (let ((org-adapt-indentation nil
)
4266 (org-last-inserted-timestamp nil
))
4267 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4268 (replace-regexp-in-string
4269 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4270 ;; Remove CLOSED keyword, if any.
4272 (equal "* H\nSCHEDULED: <2012-03-29>"
4273 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4274 (let ((org-adapt-indentation nil
)
4275 (org-last-inserted-timestamp nil
))
4276 (org-schedule nil
"<2012-03-29 Tue>"))
4277 (replace-regexp-in-string
4278 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4279 ;; With C-u argument, remove SCHEDULED keyword.
4282 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4283 (let ((org-adapt-indentation nil
)
4284 (org-last-inserted-timestamp nil
))
4285 (org-schedule '(4)))
4289 (org-test-with-temp-text "* H"
4290 (let ((org-adapt-indentation nil
)
4291 (org-last-inserted-timestamp nil
))
4292 (org-schedule '(4)))
4294 ;; With C-u C-u argument, prompt for a delay cookie.
4296 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4297 (cl-letf (((symbol-function 'org-read-date
)
4298 (lambda (&rest args
)
4299 (apply #'encode-time
4300 (org-parse-time-string "2014-03-04")))))
4301 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4302 (let ((org-adapt-indentation nil
)
4303 (org-last-inserted-timestamp nil
))
4304 (org-schedule '(16)))
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"
4312 (let ((org-adapt-indentation nil
)
4313 (org-last-inserted-timestamp nil
))
4314 (org-schedule '(16)))
4316 ;; When a region is active and
4317 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4318 ;; same value in all headlines in region.
4320 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4321 (org-test-with-temp-text "* H1\n* H2"
4322 (let ((org-adapt-indentation nil
)
4323 (org-last-inserted-timestamp nil
)
4324 (org-loop-over-headlines-in-active-region t
))
4325 (transient-mark-mode 1)
4326 (push-mark (point) t t
)
4327 (goto-char (point-max))
4328 (org-schedule nil
"2012-03-29"))
4329 (replace-regexp-in-string
4330 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4332 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4333 (org-test-with-temp-text "* H1\n* H2"
4334 (let ((org-adapt-indentation nil
)
4335 (org-last-inserted-timestamp nil
)
4336 (org-loop-over-headlines-in-active-region nil
))
4337 (transient-mark-mode 1)
4338 (push-mark (point) t t
)
4339 (goto-char (point-max))
4340 (org-schedule nil
"2012-03-29"))
4341 (replace-regexp-in-string
4342 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4344 ;; check if a repeater survives re-scheduling.
4346 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4347 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4348 (let ((org-adapt-indentation nil
)
4349 (org-last-inserted-timestamp nil
))
4350 (org-schedule nil
"2017-02-01"))
4356 (ert-deftest test-org
/buffer-property-keys
()
4357 "Test `org-buffer-property-keys' specifications."
4358 ;; Retrieve properties accross siblings.
4361 (org-test-with-temp-text "
4370 (org-buffer-property-keys))))
4371 ;; Retrieve properties accross children.
4374 (org-test-with-temp-text "
4383 (org-buffer-property-keys))))
4384 ;; Retrieve muliple properties in the same drawer.
4387 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4388 (org-buffer-property-keys))))
4389 ;; Ignore extension symbol in property name.
4392 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4393 (org-buffer-property-keys))))
4394 ;; With non-nil COLUMNS, extract property names from columns.
4397 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4398 (org-buffer-property-keys nil nil t
))))
4400 (equal '("A" "B" "COLUMNS")
4401 (org-test-with-temp-text
4402 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4403 (org-buffer-property-keys nil nil t
))))
4404 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4407 (org-test-with-temp-text
4408 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4409 (org-buffer-property-keys nil nil nil t
)))))
4411 (ert-deftest test-org
/property-values
()
4412 "Test `org-property-values' specifications."
4416 (org-test-with-temp-text
4417 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4418 (org-property-values "A"))))
4419 ;; Ignore empty values.
4421 (org-test-with-temp-text
4422 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4423 (org-property-values "A")))
4424 ;; Take into consideration extended values.
4427 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4428 (org-property-values "A")))))
4430 (ert-deftest test-org
/find-property
()
4431 "Test `org-find-property' specifications."
4435 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4436 (org-find-property "prop"))))
4437 ;; Ignore false positives.
4440 (org-test-with-temp-text
4441 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4442 (org-find-property "A"))))
4443 ;; Return first entry found in buffer.
4446 (org-test-with-temp-text
4447 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4448 (org-find-property "A"))))
4449 ;; Only search visible part of the buffer.
4452 (org-test-with-temp-text
4453 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4454 (org-narrow-to-subtree)
4455 (org-find-property "A"))))
4456 ;; With optional argument, only find entries with a specific value.
4458 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4459 (org-find-property "A" "2")))
4462 (org-test-with-temp-text
4463 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4464 (org-find-property "A" "2"))))
4465 ;; Use "nil" for explicit nil values.
4468 (org-test-with-temp-text
4469 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4470 (org-find-property "A" "nil")))))
4472 (ert-deftest test-org
/entry-delete
()
4473 "Test `org-entry-delete' specifications."
4477 " *:PROPERTIES:\n *:B: +2\n *:END:"
4478 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4479 (org-entry-delete (point) "A")
4481 ;; Also remove accumulated properties.
4485 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4486 (org-entry-delete (point) "A")
4488 ;; When last property is removed, remove the property drawer.
4492 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4493 (org-entry-delete (point) "A")
4495 ;; Return a non-nil value when some property was removed.
4497 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4498 (org-entry-delete (point) "A")))
4500 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4501 (org-entry-delete (point) "C")))
4502 ;; Special properties cannot be located in a drawer. Allow to
4503 ;; remove them anyway, in case of user error.
4505 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4506 (org-entry-delete (point) "SCHEDULED"))))
4508 (ert-deftest test-org
/entry-get
()
4509 "Test `org-entry-get' specifications."
4513 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4514 (org-entry-get (point) "A"))))
4518 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4519 (org-entry-get (point) "a"))))
4520 ;; Handle extended values, both before and after base value.
4523 (org-test-with-temp-text
4524 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4525 (org-entry-get (point) "A"))))
4526 ;; Empty values are returned as the empty string.
4529 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4530 (org-entry-get (point) "A"))))
4531 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4532 ;; otherwise, return nil.
4534 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4535 (org-entry-get (point) "A")))
4538 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4539 (org-entry-get (point) "A" nil t
))))
4540 ;; Return nil when no property is found, independently on the
4541 ;; LITERAL-NIL argument.
4543 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4544 (org-entry-get (point) "B")))
4546 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4547 (org-entry-get (point) "B" nil t
)))
4548 ;; Handle inheritance, when allowed. Include extended values and
4549 ;; possibly global values.
4553 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4554 (org-entry-get (point) "A" t
))))
4558 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4559 (let ((org-use-property-inheritance t
))
4560 (org-entry-get (point) "A" 'selective
)))))
4562 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4563 (let ((org-use-property-inheritance nil
))
4564 (org-entry-get (point) "A" 'selective
))))
4568 (org-test-with-temp-text
4569 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4570 (org-entry-get (point-max) "A" t
))))
4573 (org-test-with-temp-text
4574 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4576 (org-entry-get (point-max) "A" t
))))
4579 (org-test-with-temp-text
4580 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4582 (org-entry-get (point-max) "A" t
)))))
4584 (ert-deftest test-org
/entry-properties
()
4585 "Test `org-entry-properties' specifications."
4586 ;; Get "ITEM" property.
4589 (org-test-with-temp-text "* TODO H"
4590 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4593 (org-test-with-temp-text "* TODO H"
4594 (cdr (assoc "ITEM" (org-entry-properties))))))
4595 ;; Get "TODO" property. TODO keywords are case sensitive.
4598 (org-test-with-temp-text "* TODO H"
4599 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4602 (org-test-with-temp-text "* TODO H"
4603 (cdr (assoc "TODO" (org-entry-properties))))))
4605 (org-test-with-temp-text "* H"
4606 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4608 (org-test-with-temp-text "* todo H"
4609 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4610 ;; Get "PRIORITY" property.
4613 (org-test-with-temp-text "* [#A] H"
4614 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4617 (org-test-with-temp-text "* [#A] H"
4618 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4620 (equal (char-to-string org-default-priority
)
4621 (org-test-with-temp-text "* H"
4622 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4623 ;; Get "FILE" property.
4625 (org-test-with-temp-text-in-file "* H\nParagraph"
4626 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4627 (buffer-file-name))))
4629 (org-test-with-temp-text-in-file "* H\nParagraph"
4630 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4631 (buffer-file-name))))
4633 (org-test-with-temp-text "* H\nParagraph"
4634 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4635 ;; Get "TAGS" property.
4637 (equal ":tag1:tag2:"
4638 (org-test-with-temp-text "* H :tag1:tag2:"
4639 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4641 (equal ":tag1:tag2:"
4642 (org-test-with-temp-text "* H :tag1:tag2:"
4643 (cdr (assoc "TAGS" (org-entry-properties))))))
4645 (org-test-with-temp-text "* H"
4646 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4647 ;; Get "ALLTAGS" property.
4649 (equal ":tag1:tag2:"
4650 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4651 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4653 (equal ":tag1:tag2:"
4654 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4655 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4657 (org-test-with-temp-text "* H"
4658 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4659 ;; Get "BLOCKED" property.
4662 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4663 (let ((org-enforce-todo-dependencies t
)
4665 '(org-block-todo-from-children-or-siblings-or-parent)))
4666 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4669 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4670 (let ((org-enforce-todo-dependencies t
)
4672 '(org-block-todo-from-children-or-siblings-or-parent)))
4673 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4674 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4678 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4679 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4683 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4684 (cdr (assoc "CLOSED" (org-entry-properties))))))
4686 (org-test-with-temp-text "* H"
4687 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4691 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4692 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4696 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4697 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4699 (org-test-with-temp-text "* H"
4700 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4704 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4705 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4709 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4710 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4712 (org-test-with-temp-text "* H"
4713 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4717 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4718 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4721 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4722 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4725 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4726 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4729 (org-test-with-temp-text
4730 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4732 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4733 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4734 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4736 (equal "<2012-03-29 thu.>"
4737 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4738 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4740 (equal "[2012-03-29 thu.]"
4741 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4742 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4744 (equal "<2012-03-29 thu.>"
4745 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4746 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4748 (equal "[2014-03-04 tue.]"
4749 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4750 (cdr (assoc "TIMESTAMP_IA"
4751 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4753 (equal "<2012-03-29 thu.>"
4754 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4755 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4756 ;; Get standard properties.
4759 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4760 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4761 ;; Handle extended properties.
4764 (org-test-with-temp-text
4765 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4766 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4769 (org-test-with-temp-text
4770 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4771 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4772 ;; Ignore forbidden (special) properties.
4774 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4775 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4777 (ert-deftest test-org
/entry-put
()
4778 "Test `org-entry-put' specifications."
4779 ;; Error when not a string or nil.
4781 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4782 (org-entry-put 1 "test" 2)))
4783 ;; Error when property name is invalid.
4785 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4786 (org-entry-put 1 "no space" "value")))
4788 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4789 (org-entry-put 1 "" "value")))
4790 ;; Set "TODO" property.
4792 (string-match (regexp-quote " TODO H")
4793 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4794 (org-entry-put (point) "TODO" "TODO")
4797 (string-match (regexp-quote "* H")
4798 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4799 (org-entry-put (point) "TODO" nil
)
4801 ;; Set "PRIORITY" property.
4804 (org-test-with-temp-text "* [#B] H"
4805 (org-entry-put (point) "PRIORITY" "A")
4809 (org-test-with-temp-text "* [#B] H"
4810 (org-entry-put (point) "PRIORITY" nil
)
4812 ;; Set "SCHEDULED" property.
4814 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4815 (org-test-with-temp-text "* H"
4816 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4820 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4821 (org-entry-put (point) "SCHEDULED" nil
)
4824 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4825 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4826 (org-entry-put (point) "SCHEDULED" "earlier")
4829 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4830 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4831 (org-entry-put (point) "SCHEDULED" "later")
4833 ;; Set "DEADLINE" property.
4835 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4836 (org-test-with-temp-text "* H"
4837 (org-entry-put (point) "DEADLINE" "2014-03-04")
4841 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4842 (org-entry-put (point) "DEADLINE" nil
)
4845 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4846 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4847 (org-entry-put (point) "DEADLINE" "earlier")
4850 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4851 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4852 (org-entry-put (point) "DEADLINE" "later")
4854 ;; Set "CATEGORY" property
4856 (string-match "^ *:CATEGORY: cat"
4857 (org-test-with-temp-text "* H"
4858 (org-entry-put (point) "CATEGORY" "cat")
4860 ;; Regular properties, with or without pre-existing drawer.
4862 (string-match "^ *:A: +2$"
4863 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4864 (org-entry-put (point) "A" "2")
4867 (string-match "^ *:A: +1$"
4868 (org-test-with-temp-text "* H"
4869 (org-entry-put (point) "A" "1")
4871 ;; Special case: two consecutive headlines.
4873 (string-match "\\* A\n *:PROPERTIES:"
4874 (org-test-with-temp-text "* A\n** B"
4875 (org-entry-put (point) "A" "1")
4878 (ert-deftest test-org
/refresh-properties
()
4879 "Test `org-refresh-properties' specifications."
4882 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4883 (org-refresh-properties "A" 'org-test
)
4884 (get-text-property (point) 'org-test
))))
4886 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4887 (org-refresh-properties "B" 'org-test
)
4888 (get-text-property (point) 'org-test
)))
4889 ;; Handle properties only defined with extension syntax, i.e.,
4893 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4894 (org-refresh-properties "A" 'org-test
)
4895 (get-text-property (point) 'org-test
))))
4896 ;; When property is inherited, add text property to the whole
4900 (org-test-with-temp-text
4901 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4902 (let ((org-use-property-inheritance t
))
4903 (org-refresh-properties "A" 'org-test
))
4904 (get-text-property (point) 'org-test
))))
4905 ;; When property is inherited, use global value across the whole
4906 ;; buffer. However local values have precedence.
4909 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4911 (let ((org-use-property-inheritance nil
))
4912 (org-refresh-properties "A" 'org-test
))
4913 (get-text-property (point) 'org-test
))))
4916 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4918 (let ((org-use-property-inheritance t
))
4919 (org-refresh-properties "A" 'org-test
))
4920 (get-text-property (point) 'org-test
))))
4923 (org-test-with-temp-text
4924 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4926 (let ((org-use-property-inheritance t
))
4927 (org-refresh-properties "A" 'org-test
))
4928 (get-text-property (point) 'org-test
)))))
4933 (ert-deftest test-org
/update-radio-target-regexp
()
4934 "Test `org-update-radio-target-regexp' specifications."
4935 ;; Properly update cache with no previous radio target regexp.
4938 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4939 (save-excursion (goto-char (point-max)) (org-element-context))
4941 (search-forward "o")
4943 (org-update-radio-target-regexp)
4944 (goto-char (point-max))
4945 (org-element-type (org-element-context)))))
4946 ;; Properly update cache with previous radio target regexp.
4949 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4950 (save-excursion (goto-char (point-max)) (org-element-context))
4952 (search-forward "o")
4954 (org-update-radio-target-regexp)
4955 (search-backward "r")
4958 (org-update-radio-target-regexp)
4959 (goto-char (point-max))
4960 (delete-region (line-beginning-position) (point))
4962 (org-element-type (org-element-context))))))
4967 (ert-deftest test-org
/match-sparse-tree
()
4968 "Test `org-match-sparse-tree' specifications."
4971 (org-test-with-temp-text "* H\n** H1 :tag:"
4972 (org-match-sparse-tree nil
"tag")
4973 (search-forward "H1")
4974 (org-invisible-p2)))
4976 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4977 (org-match-sparse-tree nil
"tag")
4978 (search-forward "H2")
4979 (org-invisible-p2)))
4980 ;; "-" operator for tags.
4982 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4983 (org-match-sparse-tree nil
"tag1-tag2")
4984 (search-forward "H1")
4985 (org-invisible-p2)))
4987 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4988 (org-match-sparse-tree nil
"tag1-tag2")
4989 (search-forward "H2")
4990 (org-invisible-p2)))
4991 ;; "&" operator for tags.
4993 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4994 (org-match-sparse-tree nil
"tag1&tag2")
4995 (search-forward "H1")
4996 (org-invisible-p2)))
4998 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4999 (org-match-sparse-tree nil
"tag1&tag2")
5000 (search-forward "H2")
5001 (org-invisible-p2)))
5002 ;; "|" operator for tags.
5004 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5005 (org-match-sparse-tree nil
"tag1|tag2")
5006 (search-forward "H1")
5007 (org-invisible-p2)))
5009 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5010 (org-match-sparse-tree nil
"tag1|tag2")
5011 (search-forward "H2")
5012 (org-invisible-p2)))
5013 ;; Regexp match on tags.
5015 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5016 (org-match-sparse-tree nil
"{^tag.*}")
5017 (search-forward "H1")
5018 (org-invisible-p2)))
5020 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5021 (org-match-sparse-tree nil
"{^tag.*}")
5022 (search-forward "H2")
5023 (org-invisible-p2)))
5024 ;; Match group tags.
5026 (org-test-with-temp-text
5027 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5028 (org-match-sparse-tree nil
"work")
5029 (search-forward "H1")
5030 (org-invisible-p2)))
5032 (org-test-with-temp-text
5033 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5034 (org-match-sparse-tree nil
"work")
5035 (search-forward "H2")
5036 (org-invisible-p2)))
5037 ;; Match group tags with hard brackets.
5039 (org-test-with-temp-text
5040 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5041 (org-match-sparse-tree nil
"work")
5042 (search-forward "H1")
5043 (org-invisible-p2)))
5045 (org-test-with-temp-text
5046 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5047 (org-match-sparse-tree nil
"work")
5048 (search-forward "H2")
5049 (org-invisible-p2)))
5050 ;; Match tags in hierarchies
5052 (org-test-with-temp-text
5053 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5054 #+TAGS: [ Lev_2 : Lev_3 ]\n
5055 #+TAGS: { Lev_3 : Lev_4 }\n
5056 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5057 (org-match-sparse-tree nil
"Lev_1")
5058 (search-forward "H4")
5059 (org-invisible-p2)))
5060 ;; Match regular expressions in tags
5062 (org-test-with-temp-text
5063 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5064 (org-match-sparse-tree nil
"Lev")
5065 (search-forward "H1")
5066 (org-invisible-p2)))
5068 (org-test-with-temp-text
5069 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5070 (org-match-sparse-tree nil
"Lev")
5071 (search-forward "H1")
5072 (org-invisible-p2)))
5073 ;; Match properties.
5075 (org-test-with-temp-text
5076 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5077 (org-match-sparse-tree nil
"A=\"1\"")
5078 (search-forward "H2")
5079 (org-invisible-p2)))
5081 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5082 (org-match-sparse-tree nil
"A=\"1\"")
5083 (search-forward "H2")
5084 (org-invisible-p2)))
5085 ;; Case is not significant when matching properties.
5087 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5088 (org-match-sparse-tree nil
"a=\"1\"")
5089 (search-forward "H2")
5090 (org-invisible-p2)))
5092 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5093 (org-match-sparse-tree nil
"A=\"1\"")
5094 (search-forward "H2")
5095 (org-invisible-p2)))
5096 ;; Match special LEVEL property.
5098 (org-test-with-temp-text "* H\n** H1\n*** H2"
5099 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5100 (search-forward "H1")
5101 (org-invisible-p2)))
5103 (org-test-with-temp-text "* H\n** H1\n*** H2"
5104 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5105 (search-forward "H2")
5106 (org-invisible-p2)))
5107 ;; Comparison operators when matching properties.
5109 (org-test-with-temp-text
5110 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5111 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5112 (search-forward "H1")
5113 (org-invisible-p2)))
5115 (org-test-with-temp-text
5116 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5117 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5118 (search-forward "H2")
5119 (org-invisible-p2)))
5120 ;; Regexp match on properties values.
5122 (org-test-with-temp-text
5123 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5124 (org-match-sparse-tree nil
"A={f.*}")
5125 (search-forward "H1")
5126 (org-invisible-p2)))
5128 (org-test-with-temp-text
5129 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5130 (org-match-sparse-tree nil
"A={f.*}")
5131 (search-forward "H2")
5132 (org-invisible-p2)))
5133 ;; With an optional argument, limit match to TODO entries.
5135 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5136 (org-match-sparse-tree t
"tag")
5137 (search-forward "H1")
5138 (org-invisible-p2)))
5140 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5141 (org-match-sparse-tree t
"tag")
5142 (search-forward "H2")
5143 (org-invisible-p2))))
5145 (ert-deftest test-org
/occur
()
5146 "Test `org-occur' specifications."
5147 ;; Count number of matches.
5150 (org-test-with-temp-text "* H\nA\n* H2"
5154 (org-test-with-temp-text "* H\nA\n* H2\nA"
5156 ;; Test CALLBACK optional argument.
5159 (org-test-with-temp-text "* H\nA\n* H2"
5160 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5163 (org-test-with-temp-text "* H\nA\n* H2\nA"
5164 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5165 ;; Case-fold searches according to `org-occur-case-fold-search'.
5168 (org-test-with-temp-text "Aa"
5169 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5172 (org-test-with-temp-text "Aa"
5173 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5176 (org-test-with-temp-text "Aa"
5177 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5180 (org-test-with-temp-text "Aa"
5181 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5184 (org-test-with-temp-text "Aa"
5185 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5188 (org-test-with-temp-text "Aa"
5189 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5194 (ert-deftest test-org
/tag-string-to-alist
()
5195 "Test `org-tag-string-to-alist' specifications."
5196 ;; Tag without selection key.
5197 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5198 ;; Tag with selection key.
5199 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5203 (org-tag-string-to-alist "[ group : t1 t2 ]")
5204 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5205 ;; Mutually exclusive tags.
5206 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5207 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5210 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5211 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5213 (ert-deftest test-org
/tag-alist-to-string
()
5214 "Test `org-tag-alist-to-string' specifications."
5215 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5216 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5219 (org-tag-alist-to-string
5220 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5221 "[ group : t1 t2 ]"))
5223 (equal (org-tag-alist-to-string
5224 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5228 (org-tag-alist-to-string
5229 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5230 "{ group : tag1 tag2 }")))
5232 (ert-deftest test-org
/tag-alist-to-groups
()
5233 "Test `org-tag-alist-to-groups' specifications."
5235 (equal (org-tag-alist-to-groups
5236 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5237 '(("group" "t1" "t2"))))
5240 (org-tag-alist-to-groups
5241 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5242 '(("group" "t1" "t2"))))
5244 (org-tag-alist-to-groups
5245 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5247 (ert-deftest test-org
/tag-align
()
5248 "Test tags alignment."
5249 ;; Test aligning tags with different display width.
5251 ;; 12345678901234567890
5252 (equal "* Test :abc:"
5253 (org-test-with-temp-text "* Test :abc:"
5254 (let ((org-tags-column -
20)
5255 (indent-tabs-mode nil
))
5256 (org-fix-tags-on-the-fly))
5259 ;; 12345678901234567890
5260 (equal "* Test :日本語:"
5261 (org-test-with-temp-text "* Test :日本語:"
5262 (let ((org-tags-column -
20)
5263 (indent-tabs-mode nil
))
5264 (org-fix-tags-on-the-fly))
5266 ;; Make sure aligning tags do not skip invisible text.
5268 (equal "* [[linkx]] :tag:"
5269 (org-test-with-temp-text "* [[link<point>]] :tag:"
5270 (let ((org-tags-column 0))
5271 (org-fix-tags-on-the-fly)
5273 (buffer-string))))))
5275 (ert-deftest test-org
/tags-at
()
5277 (equal '("foo" "bar")
5278 (org-test-with-temp-text
5279 "* T<point>est :foo:bar:"
5280 (org-get-tags-at)))))
5285 (ert-deftest test-org
/auto-repeat-maybe
()
5286 "Test `org-auto-repeat-maybe' specifications."
5287 ;; Do not auto repeat when there is no valid time stamp with
5288 ;; a repeater in the entry.
5292 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5293 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5299 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5300 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5303 ;; When switching to DONE state, switch back to first TODO keyword
5304 ;; in sequence, or the same keyword if they have different types.
5308 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5309 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5315 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5316 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5322 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5323 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5326 ;; If there was no TODO keyword in the first place, do not insert
5331 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5332 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5335 ;; Revert to REPEAT_TO_STATE, if set.
5339 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5340 (org-test-with-temp-text
5343 :REPEAT_TO_STATE: KWD2
5345 <2012-03-29 Thu +2y>"
5348 ;; When switching to DONE state, update base date. If there are
5349 ;; multiple repeated time stamps, update them all.
5352 "<2014-03-29 .* \\+2y>"
5353 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5354 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5359 "<2015-03-04 .* \\+1y>"
5360 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5361 (org-test-with-temp-text
5362 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5365 ;; Throw an error if repeater unit is the hour and no time is
5366 ;; provided in the time-stamp.
5368 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5369 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5372 ;; Do not repeat commented time stamps.
5375 "<2015-03-04 .* \\+1y>"
5376 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5377 (org-test-with-temp-text
5378 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5383 "<2015-03-04 .* \\+1y>"
5384 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5385 (org-test-with-temp-text
5387 <2012-03-29 Thu. +2y>
5389 <2014-03-04 Tue +1y>
5393 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5394 ;; entry, record time of last repeat.
5398 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5399 (org-log-repeat nil
))
5400 (cl-letf (((symbol-function 'org-add-log-setup
)
5401 (lambda (&rest args
) nil
)))
5402 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5404 (buffer-string))))))
5408 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
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"))))
5419 (cl-letf (((symbol-function 'org-add-log-setup
)
5420 (lambda (&rest args
) nil
)))
5421 (org-test-with-temp-text
5422 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5424 (buffer-string))))))
5425 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5426 ;; the entry as it is no longer relevant.
5430 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5431 (org-test-with-temp-text
5432 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5434 (buffer-string))))))
5439 (ert-deftest test-org
/at-timestamp-p
()
5440 "Test `org-at-timestamp-p' specifications."
5442 (org-test-with-temp-text "<2012-03-29 Thu>"
5443 (org-at-timestamp-p)))
5445 (org-test-with-temp-text "2012-03-29 Thu"
5446 (org-at-timestamp-p)))
5447 ;; Test return values.
5450 (org-test-with-temp-text "<2012-03-29 Thu>"
5451 (org-at-timestamp-p))))
5454 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5455 (org-at-timestamp-p))))
5458 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5459 (org-at-timestamp-p))))
5462 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5463 (org-at-timestamp-p))))
5466 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5467 (org-at-timestamp-p))))
5470 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5471 (org-at-timestamp-p))))
5474 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5475 (org-at-timestamp-p))))
5478 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5479 (org-at-timestamp-p))))
5480 ;; Test optional argument.
5482 (org-test-with-temp-text "[2012-03-29 Thu]"
5483 (org-at-timestamp-p t
)))
5485 (org-test-with-temp-text "[2012-03-29 Thu]"
5486 (org-at-timestamp-p)))
5487 ;; Unlike `org-element-context', recognize time-stamps in planning
5488 ;; info line, property drawers and clocks.
5490 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5491 (org-at-timestamp-p)))
5493 (org-test-with-temp-text
5494 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5495 (org-at-timestamp-p)))
5497 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5498 (org-at-timestamp-p t
))))
5500 (ert-deftest test-org
/time-stamp
()
5501 "Test `org-time-stamp' specifications."
5502 ;; Insert chosen time stamp at point.
5505 "Te<2014-03-04 .*?>xt"
5506 (org-test-with-temp-text "Te<point>xt"
5507 (cl-letf (((symbol-function 'org-read-date
)
5508 (lambda (&rest args
)
5509 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5510 (org-time-stamp nil
)
5512 ;; With a prefix argument, also insert time.
5515 "Te<2014-03-04 .*? 00:41>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
5520 (org-parse-time-string "2014-03-04 00:41")))))
5521 (org-time-stamp '(4))
5523 ;; With two universal prefix arguments, insert an active timestamp
5524 ;; with the current time without prompting the user.
5527 "Te<2014-03-04 .*? 00:41>xt"
5528 (org-test-with-temp-text "Te<point>xt"
5529 (cl-letf (((symbol-function 'current-time
)
5531 (apply #'encode-time
5532 (org-parse-time-string "2014-03-04 00:41")))))
5533 (org-time-stamp '(16))
5535 ;; When optional argument is non-nil, insert an inactive timestamp.
5538 "Te\\[2014-03-04 .*?\\]xt"
5539 (org-test-with-temp-text "Te<point>xt"
5540 (cl-letf (((symbol-function 'org-read-date
)
5541 (lambda (&rest args
)
5542 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5543 (org-time-stamp nil t
)
5545 ;; When called from a timestamp, replace existing one.
5549 (org-test-with-temp-text "<2012-03-29<point> thu.>"
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
)
5557 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5558 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5559 (cl-letf (((symbol-function 'org-read-date
)
5560 (lambda (&rest args
)
5561 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5562 (org-time-stamp nil
)
5564 ;; When replacing a timestamp, preserve repeater, if any.
5567 "<2014-03-04 .*? \\+2y>"
5568 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
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 called twice in a raw, build a date range.
5577 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5578 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5579 (cl-letf (((symbol-function 'org-read-date
)
5580 (lambda (&rest args
)
5581 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5582 (let ((last-command 'org-time-stamp
)
5583 (this-command 'org-time-stamp
))
5584 (org-time-stamp nil
))
5585 (buffer-string))))))
5587 (ert-deftest test-org
/timestamp-has-time-p
()
5588 "Test `org-timestamp-has-time-p' specifications."
5591 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5592 (org-timestamp-has-time-p (org-element-context))))
5595 (org-test-with-temp-text "<2012-03-29 Thu>"
5596 (org-timestamp-has-time-p (org-element-context)))))
5598 (ert-deftest test-org
/get-repeat
()
5599 "Test `org-get-repeat' specifications."
5601 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
5604 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
5606 ;; Return proper repeat string.
5609 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
5611 ;; Prevent false positive (commented or verbatim time stamps)
5613 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
5616 (org-test-with-temp-text
5617 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
5619 ;; Return nil when called before first heading.
5621 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
5623 ;; When called with an optional argument, extract repeater from that
5625 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
5626 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
5628 (ert-deftest test-org
/timestamp-format
()
5629 "Test `org-timestamp-format' specifications."
5634 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5635 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5640 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5641 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5643 (ert-deftest test-org
/timestamp-split-range
()
5644 "Test `org-timestamp-split-range' specifications."
5645 ;; Extract range start (active).
5648 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5649 (let ((ts (org-timestamp-split-range (org-element-context))))
5650 (mapcar (lambda (p) (org-element-property p ts
))
5651 '(:year-end
:month-end
:day-end
))))))
5652 ;; Extract range start (inactive)
5655 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5656 (let ((ts (org-timestamp-split-range (org-element-context))))
5657 (mapcar (lambda (p) (org-element-property p ts
))
5658 '(:year-end
:month-end
:day-end
))))))
5659 ;; Extract range end (active).
5662 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5663 (let ((ts (org-timestamp-split-range
5664 (org-element-context) t
)))
5665 (mapcar (lambda (p) (org-element-property p ts
))
5666 '(:year-end
:month-end
:day-end
))))))
5667 ;; Extract range end (inactive)
5670 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5671 (let ((ts (org-timestamp-split-range
5672 (org-element-context) t
)))
5673 (mapcar (lambda (p) (org-element-property p ts
))
5674 '(:year-end
:month-end
:day-end
))))))
5675 ;; Return the timestamp if not a range.
5677 (org-test-with-temp-text "[2012-03-29 Thu]"
5678 (let* ((ts-orig (org-element-context))
5679 (ts-copy (org-timestamp-split-range ts-orig
)))
5680 (eq ts-orig ts-copy
))))
5682 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5683 (let* ((ts-orig (org-element-context))
5684 (ts-copy (org-timestamp-split-range ts-orig
)))
5685 (eq ts-orig ts-copy
)))))
5687 (ert-deftest test-org
/timestamp-translate
()
5688 "Test `org-timestamp-translate' specifications."
5689 ;; Translate whole date range.
5692 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5693 (let ((org-display-custom-times t
)
5694 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5695 (org-timestamp-translate (org-element-context))))))
5696 ;; Translate date range start.
5699 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5700 (let ((org-display-custom-times t
)
5701 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5702 (org-timestamp-translate (org-element-context) 'start
)))))
5703 ;; Translate date range end.
5706 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5707 (let ((org-display-custom-times t
)
5708 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5709 (org-timestamp-translate (org-element-context) 'end
)))))
5710 ;; Translate time range.
5713 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5714 (let ((org-display-custom-times t
)
5715 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5716 (org-timestamp-translate (org-element-context))))))
5717 ;; Translate non-range timestamp.
5720 (org-test-with-temp-text "<2012-03-29 Thu>"
5721 (let ((org-display-custom-times t
)
5722 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5723 (org-timestamp-translate (org-element-context))))))
5724 ;; Do not change `diary' timestamps.
5726 (equal "<%%(org-float t 4 2)>"
5727 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5728 (let ((org-display-custom-times t
)
5729 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5730 (org-timestamp-translate (org-element-context)))))))
5736 (ert-deftest test-org
/flag-drawer
()
5737 "Test `org-flag-drawer' specifications."
5740 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5742 (get-char-property (line-end-position) 'invisible
)))
5745 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5747 (org-flag-drawer nil
)
5748 (get-char-property (line-end-position) 'invisible
)))
5749 ;; Test optional argument.
5751 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5752 (let ((drawer (save-excursion (search-forward ":D2")
5753 (org-element-at-point))))
5754 (org-flag-drawer t drawer
)
5755 (get-char-property (progn (search-forward ":D2") (line-end-position))
5758 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5759 (let ((drawer (save-excursion (search-forward ":D2")
5760 (org-element-at-point))))
5761 (org-flag-drawer t drawer
)
5762 (get-char-property (line-end-position) 'invisible
))))
5763 ;; Do not hide fake drawers.
5765 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5768 (get-char-property (line-end-position) 'invisible
)))
5769 ;; Do not hide incomplete drawers.
5771 (org-test-with-temp-text ":D:\nparagraph"
5774 (get-char-property (line-end-position) 'invisible
)))
5775 ;; Do not hide drawers when called from final blank lines.
5777 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5778 (goto-char (point-max))
5780 (goto-char (point-min))
5781 (get-char-property (line-end-position) 'invisible
)))
5782 ;; Don't leave point in an invisible part of the buffer when hiding
5785 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5786 (goto-char (point-max))
5788 (get-char-property (point) 'invisible
))))
5790 (ert-deftest test-org
/hide-block-toggle
()
5791 "Test `org-hide-block-toggle' specifications."
5792 ;; Error when not at a block.
5794 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5795 (org-hide-block-toggle 'off
)
5796 (get-char-property (line-end-position) 'invisible
)))
5799 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5800 (org-hide-block-toggle)
5801 (get-char-property (line-end-position) 'invisible
)))
5803 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5804 (org-hide-block-toggle)
5805 (get-char-property (line-end-position) 'invisible
)))
5806 ;; Show block unconditionally when optional argument is `off'.
5808 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5809 (org-hide-block-toggle)
5810 (org-hide-block-toggle 'off
)
5811 (get-char-property (line-end-position) 'invisible
)))
5813 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5814 (org-hide-block-toggle 'off
)
5815 (get-char-property (line-end-position) 'invisible
)))
5816 ;; Hide block unconditionally when optional argument is non-nil.
5818 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5819 (org-hide-block-toggle t
)
5820 (get-char-property (line-end-position) 'invisible
)))
5822 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5823 (org-hide-block-toggle)
5824 (org-hide-block-toggle t
)
5825 (get-char-property (line-end-position) 'invisible
)))
5826 ;; Do not hide block when called from final blank lines.
5828 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5829 (org-hide-block-toggle)
5830 (goto-char (point-min))
5831 (get-char-property (line-end-position) 'invisible
)))
5832 ;; Don't leave point in an invisible part of the buffer when hiding
5835 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5836 (org-hide-block-toggle)
5837 (get-char-property (point) 'invisible
))))
5839 (ert-deftest test-org
/hide-block-toggle-maybe
()
5840 "Test `org-hide-block-toggle-maybe' specifications."
5842 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5843 (org-hide-block-toggle-maybe)))
5845 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5847 (ert-deftest test-org
/set-tags
()
5848 "Test `org-set-tags' specifications."
5849 ;; Tags set via fast-tag-selection should be visible afterwards
5851 (let ((org-tag-alist '(("NEXT" . ?n
)))
5852 (org-fast-tag-selection-single-key t
))
5853 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5854 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5855 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5856 ;; Show only headlines
5858 ;; Set NEXT tag on current entry
5859 (org-set-tags nil nil
)
5860 ;; Move point to that NEXT tag
5861 (search-forward "NEXT") (backward-word)
5862 ;; And it should be visible (i.e. no overlays)
5863 (not (overlays-at (point))))))))
5865 (ert-deftest test-org
/show-set-visibility
()
5866 "Test `org-show-set-visibility' specifications."
5867 ;; Do not throw an error before first heading.
5869 (org-test-with-temp-text "Preamble\n* Headline"
5870 (org-show-set-visibility 'tree
)
5872 ;; Test all visibility spans, both on headline and in entry.
5873 (let ((list-visible-lines
5874 (lambda (state headerp
)
5875 (org-test-with-temp-text "* Grandmother (0)
5886 **** The other child (11)
5891 (search-forward (if headerp
"Self" "Match"))
5892 (org-show-set-visibility state
)
5893 (goto-char (point-min))
5894 (let (result (line 0))
5896 (unless (org-invisible-p2) (push line result
))
5899 (nreverse result
))))))
5900 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5901 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5902 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5903 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5904 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5905 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5906 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5907 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5908 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5909 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5910 (funcall list-visible-lines
'tree nil
)))
5911 (should (equal '(0 1 3 4 5 7 12 13)
5912 (funcall list-visible-lines
'canonical t
)))
5913 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5914 (funcall list-visible-lines
'canonical nil
))))
5915 ;; When point is hidden in a drawer or a block, make sure to make it
5918 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5919 (org-hide-block-toggle)
5920 (search-forward "Text")
5921 (org-show-set-visibility 'minimal
)
5922 (org-invisible-p2)))
5924 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5926 (search-forward "Text")
5927 (org-show-set-visibility 'minimal
)
5928 (org-invisible-p2)))
5930 (org-test-with-temp-text
5931 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5934 (org-hide-block-toggle)
5935 (search-forward "Text")
5936 (org-show-set-visibility 'minimal
)
5937 (org-invisible-p2))))
5942 ;;; test-org.el ends here