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/>.
23 ;; Template test file for Org tests
30 (ert-deftest test-org
/toggle-comment
()
31 "Test `org-toggle-comment' specifications."
35 (org-test-with-temp-text "* COMMENT Test"
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
43 ;; Headline with a regular keyword.
46 (org-test-with-temp-text "* TODO COMMENT Test"
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
57 (org-test-with-temp-text "* COMMENT"
62 (org-test-with-temp-text "* "
65 ;; Headline with a single keyword.
68 (org-test-with-temp-text "* TODO COMMENT"
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
76 ;; Headline with a keyword, a priority cookie and contents.
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
88 (ert-deftest test-org
/comment-dwim
()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim
)
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim
)
104 ;; No region selected, and a comment on this line: indent it.
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t
))
110 (call-interactively 'comment-dwim
))
112 ;; Also recognize single # at column 0 as comments.
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim
)
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
125 (transient-mark-mode 1)
126 (push-mark (point) t t
)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim
)
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
136 (transient-mark-mode 1)
137 (push-mark (point) t t
)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil
))
140 (call-interactively 'comment-dwim
))
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
146 (transient-mark-mode 1)
147 (push-mark (point) t t
)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t
))
150 (call-interactively 'comment-dwim
))
152 ;; In front of a keyword without region, insert a new comment.
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim
)
158 ;; In a source block, use appropriate syntax.
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim
))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
170 (transient-mark-mode 1)
171 (push-mark (point) t t
)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim
))
179 ;;; Date and time analysis
181 (ert-deftest test-org
/org-read-date
()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t
))
186 (org-read-date t nil
"12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t
))
190 (org-read-date t nil
"29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t
))
194 (org-read-date t nil
"29.03. 16:40"))))
195 ;; Relative date applied to current time if there is single
196 ;; plus/minus, or to default date when there are two of them.
200 (cl-letf (((symbol-function 'current-time
)
202 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
205 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
209 (cl-letf (((symbol-function 'current-time
)
211 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
214 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
215 ;; When `org-read-date-prefer-future' is non-nil, prefer future
216 ;; dates (relatively to now) when incomplete. Otherwise, use
221 (cl-letf (((symbol-function 'current-time
)
223 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
224 (let ((org-read-date-prefer-future t
))
225 (org-read-date t nil
"1")))))
229 (cl-letf (((symbol-function 'current-time
)
231 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
232 (let ((org-read-date-prefer-future t
))
233 (org-read-date t nil
"3-4")))))
237 (cl-letf (((symbol-function 'current-time
)
239 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
240 (let ((org-read-date-prefer-future nil
))
241 (org-read-date t nil
"3-4")))))
242 ;; When set to `org-read-date-prefer-future' is set to `time', read
243 ;; day is moved to tomorrow if specified hour is before current
244 ;; time. However, it only happens in no other part of the date is
249 (cl-letf (((symbol-function 'current-time
)
251 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
252 (let ((org-read-date-prefer-future 'time
))
253 (org-read-date t nil
"00:40" nil
)))))
257 (cl-letf (((symbol-function 'current-time
)
259 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
260 (let ((org-read-date-prefer-future 'time
))
261 (org-read-date t nil
"29 00:40" nil
)))))
262 ;; Caveat: `org-read-date-prefer-future' always refers to current
263 ;; time, not default time, when they differ.
267 (cl-letf (((symbol-function 'current-time
)
269 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
270 (let ((org-read-date-prefer-future t
))
273 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
277 (cl-letf (((symbol-function 'current-time
)
279 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
280 (let ((org-read-date-prefer-future t
))
283 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
285 (ert-deftest test-org
/org-parse-time-string
()
286 "Test `org-parse-time-string'."
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 16:40>")
292 '(0 40 16 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>")
294 '(0 0 0 29 3 2012 nil nil nil
)))
295 (should (equal (org-parse-time-string "<2012-03-29>" t
)
296 '(0 nil nil
29 3 2012 nil nil nil
))))
298 (ert-deftest test-org
/closest-date
()
299 "Test `org-closest-date' specifications."
301 ;; Time stamps without a repeater are returned unchanged.
305 (calendar-gregorian-from-absolute
306 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
307 ;; Time stamps with a null repeater are returned unchanged.
311 (calendar-gregorian-from-absolute
312 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
313 ;; if PREFER is set to `past' always return a date before, or equal
318 (calendar-gregorian-from-absolute
319 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
323 (calendar-gregorian-from-absolute
324 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
325 ;; if PREFER is set to `future' always return a date before, or equal
330 (calendar-gregorian-from-absolute
331 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
335 (calendar-gregorian-from-absolute
336 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
337 ;; If PREFER is neither `past' nor `future', select closest date.
341 (calendar-gregorian-from-absolute
342 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
346 (calendar-gregorian-from-absolute
347 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
348 ;; Test "day" repeater.
351 (calendar-gregorian-from-absolute
352 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
355 (calendar-gregorian-from-absolute
356 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
357 ;; Test "month" repeater.
360 (calendar-gregorian-from-absolute
361 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
364 (calendar-gregorian-from-absolute
365 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
366 ;; Test "year" repeater.
369 (calendar-gregorian-from-absolute
370 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
373 (calendar-gregorian-from-absolute
374 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
376 (ert-deftest test-org
/deadline-close-p
()
377 "Test `org-deadline-close-p' specifications."
378 ;; Pretend that the current time is 2016-06-03 Fri 01:43
379 (cl-letf (((symbol-function 'current-time
)
380 (lambda () '(22353 6425 905205 644000))))
381 ;; Timestamps are close if they are within `ndays' of lead time.
382 (org-test-with-temp-text "* Heading"
383 (should (org-deadline-close-p "2016-06-03 Fri" 0))
384 (should (org-deadline-close-p "2016-06-02 Thu" 0))
385 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
386 (should (org-deadline-close-p "2016-06-04 Sat" 1))
387 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
388 ;; Read `ndays' from timestamp if argument not given.
389 (org-test-with-temp-text "* H"
390 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
391 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
392 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
393 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
394 ;; Prefer `ndays' argument over lead time in timestamp.
395 (org-test-with-temp-text "* H"
396 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
397 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
398 ;; Completed tasks are never close.
399 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
400 (org-test-with-temp-text "* TODO Heading"
401 (should (org-deadline-close-p "2016-06-03")))
402 (org-test-with-temp-text "* DONE Heading"
403 (should-not (org-deadline-close-p "2016-06-03"))))))
408 (ert-deftest test-org
/insert-property-drawer
()
409 "Test `org-insert-property-drawer' specifications."
410 ;; Error before first headline.
411 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
412 ;; Insert drawer right after headline if there is no planning line,
413 ;; or after it otherwise.
415 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text "* H\nParagraph<point>"
417 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
420 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
421 (org-test-with-temp-text
422 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
423 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
425 ;; Indent inserted drawer.
427 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
428 (org-test-with-temp-text "* H\nParagraph<point>"
429 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
431 ;; Handle insertion at eob.
433 (equal "* H\n:PROPERTIES:\n:END:\n"
434 (org-test-with-temp-text "* H"
435 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
437 ;; Skip inlinetasks before point.
438 (when (featurep 'org-inlinetask
)
440 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
441 (org-test-with-temp-text
442 "* H\n*************** I\n*************** END\nP<point>"
443 (let ((org-adapt-indentation nil
)
444 (org-inlinetask-min-level 15))
445 (org-insert-property-drawer))
447 ;; Correctly set drawer in an inlinetask.
448 (when (featurep 'org-inlinetask
)
450 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
451 (org-test-with-temp-text
452 "* H\n*************** I\nP<point>\n*************** END"
453 (let ((org-adapt-indentation nil
)
454 (org-inlinetask-min-level 15))
455 (org-insert-property-drawer))
461 (ert-deftest test-org
/fill-paragraph
()
462 "Test `org-fill-paragraph' specifications."
463 ;; At an Org table, align it.
466 (org-test-with-temp-text "|a|"
470 (equal "#+name: table\n| a |\n"
471 (org-test-with-temp-text "#+name: table\n| a |\n"
474 ;; At a paragraph, preserve line breaks.
475 (org-test-with-temp-text "some \\\\\nlong\ntext"
476 (let ((fill-column 20))
478 (should (equal (buffer-string) "some \\\\\nlong text"))))
479 ;; Correctly fill a paragraph when point is at its very end.
482 (org-test-with-temp-text "A\nB"
483 (let ((fill-column 20))
484 (goto-char (point-max))
487 ;; Correctly fill the last paragraph of a greater element.
489 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
490 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
491 (let ((fill-column 8))
496 ;; Correctly fill an element in a narrowed buffer.
499 (org-test-with-temp-text "01234 6789"
500 (let ((fill-column 5))
501 (narrow-to-region 1 8)
504 ;; Handle `adaptive-fill-regexp' in paragraphs.
507 (org-test-with-temp-text "> a\n> b"
508 (let ((fill-column 5)
509 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
512 ;; Special case: Fill first paragraph when point is at an item or
513 ;; a plain-list or a footnote reference.
516 (org-test-with-temp-text "- A\n B"
517 (let ((fill-column 20))
522 (org-test-with-temp-text "[fn:1] A\nB"
523 (let ((fill-column 20))
526 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
527 (let ((fill-column 20))
529 (should (equal (buffer-string)
530 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
531 ;; Fill contents of `comment-block' elements.
534 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
535 (let ((fill-column 20))
539 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
540 ;; Fill `comment' elements.
543 (org-test-with-temp-text " # A\n # B"
544 (let ((fill-column 20))
547 ;; Do not mix consecutive comments when filling one of them.
549 (equal "# A B\n\n# C"
550 (org-test-with-temp-text "# A\n# B\n\n# C"
551 (let ((fill-column 20))
554 ;; Use commented empty lines as separators when filling comments.
556 (equal "# A B\n#\n# C"
557 (org-test-with-temp-text "# A\n# B\n#\n# C"
558 (let ((fill-column 20))
561 ;; Handle `adaptive-fill-regexp' in comments.
564 (org-test-with-temp-text "# > a\n# > b"
565 (let ((fill-column 20)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
569 ;; Do nothing at affiliated keywords.
570 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
571 (let ((fill-column 20))
573 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
574 ;; Do not move point after table when filling a table.
576 (org-test-with-temp-text "| a | b |\n| c | d |\n"
581 (ert-deftest test-org
/auto-fill-function
()
582 "Test auto-filling features."
583 ;; Auto fill paragraph.
586 (org-test-with-temp-text "12345 7890"
587 (let ((fill-column 5))
589 (org-auto-fill-function)
591 ;; Auto fill first paragraph in an item.
593 (equal "- 12345\n 7890"
594 (org-test-with-temp-text "- 12345 7890"
595 (let ((fill-column 7))
597 (org-auto-fill-function)
599 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
601 (equal "> 12345\n 7890"
602 (org-test-with-temp-text "> 12345 7890"
603 (let ((fill-column 10)
604 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
605 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
607 (org-auto-fill-function)
610 (equal "> 12345\n> 12345\n> 7890"
611 (org-test-with-temp-text "> 12345\n> 12345 7890"
612 (let ((fill-column 10)
613 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
614 (goto-char (point-max))
615 (org-auto-fill-function)
618 (equal " 12345\n *12345\n *12345"
619 (org-test-with-temp-text " 12345\n *12345 12345"
620 (let ((fill-column 10)
621 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
622 (goto-char (point-max))
623 (org-auto-fill-function)
625 ;; Auto fill comments.
627 (equal " # 12345\n # 7890"
628 (org-test-with-temp-text " # 12345 7890"
629 (let ((fill-column 10))
631 (org-auto-fill-function)
633 ;; A hash within a line isn't a comment.
635 (equal "12345 # 7890\n# 1"
636 (org-test-with-temp-text "12345 # 7890 1"
637 (let ((fill-column 12))
639 (org-auto-fill-function)
641 ;; Correctly interpret empty prefix.
643 (equal "# a\n# b\nRegular\n# paragraph"
644 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
645 (let ((fill-column 12))
647 (org-auto-fill-function)
649 ;; Comment block: auto fill contents.
651 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
652 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
653 (let ((fill-column 5))
656 (org-auto-fill-function)
659 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
660 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
661 (let ((fill-column 5))
664 (org-auto-fill-function)
666 ;; Do not fill if a new item could be created.
669 (org-test-with-temp-text "12345 - 90"
670 (let ((fill-column 5))
672 (org-auto-fill-function)
674 ;; Do not fill if a line break could be introduced.
676 (equal "123\\\\\n7890"
677 (org-test-with-temp-text "123\\\\ 7890"
678 (let ((fill-column 6))
680 (org-auto-fill-function)
682 ;; Do not fill affiliated keywords.
684 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
685 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
686 (let ((fill-column 20))
688 (org-auto-fill-function)
695 (ert-deftest test-org
/indent-line
()
696 "Test `org-indent-line' specifications."
697 ;; Do not indent diary sexps, footnote definitions or headlines.
700 (org-test-with-temp-text "%%(org-calendar-holiday)"
702 (org-get-indentation))))
705 (org-test-with-temp-text "[fn:1] fn"
706 (let ((org-adapt-indentation t
)) (org-indent-line))
707 (org-get-indentation))))
710 (org-test-with-temp-text "* H"
712 (org-get-indentation))))
713 ;; Do not indent before first headline.
716 (org-test-with-temp-text ""
718 (org-get-indentation))))
719 ;; Indent according to headline level otherwise, unless
720 ;; `org-adapt-indentation' is nil.
723 (org-test-with-temp-text "* H\n<point>A"
724 (let ((org-adapt-indentation t
)) (org-indent-line))
725 (org-get-indentation))))
728 (org-test-with-temp-text "* H\n<point>\nA"
729 (let ((org-adapt-indentation t
)) (org-indent-line))
730 (org-get-indentation))))
733 (org-test-with-temp-text "* H\n<point>A"
734 (let ((org-adapt-indentation nil
)) (org-indent-line))
735 (org-get-indentation))))
736 ;; Indenting preserves point position.
738 (org-test-with-temp-text "* H\nA<point>B"
739 (let ((org-adapt-indentation t
)) (org-indent-line))
741 ;; Do not change indentation at an item or a LaTeX environment.
744 (org-test-with-temp-text "* H\n<point> - A"
745 (let ((org-adapt-indentation t
)) (org-indent-line))
746 (org-get-indentation))))
749 (org-test-with-temp-text
750 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
752 (org-get-indentation))))
753 ;; On blank lines at the end of a list, indent like last element
754 ;; within it if the line is still in the list. If the last element
755 ;; is an item, indent like its contents. Otherwise, indent like the
759 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
760 (let ((org-adapt-indentation t
)) (org-indent-line))
761 (org-get-indentation))))
764 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
765 (let ((org-adapt-indentation t
)) (org-indent-line))
766 (org-get-indentation))))
769 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
770 (let ((org-adapt-indentation t
)) (org-indent-line))
771 (org-get-indentation))))
774 (org-test-with-temp-text "* H\n- A\n - \n<point>"
775 (let ((org-adapt-indentation t
)) (org-indent-line))
776 (org-get-indentation))))
779 (org-test-with-temp-text
780 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
781 (let ((org-adapt-indentation t
)) (org-indent-line))
782 (org-get-indentation))))
785 (org-test-with-temp-text "- A\n B\n\n<point>"
786 (let ((org-adapt-indentation nil
)) (org-indent-line))
787 (org-get-indentation))))
790 (org-test-with-temp-text
791 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
792 (let ((org-adapt-indentation nil
)) (org-indent-line))
793 (org-get-indentation))))
794 ;; Likewise, on a blank line at the end of a footnote definition,
795 ;; indent at column 0 if line belongs to the definition. Otherwise,
796 ;; indent like the definition itself.
799 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
800 (let ((org-adapt-indentation t
)) (org-indent-line))
801 (org-get-indentation))))
804 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
805 (let ((org-adapt-indentation t
)) (org-indent-line))
806 (org-get-indentation))))
807 ;; After the end of the contents of a greater element, indent like
808 ;; the beginning of the element.
811 (org-test-with-temp-text
812 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
814 (org-get-indentation))))
815 ;; On blank lines after a paragraph, indent like its last non-empty
819 (org-test-with-temp-text " Paragraph\n\n<point>"
821 (org-get-indentation))))
822 ;; At the first line of an element, indent like previous element's
823 ;; first line, ignoring footnotes definitions and inline tasks, or
824 ;; according to parent.
827 (org-test-with-temp-text "A\n\n B\n\nC<point>"
829 (org-get-indentation))))
832 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
834 (org-get-indentation))))
837 (org-test-with-temp-text
838 " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
840 (org-get-indentation))))
841 ;; Within code part of a source block, use language major mode if
842 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
843 ;; according to line above.
846 (org-test-with-temp-text
847 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
848 (let ((org-src-tab-acts-natively t
)
849 (org-edit-src-content-indentation 0))
851 (org-get-indentation))))
854 (org-test-with-temp-text
855 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
856 (let ((org-src-tab-acts-natively nil
)
857 (org-edit-src-content-indentation 0))
859 (org-get-indentation))))
860 ;; Otherwise, indent like the first non-blank line above.
863 (org-test-with-temp-text
864 "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
866 (org-get-indentation))))
867 ;; Align node properties according to `org-property-format'. Handle
868 ;; nicely empty values.
870 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
871 (org-test-with-temp-text
872 "* 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* "
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* "
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* "
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 ;; When on a list, insert an item instead, unless called with an
1257 ;; universal argument or if list is invisible. In this case, create
1258 ;; a new headline after contents.
1260 (equal "* H\n- item\n- "
1261 (org-test-with-temp-text "* H\n- item<point>"
1262 (let ((org-insert-heading-respect-content nil
))
1263 (org-insert-heading))
1266 (equal "* H\n- item\n- item 2\n* "
1267 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1268 (let ((org-insert-heading-respect-content nil
))
1269 (org-insert-heading '(4)))
1272 (equal "* H\n- item\n* "
1273 (org-test-with-temp-text "* H\n- item"
1275 (goto-char (point-max))
1276 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1278 ;; Preserve list visibility when inserting an item.
1282 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1283 (let ((org-cycle-include-plain-lists t
))
1287 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1288 (list (get-char-property (line-beginning-position 0) 'invisible
)
1289 (get-char-property (line-end-position 2) 'invisible
))))))
1290 ;; When called with one universal argument, insert a new headline at
1291 ;; the end of the current subtree, independently on the position of
1296 (org-test-with-temp-text "* H1\n** H2"
1297 (let ((org-insert-heading-respect-content nil
))
1298 (org-insert-heading '(4)))
1303 (org-test-with-temp-text "* H<point>1\n** H2"
1304 (let ((org-insert-heading-respect-content nil
))
1305 (org-insert-heading '(4)))
1307 ;; When called with two universal arguments, insert a new headline
1308 ;; at the end of the grandparent subtree.
1310 (equal "* H1\n** H3\n- item\n** H2\n** "
1311 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1312 (let ((org-insert-heading-respect-content nil
))
1313 (org-insert-heading '(16)))
1315 ;; When optional TOP-LEVEL argument is non-nil, always insert
1316 ;; a level 1 heading.
1318 (equal "* H1\n** H2\n* "
1319 (org-test-with-temp-text "* H1\n** H2<point>"
1320 (org-insert-heading nil nil t
)
1323 (equal "* H1\n- item\n* "
1324 (org-test-with-temp-text "* H1\n- item<point>"
1325 (org-insert-heading nil nil t
)
1327 ;; Corner case: correctly insert a headline after an empty one.
1330 (org-test-with-temp-text "* <point>"
1331 (org-insert-heading)
1334 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1335 "Test `org-insert-todo-heading-respect-content' specifications."
1336 ;; Create a TODO heading.
1338 (org-test-with-temp-text "* H1\n Body"
1339 (org-insert-todo-heading-respect-content)
1340 (nth 2 (org-heading-components))))
1341 ;; Add headline at the end of the first subtree
1343 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1344 (search-forward "H1Body")
1345 (org-insert-todo-heading-respect-content)
1346 (and (eobp) (org-at-heading-p))))
1347 ;; In a list, do not create a new item.
1349 (org-test-with-temp-text "* H\n- an item\n- another one"
1350 (search-forward "an ")
1351 (org-insert-todo-heading-respect-content)
1352 (and (eobp) (org-at-heading-p)))))
1354 (ert-deftest test-org
/clone-with-time-shift
()
1355 "Test `org-clone-subtree-with-time-shift'."
1356 ;; Raise an error before first heading.
1358 (org-test-with-temp-text ""
1359 (org-clone-subtree-with-time-shift 1)))
1360 ;; Raise an error on invalid number of clones.
1362 (org-test-with-temp-text "* Clone me"
1363 (org-clone-subtree-with-time-shift -
1)))
1364 ;; Clone non-repeating once.
1370 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1371 (org-clone-subtree-with-time-shift 1 "+2d")
1372 (replace-regexp-in-string
1373 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1375 ;; Clone repeating once.
1380 * H1\n<2015-06-25 +1w>
1382 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1383 (org-clone-subtree-with-time-shift 1 "+2d")
1384 (replace-regexp-in-string
1385 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1387 ;; Clone non-repeating zero times.
1392 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1393 (org-clone-subtree-with-time-shift 0 "+2d")
1394 (replace-regexp-in-string
1395 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1397 ;; Clone repeating "zero" times.
1401 * H1\n<2015-06-23 +1w>
1403 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
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 with blank SHIFT argument.
1412 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1413 (org-clone-subtree-with-time-shift 1 "")
1414 (buffer-substring-no-properties (line-beginning-position 2)
1415 (line-end-position 2)))))
1416 ;; Find time stamps before point. If SHIFT is not specified, ask
1417 ;; for a time shift.
1421 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1422 (org-clone-subtree-with-time-shift 1 "+1d")
1423 (buffer-substring-no-properties (line-beginning-position 2)
1424 (line-end-position 2)))))
1428 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1429 (cl-letf (((symbol-function 'read-from-minibuffer
)
1430 (lambda (&rest args
) "+1d")))
1431 (org-clone-subtree-with-time-shift 1))
1432 (buffer-substring-no-properties (line-beginning-position 2)
1433 (line-end-position 2))))))
1436 ;;; Fixed-Width Areas
1438 (ert-deftest test-org
/toggle-fixed-width
()
1439 "Test `org-toggle-fixed-width' specifications."
1440 ;; No region: Toggle on fixed-width marker in paragraphs.
1443 (org-test-with-temp-text "A"
1444 (org-toggle-fixed-width)
1446 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1449 (org-test-with-temp-text ": A"
1450 (org-toggle-fixed-width)
1452 ;; No region: Toggle on marker in blank lines after elements or just
1453 ;; after a headline.
1456 (org-test-with-temp-text "* H\n"
1458 (org-toggle-fixed-width)
1461 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1462 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1463 (goto-char (point-max))
1464 (org-toggle-fixed-width)
1466 ;; No region: Toggle on marker in front of one line elements (e.g.,
1467 ;; headlines, clocks)
1469 (equal ": * Headline"
1470 (org-test-with-temp-text "* Headline"
1471 (org-toggle-fixed-width)
1474 (equal ": #+KEYWORD: value"
1475 (org-test-with-temp-text "#+KEYWORD: value"
1476 (org-toggle-fixed-width)
1478 ;; No region: error in other situations.
1480 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1482 (org-toggle-fixed-width)
1484 ;; No region: Indentation is preserved.
1487 (org-test-with-temp-text "- A\n B"
1489 (org-toggle-fixed-width)
1491 ;; Region: If it contains only fixed-width elements and blank lines,
1492 ;; toggle off fixed-width markup.
1495 (org-test-with-temp-text ": A\n\n: B"
1496 (transient-mark-mode 1)
1497 (push-mark (point) t t
)
1498 (goto-char (point-max))
1499 (org-toggle-fixed-width)
1501 ;; Region: If it contains anything else, toggle on fixed-width but
1502 ;; not on fixed-width areas.
1504 (equal ": A\n: \n: B\n: \n: C"
1505 (org-test-with-temp-text "A\n\n: B\n\nC"
1506 (transient-mark-mode 1)
1507 (push-mark (point) t t
)
1508 (goto-char (point-max))
1509 (org-toggle-fixed-width)
1511 ;; Region: Ignore blank lines at its end, unless it contains only
1515 (org-test-with-temp-text "A\n\n"
1516 (transient-mark-mode 1)
1517 (push-mark (point) t t
)
1518 (goto-char (point-max))
1519 (org-toggle-fixed-width)
1523 (org-test-with-temp-text "\n\n"
1524 (transient-mark-mode 1)
1525 (push-mark (point) t t
)
1526 (goto-char (point-max))
1527 (org-toggle-fixed-width)
1534 (ert-deftest test-org
/get-heading
()
1535 "Test `org-get-heading' specifications."
1536 ;; Return current heading, even if point is not on it.
1539 (org-test-with-temp-text "* H"
1540 (org-get-heading))))
1543 (org-test-with-temp-text "* H\nText<point>"
1544 (org-get-heading))))
1545 ;; Without any optional argument, return TODO keywords and tags.
1548 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1549 (org-get-heading))))
1552 (org-test-with-temp-text "* H :tag:"
1553 (org-get-heading))))
1554 ;; With NO-TAGS argument, ignore tags.
1557 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1558 (org-get-heading t
))))
1561 (org-test-with-temp-text "* H :tag:"
1562 (org-get-heading t
))))
1563 ;; With NO-TODO, ignore TODO keyword.
1566 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1567 (org-get-heading nil t
))))
1570 (org-test-with-temp-text "* H :tag:"
1571 (org-get-heading nil t
))))
1572 ;; TODO keywords are case-sensitive.
1575 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1576 (org-get-heading nil t
))))
1577 ;; On an empty headline, return value is consistent.
1578 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1579 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1580 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1581 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1583 (ert-deftest test-org
/in-commented-heading-p
()
1584 "Test `org-in-commented-heading-p' specifications."
1585 ;; Commented headline.
1587 (org-test-with-temp-text "* COMMENT Headline\nBody"
1588 (goto-char (point-max))
1589 (org-in-commented-heading-p)))
1590 ;; Commented ancestor.
1592 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1593 (goto-char (point-max))
1594 (org-in-commented-heading-p)))
1595 ;; Comment keyword is case-sensitive.
1597 (org-test-with-temp-text "* Comment Headline\nBody"
1598 (goto-char (point-max))
1599 (org-in-commented-heading-p)))
1600 ;; Keyword is standalone.
1602 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1603 (goto-char (point-max))
1604 (org-in-commented-heading-p)))
1605 ;; Optional argument.
1607 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1608 (goto-char (point-max))
1609 (org-in-commented-heading-p t
))))
1611 (ert-deftest test-org
/entry-blocked-p
()
1612 ;; Check other dependencies.
1614 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1615 (let ((org-enforce-todo-dependencies t
)
1617 '(org-block-todo-from-children-or-siblings-or-parent)))
1618 (org-entry-blocked-p))))
1620 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1621 (let ((org-enforce-todo-dependencies t
)
1623 '(org-block-todo-from-children-or-siblings-or-parent)))
1624 (org-entry-blocked-p))))
1625 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1628 (org-test-with-temp-text "* Blocked\n** TODO one"
1629 (let ((org-enforce-todo-dependencies t
)
1631 '(org-block-todo-from-children-or-siblings-or-parent)))
1632 (org-entry-blocked-p))))
1634 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1635 (let ((org-enforce-todo-dependencies t
)
1637 '(org-block-todo-from-children-or-siblings-or-parent)))
1638 (org-entry-blocked-p))))
1639 ;; Follow :ORDERED: specifications.
1641 (org-test-with-temp-text
1642 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1643 (let ((org-enforce-todo-dependencies t
)
1645 '(org-block-todo-from-children-or-siblings-or-parent)))
1646 (org-entry-blocked-p))))
1648 (org-test-with-temp-text
1649 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1650 (let ((org-enforce-todo-dependencies t
)
1652 '(org-block-todo-from-children-or-siblings-or-parent)))
1653 (org-entry-blocked-p)))))
1655 (ert-deftest test-org
/get-outline-path
()
1656 "Test `org-get-outline-path' specifications."
1657 ;; Top-level headlines have no outline path.
1659 (org-test-with-temp-text "* H"
1660 (org-get-outline-path)))
1661 ;; Otherwise, outline path is the path leading to the headline.
1664 (org-test-with-temp-text "* H\n** S<point>"
1665 (org-get-outline-path))))
1666 ;; Find path even when point is not on a headline.
1669 (org-test-with-temp-text "* H\n** S\nText<point>"
1670 (org-get-outline-path))))
1671 ;; TODO keywords, tags and statistics cookies are ignored.
1674 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1675 (org-get-outline-path))))
1676 ;; Links are replaced with their description or their path.
1679 (org-test-with-temp-text
1680 "* [[http://orgmode.org][Org]]\n** S<point>"
1681 (org-get-outline-path))))
1683 (equal '("http://orgmode.org")
1684 (org-test-with-temp-text
1685 "* [[http://orgmode.org]]\n** S<point>"
1686 (org-get-outline-path))))
1687 ;; When WITH-SELF is non-nil, include current heading.
1690 (org-test-with-temp-text "* H"
1691 (org-get-outline-path t
))))
1694 (org-test-with-temp-text "* H\n** S\nText<point>"
1695 (org-get-outline-path t
))))
1696 ;; Using cache is transparent to the user.
1699 (org-test-with-temp-text "* H\n** S<point>"
1700 (setq org-outline-path-cache nil
)
1701 (org-get-outline-path nil t
))))
1702 ;; Do not corrupt cache when finding outline path in distant part of
1706 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1707 (setq org-outline-path-cache nil
)
1708 (org-get-outline-path nil t
)
1709 (search-forward "S2")
1710 (org-get-outline-path nil t
))))
1711 ;; Do not choke on empty headlines.
1713 (org-test-with-temp-text "* H\n** <point>"
1714 (org-get-outline-path)))
1716 (org-test-with-temp-text "* \n** H<point>"
1717 (org-get-outline-path))))
1719 (ert-deftest test-org
/format-outline-path
()
1720 "Test `org-format-outline-path' specifications."
1722 (string= (org-format-outline-path (list "one" "two" "three"))
1726 (string= (org-format-outline-path '())
1729 (string= (org-format-outline-path '(nil))
1731 ;; Empty path and prefix.
1733 (string= (org-format-outline-path '() nil
">>")
1735 ;; Trailing whitespace in headings.
1737 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1739 ;; Non-default prefix and separators.
1741 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1742 ">>|one|two|three"))
1745 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1747 ;; Give a very narrow width.
1749 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1751 ;; Give a prefix that extends beyond the width.
1753 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1757 (ert-deftest test-org
/map-entries
()
1758 "Test `org-map-entries' specifications."
1762 (org-test-with-temp-text "* Level 1\n** Level 2"
1763 (org-map-entries #'point
))))
1767 (org-test-with-temp-text "* Level 1\n** Level 2"
1768 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1771 (org-test-with-temp-text "* Level 1\n** Level 2"
1772 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1776 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1777 (org-map-entries #'point
"yes"))))
1780 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1781 (org-map-entries #'point
"+yes-a"))))
1784 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1785 (org-map-entries #'point
"{yes?}"))))
1789 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1790 (org-map-entries #'point
"PRIORITY=\"A\""))))
1794 (org-test-with-temp-text "
1796 SCHEDULED: <2012-03-29 thu.>
1798 SCHEDULED: <2014-03-04 tue.>"
1799 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1802 (org-test-with-temp-text "
1804 SCHEDULED: <2012-03-29 thu.>
1806 SCHEDULED: <2014-03-04 tue.>"
1807 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1808 ;; Regular property match.
1811 (org-test-with-temp-text "
1820 (org-map-entries #'point
"TEST=1"))))
1821 ;; Multiple criteria.
1824 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1825 (let (org-odd-levels-only
1826 (org-use-tag-inheritance nil
))
1827 (org-map-entries #'point
"yes+LEVEL=1")))))
1831 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1832 (let (org-odd-levels-only)
1833 (org-map-entries #'point
"LEVEL=2|no")))))
1836 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1837 (let (org-odd-levels-only)
1838 (org-map-entries #'point
"yes|no")))))
1842 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1843 (let (org-odd-levels-only)
1844 (org-map-entries #'point
"yes&no"))))))
1846 (ert-deftest test-org
/edit-headline
()
1847 "Test `org-edit-headline' specifications."
1850 (org-test-with-temp-text "* A"
1851 (org-edit-headline "B")
1853 ;; Handle empty headings.
1856 (org-test-with-temp-text "* A"
1857 (org-edit-headline "")
1861 (org-test-with-temp-text "* "
1862 (org-edit-headline "A")
1864 ;; Handle TODO keywords and priority cookies.
1867 (org-test-with-temp-text "* TODO A"
1868 (org-edit-headline "B")
1872 (org-test-with-temp-text "* [#A] A"
1873 (org-edit-headline "B")
1876 (equal "* TODO [#A] B"
1877 (org-test-with-temp-text "* TODO [#A] A"
1878 (org-edit-headline "B")
1882 (org-test-with-temp-text "* A :tag:"
1883 (let ((org-tags-column 4)) (org-edit-headline "B"))
1890 (ert-deftest test-org
/set-regexps-and-options
()
1891 "Test `org-set-regexps-and-options' specifications."
1895 (let ((org-tag-alist '(("A")))
1896 (org-tag-persistent-alist nil
))
1897 (org-test-with-temp-text ""
1899 org-current-tag-alist
))))
1902 (let ((org-tag-alist '(("A")))
1903 (org-tag-persistent-alist nil
))
1904 (org-test-with-temp-text "#+TAGS: B"
1906 org-current-tag-alist
))))
1908 (equal '(("C") ("B"))
1909 (let ((org-tag-alist '(("A")))
1910 (org-tag-persistent-alist '(("C"))))
1911 (org-test-with-temp-text "#+TAGS: B"
1913 org-current-tag-alist
))))
1916 (let ((org-tag-alist '(("A")))
1917 (org-tag-persistent-alist '(("C"))))
1918 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1920 org-current-tag-alist
))))
1922 (equal '(("A" . ?a
) ("B") ("C"))
1923 (let ((org-tag-persistant-alist nil
))
1924 (org-test-with-temp-text "#+TAGS: A(a) B C"
1926 org-current-tag-alist
))))
1928 (equal '(("A") (:newline
) ("B"))
1929 (let ((org-tag-persistent-alist nil
))
1930 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1932 org-current-tag-alist
))))
1934 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1935 (let ((org-tag-persistent-alist nil
))
1936 (org-test-with-temp-text "#+TAGS: { A B } C"
1938 org-current-tag-alist
))))
1940 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1941 (let ((org-tag-persistent-alist nil
))
1942 (org-test-with-temp-text "#+TAGS: { A : B C }"
1944 org-current-tag-alist
))))
1946 (equal '(("A" "B" "C"))
1947 (let ((org-tag-persistent-alist nil
))
1948 (org-test-with-temp-text "#+TAGS: { A : B C }"
1950 org-tag-groups-alist
))))
1952 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1953 (let ((org-tag-persistent-alist nil
))
1954 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1956 org-current-tag-alist
))))
1958 (equal '(("A" "B" "C"))
1959 (let ((org-tag-persistent-alist nil
))
1960 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1962 org-tag-groups-alist
))))
1963 ;; FILETAGS keyword.
1965 (equal '("A" "B" "C")
1966 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1969 ;; PROPERTY keyword. Property names are case-insensitive.
1972 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1974 (cdr (assoc "var" org-file-properties
)))))
1978 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1980 (cdr (assoc "var" org-file-properties
)))))
1984 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1986 (cdr (assoc "var" org-file-properties
)))))
1990 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1992 org-archive-location
)))
1993 ;; CATEGORY keyword.
1996 (org-test-with-temp-text "#+CATEGORY: test"
2001 (org-test-with-temp-text "#+CATEGORY: test"
2003 (cdr (assoc "CATEGORY" org-file-properties
)))))
2006 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2007 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2009 org-columns-default-format
)))
2010 ;; CONSTANTS keyword. Constants names are case sensitive.
2012 (equal '("299792458." "3.14")
2013 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2016 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2020 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2022 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2025 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2027 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2032 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2034 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2036 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2040 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2042 (list org-highest-priority org-lowest-priority org-default-priority
))))
2046 (org-test-with-temp-text "#+PRIORITIES: X Z"
2048 (list org-highest-priority org-lowest-priority org-default-priority
))))
2052 (org-test-with-temp-text "#+STARTUP: fold odd"
2054 (list org-startup-folded org-odd-levels-only
))))
2057 (equal '(("A" "B") ("C"))
2058 (org-test-with-temp-text "#+TODO: A B | C"
2060 (list org-not-done-keywords org-done-keywords
))))
2062 (equal '(("A" "C") ("B" "D"))
2063 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2065 (list org-not-done-keywords org-done-keywords
))))
2067 (equal '(("A" "B") ("C"))
2068 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2070 (list org-not-done-keywords org-done-keywords
))))
2072 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2073 (org-test-with-temp-text "#+TODO: A(a)"
2075 org-todo-key-alist
)))
2077 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2078 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2080 org-todo-log-states
)))
2081 ;; Enter SETUPFILE keyword.
2084 (org-test-with-temp-text
2085 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2087 (cdr (assoc "a" org-file-properties
))))))
2095 (ert-deftest test-org
/coderef
()
2096 "Test coderef links specifications."
2098 (org-test-with-temp-text "
2099 #+BEGIN_SRC emacs-lisp
2104 (looking-at "(ref:sc)")))
2105 ;; Find coderef even with alternate label format.
2107 (org-test-with-temp-text "
2108 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2113 (looking-at "{ref:sc}"))))
2117 (ert-deftest test-org
/custom-id
()
2118 "Test custom ID links specifications."
2120 (org-test-with-temp-text
2121 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2123 (looking-at-p "\\* H1")))
2124 ;; Throw an error on false positives.
2126 (org-test-with-temp-text
2127 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2129 (looking-at-p "\\* H1"))))
2133 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2134 ;; a named element (#+name: text) and to headlines (* Text).
2136 (ert-deftest test-org
/fuzzy-links
()
2137 "Test fuzzy links specifications."
2138 ;; Fuzzy link goes in priority to a matching target.
2140 (org-test-with-temp-text
2141 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2142 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2143 (looking-at "<<Test>>")))
2144 ;; Then fuzzy link points to an element with a given name.
2146 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2147 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2148 (looking-at "#\\+NAME: Test")))
2149 ;; A target still lead to a matching headline otherwise.
2151 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2152 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2153 (looking-at "\\* Head2")))
2154 ;; With a leading star in link, enforce heading match.
2156 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2157 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2158 (looking-at "\\* Test")))
2159 ;; With a leading star in link, enforce exact heading match, even
2160 ;; with `org-link-search-must-match-exact-headline' set to nil.
2162 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2163 (let ((org-link-search-must-match-exact-headline nil
))
2164 (org-open-at-point))))
2165 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2167 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2168 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2169 (looking-at "\\* Test")))
2171 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2172 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2173 (looking-at "\\* Test")))
2174 ;; Heading match should not care about spaces, cookies, TODO
2175 ;; keywords, priorities, and tags. However, TODO keywords are
2179 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2180 (org-test-with-temp-text
2181 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2182 (let ((org-link-search-must-match-exact-headline nil
)
2183 (org-todo-regexp "TODO"))
2184 (org-open-at-point))
2185 (looking-at (regexp-quote first-line
)))))
2187 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2188 (let ((org-link-search-must-match-exact-headline nil
)
2189 (org-todo-regexp "TODO"))
2190 (org-open-at-point))))
2191 ;; Heading match should still be exact.
2193 (org-test-with-temp-text "
2194 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2197 (let ((org-link-search-must-match-exact-headline nil
)
2198 (org-todo-regexp "TODO"))
2199 (org-open-at-point))))
2201 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2202 (let ((org-link-search-must-match-exact-headline nil
)
2203 (org-todo-regexp "TODO"))
2204 (org-open-at-point))
2205 (looking-at-p (regexp-quote "** Test 1 2"))))
2206 ;; Heading match ignores COMMENT keyword.
2208 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2210 (looking-at "\\* COMMENT Test")))
2212 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2214 (looking-at "\\* TODO COMMENT Test")))
2215 ;; Correctly un-hexify fuzzy links.
2217 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2221 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2224 ;; Match search strings containing newline characters, including
2227 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2228 (let ((file (buffer-file-name)))
2229 (goto-char (point-max))
2230 (insert (format "[[file:%s::line1 line2]]" file
))
2232 (let ((org-link-search-must-match-exact-headline nil
))
2233 (org-open-at-point 0))
2234 (looking-at-p "line1"))))
2236 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2237 (let ((file (buffer-file-name)))
2238 (goto-char (point-max))
2239 (insert (format "[[file:%s::line1 line2]]" file
))
2241 (let ((org-link-search-must-match-exact-headline nil
))
2242 (org-open-at-point 0))
2243 (looking-at-p "line1")))))
2247 (ert-deftest test-org
/org-link-escape-ascii-character
()
2248 "Escape an ascii character."
2252 (org-link-escape "["))))
2254 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2255 "Escape an ascii control character."
2259 (org-link-escape "\t"))))
2261 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2262 "Escape an unicode multibyte character."
2266 (org-link-escape "€"))))
2268 (ert-deftest test-org
/org-link-escape-custom-table
()
2269 "Escape string with custom character table."
2273 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2275 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2276 "Escape string with custom table merged with default table."
2279 "%5BF%6F%6F%3A%42ar%0A%5D"
2280 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2282 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2283 "Unescape an ascii character."
2287 (org-link-unescape "%5B"))))
2289 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2290 "Unescpae an ascii control character."
2294 (org-link-unescape "%0A"))))
2296 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2297 "Unescape unicode multibyte character."
2301 (org-link-unescape "%E2%82%AC"))))
2303 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2304 "Unescape old style percent escaped character."
2307 "à âçèéêîôùû"
2308 (decode-coding-string
2309 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2311 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2312 "Escape and unescape a URL that includes an escaped char.
2313 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2316 "http://some.host.com/form?&id=blah%2Bblah25"
2318 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2322 (ert-deftest test-org
/open-at-point-in-keyword
()
2323 "Does `org-open-at-point' open link in a keyword line?"
2325 (org-test-with-temp-text
2326 "<<top>>\n#+KEYWORD: <point>[[top]]"
2327 (org-open-at-point) t
)))
2329 (ert-deftest test-org
/open-at-point-in-property
()
2330 "Does `org-open-at-point' open link in property drawer?"
2332 (org-test-with-temp-text
2335 :URL: <point>[[*Headline]]
2337 (org-open-at-point) t
)))
2339 (ert-deftest test-org
/open-at-point-in-comment
()
2340 "Does `org-open-at-point' open link in a commented line?"
2342 (org-test-with-temp-text
2343 "<<top>>\n# <point>[[top]]"
2344 (org-open-at-point) t
)))
2346 (ert-deftest test-org
/open-at-point
/inline-image
()
2347 "Test `org-open-at-point' on nested links."
2349 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2353 (ert-deftest test-org
/open-at-point
/radio-target
()
2354 "Test `org-open-at-point' on radio targets."
2356 (org-test-with-temp-text "<<<target>>> <point>target"
2357 (org-update-radio-target-regexp)
2359 (eq (org-element-type (org-element-context)) 'radio-target
))))
2363 (ert-deftest test-org
/store-link
()
2364 "Test `org-store-link' specifications."
2365 ;; On a headline, link to that headline. Use heading as the
2366 ;; description of the link.
2368 (let (org-store-link-props org-stored-links
)
2369 (org-test-with-temp-text-in-file "* H1"
2370 (let ((file (buffer-file-name)))
2371 (equal (format "[[file:%s::*H1][H1]]" file
)
2372 (org-store-link nil
))))))
2373 ;; On a headline, remove any link from description.
2375 (let (org-store-link-props org-stored-links
)
2376 (org-test-with-temp-text-in-file "* [[#l][d]]"
2377 (let ((file (buffer-file-name)))
2378 (equal (format "[[file:%s::*%s][d]]"
2380 (org-link-escape "[[#l][d]]"))
2381 (org-store-link nil
))))))
2383 (let (org-store-link-props org-stored-links
)
2384 (org-test-with-temp-text-in-file "* [[l]]"
2385 (let ((file (buffer-file-name)))
2386 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2387 (org-store-link nil
))))))
2389 (let (org-store-link-props org-stored-links
)
2390 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2391 (let ((file (buffer-file-name)))
2392 (equal (format "[[file:%s::*%s][d1 d2]]"
2394 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2395 (org-store-link nil
))))))
2396 ;; On a named element, link to that element.
2398 (let (org-store-link-props org-stored-links
)
2399 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2400 (let ((file (buffer-file-name)))
2401 (equal (format "[[file:%s::foo][foo]]" file
)
2402 (org-store-link nil
)))))))
2407 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2408 "Ensure properties accumulate in subtree drawers."
2409 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2410 (org-babel-next-src-block)
2411 (should (equal '(2 1) (org-babel-execute-src-block)))))
2413 (ert-deftest test-org
/custom-properties
()
2414 "Test custom properties specifications."
2417 (let ((org-custom-properties '("FOO")))
2418 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2419 (org-toggle-custom-properties-visibility)
2420 (org-invisible-p2))))
2421 ;; Properties are case-insensitive.
2423 (let ((org-custom-properties '("FOO")))
2424 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2425 (org-toggle-custom-properties-visibility)
2426 (org-invisible-p2))))
2428 (let ((org-custom-properties '("foo")))
2429 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2430 (org-toggle-custom-properties-visibility)
2431 (org-invisible-p2))))
2432 ;; Multiple custom properties in the same drawer.
2434 (let ((org-custom-properties '("FOO" "BAR")))
2435 (org-test-with-temp-text
2436 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2437 (org-toggle-custom-properties-visibility)
2438 (and (org-invisible-p2)
2439 (not (progn (forward-line) (org-invisible-p2)))
2440 (progn (forward-line) (org-invisible-p2))))))
2441 ;; Hide custom properties with an empty value.
2443 (let ((org-custom-properties '("FOO")))
2444 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2445 (org-toggle-custom-properties-visibility)
2446 (org-invisible-p2))))
2447 ;; Do not hide fake properties.
2449 (let ((org-custom-properties '("FOO")))
2450 (org-test-with-temp-text ":FOO: val\n"
2451 (org-toggle-custom-properties-visibility)
2452 (org-invisible-p2))))
2454 (let ((org-custom-properties '("A")))
2455 (org-test-with-temp-text
2456 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2457 (org-toggle-custom-properties-visibility)
2458 (org-invisible-p2)))))
2464 (ert-deftest test-org
/mark-subtree
()
2465 "Test `org-mark-subtree' specifications."
2466 ;; Error when point is before first headline.
2468 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2469 (progn (transient-mark-mode 1)
2470 (org-mark-subtree))))
2471 ;; Without argument, mark current subtree.
2475 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2476 (progn (transient-mark-mode 1)
2479 (list (region-beginning) (region-end))))))
2480 ;; With an argument, move ARG up.
2484 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2485 (progn (transient-mark-mode 1)
2487 (org-mark-subtree 1)
2488 (list (region-beginning) (region-end))))))
2489 ;; Do not get fooled by inlinetasks.
2490 (when (featurep 'org-inlinetask
)
2493 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2494 (progn (transient-mark-mode 1)
2496 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2497 (region-beginning)))))))
2503 (ert-deftest test-org
/in-regexp
()
2504 "Test `org-in-regexp' specifications."
2507 (org-test-with-temp-text "xx ab<point>c xx"
2508 (org-in-regexp "abc")))
2510 (org-test-with-temp-text "xx abc <point>xx"
2511 (org-in-regexp "abc")))
2512 ;; Return non-nil even with multiple matching regexps in the same
2515 (org-test-with-temp-text "abc xx ab<point>c xx"
2516 (org-in-regexp "abc")))
2517 ;; With optional argument NLINES, check extra lines around point.
2519 (org-test-with-temp-text "A\nB<point>\nC"
2520 (org-in-regexp "A\nB\nC")))
2522 (org-test-with-temp-text "A\nB<point>\nC"
2523 (org-in-regexp "A\nB\nC" 1)))
2525 (org-test-with-temp-text "A\nB\nC<point>"
2526 (org-in-regexp "A\nB\nC" 1)))
2527 ;; When optional argument VISUALLY is non-nil, return nil if at
2528 ;; regexp boundaries.
2530 (org-test-with-temp-text "xx abc<point> xx"
2531 (org-in-regexp "abc")))
2533 (org-test-with-temp-text "xx abc<point> xx"
2534 (org-in-regexp "abc" nil t
))))
2536 (ert-deftest test-org
/sort-entries
()
2537 "Test `org-sort-entries'."
2538 ;; Sort alphabetically.
2540 (equal "\n* abc\n* def\n* xyz\n"
2541 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2542 (org-sort-entries nil ?a
)
2545 (equal "\n* xyz\n* def\n* abc\n"
2546 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2547 (org-sort-entries nil ?A
)
2549 ;; Sort numerically.
2551 (equal "\n* 1\n* 2\n* 10\n"
2552 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2553 (org-sort-entries nil ?n
)
2556 (equal "\n* 10\n* 2\n* 1\n"
2557 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2558 (org-sort-entries nil ?N
)
2560 ;; Sort by custom function.
2562 (equal "\n* b\n* aa\n* ccc\n"
2563 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2564 (org-sort-entries nil ?f
2566 (length (buffer-substring (point-at-bol)
2571 (equal "\n* ccc\n* aa\n* b\n"
2572 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2573 (org-sort-entries nil ?F
2575 (length (buffer-substring (point-at-bol)
2579 ;; Sort by TODO keyword.
2581 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2582 (org-test-with-temp-text
2583 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2584 (org-sort-entries nil ?o
)
2587 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2588 (org-test-with-temp-text
2589 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2590 (org-sort-entries nil ?O
)
2592 ;; Sort by priority.
2594 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2595 (org-test-with-temp-text
2596 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2597 (org-sort-entries nil ?p
)
2600 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2601 (org-test-with-temp-text
2602 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2603 (org-sort-entries nil ?P
)
2605 ;; Sort by creation time.
2615 (org-test-with-temp-text
2624 (org-sort-entries nil ?c
)
2627 ;; Sort by scheduled date.
2631 SCHEDULED: <2017-05-06 Sat>
2633 SCHEDULED: <2017-05-08 Mon>
2635 DEADLINE: <2017-05-09 Tue>
2637 DEADLINE: <2017-05-07 Sun>
2639 (org-test-with-temp-text
2642 DEADLINE: <2017-05-09 Tue>
2644 DEADLINE: <2017-05-07 Sun>
2646 SCHEDULED: <2017-05-08 Mon>
2648 SCHEDULED: <2017-05-06 Sat>
2650 (org-sort-entries nil ?s
)
2652 ;; Sort by deadline date.
2656 DEADLINE: <2017-05-07 Sun>
2658 DEADLINE: <2017-05-09 Tue>
2660 SCHEDULED: <2017-05-08 Mon>
2662 SCHEDULED: <2017-05-06 Sat>
2664 (org-test-with-temp-text
2667 DEADLINE: <2017-05-09 Tue>
2669 DEADLINE: <2017-05-07 Sun>
2671 SCHEDULED: <2017-05-08 Mon>
2673 SCHEDULED: <2017-05-06 Sat>
2675 (org-sort-entries nil ?d
)
2677 ;; Sort by any date/time
2681 SCHEDULED: <2017-05-06 Sat>
2683 DEADLINE: <2017-05-07 Sun>
2685 SCHEDULED: <2017-05-08 Mon>
2687 DEADLINE: <2017-05-09 Tue>
2689 (org-test-with-temp-text
2692 DEADLINE: <2017-05-09 Tue>
2694 DEADLINE: <2017-05-07 Sun>
2696 SCHEDULED: <2017-05-08 Mon>
2698 SCHEDULED: <2017-05-06 Sat>
2700 (org-sort-entries nil ?t
)
2702 ;; Sort by clocking time.
2707 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2708 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2712 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2713 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2716 (org-test-with-temp-text
2720 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2721 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2725 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2726 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2729 (org-sort-entries nil ?k
)
2735 (ert-deftest test-org
/forward-heading-same-level
()
2736 "Test `org-forward-heading-same-level' specifications."
2737 ;; Test navigation at top level, forward and backward.
2740 (org-test-with-temp-text "* H1\n* H2"
2741 (org-forward-heading-same-level 1)
2742 (buffer-substring-no-properties (point) (line-end-position)))))
2745 (org-test-with-temp-text "* H1\n<point>* H2"
2746 (org-forward-heading-same-level -
1)
2747 (buffer-substring-no-properties (point) (line-end-position)))))
2748 ;; Test navigation in a sub-tree, forward and backward.
2751 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2752 (org-forward-heading-same-level 1)
2753 (buffer-substring-no-properties (point) (line-end-position)))))
2756 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
2757 (org-forward-heading-same-level -
1)
2758 (buffer-substring-no-properties (point) (line-end-position)))))
2759 ;; Stop at first or last sub-heading.
2762 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
2763 (org-forward-heading-same-level 1)
2764 (buffer-substring-no-properties (point) (line-end-position)))))
2767 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
2768 (org-forward-heading-same-level -
1)
2769 (buffer-substring-no-properties (point) (line-end-position)))))
2770 ;; Allow multiple moves.
2773 (org-test-with-temp-text "* H1\n* H2\n* H3"
2774 (org-forward-heading-same-level 2)
2775 (buffer-substring-no-properties (point) (line-end-position)))))
2778 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
2779 (org-forward-heading-same-level -
2)
2780 (buffer-substring-no-properties (point) (line-end-position)))))
2781 ;; Ignore spurious moves when first (or last) sibling is reached.
2784 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
2785 (org-forward-heading-same-level 100)
2786 (buffer-substring-no-properties (point) (line-end-position)))))
2789 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
2790 (org-forward-heading-same-level -
100)
2791 (buffer-substring-no-properties (point) (line-end-position))))))
2793 (ert-deftest test-org
/end-of-meta-data
()
2794 "Test `org-end-of-meta-data' specifications."
2795 ;; Skip planning line.
2797 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2798 (org-end-of-meta-data)
2800 ;; Skip properties drawer.
2802 (org-test-with-temp-text
2803 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2804 (org-end-of-meta-data)
2808 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2809 (org-end-of-meta-data)
2811 ;; Nothing to skip, go to first line.
2813 (org-test-with-temp-text "* Headline\nContents"
2814 (org-end-of-meta-data)
2815 (looking-at "Contents")))
2816 ;; With option argument, skip empty lines, regular drawers and
2819 (org-test-with-temp-text "* Headline\n\nContents"
2820 (org-end-of-meta-data t
)
2821 (looking-at "Contents")))
2823 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2824 (org-end-of-meta-data t
)
2825 (looking-at "Contents")))
2827 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2828 (org-end-of-meta-data t
)
2829 (looking-at "Contents")))
2830 ;; Special case: do not skip incomplete drawers.
2832 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2833 (org-end-of-meta-data t
)
2834 (looking-at ":LOGBOOK:")))
2835 ;; Special case: Be careful about consecutive headlines.
2837 (org-test-with-temp-text "* H1\n*H2\nContents"
2838 (org-end-of-meta-data t
)
2839 (looking-at "Contents"))))
2841 (ert-deftest test-org
/beginning-of-line
()
2842 "Test `org-beginning-of-line' specifications."
2843 ;; Move to beginning of line. If current line in invisible, move to
2844 ;; beginning of visible line instead.
2846 (org-test-with-temp-text "Some text\nSome other text<point>"
2847 (org-beginning-of-line)
2850 (org-test-with-temp-text "* H1\n** H2<point>"
2852 (org-beginning-of-line)
2853 (= (line-beginning-position) 1)))
2854 ;; With `visual-line-mode' active, move to beginning of visual line.
2856 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2858 (dotimes (i 1000) (insert "very "))
2859 (org-beginning-of-line)
2861 ;; In a wide headline, with `visual-line-mode', prefer going to the
2862 ;; beginning of a visual line than to the logical beginning of line,
2863 ;; even if special movement is active.
2865 (org-test-with-temp-text "* A <point>long headline"
2867 (dotimes (i 1000) (insert "very "))
2868 (goto-char (point-max))
2869 (org-beginning-of-line)
2872 (org-test-with-temp-text "* A <point>long headline"
2874 (dotimes (i 1000) (insert "very "))
2875 (goto-char (point-max))
2876 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2878 ;; At an headline with special movement, first move at beginning of
2879 ;; title, then at the beginning of line, rinse, repeat.
2881 (org-test-with-temp-text "* TODO Headline<point>"
2882 (let ((org-special-ctrl-a/e t
))
2883 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2884 (progn (org-beginning-of-line) (bolp))
2885 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2887 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2888 (let ((org-special-ctrl-a/e t
))
2889 (org-beginning-of-line)
2890 (looking-at "Headline"))))
2892 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2893 (let ((org-special-ctrl-a/e
'(t . nil
)))
2894 (org-beginning-of-line)
2895 (looking-at "Headline"))))
2897 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2898 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2899 (org-beginning-of-line)
2900 (looking-at "Headline"))))
2901 ;; At an headline with reversed movement, first move to beginning of
2902 ;; line, then to the beginning of title.
2904 (org-test-with-temp-text "* TODO Headline<point>"
2905 (let ((org-special-ctrl-a/e
'reversed
)
2906 (this-command last-command
))
2907 (and (progn (org-beginning-of-line) (bolp))
2908 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2910 (org-test-with-temp-text "* TODO Headline<point>"
2911 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2912 (this-command last-command
))
2913 (and (progn (org-beginning-of-line) (bolp))
2914 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2916 (org-test-with-temp-text "* TODO Headline<point>"
2917 (let ((org-special-ctrl-a/e
'(t . nil
))
2918 (this-command last-command
))
2919 (and (progn (org-beginning-of-line) (bolp))
2920 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2921 ;; At an item with special movement, first move after to beginning
2922 ;; of title, then to the beginning of line, rinse, repeat.
2924 (org-test-with-temp-text "- [ ] Item<point>"
2925 (let ((org-special-ctrl-a/e t
))
2926 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2927 (progn (org-beginning-of-line) (bolp))
2928 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2929 ;; At an item with reversed movement, first move to beginning of
2930 ;; line, then to the beginning of title.
2932 (org-test-with-temp-text "- [X] Item<point>"
2933 (let ((org-special-ctrl-a/e
'reversed
)
2934 (this-command last-command
))
2935 (and (progn (org-beginning-of-line) (bolp))
2936 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2937 ;; Leave point before invisible characters at column 0.
2939 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2940 (let ((org-special-ctrl-a/e nil
))
2941 (org-beginning-of-line)
2944 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2945 (let ((org-special-ctrl-a/e t
))
2946 (org-beginning-of-line)
2949 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2951 (org-beginning-of-line)
2953 ;; Special case: Do not error when the buffer contains only a single
2956 (org-test-with-temp-text "*<point>"
2957 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2959 (org-test-with-temp-text "*<point>"
2960 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2962 (ert-deftest test-org
/end-of-line
()
2963 "Test `org-end-of-line' specifications."
2966 (org-test-with-temp-text "Some text\nSome other text"
2969 ;; With `visual-line-mode' active, move to end of visible line.
2970 ;; However, never go past ellipsis.
2972 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2974 (dotimes (i 1000) (insert "very "))
2975 (goto-char (point-min))
2979 (org-test-with-temp-text "* A short headline\nSome contents"
2984 ;; In a wide headline, with `visual-line-mode', prefer going to end
2985 ;; of visible line if tags, or end of line, are farther.
2987 (org-test-with-temp-text "* A <point>long headline"
2989 (dotimes (i 1000) (insert "very "))
2990 (goto-char (point-min))
2994 (org-test-with-temp-text "* A <point>long headline :tag:"
2996 (dotimes (i 1000) (insert "very "))
2997 (goto-char (point-min))
3000 ;; At an headline without special movement, go to end of line.
3001 ;; However, never go past ellipsis.
3003 (org-test-with-temp-text "* Headline2b :tag:\n"
3004 (let ((org-special-ctrl-a/e nil
))
3005 (and (progn (org-end-of-line) (eolp))
3006 (progn (org-end-of-line) (eolp))))))
3008 (org-test-with-temp-text "* Headline2b :tag:\n"
3009 (let ((org-special-ctrl-a/e
'(t . nil
)))
3010 (and (progn (org-end-of-line) (eolp))
3011 (progn (org-end-of-line) (eolp))))))
3013 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3015 (let ((org-special-ctrl-a/e nil
))
3017 (= 1 (line-beginning-position)))))
3018 ;; At an headline with special movement, first move before tags,
3019 ;; then at the end of line, rinse, repeat. However, never go past
3022 (org-test-with-temp-text "* Headline1 :tag:\n"
3023 (let ((org-special-ctrl-a/e t
))
3024 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3025 (progn (org-end-of-line) (eolp))
3026 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3028 (org-test-with-temp-text "* Headline1 :tag:\n"
3029 (let ((org-special-ctrl-a/e
'(nil . t
)))
3030 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3031 (progn (org-end-of-line) (eolp))
3032 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3034 (org-test-with-temp-text "* Headline1 :tag:\n"
3035 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3036 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3037 (progn (org-end-of-line) (eolp))
3038 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3040 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3042 (let ((org-special-ctrl-a/e t
))
3045 (= 1 (line-beginning-position)))))
3046 ;; At an headline, with reversed movement, first go to end of line,
3047 ;; then before tags. However, never go past ellipsis.
3049 (org-test-with-temp-text "* Headline3 :tag:\n"
3050 (let ((org-special-ctrl-a/e
'reversed
)
3051 (this-command last-command
))
3052 (and (progn (org-end-of-line) (eolp))
3053 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3055 (org-test-with-temp-text "* Headline3 :tag:\n"
3056 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3057 (this-command last-command
))
3058 (and (progn (org-end-of-line) (eolp))
3059 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3061 (org-test-with-temp-text "* Headline3 :tag:\n"
3062 (let ((org-special-ctrl-a/e
'(nil . t
))
3063 (this-command last-command
))
3064 (and (progn (org-end-of-line) (eolp))
3065 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3067 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3069 (let ((org-special-ctrl-a/e
'reversed
))
3071 (= 1 (line-beginning-position)))))
3072 ;; At a block without hidden contents.
3074 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3075 (progn (org-end-of-line) (eolp))))
3076 ;; At a block with hidden contents.
3078 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3079 (let ((org-special-ctrl-a/e t
))
3080 (org-hide-block-toggle)
3083 ;; Get past invisible characters at the end of line.
3085 (org-test-with-temp-text "[[http://orgmode.org]]"
3089 (ert-deftest test-org
/open-line
()
3090 "Test `org-open-line' specifications."
3091 ;; Call `open-line' outside of tables.
3094 (org-test-with-temp-text "Text"
3097 ;; At a table, create a row above.
3099 (equal "\n| |\n| a |"
3100 (org-test-with-temp-text "\n<point>| a |"
3103 ;; At the very first character of the buffer, also call `open-line'.
3106 (org-test-with-temp-text "| a |"
3109 ;; Narrowing does not count.
3111 (equal "Text\n| |\n| a |"
3112 (org-test-with-temp-text "Text\n<point>| a |"
3113 (narrow-to-region (point) (point-max))
3118 (ert-deftest test-org
/forward-sentence
()
3119 "Test `org-forward-sentence' specifications."
3120 ;; At the end of a table cell, move to the end of the next one.
3122 (org-test-with-temp-text "| a<point> | b |"
3123 (org-forward-sentence)
3124 (looking-at " |$")))
3125 ;; Elsewhere in a cell, move to its end.
3127 (org-test-with-temp-text "| a<point>c | b |"
3128 (org-forward-sentence)
3129 (looking-at " | b |$")))
3130 ;; Otherwise, simply call `forward-sentence'.
3132 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3133 (org-forward-sentence)
3134 (looking-at " Sentence 2.")))
3136 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3137 (org-forward-sentence)
3138 (org-forward-sentence)
3140 ;; At the end of an element, jump to the next one, without stopping
3141 ;; on blank lines in-between.
3143 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3144 (org-forward-sentence)
3147 (ert-deftest test-org
/backward-sentence
()
3148 "Test `org-backward-sentence' specifications."
3149 ;; At the beginning of a table cell, move to the beginning of the
3152 (org-test-with-temp-text "| a | <point>b |"
3153 (org-backward-sentence)
3154 (looking-at "a | b |$")))
3155 ;; Elsewhere in a cell, move to its beginning.
3157 (org-test-with-temp-text "| a | b<point>c |"
3158 (org-backward-sentence)
3159 (looking-at "bc |$")))
3160 ;; Otherwise, simply call `backward-sentence'.
3162 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3163 (org-backward-sentence)
3164 (looking-at "Sentence 2.")))
3166 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3167 (org-backward-sentence)
3168 (org-backward-sentence)
3170 ;; Make sure to hit the beginning of a sentence on the same line as
3173 (org-test-with-temp-text "- Line 1\n line <point>2."
3174 (org-backward-sentence)
3175 (looking-at "Line 1"))))
3177 (ert-deftest test-org
/forward-paragraph
()
3178 "Test `org-forward-paragraph' specifications."
3179 ;; At end of buffer, return an error.
3181 (org-test-with-temp-text "Paragraph"
3182 (goto-char (point-max))
3183 (org-forward-paragraph)))
3186 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3187 (org-forward-paragraph)
3191 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3192 (org-forward-paragraph)
3194 ;; Do not enter elements with invisible contents.
3196 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3197 (org-hide-block-toggle)
3198 (org-forward-paragraph)
3200 ;; On an affiliated keyword, jump to the beginning of the element.
3202 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3203 (org-forward-paragraph)
3204 (looking-at "Para")))
3205 ;; On an item or a footnote definition, move to the second element
3208 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3209 (org-forward-paragraph)
3210 (looking-at " Paragraph")))
3212 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3213 (org-forward-paragraph)
3214 (looking-at "Paragraph")))
3215 ;; On an item, or a footnote definition, when the first line is
3216 ;; empty, move to the first item.
3218 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3219 (org-forward-paragraph)
3220 (looking-at " Paragraph")))
3222 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3223 (org-forward-paragraph)
3224 (looking-at "Paragraph")))
3225 ;; On a table (resp. a property drawer) do not move through table
3226 ;; rows (resp. node properties).
3228 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3229 (org-forward-paragraph)
3230 (looking-at "Paragraph")))
3232 (org-test-with-temp-text
3233 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3234 (org-forward-paragraph)
3235 (looking-at "Paragraph")))
3236 ;; On a verse or source block, stop after blank lines.
3238 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3239 (org-forward-paragraph)
3242 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3243 (org-forward-paragraph)
3244 (looking-at "L2"))))
3246 (ert-deftest test-org
/backward-paragraph
()
3247 "Test `org-backward-paragraph' specifications."
3248 ;; Error at beginning of buffer.
3250 (org-test-with-temp-text "Paragraph"
3251 (org-backward-paragraph)))
3254 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3255 (goto-char (point-max))
3256 (org-backward-paragraph)
3259 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3260 (goto-char (point-max))
3262 (org-backward-paragraph)
3266 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3267 (goto-char (point-max))
3269 (org-backward-paragraph)
3271 ;; Ignore invisible elements.
3273 (org-test-with-temp-text "* H1\n P1\n* H2"
3275 (goto-char (point-max))
3277 (org-backward-paragraph)
3279 ;; On an affiliated keyword, jump to the first one.
3281 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3282 (search-forward "c2")
3283 (org-backward-paragraph)
3284 (looking-at "#\\+name")))
3285 ;; On the second element in an item or a footnote definition, jump
3286 ;; to item or the definition.
3288 (org-test-with-temp-text "- line1\n\n line2"
3289 (goto-char (point-max))
3291 (org-backward-paragraph)
3292 (looking-at "- line1")))
3294 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3295 (goto-char (point-max))
3297 (org-backward-paragraph)
3298 (looking-at "\\[fn:1\\] line1")))
3299 ;; On a table (resp. a property drawer), ignore table rows
3300 ;; (resp. node properties).
3302 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3303 (goto-char (point-max))
3305 (org-backward-paragraph)
3308 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3309 (org-backward-paragraph)
3310 (looking-at ":PROPERTIES:")))
3311 ;; On a source or verse block, stop before blank lines.
3313 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3314 (search-forward "L3")
3316 (org-backward-paragraph)
3319 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3320 (search-forward "L3")
3322 (org-backward-paragraph)
3323 (looking-at "L2"))))
3325 (ert-deftest test-org
/forward-element
()
3326 "Test `org-forward-element' specifications."
3327 ;; 1. At EOB: should error.
3328 (org-test-with-temp-text "Some text\n"
3329 (goto-char (point-max))
3330 (should-error (org-forward-element)))
3331 ;; 2. Standard move: expected to ignore blank lines.
3332 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3333 (org-forward-element)
3334 (should (looking-at (regexp-quote "Second paragraph."))))
3335 ;; 3. Headline tests.
3336 (org-test-with-temp-text "
3341 ;; 3.1. At an headline beginning: move to next headline at the
3344 (org-forward-element)
3345 (should (looking-at (regexp-quote "** Head 1.2")))
3346 ;; 3.2. At an headline beginning: move to parent headline if no
3347 ;; headline at the same level.
3349 (org-forward-element)
3350 (should (looking-at (regexp-quote "** Head 1.2"))))
3351 ;; 4. Greater element tests.
3352 (org-test-with-temp-text
3353 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3354 ;; 4.1. At a greater element: expected to skip contents.
3355 (org-forward-element)
3356 (should (looking-at (regexp-quote "Outside.")))
3357 ;; 4.2. At the end of greater element contents: expected to skip
3358 ;; to the end of the greater element.
3360 (org-forward-element)
3361 (should (looking-at (regexp-quote "Outside."))))
3363 (org-test-with-temp-text "
3377 ;; 5.1. At list top point: expected to move to the element after
3380 (org-forward-element)
3381 (should (looking-at (regexp-quote "Outside.")))
3382 ;; 5.2. Special case: at the first line of a sub-list, but not at
3383 ;; beginning of line, move to next item.
3386 (org-forward-element)
3387 (should (looking-at "- item2"))
3390 (org-forward-element)
3391 (should (looking-at " - sub2"))
3392 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3394 (org-forward-element)
3395 (should (looking-at (regexp-quote " Inner paragraph.")))
3396 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3398 (org-forward-element)
3399 (should (looking-at (regexp-quote " Inner paragraph.")))
3400 ;; 5.5. At an item: expected to move to next item, if any.
3402 (org-forward-element)
3403 (should (looking-at " - sub3"))))
3405 (ert-deftest test-org
/backward-element
()
3406 "Test `org-backward-element' specifications."
3407 ;; 1. Should error at BOB.
3408 (org-test-with-temp-text " \nParagraph."
3409 (should-error (org-backward-element)))
3410 ;; 2. Should move at BOB when called on the first element in buffer.
3412 (org-test-with-temp-text "\n#+TITLE: test"
3413 (progn (forward-line)
3414 (org-backward-element)
3416 ;; 3. Not at the beginning of an element: move at its beginning.
3417 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3420 (org-backward-element)
3421 (should (looking-at (regexp-quote "Paragraph2."))))
3422 ;; 4. Headline tests.
3423 (org-test-with-temp-text "
3428 ;; 4.1. At an headline beginning: move to previous headline at the
3431 (org-backward-element)
3432 (should (looking-at (regexp-quote "** Head 1.1")))
3433 ;; 4.2. At an headline beginning: move to parent headline if no
3434 ;; headline at the same level.
3436 (org-backward-element)
3437 (should (looking-at (regexp-quote "* Head 1")))
3438 ;; 4.3. At the first top-level headline: should error.
3440 (should-error (org-backward-element)))
3441 ;; 5. At beginning of first element inside a greater element:
3442 ;; expected to move to greater element's beginning.
3443 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3445 (org-backward-element)
3446 (should (looking-at "#\\+BEGIN_CENTER")))
3447 ;; 6. At the beginning of the first element in a section: should
3448 ;; move back to headline, if any.
3450 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3451 (progn (goto-char (point-max))
3453 (org-backward-element)
3454 (org-at-heading-p))))
3456 (org-test-with-temp-text "
3471 ;; 7.1. At beginning of sub-list: expected to move to the
3472 ;; paragraph before it.
3474 (org-backward-element)
3475 (should (looking-at "item1"))
3476 ;; 7.2. At an item in a list: expected to move at previous item.
3478 (org-backward-element)
3479 (should (looking-at " - sub2"))
3481 (org-backward-element)
3482 (should (looking-at "- item1"))
3483 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3486 (org-backward-element)
3487 (should (looking-at " - sub1"))
3489 (org-backward-element)
3490 (should (looking-at "- item1"))
3491 ;; 7.4. At blank-lines before list end: expected to move to top
3494 (org-backward-element)
3495 (should (looking-at "- item1"))))
3497 (ert-deftest test-org
/up-element
()
3498 "Test `org-up-element' specifications."
3499 ;; 1. At BOB or with no surrounding element: should error.
3500 (org-test-with-temp-text "Paragraph."
3501 (should-error (org-up-element)))
3502 (org-test-with-temp-text "* Head1\n* Head2"
3504 (should-error (org-up-element)))
3505 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3507 (should-error (org-up-element)))
3508 ;; 2. At an headline: move to parent headline.
3509 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3512 (should (looking-at "\\* Head1")))
3513 ;; 3. Inside a greater element: move to greater element beginning.
3514 (org-test-with-temp-text
3515 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3518 (should (looking-at "#\\+BEGIN_CENTER")))
3520 (org-test-with-temp-text "* Top
3527 Paragraph within sub2.
3530 ;; 4.1. Within an item: move to the item beginning.
3533 (should (looking-at " - sub2"))
3534 ;; 4.2. At an item in a sub-list: move to parent item.
3537 (should (looking-at "- item1"))
3538 ;; 4.3. At an item in top list: move to beginning of whole list.
3541 (should (looking-at "- item1"))
3542 ;; 4.4. Special case. At very top point: should move to parent of
3546 (should (looking-at "\\* Top"))))
3548 (ert-deftest test-org
/down-element
()
3549 "Test `org-down-element' specifications."
3550 ;; Error when the element hasn't got a recursive type.
3551 (org-test-with-temp-text "Paragraph."
3552 (should-error (org-down-element)))
3553 ;; Error when the element has no contents
3554 (org-test-with-temp-text "* Headline"
3555 (should-error (org-down-element)))
3556 ;; When at a plain-list, move to first item.
3557 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3560 (should (looking-at " - Item 1.1")))
3561 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3563 (should (looking-at " Item 1")))
3564 ;; When at a table, move to first row
3565 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3567 (should (looking-at " a | b |")))
3568 ;; Otherwise, move inside the greater element.
3569 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3571 (should (looking-at "Paragraph"))))
3573 (ert-deftest test-org
/drag-element-backward
()
3574 "Test `org-drag-element-backward' specifications."
3578 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3579 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3580 (org-drag-element-backward)
3584 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3585 (org-test-with-temp-text
3586 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3587 (org-drag-element-backward)
3589 ;; Preserve blank lines.
3591 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3592 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3593 (org-drag-element-backward)
3597 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3598 (org-drag-element-backward)
3599 (looking-at-p "2")))
3600 ;; Error when trying to move first element of buffer.
3602 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3603 (org-drag-element-backward))
3605 ;; Error when trying to swap nested elements.
3607 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3608 (org-drag-element-backward))
3610 ;; Error when trying to swap an headline element and a non-headline
3613 (org-test-with-temp-text "Test.\n<point>* Head 1"
3614 (org-drag-element-backward))
3616 ;; Error when called before first element.
3618 (org-test-with-temp-text "\n<point>"
3619 (org-drag-element-backward))
3621 ;; Preserve visibility of elements and their contents.
3623 (equal '((63 .
82) (26 .
48))
3624 (org-test-with-temp-text "
3632 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3633 (search-backward "- item 1")
3634 (org-drag-element-backward)
3635 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3636 (overlays-in (point-min) (point-max))))))
3637 ;; Pathological case: handle call with point in blank lines right
3638 ;; after a headline.
3640 (equal "* H2\n* H1\nText\n\n"
3641 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3642 (org-drag-element-backward)
3645 (ert-deftest test-org
/drag-element-forward
()
3646 "Test `org-drag-element-forward' specifications."
3647 ;; 1. Error when trying to move first element of buffer.
3648 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3650 (should-error (org-drag-element-forward)))
3651 ;; 2. Error when trying to swap nested elements.
3652 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3654 (should-error (org-drag-element-forward)))
3655 ;; 3. Error when trying to swap a non-headline element and an
3657 (org-test-with-temp-text "Test.\n* Head 1"
3658 (should-error (org-drag-element-forward)))
3659 ;; 4. Error when called before first element.
3661 (org-test-with-temp-text "\n"
3663 (org-drag-element-backward))
3665 ;; 5. Otherwise, swap elements, preserving column and blank lines
3666 ;; between elements.
3667 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3668 (search-forward "graph")
3669 (org-drag-element-forward)
3670 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3671 (should (looking-at " 1")))
3672 ;; 5. Preserve visibility of elements and their contents.
3673 (org-test-with-temp-text "
3681 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3682 (search-backward "#+BEGIN_CENTER")
3683 (org-drag-element-forward)
3686 '((63 .
82) (26 .
48))
3687 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3688 (overlays-in (point-min) (point-max)))))))
3690 (ert-deftest test-org
/next-block
()
3691 "Test `org-next-block' specifications."
3694 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3696 (looking-at "#\\+BEGIN_CENTER")))
3699 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3700 (let ((case-fold-search nil
))
3702 (looking-at "#\\+begin_center"))))
3703 ;; Ignore current line.
3705 (org-test-with-temp-text
3706 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3708 (looking-at "#\\+BEGIN_CENTER")))
3709 ;; Throw an error when no block is found.
3711 (org-test-with-temp-text "Paragraph"
3712 (org-next-block 1)))
3713 ;; With an argument, skip many blocks at once.
3715 (org-test-with-temp-text
3716 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3718 (looking-at "#\\+BEGIN_QUOTE")))
3719 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3721 (org-test-with-temp-text
3722 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3723 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3724 (looking-at "#\\+BEGIN_QUOTE")))
3725 ;; Optional argument is also case-insensitive.
3727 (org-test-with-temp-text
3728 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3729 (let ((case-fold-search nil
))
3730 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3731 (looking-at "#\\+begin_quote")))))
3733 (ert-deftest test-org
/previous-block
()
3734 "Test `org-previous-block' specifications."
3737 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3738 (org-previous-block 1)
3739 (looking-at "#\\+BEGIN_CENTER")))
3742 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3743 (let ((case-fold-search nil
))
3744 (org-previous-block 1)
3745 (looking-at "#\\+begin_center"))))
3746 ;; Ignore current line.
3748 (org-test-with-temp-text
3749 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3750 (org-previous-block 1)
3751 (looking-at "#\\+BEGIN_QUOTE")))
3752 ;; Throw an error when no block is found.
3754 (org-test-with-temp-text "Paragraph<point>"
3755 (org-previous-block 1)))
3756 ;; With an argument, skip many blocks at once.
3758 (org-test-with-temp-text
3759 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3760 (org-previous-block 2)
3761 (looking-at "#\\+BEGIN_CENTER")))
3762 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3764 (org-test-with-temp-text
3765 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3766 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3767 (looking-at "#\\+BEGIN_QUOTE")))
3768 ;; Optional argument is also case-insensitive.
3770 (org-test-with-temp-text
3771 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3772 (let ((case-fold-search nil
))
3773 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3774 (looking-at "#\\+begin_quote")))))
3777 ;;; Outline structure
3779 (ert-deftest test-org
/demote
()
3780 "Test `org-demote' specifications."
3781 ;; Add correct number of stars according to `org-odd-levels-only'.
3784 (org-test-with-temp-text "* H"
3785 (let ((org-odd-levels-only nil
)) (org-demote))
3786 (org-current-level))))
3789 (org-test-with-temp-text "* H"
3790 (let ((org-odd-levels-only t
)) (org-demote))
3791 (org-current-level))))
3792 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3794 (org-test-with-temp-text "* H :tag:"
3795 (let ((org-tags-column 10)
3796 (org-auto-align-tags t
)
3797 (org-odd-levels-only nil
))
3799 (org-move-to-column 10)
3800 (looking-at-p ":tag:$")))
3802 (org-test-with-temp-text "* H :tag:"
3803 (let ((org-tags-column 10)
3804 (org-auto-align-tags nil
)
3805 (org-odd-levels-only nil
))
3807 (org-move-to-column 10)
3808 (looking-at-p ":tag:$")))
3809 ;; When `org-adapt-indentation' is non-nil, always indent planning
3810 ;; info and property drawers accordingly.
3813 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3814 (let ((org-odd-levels-only nil
)
3815 (org-adapt-indentation t
))
3818 (org-get-indentation))))
3821 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3822 (let ((org-odd-levels-only nil
)
3823 (org-adapt-indentation t
))
3826 (org-get-indentation))))
3829 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3830 (let ((org-odd-levels-only nil
)
3831 (org-adapt-indentation nil
))
3834 (org-get-indentation))))
3835 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3836 ;; section accordingly. Ignore, however, footnote definitions and
3837 ;; inlinetasks boundaries.
3840 (org-test-with-temp-text "* H\n Paragraph"
3841 (let ((org-odd-levels-only nil
)
3842 (org-adapt-indentation t
))
3845 (org-get-indentation))))
3848 (org-test-with-temp-text "* H\n Paragraph"
3849 (let ((org-odd-levels-only nil
)
3850 (org-adapt-indentation nil
))
3853 (org-get-indentation))))
3856 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3857 (let ((org-odd-levels-only nil
)
3858 (org-adapt-indentation t
))
3860 (goto-char (point-max))
3861 (org-get-indentation))))
3864 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3865 (let ((org-odd-levels-only nil
)
3866 (org-adapt-indentation t
))
3868 (goto-char (point-max))
3869 (org-get-indentation))))
3870 (when (featurep 'org-inlinetask
)
3873 (let ((org-inlinetask-min-level 5)
3874 (org-adapt-indentation t
))
3875 (org-test-with-temp-text "* H\n***** I\n***** END"
3878 (org-get-indentation))))))
3879 (when (featurep 'org-inlinetask
)
3882 (let ((org-inlinetask-min-level 5)
3883 (org-adapt-indentation t
))
3884 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3887 (org-get-indentation))))))
3888 ;; Ignore contents of source blocks or example blocks when
3889 ;; indentation should be preserved (through
3890 ;; `org-src-preserve-indentation' or "-i" flag).
3893 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3894 (let ((org-adapt-indentation t
)
3895 (org-src-preserve-indentation nil
))
3898 (org-get-indentation))))
3901 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3902 (let ((org-adapt-indentation t
)
3903 (org-src-preserve-indentation t
))
3906 (org-get-indentation))))
3909 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3910 (let ((org-adapt-indentation t
)
3911 (org-src-preserve-indentation t
))
3914 (org-get-indentation))))
3917 (org-test-with-temp-text
3918 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3919 (let ((org-adapt-indentation t
)
3920 (org-src-preserve-indentation nil
))
3923 (org-get-indentation)))))
3925 (ert-deftest test-org
/promote
()
3926 "Test `org-promote' specifications."
3927 ;; Return an error if headline is to be promoted to level 0, unless
3928 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3929 ;; headline becomes a comment.
3931 (org-test-with-temp-text "* H"
3932 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3935 (org-test-with-temp-text "* H"
3936 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3938 ;; Remove correct number of stars according to
3939 ;; `org-odd-levels-only'.
3942 (org-test-with-temp-text "*** H"
3943 (let ((org-odd-levels-only nil
)) (org-promote))
3944 (org-current-level))))
3947 (org-test-with-temp-text "*** H"
3948 (let ((org-odd-levels-only t
)) (org-promote))
3949 (org-current-level))))
3950 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3952 (org-test-with-temp-text "** H :tag:"
3953 (let ((org-tags-column 10)
3954 (org-auto-align-tags t
)
3955 (org-odd-levels-only nil
))
3957 (org-move-to-column 10)
3958 (looking-at-p ":tag:$")))
3960 (org-test-with-temp-text "** H :tag:"
3961 (let ((org-tags-column 10)
3962 (org-auto-align-tags nil
)
3963 (org-odd-levels-only nil
))
3965 (org-move-to-column 10)
3966 (looking-at-p ":tag:$")))
3967 ;; When `org-adapt-indentation' is non-nil, always indent planning
3968 ;; info and property drawers.
3971 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3972 (let ((org-odd-levels-only nil
)
3973 (org-adapt-indentation t
))
3976 (org-get-indentation))))
3979 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3980 (let ((org-odd-levels-only nil
)
3981 (org-adapt-indentation t
))
3984 (org-get-indentation))))
3987 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3988 (let ((org-odd-levels-only nil
)
3989 (org-adapt-indentation nil
))
3992 (org-get-indentation))))
3993 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3994 ;; section accordingly. Ignore, however, footnote definitions and
3995 ;; inlinetasks boundaries.
3998 (org-test-with-temp-text "** H\n Paragraph"
3999 (let ((org-odd-levels-only nil
)
4000 (org-adapt-indentation t
))
4003 (org-get-indentation))))
4006 (org-test-with-temp-text "** H\n Paragraph"
4007 (let ((org-odd-levels-only nil
)
4008 (org-adapt-indentation nil
))
4011 (org-get-indentation))))
4014 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4015 (let ((org-odd-levels-only nil
)
4016 (org-adapt-indentation t
))
4019 (org-get-indentation))))
4020 (when (featurep 'org-inlinetask
)
4023 (let ((org-inlinetask-min-level 5)
4024 (org-adapt-indentation t
))
4025 (org-test-with-temp-text "** H\n***** I\n***** END"
4028 (org-get-indentation))))))
4029 (when (featurep 'org-inlinetask
)
4032 (let ((org-inlinetask-min-level 5)
4033 (org-adapt-indentation t
))
4034 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4037 (org-get-indentation))))))
4038 ;; Give up shifting if it would break document's structure
4042 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4043 (let ((org-odd-levels-only nil
)
4044 (org-adapt-indentation t
))
4047 (org-get-indentation))))
4050 (org-test-with-temp-text "** H\n Paragraph\n * list."
4051 (let ((org-odd-levels-only nil
)
4052 (org-adapt-indentation t
))
4055 (org-get-indentation))))
4056 ;; Ignore contents of source blocks or example blocks when
4057 ;; indentation should be preserved (through
4058 ;; `org-src-preserve-indentation' or "-i" flag).
4061 (org-test-with-temp-text
4062 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4063 (let ((org-adapt-indentation t
)
4064 (org-src-preserve-indentation nil
)
4065 (org-odd-levels-only nil
))
4068 (org-get-indentation))))
4071 (org-test-with-temp-text
4072 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4073 (let ((org-adapt-indentation t
)
4074 (org-src-preserve-indentation t
)
4075 (org-odd-levels-only nil
))
4078 (org-get-indentation))))
4081 (org-test-with-temp-text
4082 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4083 (let ((org-adapt-indentation t
)
4084 (org-src-preserve-indentation t
)
4085 (org-odd-levels-only nil
))
4088 (org-get-indentation))))
4091 (org-test-with-temp-text
4092 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4093 (let ((org-adapt-indentation t
)
4094 (org-src-preserve-indentation nil
)
4095 (org-odd-levels-only nil
))
4098 (org-get-indentation)))))
4103 (ert-deftest test-org
/at-planning-p
()
4104 "Test `org-at-planning-p' specifications."
4107 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4108 (org-at-planning-p)))
4110 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4111 (org-at-planning-p)))
4112 ;; Correctly find planning attached to inlinetasks.
4113 (when (featurep 'org-inlinetask
)
4115 (org-test-with-temp-text
4116 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4117 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4119 (org-test-with-temp-text
4120 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4121 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4123 (org-test-with-temp-text
4124 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4125 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4127 (org-test-with-temp-text
4128 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4129 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4131 (ert-deftest test-org
/add-planning-info
()
4132 "Test `org-add-planning-info'."
4133 ;; Create deadline when `org-adapt-indentation' is non-nil.
4135 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4136 (org-test-with-temp-text "* H\nParagraph<point>"
4137 (let ((org-adapt-indentation t
))
4138 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4139 (replace-regexp-in-string
4140 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4142 ;; Create deadline when `org-adapt-indentation' is nil.
4144 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4145 (org-test-with-temp-text "* H\nParagraph<point>"
4146 (let ((org-adapt-indentation nil
))
4147 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4148 (replace-regexp-in-string
4149 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4151 ;; Update deadline when `org-adapt-indentation' is non-nil.
4153 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4154 (org-test-with-temp-text "\
4156 DEADLINE: <2015-06-24 Wed>
4158 (let ((org-adapt-indentation t
))
4159 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4160 (replace-regexp-in-string
4161 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4163 ;; Update deadline when `org-adapt-indentation' is nil.
4165 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4166 (org-test-with-temp-text "\
4168 DEADLINE: <2015-06-24 Wed>
4170 (let ((org-adapt-indentation nil
))
4171 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4172 (replace-regexp-in-string
4173 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4175 ;; Schedule when `org-adapt-indentation' is non-nil.
4177 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4178 (org-test-with-temp-text "* H\nParagraph<point>"
4179 (let ((org-adapt-indentation t
))
4180 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4181 (replace-regexp-in-string
4182 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4184 ;; Schedule when `org-adapt-indentation' is nil.
4186 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4187 (org-test-with-temp-text "* H\nParagraph<point>"
4188 (let ((org-adapt-indentation nil
))
4189 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4190 (replace-regexp-in-string
4191 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4193 ;; Add deadline when scheduled.
4197 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4199 (org-test-with-temp-text "\
4201 SCHEDULED: <2015-06-24 Wed>
4203 (let ((org-adapt-indentation t
))
4204 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4205 (replace-regexp-in-string
4206 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4208 ;; Remove middle entry.
4212 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4214 (org-test-with-temp-text "\
4216 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4218 (let ((org-adapt-indentation t
))
4219 (org-add-planning-info nil nil
'deadline
))
4220 (replace-regexp-in-string
4221 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4223 ;; Remove last entry and then middle entry (order should not
4228 CLOSED: [2015-06-24]
4230 (org-test-with-temp-text "\
4232 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4234 (let ((org-adapt-indentation t
))
4235 (org-add-planning-info nil nil
'scheduled
'deadline
))
4236 (replace-regexp-in-string
4237 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4239 ;; Remove closed when `org-adapt-indentation' is non-nil.
4241 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4242 (org-test-with-temp-text "\
4244 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4246 (let ((org-adapt-indentation t
))
4247 (org-add-planning-info nil nil
'closed
))
4248 (replace-regexp-in-string
4249 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4252 (equal "* H\n Paragraph"
4253 (org-test-with-temp-text "\
4255 CLOSED: [2015-06-25 Thu]
4257 (let ((org-adapt-indentation t
))
4258 (org-add-planning-info nil nil
'closed
))
4259 (replace-regexp-in-string
4260 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4262 ;; Remove closed when `org-adapt-indentation' is nil.
4264 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4265 (org-test-with-temp-text "\
4267 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4269 (let ((org-adapt-indentation nil
))
4270 (org-add-planning-info nil nil
'closed
))
4271 (replace-regexp-in-string
4272 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4275 (equal "* H\nParagraph"
4276 (org-test-with-temp-text "\
4278 CLOSED: [2015-06-25 Thu]
4280 (let ((org-adapt-indentation nil
))
4281 (org-add-planning-info nil nil
'closed
))
4282 (replace-regexp-in-string
4283 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4285 ;; Remove closed entry and delete empty line.
4290 (org-test-with-temp-text "\
4292 CLOSED: [2015-06-24 Wed]
4294 (let ((org-adapt-indentation t
))
4295 (org-add-planning-info nil nil
'closed
))
4296 (replace-regexp-in-string
4297 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4299 ;; Remove one entry and update another.
4301 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4302 (org-test-with-temp-text "\
4304 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4306 (let ((org-adapt-indentation t
))
4307 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4308 (replace-regexp-in-string
4309 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4312 (ert-deftest test-org
/deadline
()
4313 "Test `org-deadline' specifications."
4314 ;; Insert a new value or replace existing one.
4316 (equal "* H\nDEADLINE: <2012-03-29>\n"
4317 (org-test-with-temp-text "* H"
4318 (let ((org-adapt-indentation nil
)
4319 (org-last-inserted-timestamp nil
))
4320 (org-deadline nil
"<2012-03-29 Tue>"))
4321 (replace-regexp-in-string
4322 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4325 (equal "* H\nDEADLINE: <2014-03-04>"
4326 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4327 (let ((org-adapt-indentation nil
)
4328 (org-last-inserted-timestamp nil
))
4329 (org-deadline nil
"<2014-03-04 Thu>"))
4330 (replace-regexp-in-string
4331 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4333 ;; Accept delta time, e.g., "+2d".
4335 (equal "* H\nDEADLINE: <2015-03-04>\n"
4336 (cl-letf (((symbol-function 'current-time
)
4337 (lambda (&rest args
)
4338 (apply #'encode-time
4339 (org-parse-time-string "2014-03-04")))))
4340 (org-test-with-temp-text "* H"
4341 (let ((org-adapt-indentation nil
)
4342 (org-last-inserted-timestamp nil
))
4343 (org-deadline nil
"+1y"))
4344 (replace-regexp-in-string
4345 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4346 ;; Preserve repeater.
4348 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4349 (org-test-with-temp-text "* H"
4350 (let ((org-adapt-indentation nil
)
4351 (org-last-inserted-timestamp nil
))
4352 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4353 (replace-regexp-in-string
4354 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4355 ;; Remove CLOSED keyword, if any.
4357 (equal "* H\nDEADLINE: <2012-03-29>"
4358 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4359 (let ((org-adapt-indentation nil
)
4360 (org-last-inserted-timestamp nil
))
4361 (org-deadline nil
"<2012-03-29 Tue>"))
4362 (replace-regexp-in-string
4363 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4364 ;; With C-u argument, remove DEADLINE keyword.
4367 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4368 (let ((org-adapt-indentation nil
)
4369 (org-last-inserted-timestamp nil
))
4370 (org-deadline '(4)))
4374 (org-test-with-temp-text "* H"
4375 (let ((org-adapt-indentation nil
)
4376 (org-last-inserted-timestamp nil
))
4377 (org-deadline '(4)))
4379 ;; With C-u C-u argument, prompt for a delay cookie.
4381 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4382 (cl-letf (((symbol-function 'org-read-date
)
4383 (lambda (&rest args
)
4384 (apply #'encode-time
4385 (org-parse-time-string "2014-03-04")))))
4386 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4387 (let ((org-adapt-indentation nil
)
4388 (org-last-inserted-timestamp nil
))
4389 (org-deadline '(16)))
4392 (cl-letf (((symbol-function 'org-read-date
)
4393 (lambda (&rest args
)
4394 (apply #'encode-time
4395 (org-parse-time-string "2014-03-04")))))
4396 (org-test-with-temp-text "* H"
4397 (let ((org-adapt-indentation nil
)
4398 (org-last-inserted-timestamp nil
))
4399 (org-deadline '(16)))
4401 ;; When a region is active and
4402 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4403 ;; same value in all headlines in region.
4405 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4406 (org-test-with-temp-text "* H1\n* H2"
4407 (let ((org-adapt-indentation nil
)
4408 (org-last-inserted-timestamp nil
)
4409 (org-loop-over-headlines-in-active-region t
))
4410 (transient-mark-mode 1)
4411 (push-mark (point) t t
)
4412 (goto-char (point-max))
4413 (org-deadline nil
"2012-03-29"))
4414 (replace-regexp-in-string
4415 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4417 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4418 (org-test-with-temp-text "* H1\n* H2"
4419 (let ((org-adapt-indentation nil
)
4420 (org-last-inserted-timestamp nil
)
4421 (org-loop-over-headlines-in-active-region nil
))
4422 (transient-mark-mode 1)
4423 (push-mark (point) t t
)
4424 (goto-char (point-max))
4425 (org-deadline nil
"2012-03-29"))
4426 (replace-regexp-in-string
4427 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4429 (ert-deftest test-org
/schedule
()
4430 "Test `org-schedule' specifications."
4431 ;; Insert a new value or replace existing one.
4433 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4434 (org-test-with-temp-text "* H"
4435 (let ((org-adapt-indentation nil
)
4436 (org-last-inserted-timestamp nil
))
4437 (org-schedule nil
"<2012-03-29 Tue>"))
4438 (replace-regexp-in-string
4439 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4442 (equal "* H\nSCHEDULED: <2014-03-04>"
4443 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4444 (let ((org-adapt-indentation nil
)
4445 (org-last-inserted-timestamp nil
))
4446 (org-schedule nil
"<2014-03-04 Thu>"))
4447 (replace-regexp-in-string
4448 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4450 ;; Accept delta time, e.g., "+2d".
4452 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4453 (cl-letf (((symbol-function 'current-time
)
4454 (lambda (&rest args
)
4455 (apply #'encode-time
4456 (org-parse-time-string "2014-03-04")))))
4457 (org-test-with-temp-text "* H"
4458 (let ((org-adapt-indentation nil
)
4459 (org-last-inserted-timestamp nil
))
4460 (org-schedule nil
"+1y"))
4461 (replace-regexp-in-string
4462 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4463 ;; Preserve repeater.
4465 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4466 (org-test-with-temp-text "* H"
4467 (let ((org-adapt-indentation nil
)
4468 (org-last-inserted-timestamp nil
))
4469 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4470 (replace-regexp-in-string
4471 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4472 ;; Remove CLOSED keyword, if any.
4474 (equal "* H\nSCHEDULED: <2012-03-29>"
4475 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4476 (let ((org-adapt-indentation nil
)
4477 (org-last-inserted-timestamp nil
))
4478 (org-schedule nil
"<2012-03-29 Tue>"))
4479 (replace-regexp-in-string
4480 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4481 ;; With C-u argument, remove SCHEDULED keyword.
4484 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4485 (let ((org-adapt-indentation nil
)
4486 (org-last-inserted-timestamp nil
))
4487 (org-schedule '(4)))
4491 (org-test-with-temp-text "* H"
4492 (let ((org-adapt-indentation nil
)
4493 (org-last-inserted-timestamp nil
))
4494 (org-schedule '(4)))
4496 ;; With C-u C-u argument, prompt for a delay cookie.
4498 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4499 (cl-letf (((symbol-function 'org-read-date
)
4500 (lambda (&rest args
)
4501 (apply #'encode-time
4502 (org-parse-time-string "2014-03-04")))))
4503 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4504 (let ((org-adapt-indentation nil
)
4505 (org-last-inserted-timestamp nil
))
4506 (org-schedule '(16)))
4509 (cl-letf (((symbol-function 'org-read-date
)
4510 (lambda (&rest args
)
4511 (apply #'encode-time
4512 (org-parse-time-string "2014-03-04")))))
4513 (org-test-with-temp-text "* H"
4514 (let ((org-adapt-indentation nil
)
4515 (org-last-inserted-timestamp nil
))
4516 (org-schedule '(16)))
4518 ;; When a region is active and
4519 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4520 ;; same value in all headlines in region.
4522 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4523 (org-test-with-temp-text "* H1\n* H2"
4524 (let ((org-adapt-indentation nil
)
4525 (org-last-inserted-timestamp nil
)
4526 (org-loop-over-headlines-in-active-region t
))
4527 (transient-mark-mode 1)
4528 (push-mark (point) t t
)
4529 (goto-char (point-max))
4530 (org-schedule nil
"2012-03-29"))
4531 (replace-regexp-in-string
4532 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4534 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4535 (org-test-with-temp-text "* H1\n* H2"
4536 (let ((org-adapt-indentation nil
)
4537 (org-last-inserted-timestamp nil
)
4538 (org-loop-over-headlines-in-active-region nil
))
4539 (transient-mark-mode 1)
4540 (push-mark (point) t t
)
4541 (goto-char (point-max))
4542 (org-schedule nil
"2012-03-29"))
4543 (replace-regexp-in-string
4544 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4546 ;; check if a repeater survives re-scheduling.
4548 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4549 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4550 (let ((org-adapt-indentation nil
)
4551 (org-last-inserted-timestamp nil
))
4552 (org-schedule nil
"2017-02-01"))
4558 (ert-deftest test-org
/buffer-property-keys
()
4559 "Test `org-buffer-property-keys' specifications."
4560 ;; Retrieve properties accross siblings.
4563 (org-test-with-temp-text "
4572 (org-buffer-property-keys))))
4573 ;; Retrieve properties accross children.
4576 (org-test-with-temp-text "
4585 (org-buffer-property-keys))))
4586 ;; Retrieve muliple properties in the same drawer.
4589 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4590 (org-buffer-property-keys))))
4591 ;; Ignore extension symbol in property name.
4594 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4595 (org-buffer-property-keys))))
4596 ;; With non-nil COLUMNS, extract property names from columns.
4599 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4600 (org-buffer-property-keys nil nil t
))))
4602 (equal '("A" "B" "COLUMNS")
4603 (org-test-with-temp-text
4604 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4605 (org-buffer-property-keys nil nil t
))))
4606 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4609 (org-test-with-temp-text
4610 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4611 (org-buffer-property-keys nil nil nil t
)))))
4613 (ert-deftest test-org
/property-values
()
4614 "Test `org-property-values' specifications."
4618 (org-test-with-temp-text
4619 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4620 (org-property-values "A"))))
4621 ;; Ignore empty values.
4623 (org-test-with-temp-text
4624 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4625 (org-property-values "A")))
4626 ;; Take into consideration extended values.
4629 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4630 (org-property-values "A")))))
4632 (ert-deftest test-org
/find-property
()
4633 "Test `org-find-property' specifications."
4637 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4638 (org-find-property "prop"))))
4639 ;; Ignore false positives.
4642 (org-test-with-temp-text
4643 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4644 (org-find-property "A"))))
4645 ;; Return first entry found in buffer.
4648 (org-test-with-temp-text
4649 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4650 (org-find-property "A"))))
4651 ;; Only search visible part of the buffer.
4654 (org-test-with-temp-text
4655 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4656 (org-narrow-to-subtree)
4657 (org-find-property "A"))))
4658 ;; With optional argument, only find entries with a specific value.
4660 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4661 (org-find-property "A" "2")))
4664 (org-test-with-temp-text
4665 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4666 (org-find-property "A" "2"))))
4667 ;; Use "nil" for explicit nil values.
4670 (org-test-with-temp-text
4671 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4672 (org-find-property "A" "nil")))))
4674 (ert-deftest test-org
/entry-delete
()
4675 "Test `org-entry-delete' specifications."
4679 " *:PROPERTIES:\n *:B: +2\n *:END:"
4680 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4681 (org-entry-delete (point) "A")
4683 ;; Also remove accumulated properties.
4687 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4688 (org-entry-delete (point) "A")
4690 ;; When last property is removed, remove the property drawer.
4694 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4695 (org-entry-delete (point) "A")
4697 ;; Return a non-nil value when some property was removed.
4699 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4700 (org-entry-delete (point) "A")))
4702 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4703 (org-entry-delete (point) "C")))
4704 ;; Special properties cannot be located in a drawer. Allow to
4705 ;; remove them anyway, in case of user error.
4707 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4708 (org-entry-delete (point) "SCHEDULED"))))
4710 (ert-deftest test-org
/entry-get
()
4711 "Test `org-entry-get' specifications."
4715 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4716 (org-entry-get (point) "A"))))
4720 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4721 (org-entry-get (point) "a"))))
4722 ;; Handle extended values, both before and after base value.
4725 (org-test-with-temp-text
4726 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4727 (org-entry-get (point) "A"))))
4728 ;; Empty values are returned as the empty string.
4731 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4732 (org-entry-get (point) "A"))))
4733 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4734 ;; otherwise, return nil.
4736 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4737 (org-entry-get (point) "A")))
4740 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4741 (org-entry-get (point) "A" nil t
))))
4742 ;; Return nil when no property is found, independently on the
4743 ;; LITERAL-NIL argument.
4745 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4746 (org-entry-get (point) "B")))
4748 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4749 (org-entry-get (point) "B" nil t
)))
4750 ;; Handle inheritance, when allowed. Include extended values and
4751 ;; possibly global values.
4755 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4756 (org-entry-get (point) "A" t
))))
4760 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4761 (let ((org-use-property-inheritance t
))
4762 (org-entry-get (point) "A" 'selective
)))))
4764 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4765 (let ((org-use-property-inheritance nil
))
4766 (org-entry-get (point) "A" 'selective
))))
4770 (org-test-with-temp-text
4771 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4772 (org-entry-get (point-max) "A" t
))))
4775 (org-test-with-temp-text
4776 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4778 (org-entry-get (point-max) "A" t
))))
4781 (org-test-with-temp-text
4782 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4784 (org-entry-get (point-max) "A" t
)))))
4786 (ert-deftest test-org
/entry-properties
()
4787 "Test `org-entry-properties' specifications."
4788 ;; Get "ITEM" property.
4791 (org-test-with-temp-text "* TODO H"
4792 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4795 (org-test-with-temp-text "* TODO H"
4796 (cdr (assoc "ITEM" (org-entry-properties))))))
4797 ;; Get "TODO" property. TODO keywords are case sensitive.
4800 (org-test-with-temp-text "* TODO H"
4801 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4804 (org-test-with-temp-text "* TODO H"
4805 (cdr (assoc "TODO" (org-entry-properties))))))
4807 (org-test-with-temp-text "* H"
4808 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4810 (org-test-with-temp-text "* todo H"
4811 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4812 ;; Get "PRIORITY" property.
4815 (org-test-with-temp-text "* [#A] H"
4816 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4819 (org-test-with-temp-text "* [#A] H"
4820 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4822 (equal (char-to-string org-default-priority
)
4823 (org-test-with-temp-text "* H"
4824 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4825 ;; Get "FILE" property.
4827 (org-test-with-temp-text-in-file "* H\nParagraph"
4828 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4829 (buffer-file-name))))
4831 (org-test-with-temp-text-in-file "* H\nParagraph"
4832 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4833 (buffer-file-name))))
4835 (org-test-with-temp-text "* H\nParagraph"
4836 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4837 ;; Get "TAGS" property.
4839 (equal ":tag1:tag2:"
4840 (org-test-with-temp-text "* H :tag1:tag2:"
4841 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4843 (equal ":tag1:tag2:"
4844 (org-test-with-temp-text "* H :tag1:tag2:"
4845 (cdr (assoc "TAGS" (org-entry-properties))))))
4847 (org-test-with-temp-text "* H"
4848 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4849 ;; Get "ALLTAGS" property.
4851 (equal ":tag1:tag2:"
4852 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4853 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4855 (equal ":tag1:tag2:"
4856 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4857 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4859 (org-test-with-temp-text "* H"
4860 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4861 ;; Get "BLOCKED" property.
4864 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4865 (let ((org-enforce-todo-dependencies t
)
4867 '(org-block-todo-from-children-or-siblings-or-parent)))
4868 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4871 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4872 (let ((org-enforce-todo-dependencies t
)
4874 '(org-block-todo-from-children-or-siblings-or-parent)))
4875 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4876 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4880 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4881 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4885 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4886 (cdr (assoc "CLOSED" (org-entry-properties))))))
4888 (org-test-with-temp-text "* H"
4889 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4893 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4894 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4898 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4899 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4901 (org-test-with-temp-text "* H"
4902 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4906 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4907 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4911 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4912 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4914 (org-test-with-temp-text "* H"
4915 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4919 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4920 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4923 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4924 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4927 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4928 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4931 (org-test-with-temp-text
4932 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4934 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4935 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4936 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4938 (equal "<2012-03-29 thu.>"
4939 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4940 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4942 (equal "[2012-03-29 thu.]"
4943 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4944 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4946 (equal "<2012-03-29 thu.>"
4947 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4948 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4950 (equal "[2014-03-04 tue.]"
4951 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4952 (cdr (assoc "TIMESTAMP_IA"
4953 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4955 (equal "<2012-03-29 thu.>"
4956 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4957 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4958 ;; Get standard properties.
4961 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4962 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4963 ;; Handle extended properties.
4966 (org-test-with-temp-text
4967 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4968 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4971 (org-test-with-temp-text
4972 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4973 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4974 ;; Ignore forbidden (special) properties.
4976 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4977 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4979 (ert-deftest test-org
/entry-put
()
4980 "Test `org-entry-put' specifications."
4981 ;; Error when not a string or nil.
4983 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4984 (org-entry-put 1 "test" 2)))
4985 ;; Error when property name is invalid.
4987 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4988 (org-entry-put 1 "no space" "value")))
4990 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4991 (org-entry-put 1 "" "value")))
4992 ;; Set "TODO" property.
4994 (string-match (regexp-quote " TODO H")
4995 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4996 (org-entry-put (point) "TODO" "TODO")
4999 (string-match (regexp-quote "* H")
5000 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5001 (org-entry-put (point) "TODO" nil
)
5003 ;; Set "PRIORITY" property.
5006 (org-test-with-temp-text "* [#B] H"
5007 (org-entry-put (point) "PRIORITY" "A")
5011 (org-test-with-temp-text "* [#B] H"
5012 (org-entry-put (point) "PRIORITY" nil
)
5014 ;; Set "SCHEDULED" property.
5016 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5017 (org-test-with-temp-text "* H"
5018 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5022 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5023 (org-entry-put (point) "SCHEDULED" nil
)
5026 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5027 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5028 (org-entry-put (point) "SCHEDULED" "earlier")
5031 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5032 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5033 (org-entry-put (point) "SCHEDULED" "later")
5035 ;; Set "DEADLINE" property.
5037 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5038 (org-test-with-temp-text "* H"
5039 (org-entry-put (point) "DEADLINE" "2014-03-04")
5043 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5044 (org-entry-put (point) "DEADLINE" nil
)
5047 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5048 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5049 (org-entry-put (point) "DEADLINE" "earlier")
5052 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5053 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5054 (org-entry-put (point) "DEADLINE" "later")
5056 ;; Set "CATEGORY" property
5058 (string-match "^ *:CATEGORY: cat"
5059 (org-test-with-temp-text "* H"
5060 (org-entry-put (point) "CATEGORY" "cat")
5062 ;; Regular properties, with or without pre-existing drawer.
5064 (string-match "^ *:A: +2$"
5065 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5066 (org-entry-put (point) "A" "2")
5069 (string-match "^ *:A: +1$"
5070 (org-test-with-temp-text "* H"
5071 (org-entry-put (point) "A" "1")
5073 ;; Special case: two consecutive headlines.
5075 (string-match "\\* A\n *:PROPERTIES:"
5076 (org-test-with-temp-text "* A\n** B"
5077 (org-entry-put (point) "A" "1")
5080 (ert-deftest test-org
/refresh-properties
()
5081 "Test `org-refresh-properties' specifications."
5084 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5085 (org-refresh-properties "A" 'org-test
)
5086 (get-text-property (point) 'org-test
))))
5088 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5089 (org-refresh-properties "B" 'org-test
)
5090 (get-text-property (point) 'org-test
)))
5091 ;; Handle properties only defined with extension syntax, i.e.,
5095 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5096 (org-refresh-properties "A" 'org-test
)
5097 (get-text-property (point) 'org-test
))))
5098 ;; When property is inherited, add text property to the whole
5102 (org-test-with-temp-text
5103 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5104 (let ((org-use-property-inheritance t
))
5105 (org-refresh-properties "A" 'org-test
))
5106 (get-text-property (point) 'org-test
))))
5107 ;; When property is inherited, use global value across the whole
5108 ;; buffer. However local values have precedence.
5111 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5113 (let ((org-use-property-inheritance nil
))
5114 (org-refresh-properties "A" 'org-test
))
5115 (get-text-property (point) 'org-test
))))
5118 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5120 (let ((org-use-property-inheritance t
))
5121 (org-refresh-properties "A" 'org-test
))
5122 (get-text-property (point) 'org-test
))))
5125 (org-test-with-temp-text
5126 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5128 (let ((org-use-property-inheritance t
))
5129 (org-refresh-properties "A" 'org-test
))
5130 (get-text-property (point) 'org-test
)))))
5135 (ert-deftest test-org
/update-radio-target-regexp
()
5136 "Test `org-update-radio-target-regexp' specifications."
5137 ;; Properly update cache with no previous radio target regexp.
5140 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5141 (save-excursion (goto-char (point-max)) (org-element-context))
5143 (search-forward "o")
5145 (org-update-radio-target-regexp)
5146 (goto-char (point-max))
5147 (org-element-type (org-element-context)))))
5148 ;; Properly update cache with previous radio target regexp.
5151 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5152 (save-excursion (goto-char (point-max)) (org-element-context))
5154 (search-forward "o")
5156 (org-update-radio-target-regexp)
5157 (search-backward "r")
5160 (org-update-radio-target-regexp)
5161 (goto-char (point-max))
5162 (delete-region (line-beginning-position) (point))
5164 (org-element-type (org-element-context))))))
5169 (ert-deftest test-org
/match-sparse-tree
()
5170 "Test `org-match-sparse-tree' specifications."
5173 (org-test-with-temp-text "* H\n** H1 :tag:"
5174 (org-match-sparse-tree nil
"tag")
5175 (search-forward "H1")
5176 (org-invisible-p2)))
5178 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5179 (org-match-sparse-tree nil
"tag")
5180 (search-forward "H2")
5181 (org-invisible-p2)))
5182 ;; "-" operator for tags.
5184 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5185 (org-match-sparse-tree nil
"tag1-tag2")
5186 (search-forward "H1")
5187 (org-invisible-p2)))
5189 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5190 (org-match-sparse-tree nil
"tag1-tag2")
5191 (search-forward "H2")
5192 (org-invisible-p2)))
5193 ;; "&" operator for tags.
5195 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5196 (org-match-sparse-tree nil
"tag1&tag2")
5197 (search-forward "H1")
5198 (org-invisible-p2)))
5200 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5201 (org-match-sparse-tree nil
"tag1&tag2")
5202 (search-forward "H2")
5203 (org-invisible-p2)))
5204 ;; "|" operator for tags.
5206 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5207 (org-match-sparse-tree nil
"tag1|tag2")
5208 (search-forward "H1")
5209 (org-invisible-p2)))
5211 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5212 (org-match-sparse-tree nil
"tag1|tag2")
5213 (search-forward "H2")
5214 (org-invisible-p2)))
5215 ;; Regexp match on tags.
5217 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5218 (org-match-sparse-tree nil
"{^tag.*}")
5219 (search-forward "H1")
5220 (org-invisible-p2)))
5222 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5223 (org-match-sparse-tree nil
"{^tag.*}")
5224 (search-forward "H2")
5225 (org-invisible-p2)))
5226 ;; Match group tags.
5228 (org-test-with-temp-text
5229 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5230 (org-match-sparse-tree nil
"work")
5231 (search-forward "H1")
5232 (org-invisible-p2)))
5234 (org-test-with-temp-text
5235 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5236 (org-match-sparse-tree nil
"work")
5237 (search-forward "H2")
5238 (org-invisible-p2)))
5239 ;; Match group tags with hard brackets.
5241 (org-test-with-temp-text
5242 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5243 (org-match-sparse-tree nil
"work")
5244 (search-forward "H1")
5245 (org-invisible-p2)))
5247 (org-test-with-temp-text
5248 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5249 (org-match-sparse-tree nil
"work")
5250 (search-forward "H2")
5251 (org-invisible-p2)))
5252 ;; Match tags in hierarchies
5254 (org-test-with-temp-text
5255 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5256 #+TAGS: [ Lev_2 : Lev_3 ]\n
5257 #+TAGS: { Lev_3 : Lev_4 }\n
5258 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5259 (org-match-sparse-tree nil
"Lev_1")
5260 (search-forward "H4")
5261 (org-invisible-p2)))
5262 ;; Match regular expressions in tags
5264 (org-test-with-temp-text
5265 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5266 (org-match-sparse-tree nil
"Lev")
5267 (search-forward "H1")
5268 (org-invisible-p2)))
5270 (org-test-with-temp-text
5271 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5272 (org-match-sparse-tree nil
"Lev")
5273 (search-forward "H1")
5274 (org-invisible-p2)))
5275 ;; Match properties.
5277 (org-test-with-temp-text
5278 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5279 (org-match-sparse-tree nil
"A=\"1\"")
5280 (search-forward "H2")
5281 (org-invisible-p2)))
5283 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5284 (org-match-sparse-tree nil
"A=\"1\"")
5285 (search-forward "H2")
5286 (org-invisible-p2)))
5287 ;; Case is not significant when matching properties.
5289 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5290 (org-match-sparse-tree nil
"a=\"1\"")
5291 (search-forward "H2")
5292 (org-invisible-p2)))
5294 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5295 (org-match-sparse-tree nil
"A=\"1\"")
5296 (search-forward "H2")
5297 (org-invisible-p2)))
5298 ;; Match special LEVEL property.
5300 (org-test-with-temp-text "* H\n** H1\n*** H2"
5301 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5302 (search-forward "H1")
5303 (org-invisible-p2)))
5305 (org-test-with-temp-text "* H\n** H1\n*** H2"
5306 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5307 (search-forward "H2")
5308 (org-invisible-p2)))
5309 ;; Comparison operators when matching properties.
5311 (org-test-with-temp-text
5312 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5313 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5314 (search-forward "H1")
5315 (org-invisible-p2)))
5317 (org-test-with-temp-text
5318 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5319 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5320 (search-forward "H2")
5321 (org-invisible-p2)))
5322 ;; Regexp match on properties values.
5324 (org-test-with-temp-text
5325 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5326 (org-match-sparse-tree nil
"A={f.*}")
5327 (search-forward "H1")
5328 (org-invisible-p2)))
5330 (org-test-with-temp-text
5331 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5332 (org-match-sparse-tree nil
"A={f.*}")
5333 (search-forward "H2")
5334 (org-invisible-p2)))
5335 ;; With an optional argument, limit match to TODO entries.
5337 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5338 (org-match-sparse-tree t
"tag")
5339 (search-forward "H1")
5340 (org-invisible-p2)))
5342 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5343 (org-match-sparse-tree t
"tag")
5344 (search-forward "H2")
5345 (org-invisible-p2))))
5347 (ert-deftest test-org
/occur
()
5348 "Test `org-occur' specifications."
5349 ;; Count number of matches.
5352 (org-test-with-temp-text "* H\nA\n* H2"
5356 (org-test-with-temp-text "* H\nA\n* H2\nA"
5358 ;; Test CALLBACK optional argument.
5361 (org-test-with-temp-text "* H\nA\n* H2"
5362 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5365 (org-test-with-temp-text "* H\nA\n* H2\nA"
5366 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5367 ;; Case-fold searches according to `org-occur-case-fold-search'.
5370 (org-test-with-temp-text "Aa"
5371 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5374 (org-test-with-temp-text "Aa"
5375 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5378 (org-test-with-temp-text "Aa"
5379 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5382 (org-test-with-temp-text "Aa"
5383 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5386 (org-test-with-temp-text "Aa"
5387 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5390 (org-test-with-temp-text "Aa"
5391 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5396 (ert-deftest test-org
/tag-string-to-alist
()
5397 "Test `org-tag-string-to-alist' specifications."
5398 ;; Tag without selection key.
5399 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5400 ;; Tag with selection key.
5401 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5405 (org-tag-string-to-alist "[ group : t1 t2 ]")
5406 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5407 ;; Mutually exclusive tags.
5408 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5409 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5412 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5413 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5415 (ert-deftest test-org
/tag-alist-to-string
()
5416 "Test `org-tag-alist-to-string' specifications."
5417 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5418 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5421 (org-tag-alist-to-string
5422 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5423 "[ group : t1 t2 ]"))
5425 (equal (org-tag-alist-to-string
5426 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5430 (org-tag-alist-to-string
5431 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5432 "{ group : tag1 tag2 }")))
5434 (ert-deftest test-org
/tag-alist-to-groups
()
5435 "Test `org-tag-alist-to-groups' specifications."
5437 (equal (org-tag-alist-to-groups
5438 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5439 '(("group" "t1" "t2"))))
5442 (org-tag-alist-to-groups
5443 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5444 '(("group" "t1" "t2"))))
5446 (org-tag-alist-to-groups
5447 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5449 (ert-deftest test-org
/tag-align
()
5450 "Test tags alignment."
5451 ;; Test aligning tags with different display width.
5453 ;; 12345678901234567890
5454 (equal "* Test :abc:"
5455 (org-test-with-temp-text "* Test :abc:"
5456 (let ((org-tags-column -
20)
5457 (indent-tabs-mode nil
))
5458 (org-fix-tags-on-the-fly))
5461 ;; 12345678901234567890
5462 (equal "* Test :日本語:"
5463 (org-test-with-temp-text "* Test :日本語:"
5464 (let ((org-tags-column -
20)
5465 (indent-tabs-mode nil
))
5466 (org-fix-tags-on-the-fly))
5468 ;; Make sure aligning tags do not skip invisible text.
5470 (equal "* [[linkx]] :tag:"
5471 (org-test-with-temp-text "* [[link<point>]] :tag:"
5472 (let ((org-tags-column 0))
5473 (org-fix-tags-on-the-fly)
5475 (buffer-string))))))
5477 (ert-deftest test-org
/tags-at
()
5479 (equal '("foo" "bar")
5480 (org-test-with-temp-text
5481 "* T<point>est :foo:bar:"
5482 (org-get-tags-at)))))
5487 (ert-deftest test-org
/time-stamp
()
5488 "Test `org-time-stamp' specifications."
5489 ;; Insert chosen time stamp at point.
5492 "Te<2014-03-04 .*?>xt"
5493 (org-test-with-temp-text "Te<point>xt"
5494 (cl-letf (((symbol-function 'org-read-date
)
5495 (lambda (&rest args
)
5496 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5497 (org-time-stamp nil
)
5499 ;; With a prefix argument, also insert time.
5502 "Te<2014-03-04 .*? 00:41>xt"
5503 (org-test-with-temp-text "Te<point>xt"
5504 (cl-letf (((symbol-function 'org-read-date
)
5505 (lambda (&rest args
)
5506 (apply #'encode-time
5507 (org-parse-time-string "2014-03-04 00:41")))))
5508 (org-time-stamp '(4))
5510 ;; With two universal prefix arguments, insert an active timestamp
5511 ;; with the current time without prompting the user.
5514 "Te<2014-03-04 .*? 00:41>xt"
5515 (org-test-with-temp-text "Te<point>xt"
5516 (cl-letf (((symbol-function 'current-time
)
5518 (apply #'encode-time
5519 (org-parse-time-string "2014-03-04 00:41")))))
5520 (org-time-stamp '(16))
5522 ;; When optional argument is non-nil, insert an inactive timestamp.
5525 "Te\\[2014-03-04 .*?\\]xt"
5526 (org-test-with-temp-text "Te<point>xt"
5527 (cl-letf (((symbol-function 'org-read-date
)
5528 (lambda (&rest args
)
5529 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5530 (org-time-stamp nil t
)
5532 ;; When called from a timestamp, replace existing one.
5536 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5537 (cl-letf (((symbol-function 'org-read-date
)
5538 (lambda (&rest args
)
5539 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5540 (org-time-stamp nil
)
5544 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5545 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5546 (cl-letf (((symbol-function 'org-read-date
)
5547 (lambda (&rest args
)
5548 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5549 (org-time-stamp nil
)
5551 ;; When replacing a timestamp, preserve repeater, if any.
5554 "<2014-03-04 .*? \\+2y>"
5555 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5556 (cl-letf (((symbol-function 'org-read-date
)
5557 (lambda (&rest args
)
5558 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5559 (org-time-stamp nil
)
5561 ;; When called twice in a raw, build a date range.
5564 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5565 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5566 (cl-letf (((symbol-function 'org-read-date
)
5567 (lambda (&rest args
)
5568 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5569 (let ((last-command 'org-time-stamp
)
5570 (this-command 'org-time-stamp
))
5571 (org-time-stamp nil
))
5572 (buffer-string))))))
5574 (ert-deftest test-org
/timestamp-has-time-p
()
5575 "Test `org-timestamp-has-time-p' specifications."
5578 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5579 (org-timestamp-has-time-p (org-element-context))))
5582 (org-test-with-temp-text "<2012-03-29 Thu>"
5583 (org-timestamp-has-time-p (org-element-context)))))
5585 (ert-deftest test-org
/timestamp-format
()
5586 "Test `org-timestamp-format' specifications."
5591 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5592 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5597 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5598 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5600 (ert-deftest test-org
/timestamp-split-range
()
5601 "Test `org-timestamp-split-range' specifications."
5602 ;; Extract range start (active).
5605 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5606 (let ((ts (org-timestamp-split-range (org-element-context))))
5607 (mapcar (lambda (p) (org-element-property p ts
))
5608 '(:year-end
:month-end
:day-end
))))))
5609 ;; Extract range start (inactive)
5612 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5613 (let ((ts (org-timestamp-split-range (org-element-context))))
5614 (mapcar (lambda (p) (org-element-property p ts
))
5615 '(:year-end
:month-end
:day-end
))))))
5616 ;; Extract range end (active).
5619 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5620 (let ((ts (org-timestamp-split-range
5621 (org-element-context) t
)))
5622 (mapcar (lambda (p) (org-element-property p ts
))
5623 '(:year-end
:month-end
:day-end
))))))
5624 ;; Extract range end (inactive)
5627 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5628 (let ((ts (org-timestamp-split-range
5629 (org-element-context) t
)))
5630 (mapcar (lambda (p) (org-element-property p ts
))
5631 '(:year-end
:month-end
:day-end
))))))
5632 ;; Return the timestamp if not a range.
5634 (org-test-with-temp-text "[2012-03-29 Thu]"
5635 (let* ((ts-orig (org-element-context))
5636 (ts-copy (org-timestamp-split-range ts-orig
)))
5637 (eq ts-orig ts-copy
))))
5639 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5640 (let* ((ts-orig (org-element-context))
5641 (ts-copy (org-timestamp-split-range ts-orig
)))
5642 (eq ts-orig ts-copy
)))))
5644 (ert-deftest test-org
/timestamp-translate
()
5645 "Test `org-timestamp-translate' specifications."
5646 ;; Translate whole date range.
5649 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5650 (let ((org-display-custom-times t
)
5651 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5652 (org-timestamp-translate (org-element-context))))))
5653 ;; Translate date range start.
5656 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5657 (let ((org-display-custom-times t
)
5658 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5659 (org-timestamp-translate (org-element-context) 'start
)))))
5660 ;; Translate date range end.
5663 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5664 (let ((org-display-custom-times t
)
5665 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5666 (org-timestamp-translate (org-element-context) 'end
)))))
5667 ;; Translate time range.
5670 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5671 (let ((org-display-custom-times t
)
5672 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5673 (org-timestamp-translate (org-element-context))))))
5674 ;; Translate non-range timestamp.
5677 (org-test-with-temp-text "<2012-03-29 Thu>"
5678 (let ((org-display-custom-times t
)
5679 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5680 (org-timestamp-translate (org-element-context))))))
5681 ;; Do not change `diary' timestamps.
5683 (equal "<%%(org-float t 4 2)>"
5684 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5685 (let ((org-display-custom-times t
)
5686 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5687 (org-timestamp-translate (org-element-context)))))))
5693 (ert-deftest test-org
/flag-drawer
()
5694 "Test `org-flag-drawer' specifications."
5697 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5699 (get-char-property (line-end-position) 'invisible
)))
5702 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5704 (org-flag-drawer nil
)
5705 (get-char-property (line-end-position) 'invisible
)))
5706 ;; Test optional argument.
5708 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5709 (let ((drawer (save-excursion (search-forward ":D2")
5710 (org-element-at-point))))
5711 (org-flag-drawer t drawer
)
5712 (get-char-property (progn (search-forward ":D2") (line-end-position))
5715 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5716 (let ((drawer (save-excursion (search-forward ":D2")
5717 (org-element-at-point))))
5718 (org-flag-drawer t drawer
)
5719 (get-char-property (line-end-position) 'invisible
))))
5720 ;; Do not hide fake drawers.
5722 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5725 (get-char-property (line-end-position) 'invisible
)))
5726 ;; Do not hide incomplete drawers.
5728 (org-test-with-temp-text ":D:\nparagraph"
5731 (get-char-property (line-end-position) 'invisible
)))
5732 ;; Do not hide drawers when called from final blank lines.
5734 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5735 (goto-char (point-max))
5737 (goto-char (point-min))
5738 (get-char-property (line-end-position) 'invisible
)))
5739 ;; Don't leave point in an invisible part of the buffer when hiding
5742 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5743 (goto-char (point-max))
5745 (get-char-property (point) 'invisible
))))
5747 (ert-deftest test-org
/hide-block-toggle
()
5748 "Test `org-hide-block-toggle' specifications."
5749 ;; Error when not at a block.
5751 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5752 (org-hide-block-toggle 'off
)
5753 (get-char-property (line-end-position) 'invisible
)))
5756 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5757 (org-hide-block-toggle)
5758 (get-char-property (line-end-position) 'invisible
)))
5760 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5761 (org-hide-block-toggle)
5762 (get-char-property (line-end-position) 'invisible
)))
5763 ;; Show block unconditionally when optional argument is `off'.
5765 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5766 (org-hide-block-toggle)
5767 (org-hide-block-toggle 'off
)
5768 (get-char-property (line-end-position) 'invisible
)))
5770 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5771 (org-hide-block-toggle 'off
)
5772 (get-char-property (line-end-position) 'invisible
)))
5773 ;; Hide block unconditionally when optional argument is non-nil.
5775 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5776 (org-hide-block-toggle t
)
5777 (get-char-property (line-end-position) 'invisible
)))
5779 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5780 (org-hide-block-toggle)
5781 (org-hide-block-toggle t
)
5782 (get-char-property (line-end-position) 'invisible
)))
5783 ;; Do not hide block when called from final blank lines.
5785 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5786 (org-hide-block-toggle)
5787 (goto-char (point-min))
5788 (get-char-property (line-end-position) 'invisible
)))
5789 ;; Don't leave point in an invisible part of the buffer when hiding
5792 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5793 (org-hide-block-toggle)
5794 (get-char-property (point) 'invisible
))))
5796 (ert-deftest test-org
/hide-block-toggle-maybe
()
5797 "Test `org-hide-block-toggle-maybe' specifications."
5799 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5800 (org-hide-block-toggle-maybe)))
5802 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5804 (ert-deftest test-org
/set-tags
()
5805 "Test `org-set-tags' specifications."
5806 ;; Tags set via fast-tag-selection should be visible afterwards
5808 (let ((org-tag-alist '(("NEXT" . ?n
)))
5809 (org-fast-tag-selection-single-key t
))
5810 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5811 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5812 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5813 ;; Show only headlines
5815 ;; Set NEXT tag on current entry
5816 (org-set-tags nil nil
)
5817 ;; Move point to that NEXT tag
5818 (search-forward "NEXT") (backward-word)
5819 ;; And it should be visible (i.e. no overlays)
5820 (not (overlays-at (point))))))))
5822 (ert-deftest test-org
/show-set-visibility
()
5823 "Test `org-show-set-visibility' specifications."
5824 ;; Do not throw an error before first heading.
5826 (org-test-with-temp-text "Preamble\n* Headline"
5827 (org-show-set-visibility 'tree
)
5829 ;; Test all visibility spans, both on headline and in entry.
5830 (let ((list-visible-lines
5831 (lambda (state headerp
)
5832 (org-test-with-temp-text "* Grandmother (0)
5843 **** The other child (11)
5848 (search-forward (if headerp
"Self" "Match"))
5849 (org-show-set-visibility state
)
5850 (goto-char (point-min))
5851 (let (result (line 0))
5853 (unless (org-invisible-p2) (push line result
))
5856 (nreverse result
))))))
5857 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5858 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5859 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5860 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5861 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5862 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5863 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5864 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5865 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5866 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5867 (funcall list-visible-lines
'tree nil
)))
5868 (should (equal '(0 1 3 4 5 7 12 13)
5869 (funcall list-visible-lines
'canonical t
)))
5870 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5871 (funcall list-visible-lines
'canonical nil
))))
5872 ;; When point is hidden in a drawer or a block, make sure to make it
5875 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5876 (org-hide-block-toggle)
5877 (search-forward "Text")
5878 (org-show-set-visibility 'minimal
)
5879 (org-invisible-p2)))
5881 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5883 (search-forward "Text")
5884 (org-show-set-visibility 'minimal
)
5885 (org-invisible-p2)))
5887 (org-test-with-temp-text
5888 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5891 (org-hide-block-toggle)
5892 (search-forward "Text")
5893 (org-show-set-visibility 'minimal
)
5894 (org-invisible-p2))))
5899 ;;; test-org.el ends here