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"))))))
403 (ert-deftest test-org
/get-repeat
()
404 (org-test-with-temp-text
405 "* H\nSCHEDULED: <2017-02-03 Fri .+23d>"
406 (should (string= ".+23d" (org-get-repeat)))))
411 (ert-deftest test-org
/insert-property-drawer
()
412 "Test `org-insert-property-drawer' specifications."
413 ;; Error before first headline.
414 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
415 ;; Insert drawer right after headline if there is no planning line,
416 ;; or after it otherwise.
418 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
419 (org-test-with-temp-text "* H\nParagraph<point>"
420 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
423 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
424 (org-test-with-temp-text
425 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
426 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
428 ;; Indent inserted drawer.
430 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
431 (org-test-with-temp-text "* H\nParagraph<point>"
432 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
434 ;; Handle insertion at eob.
436 (equal "* H\n:PROPERTIES:\n:END:\n"
437 (org-test-with-temp-text "* H"
438 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
440 ;; Skip inlinetasks before point.
441 (when (featurep 'org-inlinetask
)
443 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
444 (org-test-with-temp-text
445 "* H\n*************** I\n*************** END\nP<point>"
446 (let ((org-adapt-indentation nil
)
447 (org-inlinetask-min-level 15))
448 (org-insert-property-drawer))
450 ;; Correctly set drawer in an inlinetask.
451 (when (featurep 'org-inlinetask
)
453 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
454 (org-test-with-temp-text
455 "* H\n*************** I\nP<point>\n*************** END"
456 (let ((org-adapt-indentation nil
)
457 (org-inlinetask-min-level 15))
458 (org-insert-property-drawer))
464 (ert-deftest test-org
/fill-paragraph
()
465 "Test `org-fill-paragraph' specifications."
466 ;; At an Org table, align it.
469 (org-test-with-temp-text "|a|"
473 (equal "#+name: table\n| a |\n"
474 (org-test-with-temp-text "#+name: table\n| a |\n"
477 ;; At a paragraph, preserve line breaks.
478 (org-test-with-temp-text "some \\\\\nlong\ntext"
479 (let ((fill-column 20))
481 (should (equal (buffer-string) "some \\\\\nlong text"))))
482 ;; Correctly fill a paragraph when point is at its very end.
485 (org-test-with-temp-text "A\nB"
486 (let ((fill-column 20))
487 (goto-char (point-max))
490 ;; Correctly fill the last paragraph of a greater element.
492 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
493 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
494 (let ((fill-column 8))
499 ;; Correctly fill an element in a narrowed buffer.
502 (org-test-with-temp-text "01234 6789"
503 (let ((fill-column 5))
504 (narrow-to-region 1 8)
507 ;; Handle `adaptive-fill-regexp' in paragraphs.
510 (org-test-with-temp-text "> a\n> b"
511 (let ((fill-column 5)
512 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
515 ;; Special case: Fill first paragraph when point is at an item or
516 ;; a plain-list or a footnote reference.
519 (org-test-with-temp-text "- A\n B"
520 (let ((fill-column 20))
525 (org-test-with-temp-text "[fn:1] A\nB"
526 (let ((fill-column 20))
529 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
530 (let ((fill-column 20))
532 (should (equal (buffer-string)
533 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
534 ;; Fill contents of `comment-block' elements.
537 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
538 (let ((fill-column 20))
542 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
543 ;; Fill `comment' elements.
546 (org-test-with-temp-text " # A\n # B"
547 (let ((fill-column 20))
550 ;; Do not mix consecutive comments when filling one of them.
552 (equal "# A B\n\n# C"
553 (org-test-with-temp-text "# A\n# B\n\n# C"
554 (let ((fill-column 20))
557 ;; Use commented empty lines as separators when filling comments.
559 (equal "# A B\n#\n# C"
560 (org-test-with-temp-text "# A\n# B\n#\n# C"
561 (let ((fill-column 20))
564 ;; Handle `adaptive-fill-regexp' in comments.
567 (org-test-with-temp-text "# > a\n# > b"
568 (let ((fill-column 20)
569 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
572 ;; Do nothing at affiliated keywords.
573 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
574 (let ((fill-column 20))
576 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
577 ;; Do not move point after table when filling a table.
579 (org-test-with-temp-text "| a | b |\n| c | d |\n"
584 (ert-deftest test-org
/auto-fill-function
()
585 "Test auto-filling features."
586 ;; Auto fill paragraph.
589 (org-test-with-temp-text "12345 7890"
590 (let ((fill-column 5))
592 (org-auto-fill-function)
594 ;; Auto fill first paragraph in an item.
596 (equal "- 12345\n 7890"
597 (org-test-with-temp-text "- 12345 7890"
598 (let ((fill-column 7))
600 (org-auto-fill-function)
602 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
604 (equal "> 12345\n 7890"
605 (org-test-with-temp-text "> 12345 7890"
606 (let ((fill-column 10)
607 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
608 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
610 (org-auto-fill-function)
613 (equal "> 12345\n> 12345\n> 7890"
614 (org-test-with-temp-text "> 12345\n> 12345 7890"
615 (let ((fill-column 10)
616 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
617 (goto-char (point-max))
618 (org-auto-fill-function)
621 (equal " 12345\n *12345\n *12345"
622 (org-test-with-temp-text " 12345\n *12345 12345"
623 (let ((fill-column 10)
624 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
625 (goto-char (point-max))
626 (org-auto-fill-function)
628 ;; Auto fill comments.
630 (equal " # 12345\n # 7890"
631 (org-test-with-temp-text " # 12345 7890"
632 (let ((fill-column 10))
634 (org-auto-fill-function)
636 ;; A hash within a line isn't a comment.
638 (equal "12345 # 7890\n# 1"
639 (org-test-with-temp-text "12345 # 7890 1"
640 (let ((fill-column 12))
642 (org-auto-fill-function)
644 ;; Correctly interpret empty prefix.
646 (equal "# a\n# b\nRegular\n# paragraph"
647 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
648 (let ((fill-column 12))
650 (org-auto-fill-function)
652 ;; Comment block: auto fill contents.
654 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
655 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
656 (let ((fill-column 5))
659 (org-auto-fill-function)
662 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
663 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
664 (let ((fill-column 5))
667 (org-auto-fill-function)
669 ;; Do not fill if a new item could be created.
672 (org-test-with-temp-text "12345 - 90"
673 (let ((fill-column 5))
675 (org-auto-fill-function)
677 ;; Do not fill if a line break could be introduced.
679 (equal "123\\\\\n7890"
680 (org-test-with-temp-text "123\\\\ 7890"
681 (let ((fill-column 6))
683 (org-auto-fill-function)
685 ;; Do not fill affiliated keywords.
687 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
688 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
689 (let ((fill-column 20))
691 (org-auto-fill-function)
698 (ert-deftest test-org
/indent-line
()
699 "Test `org-indent-line' specifications."
700 ;; Do not indent diary sexps, footnote definitions or headlines.
703 (org-test-with-temp-text "%%(org-calendar-holiday)"
705 (org-get-indentation))))
708 (org-test-with-temp-text "[fn:1] fn"
709 (let ((org-adapt-indentation t
)) (org-indent-line))
710 (org-get-indentation))))
713 (org-test-with-temp-text "* H"
715 (org-get-indentation))))
716 ;; Do not indent before first headline.
719 (org-test-with-temp-text ""
721 (org-get-indentation))))
722 ;; Indent according to headline level otherwise, unless
723 ;; `org-adapt-indentation' is nil.
726 (org-test-with-temp-text "* H\n<point>A"
727 (let ((org-adapt-indentation t
)) (org-indent-line))
728 (org-get-indentation))))
731 (org-test-with-temp-text "* H\n<point>\nA"
732 (let ((org-adapt-indentation t
)) (org-indent-line))
733 (org-get-indentation))))
736 (org-test-with-temp-text "* H\n<point>A"
737 (let ((org-adapt-indentation nil
)) (org-indent-line))
738 (org-get-indentation))))
739 ;; Indenting preserves point position.
741 (org-test-with-temp-text "* H\nA<point>B"
742 (let ((org-adapt-indentation t
)) (org-indent-line))
744 ;; Do not change indentation at an item or a LaTeX environment.
747 (org-test-with-temp-text "* H\n<point> - A"
748 (let ((org-adapt-indentation t
)) (org-indent-line))
749 (org-get-indentation))))
752 (org-test-with-temp-text
753 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
755 (org-get-indentation))))
756 ;; On blank lines at the end of a list, indent like last element
757 ;; within it if the line is still in the list. If the last element
758 ;; is an item, indent like its contents. Otherwise, indent like the
762 (org-test-with-temp-text "* H\n- A\n - AA\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 -\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 - AA\n\n\n\n<point>"
773 (let ((org-adapt-indentation t
)) (org-indent-line))
774 (org-get-indentation))))
777 (org-test-with-temp-text "* H\n- A\n - \n<point>"
778 (let ((org-adapt-indentation t
)) (org-indent-line))
779 (org-get-indentation))))
782 (org-test-with-temp-text
783 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
784 (let ((org-adapt-indentation t
)) (org-indent-line))
785 (org-get-indentation))))
788 (org-test-with-temp-text "- A\n B\n\n<point>"
789 (let ((org-adapt-indentation nil
)) (org-indent-line))
790 (org-get-indentation))))
791 ;; Likewise, on a blank line at the end of a footnote definition,
792 ;; indent at column 0 if line belongs to the definition. Otherwise,
793 ;; indent like the definition itself.
796 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
797 (goto-char (point-max))
798 (let ((org-adapt-indentation t
)) (org-indent-line))
799 (org-get-indentation))))
802 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
803 (goto-char (point-max))
804 (let ((org-adapt-indentation t
)) (org-indent-line))
805 (org-get-indentation))))
806 ;; After the end of the contents of a greater element, indent like
807 ;; the beginning of the element.
810 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
813 (org-get-indentation))))
814 ;; On blank lines after a paragraph, indent like its last non-empty
818 (org-test-with-temp-text " Paragraph\n\n<point>"
820 (org-get-indentation))))
821 ;; At the first line of an element, indent like previous element's
822 ;; first line, ignoring footnotes definitions and inline tasks, or
823 ;; according to parent.
826 (org-test-with-temp-text "A\n\n B\n\nC"
827 (goto-char (point-max))
829 (org-get-indentation))))
832 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
833 (goto-char (point-max))
835 (org-get-indentation))))
838 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
841 (org-get-indentation))))
842 ;; Within code part of a source block, use language major mode if
843 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
844 ;; according to line above.
847 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
849 (let ((org-src-tab-acts-natively t
)
850 (org-edit-src-content-indentation 0))
852 (org-get-indentation))))
855 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
857 (let ((org-src-tab-acts-natively nil
)
858 (org-edit-src-content-indentation 0))
860 (org-get-indentation))))
861 ;; Otherwise, indent like the first non-blank line above.
864 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
867 (org-get-indentation))))
868 ;; Align node properties according to `org-property-format'. Handle
869 ;; nicely empty values.
871 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
872 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
873 (let ((org-property-format "%-10s %s")) (org-indent-line))
876 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
877 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
878 (let ((org-property-format "%-10s %s")) (org-indent-line))
881 (ert-deftest test-org
/indent-region
()
882 "Test `org-indent-region' specifications."
886 (org-test-with-temp-text " A\nB\n C"
887 (org-indent-region (point-min) (point-max))
889 ;; Indent greater elements along with their contents.
891 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
892 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
893 (org-indent-region (point-min) (point-max))
895 ;; Ignore contents of verse blocks. Only indent block delimiters.
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))
902 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
903 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
904 (org-indent-region (point-min) (point-max))
906 ;; Indent example blocks as a single block, unless indentation
907 ;; should be preserved. In this case only indent the block markers.
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\n A\n B\n#+END_EXAMPLE"
915 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
916 (org-indent-region (point-min) (point-max))
919 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
920 (org-test-with-temp-text
921 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
922 (org-indent-region (point-min) (point-max))
925 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
926 (org-test-with-temp-text
927 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
928 (let ((org-src-preserve-indentation t
))
929 (org-indent-region (point-min) (point-max)))
931 ;; Treat export blocks as a whole.
933 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
934 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
935 (org-indent-region (point-min) (point-max))
938 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
939 (org-test-with-temp-text
940 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
941 (org-indent-region (point-min) (point-max))
943 ;; Indent according to mode if `org-src-tab-acts-natively' is
944 ;; non-nil. Otherwise, do not indent code at all.
946 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
947 (org-test-with-temp-text
948 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
949 (let ((org-src-tab-acts-natively t
)
950 (org-edit-src-content-indentation 0))
951 (org-indent-region (point-min) (point-max)))
954 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
955 (org-test-with-temp-text
956 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
957 (let ((org-src-tab-acts-natively nil
)
958 (org-edit-src-content-indentation 0))
959 (org-indent-region (point-min) (point-max)))
961 ;; Align node properties according to `org-property-format'. Handle
962 ;; nicely empty values.
964 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
965 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
966 (let ((org-property-format "%-10s %s")
967 (org-adapt-indentation nil
))
968 (org-indent-region (point) (point-max)))
971 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
972 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
973 (let ((org-property-format "%-10s %s")
974 (org-adapt-indentation nil
))
975 (org-indent-region (point) (point-max)))
977 ;; Indent plain lists.
979 (equal "- A\n B\n - C\n\n D"
980 (org-test-with-temp-text "- A\n B\n - C\n\n D"
981 (org-indent-region (point-min) (point-max))
985 (org-test-with-temp-text " - A\n\n - B"
986 (org-indent-region (point-min) (point-max))
988 ;; Indent footnote definitions.
990 (equal "[fn:1] Definition\n\nDefinition"
991 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
992 (org-indent-region (point-min) (point-max))
994 ;; Special case: Start indenting on a blank line.
997 (org-test-with-temp-text "\n Paragraph"
998 (org-indent-region (point-min) (point-max))
1005 (ert-deftest test-org
/delete-indentation
()
1006 "Test `org-delete-indentation' specifications."
1008 (should (equal "foo bar"
1009 (org-test-with-temp-text
1011 (org-delete-indentation)
1013 ;; With optional argument.
1014 (should (equal "foo bar"
1015 (org-test-with-temp-text
1017 (org-delete-indentation t
)
1019 ;; At headline text should be appended to the headline text.
1021 (equal"* foo bar :tag:"
1022 (let (org-auto-align-tags)
1023 (org-test-with-temp-text
1024 "* foo :tag:\n bar<point>"
1025 (org-delete-indentation)
1028 (equal "* foo bar :tag:"
1029 (let (org-auto-align-tags)
1030 (org-test-with-temp-text
1031 "* foo <point>:tag:\n bar"
1032 (org-delete-indentation t
)
1033 (buffer-string))))))
1035 (ert-deftest test-org
/return
()
1036 "Test `org-return' specifications."
1039 (equal "Para\ngraph"
1040 (org-test-with-temp-text "Para<point>graph"
1043 ;; With optional argument, indent line.
1045 (equal " Para\n graph"
1046 (org-test-with-temp-text " Para<point>graph"
1049 ;; On a table, call `org-table-next-row'.
1051 (org-test-with-temp-text "| <point>a |\n| b |"
1053 (looking-at-p "b")))
1054 ;; Open link or timestamp under point when `org-return-follows-link'
1057 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1058 (let ((org-return-follows-link t
)
1059 (org-link-search-must-match-exact-headline nil
))
1061 (looking-at-p "<<target>>")))
1063 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1064 (let ((org-return-follows-link nil
)) (org-return))
1065 (looking-at-p "<<target>>")))
1067 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1068 (let ((org-return-follows-link t
)) (org-return))
1069 (looking-at-p "* b")))
1071 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1072 (let ((org-return-follows-link t
)
1073 (org-link-search-must-match-exact-headline nil
))
1075 (looking-at-p "<<target>>")))
1077 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1078 (let ((org-return-follows-link t
)
1079 (org-link-search-must-match-exact-headline nil
))
1081 (looking-at-p "<<target>>")))
1082 ;; When `org-return-follows-link' is non-nil, tolerate links and
1083 ;; timestamps in comments, node properties, etc.
1085 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1086 (let ((org-return-follows-link t
)
1087 (org-link-search-must-match-exact-headline nil
))
1089 (looking-at-p "<<target>>")))
1091 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1092 (let ((org-return-follows-link nil
)) (org-return))
1093 (looking-at-p "<<target>>")))
1095 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1096 (let ((org-return-follows-link t
)
1097 (org-link-search-must-match-exact-headline nil
))
1099 (looking-at-p "<<target>>")))
1100 ;; However, do not open link when point is in a table.
1102 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1103 (let ((org-return-follows-link t
)) (org-return))
1104 (looking-at-p "between")))
1105 ;; Special case: in a list, when indenting, do not break structure.
1108 (org-test-with-temp-text "- A <point>B"
1113 (org-test-with-temp-text "- A\n<point>- B"
1116 ;; On tags part of a headline, add a newline below it instead of
1119 (equal "* H :tag:\n"
1120 (org-test-with-temp-text "* H :<point>tag:"
1123 ;; Before headline text, add a newline below it instead of breaking
1126 (equal "* TODO H :tag:\n"
1127 (org-test-with-temp-text "* <point>TODO H :tag:"
1131 (equal "* TODO [#B] H :tag:\n"
1132 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1135 (should ;TODO are case-sensitive
1137 (org-test-with-temp-text "* <point>Todo"
1140 ;; At headline text, break headline text but preserve tags.
1142 (equal "* TODO [#B] foo :tag:\nbar"
1143 (let (org-auto-align-tags)
1144 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1147 ;; At bol of headline insert newline.
1150 (org-test-with-temp-text "<point>* h"
1153 ;; Refuse to leave invalid headline in buffer.
1156 (org-test-with-temp-text "*<point> h"
1160 (ert-deftest test-org
/meta-return
()
1161 "Test M-RET (`org-meta-return') specifications."
1162 ;; In a table field insert a row above.
1164 (org-test-with-temp-text "| a |"
1168 (looking-at "| |$")))
1169 ;; In a paragraph change current line into a header.
1171 (org-test-with-temp-text "a"
1174 (looking-at "\* a$")))
1175 ;; In an item insert an item, in this case above.
1177 (org-test-with-temp-text "- a"
1180 (looking-at "- $")))
1181 ;; In a drawer and item insert an item, in this case above.
1183 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1187 (looking-at "- $"))))
1189 (ert-deftest test-org
/insert-heading
()
1190 "Test `org-insert-heading' specifications."
1191 ;; In an empty buffer, insert a new headline.
1194 (org-test-with-temp-text ""
1195 (org-insert-heading)
1197 ;; At the beginning of a line, turn it into a headline.
1200 (org-test-with-temp-text "<point>P"
1201 (org-insert-heading)
1203 ;; In the middle of a line, split the line if allowed, otherwise,
1204 ;; insert the headline at its end.
1206 (equal "Para\n* graph"
1207 (org-test-with-temp-text "Para<point>graph"
1208 (let ((org-M-RET-may-split-line '((default . t
))))
1209 (org-insert-heading))
1212 (equal "Paragraph\n* "
1213 (org-test-with-temp-text "Para<point>graph"
1214 (let ((org-M-RET-may-split-line '((default . nil
))))
1215 (org-insert-heading))
1217 ;; At the beginning of a headline, create one above.
1220 (org-test-with-temp-text "* H"
1221 (org-insert-heading)
1223 ;; In the middle of a headline, split it if allowed.
1226 (org-test-with-temp-text "* H<point>1"
1227 (let ((org-M-RET-may-split-line '((headline . t
))))
1228 (org-insert-heading))
1232 (org-test-with-temp-text "* H<point>1"
1233 (let ((org-M-RET-may-split-line '((headline . nil
))))
1234 (org-insert-heading))
1236 ;; However, splitting cannot happen on TODO keywords, priorities or
1239 (equal "* TODO H1\n* \n"
1240 (org-test-with-temp-text "* TO<point>DO H1"
1241 (let ((org-M-RET-may-split-line '((headline . t
))))
1242 (org-insert-heading))
1245 (equal "* [#A] H1\n* \n"
1246 (org-test-with-temp-text "* [#<point>A] H1"
1247 (let ((org-M-RET-may-split-line '((headline . t
))))
1248 (org-insert-heading))
1251 (equal "* H1 :tag:\n* \n"
1252 (org-test-with-temp-text "* H1 :ta<point>g:"
1253 (let ((org-M-RET-may-split-line '((headline . t
))))
1254 (org-insert-heading))
1256 ;; New headline level depends on the level of the headline above.
1259 (org-test-with-temp-text "** H\n<point>P"
1260 (org-insert-heading)
1263 (equal "** H\nPara\n** graph"
1264 (org-test-with-temp-text "** H\nPara<point>graph"
1265 (let ((org-M-RET-may-split-line '((default . t
))))
1266 (org-insert-heading))
1270 (org-test-with-temp-text "** H"
1271 (org-insert-heading)
1273 ;; When called with one universal argument, insert a new headline at
1274 ;; the end of the current subtree, independently on the position of
1279 (org-test-with-temp-text "* H1\n** H2"
1280 (let ((org-insert-heading-respect-content nil
))
1281 (org-insert-heading '(4)))
1286 (org-test-with-temp-text "* H<point>1\n** H2"
1287 (let ((org-insert-heading-respect-content nil
))
1288 (org-insert-heading '(4)))
1290 ;; When called with two universal arguments, insert a new headline
1291 ;; at the end of the grandparent subtree.
1293 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1294 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1295 (let ((org-insert-heading-respect-content nil
))
1296 (org-insert-heading '(16)))
1298 ;; When optional TOP-LEVEL argument is non-nil, always insert
1299 ;; a level 1 heading.
1301 (equal "* H1\n** H2\n* \n"
1302 (org-test-with-temp-text "* H1\n** H2<point>"
1303 (org-insert-heading nil nil t
)
1306 (equal "* H1\n- item\n* "
1307 (org-test-with-temp-text "* H1\n- item<point>"
1308 (org-insert-heading nil nil t
)
1310 ;; Obey `org-blank-before-new-entry'.
1312 (equal "* H1\n\n* \n"
1313 (org-test-with-temp-text "* H1<point>"
1314 (let ((org-blank-before-new-entry '((heading . t
))))
1315 (org-insert-heading))
1319 (org-test-with-temp-text "* H1<point>"
1320 (let ((org-blank-before-new-entry '((heading . nil
))))
1321 (org-insert-heading))
1324 (equal "* H1\n* H2\n* \n"
1325 (org-test-with-temp-text "* H1\n* H2<point>"
1326 (let ((org-blank-before-new-entry '((heading . auto
))))
1327 (org-insert-heading))
1330 (equal "* H1\n\n* H2\n\n* \n"
1331 (org-test-with-temp-text "* H1\n\n* H2<point>"
1332 (let ((org-blank-before-new-entry '((heading . auto
))))
1333 (org-insert-heading))
1335 ;; Corner case: correctly insert a headline after an empty one.
1338 (org-test-with-temp-text "* <point>"
1339 (org-insert-heading)
1342 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1343 "Test `org-insert-todo-heading-respect-content' specifications."
1344 ;; Create a TODO heading.
1346 (org-test-with-temp-text "* H1\n Body"
1347 (org-insert-todo-heading-respect-content)
1348 (nth 2 (org-heading-components))))
1349 ;; Add headline at the end of the first subtree
1353 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1354 (org-insert-todo-heading-respect-content)
1355 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1356 ;; In a list, do not create a new item.
1360 (org-test-with-temp-text "* H\n- an item\n- another one"
1361 (search-forward "an ")
1362 (org-insert-todo-heading-respect-content)
1363 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1365 (ert-deftest test-org
/clone-with-time-shift
()
1366 "Test `org-clone-subtree-with-time-shift'."
1367 ;; Raise an error before first heading.
1369 (org-test-with-temp-text ""
1370 (org-clone-subtree-with-time-shift 1)))
1371 ;; Raise an error on invalid number of clones.
1373 (org-test-with-temp-text "* Clone me"
1374 (org-clone-subtree-with-time-shift -
1)))
1375 ;; Clone non-repeating once.
1381 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1382 (org-clone-subtree-with-time-shift 1 "+2d")
1383 (replace-regexp-in-string
1384 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1386 ;; Clone repeating once.
1391 * H1\n<2015-06-25 +1w>
1393 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1394 (org-clone-subtree-with-time-shift 1 "+2d")
1395 (replace-regexp-in-string
1396 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1398 ;; Clone non-repeating zero times.
1403 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1404 (org-clone-subtree-with-time-shift 0 "+2d")
1405 (replace-regexp-in-string
1406 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1408 ;; Clone repeating "zero" times.
1412 * H1\n<2015-06-23 +1w>
1414 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1415 (org-clone-subtree-with-time-shift 0 "+2d")
1416 (replace-regexp-in-string
1417 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1419 ;; Clone with blank SHIFT argument.
1423 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1424 (org-clone-subtree-with-time-shift 1 "")
1425 (buffer-substring-no-properties (line-beginning-position 2)
1426 (line-end-position 2)))))
1427 ;; Find time stamps before point. If SHIFT is not specified, ask
1428 ;; for a time shift.
1432 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1433 (org-clone-subtree-with-time-shift 1 "+1d")
1434 (buffer-substring-no-properties (line-beginning-position 2)
1435 (line-end-position 2)))))
1439 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1440 (cl-letf (((symbol-function 'read-from-minibuffer
)
1441 (lambda (&rest args
) "+1d")))
1442 (org-clone-subtree-with-time-shift 1))
1443 (buffer-substring-no-properties (line-beginning-position 2)
1444 (line-end-position 2))))))
1447 ;;; Fixed-Width Areas
1449 (ert-deftest test-org
/toggle-fixed-width
()
1450 "Test `org-toggle-fixed-width' specifications."
1451 ;; No region: Toggle on fixed-width marker in paragraphs.
1454 (org-test-with-temp-text "A"
1455 (org-toggle-fixed-width)
1457 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1460 (org-test-with-temp-text ": A"
1461 (org-toggle-fixed-width)
1463 ;; No region: Toggle on marker in blank lines after elements or just
1464 ;; after a headline.
1467 (org-test-with-temp-text "* H\n"
1469 (org-toggle-fixed-width)
1472 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1473 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1474 (goto-char (point-max))
1475 (org-toggle-fixed-width)
1477 ;; No region: Toggle on marker in front of one line elements (e.g.,
1478 ;; headlines, clocks)
1480 (equal ": * Headline"
1481 (org-test-with-temp-text "* Headline"
1482 (org-toggle-fixed-width)
1485 (equal ": #+KEYWORD: value"
1486 (org-test-with-temp-text "#+KEYWORD: value"
1487 (org-toggle-fixed-width)
1489 ;; No region: error in other situations.
1491 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1493 (org-toggle-fixed-width)
1495 ;; No region: Indentation is preserved.
1498 (org-test-with-temp-text "- A\n B"
1500 (org-toggle-fixed-width)
1502 ;; Region: If it contains only fixed-width elements and blank lines,
1503 ;; toggle off fixed-width markup.
1506 (org-test-with-temp-text ": A\n\n: B"
1507 (transient-mark-mode 1)
1508 (push-mark (point) t t
)
1509 (goto-char (point-max))
1510 (org-toggle-fixed-width)
1512 ;; Region: If it contains anything else, toggle on fixed-width but
1513 ;; not on fixed-width areas.
1515 (equal ": A\n: \n: B\n: \n: C"
1516 (org-test-with-temp-text "A\n\n: B\n\nC"
1517 (transient-mark-mode 1)
1518 (push-mark (point) t t
)
1519 (goto-char (point-max))
1520 (org-toggle-fixed-width)
1522 ;; Region: Ignore blank lines at its end, unless it contains only
1526 (org-test-with-temp-text "A\n\n"
1527 (transient-mark-mode 1)
1528 (push-mark (point) t t
)
1529 (goto-char (point-max))
1530 (org-toggle-fixed-width)
1534 (org-test-with-temp-text "\n\n"
1535 (transient-mark-mode 1)
1536 (push-mark (point) t t
)
1537 (goto-char (point-max))
1538 (org-toggle-fixed-width)
1545 (ert-deftest test-org
/get-heading
()
1546 "Test `org-get-heading' specifications."
1547 ;; Return current heading, even if point is not on it.
1550 (org-test-with-temp-text "* H"
1551 (org-get-heading))))
1554 (org-test-with-temp-text "* H\nText<point>"
1555 (org-get-heading))))
1556 ;; Without any optional argument, return TODO keyword, priority
1557 ;; cookie, COMMENT keyword and tags.
1560 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1561 (org-get-heading))))
1564 (org-test-with-temp-text "* [#A] H"
1565 (org-get-heading))))
1568 (org-test-with-temp-text "* COMMENT H"
1569 (org-get-heading))))
1572 (org-test-with-temp-text "* H :tag:"
1573 (org-get-heading))))
1574 ;; With NO-TAGS argument, ignore tags.
1577 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1578 (org-get-heading t
))))
1581 (org-test-with-temp-text "* H :tag:"
1582 (org-get-heading t
))))
1583 ;; With NO-TODO, ignore TODO keyword.
1586 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1587 (org-get-heading nil t
))))
1590 (org-test-with-temp-text "* H :tag:"
1591 (org-get-heading nil t
))))
1592 ;; TODO keywords are case-sensitive.
1595 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1596 (org-get-heading nil t
))))
1597 ;; With NO-PRIORITY, ignore priority.
1600 (org-test-with-temp-text "* [#A] H"
1601 (org-get-heading nil nil t
))))
1604 (org-test-with-temp-text "* H"
1605 (org-get-heading nil nil t
))))
1608 (org-test-with-temp-text "* TODO [#A] H"
1609 (org-get-heading nil nil t
))))
1610 ;; With NO-COMMENT, ignore COMMENT keyword.
1613 (org-test-with-temp-text "* COMMENT H"
1614 (org-get-heading nil nil nil t
))))
1617 (org-test-with-temp-text "* H"
1618 (org-get-heading nil nil nil t
))))
1620 (equal "TODO [#A] H"
1621 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1622 (org-get-heading nil nil nil t
))))
1623 ;; On an empty headline, return value is consistent.
1624 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1625 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1626 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1627 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1629 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1631 (ert-deftest test-org
/in-commented-heading-p
()
1632 "Test `org-in-commented-heading-p' specifications."
1633 ;; Commented headline.
1635 (org-test-with-temp-text "* COMMENT Headline\nBody"
1636 (goto-char (point-max))
1637 (org-in-commented-heading-p)))
1638 ;; Commented ancestor.
1640 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1641 (goto-char (point-max))
1642 (org-in-commented-heading-p)))
1643 ;; Comment keyword is case-sensitive.
1645 (org-test-with-temp-text "* Comment Headline\nBody"
1646 (goto-char (point-max))
1647 (org-in-commented-heading-p)))
1648 ;; Keyword is standalone.
1650 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1651 (goto-char (point-max))
1652 (org-in-commented-heading-p)))
1653 ;; Optional argument.
1655 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1656 (goto-char (point-max))
1657 (org-in-commented-heading-p t
))))
1659 (ert-deftest test-org
/entry-blocked-p
()
1660 ;; Check other dependencies.
1662 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1663 (let ((org-enforce-todo-dependencies t
)
1665 '(org-block-todo-from-children-or-siblings-or-parent)))
1666 (org-entry-blocked-p))))
1668 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1669 (let ((org-enforce-todo-dependencies t
)
1671 '(org-block-todo-from-children-or-siblings-or-parent)))
1672 (org-entry-blocked-p))))
1673 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1676 (org-test-with-temp-text "* Blocked\n** TODO one"
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 "* DONE Blocked\n** TODO one"
1683 (let ((org-enforce-todo-dependencies t
)
1685 '(org-block-todo-from-children-or-siblings-or-parent)))
1686 (org-entry-blocked-p))))
1687 ;; Follow :ORDERED: specifications.
1689 (org-test-with-temp-text
1690 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
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
1697 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1698 (let ((org-enforce-todo-dependencies t
)
1700 '(org-block-todo-from-children-or-siblings-or-parent)))
1701 (org-entry-blocked-p)))))
1703 (ert-deftest test-org
/get-outline-path
()
1704 "Test `org-get-outline-path' specifications."
1705 ;; Top-level headlines have no outline path.
1707 (org-test-with-temp-text "* H"
1708 (org-get-outline-path)))
1709 ;; Otherwise, outline path is the path leading to the headline.
1712 (org-test-with-temp-text "* H\n** S<point>"
1713 (org-get-outline-path))))
1714 ;; Find path even when point is not on a headline.
1717 (org-test-with-temp-text "* H\n** S\nText<point>"
1718 (org-get-outline-path))))
1719 ;; TODO keywords, tags and statistics cookies are ignored.
1722 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1723 (org-get-outline-path))))
1724 ;; Links are replaced with their description or their path.
1727 (org-test-with-temp-text
1728 "* [[http://orgmode.org][Org]]\n** S<point>"
1729 (org-get-outline-path))))
1731 (equal '("http://orgmode.org")
1732 (org-test-with-temp-text
1733 "* [[http://orgmode.org]]\n** S<point>"
1734 (org-get-outline-path))))
1735 ;; When WITH-SELF is non-nil, include current heading.
1738 (org-test-with-temp-text "* H"
1739 (org-get-outline-path t
))))
1742 (org-test-with-temp-text "* H\n** S\nText<point>"
1743 (org-get-outline-path t
))))
1744 ;; Using cache is transparent to the user.
1747 (org-test-with-temp-text "* H\n** S<point>"
1748 (setq org-outline-path-cache nil
)
1749 (org-get-outline-path nil t
))))
1750 ;; Do not corrupt cache when finding outline path in distant part of
1754 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1755 (setq org-outline-path-cache nil
)
1756 (org-get-outline-path nil t
)
1757 (search-forward "S2")
1758 (org-get-outline-path nil t
))))
1759 ;; Do not choke on empty headlines.
1761 (org-test-with-temp-text "* H\n** <point>"
1762 (org-get-outline-path)))
1764 (org-test-with-temp-text "* \n** H<point>"
1765 (org-get-outline-path))))
1767 (ert-deftest test-org
/format-outline-path
()
1768 "Test `org-format-outline-path' specifications."
1770 (string= (org-format-outline-path (list "one" "two" "three"))
1774 (string= (org-format-outline-path '())
1777 (string= (org-format-outline-path '(nil))
1779 ;; Empty path and prefix.
1781 (string= (org-format-outline-path '() nil
">>")
1783 ;; Trailing whitespace in headings.
1785 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1787 ;; Non-default prefix and separators.
1789 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1790 ">>|one|two|three"))
1793 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1795 ;; Give a very narrow width.
1797 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1799 ;; Give a prefix that extends beyond the width.
1801 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1805 (ert-deftest test-org
/map-entries
()
1806 "Test `org-map-entries' specifications."
1810 (org-test-with-temp-text "* Level 1\n** Level 2"
1811 (org-map-entries #'point
))))
1815 (org-test-with-temp-text "* Level 1\n** Level 2"
1816 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1819 (org-test-with-temp-text "* Level 1\n** Level 2"
1820 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1824 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1825 (org-map-entries #'point
"yes"))))
1828 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1829 (org-map-entries #'point
"+yes-a"))))
1832 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1833 (org-map-entries #'point
"{yes?}"))))
1837 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1838 (org-map-entries #'point
"PRIORITY=\"A\""))))
1842 (org-test-with-temp-text "
1844 SCHEDULED: <2012-03-29 thu.>
1846 SCHEDULED: <2014-03-04 tue.>"
1847 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1850 (org-test-with-temp-text "
1852 SCHEDULED: <2012-03-29 thu.>
1854 SCHEDULED: <2014-03-04 tue.>"
1855 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1856 ;; Regular property match.
1859 (org-test-with-temp-text "
1868 (org-map-entries #'point
"TEST=1"))))
1869 ;; Multiple criteria.
1872 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1873 (let (org-odd-levels-only
1874 (org-use-tag-inheritance nil
))
1875 (org-map-entries #'point
"yes+LEVEL=1")))))
1879 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1880 (let (org-odd-levels-only)
1881 (org-map-entries #'point
"LEVEL=2|no")))))
1884 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1885 (let (org-odd-levels-only)
1886 (org-map-entries #'point
"yes|no")))))
1890 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1891 (let (org-odd-levels-only)
1892 (org-map-entries #'point
"yes&no"))))))
1894 (ert-deftest test-org
/edit-headline
()
1895 "Test `org-edit-headline' specifications."
1898 (org-test-with-temp-text "* A"
1899 (org-edit-headline "B")
1901 ;; Handle empty headings.
1904 (org-test-with-temp-text "* A"
1905 (org-edit-headline "")
1909 (org-test-with-temp-text "* "
1910 (org-edit-headline "A")
1912 ;; Handle TODO keywords and priority cookies.
1915 (org-test-with-temp-text "* TODO A"
1916 (org-edit-headline "B")
1920 (org-test-with-temp-text "* [#A] A"
1921 (org-edit-headline "B")
1924 (equal "* TODO [#A] B"
1925 (org-test-with-temp-text "* TODO [#A] A"
1926 (org-edit-headline "B")
1930 (org-test-with-temp-text "* A :tag:"
1931 (let ((org-tags-column 4)) (org-edit-headline "B"))
1938 (ert-deftest test-org
/set-regexps-and-options
()
1939 "Test `org-set-regexps-and-options' specifications."
1943 (let ((org-tag-alist '(("A")))
1944 (org-tag-persistent-alist nil
))
1945 (org-test-with-temp-text ""
1947 org-current-tag-alist
))))
1950 (let ((org-tag-alist '(("A")))
1951 (org-tag-persistent-alist nil
))
1952 (org-test-with-temp-text "#+TAGS: B"
1954 org-current-tag-alist
))))
1956 (equal '(("C") ("B"))
1957 (let ((org-tag-alist '(("A")))
1958 (org-tag-persistent-alist '(("C"))))
1959 (org-test-with-temp-text "#+TAGS: B"
1961 org-current-tag-alist
))))
1964 (let ((org-tag-alist '(("A")))
1965 (org-tag-persistent-alist '(("C"))))
1966 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1968 org-current-tag-alist
))))
1970 (equal '(("A" . ?a
) ("B") ("C"))
1971 (let ((org-tag-persistant-alist nil
))
1972 (org-test-with-temp-text "#+TAGS: A(a) B C"
1974 org-current-tag-alist
))))
1976 (equal '(("A") (:newline
) ("B"))
1977 (let ((org-tag-persistent-alist nil
))
1978 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1980 org-current-tag-alist
))))
1982 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1983 (let ((org-tag-persistent-alist nil
))
1984 (org-test-with-temp-text "#+TAGS: { A B } C"
1986 org-current-tag-alist
))))
1988 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1989 (let ((org-tag-persistent-alist nil
))
1990 (org-test-with-temp-text "#+TAGS: { A : B C }"
1992 org-current-tag-alist
))))
1994 (equal '(("A" "B" "C"))
1995 (let ((org-tag-persistent-alist nil
))
1996 (org-test-with-temp-text "#+TAGS: { A : B C }"
1998 org-tag-groups-alist
))))
2000 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2001 (let ((org-tag-persistent-alist nil
))
2002 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2004 org-current-tag-alist
))))
2006 (equal '(("A" "B" "C"))
2007 (let ((org-tag-persistent-alist nil
))
2008 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2010 org-tag-groups-alist
))))
2011 ;; FILETAGS keyword.
2013 (equal '("A" "B" "C")
2014 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2017 ;; PROPERTY keyword. Property names are case-insensitive.
2020 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2022 (cdr (assoc "var" org-file-properties
)))))
2026 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2028 (cdr (assoc "var" org-file-properties
)))))
2032 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2034 (cdr (assoc "var" org-file-properties
)))))
2038 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2040 org-archive-location
)))
2041 ;; CATEGORY keyword.
2044 (org-test-with-temp-text "#+CATEGORY: test"
2049 (org-test-with-temp-text "#+CATEGORY: test"
2051 (cdr (assoc "CATEGORY" org-file-properties
)))))
2054 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2055 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2057 org-columns-default-format
)))
2058 ;; CONSTANTS keyword. Constants names are case sensitive.
2060 (equal '("299792458." "3.14")
2061 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2064 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2068 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2070 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2073 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2075 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2080 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2082 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2084 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2088 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2090 (list org-highest-priority org-lowest-priority org-default-priority
))))
2094 (org-test-with-temp-text "#+PRIORITIES: X Z"
2096 (list org-highest-priority org-lowest-priority org-default-priority
))))
2100 (org-test-with-temp-text "#+STARTUP: fold odd"
2102 (list org-startup-folded org-odd-levels-only
))))
2105 (equal '(("A" "B") ("C"))
2106 (org-test-with-temp-text "#+TODO: A B | C"
2108 (list org-not-done-keywords org-done-keywords
))))
2110 (equal '(("A" "C") ("B" "D"))
2111 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2113 (list org-not-done-keywords org-done-keywords
))))
2115 (equal '(("A" "B") ("C"))
2116 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2118 (list org-not-done-keywords org-done-keywords
))))
2120 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2121 (org-test-with-temp-text "#+TODO: A(a)"
2123 org-todo-key-alist
)))
2125 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2126 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2128 org-todo-log-states
)))
2129 ;; Enter SETUPFILE keyword.
2132 (org-test-with-temp-text
2133 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2135 (cdr (assoc "a" org-file-properties
))))))
2143 (ert-deftest test-org
/coderef
()
2144 "Test coderef links specifications."
2146 (org-test-with-temp-text "
2147 #+BEGIN_SRC emacs-lisp
2152 (looking-at "(ref:sc)")))
2153 ;; Find coderef even with alternate label format.
2155 (org-test-with-temp-text "
2156 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2161 (looking-at "{ref:sc}"))))
2165 (ert-deftest test-org
/custom-id
()
2166 "Test custom ID links specifications."
2168 (org-test-with-temp-text
2169 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2171 (looking-at-p "\\* H1")))
2172 ;; Throw an error on false positives.
2174 (org-test-with-temp-text
2175 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2177 (looking-at-p "\\* H1"))))
2181 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2182 ;; a named element (#+name: text) and to headlines (* Text).
2184 (ert-deftest test-org
/fuzzy-links
()
2185 "Test fuzzy links specifications."
2186 ;; Fuzzy link goes in priority to a matching target.
2188 (org-test-with-temp-text
2189 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2190 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2191 (looking-at "<<Test>>")))
2192 ;; Then fuzzy link points to an element with a given name.
2194 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2195 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2196 (looking-at "#\\+NAME: Test")))
2197 ;; A target still lead to a matching headline otherwise.
2199 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2200 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2201 (looking-at "\\* Head2")))
2202 ;; With a leading star in link, enforce heading match.
2204 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2205 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2206 (looking-at "\\* Test")))
2207 ;; With a leading star in link, enforce exact heading match, even
2208 ;; with `org-link-search-must-match-exact-headline' set to nil.
2210 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2211 (let ((org-link-search-must-match-exact-headline nil
))
2212 (org-open-at-point))))
2213 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2215 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2216 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2217 (looking-at "\\* Test")))
2219 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2220 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2221 (looking-at "\\* Test")))
2222 ;; Heading match should not care about spaces, cookies, TODO
2223 ;; keywords, priorities, and tags. However, TODO keywords are
2227 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2228 (org-test-with-temp-text
2229 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2230 (let ((org-link-search-must-match-exact-headline nil
)
2231 (org-todo-regexp "TODO"))
2232 (org-open-at-point))
2233 (looking-at (regexp-quote first-line
)))))
2235 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2236 (let ((org-link-search-must-match-exact-headline nil
)
2237 (org-todo-regexp "TODO"))
2238 (org-open-at-point))))
2239 ;; Heading match should still be exact.
2241 (org-test-with-temp-text "
2242 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2245 (let ((org-link-search-must-match-exact-headline nil
)
2246 (org-todo-regexp "TODO"))
2247 (org-open-at-point))))
2249 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\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 (looking-at-p (regexp-quote "** Test 1 2"))))
2254 ;; Heading match ignores COMMENT keyword.
2256 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2258 (looking-at "\\* COMMENT Test")))
2260 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2262 (looking-at "\\* TODO COMMENT Test")))
2263 ;; Correctly un-hexify fuzzy links.
2265 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2269 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2275 (ert-deftest test-org
/org-link-escape-ascii-character
()
2276 "Escape an ascii character."
2280 (org-link-escape "["))))
2282 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2283 "Escape an ascii control character."
2287 (org-link-escape "\t"))))
2289 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2290 "Escape an unicode multibyte character."
2294 (org-link-escape "€"))))
2296 (ert-deftest test-org
/org-link-escape-custom-table
()
2297 "Escape string with custom character table."
2301 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2303 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2304 "Escape string with custom table merged with default table."
2307 "%5BF%6F%6F%3A%42ar%0A%5D"
2308 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2310 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2311 "Unescape an ascii character."
2315 (org-link-unescape "%5B"))))
2317 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2318 "Unescpae an ascii control character."
2322 (org-link-unescape "%0A"))))
2324 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2325 "Unescape unicode multibyte character."
2329 (org-link-unescape "%E2%82%AC"))))
2331 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2332 "Unescape old style percent escaped character."
2335 "à âçèéêîôùû"
2336 (decode-coding-string
2337 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2339 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2340 "Escape and unescape a URL that includes an escaped char.
2341 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2344 "http://some.host.com/form?&id=blah%2Bblah25"
2346 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2350 (ert-deftest test-org
/open-at-point-in-keyword
()
2351 "Does `org-open-at-point' open link in a keyword line?"
2353 (org-test-with-temp-text
2354 "<<top>>\n#+KEYWORD: <point>[[top]]"
2355 (org-open-at-point) t
)))
2357 (ert-deftest test-org
/open-at-point-in-property
()
2358 "Does `org-open-at-point' open link in property drawer?"
2360 (org-test-with-temp-text
2363 :URL: <point>[[*Headline]]
2365 (org-open-at-point) t
)))
2367 (ert-deftest test-org
/open-at-point-in-comment
()
2368 "Does `org-open-at-point' open link in a commented line?"
2370 (org-test-with-temp-text
2371 "<<top>>\n# <point>[[top]]"
2372 (org-open-at-point) t
)))
2374 (ert-deftest test-org
/open-at-point
/inline-image
()
2375 "Test `org-open-at-point' on nested links."
2377 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2381 (ert-deftest test-org
/open-at-point
/radio-target
()
2382 "Test `org-open-at-point' on radio targets."
2384 (org-test-with-temp-text "<<<target>>> <point>target"
2385 (org-update-radio-target-regexp)
2387 (eq (org-element-type (org-element-context)) 'radio-target
))))
2391 (ert-deftest test-org
/store-link
()
2392 "Test `org-store-link' specifications."
2393 ;; On a headline, link to that headline. Use heading as the
2394 ;; description of the link.
2396 (let (org-store-link-props org-stored-links
)
2397 (org-test-with-temp-text-in-file "* H1"
2398 (let ((file (buffer-file-name)))
2399 (equal (format "[[file:%s::*H1][H1]]" file
)
2400 (org-store-link nil
))))))
2401 ;; On a headline, remove any link from description.
2403 (let (org-store-link-props org-stored-links
)
2404 (org-test-with-temp-text-in-file "* [[#l][d]]"
2405 (let ((file (buffer-file-name)))
2406 (equal (format "[[file:%s::*%s][d]]"
2408 (org-link-escape "[[#l][d]]"))
2409 (org-store-link nil
))))))
2411 (let (org-store-link-props org-stored-links
)
2412 (org-test-with-temp-text-in-file "* [[l]]"
2413 (let ((file (buffer-file-name)))
2414 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2415 (org-store-link nil
))))))
2417 (let (org-store-link-props org-stored-links
)
2418 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2419 (let ((file (buffer-file-name)))
2420 (equal (format "[[file:%s::*%s][d1 d2]]"
2422 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2423 (org-store-link nil
))))))
2424 ;; On a named element, link to that element.
2426 (let (org-store-link-props org-stored-links
)
2427 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2428 (let ((file (buffer-file-name)))
2429 (equal (format "[[file:%s::foo][foo]]" file
)
2430 (org-store-link nil
)))))))
2435 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2436 "Ensure properties accumulate in subtree drawers."
2437 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2438 (org-babel-next-src-block)
2439 (should (equal '(2 1) (org-babel-execute-src-block)))))
2441 (ert-deftest test-org
/custom-properties
()
2442 "Test custom properties specifications."
2445 (let ((org-custom-properties '("FOO")))
2446 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2447 (org-toggle-custom-properties-visibility)
2448 (org-invisible-p2))))
2449 ;; Properties are case-insensitive.
2451 (let ((org-custom-properties '("FOO")))
2452 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2453 (org-toggle-custom-properties-visibility)
2454 (org-invisible-p2))))
2456 (let ((org-custom-properties '("foo")))
2457 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2458 (org-toggle-custom-properties-visibility)
2459 (org-invisible-p2))))
2460 ;; Multiple custom properties in the same drawer.
2462 (let ((org-custom-properties '("FOO" "BAR")))
2463 (org-test-with-temp-text
2464 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2465 (org-toggle-custom-properties-visibility)
2466 (and (org-invisible-p2)
2467 (not (progn (forward-line) (org-invisible-p2)))
2468 (progn (forward-line) (org-invisible-p2))))))
2469 ;; Hide custom properties with an empty value.
2471 (let ((org-custom-properties '("FOO")))
2472 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2473 (org-toggle-custom-properties-visibility)
2474 (org-invisible-p2))))
2475 ;; Do not hide fake properties.
2477 (let ((org-custom-properties '("FOO")))
2478 (org-test-with-temp-text ":FOO: val\n"
2479 (org-toggle-custom-properties-visibility)
2480 (org-invisible-p2))))
2482 (let ((org-custom-properties '("A")))
2483 (org-test-with-temp-text
2484 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2485 (org-toggle-custom-properties-visibility)
2486 (org-invisible-p2)))))
2492 (ert-deftest test-org
/mark-subtree
()
2493 "Test `org-mark-subtree' specifications."
2494 ;; Error when point is before first headline.
2496 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2497 (progn (transient-mark-mode 1)
2498 (org-mark-subtree))))
2499 ;; Without argument, mark current subtree.
2503 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2504 (progn (transient-mark-mode 1)
2507 (list (region-beginning) (region-end))))))
2508 ;; With an argument, move ARG up.
2512 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2513 (progn (transient-mark-mode 1)
2515 (org-mark-subtree 1)
2516 (list (region-beginning) (region-end))))))
2517 ;; Do not get fooled by inlinetasks.
2518 (when (featurep 'org-inlinetask
)
2521 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2522 (progn (transient-mark-mode 1)
2524 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2525 (region-beginning)))))))
2531 (ert-deftest test-org
/in-regexp
()
2532 "Test `org-in-regexp' specifications."
2535 (org-test-with-temp-text "xx ab<point>c xx"
2536 (org-in-regexp "abc")))
2538 (org-test-with-temp-text "xx abc <point>xx"
2539 (org-in-regexp "abc")))
2540 ;; Return non-nil even with multiple matching regexps in the same
2543 (org-test-with-temp-text "abc xx ab<point>c xx"
2544 (org-in-regexp "abc")))
2545 ;; With optional argument NLINES, check extra lines around point.
2547 (org-test-with-temp-text "A\nB<point>\nC"
2548 (org-in-regexp "A\nB\nC")))
2550 (org-test-with-temp-text "A\nB<point>\nC"
2551 (org-in-regexp "A\nB\nC" 1)))
2553 (org-test-with-temp-text "A\nB\nC<point>"
2554 (org-in-regexp "A\nB\nC" 1)))
2555 ;; When optional argument VISUALLY is non-nil, return nil if at
2556 ;; regexp boundaries.
2558 (org-test-with-temp-text "xx abc<point> xx"
2559 (org-in-regexp "abc")))
2561 (org-test-with-temp-text "xx abc<point> xx"
2562 (org-in-regexp "abc" nil t
))))
2567 (ert-deftest test-org
/end-of-meta-data
()
2568 "Test `org-end-of-meta-data' specifications."
2569 ;; Skip planning line.
2571 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2572 (org-end-of-meta-data)
2574 ;; Skip properties drawer.
2576 (org-test-with-temp-text
2577 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2578 (org-end-of-meta-data)
2582 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2583 (org-end-of-meta-data)
2585 ;; Nothing to skip, go to first line.
2587 (org-test-with-temp-text "* Headline\nContents"
2588 (org-end-of-meta-data)
2589 (looking-at "Contents")))
2590 ;; With option argument, skip empty lines, regular drawers and
2593 (org-test-with-temp-text "* Headline\n\nContents"
2594 (org-end-of-meta-data t
)
2595 (looking-at "Contents")))
2597 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2598 (org-end-of-meta-data t
)
2599 (looking-at "Contents")))
2601 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2602 (org-end-of-meta-data t
)
2603 (looking-at "Contents")))
2604 ;; Special case: do not skip incomplete drawers.
2606 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2607 (org-end-of-meta-data t
)
2608 (looking-at ":LOGBOOK:")))
2609 ;; Special case: Be careful about consecutive headlines.
2611 (org-test-with-temp-text "* H1\n*H2\nContents"
2612 (org-end-of-meta-data t
)
2613 (looking-at "Contents"))))
2615 (ert-deftest test-org
/beginning-of-line
()
2616 "Test `org-beginning-of-line' specifications."
2617 ;; Move to beginning of line. If current line in invisible, move to
2618 ;; beginning of visible line instead.
2620 (org-test-with-temp-text "Some text\nSome other text<point>"
2621 (org-beginning-of-line)
2624 (org-test-with-temp-text "* H1\n** H2<point>"
2626 (org-beginning-of-line)
2627 (= (line-beginning-position) 1)))
2628 ;; With `visual-line-mode' active, move to beginning of visual line.
2630 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2632 (dotimes (i 1000) (insert "very "))
2633 (org-beginning-of-line)
2635 ;; In a wide headline, with `visual-line-mode', prefer going to the
2636 ;; beginning of a visual line than to the logical beginning of line,
2637 ;; even if special movement is active.
2639 (org-test-with-temp-text "* A <point>long headline"
2641 (dotimes (i 1000) (insert "very "))
2642 (goto-char (point-max))
2643 (org-beginning-of-line)
2646 (org-test-with-temp-text "* A <point>long headline"
2648 (dotimes (i 1000) (insert "very "))
2649 (goto-char (point-max))
2650 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2652 ;; At an headline with special movement, first move at beginning of
2653 ;; title, then at the beginning of line, rinse, repeat.
2655 (org-test-with-temp-text "* TODO Headline<point>"
2656 (let ((org-special-ctrl-a/e t
))
2657 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2658 (progn (org-beginning-of-line) (bolp))
2659 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2661 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2662 (let ((org-special-ctrl-a/e t
))
2663 (org-beginning-of-line)
2664 (looking-at "Headline"))))
2666 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2667 (let ((org-special-ctrl-a/e
'(t . nil
)))
2668 (org-beginning-of-line)
2669 (looking-at "Headline"))))
2671 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2672 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2673 (org-beginning-of-line)
2674 (looking-at "Headline"))))
2675 ;; At an headline with reversed movement, first move to beginning of
2676 ;; line, then to the beginning of title.
2678 (org-test-with-temp-text "* TODO Headline<point>"
2679 (let ((org-special-ctrl-a/e
'reversed
)
2680 (this-command last-command
))
2681 (and (progn (org-beginning-of-line) (bolp))
2682 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2684 (org-test-with-temp-text "* TODO Headline<point>"
2685 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2686 (this-command last-command
))
2687 (and (progn (org-beginning-of-line) (bolp))
2688 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2690 (org-test-with-temp-text "* TODO Headline<point>"
2691 (let ((org-special-ctrl-a/e
'(t . nil
))
2692 (this-command last-command
))
2693 (and (progn (org-beginning-of-line) (bolp))
2694 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2695 ;; At an item with special movement, first move after to beginning
2696 ;; of title, then to the beginning of line, rinse, repeat.
2698 (org-test-with-temp-text "- [ ] Item<point>"
2699 (let ((org-special-ctrl-a/e t
))
2700 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2701 (progn (org-beginning-of-line) (bolp))
2702 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2703 ;; At an item with reversed movement, first move to beginning of
2704 ;; line, then to the beginning of title.
2706 (org-test-with-temp-text "- [X] Item<point>"
2707 (let ((org-special-ctrl-a/e
'reversed
)
2708 (this-command last-command
))
2709 (and (progn (org-beginning-of-line) (bolp))
2710 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2711 ;; Leave point before invisible characters at column 0.
2713 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2714 (let ((org-special-ctrl-a/e nil
))
2715 (org-beginning-of-line)
2718 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2719 (let ((org-special-ctrl-a/e t
))
2720 (org-beginning-of-line)
2723 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2725 (org-beginning-of-line)
2727 ;; Special case: Do not error when the buffer contains only a single
2730 (org-test-with-temp-text "*<point>"
2731 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2733 (org-test-with-temp-text "*<point>"
2734 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2736 (ert-deftest test-org
/end-of-line
()
2737 "Test `org-end-of-line' specifications."
2740 (org-test-with-temp-text "Some text\nSome other text"
2743 ;; With `visual-line-mode' active, move to end of visible line.
2744 ;; However, never go past ellipsis.
2746 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2748 (dotimes (i 1000) (insert "very "))
2749 (goto-char (point-min))
2753 (org-test-with-temp-text "* A short headline\nSome contents"
2758 ;; In a wide headline, with `visual-line-mode', prefer going to end
2759 ;; of visible line if tags, or end of line, are farther.
2761 (org-test-with-temp-text "* A <point>long headline"
2763 (dotimes (i 1000) (insert "very "))
2764 (goto-char (point-min))
2768 (org-test-with-temp-text "* A <point>long headline :tag:"
2770 (dotimes (i 1000) (insert "very "))
2771 (goto-char (point-min))
2774 ;; At an headline without special movement, go to end of line.
2775 ;; However, never go past ellipsis.
2777 (org-test-with-temp-text "* Headline2b :tag:\n"
2778 (let ((org-special-ctrl-a/e nil
))
2779 (and (progn (org-end-of-line) (eolp))
2780 (progn (org-end-of-line) (eolp))))))
2782 (org-test-with-temp-text "* Headline2b :tag:\n"
2783 (let ((org-special-ctrl-a/e
'(t . nil
)))
2784 (and (progn (org-end-of-line) (eolp))
2785 (progn (org-end-of-line) (eolp))))))
2787 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2789 (let ((org-special-ctrl-a/e nil
))
2791 (= 1 (line-beginning-position)))))
2792 ;; At an headline with special movement, first move before tags,
2793 ;; then at the end of line, rinse, repeat. However, never go past
2796 (org-test-with-temp-text "* Headline1 :tag:\n"
2797 (let ((org-special-ctrl-a/e t
))
2798 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2799 (progn (org-end-of-line) (eolp))
2800 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2802 (org-test-with-temp-text "* Headline1 :tag:\n"
2803 (let ((org-special-ctrl-a/e
'(nil . t
)))
2804 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2805 (progn (org-end-of-line) (eolp))
2806 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2808 (org-test-with-temp-text "* Headline1 :tag:\n"
2809 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2810 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2811 (progn (org-end-of-line) (eolp))
2812 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2814 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2816 (let ((org-special-ctrl-a/e t
))
2819 (= 1 (line-beginning-position)))))
2820 ;; At an headline, with reversed movement, first go to end of line,
2821 ;; then before tags. However, never go past ellipsis.
2823 (org-test-with-temp-text "* Headline3 :tag:\n"
2824 (let ((org-special-ctrl-a/e
'reversed
)
2825 (this-command last-command
))
2826 (and (progn (org-end-of-line) (eolp))
2827 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2829 (org-test-with-temp-text "* Headline3 :tag:\n"
2830 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2831 (this-command last-command
))
2832 (and (progn (org-end-of-line) (eolp))
2833 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2835 (org-test-with-temp-text "* Headline3 :tag:\n"
2836 (let ((org-special-ctrl-a/e
'(nil . t
))
2837 (this-command last-command
))
2838 (and (progn (org-end-of-line) (eolp))
2839 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2841 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2843 (let ((org-special-ctrl-a/e
'reversed
))
2845 (= 1 (line-beginning-position)))))
2846 ;; At a block without hidden contents.
2848 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2849 (progn (org-end-of-line) (eolp))))
2850 ;; At a block with hidden contents.
2852 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2853 (let ((org-special-ctrl-a/e t
))
2854 (org-hide-block-toggle)
2857 ;; Get past invisible characters at the end of line.
2859 (org-test-with-temp-text "[[http://orgmode.org]]"
2863 (ert-deftest test-org
/open-line
()
2864 "Test `org-open-line' specifications."
2865 ;; Call `open-line' outside of tables.
2868 (org-test-with-temp-text "Text"
2871 ;; At a table, create a row above.
2873 (equal "\n| |\n| a |"
2874 (org-test-with-temp-text "\n<point>| a |"
2877 ;; At the very first character of the buffer, also call `open-line'.
2880 (org-test-with-temp-text "| a |"
2883 ;; Narrowing does not count.
2885 (equal "Text\n| |\n| a |"
2886 (org-test-with-temp-text "Text\n<point>| a |"
2887 (narrow-to-region (point) (point-max))
2892 (ert-deftest test-org
/forward-sentence
()
2893 "Test `org-forward-sentence' specifications."
2894 ;; At the end of a table cell, move to the end of the next one.
2896 (org-test-with-temp-text "| a<point> | b |"
2897 (org-forward-sentence)
2898 (looking-at " |$")))
2899 ;; Elsewhere in a cell, move to its end.
2901 (org-test-with-temp-text "| a<point>c | b |"
2902 (org-forward-sentence)
2903 (looking-at " | b |$")))
2904 ;; Otherwise, simply call `forward-sentence'.
2906 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2907 (org-forward-sentence)
2908 (looking-at " Sentence 2.")))
2910 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2911 (org-forward-sentence)
2912 (org-forward-sentence)
2914 ;; At the end of an element, jump to the next one, without stopping
2915 ;; on blank lines in-between.
2917 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2918 (org-forward-sentence)
2921 (ert-deftest test-org
/backward-sentence
()
2922 "Test `org-backward-sentence' specifications."
2923 ;; At the beginning of a table cell, move to the beginning of the
2926 (org-test-with-temp-text "| a | <point>b |"
2927 (org-backward-sentence)
2928 (looking-at "a | b |$")))
2929 ;; Elsewhere in a cell, move to its beginning.
2931 (org-test-with-temp-text "| a | b<point>c |"
2932 (org-backward-sentence)
2933 (looking-at "bc |$")))
2934 ;; Otherwise, simply call `backward-sentence'.
2936 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2937 (org-backward-sentence)
2938 (looking-at "Sentence 2.")))
2940 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2941 (org-backward-sentence)
2942 (org-backward-sentence)
2944 ;; Make sure to hit the beginning of a sentence on the same line as
2947 (org-test-with-temp-text "- Line 1\n line <point>2."
2948 (org-backward-sentence)
2949 (looking-at "Line 1"))))
2951 (ert-deftest test-org
/forward-paragraph
()
2952 "Test `org-forward-paragraph' specifications."
2953 ;; At end of buffer, return an error.
2955 (org-test-with-temp-text "Paragraph"
2956 (goto-char (point-max))
2957 (org-forward-paragraph)))
2960 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2961 (org-forward-paragraph)
2965 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2966 (org-forward-paragraph)
2968 ;; Do not enter elements with invisible contents.
2970 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2971 (org-hide-block-toggle)
2972 (org-forward-paragraph)
2974 ;; On an affiliated keyword, jump to the beginning of the element.
2976 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2977 (org-forward-paragraph)
2978 (looking-at "Para")))
2979 ;; On an item or a footnote definition, move to the second element
2982 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2983 (org-forward-paragraph)
2984 (looking-at " Paragraph")))
2986 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2987 (org-forward-paragraph)
2988 (looking-at "Paragraph")))
2989 ;; On an item, or a footnote definition, when the first line is
2990 ;; empty, move to the first item.
2992 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2993 (org-forward-paragraph)
2994 (looking-at " Paragraph")))
2996 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2997 (org-forward-paragraph)
2998 (looking-at "Paragraph")))
2999 ;; On a table (resp. a property drawer) do not move through table
3000 ;; rows (resp. node properties).
3002 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3003 (org-forward-paragraph)
3004 (looking-at "Paragraph")))
3006 (org-test-with-temp-text
3007 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3008 (org-forward-paragraph)
3009 (looking-at "Paragraph")))
3010 ;; On a verse or source block, stop after blank lines.
3012 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3013 (org-forward-paragraph)
3016 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3017 (org-forward-paragraph)
3018 (looking-at "L2"))))
3020 (ert-deftest test-org
/backward-paragraph
()
3021 "Test `org-backward-paragraph' specifications."
3022 ;; Error at beginning of buffer.
3024 (org-test-with-temp-text "Paragraph"
3025 (org-backward-paragraph)))
3028 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3029 (goto-char (point-max))
3030 (org-backward-paragraph)
3033 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3034 (goto-char (point-max))
3036 (org-backward-paragraph)
3040 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3041 (goto-char (point-max))
3043 (org-backward-paragraph)
3045 ;; Ignore invisible elements.
3047 (org-test-with-temp-text "* H1\n P1\n* H2"
3049 (goto-char (point-max))
3051 (org-backward-paragraph)
3053 ;; On an affiliated keyword, jump to the first one.
3055 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3056 (search-forward "c2")
3057 (org-backward-paragraph)
3058 (looking-at "#\\+name")))
3059 ;; On the second element in an item or a footnote definition, jump
3060 ;; to item or the definition.
3062 (org-test-with-temp-text "- line1\n\n line2"
3063 (goto-char (point-max))
3065 (org-backward-paragraph)
3066 (looking-at "- line1")))
3068 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3069 (goto-char (point-max))
3071 (org-backward-paragraph)
3072 (looking-at "\\[fn:1\\] line1")))
3073 ;; On a table (resp. a property drawer), ignore table rows
3074 ;; (resp. node properties).
3076 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3077 (goto-char (point-max))
3079 (org-backward-paragraph)
3082 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3083 (org-backward-paragraph)
3084 (looking-at ":PROPERTIES:")))
3085 ;; On a source or verse block, stop before blank lines.
3087 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3088 (search-forward "L3")
3090 (org-backward-paragraph)
3093 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3094 (search-forward "L3")
3096 (org-backward-paragraph)
3097 (looking-at "L2"))))
3099 (ert-deftest test-org
/forward-element
()
3100 "Test `org-forward-element' specifications."
3101 ;; 1. At EOB: should error.
3102 (org-test-with-temp-text "Some text\n"
3103 (goto-char (point-max))
3104 (should-error (org-forward-element)))
3105 ;; 2. Standard move: expected to ignore blank lines.
3106 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3107 (org-forward-element)
3108 (should (looking-at (regexp-quote "Second paragraph."))))
3109 ;; 3. Headline tests.
3110 (org-test-with-temp-text "
3115 ;; 3.1. At an headline beginning: move to next headline at the
3118 (org-forward-element)
3119 (should (looking-at (regexp-quote "** Head 1.2")))
3120 ;; 3.2. At an headline beginning: move to parent headline if no
3121 ;; headline at the same level.
3123 (org-forward-element)
3124 (should (looking-at (regexp-quote "** Head 1.2"))))
3125 ;; 4. Greater element tests.
3126 (org-test-with-temp-text
3127 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3128 ;; 4.1. At a greater element: expected to skip contents.
3129 (org-forward-element)
3130 (should (looking-at (regexp-quote "Outside.")))
3131 ;; 4.2. At the end of greater element contents: expected to skip
3132 ;; to the end of the greater element.
3134 (org-forward-element)
3135 (should (looking-at (regexp-quote "Outside."))))
3137 (org-test-with-temp-text "
3151 ;; 5.1. At list top point: expected to move to the element after
3154 (org-forward-element)
3155 (should (looking-at (regexp-quote "Outside.")))
3156 ;; 5.2. Special case: at the first line of a sub-list, but not at
3157 ;; beginning of line, move to next item.
3160 (org-forward-element)
3161 (should (looking-at "- item2"))
3164 (org-forward-element)
3165 (should (looking-at " - sub2"))
3166 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3168 (org-forward-element)
3169 (should (looking-at (regexp-quote " Inner paragraph.")))
3170 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3172 (org-forward-element)
3173 (should (looking-at (regexp-quote " Inner paragraph.")))
3174 ;; 5.5. At an item: expected to move to next item, if any.
3176 (org-forward-element)
3177 (should (looking-at " - sub3"))))
3179 (ert-deftest test-org
/backward-element
()
3180 "Test `org-backward-element' specifications."
3181 ;; 1. Should error at BOB.
3182 (org-test-with-temp-text " \nParagraph."
3183 (should-error (org-backward-element)))
3184 ;; 2. Should move at BOB when called on the first element in buffer.
3186 (org-test-with-temp-text "\n#+TITLE: test"
3187 (progn (forward-line)
3188 (org-backward-element)
3190 ;; 3. Not at the beginning of an element: move at its beginning.
3191 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3194 (org-backward-element)
3195 (should (looking-at (regexp-quote "Paragraph2."))))
3196 ;; 4. Headline tests.
3197 (org-test-with-temp-text "
3202 ;; 4.1. At an headline beginning: move to previous headline at the
3205 (org-backward-element)
3206 (should (looking-at (regexp-quote "** Head 1.1")))
3207 ;; 4.2. At an headline beginning: move to parent headline if no
3208 ;; headline at the same level.
3210 (org-backward-element)
3211 (should (looking-at (regexp-quote "* Head 1")))
3212 ;; 4.3. At the first top-level headline: should error.
3214 (should-error (org-backward-element)))
3215 ;; 5. At beginning of first element inside a greater element:
3216 ;; expected to move to greater element's beginning.
3217 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3219 (org-backward-element)
3220 (should (looking-at "#\\+BEGIN_CENTER")))
3221 ;; 6. At the beginning of the first element in a section: should
3222 ;; move back to headline, if any.
3224 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3225 (progn (goto-char (point-max))
3227 (org-backward-element)
3228 (org-at-heading-p))))
3230 (org-test-with-temp-text "
3245 ;; 7.1. At beginning of sub-list: expected to move to the
3246 ;; paragraph before it.
3248 (org-backward-element)
3249 (should (looking-at "item1"))
3250 ;; 7.2. At an item in a list: expected to move at previous item.
3252 (org-backward-element)
3253 (should (looking-at " - sub2"))
3255 (org-backward-element)
3256 (should (looking-at "- item1"))
3257 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3260 (org-backward-element)
3261 (should (looking-at " - sub1"))
3263 (org-backward-element)
3264 (should (looking-at "- item1"))
3265 ;; 7.4. At blank-lines before list end: expected to move to top
3268 (org-backward-element)
3269 (should (looking-at "- item1"))))
3271 (ert-deftest test-org
/up-element
()
3272 "Test `org-up-element' specifications."
3273 ;; 1. At BOB or with no surrounding element: should error.
3274 (org-test-with-temp-text "Paragraph."
3275 (should-error (org-up-element)))
3276 (org-test-with-temp-text "* Head1\n* Head2"
3278 (should-error (org-up-element)))
3279 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3281 (should-error (org-up-element)))
3282 ;; 2. At an headline: move to parent headline.
3283 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3286 (should (looking-at "\\* Head1")))
3287 ;; 3. Inside a greater element: move to greater element beginning.
3288 (org-test-with-temp-text
3289 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3292 (should (looking-at "#\\+BEGIN_CENTER")))
3294 (org-test-with-temp-text "* Top
3301 Paragraph within sub2.
3304 ;; 4.1. Within an item: move to the item beginning.
3307 (should (looking-at " - sub2"))
3308 ;; 4.2. At an item in a sub-list: move to parent item.
3311 (should (looking-at "- item1"))
3312 ;; 4.3. At an item in top list: move to beginning of whole list.
3315 (should (looking-at "- item1"))
3316 ;; 4.4. Special case. At very top point: should move to parent of
3320 (should (looking-at "\\* Top"))))
3322 (ert-deftest test-org
/down-element
()
3323 "Test `org-down-element' specifications."
3324 ;; Error when the element hasn't got a recursive type.
3325 (org-test-with-temp-text "Paragraph."
3326 (should-error (org-down-element)))
3327 ;; Error when the element has no contents
3328 (org-test-with-temp-text "* Headline"
3329 (should-error (org-down-element)))
3330 ;; When at a plain-list, move to first item.
3331 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3334 (should (looking-at " - Item 1.1")))
3335 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3337 (should (looking-at " Item 1")))
3338 ;; When at a table, move to first row
3339 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3341 (should (looking-at " a | b |")))
3342 ;; Otherwise, move inside the greater element.
3343 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3345 (should (looking-at "Paragraph"))))
3347 (ert-deftest test-org
/drag-element-backward
()
3348 "Test `org-drag-element-backward' specifications."
3352 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3353 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3354 (org-drag-element-backward)
3358 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3359 (org-test-with-temp-text
3360 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3361 (org-drag-element-backward)
3363 ;; Preserve blank lines.
3365 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3366 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3367 (org-drag-element-backward)
3371 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3372 (org-drag-element-backward)
3373 (looking-at-p "2")))
3374 ;; Error when trying to move first element of buffer.
3376 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3377 (org-drag-element-backward))
3379 ;; Error when trying to swap nested elements.
3381 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3382 (org-drag-element-backward))
3384 ;; Error when trying to swap an headline element and a non-headline
3387 (org-test-with-temp-text "Test.\n<point>* Head 1"
3388 (org-drag-element-backward))
3390 ;; Error when called before first element.
3392 (org-test-with-temp-text "\n<point>"
3393 (org-drag-element-backward))
3395 ;; Preserve visibility of elements and their contents.
3397 (equal '((63 .
82) (26 .
48))
3398 (org-test-with-temp-text "
3406 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3407 (search-backward "- item 1")
3408 (org-drag-element-backward)
3409 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3410 (overlays-in (point-min) (point-max))))))
3411 ;; Pathological case: handle call with point in blank lines right
3412 ;; after a headline.
3414 (equal "* H2\n* H1\nText\n\n"
3415 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3416 (org-drag-element-backward)
3419 (ert-deftest test-org
/drag-element-forward
()
3420 "Test `org-drag-element-forward' specifications."
3421 ;; 1. Error when trying to move first element of buffer.
3422 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3424 (should-error (org-drag-element-forward)))
3425 ;; 2. Error when trying to swap nested elements.
3426 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3428 (should-error (org-drag-element-forward)))
3429 ;; 3. Error when trying to swap a non-headline element and an
3431 (org-test-with-temp-text "Test.\n* Head 1"
3432 (should-error (org-drag-element-forward)))
3433 ;; 4. Error when called before first element.
3435 (org-test-with-temp-text "\n"
3437 (org-drag-element-backward))
3439 ;; 5. Otherwise, swap elements, preserving column and blank lines
3440 ;; between elements.
3441 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3442 (search-forward "graph")
3443 (org-drag-element-forward)
3444 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3445 (should (looking-at " 1")))
3446 ;; 5. Preserve visibility of elements and their contents.
3447 (org-test-with-temp-text "
3455 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3456 (search-backward "#+BEGIN_CENTER")
3457 (org-drag-element-forward)
3460 '((63 .
82) (26 .
48))
3461 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3462 (overlays-in (point-min) (point-max)))))))
3464 (ert-deftest test-org
/next-block
()
3465 "Test `org-next-block' specifications."
3468 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3470 (looking-at "#\\+BEGIN_CENTER")))
3473 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3474 (let ((case-fold-search nil
))
3476 (looking-at "#\\+begin_center"))))
3477 ;; Ignore current line.
3479 (org-test-with-temp-text
3480 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3482 (looking-at "#\\+BEGIN_CENTER")))
3483 ;; Throw an error when no block is found.
3485 (org-test-with-temp-text "Paragraph"
3486 (org-next-block 1)))
3487 ;; With an argument, skip many blocks at once.
3489 (org-test-with-temp-text
3490 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3492 (looking-at "#\\+BEGIN_QUOTE")))
3493 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3495 (org-test-with-temp-text
3496 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3497 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3498 (looking-at "#\\+BEGIN_QUOTE")))
3499 ;; Optional argument is also case-insensitive.
3501 (org-test-with-temp-text
3502 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3503 (let ((case-fold-search nil
))
3504 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3505 (looking-at "#\\+begin_quote")))))
3507 (ert-deftest test-org
/previous-block
()
3508 "Test `org-previous-block' specifications."
3511 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3512 (org-previous-block 1)
3513 (looking-at "#\\+BEGIN_CENTER")))
3516 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3517 (let ((case-fold-search nil
))
3518 (org-previous-block 1)
3519 (looking-at "#\\+begin_center"))))
3520 ;; Ignore current line.
3522 (org-test-with-temp-text
3523 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3524 (org-previous-block 1)
3525 (looking-at "#\\+BEGIN_QUOTE")))
3526 ;; Throw an error when no block is found.
3528 (org-test-with-temp-text "Paragraph<point>"
3529 (org-previous-block 1)))
3530 ;; With an argument, skip many blocks at once.
3532 (org-test-with-temp-text
3533 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3534 (org-previous-block 2)
3535 (looking-at "#\\+BEGIN_CENTER")))
3536 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3538 (org-test-with-temp-text
3539 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3540 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3541 (looking-at "#\\+BEGIN_QUOTE")))
3542 ;; Optional argument is also case-insensitive.
3544 (org-test-with-temp-text
3545 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3546 (let ((case-fold-search nil
))
3547 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3548 (looking-at "#\\+begin_quote")))))
3551 ;;; Outline structure
3553 (ert-deftest test-org
/demote
()
3554 "Test `org-demote' specifications."
3555 ;; Add correct number of stars according to `org-odd-levels-only'.
3558 (org-test-with-temp-text "* H"
3559 (let ((org-odd-levels-only nil
)) (org-demote))
3560 (org-current-level))))
3563 (org-test-with-temp-text "* H"
3564 (let ((org-odd-levels-only t
)) (org-demote))
3565 (org-current-level))))
3566 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3568 (org-test-with-temp-text "* H :tag:"
3569 (let ((org-tags-column 10)
3570 (org-auto-align-tags t
)
3571 (org-odd-levels-only nil
))
3573 (org-move-to-column 10)
3574 (looking-at-p ":tag:$")))
3576 (org-test-with-temp-text "* H :tag:"
3577 (let ((org-tags-column 10)
3578 (org-auto-align-tags nil
)
3579 (org-odd-levels-only nil
))
3581 (org-move-to-column 10)
3582 (looking-at-p ":tag:$")))
3583 ;; When `org-adapt-indentation' is non-nil, always indent planning
3584 ;; info and property drawers accordingly.
3587 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3588 (let ((org-odd-levels-only nil
)
3589 (org-adapt-indentation t
))
3592 (org-get-indentation))))
3595 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3596 (let ((org-odd-levels-only nil
)
3597 (org-adapt-indentation t
))
3600 (org-get-indentation))))
3603 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3604 (let ((org-odd-levels-only nil
)
3605 (org-adapt-indentation nil
))
3608 (org-get-indentation))))
3609 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3610 ;; section accordingly. Ignore, however, footnote definitions and
3611 ;; inlinetasks boundaries.
3614 (org-test-with-temp-text "* H\n Paragraph"
3615 (let ((org-odd-levels-only nil
)
3616 (org-adapt-indentation t
))
3619 (org-get-indentation))))
3622 (org-test-with-temp-text "* H\n Paragraph"
3623 (let ((org-odd-levels-only nil
)
3624 (org-adapt-indentation nil
))
3627 (org-get-indentation))))
3630 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3631 (let ((org-odd-levels-only nil
)
3632 (org-adapt-indentation t
))
3634 (goto-char (point-max))
3635 (org-get-indentation))))
3638 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3639 (let ((org-odd-levels-only nil
)
3640 (org-adapt-indentation t
))
3642 (goto-char (point-max))
3643 (org-get-indentation))))
3644 (when (featurep 'org-inlinetask
)
3647 (let ((org-inlinetask-min-level 5)
3648 (org-adapt-indentation t
))
3649 (org-test-with-temp-text "* H\n***** I\n***** END"
3652 (org-get-indentation))))))
3653 (when (featurep 'org-inlinetask
)
3656 (let ((org-inlinetask-min-level 5)
3657 (org-adapt-indentation t
))
3658 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3661 (org-get-indentation))))))
3662 ;; Ignore contents of source blocks or example blocks when
3663 ;; indentation should be preserved (through
3664 ;; `org-src-preserve-indentation' or "-i" flag).
3667 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3668 (let ((org-adapt-indentation t
)
3669 (org-src-preserve-indentation nil
))
3672 (org-get-indentation))))
3675 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3676 (let ((org-adapt-indentation t
)
3677 (org-src-preserve-indentation t
))
3680 (org-get-indentation))))
3683 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3684 (let ((org-adapt-indentation t
)
3685 (org-src-preserve-indentation t
))
3688 (org-get-indentation))))
3691 (org-test-with-temp-text
3692 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3693 (let ((org-adapt-indentation t
)
3694 (org-src-preserve-indentation nil
))
3697 (org-get-indentation)))))
3699 (ert-deftest test-org
/promote
()
3700 "Test `org-promote' specifications."
3701 ;; Return an error if headline is to be promoted to level 0, unless
3702 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3703 ;; headline becomes a comment.
3705 (org-test-with-temp-text "* H"
3706 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3709 (org-test-with-temp-text "* H"
3710 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3712 ;; Remove correct number of stars according to
3713 ;; `org-odd-levels-only'.
3716 (org-test-with-temp-text "*** H"
3717 (let ((org-odd-levels-only nil
)) (org-promote))
3718 (org-current-level))))
3721 (org-test-with-temp-text "*** H"
3722 (let ((org-odd-levels-only t
)) (org-promote))
3723 (org-current-level))))
3724 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3726 (org-test-with-temp-text "** H :tag:"
3727 (let ((org-tags-column 10)
3728 (org-auto-align-tags t
)
3729 (org-odd-levels-only nil
))
3731 (org-move-to-column 10)
3732 (looking-at-p ":tag:$")))
3734 (org-test-with-temp-text "** H :tag:"
3735 (let ((org-tags-column 10)
3736 (org-auto-align-tags nil
)
3737 (org-odd-levels-only nil
))
3739 (org-move-to-column 10)
3740 (looking-at-p ":tag:$")))
3741 ;; When `org-adapt-indentation' is non-nil, always indent planning
3742 ;; info and property drawers.
3745 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3746 (let ((org-odd-levels-only nil
)
3747 (org-adapt-indentation t
))
3750 (org-get-indentation))))
3753 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3754 (let ((org-odd-levels-only nil
)
3755 (org-adapt-indentation t
))
3758 (org-get-indentation))))
3761 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3762 (let ((org-odd-levels-only nil
)
3763 (org-adapt-indentation nil
))
3766 (org-get-indentation))))
3767 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3768 ;; section accordingly. Ignore, however, footnote definitions and
3769 ;; inlinetasks boundaries.
3772 (org-test-with-temp-text "** H\n Paragraph"
3773 (let ((org-odd-levels-only nil
)
3774 (org-adapt-indentation t
))
3777 (org-get-indentation))))
3780 (org-test-with-temp-text "** H\n Paragraph"
3781 (let ((org-odd-levels-only nil
)
3782 (org-adapt-indentation nil
))
3785 (org-get-indentation))))
3788 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3789 (let ((org-odd-levels-only nil
)
3790 (org-adapt-indentation t
))
3793 (org-get-indentation))))
3794 (when (featurep 'org-inlinetask
)
3797 (let ((org-inlinetask-min-level 5)
3798 (org-adapt-indentation t
))
3799 (org-test-with-temp-text "** H\n***** I\n***** END"
3802 (org-get-indentation))))))
3803 (when (featurep 'org-inlinetask
)
3806 (let ((org-inlinetask-min-level 5)
3807 (org-adapt-indentation t
))
3808 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3811 (org-get-indentation))))))
3812 ;; Give up shifting if it would break document's structure
3816 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3817 (let ((org-odd-levels-only nil
)
3818 (org-adapt-indentation t
))
3821 (org-get-indentation))))
3824 (org-test-with-temp-text "** H\n Paragraph\n * list."
3825 (let ((org-odd-levels-only nil
)
3826 (org-adapt-indentation t
))
3829 (org-get-indentation))))
3830 ;; Ignore contents of source blocks or example blocks when
3831 ;; indentation should be preserved (through
3832 ;; `org-src-preserve-indentation' or "-i" flag).
3835 (org-test-with-temp-text
3836 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3837 (let ((org-adapt-indentation t
)
3838 (org-src-preserve-indentation nil
)
3839 (org-odd-levels-only nil
))
3842 (org-get-indentation))))
3845 (org-test-with-temp-text
3846 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3847 (let ((org-adapt-indentation t
)
3848 (org-src-preserve-indentation t
)
3849 (org-odd-levels-only nil
))
3852 (org-get-indentation))))
3855 (org-test-with-temp-text
3856 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3857 (let ((org-adapt-indentation t
)
3858 (org-src-preserve-indentation t
)
3859 (org-odd-levels-only nil
))
3862 (org-get-indentation))))
3865 (org-test-with-temp-text
3866 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3867 (let ((org-adapt-indentation t
)
3868 (org-src-preserve-indentation nil
)
3869 (org-odd-levels-only nil
))
3872 (org-get-indentation)))))
3874 (ert-deftest test-org
/org-get-valid-level
()
3875 "Test function `org-get-valid-level' specifications."
3876 (let ((org-odd-levels-only nil
))
3877 (should (equal 1 (org-get-valid-level 0 0)))
3878 (should (equal 1 (org-get-valid-level 0 1)))
3879 (should (equal 2 (org-get-valid-level 0 2)))
3880 (should (equal 3 (org-get-valid-level 0 3)))
3881 (should (equal 1 (org-get-valid-level 1 0)))
3882 (should (equal 2 (org-get-valid-level 1 1)))
3883 (should (equal 23 (org-get-valid-level 1 22)))
3884 (should (equal 1 (org-get-valid-level 1 -
1)))
3885 (should (equal 1 (org-get-valid-level 2 -
1))))
3886 (let ((org-odd-levels-only t
))
3887 (should (equal 1 (org-get-valid-level 0 0)))
3888 (should (equal 1 (org-get-valid-level 0 1)))
3889 (should (equal 3 (org-get-valid-level 0 2)))
3890 (should (equal 5 (org-get-valid-level 0 3)))
3891 (should (equal 1 (org-get-valid-level 1 0)))
3892 (should (equal 3 (org-get-valid-level 1 1)))
3893 (should (equal 3 (org-get-valid-level 2 1)))
3894 (should (equal 5 (org-get-valid-level 3 1)))
3895 (should (equal 5 (org-get-valid-level 4 1)))
3896 (should (equal 43 (org-get-valid-level 1 21)))
3897 (should (equal 1 (org-get-valid-level 1 -
1)))
3898 (should (equal 1 (org-get-valid-level 2 -
1)))
3899 (should (equal 1 (org-get-valid-level 3 -
1)))
3900 (should (equal 3 (org-get-valid-level 4 -
1)))
3901 (should (equal 3 (org-get-valid-level 5 -
1)))))
3906 (ert-deftest test-org
/at-planning-p
()
3907 "Test `org-at-planning-p' specifications."
3910 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3911 (org-at-planning-p)))
3913 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3914 (org-at-planning-p)))
3915 ;; Correctly find planning attached to inlinetasks.
3916 (when (featurep 'org-inlinetask
)
3918 (org-test-with-temp-text
3919 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3920 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3922 (org-test-with-temp-text
3923 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3924 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3926 (org-test-with-temp-text
3927 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3928 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3930 (org-test-with-temp-text
3931 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3932 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3934 (ert-deftest test-org
/add-planning-info
()
3935 "Test `org-add-planning-info'."
3936 ;; Create deadline when `org-adapt-indentation' is non-nil.
3938 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3939 (org-test-with-temp-text "* H\nParagraph<point>"
3940 (let ((org-adapt-indentation t
))
3941 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3942 (replace-regexp-in-string
3943 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3945 ;; Create deadline when `org-adapt-indentation' is nil.
3947 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3948 (org-test-with-temp-text "* H\nParagraph<point>"
3949 (let ((org-adapt-indentation nil
))
3950 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3951 (replace-regexp-in-string
3952 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3954 ;; Update deadline when `org-adapt-indentation' is non-nil.
3956 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3957 (org-test-with-temp-text "\
3959 DEADLINE: <2015-06-24 Wed>
3961 (let ((org-adapt-indentation t
))
3962 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3963 (replace-regexp-in-string
3964 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3966 ;; Update deadline when `org-adapt-indentation' is nil.
3968 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3969 (org-test-with-temp-text "\
3971 DEADLINE: <2015-06-24 Wed>
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 ;; Schedule when `org-adapt-indentation' is non-nil.
3980 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3981 (org-test-with-temp-text "* H\nParagraph<point>"
3982 (let ((org-adapt-indentation t
))
3983 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3984 (replace-regexp-in-string
3985 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3987 ;; Schedule when `org-adapt-indentation' is nil.
3989 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3990 (org-test-with-temp-text "* H\nParagraph<point>"
3991 (let ((org-adapt-indentation nil
))
3992 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3993 (replace-regexp-in-string
3994 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3996 ;; Add deadline when scheduled.
4000 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4002 (org-test-with-temp-text "\
4004 SCHEDULED: <2015-06-24 Wed>
4006 (let ((org-adapt-indentation t
))
4007 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4008 (replace-regexp-in-string
4009 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4011 ;; Remove middle entry.
4015 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4017 (org-test-with-temp-text "\
4019 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4021 (let ((org-adapt-indentation t
))
4022 (org-add-planning-info nil nil
'deadline
))
4023 (replace-regexp-in-string
4024 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4026 ;; Remove last entry and then middle entry (order should not
4031 CLOSED: [2015-06-24]
4033 (org-test-with-temp-text "\
4035 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4037 (let ((org-adapt-indentation t
))
4038 (org-add-planning-info nil nil
'scheduled
'deadline
))
4039 (replace-regexp-in-string
4040 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4042 ;; Remove closed when `org-adapt-indentation' is non-nil.
4044 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4045 (org-test-with-temp-text "\
4047 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4049 (let ((org-adapt-indentation t
))
4050 (org-add-planning-info nil nil
'closed
))
4051 (replace-regexp-in-string
4052 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4055 (equal "* H\n Paragraph"
4056 (org-test-with-temp-text "\
4058 CLOSED: [2015-06-25 Thu]
4060 (let ((org-adapt-indentation t
))
4061 (org-add-planning-info nil nil
'closed
))
4062 (replace-regexp-in-string
4063 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4065 ;; Remove closed when `org-adapt-indentation' is nil.
4067 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4068 (org-test-with-temp-text "\
4070 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4072 (let ((org-adapt-indentation nil
))
4073 (org-add-planning-info nil nil
'closed
))
4074 (replace-regexp-in-string
4075 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4078 (equal "* H\nParagraph"
4079 (org-test-with-temp-text "\
4081 CLOSED: [2015-06-25 Thu]
4083 (let ((org-adapt-indentation nil
))
4084 (org-add-planning-info nil nil
'closed
))
4085 (replace-regexp-in-string
4086 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4088 ;; Remove closed entry and delete empty line.
4093 (org-test-with-temp-text "\
4095 CLOSED: [2015-06-24 Wed]
4097 (let ((org-adapt-indentation t
))
4098 (org-add-planning-info nil nil
'closed
))
4099 (replace-regexp-in-string
4100 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4102 ;; Remove one entry and update another.
4104 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4105 (org-test-with-temp-text "\
4107 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4109 (let ((org-adapt-indentation t
))
4110 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4111 (replace-regexp-in-string
4112 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4115 (ert-deftest test-org
/deadline
()
4116 "Test `org-deadline' specifications."
4117 ;; Insert a new value or replace existing one.
4119 (equal "* H\nDEADLINE: <2012-03-29>\n"
4120 (org-test-with-temp-text "* H"
4121 (let ((org-adapt-indentation nil
)
4122 (org-last-inserted-timestamp nil
))
4123 (org-deadline nil
"<2012-03-29 Tue>"))
4124 (replace-regexp-in-string
4125 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4128 (equal "* H\nDEADLINE: <2014-03-04>"
4129 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4130 (let ((org-adapt-indentation nil
)
4131 (org-last-inserted-timestamp nil
))
4132 (org-deadline nil
"<2014-03-04 Thu>"))
4133 (replace-regexp-in-string
4134 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4136 ;; Accept delta time, e.g., "+2d".
4138 (equal "* H\nDEADLINE: <2015-03-04>\n"
4139 (cl-letf (((symbol-function 'current-time
)
4140 (lambda (&rest args
)
4141 (apply #'encode-time
4142 (org-parse-time-string "2014-03-04")))))
4143 (org-test-with-temp-text "* H"
4144 (let ((org-adapt-indentation nil
)
4145 (org-last-inserted-timestamp nil
))
4146 (org-deadline nil
"+1y"))
4147 (replace-regexp-in-string
4148 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4149 ;; Preserve repeater.
4151 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4152 (org-test-with-temp-text "* H"
4153 (let ((org-adapt-indentation nil
)
4154 (org-last-inserted-timestamp nil
))
4155 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4156 (replace-regexp-in-string
4157 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4158 ;; Remove CLOSED keyword, if any.
4160 (equal "* H\nDEADLINE: <2012-03-29>"
4161 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4162 (let ((org-adapt-indentation nil
)
4163 (org-last-inserted-timestamp nil
))
4164 (org-deadline nil
"<2012-03-29 Tue>"))
4165 (replace-regexp-in-string
4166 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4167 ;; With C-u argument, remove DEADLINE keyword.
4170 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4171 (let ((org-adapt-indentation nil
)
4172 (org-last-inserted-timestamp nil
))
4173 (org-deadline '(4)))
4177 (org-test-with-temp-text "* H"
4178 (let ((org-adapt-indentation nil
)
4179 (org-last-inserted-timestamp nil
))
4180 (org-deadline '(4)))
4182 ;; With C-u C-u argument, prompt for a delay cookie.
4184 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4185 (cl-letf (((symbol-function 'org-read-date
)
4186 (lambda (&rest args
)
4187 (apply #'encode-time
4188 (org-parse-time-string "2014-03-04")))))
4189 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4190 (let ((org-adapt-indentation nil
)
4191 (org-last-inserted-timestamp nil
))
4192 (org-deadline '(16)))
4195 (cl-letf (((symbol-function 'org-read-date
)
4196 (lambda (&rest args
)
4197 (apply #'encode-time
4198 (org-parse-time-string "2014-03-04")))))
4199 (org-test-with-temp-text "* H"
4200 (let ((org-adapt-indentation nil
)
4201 (org-last-inserted-timestamp nil
))
4202 (org-deadline '(16)))
4204 ;; When a region is active and
4205 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4206 ;; same value in all headlines in region.
4208 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4209 (org-test-with-temp-text "* H1\n* H2"
4210 (let ((org-adapt-indentation nil
)
4211 (org-last-inserted-timestamp nil
)
4212 (org-loop-over-headlines-in-active-region t
))
4213 (transient-mark-mode 1)
4214 (push-mark (point) t t
)
4215 (goto-char (point-max))
4216 (org-deadline nil
"2012-03-29"))
4217 (replace-regexp-in-string
4218 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4220 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4221 (org-test-with-temp-text "* H1\n* H2"
4222 (let ((org-adapt-indentation nil
)
4223 (org-last-inserted-timestamp nil
)
4224 (org-loop-over-headlines-in-active-region nil
))
4225 (transient-mark-mode 1)
4226 (push-mark (point) t t
)
4227 (goto-char (point-max))
4228 (org-deadline nil
"2012-03-29"))
4229 (replace-regexp-in-string
4230 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4232 (ert-deftest test-org
/schedule
()
4233 "Test `org-schedule' specifications."
4234 ;; Insert a new value or replace existing one.
4236 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4237 (org-test-with-temp-text "* H"
4238 (let ((org-adapt-indentation nil
)
4239 (org-last-inserted-timestamp nil
))
4240 (org-schedule nil
"<2012-03-29 Tue>"))
4241 (replace-regexp-in-string
4242 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4245 (equal "* H\nSCHEDULED: <2014-03-04>"
4246 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4247 (let ((org-adapt-indentation nil
)
4248 (org-last-inserted-timestamp nil
))
4249 (org-schedule nil
"<2014-03-04 Thu>"))
4250 (replace-regexp-in-string
4251 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4253 ;; Accept delta time, e.g., "+2d".
4255 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4256 (cl-letf (((symbol-function 'current-time
)
4257 (lambda (&rest args
)
4258 (apply #'encode-time
4259 (org-parse-time-string "2014-03-04")))))
4260 (org-test-with-temp-text "* H"
4261 (let ((org-adapt-indentation nil
)
4262 (org-last-inserted-timestamp nil
))
4263 (org-schedule nil
"+1y"))
4264 (replace-regexp-in-string
4265 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4266 ;; Preserve repeater.
4268 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4269 (org-test-with-temp-text "* H"
4270 (let ((org-adapt-indentation nil
)
4271 (org-last-inserted-timestamp nil
))
4272 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4273 (replace-regexp-in-string
4274 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4275 ;; Remove CLOSED keyword, if any.
4277 (equal "* H\nSCHEDULED: <2012-03-29>"
4278 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4279 (let ((org-adapt-indentation nil
)
4280 (org-last-inserted-timestamp nil
))
4281 (org-schedule nil
"<2012-03-29 Tue>"))
4282 (replace-regexp-in-string
4283 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4284 ;; With C-u argument, remove SCHEDULED keyword.
4287 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4288 (let ((org-adapt-indentation nil
)
4289 (org-last-inserted-timestamp nil
))
4290 (org-schedule '(4)))
4294 (org-test-with-temp-text "* H"
4295 (let ((org-adapt-indentation nil
)
4296 (org-last-inserted-timestamp nil
))
4297 (org-schedule '(4)))
4299 ;; With C-u C-u argument, prompt for a delay cookie.
4301 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4302 (cl-letf (((symbol-function 'org-read-date
)
4303 (lambda (&rest args
)
4304 (apply #'encode-time
4305 (org-parse-time-string "2014-03-04")))))
4306 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4307 (let ((org-adapt-indentation nil
)
4308 (org-last-inserted-timestamp nil
))
4309 (org-schedule '(16)))
4312 (cl-letf (((symbol-function 'org-read-date
)
4313 (lambda (&rest args
)
4314 (apply #'encode-time
4315 (org-parse-time-string "2014-03-04")))))
4316 (org-test-with-temp-text "* H"
4317 (let ((org-adapt-indentation nil
)
4318 (org-last-inserted-timestamp nil
))
4319 (org-schedule '(16)))
4321 ;; When a region is active and
4322 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4323 ;; same value in all headlines in region.
4325 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4326 (org-test-with-temp-text "* H1\n* H2"
4327 (let ((org-adapt-indentation nil
)
4328 (org-last-inserted-timestamp nil
)
4329 (org-loop-over-headlines-in-active-region t
))
4330 (transient-mark-mode 1)
4331 (push-mark (point) t t
)
4332 (goto-char (point-max))
4333 (org-schedule nil
"2012-03-29"))
4334 (replace-regexp-in-string
4335 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4337 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4338 (org-test-with-temp-text "* H1\n* H2"
4339 (let ((org-adapt-indentation nil
)
4340 (org-last-inserted-timestamp nil
)
4341 (org-loop-over-headlines-in-active-region nil
))
4342 (transient-mark-mode 1)
4343 (push-mark (point) t t
)
4344 (goto-char (point-max))
4345 (org-schedule nil
"2012-03-29"))
4346 (replace-regexp-in-string
4347 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4349 ;; check if a repeater survives re-scheduling.
4351 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4352 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4353 (let ((org-adapt-indentation nil
)
4354 (org-last-inserted-timestamp nil
))
4355 (org-schedule nil
"2017-02-01"))
4361 (ert-deftest test-org
/buffer-property-keys
()
4362 "Test `org-buffer-property-keys' specifications."
4363 ;; Retrieve properties accross siblings.
4366 (org-test-with-temp-text "
4375 (org-buffer-property-keys))))
4376 ;; Retrieve properties accross children.
4379 (org-test-with-temp-text "
4388 (org-buffer-property-keys))))
4389 ;; Retrieve muliple properties in the same drawer.
4392 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4393 (org-buffer-property-keys))))
4394 ;; Ignore extension symbol in property name.
4397 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4398 (org-buffer-property-keys))))
4399 ;; With non-nil COLUMNS, extract property names from columns.
4402 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4403 (org-buffer-property-keys nil nil t
))))
4405 (equal '("A" "B" "COLUMNS")
4406 (org-test-with-temp-text
4407 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4408 (org-buffer-property-keys nil nil t
))))
4409 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4412 (org-test-with-temp-text
4413 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4414 (org-buffer-property-keys nil nil nil t
)))))
4416 (ert-deftest test-org
/property-values
()
4417 "Test `org-property-values' specifications."
4421 (org-test-with-temp-text
4422 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4423 (org-property-values "A"))))
4424 ;; Ignore empty values.
4426 (org-test-with-temp-text
4427 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4428 (org-property-values "A")))
4429 ;; Take into consideration extended values.
4432 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4433 (org-property-values "A")))))
4435 (ert-deftest test-org
/find-property
()
4436 "Test `org-find-property' specifications."
4440 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4441 (org-find-property "prop"))))
4442 ;; Ignore false positives.
4445 (org-test-with-temp-text
4446 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4447 (org-find-property "A"))))
4448 ;; Return first entry found in buffer.
4451 (org-test-with-temp-text
4452 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4453 (org-find-property "A"))))
4454 ;; Only search visible part of the buffer.
4457 (org-test-with-temp-text
4458 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4459 (org-narrow-to-subtree)
4460 (org-find-property "A"))))
4461 ;; With optional argument, only find entries with a specific value.
4463 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4464 (org-find-property "A" "2")))
4467 (org-test-with-temp-text
4468 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4469 (org-find-property "A" "2"))))
4470 ;; Use "nil" for explicit nil values.
4473 (org-test-with-temp-text
4474 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4475 (org-find-property "A" "nil")))))
4477 (ert-deftest test-org
/entry-delete
()
4478 "Test `org-entry-delete' specifications."
4482 " *:PROPERTIES:\n *:B: +2\n *:END:"
4483 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4484 (org-entry-delete (point) "A")
4486 ;; Also remove accumulated properties.
4490 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4491 (org-entry-delete (point) "A")
4493 ;; When last property is removed, remove the property drawer.
4497 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4498 (org-entry-delete (point) "A")
4500 ;; Return a non-nil value when some property was removed.
4502 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4503 (org-entry-delete (point) "A")))
4505 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4506 (org-entry-delete (point) "C")))
4507 ;; Special properties cannot be located in a drawer. Allow to
4508 ;; remove them anyway, in case of user error.
4510 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4511 (org-entry-delete (point) "SCHEDULED"))))
4513 (ert-deftest test-org
/entry-get
()
4514 "Test `org-entry-get' specifications."
4518 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4519 (org-entry-get (point) "A"))))
4523 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4524 (org-entry-get (point) "a"))))
4525 ;; Handle extended values, both before and after base value.
4528 (org-test-with-temp-text
4529 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4530 (org-entry-get (point) "A"))))
4531 ;; Empty values are returned as the empty string.
4534 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4535 (org-entry-get (point) "A"))))
4536 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4537 ;; otherwise, return nil.
4539 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4540 (org-entry-get (point) "A")))
4543 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4544 (org-entry-get (point) "A" nil t
))))
4545 ;; Return nil when no property is found, independently on the
4546 ;; LITERAL-NIL argument.
4548 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4549 (org-entry-get (point) "B")))
4551 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4552 (org-entry-get (point) "B" nil t
)))
4553 ;; Handle inheritance, when allowed. Include extended values and
4554 ;; possibly global values.
4558 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4559 (org-entry-get (point) "A" t
))))
4563 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4564 (let ((org-use-property-inheritance t
))
4565 (org-entry-get (point) "A" 'selective
)))))
4567 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4568 (let ((org-use-property-inheritance nil
))
4569 (org-entry-get (point) "A" 'selective
))))
4573 (org-test-with-temp-text
4574 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4575 (org-entry-get (point-max) "A" t
))))
4578 (org-test-with-temp-text
4579 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4581 (org-entry-get (point-max) "A" t
))))
4584 (org-test-with-temp-text
4585 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4587 (org-entry-get (point-max) "A" t
)))))
4589 (ert-deftest test-org
/entry-properties
()
4590 "Test `org-entry-properties' specifications."
4591 ;; Get "ITEM" property.
4594 (org-test-with-temp-text "* TODO H"
4595 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4598 (org-test-with-temp-text "* TODO H"
4599 (cdr (assoc "ITEM" (org-entry-properties))))))
4600 ;; Get "TODO" property. TODO keywords are case sensitive.
4603 (org-test-with-temp-text "* TODO H"
4604 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4607 (org-test-with-temp-text "* TODO H"
4608 (cdr (assoc "TODO" (org-entry-properties))))))
4610 (org-test-with-temp-text "* H"
4611 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4613 (org-test-with-temp-text "* todo H"
4614 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4615 ;; Get "PRIORITY" property.
4618 (org-test-with-temp-text "* [#A] H"
4619 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4622 (org-test-with-temp-text "* [#A] H"
4623 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4625 (equal (char-to-string org-default-priority
)
4626 (org-test-with-temp-text "* H"
4627 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4628 ;; Get "FILE" property.
4630 (org-test-with-temp-text-in-file "* H\nParagraph"
4631 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4632 (buffer-file-name))))
4634 (org-test-with-temp-text-in-file "* H\nParagraph"
4635 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4636 (buffer-file-name))))
4638 (org-test-with-temp-text "* H\nParagraph"
4639 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4640 ;; Get "TAGS" property.
4642 (equal ":tag1:tag2:"
4643 (org-test-with-temp-text "* H :tag1:tag2:"
4644 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4646 (equal ":tag1:tag2:"
4647 (org-test-with-temp-text "* H :tag1:tag2:"
4648 (cdr (assoc "TAGS" (org-entry-properties))))))
4650 (org-test-with-temp-text "* H"
4651 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4652 ;; Get "ALLTAGS" property.
4654 (equal ":tag1:tag2:"
4655 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4656 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4658 (equal ":tag1:tag2:"
4659 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4660 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4662 (org-test-with-temp-text "* H"
4663 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4664 ;; Get "BLOCKED" property.
4667 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4668 (let ((org-enforce-todo-dependencies t
)
4670 '(org-block-todo-from-children-or-siblings-or-parent)))
4671 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4674 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4675 (let ((org-enforce-todo-dependencies t
)
4677 '(org-block-todo-from-children-or-siblings-or-parent)))
4678 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4679 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4683 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4684 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4688 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4689 (cdr (assoc "CLOSED" (org-entry-properties))))))
4691 (org-test-with-temp-text "* H"
4692 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4696 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4697 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4701 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4702 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4704 (org-test-with-temp-text "* H"
4705 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4709 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4710 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4714 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4715 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4717 (org-test-with-temp-text "* H"
4718 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4722 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4723 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4726 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4727 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4730 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4731 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4734 (org-test-with-temp-text
4735 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4737 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4738 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4739 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4741 (equal "<2012-03-29 thu.>"
4742 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4743 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4745 (equal "[2012-03-29 thu.]"
4746 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4747 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4749 (equal "<2012-03-29 thu.>"
4750 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4751 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4753 (equal "[2014-03-04 tue.]"
4754 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4755 (cdr (assoc "TIMESTAMP_IA"
4756 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4758 (equal "<2012-03-29 thu.>"
4759 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4760 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4761 ;; Get standard properties.
4764 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4765 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4766 ;; Handle extended properties.
4769 (org-test-with-temp-text
4770 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4771 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4774 (org-test-with-temp-text
4775 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4776 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4777 ;; Ignore forbidden (special) properties.
4779 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4780 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4782 (ert-deftest test-org
/entry-put
()
4783 "Test `org-entry-put' specifications."
4784 ;; Error when not a string or nil.
4786 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4787 (org-entry-put 1 "test" 2)))
4788 ;; Error when property name is invalid.
4790 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4791 (org-entry-put 1 "no space" "value")))
4793 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4794 (org-entry-put 1 "" "value")))
4795 ;; Set "TODO" property.
4797 (string-match (regexp-quote " TODO H")
4798 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4799 (org-entry-put (point) "TODO" "TODO")
4802 (string-match (regexp-quote "* H")
4803 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4804 (org-entry-put (point) "TODO" nil
)
4806 ;; Set "PRIORITY" property.
4809 (org-test-with-temp-text "* [#B] H"
4810 (org-entry-put (point) "PRIORITY" "A")
4814 (org-test-with-temp-text "* [#B] H"
4815 (org-entry-put (point) "PRIORITY" nil
)
4817 ;; Set "SCHEDULED" property.
4819 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4820 (org-test-with-temp-text "* H"
4821 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4825 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4826 (org-entry-put (point) "SCHEDULED" nil
)
4829 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4830 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4831 (org-entry-put (point) "SCHEDULED" "earlier")
4834 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4835 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4836 (org-entry-put (point) "SCHEDULED" "later")
4838 ;; Set "DEADLINE" property.
4840 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4841 (org-test-with-temp-text "* H"
4842 (org-entry-put (point) "DEADLINE" "2014-03-04")
4846 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4847 (org-entry-put (point) "DEADLINE" nil
)
4850 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4851 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4852 (org-entry-put (point) "DEADLINE" "earlier")
4855 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4856 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4857 (org-entry-put (point) "DEADLINE" "later")
4859 ;; Set "CATEGORY" property
4861 (string-match "^ *:CATEGORY: cat"
4862 (org-test-with-temp-text "* H"
4863 (org-entry-put (point) "CATEGORY" "cat")
4865 ;; Regular properties, with or without pre-existing drawer.
4867 (string-match "^ *:A: +2$"
4868 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4869 (org-entry-put (point) "A" "2")
4872 (string-match "^ *:A: +1$"
4873 (org-test-with-temp-text "* H"
4874 (org-entry-put (point) "A" "1")
4876 ;; Special case: two consecutive headlines.
4878 (string-match "\\* A\n *:PROPERTIES:"
4879 (org-test-with-temp-text "* A\n** B"
4880 (org-entry-put (point) "A" "1")
4883 (ert-deftest test-org
/refresh-properties
()
4884 "Test `org-refresh-properties' specifications."
4887 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4888 (org-refresh-properties "A" 'org-test
)
4889 (get-text-property (point) 'org-test
))))
4891 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4892 (org-refresh-properties "B" 'org-test
)
4893 (get-text-property (point) 'org-test
)))
4894 ;; Handle properties only defined with extension syntax, i.e.,
4898 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4899 (org-refresh-properties "A" 'org-test
)
4900 (get-text-property (point) 'org-test
))))
4901 ;; When property is inherited, add text property to the whole
4905 (org-test-with-temp-text
4906 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4907 (let ((org-use-property-inheritance t
))
4908 (org-refresh-properties "A" 'org-test
))
4909 (get-text-property (point) 'org-test
))))
4910 ;; When property is inherited, use global value across the whole
4911 ;; buffer. However local values have precedence.
4914 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4916 (let ((org-use-property-inheritance nil
))
4917 (org-refresh-properties "A" 'org-test
))
4918 (get-text-property (point) 'org-test
))))
4921 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4923 (let ((org-use-property-inheritance t
))
4924 (org-refresh-properties "A" 'org-test
))
4925 (get-text-property (point) 'org-test
))))
4928 (org-test-with-temp-text
4929 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4931 (let ((org-use-property-inheritance t
))
4932 (org-refresh-properties "A" 'org-test
))
4933 (get-text-property (point) 'org-test
)))))
4938 (ert-deftest test-org
/update-radio-target-regexp
()
4939 "Test `org-update-radio-target-regexp' specifications."
4940 ;; Properly update cache with no previous radio target regexp.
4943 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4944 (save-excursion (goto-char (point-max)) (org-element-context))
4946 (search-forward "o")
4948 (org-update-radio-target-regexp)
4949 (goto-char (point-max))
4950 (org-element-type (org-element-context)))))
4951 ;; Properly update cache with previous radio target regexp.
4954 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4955 (save-excursion (goto-char (point-max)) (org-element-context))
4957 (search-forward "o")
4959 (org-update-radio-target-regexp)
4960 (search-backward "r")
4963 (org-update-radio-target-regexp)
4964 (goto-char (point-max))
4965 (delete-region (line-beginning-position) (point))
4967 (org-element-type (org-element-context))))))
4972 (ert-deftest test-org
/match-sparse-tree
()
4973 "Test `org-match-sparse-tree' specifications."
4976 (org-test-with-temp-text "* H\n** H1 :tag:"
4977 (org-match-sparse-tree nil
"tag")
4978 (search-forward "H1")
4979 (org-invisible-p2)))
4981 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4982 (org-match-sparse-tree nil
"tag")
4983 (search-forward "H2")
4984 (org-invisible-p2)))
4985 ;; "-" operator for tags.
4987 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4988 (org-match-sparse-tree nil
"tag1-tag2")
4989 (search-forward "H1")
4990 (org-invisible-p2)))
4992 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4993 (org-match-sparse-tree nil
"tag1-tag2")
4994 (search-forward "H2")
4995 (org-invisible-p2)))
4996 ;; "&" operator for tags.
4998 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4999 (org-match-sparse-tree nil
"tag1&tag2")
5000 (search-forward "H1")
5001 (org-invisible-p2)))
5003 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5004 (org-match-sparse-tree nil
"tag1&tag2")
5005 (search-forward "H2")
5006 (org-invisible-p2)))
5007 ;; "|" operator for tags.
5009 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5010 (org-match-sparse-tree nil
"tag1|tag2")
5011 (search-forward "H1")
5012 (org-invisible-p2)))
5014 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5015 (org-match-sparse-tree nil
"tag1|tag2")
5016 (search-forward "H2")
5017 (org-invisible-p2)))
5018 ;; Regexp match on tags.
5020 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5021 (org-match-sparse-tree nil
"{^tag.*}")
5022 (search-forward "H1")
5023 (org-invisible-p2)))
5025 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5026 (org-match-sparse-tree nil
"{^tag.*}")
5027 (search-forward "H2")
5028 (org-invisible-p2)))
5029 ;; Match group tags.
5031 (org-test-with-temp-text
5032 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5033 (org-match-sparse-tree nil
"work")
5034 (search-forward "H1")
5035 (org-invisible-p2)))
5037 (org-test-with-temp-text
5038 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5039 (org-match-sparse-tree nil
"work")
5040 (search-forward "H2")
5041 (org-invisible-p2)))
5042 ;; Match group tags with hard brackets.
5044 (org-test-with-temp-text
5045 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5046 (org-match-sparse-tree nil
"work")
5047 (search-forward "H1")
5048 (org-invisible-p2)))
5050 (org-test-with-temp-text
5051 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5052 (org-match-sparse-tree nil
"work")
5053 (search-forward "H2")
5054 (org-invisible-p2)))
5055 ;; Match tags in hierarchies
5057 (org-test-with-temp-text
5058 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5059 #+TAGS: [ Lev_2 : Lev_3 ]\n
5060 #+TAGS: { Lev_3 : Lev_4 }\n
5061 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5062 (org-match-sparse-tree nil
"Lev_1")
5063 (search-forward "H4")
5064 (org-invisible-p2)))
5065 ;; Match regular expressions in tags
5067 (org-test-with-temp-text
5068 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5069 (org-match-sparse-tree nil
"Lev")
5070 (search-forward "H1")
5071 (org-invisible-p2)))
5073 (org-test-with-temp-text
5074 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5075 (org-match-sparse-tree nil
"Lev")
5076 (search-forward "H1")
5077 (org-invisible-p2)))
5078 ;; Match properties.
5080 (org-test-with-temp-text
5081 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5082 (org-match-sparse-tree nil
"A=\"1\"")
5083 (search-forward "H2")
5084 (org-invisible-p2)))
5086 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5087 (org-match-sparse-tree nil
"A=\"1\"")
5088 (search-forward "H2")
5089 (org-invisible-p2)))
5090 ;; Case is not significant when matching properties.
5092 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5093 (org-match-sparse-tree nil
"a=\"1\"")
5094 (search-forward "H2")
5095 (org-invisible-p2)))
5097 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5098 (org-match-sparse-tree nil
"A=\"1\"")
5099 (search-forward "H2")
5100 (org-invisible-p2)))
5101 ;; Match special LEVEL property.
5103 (org-test-with-temp-text "* H\n** H1\n*** H2"
5104 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5105 (search-forward "H1")
5106 (org-invisible-p2)))
5108 (org-test-with-temp-text "* H\n** H1\n*** H2"
5109 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5110 (search-forward "H2")
5111 (org-invisible-p2)))
5112 ;; Comparison operators when matching properties.
5114 (org-test-with-temp-text
5115 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5116 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5117 (search-forward "H1")
5118 (org-invisible-p2)))
5120 (org-test-with-temp-text
5121 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5122 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5123 (search-forward "H2")
5124 (org-invisible-p2)))
5125 ;; Regexp match on properties values.
5127 (org-test-with-temp-text
5128 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5129 (org-match-sparse-tree nil
"A={f.*}")
5130 (search-forward "H1")
5131 (org-invisible-p2)))
5133 (org-test-with-temp-text
5134 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5135 (org-match-sparse-tree nil
"A={f.*}")
5136 (search-forward "H2")
5137 (org-invisible-p2)))
5138 ;; With an optional argument, limit match to TODO entries.
5140 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5141 (org-match-sparse-tree t
"tag")
5142 (search-forward "H1")
5143 (org-invisible-p2)))
5145 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5146 (org-match-sparse-tree t
"tag")
5147 (search-forward "H2")
5148 (org-invisible-p2))))
5150 (ert-deftest test-org
/occur
()
5151 "Test `org-occur' specifications."
5152 ;; Count number of matches.
5155 (org-test-with-temp-text "* H\nA\n* H2"
5159 (org-test-with-temp-text "* H\nA\n* H2\nA"
5161 ;; Test CALLBACK optional argument.
5164 (org-test-with-temp-text "* H\nA\n* H2"
5165 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5168 (org-test-with-temp-text "* H\nA\n* H2\nA"
5169 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5170 ;; Case-fold searches according to `org-occur-case-fold-search'.
5173 (org-test-with-temp-text "Aa"
5174 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5177 (org-test-with-temp-text "Aa"
5178 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5181 (org-test-with-temp-text "Aa"
5182 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5185 (org-test-with-temp-text "Aa"
5186 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5189 (org-test-with-temp-text "Aa"
5190 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5193 (org-test-with-temp-text "Aa"
5194 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5199 (ert-deftest test-org
/tag-string-to-alist
()
5200 "Test `org-tag-string-to-alist' specifications."
5201 ;; Tag without selection key.
5202 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5203 ;; Tag with selection key.
5204 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5208 (org-tag-string-to-alist "[ group : t1 t2 ]")
5209 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5210 ;; Mutually exclusive tags.
5211 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5212 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5215 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5216 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5218 (ert-deftest test-org
/tag-alist-to-string
()
5219 "Test `org-tag-alist-to-string' specifications."
5220 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5221 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5224 (org-tag-alist-to-string
5225 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5226 "[ group : t1 t2 ]"))
5228 (equal (org-tag-alist-to-string
5229 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5233 (org-tag-alist-to-string
5234 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5235 "{ group : tag1 tag2 }")))
5237 (ert-deftest test-org
/tag-alist-to-groups
()
5238 "Test `org-tag-alist-to-groups' specifications."
5240 (equal (org-tag-alist-to-groups
5241 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5242 '(("group" "t1" "t2"))))
5245 (org-tag-alist-to-groups
5246 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5247 '(("group" "t1" "t2"))))
5249 (org-tag-alist-to-groups
5250 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5252 (ert-deftest test-org
/tag-align
()
5253 "Test tags alignment."
5254 ;; Test aligning tags with different display width.
5256 ;; 12345678901234567890
5257 (equal "* Test :abc:"
5258 (org-test-with-temp-text "* Test :abc:"
5259 (let ((org-tags-column -
20)
5260 (indent-tabs-mode nil
))
5261 (org-fix-tags-on-the-fly))
5264 ;; 12345678901234567890
5265 (equal "* Test :日本語:"
5266 (org-test-with-temp-text "* Test :日本語:"
5267 (let ((org-tags-column -
20)
5268 (indent-tabs-mode nil
))
5269 (org-fix-tags-on-the-fly))
5271 ;; Make sure aligning tags do not skip invisible text.
5273 (equal "* [[linkx]] :tag:"
5274 (org-test-with-temp-text "* [[link<point>]] :tag:"
5275 (let ((org-tags-column 0))
5276 (org-fix-tags-on-the-fly)
5278 (buffer-string))))))
5280 (ert-deftest test-org
/tags-at
()
5282 (equal '("foo" "bar")
5283 (org-test-with-temp-text
5284 "* T<point>est :foo:bar:"
5285 (org-get-tags-at)))))
5290 (ert-deftest test-org
/auto-repeat-maybe
()
5291 "Test `org-auto-repeat-maybe' specifications."
5292 ;; Do not auto repeat when there is no valid time stamp with
5293 ;; a repeater in the entry.
5297 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5298 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5304 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5305 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5308 ;; When switching to DONE state, switch back to first TODO keyword
5309 ;; in sequence, or the same keyword if they have different types.
5313 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5314 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5320 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5321 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5327 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5328 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5331 ;; If there was no TODO keyword in the first place, do not insert
5336 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5337 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5340 ;; Revert to REPEAT_TO_STATE, if set.
5344 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5345 (org-test-with-temp-text
5348 :REPEAT_TO_STATE: KWD2
5350 <2012-03-29 Thu +2y>"
5353 ;; When switching to DONE state, update base date. If there are
5354 ;; multiple repeated time stamps, update them all.
5357 "<2014-03-29 .* \\+2y>"
5358 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5359 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5364 "<2015-03-04 .* \\+1y>"
5365 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5366 (org-test-with-temp-text
5367 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5370 ;; Throw an error if repeater unit is the hour and no time is
5371 ;; provided in the time-stamp.
5373 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5374 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5377 ;; Do not repeat commented time stamps.
5380 "<2015-03-04 .* \\+1y>"
5381 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5382 (org-test-with-temp-text
5383 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5388 "<2015-03-04 .* \\+1y>"
5389 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5390 (org-test-with-temp-text
5392 <2012-03-29 Thu. +2y>
5394 <2014-03-04 Tue +1y>
5398 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5399 ;; entry, record time of last repeat.
5403 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5404 (org-log-repeat nil
))
5405 (cl-letf (((symbol-function 'org-add-log-setup
)
5406 (lambda (&rest args
) nil
)))
5407 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5409 (buffer-string))))))
5413 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5415 (cl-letf (((symbol-function 'org-add-log-setup
)
5416 (lambda (&rest args
) nil
)))
5417 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5419 (buffer-string))))))
5423 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5424 (cl-letf (((symbol-function 'org-add-log-setup
)
5425 (lambda (&rest args
) nil
)))
5426 (org-test-with-temp-text
5427 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5429 (buffer-string))))))
5430 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5431 ;; the entry as it is no longer relevant.
5435 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5436 (org-test-with-temp-text
5437 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5439 (buffer-string))))))
5444 (ert-deftest test-org
/at-timestamp-p
()
5445 "Test `org-at-timestamp-p' specifications."
5447 (org-test-with-temp-text "<2012-03-29 Thu>"
5448 (org-at-timestamp-p)))
5450 (org-test-with-temp-text "2012-03-29 Thu"
5451 (org-at-timestamp-p)))
5452 ;; Test return values.
5455 (org-test-with-temp-text "<2012-03-29 Thu>"
5456 (org-at-timestamp-p))))
5459 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5460 (org-at-timestamp-p))))
5463 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5464 (org-at-timestamp-p))))
5467 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5468 (org-at-timestamp-p))))
5471 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5472 (org-at-timestamp-p))))
5475 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5476 (org-at-timestamp-p))))
5479 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5480 (org-at-timestamp-p))))
5483 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5484 (org-at-timestamp-p))))
5485 ;; Test optional argument.
5487 (org-test-with-temp-text "[2012-03-29 Thu]"
5488 (org-at-timestamp-p t
)))
5490 (org-test-with-temp-text "[2012-03-29 Thu]"
5491 (org-at-timestamp-p)))
5492 ;; Unlike `org-element-context', recognize time-stamps in planning
5493 ;; info line, property drawers and clocks.
5495 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5496 (org-at-timestamp-p)))
5498 (org-test-with-temp-text
5499 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5500 (org-at-timestamp-p)))
5502 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5503 (org-at-timestamp-p t
))))
5505 (ert-deftest test-org
/time-stamp
()
5506 "Test `org-time-stamp' specifications."
5507 ;; Insert chosen time stamp at point.
5510 "Te<2014-03-04 .*?>xt"
5511 (org-test-with-temp-text "Te<point>xt"
5512 (cl-letf (((symbol-function 'org-read-date
)
5513 (lambda (&rest args
)
5514 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5515 (org-time-stamp nil
)
5517 ;; With a prefix argument, also insert time.
5520 "Te<2014-03-04 .*? 00:41>xt"
5521 (org-test-with-temp-text "Te<point>xt"
5522 (cl-letf (((symbol-function 'org-read-date
)
5523 (lambda (&rest args
)
5524 (apply #'encode-time
5525 (org-parse-time-string "2014-03-04 00:41")))))
5526 (org-time-stamp '(4))
5528 ;; With two universal prefix arguments, insert an active timestamp
5529 ;; with the current time without prompting the user.
5532 "Te<2014-03-04 .*? 00:41>xt"
5533 (org-test-with-temp-text "Te<point>xt"
5534 (cl-letf (((symbol-function 'current-time
)
5536 (apply #'encode-time
5537 (org-parse-time-string "2014-03-04 00:41")))))
5538 (org-time-stamp '(16))
5540 ;; When optional argument is non-nil, insert an inactive timestamp.
5543 "Te\\[2014-03-04 .*?\\]xt"
5544 (org-test-with-temp-text "Te<point>xt"
5545 (cl-letf (((symbol-function 'org-read-date
)
5546 (lambda (&rest args
)
5547 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5548 (org-time-stamp nil t
)
5550 ;; When called from a timestamp, replace existing one.
5554 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5555 (cl-letf (((symbol-function 'org-read-date
)
5556 (lambda (&rest args
)
5557 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5558 (org-time-stamp nil
)
5562 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5563 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5564 (cl-letf (((symbol-function 'org-read-date
)
5565 (lambda (&rest args
)
5566 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5567 (org-time-stamp nil
)
5569 ;; When replacing a timestamp, preserve repeater, if any.
5572 "<2014-03-04 .*? \\+2y>"
5573 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5574 (cl-letf (((symbol-function 'org-read-date
)
5575 (lambda (&rest args
)
5576 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5577 (org-time-stamp nil
)
5579 ;; When called twice in a raw, build a date range.
5582 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5583 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5584 (cl-letf (((symbol-function 'org-read-date
)
5585 (lambda (&rest args
)
5586 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5587 (let ((last-command 'org-time-stamp
)
5588 (this-command 'org-time-stamp
))
5589 (org-time-stamp nil
))
5590 (buffer-string))))))
5592 (ert-deftest test-org
/timestamp-has-time-p
()
5593 "Test `org-timestamp-has-time-p' specifications."
5596 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5597 (org-timestamp-has-time-p (org-element-context))))
5600 (org-test-with-temp-text "<2012-03-29 Thu>"
5601 (org-timestamp-has-time-p (org-element-context)))))
5603 (ert-deftest test-org
/get-repeat
()
5604 "Test `org-get-repeat' specifications."
5606 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
5609 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
5611 ;; Return proper repeat string.
5614 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
5616 ;; Prevent false positive (commented or verbatim time stamps)
5618 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
5621 (org-test-with-temp-text
5622 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
5624 ;; Return nil when called before first heading.
5626 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
5628 ;; When called with an optional argument, extract repeater from that
5630 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
5631 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
5633 (ert-deftest test-org
/timestamp-format
()
5634 "Test `org-timestamp-format' specifications."
5639 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5640 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5645 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5646 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5648 (ert-deftest test-org
/timestamp-split-range
()
5649 "Test `org-timestamp-split-range' specifications."
5650 ;; Extract range start (active).
5653 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5654 (let ((ts (org-timestamp-split-range (org-element-context))))
5655 (mapcar (lambda (p) (org-element-property p ts
))
5656 '(:year-end
:month-end
:day-end
))))))
5657 ;; Extract range start (inactive)
5660 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5661 (let ((ts (org-timestamp-split-range (org-element-context))))
5662 (mapcar (lambda (p) (org-element-property p ts
))
5663 '(:year-end
:month-end
:day-end
))))))
5664 ;; Extract range end (active).
5667 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5668 (let ((ts (org-timestamp-split-range
5669 (org-element-context) t
)))
5670 (mapcar (lambda (p) (org-element-property p ts
))
5671 '(:year-end
:month-end
:day-end
))))))
5672 ;; Extract range end (inactive)
5675 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5676 (let ((ts (org-timestamp-split-range
5677 (org-element-context) t
)))
5678 (mapcar (lambda (p) (org-element-property p ts
))
5679 '(:year-end
:month-end
:day-end
))))))
5680 ;; Return the timestamp if not a range.
5682 (org-test-with-temp-text "[2012-03-29 Thu]"
5683 (let* ((ts-orig (org-element-context))
5684 (ts-copy (org-timestamp-split-range ts-orig
)))
5685 (eq ts-orig ts-copy
))))
5687 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5688 (let* ((ts-orig (org-element-context))
5689 (ts-copy (org-timestamp-split-range ts-orig
)))
5690 (eq ts-orig ts-copy
)))))
5692 (ert-deftest test-org
/timestamp-translate
()
5693 "Test `org-timestamp-translate' specifications."
5694 ;; Translate whole date range.
5697 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5698 (let ((org-display-custom-times t
)
5699 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5700 (org-timestamp-translate (org-element-context))))))
5701 ;; Translate date range start.
5704 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5705 (let ((org-display-custom-times t
)
5706 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5707 (org-timestamp-translate (org-element-context) 'start
)))))
5708 ;; Translate date range end.
5711 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5712 (let ((org-display-custom-times t
)
5713 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5714 (org-timestamp-translate (org-element-context) 'end
)))))
5715 ;; Translate time range.
5718 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5719 (let ((org-display-custom-times t
)
5720 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5721 (org-timestamp-translate (org-element-context))))))
5722 ;; Translate non-range timestamp.
5725 (org-test-with-temp-text "<2012-03-29 Thu>"
5726 (let ((org-display-custom-times t
)
5727 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5728 (org-timestamp-translate (org-element-context))))))
5729 ;; Do not change `diary' timestamps.
5731 (equal "<%%(org-float t 4 2)>"
5732 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5733 (let ((org-display-custom-times t
)
5734 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5735 (org-timestamp-translate (org-element-context)))))))
5741 (ert-deftest test-org
/flag-drawer
()
5742 "Test `org-flag-drawer' specifications."
5745 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5747 (get-char-property (line-end-position) 'invisible
)))
5750 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5752 (org-flag-drawer nil
)
5753 (get-char-property (line-end-position) 'invisible
)))
5754 ;; Test optional argument.
5756 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5757 (let ((drawer (save-excursion (search-forward ":D2")
5758 (org-element-at-point))))
5759 (org-flag-drawer t drawer
)
5760 (get-char-property (progn (search-forward ":D2") (line-end-position))
5763 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5764 (let ((drawer (save-excursion (search-forward ":D2")
5765 (org-element-at-point))))
5766 (org-flag-drawer t drawer
)
5767 (get-char-property (line-end-position) 'invisible
))))
5768 ;; Do not hide fake drawers.
5770 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5773 (get-char-property (line-end-position) 'invisible
)))
5774 ;; Do not hide incomplete drawers.
5776 (org-test-with-temp-text ":D:\nparagraph"
5779 (get-char-property (line-end-position) 'invisible
)))
5780 ;; Do not hide drawers when called from final blank lines.
5782 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5783 (goto-char (point-max))
5785 (goto-char (point-min))
5786 (get-char-property (line-end-position) 'invisible
)))
5787 ;; Don't leave point in an invisible part of the buffer when hiding
5790 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5791 (goto-char (point-max))
5793 (get-char-property (point) 'invisible
))))
5795 (ert-deftest test-org
/hide-block-toggle
()
5796 "Test `org-hide-block-toggle' specifications."
5797 ;; Error when not at a block.
5799 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5800 (org-hide-block-toggle 'off
)
5801 (get-char-property (line-end-position) 'invisible
)))
5804 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5805 (org-hide-block-toggle)
5806 (get-char-property (line-end-position) 'invisible
)))
5808 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5809 (org-hide-block-toggle)
5810 (get-char-property (line-end-position) 'invisible
)))
5811 ;; Show block unconditionally when optional argument is `off'.
5813 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5814 (org-hide-block-toggle)
5815 (org-hide-block-toggle 'off
)
5816 (get-char-property (line-end-position) 'invisible
)))
5818 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5819 (org-hide-block-toggle 'off
)
5820 (get-char-property (line-end-position) 'invisible
)))
5821 ;; Hide block unconditionally when optional argument is non-nil.
5823 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5824 (org-hide-block-toggle t
)
5825 (get-char-property (line-end-position) 'invisible
)))
5827 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5828 (org-hide-block-toggle)
5829 (org-hide-block-toggle t
)
5830 (get-char-property (line-end-position) 'invisible
)))
5831 ;; Do not hide block when called from final blank lines.
5833 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5834 (org-hide-block-toggle)
5835 (goto-char (point-min))
5836 (get-char-property (line-end-position) 'invisible
)))
5837 ;; Don't leave point in an invisible part of the buffer when hiding
5840 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5841 (org-hide-block-toggle)
5842 (get-char-property (point) 'invisible
))))
5844 (ert-deftest test-org
/hide-block-toggle-maybe
()
5845 "Test `org-hide-block-toggle-maybe' specifications."
5847 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5848 (org-hide-block-toggle-maybe)))
5850 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5852 (ert-deftest test-org
/set-tags
()
5853 "Test `org-set-tags' specifications."
5854 ;; Tags set via fast-tag-selection should be visible afterwards
5856 (let ((org-tag-alist '(("NEXT" . ?n
)))
5857 (org-fast-tag-selection-single-key t
))
5858 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5859 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5860 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5861 ;; Show only headlines
5863 ;; Set NEXT tag on current entry
5864 (org-set-tags nil nil
)
5865 ;; Move point to that NEXT tag
5866 (search-forward "NEXT") (backward-word)
5867 ;; And it should be visible (i.e. no overlays)
5868 (not (overlays-at (point))))))))
5870 (ert-deftest test-org
/show-set-visibility
()
5871 "Test `org-show-set-visibility' specifications."
5872 ;; Do not throw an error before first heading.
5874 (org-test-with-temp-text "Preamble\n* Headline"
5875 (org-show-set-visibility 'tree
)
5877 ;; Test all visibility spans, both on headline and in entry.
5878 (let ((list-visible-lines
5879 (lambda (state headerp
)
5880 (org-test-with-temp-text "* Grandmother (0)
5891 **** The other child (11)
5896 (search-forward (if headerp
"Self" "Match"))
5897 (org-show-set-visibility state
)
5898 (goto-char (point-min))
5899 (let (result (line 0))
5901 (unless (org-invisible-p2) (push line result
))
5904 (nreverse result
))))))
5905 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5906 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5907 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5908 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5909 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5910 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5911 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5912 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5913 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5914 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5915 (funcall list-visible-lines
'tree nil
)))
5916 (should (equal '(0 1 3 4 5 7 12 13)
5917 (funcall list-visible-lines
'canonical t
)))
5918 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5919 (funcall list-visible-lines
'canonical nil
))))
5920 ;; When point is hidden in a drawer or a block, make sure to make it
5923 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5924 (org-hide-block-toggle)
5925 (search-forward "Text")
5926 (org-show-set-visibility 'minimal
)
5927 (org-invisible-p2)))
5929 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5931 (search-forward "Text")
5932 (org-show-set-visibility 'minimal
)
5933 (org-invisible-p2)))
5935 (org-test-with-temp-text
5936 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5939 (org-hide-block-toggle)
5940 (search-forward "Text")
5941 (org-show-set-visibility 'minimal
)
5942 (org-invisible-p2))))
5947 ;;; test-org.el ends here