1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (progn (call-interactively 'comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (progn (call-interactively 'comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# Comment"
106 (progn (forward-line)
107 (let ((org-adapt-indentation t
))
108 (call-interactively 'comment-dwim
))
110 ;; Also recognize single # at column 0 as comments.
113 (org-test-with-temp-text "# Comment"
114 (progn (forward-line)
115 (call-interactively 'comment-dwim
)
117 ;; Region selected and only comments and blank lines within it:
118 ;; un-comment all commented lines.
120 (equal "Comment 1\n\nComment 2"
121 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
123 (transient-mark-mode 1)
124 (push-mark (point) t t
)
125 (goto-char (point-max))
126 (call-interactively 'comment-dwim
)
128 ;; Region selected without comments: comment all lines if
129 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
131 (equal "# Comment 1\n\n# Comment 2"
132 (org-test-with-temp-text "Comment 1\n\nComment 2"
134 (transient-mark-mode 1)
135 (push-mark (point) t t
)
136 (goto-char (point-max))
137 (let ((comment-empty-lines nil
))
138 (call-interactively 'comment-dwim
))
141 (equal "# Comment 1\n# \n# Comment 2"
142 (org-test-with-temp-text "Comment 1\n\nComment 2"
144 (transient-mark-mode 1)
145 (push-mark (point) t t
)
146 (goto-char (point-max))
147 (let ((comment-empty-lines t
))
148 (call-interactively 'comment-dwim
))
150 ;; In front of a keyword without region, insert a new comment.
152 (equal "# \n#+KEYWORD: value"
153 (org-test-with-temp-text "#+KEYWORD: value"
154 (progn (call-interactively 'comment-dwim
)
156 ;; In a source block, use appropriate syntax.
159 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively 'comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position) (point)))))
165 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
166 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
168 (transient-mark-mode 1)
169 (push-mark (point) t t
)
171 (let ((org-edit-src-content-indentation 2))
172 (call-interactively 'comment-dwim
))
177 ;;; Date and time analysis
179 (ert-deftest test-org
/org-read-date
()
180 "Test `org-read-date' specifications."
181 ;; Parse ISO date with abbreviated year and month.
182 (should (equal "2012-03-29 16:40"
183 (let ((org-time-was-given t
))
184 (org-read-date t nil
"12-3-29 16:40"))))
185 ;; Parse Europeans dates.
186 (should (equal "2012-03-29 16:40"
187 (let ((org-time-was-given t
))
188 (org-read-date t nil
"29.03.2012 16:40"))))
189 ;; Parse Europeans dates without year.
190 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
191 (let ((org-time-was-given t
))
192 (org-read-date t nil
"29.03. 16:40"))))
193 ;; Relative date applied to current time if there is single
194 ;; plus/minus, or to default date when there are two of them.
198 (cl-letf (((symbol-function 'current-time
)
200 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
203 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
207 (cl-letf (((symbol-function 'current-time
)
209 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (cl-letf (((symbol-function 'current-time
)
221 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
222 (let ((org-read-date-prefer-future t
))
223 (org-read-date t nil
"1")))))
227 (cl-letf (((symbol-function 'current-time
)
229 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
230 (let ((org-read-date-prefer-future t
))
231 (org-read-date t nil
"3-4")))))
235 (cl-letf (((symbol-function 'current-time
)
237 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
238 (let ((org-read-date-prefer-future nil
))
239 (org-read-date t nil
"3-4")))))
240 ;; When set to `org-read-date-prefer-future' is set to `time', read
241 ;; day is moved to tomorrow if specified hour is before current
242 ;; time. However, it only happens in no other part of the date is
247 (cl-letf (((symbol-function 'current-time
)
249 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
250 (let ((org-read-date-prefer-future 'time
))
251 (org-read-date t nil
"00:40" nil
)))))
255 (cl-letf (((symbol-function 'current-time
)
257 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
258 (let ((org-read-date-prefer-future 'time
))
259 (org-read-date t nil
"29 00:40" nil
)))))
260 ;; Caveat: `org-read-date-prefer-future' always refers to current
261 ;; time, not default time, when they differ.
265 (cl-letf (((symbol-function 'current-time
)
267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
268 (let ((org-read-date-prefer-future t
))
271 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
275 (cl-letf (((symbol-function 'current-time
)
277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
278 (let ((org-read-date-prefer-future t
))
281 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
283 (ert-deftest test-org
/org-parse-time-string
()
284 "Test `org-parse-time-string'."
285 (should (equal (org-parse-time-string "2012-03-29 16:40")
286 '(0 40 16 29 3 2012 nil nil nil
)))
287 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
288 '(0 40 16 29 3 2012 nil nil nil
)))
289 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
290 '(0 40 16 29 3 2012 nil nil nil
)))
291 (should (equal (org-parse-time-string "<2012-03-29>")
292 '(0 0 0 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>" t
)
294 '(0 nil nil
29 3 2012 nil nil nil
))))
296 (ert-deftest test-org
/closest-date
()
297 "Test `org-closest-date' specifications."
299 ;; Time stamps without a repeater are returned unchanged.
303 (calendar-gregorian-from-absolute
304 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
305 ;; Time stamps with a null repeater are returned unchanged.
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
311 ;; if PREFER is set to `past' always return a date before, or equal
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
323 ;; if PREFER is set to `future' always return a date before, or equal
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
333 (calendar-gregorian-from-absolute
334 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
335 ;; If PREFER is neither `past' nor `future', select closest date.
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
346 ;; Test "day" repeater.
349 (calendar-gregorian-from-absolute
350 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
355 ;; Test "month" repeater.
358 (calendar-gregorian-from-absolute
359 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
364 ;; Test "year" repeater.
367 (calendar-gregorian-from-absolute
368 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
371 (calendar-gregorian-from-absolute
372 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
374 (ert-deftest test-org
/deadline-close-p
()
375 "Test `org-deadline-close-p' specifications."
376 ;; Pretend that the current time is 2016-06-03 Fri 01:43
377 (cl-letf (((symbol-function 'current-time
)
378 (lambda () '(22353 6425 905205 644000))))
379 ;; Timestamps are close if they are within `ndays' of lead time.
380 (org-test-with-temp-text "* Heading"
381 (should (org-deadline-close-p "2016-06-03 Fri" 0))
382 (should (org-deadline-close-p "2016-06-02 Thu" 0))
383 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
384 (should (org-deadline-close-p "2016-06-04 Sat" 1))
385 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
386 ;; Read `ndays' from timestamp if argument not given.
387 (org-test-with-temp-text "* H"
388 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
389 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
390 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
391 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
392 ;; Prefer `ndays' argument over lead time in timestamp.
393 (org-test-with-temp-text "* H"
394 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
395 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
396 ;; Completed tasks are never close.
397 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
398 (org-test-with-temp-text "* TODO Heading"
399 (should (org-deadline-close-p "2016-06-03")))
400 (org-test-with-temp-text "* DONE Heading"
401 (should-not (org-deadline-close-p "2016-06-03"))))))
406 (ert-deftest test-org
/insert-property-drawer
()
407 "Test `org-insert-property-drawer' specifications."
408 ;; Error before first headline.
409 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
410 ;; Insert drawer right after headline if there is no planning line,
411 ;; or after it otherwise.
413 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
414 (org-test-with-temp-text "* H\nParagraph<point>"
415 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
418 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
419 (org-test-with-temp-text
420 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
421 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
423 ;; Indent inserted drawer.
425 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
426 (org-test-with-temp-text "* H\nParagraph<point>"
427 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
429 ;; Handle insertion at eob.
431 (equal "* H\n:PROPERTIES:\n:END:\n"
432 (org-test-with-temp-text "* H"
433 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
435 ;; Skip inlinetasks before point.
436 (when (featurep 'org-inlinetask
)
438 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
439 (org-test-with-temp-text
440 "* H\n*************** I\n*************** END\nP<point>"
441 (let ((org-adapt-indentation nil
)
442 (org-inlinetask-min-level 15))
443 (org-insert-property-drawer))
445 ;; Correctly set drawer in an inlinetask.
446 (when (featurep 'org-inlinetask
)
448 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
449 (org-test-with-temp-text
450 "* H\n*************** I\nP<point>\n*************** END"
451 (let ((org-adapt-indentation nil
)
452 (org-inlinetask-min-level 15))
453 (org-insert-property-drawer))
459 (ert-deftest test-org
/fill-paragraph
()
460 "Test `org-fill-paragraph' specifications."
461 ;; At an Org table, align it.
464 (org-test-with-temp-text "|a|"
468 (equal "#+name: table\n| a |\n"
469 (org-test-with-temp-text "#+name: table\n| a |\n"
472 ;; At a paragraph, preserve line breaks.
473 (org-test-with-temp-text "some \\\\\nlong\ntext"
474 (let ((fill-column 20))
476 (should (equal (buffer-string) "some \\\\\nlong text"))))
477 ;; Correctly fill a paragraph when point is at its very end.
480 (org-test-with-temp-text "A\nB"
481 (let ((fill-column 20))
482 (goto-char (point-max))
485 ;; Correctly fill the last paragraph of a greater element.
487 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
488 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
489 (let ((fill-column 8))
494 ;; Correctly fill an element in a narrowed buffer.
497 (org-test-with-temp-text "01234 6789"
498 (let ((fill-column 5))
499 (narrow-to-region 1 8)
502 ;; Handle `adaptive-fill-regexp' in paragraphs.
505 (org-test-with-temp-text "> a\n> b"
506 (let ((fill-column 5)
507 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
510 ;; Special case: Fill first paragraph when point is at an item or
511 ;; a plain-list or a footnote reference.
514 (org-test-with-temp-text "- A\n B"
515 (let ((fill-column 20))
520 (org-test-with-temp-text "[fn:1] A\nB"
521 (let ((fill-column 20))
524 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
525 (let ((fill-column 20))
527 (should (equal (buffer-string)
528 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
529 ;; Fill contents of `comment-block' elements.
532 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
533 (let ((fill-column 20))
537 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
538 ;; Fill `comment' elements.
541 (org-test-with-temp-text " # A\n # B"
542 (let ((fill-column 20))
545 ;; Do not mix consecutive comments when filling one of them.
547 (equal "# A B\n\n# C"
548 (org-test-with-temp-text "# A\n# B\n\n# C"
549 (let ((fill-column 20))
552 ;; Use commented empty lines as separators when filling comments.
554 (equal "# A B\n#\n# C"
555 (org-test-with-temp-text "# A\n# B\n#\n# C"
556 (let ((fill-column 20))
559 ;; Handle `adaptive-fill-regexp' in comments.
562 (org-test-with-temp-text "# > a\n# > b"
563 (let ((fill-column 20)
564 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
567 ;; Do nothing at affiliated keywords.
568 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
569 (let ((fill-column 20))
571 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
572 ;; Do not move point after table when filling a table.
574 (org-test-with-temp-text "| a | b |\n| c | d |\n"
579 (ert-deftest test-org
/auto-fill-function
()
580 "Test auto-filling features."
581 ;; Auto fill paragraph.
584 (org-test-with-temp-text "12345 7890"
585 (let ((fill-column 5))
587 (org-auto-fill-function)
589 ;; Auto fill first paragraph in an item.
591 (equal "- 12345\n 7890"
592 (org-test-with-temp-text "- 12345 7890"
593 (let ((fill-column 7))
595 (org-auto-fill-function)
597 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
599 (equal "> 12345\n 7890"
600 (org-test-with-temp-text "> 12345 7890"
601 (let ((fill-column 10)
602 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
603 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
605 (org-auto-fill-function)
608 (equal "> 12345\n> 12345\n> 7890"
609 (org-test-with-temp-text "> 12345\n> 12345 7890"
610 (let ((fill-column 10)
611 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
612 (goto-char (point-max))
613 (org-auto-fill-function)
616 (equal " 12345\n *12345\n *12345"
617 (org-test-with-temp-text " 12345\n *12345 12345"
618 (let ((fill-column 10)
619 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
620 (goto-char (point-max))
621 (org-auto-fill-function)
623 ;; Auto fill comments.
625 (equal " # 12345\n # 7890"
626 (org-test-with-temp-text " # 12345 7890"
627 (let ((fill-column 10))
629 (org-auto-fill-function)
631 ;; A hash within a line isn't a comment.
633 (equal "12345 # 7890\n# 1"
634 (org-test-with-temp-text "12345 # 7890 1"
635 (let ((fill-column 12))
637 (org-auto-fill-function)
639 ;; Correctly interpret empty prefix.
641 (equal "# a\n# b\nRegular\n# paragraph"
642 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
643 (let ((fill-column 12))
645 (org-auto-fill-function)
647 ;; Comment block: auto fill contents.
649 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
650 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
651 (let ((fill-column 5))
654 (org-auto-fill-function)
657 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
658 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
659 (let ((fill-column 5))
662 (org-auto-fill-function)
664 ;; Do not fill if a new item could be created.
667 (org-test-with-temp-text "12345 - 90"
668 (let ((fill-column 5))
670 (org-auto-fill-function)
672 ;; Do not fill if a line break could be introduced.
674 (equal "123\\\\\n7890"
675 (org-test-with-temp-text "123\\\\ 7890"
676 (let ((fill-column 6))
678 (org-auto-fill-function)
680 ;; Do not fill affiliated keywords.
682 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
683 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
684 (let ((fill-column 20))
686 (org-auto-fill-function)
693 (ert-deftest test-org
/indent-line
()
694 "Test `org-indent-line' specifications."
695 ;; Do not indent diary sexps, footnote definitions or headlines.
698 (org-test-with-temp-text "%%(org-calendar-holiday)"
700 (org-get-indentation))))
703 (org-test-with-temp-text "[fn:1] fn"
704 (let ((org-adapt-indentation t
)) (org-indent-line))
705 (org-get-indentation))))
708 (org-test-with-temp-text "* H"
710 (org-get-indentation))))
711 ;; Do not indent before first headline.
714 (org-test-with-temp-text ""
716 (org-get-indentation))))
717 ;; Indent according to headline level otherwise, unless
718 ;; `org-adapt-indentation' is nil.
721 (org-test-with-temp-text "* H\n<point>A"
722 (let ((org-adapt-indentation t
)) (org-indent-line))
723 (org-get-indentation))))
726 (org-test-with-temp-text "* H\n<point>\nA"
727 (let ((org-adapt-indentation t
)) (org-indent-line))
728 (org-get-indentation))))
731 (org-test-with-temp-text "* H\n<point>A"
732 (let ((org-adapt-indentation nil
)) (org-indent-line))
733 (org-get-indentation))))
734 ;; Indenting preserves point position.
736 (org-test-with-temp-text "* H\nA<point>B"
737 (let ((org-adapt-indentation t
)) (org-indent-line))
739 ;; Do not change indentation at an item or a LaTeX environment.
742 (org-test-with-temp-text "* H\n<point> - A"
743 (let ((org-adapt-indentation t
)) (org-indent-line))
744 (org-get-indentation))))
747 (org-test-with-temp-text
748 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
750 (org-get-indentation))))
751 ;; On blank lines at the end of a list, indent like last element
752 ;; within it if the line is still in the list. If the last element
753 ;; is an item, indent like its contents. Otherwise, indent like the
757 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
758 (let ((org-adapt-indentation t
)) (org-indent-line))
759 (org-get-indentation))))
762 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
763 (let ((org-adapt-indentation t
)) (org-indent-line))
764 (org-get-indentation))))
767 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
768 (let ((org-adapt-indentation t
)) (org-indent-line))
769 (org-get-indentation))))
772 (org-test-with-temp-text "* H\n- A\n - \n<point>"
773 (let ((org-adapt-indentation t
)) (org-indent-line))
774 (org-get-indentation))))
777 (org-test-with-temp-text
778 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
779 (let ((org-adapt-indentation t
)) (org-indent-line))
780 (org-get-indentation))))
783 (org-test-with-temp-text "- A\n B\n\n<point>"
784 (let ((org-adapt-indentation nil
)) (org-indent-line))
785 (org-get-indentation))))
786 ;; Likewise, on a blank line at the end of a footnote definition,
787 ;; indent at column 0 if line belongs to the definition. Otherwise,
788 ;; indent like the definition itself.
791 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
792 (goto-char (point-max))
793 (let ((org-adapt-indentation t
)) (org-indent-line))
794 (org-get-indentation))))
797 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
798 (goto-char (point-max))
799 (let ((org-adapt-indentation t
)) (org-indent-line))
800 (org-get-indentation))))
801 ;; After the end of the contents of a greater element, indent like
802 ;; the beginning of the element.
805 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
808 (org-get-indentation))))
809 ;; On blank lines after a paragraph, indent like its last non-empty
813 (org-test-with-temp-text " Paragraph\n\n<point>"
815 (org-get-indentation))))
816 ;; At the first line of an element, indent like previous element's
817 ;; first line, ignoring footnotes definitions and inline tasks, or
818 ;; according to parent.
821 (org-test-with-temp-text "A\n\n B\n\nC"
822 (goto-char (point-max))
824 (org-get-indentation))))
827 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
828 (goto-char (point-max))
830 (org-get-indentation))))
833 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
836 (org-get-indentation))))
837 ;; Within code part of a source block, use language major mode if
838 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
839 ;; according to line above.
842 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
844 (let ((org-src-tab-acts-natively t
)
845 (org-edit-src-content-indentation 0))
847 (org-get-indentation))))
850 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
852 (let ((org-src-tab-acts-natively nil
)
853 (org-edit-src-content-indentation 0))
855 (org-get-indentation))))
856 ;; Otherwise, indent like the first non-blank line above.
859 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
862 (org-get-indentation))))
863 ;; Align node properties according to `org-property-format'. Handle
864 ;; nicely empty values.
866 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
867 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
868 (let ((org-property-format "%-10s %s")) (org-indent-line))
871 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
872 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
873 (let ((org-property-format "%-10s %s")) (org-indent-line))
876 (ert-deftest test-org
/indent-region
()
877 "Test `org-indent-region' specifications."
881 (org-test-with-temp-text " A\nB\n C"
882 (org-indent-region (point-min) (point-max))
884 ;; Indent greater elements along with their contents.
886 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
887 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
888 (org-indent-region (point-min) (point-max))
890 ;; Ignore contents of verse blocks. Only indent block delimiters.
892 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
893 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
894 (org-indent-region (point-min) (point-max))
897 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
898 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
899 (org-indent-region (point-min) (point-max))
901 ;; Indent example blocks as a single block, unless indentation
902 ;; should be preserved. In this case only indent the block markers.
904 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
905 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
906 (org-indent-region (point-min) (point-max))
909 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
910 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
911 (org-indent-region (point-min) (point-max))
914 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
915 (org-test-with-temp-text
916 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
917 (org-indent-region (point-min) (point-max))
920 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
921 (org-test-with-temp-text
922 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
923 (let ((org-src-preserve-indentation t
))
924 (org-indent-region (point-min) (point-max)))
926 ;; Treat export blocks as a whole.
928 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
929 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
930 (org-indent-region (point-min) (point-max))
933 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
934 (org-test-with-temp-text
935 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
936 (org-indent-region (point-min) (point-max))
938 ;; Indent according to mode if `org-src-tab-acts-natively' is
939 ;; non-nil. Otherwise, do not indent code at all.
941 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
942 (org-test-with-temp-text
943 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
944 (let ((org-src-tab-acts-natively t
)
945 (org-edit-src-content-indentation 0))
946 (org-indent-region (point-min) (point-max)))
949 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
950 (org-test-with-temp-text
951 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
952 (let ((org-src-tab-acts-natively nil
)
953 (org-edit-src-content-indentation 0))
954 (org-indent-region (point-min) (point-max)))
956 ;; Align node properties according to `org-property-format'. Handle
957 ;; nicely empty values.
959 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
960 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
961 (let ((org-property-format "%-10s %s")
962 (org-adapt-indentation nil
))
963 (org-indent-region (point) (point-max)))
966 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
967 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
968 (let ((org-property-format "%-10s %s")
969 (org-adapt-indentation nil
))
970 (org-indent-region (point) (point-max)))
972 ;; Indent plain lists.
974 (equal "- A\n B\n - C\n\n D"
975 (org-test-with-temp-text "- A\n B\n - C\n\n D"
976 (org-indent-region (point-min) (point-max))
980 (org-test-with-temp-text " - A\n\n - B"
981 (org-indent-region (point-min) (point-max))
983 ;; Indent footnote definitions.
985 (equal "[fn:1] Definition\n\nDefinition"
986 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
987 (org-indent-region (point-min) (point-max))
989 ;; Special case: Start indenting on a blank line.
992 (org-test-with-temp-text "\n Paragraph"
993 (org-indent-region (point-min) (point-max))
1000 (ert-deftest test-org
/delete-indentation
()
1001 "Test `org-delete-indentation' specifications."
1003 (should (equal "foo bar"
1004 (org-test-with-temp-text
1006 (org-delete-indentation)
1008 ;; With optional argument.
1009 (should (equal "foo bar"
1010 (org-test-with-temp-text
1012 (org-delete-indentation t
)
1014 ;; At headline text should be appended to the headline text.
1016 (equal"* foo bar :tag:"
1017 (let (org-auto-align-tags)
1018 (org-test-with-temp-text
1019 "* foo :tag:\n bar<point>"
1020 (org-delete-indentation)
1023 (equal "* foo bar :tag:"
1024 (let (org-auto-align-tags)
1025 (org-test-with-temp-text
1026 "* foo <point>:tag:\n bar"
1027 (org-delete-indentation t
)
1028 (buffer-string))))))
1030 (ert-deftest test-org
/return
()
1031 "Test `org-return' specifications."
1034 (equal "Para\ngraph"
1035 (org-test-with-temp-text "Para<point>graph"
1038 ;; With optional argument, indent line.
1040 (equal " Para\n graph"
1041 (org-test-with-temp-text " Para<point>graph"
1044 ;; On a table, call `org-table-next-row'.
1046 (org-test-with-temp-text "| <point>a |\n| b |"
1048 (looking-at-p "b")))
1049 ;; Open link or timestamp under point when `org-return-follows-link'
1052 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1053 (let ((org-return-follows-link t
)
1054 (org-link-search-must-match-exact-headline nil
))
1056 (looking-at-p "<<target>>")))
1058 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1059 (let ((org-return-follows-link nil
)) (org-return))
1060 (looking-at-p "<<target>>")))
1062 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1063 (let ((org-return-follows-link t
)) (org-return))
1064 (looking-at-p "* b")))
1066 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1067 (let ((org-return-follows-link t
)
1068 (org-link-search-must-match-exact-headline nil
))
1070 (looking-at-p "<<target>>")))
1072 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1073 (let ((org-return-follows-link t
)
1074 (org-link-search-must-match-exact-headline nil
))
1076 (looking-at-p "<<target>>")))
1077 ;; When `org-return-follows-link' is non-nil, tolerate links and
1078 ;; timestamps in comments, node properties, etc.
1080 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1081 (let ((org-return-follows-link t
)
1082 (org-link-search-must-match-exact-headline nil
))
1084 (looking-at-p "<<target>>")))
1086 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1087 (let ((org-return-follows-link nil
)) (org-return))
1088 (looking-at-p "<<target>>")))
1090 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1091 (let ((org-return-follows-link t
)
1092 (org-link-search-must-match-exact-headline nil
))
1094 (looking-at-p "<<target>>")))
1095 ;; However, do not open link when point is in a table.
1097 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1098 (let ((org-return-follows-link t
)) (org-return))
1099 (looking-at-p "between")))
1100 ;; Special case: in a list, when indenting, do not break structure.
1103 (org-test-with-temp-text "- A <point>B"
1108 (org-test-with-temp-text "- A\n<point>- B"
1111 ;; On tags part of a headline, add a newline below it instead of
1114 (equal "* H :tag:\n"
1115 (org-test-with-temp-text "* H :<point>tag:"
1118 ;; Before headline text, add a newline below it instead of breaking
1121 (equal "* TODO H :tag:\n"
1122 (org-test-with-temp-text "* <point>TODO H :tag:"
1126 (equal "* TODO [#B] H :tag:\n"
1127 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1130 (should ;TODO are case-sensitive
1132 (org-test-with-temp-text "* <point>Todo"
1135 ;; At headline text, break headline text but preserve tags.
1137 (equal "* TODO [#B] foo :tag:\nbar"
1138 (let (org-auto-align-tags)
1139 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1142 ;; At bol of headline insert newline.
1145 (org-test-with-temp-text "<point>* h"
1148 ;; Refuse to leave invalid headline in buffer.
1151 (org-test-with-temp-text "*<point> h"
1155 (ert-deftest test-org
/meta-return
()
1156 "Test M-RET (`org-meta-return') specifications."
1157 ;; In a table field insert a row above.
1159 (org-test-with-temp-text "| a |"
1163 (looking-at "| |$")))
1164 ;; In a paragraph change current line into a header.
1166 (org-test-with-temp-text "a"
1169 (looking-at "\* a$")))
1170 ;; In an item insert an item, in this case above.
1172 (org-test-with-temp-text "- a"
1175 (looking-at "- $")))
1176 ;; In a drawer and item insert an item, in this case above.
1178 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1182 (looking-at "- $"))))
1184 (ert-deftest test-org
/insert-heading
()
1185 "Test `org-insert-heading' specifications."
1186 ;; In an empty buffer, insert a new headline.
1189 (org-test-with-temp-text ""
1190 (org-insert-heading)
1192 ;; At the beginning of a line, turn it into a headline.
1195 (org-test-with-temp-text "<point>P"
1196 (org-insert-heading)
1198 ;; In the middle of a line, split the line if allowed, otherwise,
1199 ;; insert the headline at its end.
1201 (equal "Para\n* graph"
1202 (org-test-with-temp-text "Para<point>graph"
1203 (let ((org-M-RET-may-split-line '((default . t
))))
1204 (org-insert-heading))
1207 (equal "Paragraph\n* "
1208 (org-test-with-temp-text "Para<point>graph"
1209 (let ((org-M-RET-may-split-line '((default . nil
))))
1210 (org-insert-heading))
1212 ;; At the beginning of a headline, create one above.
1215 (org-test-with-temp-text "* H"
1216 (org-insert-heading)
1218 ;; In the middle of a headline, split it if allowed.
1221 (org-test-with-temp-text "* H<point>1"
1222 (let ((org-M-RET-may-split-line '((headline . t
))))
1223 (org-insert-heading))
1227 (org-test-with-temp-text "* H<point>1"
1228 (let ((org-M-RET-may-split-line '((headline . nil
))))
1229 (org-insert-heading))
1231 ;; However, splitting cannot happen on TODO keywords, priorities or
1234 (equal "* TODO H1\n* \n"
1235 (org-test-with-temp-text "* TO<point>DO H1"
1236 (let ((org-M-RET-may-split-line '((headline . t
))))
1237 (org-insert-heading))
1240 (equal "* [#A] H1\n* \n"
1241 (org-test-with-temp-text "* [#<point>A] H1"
1242 (let ((org-M-RET-may-split-line '((headline . t
))))
1243 (org-insert-heading))
1246 (equal "* H1 :tag:\n* \n"
1247 (org-test-with-temp-text "* H1 :ta<point>g:"
1248 (let ((org-M-RET-may-split-line '((headline . t
))))
1249 (org-insert-heading))
1251 ;; New headline level depends on the level of the headline above.
1254 (org-test-with-temp-text "** H\n<point>P"
1255 (org-insert-heading)
1258 (equal "** H\nPara\n** graph"
1259 (org-test-with-temp-text "** H\nPara<point>graph"
1260 (let ((org-M-RET-may-split-line '((default . t
))))
1261 (org-insert-heading))
1265 (org-test-with-temp-text "** H"
1266 (org-insert-heading)
1268 ;; When called with one universal argument, insert a new headline at
1269 ;; the end of the current subtree, independently on the position of
1274 (org-test-with-temp-text "* H1\n** H2"
1275 (let ((org-insert-heading-respect-content nil
))
1276 (org-insert-heading '(4)))
1281 (org-test-with-temp-text "* H<point>1\n** H2"
1282 (let ((org-insert-heading-respect-content nil
))
1283 (org-insert-heading '(4)))
1285 ;; When called with two universal arguments, insert a new headline
1286 ;; at the end of the grandparent subtree.
1288 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1289 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1290 (let ((org-insert-heading-respect-content nil
))
1291 (org-insert-heading '(16)))
1293 ;; When optional TOP-LEVEL argument is non-nil, always insert
1294 ;; a level 1 heading.
1296 (equal "* H1\n** H2\n* \n"
1297 (org-test-with-temp-text "* H1\n** H2<point>"
1298 (org-insert-heading nil nil t
)
1301 (equal "* H1\n- item\n* "
1302 (org-test-with-temp-text "* H1\n- item<point>"
1303 (org-insert-heading nil nil t
)
1305 ;; Obey `org-blank-before-new-entry'.
1307 (equal "* H1\n\n* \n"
1308 (org-test-with-temp-text "* H1<point>"
1309 (let ((org-blank-before-new-entry '((heading . t
))))
1310 (org-insert-heading))
1314 (org-test-with-temp-text "* H1<point>"
1315 (let ((org-blank-before-new-entry '((heading . nil
))))
1316 (org-insert-heading))
1319 (equal "* H1\n* H2\n* \n"
1320 (org-test-with-temp-text "* H1\n* H2<point>"
1321 (let ((org-blank-before-new-entry '((heading . auto
))))
1322 (org-insert-heading))
1325 (equal "* H1\n\n* H2\n\n* \n"
1326 (org-test-with-temp-text "* H1\n\n* H2<point>"
1327 (let ((org-blank-before-new-entry '((heading . auto
))))
1328 (org-insert-heading))
1330 ;; Corner case: correctly insert a headline after an empty one.
1333 (org-test-with-temp-text "* <point>"
1334 (org-insert-heading)
1337 (org-test-with-temp-text "* <point>\n"
1338 (org-insert-heading)
1339 (looking-at-p "\n\\'")))
1340 ;; Do not insert spurious headlines when inserting a new headline.
1342 (equal "* H1\n* H2\n* \n"
1343 (org-test-with-temp-text "* H1\n* H2<point>\n"
1344 (org-insert-heading)
1346 ;; Preserve visibility at beginning of line. In particular, when
1347 ;; removing spurious blank lines, do not visually merge heading with
1348 ;; the line visible above.
1350 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1352 (let ((org-blank-before-new-entry '((heading . nil
))))
1353 (org-insert-heading '(4)))
1354 (invisible-p (line-end-position 0)))))
1356 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1357 "Test `org-insert-todo-heading-respect-content' specifications."
1358 ;; Create a TODO heading.
1360 (org-test-with-temp-text "* H1\n Body"
1361 (org-insert-todo-heading-respect-content)
1362 (nth 2 (org-heading-components))))
1363 ;; Add headline at the end of the first subtree
1367 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1368 (org-insert-todo-heading-respect-content)
1369 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1370 ;; In a list, do not create a new item.
1374 (org-test-with-temp-text "* H\n- an item\n- another one"
1375 (search-forward "an ")
1376 (org-insert-todo-heading-respect-content)
1377 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1379 (ert-deftest test-org
/clone-with-time-shift
()
1380 "Test `org-clone-subtree-with-time-shift'."
1381 ;; Raise an error before first heading.
1383 (org-test-with-temp-text ""
1384 (org-clone-subtree-with-time-shift 1)))
1385 ;; Raise an error on invalid number of clones.
1387 (org-test-with-temp-text "* Clone me"
1388 (org-clone-subtree-with-time-shift -
1)))
1389 ;; Clone non-repeating once.
1395 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1396 (org-clone-subtree-with-time-shift 1 "+2d")
1397 (replace-regexp-in-string
1398 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1400 ;; Clone repeating once.
1405 * H1\n<2015-06-25 +1w>
1407 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1408 (org-clone-subtree-with-time-shift 1 "+2d")
1409 (replace-regexp-in-string
1410 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1412 ;; Clone non-repeating zero times.
1417 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1418 (org-clone-subtree-with-time-shift 0 "+2d")
1419 (replace-regexp-in-string
1420 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1422 ;; Clone repeating "zero" times.
1426 * H1\n<2015-06-23 +1w>
1428 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1429 (org-clone-subtree-with-time-shift 0 "+2d")
1430 (replace-regexp-in-string
1431 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1433 ;; Clone with blank SHIFT argument.
1437 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1438 (org-clone-subtree-with-time-shift 1 "")
1439 (buffer-substring-no-properties (line-beginning-position 2)
1440 (line-end-position 2)))))
1441 ;; Find time stamps before point. If SHIFT is not specified, ask
1442 ;; for a time shift.
1446 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1447 (org-clone-subtree-with-time-shift 1 "+1d")
1448 (buffer-substring-no-properties (line-beginning-position 2)
1449 (line-end-position 2)))))
1453 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1454 (cl-letf (((symbol-function 'read-from-minibuffer
)
1455 (lambda (&rest args
) "+1d")))
1456 (org-clone-subtree-with-time-shift 1))
1457 (buffer-substring-no-properties (line-beginning-position 2)
1458 (line-end-position 2))))))
1461 ;;; Fixed-Width Areas
1463 (ert-deftest test-org
/toggle-fixed-width
()
1464 "Test `org-toggle-fixed-width' specifications."
1465 ;; No region: Toggle on fixed-width marker in paragraphs.
1468 (org-test-with-temp-text "A"
1469 (org-toggle-fixed-width)
1471 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1474 (org-test-with-temp-text ": A"
1475 (org-toggle-fixed-width)
1477 ;; No region: Toggle on marker in blank lines after elements or just
1478 ;; after a headline.
1481 (org-test-with-temp-text "* H\n"
1483 (org-toggle-fixed-width)
1486 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1487 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1488 (goto-char (point-max))
1489 (org-toggle-fixed-width)
1491 ;; No region: Toggle on marker in front of one line elements (e.g.,
1492 ;; headlines, clocks)
1494 (equal ": * Headline"
1495 (org-test-with-temp-text "* Headline"
1496 (org-toggle-fixed-width)
1499 (equal ": #+KEYWORD: value"
1500 (org-test-with-temp-text "#+KEYWORD: value"
1501 (org-toggle-fixed-width)
1503 ;; No region: error in other situations.
1505 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1507 (org-toggle-fixed-width)
1509 ;; No region: Indentation is preserved.
1512 (org-test-with-temp-text "- A\n B"
1514 (org-toggle-fixed-width)
1516 ;; Region: If it contains only fixed-width elements and blank lines,
1517 ;; toggle off fixed-width markup.
1520 (org-test-with-temp-text ": A\n\n: B"
1521 (transient-mark-mode 1)
1522 (push-mark (point) t t
)
1523 (goto-char (point-max))
1524 (org-toggle-fixed-width)
1526 ;; Region: If it contains anything else, toggle on fixed-width but
1527 ;; not on fixed-width areas.
1529 (equal ": A\n: \n: B\n: \n: C"
1530 (org-test-with-temp-text "A\n\n: B\n\nC"
1531 (transient-mark-mode 1)
1532 (push-mark (point) t t
)
1533 (goto-char (point-max))
1534 (org-toggle-fixed-width)
1536 ;; Region: Ignore blank lines at its end, unless it contains only
1540 (org-test-with-temp-text "A\n\n"
1541 (transient-mark-mode 1)
1542 (push-mark (point) t t
)
1543 (goto-char (point-max))
1544 (org-toggle-fixed-width)
1548 (org-test-with-temp-text "\n\n"
1549 (transient-mark-mode 1)
1550 (push-mark (point) t t
)
1551 (goto-char (point-max))
1552 (org-toggle-fixed-width)
1559 (ert-deftest test-org
/get-heading
()
1560 "Test `org-get-heading' specifications."
1561 ;; Return current heading, even if point is not on it.
1564 (org-test-with-temp-text "* H"
1565 (org-get-heading))))
1568 (org-test-with-temp-text "* H\nText<point>"
1569 (org-get-heading))))
1570 ;; Without any optional argument, return TODO keyword, priority
1571 ;; cookie, COMMENT keyword and tags.
1574 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1575 (org-get-heading))))
1578 (org-test-with-temp-text "* [#A] H"
1579 (org-get-heading))))
1582 (org-test-with-temp-text "* COMMENT H"
1583 (org-get-heading))))
1586 (org-test-with-temp-text "* H :tag:"
1587 (org-get-heading))))
1588 ;; With NO-TAGS argument, ignore tags.
1591 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1592 (org-get-heading t
))))
1595 (org-test-with-temp-text "* H :tag:"
1596 (org-get-heading t
))))
1597 ;; With NO-TODO, ignore TODO keyword.
1600 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1601 (org-get-heading nil t
))))
1604 (org-test-with-temp-text "* H :tag:"
1605 (org-get-heading nil t
))))
1606 ;; TODO keywords are case-sensitive.
1609 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1610 (org-get-heading nil t
))))
1611 ;; With NO-PRIORITY, ignore priority.
1614 (org-test-with-temp-text "* [#A] H"
1615 (org-get-heading nil nil t
))))
1618 (org-test-with-temp-text "* H"
1619 (org-get-heading nil nil t
))))
1622 (org-test-with-temp-text "* TODO [#A] H"
1623 (org-get-heading nil nil t
))))
1624 ;; With NO-COMMENT, ignore COMMENT keyword.
1627 (org-test-with-temp-text "* COMMENT H"
1628 (org-get-heading nil nil nil t
))))
1631 (org-test-with-temp-text "* H"
1632 (org-get-heading nil nil nil t
))))
1634 (equal "TODO [#A] H"
1635 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1636 (org-get-heading nil nil nil t
))))
1637 ;; On an empty headline, return value is consistent.
1638 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1639 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1640 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1641 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1643 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1645 (ert-deftest test-org
/in-commented-heading-p
()
1646 "Test `org-in-commented-heading-p' specifications."
1647 ;; Commented headline.
1649 (org-test-with-temp-text "* COMMENT Headline\nBody"
1650 (goto-char (point-max))
1651 (org-in-commented-heading-p)))
1652 ;; Commented ancestor.
1654 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1655 (goto-char (point-max))
1656 (org-in-commented-heading-p)))
1657 ;; Comment keyword is case-sensitive.
1659 (org-test-with-temp-text "* Comment Headline\nBody"
1660 (goto-char (point-max))
1661 (org-in-commented-heading-p)))
1662 ;; Keyword is standalone.
1664 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1665 (goto-char (point-max))
1666 (org-in-commented-heading-p)))
1667 ;; Optional argument.
1669 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1670 (goto-char (point-max))
1671 (org-in-commented-heading-p t
))))
1673 (ert-deftest test-org
/entry-blocked-p
()
1674 ;; Check other dependencies.
1676 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1677 (let ((org-enforce-todo-dependencies t
)
1679 '(org-block-todo-from-children-or-siblings-or-parent)))
1680 (org-entry-blocked-p))))
1682 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1683 (let ((org-enforce-todo-dependencies t
)
1685 '(org-block-todo-from-children-or-siblings-or-parent)))
1686 (org-entry-blocked-p))))
1687 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1690 (org-test-with-temp-text "* Blocked\n** TODO one"
1691 (let ((org-enforce-todo-dependencies t
)
1693 '(org-block-todo-from-children-or-siblings-or-parent)))
1694 (org-entry-blocked-p))))
1696 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1697 (let ((org-enforce-todo-dependencies t
)
1699 '(org-block-todo-from-children-or-siblings-or-parent)))
1700 (org-entry-blocked-p))))
1701 ;; Follow :ORDERED: specifications.
1703 (org-test-with-temp-text
1704 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1705 (let ((org-enforce-todo-dependencies t
)
1707 '(org-block-todo-from-children-or-siblings-or-parent)))
1708 (org-entry-blocked-p))))
1710 (org-test-with-temp-text
1711 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1712 (let ((org-enforce-todo-dependencies t
)
1714 '(org-block-todo-from-children-or-siblings-or-parent)))
1715 (org-entry-blocked-p)))))
1717 (ert-deftest test-org
/get-outline-path
()
1718 "Test `org-get-outline-path' specifications."
1719 ;; Top-level headlines have no outline path.
1721 (org-test-with-temp-text "* H"
1722 (org-get-outline-path)))
1723 ;; Otherwise, outline path is the path leading to the headline.
1726 (org-test-with-temp-text "* H\n** S<point>"
1727 (org-get-outline-path))))
1728 ;; Find path even when point is not on a headline.
1731 (org-test-with-temp-text "* H\n** S\nText<point>"
1732 (org-get-outline-path))))
1733 ;; TODO keywords, tags and statistics cookies are ignored.
1736 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1737 (org-get-outline-path))))
1738 ;; Links are replaced with their description or their path.
1741 (org-test-with-temp-text
1742 "* [[http://orgmode.org][Org]]\n** S<point>"
1743 (org-get-outline-path))))
1745 (equal '("http://orgmode.org")
1746 (org-test-with-temp-text
1747 "* [[http://orgmode.org]]\n** S<point>"
1748 (org-get-outline-path))))
1749 ;; When WITH-SELF is non-nil, include current heading.
1752 (org-test-with-temp-text "* H"
1753 (org-get-outline-path t
))))
1756 (org-test-with-temp-text "* H\n** S\nText<point>"
1757 (org-get-outline-path t
))))
1758 ;; Using cache is transparent to the user.
1761 (org-test-with-temp-text "* H\n** S<point>"
1762 (setq org-outline-path-cache nil
)
1763 (org-get-outline-path nil t
))))
1764 ;; Do not corrupt cache when finding outline path in distant part of
1768 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1769 (setq org-outline-path-cache nil
)
1770 (org-get-outline-path nil t
)
1771 (search-forward "S2")
1772 (org-get-outline-path nil t
))))
1773 ;; Do not choke on empty headlines.
1775 (org-test-with-temp-text "* H\n** <point>"
1776 (org-get-outline-path)))
1778 (org-test-with-temp-text "* \n** H<point>"
1779 (org-get-outline-path))))
1781 (ert-deftest test-org
/format-outline-path
()
1782 "Test `org-format-outline-path' specifications."
1784 (string= (org-format-outline-path (list "one" "two" "three"))
1788 (string= (org-format-outline-path '())
1791 (string= (org-format-outline-path '(nil))
1793 ;; Empty path and prefix.
1795 (string= (org-format-outline-path '() nil
">>")
1797 ;; Trailing whitespace in headings.
1799 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1801 ;; Non-default prefix and separators.
1803 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1804 ">>|one|two|three"))
1807 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1809 ;; Give a very narrow width.
1811 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1813 ;; Give a prefix that extends beyond the width.
1815 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1819 (ert-deftest test-org
/map-entries
()
1820 "Test `org-map-entries' specifications."
1824 (org-test-with-temp-text "* Level 1\n** Level 2"
1825 (org-map-entries #'point
))))
1829 (org-test-with-temp-text "* Level 1\n** Level 2"
1830 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1833 (org-test-with-temp-text "* Level 1\n** Level 2"
1834 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1838 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1839 (org-map-entries #'point
"yes"))))
1842 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1843 (org-map-entries #'point
"+yes-a"))))
1846 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1847 (org-map-entries #'point
"{yes?}"))))
1851 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1852 (org-map-entries #'point
"PRIORITY=\"A\""))))
1856 (org-test-with-temp-text "
1858 SCHEDULED: <2012-03-29 thu.>
1860 SCHEDULED: <2014-03-04 tue.>"
1861 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1864 (org-test-with-temp-text "
1866 SCHEDULED: <2012-03-29 thu.>
1868 SCHEDULED: <2014-03-04 tue.>"
1869 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1870 ;; Regular property match.
1873 (org-test-with-temp-text "
1882 (org-map-entries #'point
"TEST=1"))))
1883 ;; Multiple criteria.
1886 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1887 (let (org-odd-levels-only
1888 (org-use-tag-inheritance nil
))
1889 (org-map-entries #'point
"yes+LEVEL=1")))))
1893 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1894 (let (org-odd-levels-only)
1895 (org-map-entries #'point
"LEVEL=2|no")))))
1898 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1899 (let (org-odd-levels-only)
1900 (org-map-entries #'point
"yes|no")))))
1904 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1905 (let (org-odd-levels-only)
1906 (org-map-entries #'point
"yes&no"))))))
1908 (ert-deftest test-org
/edit-headline
()
1909 "Test `org-edit-headline' specifications."
1912 (org-test-with-temp-text "* A"
1913 (org-edit-headline "B")
1915 ;; Handle empty headings.
1918 (org-test-with-temp-text "* A"
1919 (org-edit-headline "")
1923 (org-test-with-temp-text "* "
1924 (org-edit-headline "A")
1926 ;; Handle TODO keywords and priority cookies.
1929 (org-test-with-temp-text "* TODO A"
1930 (org-edit-headline "B")
1934 (org-test-with-temp-text "* [#A] A"
1935 (org-edit-headline "B")
1938 (equal "* TODO [#A] B"
1939 (org-test-with-temp-text "* TODO [#A] A"
1940 (org-edit-headline "B")
1944 (org-test-with-temp-text "* A :tag:"
1945 (let ((org-tags-column 4)) (org-edit-headline "B"))
1952 (ert-deftest test-org
/set-regexps-and-options
()
1953 "Test `org-set-regexps-and-options' specifications."
1957 (let ((org-tag-alist '(("A")))
1958 (org-tag-persistent-alist nil
))
1959 (org-test-with-temp-text ""
1961 org-current-tag-alist
))))
1964 (let ((org-tag-alist '(("A")))
1965 (org-tag-persistent-alist nil
))
1966 (org-test-with-temp-text "#+TAGS: B"
1968 org-current-tag-alist
))))
1970 (equal '(("C") ("B"))
1971 (let ((org-tag-alist '(("A")))
1972 (org-tag-persistent-alist '(("C"))))
1973 (org-test-with-temp-text "#+TAGS: B"
1975 org-current-tag-alist
))))
1978 (let ((org-tag-alist '(("A")))
1979 (org-tag-persistent-alist '(("C"))))
1980 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1982 org-current-tag-alist
))))
1984 (equal '(("A" . ?a
) ("B") ("C"))
1985 (let ((org-tag-persistant-alist nil
))
1986 (org-test-with-temp-text "#+TAGS: A(a) B C"
1988 org-current-tag-alist
))))
1990 (equal '(("A") (:newline
) ("B"))
1991 (let ((org-tag-persistent-alist nil
))
1992 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1994 org-current-tag-alist
))))
1996 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1997 (let ((org-tag-persistent-alist nil
))
1998 (org-test-with-temp-text "#+TAGS: { A B } C"
2000 org-current-tag-alist
))))
2002 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2003 (let ((org-tag-persistent-alist nil
))
2004 (org-test-with-temp-text "#+TAGS: { A : B C }"
2006 org-current-tag-alist
))))
2008 (equal '(("A" "B" "C"))
2009 (let ((org-tag-persistent-alist nil
))
2010 (org-test-with-temp-text "#+TAGS: { A : B C }"
2012 org-tag-groups-alist
))))
2014 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2015 (let ((org-tag-persistent-alist nil
))
2016 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2018 org-current-tag-alist
))))
2020 (equal '(("A" "B" "C"))
2021 (let ((org-tag-persistent-alist nil
))
2022 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2024 org-tag-groups-alist
))))
2025 ;; FILETAGS keyword.
2027 (equal '("A" "B" "C")
2028 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2031 ;; PROPERTY keyword. Property names are case-insensitive.
2034 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2036 (cdr (assoc "var" org-file-properties
)))))
2040 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2042 (cdr (assoc "var" org-file-properties
)))))
2046 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2048 (cdr (assoc "var" org-file-properties
)))))
2052 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2054 org-archive-location
)))
2055 ;; CATEGORY keyword.
2058 (org-test-with-temp-text "#+CATEGORY: test"
2063 (org-test-with-temp-text "#+CATEGORY: test"
2065 (cdr (assoc "CATEGORY" org-file-properties
)))))
2068 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2069 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2071 org-columns-default-format
)))
2072 ;; CONSTANTS keyword. Constants names are case sensitive.
2074 (equal '("299792458." "3.14")
2075 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2078 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2082 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2084 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2087 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2089 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2094 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2096 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2098 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2102 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2104 (list org-highest-priority org-lowest-priority org-default-priority
))))
2108 (org-test-with-temp-text "#+PRIORITIES: X Z"
2110 (list org-highest-priority org-lowest-priority org-default-priority
))))
2114 (org-test-with-temp-text "#+STARTUP: fold odd"
2116 (list org-startup-folded org-odd-levels-only
))))
2119 (equal '(("A" "B") ("C"))
2120 (org-test-with-temp-text "#+TODO: A B | C"
2122 (list org-not-done-keywords org-done-keywords
))))
2124 (equal '(("A" "C") ("B" "D"))
2125 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2127 (list org-not-done-keywords org-done-keywords
))))
2129 (equal '(("A" "B") ("C"))
2130 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2132 (list org-not-done-keywords org-done-keywords
))))
2134 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2135 (org-test-with-temp-text "#+TODO: A(a)"
2137 org-todo-key-alist
)))
2139 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2140 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2142 org-todo-log-states
)))
2143 ;; Enter SETUPFILE keyword.
2146 (org-test-with-temp-text
2147 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2149 (cdr (assoc "a" org-file-properties
))))))
2157 (ert-deftest test-org
/coderef
()
2158 "Test coderef links specifications."
2160 (org-test-with-temp-text "
2161 #+BEGIN_SRC emacs-lisp
2166 (looking-at "(ref:sc)")))
2167 ;; Find coderef even with alternate label format.
2169 (org-test-with-temp-text "
2170 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2175 (looking-at "{ref:sc}"))))
2179 (ert-deftest test-org
/custom-id
()
2180 "Test custom ID links specifications."
2182 (org-test-with-temp-text
2183 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2185 (looking-at-p "\\* H1")))
2186 ;; Throw an error on false positives.
2188 (org-test-with-temp-text
2189 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2191 (looking-at-p "\\* H1"))))
2195 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2196 ;; a named element (#+name: text) and to headlines (* Text).
2198 (ert-deftest test-org
/fuzzy-links
()
2199 "Test fuzzy links specifications."
2200 ;; Fuzzy link goes in priority to a matching target.
2202 (org-test-with-temp-text
2203 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2204 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2205 (looking-at "<<Test>>")))
2206 ;; Then fuzzy link points to an element with a given name.
2208 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2209 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2210 (looking-at "#\\+NAME: Test")))
2211 ;; A target still lead to a matching headline otherwise.
2213 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2214 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2215 (looking-at "\\* Head2")))
2216 ;; With a leading star in link, enforce heading match.
2218 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2219 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2220 (looking-at "\\* Test")))
2221 ;; With a leading star in link, enforce exact heading match, even
2222 ;; with `org-link-search-must-match-exact-headline' set to nil.
2224 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2225 (let ((org-link-search-must-match-exact-headline nil
))
2226 (org-open-at-point))))
2227 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2229 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2230 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2231 (looking-at "\\* Test")))
2233 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2234 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2235 (looking-at "\\* Test")))
2236 ;; Heading match should not care about spaces, cookies, TODO
2237 ;; keywords, priorities, and tags. However, TODO keywords are
2241 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2242 (org-test-with-temp-text
2243 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2244 (let ((org-link-search-must-match-exact-headline nil
)
2245 (org-todo-regexp "TODO"))
2246 (org-open-at-point))
2247 (looking-at (regexp-quote first-line
)))))
2249 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2250 (let ((org-link-search-must-match-exact-headline nil
)
2251 (org-todo-regexp "TODO"))
2252 (org-open-at-point))))
2253 ;; Heading match should still be exact.
2255 (org-test-with-temp-text "
2256 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2259 (let ((org-link-search-must-match-exact-headline nil
)
2260 (org-todo-regexp "TODO"))
2261 (org-open-at-point))))
2263 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2264 (let ((org-link-search-must-match-exact-headline nil
)
2265 (org-todo-regexp "TODO"))
2266 (org-open-at-point))
2267 (looking-at-p (regexp-quote "** Test 1 2"))))
2268 ;; Heading match ignores COMMENT keyword.
2270 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2272 (looking-at "\\* COMMENT Test")))
2274 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2276 (looking-at "\\* TODO COMMENT Test")))
2277 ;; Correctly un-hexify fuzzy links.
2279 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2283 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2286 ;; Match search strings containing newline characters.
2288 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2289 (let ((file (buffer-file-name)))
2290 (goto-char (point-max))
2291 (insert (format "[[file:%s::line1 line2]]" file
))
2293 (let ((org-link-search-must-match-exact-headline nil
))
2294 (org-open-at-point))
2295 (looking-at-p "line1")))))
2299 (ert-deftest test-org
/org-link-escape-ascii-character
()
2300 "Escape an ascii character."
2304 (org-link-escape "["))))
2306 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2307 "Escape an ascii control character."
2311 (org-link-escape "\t"))))
2313 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2314 "Escape an unicode multibyte character."
2318 (org-link-escape "€"))))
2320 (ert-deftest test-org
/org-link-escape-custom-table
()
2321 "Escape string with custom character table."
2325 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2327 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2328 "Escape string with custom table merged with default table."
2331 "%5BF%6F%6F%3A%42ar%0A%5D"
2332 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2334 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2335 "Unescape an ascii character."
2339 (org-link-unescape "%5B"))))
2341 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2342 "Unescpae an ascii control character."
2346 (org-link-unescape "%0A"))))
2348 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2349 "Unescape unicode multibyte character."
2353 (org-link-unescape "%E2%82%AC"))))
2355 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2356 "Unescape old style percent escaped character."
2359 "à âçèéêîôùû"
2360 (decode-coding-string
2361 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2363 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2364 "Escape and unescape a URL that includes an escaped char.
2365 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2368 "http://some.host.com/form?&id=blah%2Bblah25"
2370 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2374 (ert-deftest test-org
/open-at-point-in-keyword
()
2375 "Does `org-open-at-point' open link in a keyword line?"
2377 (org-test-with-temp-text
2378 "<<top>>\n#+KEYWORD: <point>[[top]]"
2379 (org-open-at-point) t
)))
2381 (ert-deftest test-org
/open-at-point-in-property
()
2382 "Does `org-open-at-point' open link in property drawer?"
2384 (org-test-with-temp-text
2387 :URL: <point>[[*Headline]]
2389 (org-open-at-point) t
)))
2391 (ert-deftest test-org
/open-at-point-in-comment
()
2392 "Does `org-open-at-point' open link in a commented line?"
2394 (org-test-with-temp-text
2395 "<<top>>\n# <point>[[top]]"
2396 (org-open-at-point) t
)))
2398 (ert-deftest test-org
/open-at-point
/inline-image
()
2399 "Test `org-open-at-point' on nested links."
2401 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2405 (ert-deftest test-org
/open-at-point
/radio-target
()
2406 "Test `org-open-at-point' on radio targets."
2408 (org-test-with-temp-text "<<<target>>> <point>target"
2409 (org-update-radio-target-regexp)
2411 (eq (org-element-type (org-element-context)) 'radio-target
))))
2415 (ert-deftest test-org
/store-link
()
2416 "Test `org-store-link' specifications."
2417 ;; On a headline, link to that headline. Use heading as the
2418 ;; description of the link.
2420 (let (org-store-link-props org-stored-links
)
2421 (org-test-with-temp-text-in-file "* H1"
2422 (let ((file (buffer-file-name)))
2423 (equal (format "[[file:%s::*H1][H1]]" file
)
2424 (org-store-link nil
))))))
2425 ;; On a headline, remove any link from description.
2427 (let (org-store-link-props org-stored-links
)
2428 (org-test-with-temp-text-in-file "* [[#l][d]]"
2429 (let ((file (buffer-file-name)))
2430 (equal (format "[[file:%s::*%s][d]]"
2432 (org-link-escape "[[#l][d]]"))
2433 (org-store-link nil
))))))
2435 (let (org-store-link-props org-stored-links
)
2436 (org-test-with-temp-text-in-file "* [[l]]"
2437 (let ((file (buffer-file-name)))
2438 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2439 (org-store-link nil
))))))
2441 (let (org-store-link-props org-stored-links
)
2442 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2443 (let ((file (buffer-file-name)))
2444 (equal (format "[[file:%s::*%s][d1 d2]]"
2446 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2447 (org-store-link nil
))))))
2448 ;; On a named element, link to that element.
2450 (let (org-store-link-props org-stored-links
)
2451 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2452 (let ((file (buffer-file-name)))
2453 (equal (format "[[file:%s::foo][foo]]" file
)
2454 (org-store-link nil
)))))))
2459 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2460 "Ensure properties accumulate in subtree drawers."
2461 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2462 (org-babel-next-src-block)
2463 (should (equal '(2 1) (org-babel-execute-src-block)))))
2465 (ert-deftest test-org
/custom-properties
()
2466 "Test custom properties specifications."
2469 (let ((org-custom-properties '("FOO")))
2470 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2471 (org-toggle-custom-properties-visibility)
2472 (org-invisible-p2))))
2473 ;; Properties are case-insensitive.
2475 (let ((org-custom-properties '("FOO")))
2476 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2477 (org-toggle-custom-properties-visibility)
2478 (org-invisible-p2))))
2480 (let ((org-custom-properties '("foo")))
2481 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2482 (org-toggle-custom-properties-visibility)
2483 (org-invisible-p2))))
2484 ;; Multiple custom properties in the same drawer.
2486 (let ((org-custom-properties '("FOO" "BAR")))
2487 (org-test-with-temp-text
2488 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2489 (org-toggle-custom-properties-visibility)
2490 (and (org-invisible-p2)
2491 (not (progn (forward-line) (org-invisible-p2)))
2492 (progn (forward-line) (org-invisible-p2))))))
2493 ;; Hide custom properties with an empty value.
2495 (let ((org-custom-properties '("FOO")))
2496 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2497 (org-toggle-custom-properties-visibility)
2498 (org-invisible-p2))))
2499 ;; Do not hide fake properties.
2501 (let ((org-custom-properties '("FOO")))
2502 (org-test-with-temp-text ":FOO: val\n"
2503 (org-toggle-custom-properties-visibility)
2504 (org-invisible-p2))))
2506 (let ((org-custom-properties '("A")))
2507 (org-test-with-temp-text
2508 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2509 (org-toggle-custom-properties-visibility)
2510 (org-invisible-p2)))))
2516 (ert-deftest test-org
/mark-subtree
()
2517 "Test `org-mark-subtree' specifications."
2518 ;; Error when point is before first headline.
2520 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2521 (progn (transient-mark-mode 1)
2522 (org-mark-subtree))))
2523 ;; Without argument, mark current subtree.
2527 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2528 (progn (transient-mark-mode 1)
2531 (list (region-beginning) (region-end))))))
2532 ;; With an argument, move ARG up.
2536 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2537 (progn (transient-mark-mode 1)
2539 (org-mark-subtree 1)
2540 (list (region-beginning) (region-end))))))
2541 ;; Do not get fooled by inlinetasks.
2542 (when (featurep 'org-inlinetask
)
2545 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2546 (progn (transient-mark-mode 1)
2548 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2549 (region-beginning)))))))
2555 (ert-deftest test-org
/in-regexp
()
2556 "Test `org-in-regexp' specifications."
2559 (org-test-with-temp-text "xx ab<point>c xx"
2560 (org-in-regexp "abc")))
2562 (org-test-with-temp-text "xx abc <point>xx"
2563 (org-in-regexp "abc")))
2564 ;; Return non-nil even with multiple matching regexps in the same
2567 (org-test-with-temp-text "abc xx ab<point>c xx"
2568 (org-in-regexp "abc")))
2569 ;; With optional argument NLINES, check extra lines around point.
2571 (org-test-with-temp-text "A\nB<point>\nC"
2572 (org-in-regexp "A\nB\nC")))
2574 (org-test-with-temp-text "A\nB<point>\nC"
2575 (org-in-regexp "A\nB\nC" 1)))
2577 (org-test-with-temp-text "A\nB\nC<point>"
2578 (org-in-regexp "A\nB\nC" 1)))
2579 ;; When optional argument VISUALLY is non-nil, return nil if at
2580 ;; regexp boundaries.
2582 (org-test-with-temp-text "xx abc<point> xx"
2583 (org-in-regexp "abc")))
2585 (org-test-with-temp-text "xx abc<point> xx"
2586 (org-in-regexp "abc" nil t
))))
2591 (ert-deftest test-org
/end-of-meta-data
()
2592 "Test `org-end-of-meta-data' specifications."
2593 ;; Skip planning line.
2595 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2596 (org-end-of-meta-data)
2598 ;; Skip properties drawer.
2600 (org-test-with-temp-text
2601 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2602 (org-end-of-meta-data)
2606 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2607 (org-end-of-meta-data)
2609 ;; Nothing to skip, go to first line.
2611 (org-test-with-temp-text "* Headline\nContents"
2612 (org-end-of-meta-data)
2613 (looking-at "Contents")))
2614 ;; With option argument, skip empty lines, regular drawers and
2617 (org-test-with-temp-text "* Headline\n\nContents"
2618 (org-end-of-meta-data t
)
2619 (looking-at "Contents")))
2621 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2622 (org-end-of-meta-data t
)
2623 (looking-at "Contents")))
2625 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2626 (org-end-of-meta-data t
)
2627 (looking-at "Contents")))
2628 ;; Special case: do not skip incomplete drawers.
2630 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2631 (org-end-of-meta-data t
)
2632 (looking-at ":LOGBOOK:")))
2633 ;; Special case: Be careful about consecutive headlines.
2635 (org-test-with-temp-text "* H1\n*H2\nContents"
2636 (org-end-of-meta-data t
)
2637 (looking-at "Contents"))))
2639 (ert-deftest test-org
/beginning-of-line
()
2640 "Test `org-beginning-of-line' specifications."
2641 ;; Move to beginning of line. If current line in invisible, move to
2642 ;; beginning of visible line instead.
2644 (org-test-with-temp-text "Some text\nSome other text<point>"
2645 (org-beginning-of-line)
2648 (org-test-with-temp-text "* H1\n** H2<point>"
2650 (org-beginning-of-line)
2651 (= (line-beginning-position) 1)))
2652 ;; With `visual-line-mode' active, move to beginning of visual line.
2654 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2656 (dotimes (i 1000) (insert "very "))
2657 (org-beginning-of-line)
2659 ;; In a wide headline, with `visual-line-mode', prefer going to the
2660 ;; beginning of a visual line than to the logical beginning of line,
2661 ;; even if special movement is active.
2663 (org-test-with-temp-text "* A <point>long headline"
2665 (dotimes (i 1000) (insert "very "))
2666 (goto-char (point-max))
2667 (org-beginning-of-line)
2670 (org-test-with-temp-text "* A <point>long headline"
2672 (dotimes (i 1000) (insert "very "))
2673 (goto-char (point-max))
2674 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2676 ;; At an headline with special movement, first move at beginning of
2677 ;; title, then at the beginning of line, rinse, repeat.
2679 (org-test-with-temp-text "* TODO Headline<point>"
2680 (let ((org-special-ctrl-a/e t
))
2681 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2682 (progn (org-beginning-of-line) (bolp))
2683 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2685 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2686 (let ((org-special-ctrl-a/e t
))
2687 (org-beginning-of-line)
2688 (looking-at "Headline"))))
2690 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2691 (let ((org-special-ctrl-a/e
'(t . nil
)))
2692 (org-beginning-of-line)
2693 (looking-at "Headline"))))
2695 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2696 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2697 (org-beginning-of-line)
2698 (looking-at "Headline"))))
2699 ;; At an headline with reversed movement, first move to beginning of
2700 ;; line, then to the beginning of title.
2702 (org-test-with-temp-text "* TODO Headline<point>"
2703 (let ((org-special-ctrl-a/e
'reversed
)
2704 (this-command last-command
))
2705 (and (progn (org-beginning-of-line) (bolp))
2706 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2708 (org-test-with-temp-text "* TODO Headline<point>"
2709 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2710 (this-command last-command
))
2711 (and (progn (org-beginning-of-line) (bolp))
2712 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2714 (org-test-with-temp-text "* TODO Headline<point>"
2715 (let ((org-special-ctrl-a/e
'(t . nil
))
2716 (this-command last-command
))
2717 (and (progn (org-beginning-of-line) (bolp))
2718 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2719 ;; At an item with special movement, first move after to beginning
2720 ;; of title, then to the beginning of line, rinse, repeat.
2722 (org-test-with-temp-text "- [ ] Item<point>"
2723 (let ((org-special-ctrl-a/e t
))
2724 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2725 (progn (org-beginning-of-line) (bolp))
2726 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2727 ;; At an item with reversed movement, first move to beginning of
2728 ;; line, then to the beginning of title.
2730 (org-test-with-temp-text "- [X] Item<point>"
2731 (let ((org-special-ctrl-a/e
'reversed
)
2732 (this-command last-command
))
2733 (and (progn (org-beginning-of-line) (bolp))
2734 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2735 ;; Leave point before invisible characters at column 0.
2737 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2738 (let ((org-special-ctrl-a/e nil
))
2739 (org-beginning-of-line)
2742 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2743 (let ((org-special-ctrl-a/e t
))
2744 (org-beginning-of-line)
2747 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2749 (org-beginning-of-line)
2751 ;; Special case: Do not error when the buffer contains only a single
2754 (org-test-with-temp-text "*<point>"
2755 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2757 (org-test-with-temp-text "*<point>"
2758 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2760 (ert-deftest test-org
/end-of-line
()
2761 "Test `org-end-of-line' specifications."
2764 (org-test-with-temp-text "Some text\nSome other text"
2767 ;; With `visual-line-mode' active, move to end of visible line.
2768 ;; However, never go past ellipsis.
2770 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2772 (dotimes (i 1000) (insert "very "))
2773 (goto-char (point-min))
2777 (org-test-with-temp-text "* A short headline\nSome contents"
2782 ;; In a wide headline, with `visual-line-mode', prefer going to end
2783 ;; of visible line if tags, or end of line, are farther.
2785 (org-test-with-temp-text "* A <point>long headline"
2787 (dotimes (i 1000) (insert "very "))
2788 (goto-char (point-min))
2792 (org-test-with-temp-text "* A <point>long headline :tag:"
2794 (dotimes (i 1000) (insert "very "))
2795 (goto-char (point-min))
2798 ;; At an headline without special movement, go to end of line.
2799 ;; However, never go past ellipsis.
2801 (org-test-with-temp-text "* Headline2b :tag:\n"
2802 (let ((org-special-ctrl-a/e nil
))
2803 (and (progn (org-end-of-line) (eolp))
2804 (progn (org-end-of-line) (eolp))))))
2806 (org-test-with-temp-text "* Headline2b :tag:\n"
2807 (let ((org-special-ctrl-a/e
'(t . nil
)))
2808 (and (progn (org-end-of-line) (eolp))
2809 (progn (org-end-of-line) (eolp))))))
2811 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2813 (let ((org-special-ctrl-a/e nil
))
2815 (= 1 (line-beginning-position)))))
2816 ;; At an headline with special movement, first move before tags,
2817 ;; then at the end of line, rinse, repeat. However, never go past
2820 (org-test-with-temp-text "* Headline1 :tag:\n"
2821 (let ((org-special-ctrl-a/e t
))
2822 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2823 (progn (org-end-of-line) (eolp))
2824 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2826 (org-test-with-temp-text "* Headline1 :tag:\n"
2827 (let ((org-special-ctrl-a/e
'(nil . t
)))
2828 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2829 (progn (org-end-of-line) (eolp))
2830 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2832 (org-test-with-temp-text "* Headline1 :tag:\n"
2833 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2834 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2835 (progn (org-end-of-line) (eolp))
2836 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2838 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2840 (let ((org-special-ctrl-a/e t
))
2843 (= 1 (line-beginning-position)))))
2844 ;; At an headline, with reversed movement, first go to end of line,
2845 ;; then before tags. However, never go past ellipsis.
2847 (org-test-with-temp-text "* Headline3 :tag:\n"
2848 (let ((org-special-ctrl-a/e
'reversed
)
2849 (this-command last-command
))
2850 (and (progn (org-end-of-line) (eolp))
2851 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2853 (org-test-with-temp-text "* Headline3 :tag:\n"
2854 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2855 (this-command last-command
))
2856 (and (progn (org-end-of-line) (eolp))
2857 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2859 (org-test-with-temp-text "* Headline3 :tag:\n"
2860 (let ((org-special-ctrl-a/e
'(nil . t
))
2861 (this-command last-command
))
2862 (and (progn (org-end-of-line) (eolp))
2863 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2865 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2867 (let ((org-special-ctrl-a/e
'reversed
))
2869 (= 1 (line-beginning-position)))))
2870 ;; At a block without hidden contents.
2872 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2873 (progn (org-end-of-line) (eolp))))
2874 ;; At a block with hidden contents.
2876 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2877 (let ((org-special-ctrl-a/e t
))
2878 (org-hide-block-toggle)
2881 ;; Get past invisible characters at the end of line.
2883 (org-test-with-temp-text "[[http://orgmode.org]]"
2887 (ert-deftest test-org
/open-line
()
2888 "Test `org-open-line' specifications."
2889 ;; Call `open-line' outside of tables.
2892 (org-test-with-temp-text "Text"
2895 ;; At a table, create a row above.
2897 (equal "\n| |\n| a |"
2898 (org-test-with-temp-text "\n<point>| a |"
2901 ;; At the very first character of the buffer, also call `open-line'.
2904 (org-test-with-temp-text "| a |"
2907 ;; Narrowing does not count.
2909 (equal "Text\n| |\n| a |"
2910 (org-test-with-temp-text "Text\n<point>| a |"
2911 (narrow-to-region (point) (point-max))
2916 (ert-deftest test-org
/forward-sentence
()
2917 "Test `org-forward-sentence' specifications."
2918 ;; At the end of a table cell, move to the end of the next one.
2920 (org-test-with-temp-text "| a<point> | b |"
2921 (org-forward-sentence)
2922 (looking-at " |$")))
2923 ;; Elsewhere in a cell, move to its end.
2925 (org-test-with-temp-text "| a<point>c | b |"
2926 (org-forward-sentence)
2927 (looking-at " | b |$")))
2928 ;; Otherwise, simply call `forward-sentence'.
2930 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2931 (org-forward-sentence)
2932 (looking-at " Sentence 2.")))
2934 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2935 (org-forward-sentence)
2936 (org-forward-sentence)
2938 ;; At the end of an element, jump to the next one, without stopping
2939 ;; on blank lines in-between.
2941 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2942 (org-forward-sentence)
2945 (ert-deftest test-org
/backward-sentence
()
2946 "Test `org-backward-sentence' specifications."
2947 ;; At the beginning of a table cell, move to the beginning of the
2950 (org-test-with-temp-text "| a | <point>b |"
2951 (org-backward-sentence)
2952 (looking-at "a | b |$")))
2953 ;; Elsewhere in a cell, move to its beginning.
2955 (org-test-with-temp-text "| a | b<point>c |"
2956 (org-backward-sentence)
2957 (looking-at "bc |$")))
2958 ;; Otherwise, simply call `backward-sentence'.
2960 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2961 (org-backward-sentence)
2962 (looking-at "Sentence 2.")))
2964 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2965 (org-backward-sentence)
2966 (org-backward-sentence)
2968 ;; Make sure to hit the beginning of a sentence on the same line as
2971 (org-test-with-temp-text "- Line 1\n line <point>2."
2972 (org-backward-sentence)
2973 (looking-at "Line 1"))))
2975 (ert-deftest test-org
/forward-paragraph
()
2976 "Test `org-forward-paragraph' specifications."
2977 ;; At end of buffer, return an error.
2979 (org-test-with-temp-text "Paragraph"
2980 (goto-char (point-max))
2981 (org-forward-paragraph)))
2984 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2985 (org-forward-paragraph)
2989 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2990 (org-forward-paragraph)
2992 ;; Do not enter elements with invisible contents.
2994 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2995 (org-hide-block-toggle)
2996 (org-forward-paragraph)
2998 ;; On an affiliated keyword, jump to the beginning of the element.
3000 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3001 (org-forward-paragraph)
3002 (looking-at "Para")))
3003 ;; On an item or a footnote definition, move to the second element
3006 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3007 (org-forward-paragraph)
3008 (looking-at " Paragraph")))
3010 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3011 (org-forward-paragraph)
3012 (looking-at "Paragraph")))
3013 ;; On an item, or a footnote definition, when the first line is
3014 ;; empty, move to the first item.
3016 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3017 (org-forward-paragraph)
3018 (looking-at " Paragraph")))
3020 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3021 (org-forward-paragraph)
3022 (looking-at "Paragraph")))
3023 ;; On a table (resp. a property drawer) do not move through table
3024 ;; rows (resp. node properties).
3026 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3027 (org-forward-paragraph)
3028 (looking-at "Paragraph")))
3030 (org-test-with-temp-text
3031 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3032 (org-forward-paragraph)
3033 (looking-at "Paragraph")))
3034 ;; On a verse or source block, stop after blank lines.
3036 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3037 (org-forward-paragraph)
3040 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3041 (org-forward-paragraph)
3042 (looking-at "L2"))))
3044 (ert-deftest test-org
/backward-paragraph
()
3045 "Test `org-backward-paragraph' specifications."
3046 ;; Error at beginning of buffer.
3048 (org-test-with-temp-text "Paragraph"
3049 (org-backward-paragraph)))
3052 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3053 (goto-char (point-max))
3054 (org-backward-paragraph)
3057 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3058 (goto-char (point-max))
3060 (org-backward-paragraph)
3064 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3065 (goto-char (point-max))
3067 (org-backward-paragraph)
3069 ;; Ignore invisible elements.
3071 (org-test-with-temp-text "* H1\n P1\n* H2"
3073 (goto-char (point-max))
3075 (org-backward-paragraph)
3077 ;; On an affiliated keyword, jump to the first one.
3079 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3080 (search-forward "c2")
3081 (org-backward-paragraph)
3082 (looking-at "#\\+name")))
3083 ;; On the second element in an item or a footnote definition, jump
3084 ;; to item or the definition.
3086 (org-test-with-temp-text "- line1\n\n line2"
3087 (goto-char (point-max))
3089 (org-backward-paragraph)
3090 (looking-at "- line1")))
3092 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3093 (goto-char (point-max))
3095 (org-backward-paragraph)
3096 (looking-at "\\[fn:1\\] line1")))
3097 ;; On a table (resp. a property drawer), ignore table rows
3098 ;; (resp. node properties).
3100 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3101 (goto-char (point-max))
3103 (org-backward-paragraph)
3106 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3107 (org-backward-paragraph)
3108 (looking-at ":PROPERTIES:")))
3109 ;; On a source or verse block, stop before blank lines.
3111 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3112 (search-forward "L3")
3114 (org-backward-paragraph)
3117 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3118 (search-forward "L3")
3120 (org-backward-paragraph)
3121 (looking-at "L2"))))
3123 (ert-deftest test-org
/forward-element
()
3124 "Test `org-forward-element' specifications."
3125 ;; 1. At EOB: should error.
3126 (org-test-with-temp-text "Some text\n"
3127 (goto-char (point-max))
3128 (should-error (org-forward-element)))
3129 ;; 2. Standard move: expected to ignore blank lines.
3130 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3131 (org-forward-element)
3132 (should (looking-at (regexp-quote "Second paragraph."))))
3133 ;; 3. Headline tests.
3134 (org-test-with-temp-text "
3139 ;; 3.1. At an headline beginning: move to next headline at the
3142 (org-forward-element)
3143 (should (looking-at (regexp-quote "** Head 1.2")))
3144 ;; 3.2. At an headline beginning: move to parent headline if no
3145 ;; headline at the same level.
3147 (org-forward-element)
3148 (should (looking-at (regexp-quote "** Head 1.2"))))
3149 ;; 4. Greater element tests.
3150 (org-test-with-temp-text
3151 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3152 ;; 4.1. At a greater element: expected to skip contents.
3153 (org-forward-element)
3154 (should (looking-at (regexp-quote "Outside.")))
3155 ;; 4.2. At the end of greater element contents: expected to skip
3156 ;; to the end of the greater element.
3158 (org-forward-element)
3159 (should (looking-at (regexp-quote "Outside."))))
3161 (org-test-with-temp-text "
3175 ;; 5.1. At list top point: expected to move to the element after
3178 (org-forward-element)
3179 (should (looking-at (regexp-quote "Outside.")))
3180 ;; 5.2. Special case: at the first line of a sub-list, but not at
3181 ;; beginning of line, move to next item.
3184 (org-forward-element)
3185 (should (looking-at "- item2"))
3188 (org-forward-element)
3189 (should (looking-at " - sub2"))
3190 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3192 (org-forward-element)
3193 (should (looking-at (regexp-quote " Inner paragraph.")))
3194 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3196 (org-forward-element)
3197 (should (looking-at (regexp-quote " Inner paragraph.")))
3198 ;; 5.5. At an item: expected to move to next item, if any.
3200 (org-forward-element)
3201 (should (looking-at " - sub3"))))
3203 (ert-deftest test-org
/backward-element
()
3204 "Test `org-backward-element' specifications."
3205 ;; 1. Should error at BOB.
3206 (org-test-with-temp-text " \nParagraph."
3207 (should-error (org-backward-element)))
3208 ;; 2. Should move at BOB when called on the first element in buffer.
3210 (org-test-with-temp-text "\n#+TITLE: test"
3211 (progn (forward-line)
3212 (org-backward-element)
3214 ;; 3. Not at the beginning of an element: move at its beginning.
3215 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3218 (org-backward-element)
3219 (should (looking-at (regexp-quote "Paragraph2."))))
3220 ;; 4. Headline tests.
3221 (org-test-with-temp-text "
3226 ;; 4.1. At an headline beginning: move to previous headline at the
3229 (org-backward-element)
3230 (should (looking-at (regexp-quote "** Head 1.1")))
3231 ;; 4.2. At an headline beginning: move to parent headline if no
3232 ;; headline at the same level.
3234 (org-backward-element)
3235 (should (looking-at (regexp-quote "* Head 1")))
3236 ;; 4.3. At the first top-level headline: should error.
3238 (should-error (org-backward-element)))
3239 ;; 5. At beginning of first element inside a greater element:
3240 ;; expected to move to greater element's beginning.
3241 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3243 (org-backward-element)
3244 (should (looking-at "#\\+BEGIN_CENTER")))
3245 ;; 6. At the beginning of the first element in a section: should
3246 ;; move back to headline, if any.
3248 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3249 (progn (goto-char (point-max))
3251 (org-backward-element)
3252 (org-at-heading-p))))
3254 (org-test-with-temp-text "
3269 ;; 7.1. At beginning of sub-list: expected to move to the
3270 ;; paragraph before it.
3272 (org-backward-element)
3273 (should (looking-at "item1"))
3274 ;; 7.2. At an item in a list: expected to move at previous item.
3276 (org-backward-element)
3277 (should (looking-at " - sub2"))
3279 (org-backward-element)
3280 (should (looking-at "- item1"))
3281 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3284 (org-backward-element)
3285 (should (looking-at " - sub1"))
3287 (org-backward-element)
3288 (should (looking-at "- item1"))
3289 ;; 7.4. At blank-lines before list end: expected to move to top
3292 (org-backward-element)
3293 (should (looking-at "- item1"))))
3295 (ert-deftest test-org
/up-element
()
3296 "Test `org-up-element' specifications."
3297 ;; 1. At BOB or with no surrounding element: should error.
3298 (org-test-with-temp-text "Paragraph."
3299 (should-error (org-up-element)))
3300 (org-test-with-temp-text "* Head1\n* Head2"
3302 (should-error (org-up-element)))
3303 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3305 (should-error (org-up-element)))
3306 ;; 2. At an headline: move to parent headline.
3307 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3310 (should (looking-at "\\* Head1")))
3311 ;; 3. Inside a greater element: move to greater element beginning.
3312 (org-test-with-temp-text
3313 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3316 (should (looking-at "#\\+BEGIN_CENTER")))
3318 (org-test-with-temp-text "* Top
3325 Paragraph within sub2.
3328 ;; 4.1. Within an item: move to the item beginning.
3331 (should (looking-at " - sub2"))
3332 ;; 4.2. At an item in a sub-list: move to parent item.
3335 (should (looking-at "- item1"))
3336 ;; 4.3. At an item in top list: move to beginning of whole list.
3339 (should (looking-at "- item1"))
3340 ;; 4.4. Special case. At very top point: should move to parent of
3344 (should (looking-at "\\* Top"))))
3346 (ert-deftest test-org
/down-element
()
3347 "Test `org-down-element' specifications."
3348 ;; Error when the element hasn't got a recursive type.
3349 (org-test-with-temp-text "Paragraph."
3350 (should-error (org-down-element)))
3351 ;; Error when the element has no contents
3352 (org-test-with-temp-text "* Headline"
3353 (should-error (org-down-element)))
3354 ;; When at a plain-list, move to first item.
3355 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3358 (should (looking-at " - Item 1.1")))
3359 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3361 (should (looking-at " Item 1")))
3362 ;; When at a table, move to first row
3363 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3365 (should (looking-at " a | b |")))
3366 ;; Otherwise, move inside the greater element.
3367 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3369 (should (looking-at "Paragraph"))))
3371 (ert-deftest test-org
/drag-element-backward
()
3372 "Test `org-drag-element-backward' specifications."
3376 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3377 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3378 (org-drag-element-backward)
3382 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3383 (org-test-with-temp-text
3384 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3385 (org-drag-element-backward)
3387 ;; Preserve blank lines.
3389 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3390 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3391 (org-drag-element-backward)
3395 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3396 (org-drag-element-backward)
3397 (looking-at-p "2")))
3398 ;; Error when trying to move first element of buffer.
3400 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3401 (org-drag-element-backward))
3403 ;; Error when trying to swap nested elements.
3405 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3406 (org-drag-element-backward))
3408 ;; Error when trying to swap an headline element and a non-headline
3411 (org-test-with-temp-text "Test.\n<point>* Head 1"
3412 (org-drag-element-backward))
3414 ;; Error when called before first element.
3416 (org-test-with-temp-text "\n<point>"
3417 (org-drag-element-backward))
3419 ;; Preserve visibility of elements and their contents.
3421 (equal '((63 .
82) (26 .
48))
3422 (org-test-with-temp-text "
3430 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3431 (search-backward "- item 1")
3432 (org-drag-element-backward)
3433 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3434 (overlays-in (point-min) (point-max))))))
3435 ;; Pathological case: handle call with point in blank lines right
3436 ;; after a headline.
3438 (equal "* H2\n* H1\nText\n\n"
3439 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3440 (org-drag-element-backward)
3443 (ert-deftest test-org
/drag-element-forward
()
3444 "Test `org-drag-element-forward' specifications."
3445 ;; 1. Error when trying to move first element of buffer.
3446 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3448 (should-error (org-drag-element-forward)))
3449 ;; 2. Error when trying to swap nested elements.
3450 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3452 (should-error (org-drag-element-forward)))
3453 ;; 3. Error when trying to swap a non-headline element and an
3455 (org-test-with-temp-text "Test.\n* Head 1"
3456 (should-error (org-drag-element-forward)))
3457 ;; 4. Error when called before first element.
3459 (org-test-with-temp-text "\n"
3461 (org-drag-element-backward))
3463 ;; 5. Otherwise, swap elements, preserving column and blank lines
3464 ;; between elements.
3465 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3466 (search-forward "graph")
3467 (org-drag-element-forward)
3468 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3469 (should (looking-at " 1")))
3470 ;; 5. Preserve visibility of elements and their contents.
3471 (org-test-with-temp-text "
3479 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3480 (search-backward "#+BEGIN_CENTER")
3481 (org-drag-element-forward)
3484 '((63 .
82) (26 .
48))
3485 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3486 (overlays-in (point-min) (point-max)))))))
3488 (ert-deftest test-org
/next-block
()
3489 "Test `org-next-block' specifications."
3492 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3494 (looking-at "#\\+BEGIN_CENTER")))
3497 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3498 (let ((case-fold-search nil
))
3500 (looking-at "#\\+begin_center"))))
3501 ;; Ignore current line.
3503 (org-test-with-temp-text
3504 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3506 (looking-at "#\\+BEGIN_CENTER")))
3507 ;; Throw an error when no block is found.
3509 (org-test-with-temp-text "Paragraph"
3510 (org-next-block 1)))
3511 ;; With an argument, skip many blocks at once.
3513 (org-test-with-temp-text
3514 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3516 (looking-at "#\\+BEGIN_QUOTE")))
3517 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3519 (org-test-with-temp-text
3520 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3521 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3522 (looking-at "#\\+BEGIN_QUOTE")))
3523 ;; Optional argument is also case-insensitive.
3525 (org-test-with-temp-text
3526 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3527 (let ((case-fold-search nil
))
3528 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3529 (looking-at "#\\+begin_quote")))))
3531 (ert-deftest test-org
/previous-block
()
3532 "Test `org-previous-block' specifications."
3535 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3536 (org-previous-block 1)
3537 (looking-at "#\\+BEGIN_CENTER")))
3540 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3541 (let ((case-fold-search nil
))
3542 (org-previous-block 1)
3543 (looking-at "#\\+begin_center"))))
3544 ;; Ignore current line.
3546 (org-test-with-temp-text
3547 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3548 (org-previous-block 1)
3549 (looking-at "#\\+BEGIN_QUOTE")))
3550 ;; Throw an error when no block is found.
3552 (org-test-with-temp-text "Paragraph<point>"
3553 (org-previous-block 1)))
3554 ;; With an argument, skip many blocks at once.
3556 (org-test-with-temp-text
3557 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3558 (org-previous-block 2)
3559 (looking-at "#\\+BEGIN_CENTER")))
3560 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3562 (org-test-with-temp-text
3563 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3564 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3565 (looking-at "#\\+BEGIN_QUOTE")))
3566 ;; Optional argument is also case-insensitive.
3568 (org-test-with-temp-text
3569 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3570 (let ((case-fold-search nil
))
3571 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3572 (looking-at "#\\+begin_quote")))))
3575 ;;; Outline structure
3577 (ert-deftest test-org
/demote
()
3578 "Test `org-demote' specifications."
3579 ;; Add correct number of stars according to `org-odd-levels-only'.
3582 (org-test-with-temp-text "* H"
3583 (let ((org-odd-levels-only nil
)) (org-demote))
3584 (org-current-level))))
3587 (org-test-with-temp-text "* H"
3588 (let ((org-odd-levels-only t
)) (org-demote))
3589 (org-current-level))))
3590 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3592 (org-test-with-temp-text "* H :tag:"
3593 (let ((org-tags-column 10)
3594 (org-auto-align-tags t
)
3595 (org-odd-levels-only nil
))
3597 (org-move-to-column 10)
3598 (looking-at-p ":tag:$")))
3600 (org-test-with-temp-text "* H :tag:"
3601 (let ((org-tags-column 10)
3602 (org-auto-align-tags nil
)
3603 (org-odd-levels-only nil
))
3605 (org-move-to-column 10)
3606 (looking-at-p ":tag:$")))
3607 ;; When `org-adapt-indentation' is non-nil, always indent planning
3608 ;; info and property drawers accordingly.
3611 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3612 (let ((org-odd-levels-only nil
)
3613 (org-adapt-indentation t
))
3616 (org-get-indentation))))
3619 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3620 (let ((org-odd-levels-only nil
)
3621 (org-adapt-indentation t
))
3624 (org-get-indentation))))
3627 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3628 (let ((org-odd-levels-only nil
)
3629 (org-adapt-indentation nil
))
3632 (org-get-indentation))))
3633 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3634 ;; section accordingly. Ignore, however, footnote definitions and
3635 ;; inlinetasks boundaries.
3638 (org-test-with-temp-text "* H\n Paragraph"
3639 (let ((org-odd-levels-only nil
)
3640 (org-adapt-indentation t
))
3643 (org-get-indentation))))
3646 (org-test-with-temp-text "* H\n Paragraph"
3647 (let ((org-odd-levels-only nil
)
3648 (org-adapt-indentation nil
))
3651 (org-get-indentation))))
3654 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3655 (let ((org-odd-levels-only nil
)
3656 (org-adapt-indentation t
))
3658 (goto-char (point-max))
3659 (org-get-indentation))))
3662 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3663 (let ((org-odd-levels-only nil
)
3664 (org-adapt-indentation t
))
3666 (goto-char (point-max))
3667 (org-get-indentation))))
3668 (when (featurep 'org-inlinetask
)
3671 (let ((org-inlinetask-min-level 5)
3672 (org-adapt-indentation t
))
3673 (org-test-with-temp-text "* H\n***** I\n***** END"
3676 (org-get-indentation))))))
3677 (when (featurep 'org-inlinetask
)
3680 (let ((org-inlinetask-min-level 5)
3681 (org-adapt-indentation t
))
3682 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3685 (org-get-indentation))))))
3686 ;; Ignore contents of source blocks or example blocks when
3687 ;; indentation should be preserved (through
3688 ;; `org-src-preserve-indentation' or "-i" flag).
3691 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3692 (let ((org-adapt-indentation t
)
3693 (org-src-preserve-indentation nil
))
3696 (org-get-indentation))))
3699 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3700 (let ((org-adapt-indentation t
)
3701 (org-src-preserve-indentation t
))
3704 (org-get-indentation))))
3707 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3708 (let ((org-adapt-indentation t
)
3709 (org-src-preserve-indentation t
))
3712 (org-get-indentation))))
3715 (org-test-with-temp-text
3716 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3717 (let ((org-adapt-indentation t
)
3718 (org-src-preserve-indentation nil
))
3721 (org-get-indentation)))))
3723 (ert-deftest test-org
/promote
()
3724 "Test `org-promote' specifications."
3725 ;; Return an error if headline is to be promoted to level 0, unless
3726 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3727 ;; headline becomes a comment.
3729 (org-test-with-temp-text "* H"
3730 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3733 (org-test-with-temp-text "* H"
3734 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3736 ;; Remove correct number of stars according to
3737 ;; `org-odd-levels-only'.
3740 (org-test-with-temp-text "*** H"
3741 (let ((org-odd-levels-only nil
)) (org-promote))
3742 (org-current-level))))
3745 (org-test-with-temp-text "*** H"
3746 (let ((org-odd-levels-only t
)) (org-promote))
3747 (org-current-level))))
3748 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3750 (org-test-with-temp-text "** H :tag:"
3751 (let ((org-tags-column 10)
3752 (org-auto-align-tags t
)
3753 (org-odd-levels-only nil
))
3755 (org-move-to-column 10)
3756 (looking-at-p ":tag:$")))
3758 (org-test-with-temp-text "** H :tag:"
3759 (let ((org-tags-column 10)
3760 (org-auto-align-tags nil
)
3761 (org-odd-levels-only nil
))
3763 (org-move-to-column 10)
3764 (looking-at-p ":tag:$")))
3765 ;; When `org-adapt-indentation' is non-nil, always indent planning
3766 ;; info and property drawers.
3769 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3770 (let ((org-odd-levels-only nil
)
3771 (org-adapt-indentation t
))
3774 (org-get-indentation))))
3777 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3778 (let ((org-odd-levels-only nil
)
3779 (org-adapt-indentation t
))
3782 (org-get-indentation))))
3785 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3786 (let ((org-odd-levels-only nil
)
3787 (org-adapt-indentation nil
))
3790 (org-get-indentation))))
3791 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3792 ;; section accordingly. Ignore, however, footnote definitions and
3793 ;; inlinetasks boundaries.
3796 (org-test-with-temp-text "** H\n Paragraph"
3797 (let ((org-odd-levels-only nil
)
3798 (org-adapt-indentation t
))
3801 (org-get-indentation))))
3804 (org-test-with-temp-text "** H\n Paragraph"
3805 (let ((org-odd-levels-only nil
)
3806 (org-adapt-indentation nil
))
3809 (org-get-indentation))))
3812 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3813 (let ((org-odd-levels-only nil
)
3814 (org-adapt-indentation t
))
3817 (org-get-indentation))))
3818 (when (featurep 'org-inlinetask
)
3821 (let ((org-inlinetask-min-level 5)
3822 (org-adapt-indentation t
))
3823 (org-test-with-temp-text "** H\n***** I\n***** END"
3826 (org-get-indentation))))))
3827 (when (featurep 'org-inlinetask
)
3830 (let ((org-inlinetask-min-level 5)
3831 (org-adapt-indentation t
))
3832 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3835 (org-get-indentation))))))
3836 ;; Give up shifting if it would break document's structure
3840 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3841 (let ((org-odd-levels-only nil
)
3842 (org-adapt-indentation t
))
3845 (org-get-indentation))))
3848 (org-test-with-temp-text "** H\n Paragraph\n * list."
3849 (let ((org-odd-levels-only nil
)
3850 (org-adapt-indentation t
))
3853 (org-get-indentation))))
3854 ;; Ignore contents of source blocks or example blocks when
3855 ;; indentation should be preserved (through
3856 ;; `org-src-preserve-indentation' or "-i" flag).
3859 (org-test-with-temp-text
3860 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3861 (let ((org-adapt-indentation t
)
3862 (org-src-preserve-indentation nil
)
3863 (org-odd-levels-only nil
))
3866 (org-get-indentation))))
3869 (org-test-with-temp-text
3870 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3871 (let ((org-adapt-indentation t
)
3872 (org-src-preserve-indentation t
)
3873 (org-odd-levels-only nil
))
3876 (org-get-indentation))))
3879 (org-test-with-temp-text
3880 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3881 (let ((org-adapt-indentation t
)
3882 (org-src-preserve-indentation t
)
3883 (org-odd-levels-only nil
))
3886 (org-get-indentation))))
3889 (org-test-with-temp-text
3890 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3891 (let ((org-adapt-indentation t
)
3892 (org-src-preserve-indentation nil
)
3893 (org-odd-levels-only nil
))
3896 (org-get-indentation)))))
3898 (ert-deftest test-org
/org-get-valid-level
()
3899 "Test function `org-get-valid-level' specifications."
3900 (let ((org-odd-levels-only nil
))
3901 (should (equal 1 (org-get-valid-level 0 0)))
3902 (should (equal 1 (org-get-valid-level 0 1)))
3903 (should (equal 2 (org-get-valid-level 0 2)))
3904 (should (equal 3 (org-get-valid-level 0 3)))
3905 (should (equal 1 (org-get-valid-level 1 0)))
3906 (should (equal 2 (org-get-valid-level 1 1)))
3907 (should (equal 23 (org-get-valid-level 1 22)))
3908 (should (equal 1 (org-get-valid-level 1 -
1)))
3909 (should (equal 1 (org-get-valid-level 2 -
1))))
3910 (let ((org-odd-levels-only t
))
3911 (should (equal 1 (org-get-valid-level 0 0)))
3912 (should (equal 1 (org-get-valid-level 0 1)))
3913 (should (equal 3 (org-get-valid-level 0 2)))
3914 (should (equal 5 (org-get-valid-level 0 3)))
3915 (should (equal 1 (org-get-valid-level 1 0)))
3916 (should (equal 3 (org-get-valid-level 1 1)))
3917 (should (equal 3 (org-get-valid-level 2 1)))
3918 (should (equal 5 (org-get-valid-level 3 1)))
3919 (should (equal 5 (org-get-valid-level 4 1)))
3920 (should (equal 43 (org-get-valid-level 1 21)))
3921 (should (equal 1 (org-get-valid-level 1 -
1)))
3922 (should (equal 1 (org-get-valid-level 2 -
1)))
3923 (should (equal 1 (org-get-valid-level 3 -
1)))
3924 (should (equal 3 (org-get-valid-level 4 -
1)))
3925 (should (equal 3 (org-get-valid-level 5 -
1)))))
3930 (ert-deftest test-org
/at-planning-p
()
3931 "Test `org-at-planning-p' specifications."
3934 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3935 (org-at-planning-p)))
3937 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3938 (org-at-planning-p)))
3939 ;; Correctly find planning attached to inlinetasks.
3940 (when (featurep 'org-inlinetask
)
3942 (org-test-with-temp-text
3943 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3944 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3946 (org-test-with-temp-text
3947 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3948 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3950 (org-test-with-temp-text
3951 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3952 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3954 (org-test-with-temp-text
3955 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3956 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3958 (ert-deftest test-org
/add-planning-info
()
3959 "Test `org-add-planning-info'."
3960 ;; Create deadline when `org-adapt-indentation' is non-nil.
3962 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3963 (org-test-with-temp-text "* H\nParagraph<point>"
3964 (let ((org-adapt-indentation t
))
3965 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3966 (replace-regexp-in-string
3967 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3969 ;; Create deadline when `org-adapt-indentation' is nil.
3971 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3972 (org-test-with-temp-text "* H\nParagraph<point>"
3973 (let ((org-adapt-indentation nil
))
3974 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3975 (replace-regexp-in-string
3976 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3978 ;; Update deadline when `org-adapt-indentation' is non-nil.
3980 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3981 (org-test-with-temp-text "\
3983 DEADLINE: <2015-06-24 Wed>
3985 (let ((org-adapt-indentation t
))
3986 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3987 (replace-regexp-in-string
3988 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3990 ;; Update deadline when `org-adapt-indentation' is nil.
3992 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3993 (org-test-with-temp-text "\
3995 DEADLINE: <2015-06-24 Wed>
3997 (let ((org-adapt-indentation nil
))
3998 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3999 (replace-regexp-in-string
4000 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4002 ;; Schedule when `org-adapt-indentation' is non-nil.
4004 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4005 (org-test-with-temp-text "* H\nParagraph<point>"
4006 (let ((org-adapt-indentation t
))
4007 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4008 (replace-regexp-in-string
4009 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4011 ;; Schedule when `org-adapt-indentation' is nil.
4013 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4014 (org-test-with-temp-text "* H\nParagraph<point>"
4015 (let ((org-adapt-indentation nil
))
4016 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4017 (replace-regexp-in-string
4018 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4020 ;; Add deadline when scheduled.
4024 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4026 (org-test-with-temp-text "\
4028 SCHEDULED: <2015-06-24 Wed>
4030 (let ((org-adapt-indentation t
))
4031 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4032 (replace-regexp-in-string
4033 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4035 ;; Remove middle entry.
4039 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4041 (org-test-with-temp-text "\
4043 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4045 (let ((org-adapt-indentation t
))
4046 (org-add-planning-info nil nil
'deadline
))
4047 (replace-regexp-in-string
4048 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4050 ;; Remove last entry and then middle entry (order should not
4055 CLOSED: [2015-06-24]
4057 (org-test-with-temp-text "\
4059 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4061 (let ((org-adapt-indentation t
))
4062 (org-add-planning-info nil nil
'scheduled
'deadline
))
4063 (replace-regexp-in-string
4064 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4066 ;; Remove closed when `org-adapt-indentation' is non-nil.
4068 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4069 (org-test-with-temp-text "\
4071 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4073 (let ((org-adapt-indentation t
))
4074 (org-add-planning-info nil nil
'closed
))
4075 (replace-regexp-in-string
4076 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4079 (equal "* H\n Paragraph"
4080 (org-test-with-temp-text "\
4082 CLOSED: [2015-06-25 Thu]
4084 (let ((org-adapt-indentation t
))
4085 (org-add-planning-info nil nil
'closed
))
4086 (replace-regexp-in-string
4087 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4089 ;; Remove closed when `org-adapt-indentation' is nil.
4091 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4092 (org-test-with-temp-text "\
4094 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4096 (let ((org-adapt-indentation nil
))
4097 (org-add-planning-info nil nil
'closed
))
4098 (replace-regexp-in-string
4099 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4102 (equal "* H\nParagraph"
4103 (org-test-with-temp-text "\
4105 CLOSED: [2015-06-25 Thu]
4107 (let ((org-adapt-indentation nil
))
4108 (org-add-planning-info nil nil
'closed
))
4109 (replace-regexp-in-string
4110 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4112 ;; Remove closed entry and delete empty line.
4117 (org-test-with-temp-text "\
4119 CLOSED: [2015-06-24 Wed]
4121 (let ((org-adapt-indentation t
))
4122 (org-add-planning-info nil nil
'closed
))
4123 (replace-regexp-in-string
4124 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4126 ;; Remove one entry and update another.
4128 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4129 (org-test-with-temp-text "\
4131 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4133 (let ((org-adapt-indentation t
))
4134 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4135 (replace-regexp-in-string
4136 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4139 (ert-deftest test-org
/deadline
()
4140 "Test `org-deadline' specifications."
4141 ;; Insert a new value or replace existing one.
4143 (equal "* H\nDEADLINE: <2012-03-29>\n"
4144 (org-test-with-temp-text "* H"
4145 (let ((org-adapt-indentation nil
)
4146 (org-last-inserted-timestamp nil
))
4147 (org-deadline nil
"<2012-03-29 Tue>"))
4148 (replace-regexp-in-string
4149 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4152 (equal "* H\nDEADLINE: <2014-03-04>"
4153 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4154 (let ((org-adapt-indentation nil
)
4155 (org-last-inserted-timestamp nil
))
4156 (org-deadline nil
"<2014-03-04 Thu>"))
4157 (replace-regexp-in-string
4158 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4160 ;; Accept delta time, e.g., "+2d".
4162 (equal "* H\nDEADLINE: <2015-03-04>\n"
4163 (cl-letf (((symbol-function 'current-time
)
4164 (lambda (&rest args
)
4165 (apply #'encode-time
4166 (org-parse-time-string "2014-03-04")))))
4167 (org-test-with-temp-text "* H"
4168 (let ((org-adapt-indentation nil
)
4169 (org-last-inserted-timestamp nil
))
4170 (org-deadline nil
"+1y"))
4171 (replace-regexp-in-string
4172 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4173 ;; Preserve repeater.
4175 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4176 (org-test-with-temp-text "* H"
4177 (let ((org-adapt-indentation nil
)
4178 (org-last-inserted-timestamp nil
))
4179 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4180 (replace-regexp-in-string
4181 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4182 ;; Remove CLOSED keyword, if any.
4184 (equal "* H\nDEADLINE: <2012-03-29>"
4185 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4186 (let ((org-adapt-indentation nil
)
4187 (org-last-inserted-timestamp nil
))
4188 (org-deadline nil
"<2012-03-29 Tue>"))
4189 (replace-regexp-in-string
4190 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4191 ;; With C-u argument, remove DEADLINE keyword.
4194 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4195 (let ((org-adapt-indentation nil
)
4196 (org-last-inserted-timestamp nil
))
4197 (org-deadline '(4)))
4201 (org-test-with-temp-text "* H"
4202 (let ((org-adapt-indentation nil
)
4203 (org-last-inserted-timestamp nil
))
4204 (org-deadline '(4)))
4206 ;; With C-u C-u argument, prompt for a delay cookie.
4208 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4209 (cl-letf (((symbol-function 'org-read-date
)
4210 (lambda (&rest args
)
4211 (apply #'encode-time
4212 (org-parse-time-string "2014-03-04")))))
4213 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4214 (let ((org-adapt-indentation nil
)
4215 (org-last-inserted-timestamp nil
))
4216 (org-deadline '(16)))
4219 (cl-letf (((symbol-function 'org-read-date
)
4220 (lambda (&rest args
)
4221 (apply #'encode-time
4222 (org-parse-time-string "2014-03-04")))))
4223 (org-test-with-temp-text "* H"
4224 (let ((org-adapt-indentation nil
)
4225 (org-last-inserted-timestamp nil
))
4226 (org-deadline '(16)))
4228 ;; When a region is active and
4229 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4230 ;; same value in all headlines in region.
4232 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4233 (org-test-with-temp-text "* H1\n* H2"
4234 (let ((org-adapt-indentation nil
)
4235 (org-last-inserted-timestamp nil
)
4236 (org-loop-over-headlines-in-active-region t
))
4237 (transient-mark-mode 1)
4238 (push-mark (point) t t
)
4239 (goto-char (point-max))
4240 (org-deadline nil
"2012-03-29"))
4241 (replace-regexp-in-string
4242 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4244 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4245 (org-test-with-temp-text "* H1\n* H2"
4246 (let ((org-adapt-indentation nil
)
4247 (org-last-inserted-timestamp nil
)
4248 (org-loop-over-headlines-in-active-region nil
))
4249 (transient-mark-mode 1)
4250 (push-mark (point) t t
)
4251 (goto-char (point-max))
4252 (org-deadline nil
"2012-03-29"))
4253 (replace-regexp-in-string
4254 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4256 (ert-deftest test-org
/schedule
()
4257 "Test `org-schedule' specifications."
4258 ;; Insert a new value or replace existing one.
4260 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4261 (org-test-with-temp-text "* H"
4262 (let ((org-adapt-indentation nil
)
4263 (org-last-inserted-timestamp nil
))
4264 (org-schedule nil
"<2012-03-29 Tue>"))
4265 (replace-regexp-in-string
4266 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4269 (equal "* H\nSCHEDULED: <2014-03-04>"
4270 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4271 (let ((org-adapt-indentation nil
)
4272 (org-last-inserted-timestamp nil
))
4273 (org-schedule nil
"<2014-03-04 Thu>"))
4274 (replace-regexp-in-string
4275 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4277 ;; Accept delta time, e.g., "+2d".
4279 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4280 (cl-letf (((symbol-function 'current-time
)
4281 (lambda (&rest args
)
4282 (apply #'encode-time
4283 (org-parse-time-string "2014-03-04")))))
4284 (org-test-with-temp-text "* H"
4285 (let ((org-adapt-indentation nil
)
4286 (org-last-inserted-timestamp nil
))
4287 (org-schedule nil
"+1y"))
4288 (replace-regexp-in-string
4289 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4290 ;; Preserve repeater.
4292 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4293 (org-test-with-temp-text "* H"
4294 (let ((org-adapt-indentation nil
)
4295 (org-last-inserted-timestamp nil
))
4296 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4297 (replace-regexp-in-string
4298 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4299 ;; Remove CLOSED keyword, if any.
4301 (equal "* H\nSCHEDULED: <2012-03-29>"
4302 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4303 (let ((org-adapt-indentation nil
)
4304 (org-last-inserted-timestamp nil
))
4305 (org-schedule nil
"<2012-03-29 Tue>"))
4306 (replace-regexp-in-string
4307 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4308 ;; With C-u argument, remove SCHEDULED keyword.
4311 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4312 (let ((org-adapt-indentation nil
)
4313 (org-last-inserted-timestamp nil
))
4314 (org-schedule '(4)))
4318 (org-test-with-temp-text "* H"
4319 (let ((org-adapt-indentation nil
)
4320 (org-last-inserted-timestamp nil
))
4321 (org-schedule '(4)))
4323 ;; With C-u C-u argument, prompt for a delay cookie.
4325 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4326 (cl-letf (((symbol-function 'org-read-date
)
4327 (lambda (&rest args
)
4328 (apply #'encode-time
4329 (org-parse-time-string "2014-03-04")))))
4330 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4331 (let ((org-adapt-indentation nil
)
4332 (org-last-inserted-timestamp nil
))
4333 (org-schedule '(16)))
4336 (cl-letf (((symbol-function 'org-read-date
)
4337 (lambda (&rest args
)
4338 (apply #'encode-time
4339 (org-parse-time-string "2014-03-04")))))
4340 (org-test-with-temp-text "* H"
4341 (let ((org-adapt-indentation nil
)
4342 (org-last-inserted-timestamp nil
))
4343 (org-schedule '(16)))
4345 ;; When a region is active and
4346 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4347 ;; same value in all headlines in region.
4349 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4350 (org-test-with-temp-text "* H1\n* H2"
4351 (let ((org-adapt-indentation nil
)
4352 (org-last-inserted-timestamp nil
)
4353 (org-loop-over-headlines-in-active-region t
))
4354 (transient-mark-mode 1)
4355 (push-mark (point) t t
)
4356 (goto-char (point-max))
4357 (org-schedule nil
"2012-03-29"))
4358 (replace-regexp-in-string
4359 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4361 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4362 (org-test-with-temp-text "* H1\n* H2"
4363 (let ((org-adapt-indentation nil
)
4364 (org-last-inserted-timestamp nil
)
4365 (org-loop-over-headlines-in-active-region nil
))
4366 (transient-mark-mode 1)
4367 (push-mark (point) t t
)
4368 (goto-char (point-max))
4369 (org-schedule nil
"2012-03-29"))
4370 (replace-regexp-in-string
4371 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4373 ;; check if a repeater survives re-scheduling.
4375 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4376 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4377 (let ((org-adapt-indentation nil
)
4378 (org-last-inserted-timestamp nil
))
4379 (org-schedule nil
"2017-02-01"))
4385 (ert-deftest test-org
/buffer-property-keys
()
4386 "Test `org-buffer-property-keys' specifications."
4387 ;; Retrieve properties accross siblings.
4390 (org-test-with-temp-text "
4399 (org-buffer-property-keys))))
4400 ;; Retrieve properties accross children.
4403 (org-test-with-temp-text "
4412 (org-buffer-property-keys))))
4413 ;; Retrieve muliple properties in the same drawer.
4416 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4417 (org-buffer-property-keys))))
4418 ;; Ignore extension symbol in property name.
4421 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4422 (org-buffer-property-keys))))
4423 ;; With non-nil COLUMNS, extract property names from columns.
4426 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4427 (org-buffer-property-keys nil nil t
))))
4429 (equal '("A" "B" "COLUMNS")
4430 (org-test-with-temp-text
4431 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4432 (org-buffer-property-keys nil nil t
))))
4433 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4436 (org-test-with-temp-text
4437 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4438 (org-buffer-property-keys nil nil nil t
)))))
4440 (ert-deftest test-org
/property-values
()
4441 "Test `org-property-values' specifications."
4445 (org-test-with-temp-text
4446 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4447 (org-property-values "A"))))
4448 ;; Ignore empty values.
4450 (org-test-with-temp-text
4451 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4452 (org-property-values "A")))
4453 ;; Take into consideration extended values.
4456 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4457 (org-property-values "A")))))
4459 (ert-deftest test-org
/find-property
()
4460 "Test `org-find-property' specifications."
4464 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4465 (org-find-property "prop"))))
4466 ;; Ignore false positives.
4469 (org-test-with-temp-text
4470 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4471 (org-find-property "A"))))
4472 ;; Return first entry found in buffer.
4475 (org-test-with-temp-text
4476 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4477 (org-find-property "A"))))
4478 ;; Only search visible part of the buffer.
4481 (org-test-with-temp-text
4482 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4483 (org-narrow-to-subtree)
4484 (org-find-property "A"))))
4485 ;; With optional argument, only find entries with a specific value.
4487 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4488 (org-find-property "A" "2")))
4491 (org-test-with-temp-text
4492 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4493 (org-find-property "A" "2"))))
4494 ;; Use "nil" for explicit nil values.
4497 (org-test-with-temp-text
4498 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4499 (org-find-property "A" "nil")))))
4501 (ert-deftest test-org
/entry-delete
()
4502 "Test `org-entry-delete' specifications."
4506 " *:PROPERTIES:\n *:B: +2\n *:END:"
4507 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4508 (org-entry-delete (point) "A")
4510 ;; Also remove accumulated properties.
4514 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4515 (org-entry-delete (point) "A")
4517 ;; When last property is removed, remove the property drawer.
4521 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4522 (org-entry-delete (point) "A")
4524 ;; Return a non-nil value when some property was removed.
4526 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4527 (org-entry-delete (point) "A")))
4529 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4530 (org-entry-delete (point) "C")))
4531 ;; Special properties cannot be located in a drawer. Allow to
4532 ;; remove them anyway, in case of user error.
4534 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4535 (org-entry-delete (point) "SCHEDULED"))))
4537 (ert-deftest test-org
/entry-get
()
4538 "Test `org-entry-get' specifications."
4542 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4543 (org-entry-get (point) "A"))))
4547 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4548 (org-entry-get (point) "a"))))
4549 ;; Handle extended values, both before and after base value.
4552 (org-test-with-temp-text
4553 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4554 (org-entry-get (point) "A"))))
4555 ;; Empty values are returned as the empty string.
4558 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4559 (org-entry-get (point) "A"))))
4560 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4561 ;; otherwise, return nil.
4563 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4564 (org-entry-get (point) "A")))
4567 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4568 (org-entry-get (point) "A" nil t
))))
4569 ;; Return nil when no property is found, independently on the
4570 ;; LITERAL-NIL argument.
4572 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4573 (org-entry-get (point) "B")))
4575 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4576 (org-entry-get (point) "B" nil t
)))
4577 ;; Handle inheritance, when allowed. Include extended values and
4578 ;; possibly global values.
4582 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4583 (org-entry-get (point) "A" t
))))
4587 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4588 (let ((org-use-property-inheritance t
))
4589 (org-entry-get (point) "A" 'selective
)))))
4591 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4592 (let ((org-use-property-inheritance nil
))
4593 (org-entry-get (point) "A" 'selective
))))
4597 (org-test-with-temp-text
4598 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4599 (org-entry-get (point-max) "A" t
))))
4602 (org-test-with-temp-text
4603 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4605 (org-entry-get (point-max) "A" t
))))
4608 (org-test-with-temp-text
4609 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4611 (org-entry-get (point-max) "A" t
)))))
4613 (ert-deftest test-org
/entry-properties
()
4614 "Test `org-entry-properties' specifications."
4615 ;; Get "ITEM" property.
4618 (org-test-with-temp-text "* TODO H"
4619 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4622 (org-test-with-temp-text "* TODO H"
4623 (cdr (assoc "ITEM" (org-entry-properties))))))
4624 ;; Get "TODO" property. TODO keywords are case sensitive.
4627 (org-test-with-temp-text "* TODO H"
4628 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4631 (org-test-with-temp-text "* TODO H"
4632 (cdr (assoc "TODO" (org-entry-properties))))))
4634 (org-test-with-temp-text "* H"
4635 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4637 (org-test-with-temp-text "* todo H"
4638 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4639 ;; Get "PRIORITY" property.
4642 (org-test-with-temp-text "* [#A] H"
4643 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4646 (org-test-with-temp-text "* [#A] H"
4647 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4649 (equal (char-to-string org-default-priority
)
4650 (org-test-with-temp-text "* H"
4651 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4652 ;; Get "FILE" property.
4654 (org-test-with-temp-text-in-file "* H\nParagraph"
4655 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4656 (buffer-file-name))))
4658 (org-test-with-temp-text-in-file "* H\nParagraph"
4659 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4660 (buffer-file-name))))
4662 (org-test-with-temp-text "* H\nParagraph"
4663 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4664 ;; Get "TAGS" property.
4666 (equal ":tag1:tag2:"
4667 (org-test-with-temp-text "* H :tag1:tag2:"
4668 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4670 (equal ":tag1:tag2:"
4671 (org-test-with-temp-text "* H :tag1:tag2:"
4672 (cdr (assoc "TAGS" (org-entry-properties))))))
4674 (org-test-with-temp-text "* H"
4675 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4676 ;; Get "ALLTAGS" property.
4678 (equal ":tag1:tag2:"
4679 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4680 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4682 (equal ":tag1:tag2:"
4683 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4684 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4686 (org-test-with-temp-text "* H"
4687 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4688 ;; Get "BLOCKED" property.
4691 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4692 (let ((org-enforce-todo-dependencies t
)
4694 '(org-block-todo-from-children-or-siblings-or-parent)))
4695 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4698 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4699 (let ((org-enforce-todo-dependencies t
)
4701 '(org-block-todo-from-children-or-siblings-or-parent)))
4702 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4703 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4707 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4708 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4712 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4713 (cdr (assoc "CLOSED" (org-entry-properties))))))
4715 (org-test-with-temp-text "* H"
4716 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4720 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4721 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4725 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4726 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4728 (org-test-with-temp-text "* H"
4729 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4733 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4734 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4738 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4739 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4741 (org-test-with-temp-text "* H"
4742 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4746 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4747 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4750 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4751 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4754 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4755 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4758 (org-test-with-temp-text
4759 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4761 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4762 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4763 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4765 (equal "<2012-03-29 thu.>"
4766 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4767 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4769 (equal "[2012-03-29 thu.]"
4770 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4771 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4773 (equal "<2012-03-29 thu.>"
4774 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4775 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4777 (equal "[2014-03-04 tue.]"
4778 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4779 (cdr (assoc "TIMESTAMP_IA"
4780 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4782 (equal "<2012-03-29 thu.>"
4783 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4784 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4785 ;; Get standard properties.
4788 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4789 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4790 ;; Handle extended properties.
4793 (org-test-with-temp-text
4794 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4795 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4798 (org-test-with-temp-text
4799 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4800 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4801 ;; Ignore forbidden (special) properties.
4803 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4804 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4806 (ert-deftest test-org
/entry-put
()
4807 "Test `org-entry-put' specifications."
4808 ;; Error when not a string or nil.
4810 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4811 (org-entry-put 1 "test" 2)))
4812 ;; Error when property name is invalid.
4814 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4815 (org-entry-put 1 "no space" "value")))
4817 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4818 (org-entry-put 1 "" "value")))
4819 ;; Set "TODO" property.
4821 (string-match (regexp-quote " TODO H")
4822 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4823 (org-entry-put (point) "TODO" "TODO")
4826 (string-match (regexp-quote "* H")
4827 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4828 (org-entry-put (point) "TODO" nil
)
4830 ;; Set "PRIORITY" property.
4833 (org-test-with-temp-text "* [#B] H"
4834 (org-entry-put (point) "PRIORITY" "A")
4838 (org-test-with-temp-text "* [#B] H"
4839 (org-entry-put (point) "PRIORITY" nil
)
4841 ;; Set "SCHEDULED" property.
4843 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4844 (org-test-with-temp-text "* H"
4845 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4849 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4850 (org-entry-put (point) "SCHEDULED" nil
)
4853 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4854 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4855 (org-entry-put (point) "SCHEDULED" "earlier")
4858 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4859 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4860 (org-entry-put (point) "SCHEDULED" "later")
4862 ;; Set "DEADLINE" property.
4864 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4865 (org-test-with-temp-text "* H"
4866 (org-entry-put (point) "DEADLINE" "2014-03-04")
4870 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4871 (org-entry-put (point) "DEADLINE" nil
)
4874 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4875 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4876 (org-entry-put (point) "DEADLINE" "earlier")
4879 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4880 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4881 (org-entry-put (point) "DEADLINE" "later")
4883 ;; Set "CATEGORY" property
4885 (string-match "^ *:CATEGORY: cat"
4886 (org-test-with-temp-text "* H"
4887 (org-entry-put (point) "CATEGORY" "cat")
4889 ;; Regular properties, with or without pre-existing drawer.
4891 (string-match "^ *:A: +2$"
4892 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4893 (org-entry-put (point) "A" "2")
4896 (string-match "^ *:A: +1$"
4897 (org-test-with-temp-text "* H"
4898 (org-entry-put (point) "A" "1")
4900 ;; Special case: two consecutive headlines.
4902 (string-match "\\* A\n *:PROPERTIES:"
4903 (org-test-with-temp-text "* A\n** B"
4904 (org-entry-put (point) "A" "1")
4907 (ert-deftest test-org
/refresh-properties
()
4908 "Test `org-refresh-properties' specifications."
4911 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4912 (org-refresh-properties "A" 'org-test
)
4913 (get-text-property (point) 'org-test
))))
4915 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4916 (org-refresh-properties "B" 'org-test
)
4917 (get-text-property (point) 'org-test
)))
4918 ;; Handle properties only defined with extension syntax, i.e.,
4922 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4923 (org-refresh-properties "A" 'org-test
)
4924 (get-text-property (point) 'org-test
))))
4925 ;; When property is inherited, add text property to the whole
4929 (org-test-with-temp-text
4930 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4931 (let ((org-use-property-inheritance t
))
4932 (org-refresh-properties "A" 'org-test
))
4933 (get-text-property (point) 'org-test
))))
4934 ;; When property is inherited, use global value across the whole
4935 ;; buffer. However local values have precedence.
4938 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4940 (let ((org-use-property-inheritance nil
))
4941 (org-refresh-properties "A" 'org-test
))
4942 (get-text-property (point) 'org-test
))))
4945 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4947 (let ((org-use-property-inheritance t
))
4948 (org-refresh-properties "A" 'org-test
))
4949 (get-text-property (point) 'org-test
))))
4952 (org-test-with-temp-text
4953 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4955 (let ((org-use-property-inheritance t
))
4956 (org-refresh-properties "A" 'org-test
))
4957 (get-text-property (point) 'org-test
)))))
4962 (ert-deftest test-org
/update-radio-target-regexp
()
4963 "Test `org-update-radio-target-regexp' specifications."
4964 ;; Properly update cache with no previous radio target regexp.
4967 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4968 (save-excursion (goto-char (point-max)) (org-element-context))
4970 (search-forward "o")
4972 (org-update-radio-target-regexp)
4973 (goto-char (point-max))
4974 (org-element-type (org-element-context)))))
4975 ;; Properly update cache with previous radio target regexp.
4978 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4979 (save-excursion (goto-char (point-max)) (org-element-context))
4981 (search-forward "o")
4983 (org-update-radio-target-regexp)
4984 (search-backward "r")
4987 (org-update-radio-target-regexp)
4988 (goto-char (point-max))
4989 (delete-region (line-beginning-position) (point))
4991 (org-element-type (org-element-context))))))
4996 (ert-deftest test-org
/match-sparse-tree
()
4997 "Test `org-match-sparse-tree' specifications."
5000 (org-test-with-temp-text "* H\n** H1 :tag:"
5001 (org-match-sparse-tree nil
"tag")
5002 (search-forward "H1")
5003 (org-invisible-p2)))
5005 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5006 (org-match-sparse-tree nil
"tag")
5007 (search-forward "H2")
5008 (org-invisible-p2)))
5009 ;; "-" operator for tags.
5011 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5012 (org-match-sparse-tree nil
"tag1-tag2")
5013 (search-forward "H1")
5014 (org-invisible-p2)))
5016 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5017 (org-match-sparse-tree nil
"tag1-tag2")
5018 (search-forward "H2")
5019 (org-invisible-p2)))
5020 ;; "&" operator for tags.
5022 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5023 (org-match-sparse-tree nil
"tag1&tag2")
5024 (search-forward "H1")
5025 (org-invisible-p2)))
5027 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5028 (org-match-sparse-tree nil
"tag1&tag2")
5029 (search-forward "H2")
5030 (org-invisible-p2)))
5031 ;; "|" operator for tags.
5033 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5034 (org-match-sparse-tree nil
"tag1|tag2")
5035 (search-forward "H1")
5036 (org-invisible-p2)))
5038 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5039 (org-match-sparse-tree nil
"tag1|tag2")
5040 (search-forward "H2")
5041 (org-invisible-p2)))
5042 ;; Regexp match on tags.
5044 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5045 (org-match-sparse-tree nil
"{^tag.*}")
5046 (search-forward "H1")
5047 (org-invisible-p2)))
5049 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5050 (org-match-sparse-tree nil
"{^tag.*}")
5051 (search-forward "H2")
5052 (org-invisible-p2)))
5053 ;; Match group tags.
5055 (org-test-with-temp-text
5056 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5057 (org-match-sparse-tree nil
"work")
5058 (search-forward "H1")
5059 (org-invisible-p2)))
5061 (org-test-with-temp-text
5062 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5063 (org-match-sparse-tree nil
"work")
5064 (search-forward "H2")
5065 (org-invisible-p2)))
5066 ;; Match group tags with hard brackets.
5068 (org-test-with-temp-text
5069 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5070 (org-match-sparse-tree nil
"work")
5071 (search-forward "H1")
5072 (org-invisible-p2)))
5074 (org-test-with-temp-text
5075 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5076 (org-match-sparse-tree nil
"work")
5077 (search-forward "H2")
5078 (org-invisible-p2)))
5079 ;; Match tags in hierarchies
5081 (org-test-with-temp-text
5082 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5083 #+TAGS: [ Lev_2 : Lev_3 ]\n
5084 #+TAGS: { Lev_3 : Lev_4 }\n
5085 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5086 (org-match-sparse-tree nil
"Lev_1")
5087 (search-forward "H4")
5088 (org-invisible-p2)))
5089 ;; Match regular expressions in tags
5091 (org-test-with-temp-text
5092 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5093 (org-match-sparse-tree nil
"Lev")
5094 (search-forward "H1")
5095 (org-invisible-p2)))
5097 (org-test-with-temp-text
5098 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5099 (org-match-sparse-tree nil
"Lev")
5100 (search-forward "H1")
5101 (org-invisible-p2)))
5102 ;; Match properties.
5104 (org-test-with-temp-text
5105 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5106 (org-match-sparse-tree nil
"A=\"1\"")
5107 (search-forward "H2")
5108 (org-invisible-p2)))
5110 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5111 (org-match-sparse-tree nil
"A=\"1\"")
5112 (search-forward "H2")
5113 (org-invisible-p2)))
5114 ;; Case is not significant when matching properties.
5116 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5117 (org-match-sparse-tree nil
"a=\"1\"")
5118 (search-forward "H2")
5119 (org-invisible-p2)))
5121 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5122 (org-match-sparse-tree nil
"A=\"1\"")
5123 (search-forward "H2")
5124 (org-invisible-p2)))
5125 ;; Match special LEVEL property.
5127 (org-test-with-temp-text "* H\n** H1\n*** H2"
5128 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5129 (search-forward "H1")
5130 (org-invisible-p2)))
5132 (org-test-with-temp-text "* H\n** H1\n*** H2"
5133 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5134 (search-forward "H2")
5135 (org-invisible-p2)))
5136 ;; Comparison operators when matching properties.
5138 (org-test-with-temp-text
5139 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5140 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5141 (search-forward "H1")
5142 (org-invisible-p2)))
5144 (org-test-with-temp-text
5145 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5146 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5147 (search-forward "H2")
5148 (org-invisible-p2)))
5149 ;; Regexp match on properties values.
5151 (org-test-with-temp-text
5152 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5153 (org-match-sparse-tree nil
"A={f.*}")
5154 (search-forward "H1")
5155 (org-invisible-p2)))
5157 (org-test-with-temp-text
5158 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5159 (org-match-sparse-tree nil
"A={f.*}")
5160 (search-forward "H2")
5161 (org-invisible-p2)))
5162 ;; With an optional argument, limit match to TODO entries.
5164 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5165 (org-match-sparse-tree t
"tag")
5166 (search-forward "H1")
5167 (org-invisible-p2)))
5169 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5170 (org-match-sparse-tree t
"tag")
5171 (search-forward "H2")
5172 (org-invisible-p2))))
5174 (ert-deftest test-org
/occur
()
5175 "Test `org-occur' specifications."
5176 ;; Count number of matches.
5179 (org-test-with-temp-text "* H\nA\n* H2"
5183 (org-test-with-temp-text "* H\nA\n* H2\nA"
5185 ;; Test CALLBACK optional argument.
5188 (org-test-with-temp-text "* H\nA\n* H2"
5189 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5192 (org-test-with-temp-text "* H\nA\n* H2\nA"
5193 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5194 ;; Case-fold searches according to `org-occur-case-fold-search'.
5197 (org-test-with-temp-text "Aa"
5198 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5201 (org-test-with-temp-text "Aa"
5202 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5205 (org-test-with-temp-text "Aa"
5206 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5209 (org-test-with-temp-text "Aa"
5210 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5213 (org-test-with-temp-text "Aa"
5214 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5217 (org-test-with-temp-text "Aa"
5218 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5223 (ert-deftest test-org
/tag-string-to-alist
()
5224 "Test `org-tag-string-to-alist' specifications."
5225 ;; Tag without selection key.
5226 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5227 ;; Tag with selection key.
5228 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5232 (org-tag-string-to-alist "[ group : t1 t2 ]")
5233 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5234 ;; Mutually exclusive tags.
5235 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5236 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5239 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5240 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5242 (ert-deftest test-org
/tag-alist-to-string
()
5243 "Test `org-tag-alist-to-string' specifications."
5244 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5245 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5248 (org-tag-alist-to-string
5249 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5250 "[ group : t1 t2 ]"))
5252 (equal (org-tag-alist-to-string
5253 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5257 (org-tag-alist-to-string
5258 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5259 "{ group : tag1 tag2 }")))
5261 (ert-deftest test-org
/tag-alist-to-groups
()
5262 "Test `org-tag-alist-to-groups' specifications."
5264 (equal (org-tag-alist-to-groups
5265 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5266 '(("group" "t1" "t2"))))
5269 (org-tag-alist-to-groups
5270 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5271 '(("group" "t1" "t2"))))
5273 (org-tag-alist-to-groups
5274 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5276 (ert-deftest test-org
/tag-align
()
5277 "Test tags alignment."
5278 ;; Test aligning tags with different display width.
5280 ;; 12345678901234567890
5281 (equal "* Test :abc:"
5282 (org-test-with-temp-text "* Test :abc:"
5283 (let ((org-tags-column -
20)
5284 (indent-tabs-mode nil
))
5285 (org-fix-tags-on-the-fly))
5288 ;; 12345678901234567890
5289 (equal "* Test :日本語:"
5290 (org-test-with-temp-text "* Test :日本語:"
5291 (let ((org-tags-column -
20)
5292 (indent-tabs-mode nil
))
5293 (org-fix-tags-on-the-fly))
5295 ;; Make sure aligning tags do not skip invisible text.
5297 (equal "* [[linkx]] :tag:"
5298 (org-test-with-temp-text "* [[link<point>]] :tag:"
5299 (let ((org-tags-column 0))
5300 (org-fix-tags-on-the-fly)
5302 (buffer-string))))))
5304 (ert-deftest test-org
/tags-at
()
5306 (equal '("foo" "bar")
5307 (org-test-with-temp-text
5308 "* T<point>est :foo:bar:"
5309 (org-get-tags-at)))))
5314 (ert-deftest test-org
/auto-repeat-maybe
()
5315 "Test `org-auto-repeat-maybe' specifications."
5316 ;; Do not auto repeat when there is no valid time stamp with
5317 ;; a repeater in the entry.
5321 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5322 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5328 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5329 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5332 ;; When switching to DONE state, switch back to first TODO keyword
5333 ;; in sequence, or the same keyword if they have different types.
5337 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5338 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5344 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5345 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5351 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5352 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5355 ;; If there was no TODO keyword in the first place, do not insert
5360 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5361 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5364 ;; Revert to REPEAT_TO_STATE, if set.
5368 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5369 (org-test-with-temp-text
5372 :REPEAT_TO_STATE: KWD2
5374 <2012-03-29 Thu +2y>"
5377 ;; When switching to DONE state, update base date. If there are
5378 ;; multiple repeated time stamps, update them all.
5381 "<2014-03-29 .* \\+2y>"
5382 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5383 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5388 "<2015-03-04 .* \\+1y>"
5389 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5390 (org-test-with-temp-text
5391 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5394 ;; Throw an error if repeater unit is the hour and no time is
5395 ;; provided in the time-stamp.
5397 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5398 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5401 ;; Do not repeat commented time stamps.
5404 "<2015-03-04 .* \\+1y>"
5405 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5406 (org-test-with-temp-text
5407 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5412 "<2015-03-04 .* \\+1y>"
5413 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5414 (org-test-with-temp-text
5416 <2012-03-29 Thu. +2y>
5418 <2014-03-04 Tue +1y>
5422 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5423 ;; entry, record time of last repeat.
5427 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5428 (org-log-repeat nil
))
5429 (cl-letf (((symbol-function 'org-add-log-setup
)
5430 (lambda (&rest args
) nil
)))
5431 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5433 (buffer-string))))))
5437 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5439 (cl-letf (((symbol-function 'org-add-log-setup
)
5440 (lambda (&rest args
) nil
)))
5441 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5443 (buffer-string))))))
5447 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5448 (cl-letf (((symbol-function 'org-add-log-setup
)
5449 (lambda (&rest args
) nil
)))
5450 (org-test-with-temp-text
5451 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5453 (buffer-string))))))
5454 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5455 ;; the entry as it is no longer relevant.
5459 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5460 (org-test-with-temp-text
5461 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5463 (buffer-string))))))
5468 (ert-deftest test-org
/at-timestamp-p
()
5469 "Test `org-at-timestamp-p' specifications."
5471 (org-test-with-temp-text "<2012-03-29 Thu>"
5472 (org-at-timestamp-p)))
5474 (org-test-with-temp-text "2012-03-29 Thu"
5475 (org-at-timestamp-p)))
5476 ;; Test return values.
5479 (org-test-with-temp-text "<2012-03-29 Thu>"
5480 (org-at-timestamp-p))))
5483 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5484 (org-at-timestamp-p))))
5487 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5488 (org-at-timestamp-p))))
5491 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5492 (org-at-timestamp-p))))
5495 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5496 (org-at-timestamp-p))))
5499 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5500 (org-at-timestamp-p))))
5503 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5504 (org-at-timestamp-p))))
5507 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5508 (org-at-timestamp-p))))
5509 ;; Test optional argument.
5511 (org-test-with-temp-text "[2012-03-29 Thu]"
5512 (org-at-timestamp-p t
)))
5514 (org-test-with-temp-text "[2012-03-29 Thu]"
5515 (org-at-timestamp-p)))
5516 ;; Unlike `org-element-context', recognize time-stamps in planning
5517 ;; info line, property drawers and clocks.
5519 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5520 (org-at-timestamp-p)))
5522 (org-test-with-temp-text
5523 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5524 (org-at-timestamp-p)))
5526 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5527 (org-at-timestamp-p t
))))
5529 (ert-deftest test-org
/time-stamp
()
5530 "Test `org-time-stamp' specifications."
5531 ;; Insert chosen time stamp at point.
5534 "Te<2014-03-04 .*?>xt"
5535 (org-test-with-temp-text "Te<point>xt"
5536 (cl-letf (((symbol-function 'org-read-date
)
5537 (lambda (&rest args
)
5538 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5539 (org-time-stamp nil
)
5541 ;; With a prefix argument, also insert time.
5544 "Te<2014-03-04 .*? 00:41>xt"
5545 (org-test-with-temp-text "Te<point>xt"
5546 (cl-letf (((symbol-function 'org-read-date
)
5547 (lambda (&rest args
)
5548 (apply #'encode-time
5549 (org-parse-time-string "2014-03-04 00:41")))))
5550 (org-time-stamp '(4))
5552 ;; With two universal prefix arguments, insert an active timestamp
5553 ;; with the current time without prompting the user.
5556 "Te<2014-03-04 .*? 00:41>xt"
5557 (org-test-with-temp-text "Te<point>xt"
5558 (cl-letf (((symbol-function 'current-time
)
5560 (apply #'encode-time
5561 (org-parse-time-string "2014-03-04 00:41")))))
5562 (org-time-stamp '(16))
5564 ;; When optional argument is non-nil, insert an inactive timestamp.
5567 "Te\\[2014-03-04 .*?\\]xt"
5568 (org-test-with-temp-text "Te<point>xt"
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 t
)
5574 ;; When called from a timestamp, replace existing one.
5578 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5579 (cl-letf (((symbol-function 'org-read-date
)
5580 (lambda (&rest args
)
5581 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5582 (org-time-stamp nil
)
5586 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5587 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5588 (cl-letf (((symbol-function 'org-read-date
)
5589 (lambda (&rest args
)
5590 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5591 (org-time-stamp nil
)
5593 ;; When replacing a timestamp, preserve repeater, if any.
5596 "<2014-03-04 .*? \\+2y>"
5597 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5598 (cl-letf (((symbol-function 'org-read-date
)
5599 (lambda (&rest args
)
5600 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5601 (org-time-stamp nil
)
5603 ;; When called twice in a raw, build a date range.
5606 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5607 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5608 (cl-letf (((symbol-function 'org-read-date
)
5609 (lambda (&rest args
)
5610 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5611 (let ((last-command 'org-time-stamp
)
5612 (this-command 'org-time-stamp
))
5613 (org-time-stamp nil
))
5614 (buffer-string))))))
5616 (ert-deftest test-org
/timestamp-has-time-p
()
5617 "Test `org-timestamp-has-time-p' specifications."
5620 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5621 (org-timestamp-has-time-p (org-element-context))))
5624 (org-test-with-temp-text "<2012-03-29 Thu>"
5625 (org-timestamp-has-time-p (org-element-context)))))
5627 (ert-deftest test-org
/get-repeat
()
5628 "Test `org-get-repeat' specifications."
5630 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
5633 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
5635 ;; Return proper repeat string.
5638 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
5640 ;; Prevent false positive (commented or verbatim time stamps)
5642 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
5645 (org-test-with-temp-text
5646 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
5648 ;; Return nil when called before first heading.
5650 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
5652 ;; When called with an optional argument, extract repeater from that
5654 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
5655 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
5657 (ert-deftest test-org
/timestamp-format
()
5658 "Test `org-timestamp-format' specifications."
5663 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5664 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5669 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5670 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5672 (ert-deftest test-org
/timestamp-split-range
()
5673 "Test `org-timestamp-split-range' specifications."
5674 ;; Extract range start (active).
5677 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5678 (let ((ts (org-timestamp-split-range (org-element-context))))
5679 (mapcar (lambda (p) (org-element-property p ts
))
5680 '(:year-end
:month-end
:day-end
))))))
5681 ;; Extract range start (inactive)
5684 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5685 (let ((ts (org-timestamp-split-range (org-element-context))))
5686 (mapcar (lambda (p) (org-element-property p ts
))
5687 '(:year-end
:month-end
:day-end
))))))
5688 ;; Extract range end (active).
5691 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5692 (let ((ts (org-timestamp-split-range
5693 (org-element-context) t
)))
5694 (mapcar (lambda (p) (org-element-property p ts
))
5695 '(:year-end
:month-end
:day-end
))))))
5696 ;; Extract range end (inactive)
5699 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5700 (let ((ts (org-timestamp-split-range
5701 (org-element-context) t
)))
5702 (mapcar (lambda (p) (org-element-property p ts
))
5703 '(:year-end
:month-end
:day-end
))))))
5704 ;; Return the timestamp if not a range.
5706 (org-test-with-temp-text "[2012-03-29 Thu]"
5707 (let* ((ts-orig (org-element-context))
5708 (ts-copy (org-timestamp-split-range ts-orig
)))
5709 (eq ts-orig ts-copy
))))
5711 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5712 (let* ((ts-orig (org-element-context))
5713 (ts-copy (org-timestamp-split-range ts-orig
)))
5714 (eq ts-orig ts-copy
)))))
5716 (ert-deftest test-org
/timestamp-translate
()
5717 "Test `org-timestamp-translate' specifications."
5718 ;; Translate whole date range.
5721 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5722 (let ((org-display-custom-times t
)
5723 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5724 (org-timestamp-translate (org-element-context))))))
5725 ;; Translate date range start.
5728 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5729 (let ((org-display-custom-times t
)
5730 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5731 (org-timestamp-translate (org-element-context) 'start
)))))
5732 ;; Translate date range end.
5735 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5736 (let ((org-display-custom-times t
)
5737 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5738 (org-timestamp-translate (org-element-context) 'end
)))))
5739 ;; Translate time range.
5742 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5743 (let ((org-display-custom-times t
)
5744 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5745 (org-timestamp-translate (org-element-context))))))
5746 ;; Translate non-range timestamp.
5749 (org-test-with-temp-text "<2012-03-29 Thu>"
5750 (let ((org-display-custom-times t
)
5751 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5752 (org-timestamp-translate (org-element-context))))))
5753 ;; Do not change `diary' timestamps.
5755 (equal "<%%(org-float t 4 2)>"
5756 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5757 (let ((org-display-custom-times t
)
5758 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5759 (org-timestamp-translate (org-element-context)))))))
5765 (ert-deftest test-org
/flag-drawer
()
5766 "Test `org-flag-drawer' specifications."
5769 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5771 (get-char-property (line-end-position) 'invisible
)))
5774 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5776 (org-flag-drawer nil
)
5777 (get-char-property (line-end-position) 'invisible
)))
5778 ;; Test optional argument.
5780 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5781 (let ((drawer (save-excursion (search-forward ":D2")
5782 (org-element-at-point))))
5783 (org-flag-drawer t drawer
)
5784 (get-char-property (progn (search-forward ":D2") (line-end-position))
5787 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5788 (let ((drawer (save-excursion (search-forward ":D2")
5789 (org-element-at-point))))
5790 (org-flag-drawer t drawer
)
5791 (get-char-property (line-end-position) 'invisible
))))
5792 ;; Do not hide fake drawers.
5794 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5797 (get-char-property (line-end-position) 'invisible
)))
5798 ;; Do not hide incomplete drawers.
5800 (org-test-with-temp-text ":D:\nparagraph"
5803 (get-char-property (line-end-position) 'invisible
)))
5804 ;; Do not hide drawers when called from final blank lines.
5806 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5807 (goto-char (point-max))
5809 (goto-char (point-min))
5810 (get-char-property (line-end-position) 'invisible
)))
5811 ;; Don't leave point in an invisible part of the buffer when hiding
5814 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5815 (goto-char (point-max))
5817 (get-char-property (point) 'invisible
))))
5819 (ert-deftest test-org
/hide-block-toggle
()
5820 "Test `org-hide-block-toggle' specifications."
5821 ;; Error when not at a block.
5823 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5824 (org-hide-block-toggle 'off
)
5825 (get-char-property (line-end-position) 'invisible
)))
5828 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5829 (org-hide-block-toggle)
5830 (get-char-property (line-end-position) 'invisible
)))
5832 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5833 (org-hide-block-toggle)
5834 (get-char-property (line-end-position) 'invisible
)))
5835 ;; Show block unconditionally when optional argument is `off'.
5837 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5838 (org-hide-block-toggle)
5839 (org-hide-block-toggle 'off
)
5840 (get-char-property (line-end-position) 'invisible
)))
5842 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5843 (org-hide-block-toggle 'off
)
5844 (get-char-property (line-end-position) 'invisible
)))
5845 ;; Hide block unconditionally when optional argument is non-nil.
5847 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5848 (org-hide-block-toggle t
)
5849 (get-char-property (line-end-position) 'invisible
)))
5851 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5852 (org-hide-block-toggle)
5853 (org-hide-block-toggle t
)
5854 (get-char-property (line-end-position) 'invisible
)))
5855 ;; Do not hide block when called from final blank lines.
5857 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5858 (org-hide-block-toggle)
5859 (goto-char (point-min))
5860 (get-char-property (line-end-position) 'invisible
)))
5861 ;; Don't leave point in an invisible part of the buffer when hiding
5864 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5865 (org-hide-block-toggle)
5866 (get-char-property (point) 'invisible
))))
5868 (ert-deftest test-org
/hide-block-toggle-maybe
()
5869 "Test `org-hide-block-toggle-maybe' specifications."
5871 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5872 (org-hide-block-toggle-maybe)))
5874 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5876 (ert-deftest test-org
/set-tags
()
5877 "Test `org-set-tags' specifications."
5878 ;; Tags set via fast-tag-selection should be visible afterwards
5880 (let ((org-tag-alist '(("NEXT" . ?n
)))
5881 (org-fast-tag-selection-single-key t
))
5882 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5883 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5884 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5885 ;; Show only headlines
5887 ;; Set NEXT tag on current entry
5888 (org-set-tags nil nil
)
5889 ;; Move point to that NEXT tag
5890 (search-forward "NEXT") (backward-word)
5891 ;; And it should be visible (i.e. no overlays)
5892 (not (overlays-at (point))))))))
5894 (ert-deftest test-org
/show-set-visibility
()
5895 "Test `org-show-set-visibility' specifications."
5896 ;; Do not throw an error before first heading.
5898 (org-test-with-temp-text "Preamble\n* Headline"
5899 (org-show-set-visibility 'tree
)
5901 ;; Test all visibility spans, both on headline and in entry.
5902 (let ((list-visible-lines
5903 (lambda (state headerp
)
5904 (org-test-with-temp-text "* Grandmother (0)
5915 **** The other child (11)
5920 (search-forward (if headerp
"Self" "Match"))
5921 (org-show-set-visibility state
)
5922 (goto-char (point-min))
5923 (let (result (line 0))
5925 (unless (org-invisible-p2) (push line result
))
5928 (nreverse result
))))))
5929 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5930 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5931 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5932 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5933 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5934 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5935 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5936 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5937 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5938 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5939 (funcall list-visible-lines
'tree nil
)))
5940 (should (equal '(0 1 3 4 5 7 12 13)
5941 (funcall list-visible-lines
'canonical t
)))
5942 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5943 (funcall list-visible-lines
'canonical nil
))))
5944 ;; When point is hidden in a drawer or a block, make sure to make it
5947 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5948 (org-hide-block-toggle)
5949 (search-forward "Text")
5950 (org-show-set-visibility 'minimal
)
5951 (org-invisible-p2)))
5953 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5955 (search-forward "Text")
5956 (org-show-set-visibility 'minimal
)
5957 (org-invisible-p2)))
5959 (org-test-with-temp-text
5960 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5963 (org-hide-block-toggle)
5964 (search-forward "Text")
5965 (org-show-set-visibility 'minimal
)
5966 (org-invisible-p2))))
5971 ;;; test-org.el ends here