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))))
788 ;; Likewise, on a blank line at the end of a footnote definition,
789 ;; indent at column 0 if line belongs to the definition. Otherwise,
790 ;; indent like the definition itself.
793 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
794 (goto-char (point-max))
795 (let ((org-adapt-indentation t
)) (org-indent-line))
796 (org-get-indentation))))
799 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
800 (goto-char (point-max))
801 (let ((org-adapt-indentation t
)) (org-indent-line))
802 (org-get-indentation))))
803 ;; After the end of the contents of a greater element, indent like
804 ;; the beginning of the element.
807 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
810 (org-get-indentation))))
811 ;; On blank lines after a paragraph, indent like its last non-empty
815 (org-test-with-temp-text " Paragraph\n\n<point>"
817 (org-get-indentation))))
818 ;; At the first line of an element, indent like previous element's
819 ;; first line, ignoring footnotes definitions and inline tasks, or
820 ;; according to parent.
823 (org-test-with-temp-text "A\n\n B\n\nC"
824 (goto-char (point-max))
826 (org-get-indentation))))
829 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
830 (goto-char (point-max))
832 (org-get-indentation))))
835 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
838 (org-get-indentation))))
839 ;; Within code part of a source block, use language major mode if
840 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
841 ;; according to line above.
844 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
846 (let ((org-src-tab-acts-natively t
)
847 (org-edit-src-content-indentation 0))
849 (org-get-indentation))))
852 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
854 (let ((org-src-tab-acts-natively nil
)
855 (org-edit-src-content-indentation 0))
857 (org-get-indentation))))
858 ;; Otherwise, indent like the first non-blank line above.
861 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
864 (org-get-indentation))))
865 ;; Align node properties according to `org-property-format'. Handle
866 ;; nicely empty values.
868 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
869 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
870 (let ((org-property-format "%-10s %s")) (org-indent-line))
873 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
874 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
875 (let ((org-property-format "%-10s %s")) (org-indent-line))
878 (ert-deftest test-org
/indent-region
()
879 "Test `org-indent-region' specifications."
883 (org-test-with-temp-text " A\nB\n C"
884 (org-indent-region (point-min) (point-max))
886 ;; Indent greater elements along with their contents.
888 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
889 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
890 (org-indent-region (point-min) (point-max))
892 ;; Ignore contents of verse blocks. Only indent block delimiters.
894 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
895 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
896 (org-indent-region (point-min) (point-max))
899 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
900 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
901 (org-indent-region (point-min) (point-max))
903 ;; Indent example blocks as a single block, unless indentation
904 ;; should be preserved. In this case only indent the block markers.
906 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
907 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
908 (org-indent-region (point-min) (point-max))
911 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
912 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
913 (org-indent-region (point-min) (point-max))
916 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
917 (org-test-with-temp-text
918 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
919 (org-indent-region (point-min) (point-max))
922 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
923 (org-test-with-temp-text
924 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
925 (let ((org-src-preserve-indentation t
))
926 (org-indent-region (point-min) (point-max)))
928 ;; Treat export blocks as a whole.
930 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
931 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
932 (org-indent-region (point-min) (point-max))
935 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
936 (org-test-with-temp-text
937 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
938 (org-indent-region (point-min) (point-max))
940 ;; Indent according to mode if `org-src-tab-acts-natively' is
941 ;; non-nil. Otherwise, do not indent code at all.
943 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
944 (org-test-with-temp-text
945 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
946 (let ((org-src-tab-acts-natively t
)
947 (org-edit-src-content-indentation 0))
948 (org-indent-region (point-min) (point-max)))
951 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
952 (org-test-with-temp-text
953 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
954 (let ((org-src-tab-acts-natively nil
)
955 (org-edit-src-content-indentation 0))
956 (org-indent-region (point-min) (point-max)))
958 ;; Align node properties according to `org-property-format'. Handle
959 ;; nicely empty values.
961 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
962 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
963 (let ((org-property-format "%-10s %s")
964 (org-adapt-indentation nil
))
965 (org-indent-region (point) (point-max)))
968 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
969 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
970 (let ((org-property-format "%-10s %s")
971 (org-adapt-indentation nil
))
972 (org-indent-region (point) (point-max)))
974 ;; Indent plain lists.
976 (equal "- A\n B\n - C\n\n D"
977 (org-test-with-temp-text "- A\n B\n - C\n\n D"
978 (org-indent-region (point-min) (point-max))
982 (org-test-with-temp-text " - A\n\n - B"
983 (org-indent-region (point-min) (point-max))
985 ;; Indent footnote definitions.
987 (equal "[fn:1] Definition\n\nDefinition"
988 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
989 (org-indent-region (point-min) (point-max))
991 ;; Special case: Start indenting on a blank line.
994 (org-test-with-temp-text "\n Paragraph"
995 (org-indent-region (point-min) (point-max))
1002 (ert-deftest test-org
/delete-indentation
()
1003 "Test `org-delete-indentation' specifications."
1005 (should (equal "foo bar"
1006 (org-test-with-temp-text
1008 (org-delete-indentation)
1010 ;; With optional argument.
1011 (should (equal "foo bar"
1012 (org-test-with-temp-text
1014 (org-delete-indentation t
)
1016 ;; At headline text should be appended to the headline text.
1018 (equal"* foo bar :tag:"
1019 (let (org-auto-align-tags)
1020 (org-test-with-temp-text
1021 "* foo :tag:\n bar<point>"
1022 (org-delete-indentation)
1025 (equal "* foo bar :tag:"
1026 (let (org-auto-align-tags)
1027 (org-test-with-temp-text
1028 "* foo <point>:tag:\n bar"
1029 (org-delete-indentation t
)
1030 (buffer-string))))))
1032 (ert-deftest test-org
/return
()
1033 "Test `org-return' specifications."
1036 (equal "Para\ngraph"
1037 (org-test-with-temp-text "Para<point>graph"
1040 ;; With optional argument, indent line.
1042 (equal " Para\n graph"
1043 (org-test-with-temp-text " Para<point>graph"
1046 ;; On a table, call `org-table-next-row'.
1048 (org-test-with-temp-text "| <point>a |\n| b |"
1050 (looking-at-p "b")))
1051 ;; Open link or timestamp under point when `org-return-follows-link'
1054 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1055 (let ((org-return-follows-link t
)
1056 (org-link-search-must-match-exact-headline nil
))
1058 (looking-at-p "<<target>>")))
1060 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1061 (let ((org-return-follows-link nil
)) (org-return))
1062 (looking-at-p "<<target>>")))
1064 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1065 (let ((org-return-follows-link t
)) (org-return))
1066 (looking-at-p "* b")))
1068 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1069 (let ((org-return-follows-link t
)
1070 (org-link-search-must-match-exact-headline nil
))
1072 (looking-at-p "<<target>>")))
1074 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1075 (let ((org-return-follows-link t
)
1076 (org-link-search-must-match-exact-headline nil
))
1078 (looking-at-p "<<target>>")))
1079 ;; When `org-return-follows-link' is non-nil, tolerate links and
1080 ;; timestamps in comments, node properties, etc.
1082 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1083 (let ((org-return-follows-link t
)
1084 (org-link-search-must-match-exact-headline nil
))
1086 (looking-at-p "<<target>>")))
1088 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1089 (let ((org-return-follows-link nil
)) (org-return))
1090 (looking-at-p "<<target>>")))
1092 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1093 (let ((org-return-follows-link t
)
1094 (org-link-search-must-match-exact-headline nil
))
1096 (looking-at-p "<<target>>")))
1097 ;; However, do not open link when point is in a table.
1099 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1100 (let ((org-return-follows-link t
)) (org-return))
1101 (looking-at-p "between")))
1102 ;; Special case: in a list, when indenting, do not break structure.
1105 (org-test-with-temp-text "- A <point>B"
1110 (org-test-with-temp-text "- A\n<point>- B"
1113 ;; On tags part of a headline, add a newline below it instead of
1116 (equal "* H :tag:\n"
1117 (org-test-with-temp-text "* H :<point>tag:"
1120 ;; Before headline text, add a newline below it instead of breaking
1123 (equal "* TODO H :tag:\n"
1124 (org-test-with-temp-text "* <point>TODO H :tag:"
1128 (equal "* TODO [#B] H :tag:\n"
1129 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1132 (should ;TODO are case-sensitive
1134 (org-test-with-temp-text "* <point>Todo"
1137 ;; At headline text, break headline text but preserve tags.
1139 (equal "* TODO [#B] foo :tag:\nbar"
1140 (let (org-auto-align-tags)
1141 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1144 ;; At bol of headline insert newline.
1147 (org-test-with-temp-text "<point>* h"
1150 ;; Refuse to leave invalid headline in buffer.
1153 (org-test-with-temp-text "*<point> h"
1157 (ert-deftest test-org
/meta-return
()
1158 "Test M-RET (`org-meta-return') specifications."
1159 ;; In a table field insert a row above.
1161 (org-test-with-temp-text "| a |"
1165 (looking-at "| |$")))
1166 ;; In a paragraph change current line into a header.
1168 (org-test-with-temp-text "a"
1171 (looking-at "\* a$")))
1172 ;; In an item insert an item, in this case above.
1174 (org-test-with-temp-text "- a"
1177 (looking-at "- $")))
1178 ;; In a drawer and item insert an item, in this case above.
1180 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1184 (looking-at "- $"))))
1186 (ert-deftest test-org
/insert-heading
()
1187 "Test `org-insert-heading' specifications."
1188 ;; In an empty buffer, insert a new headline.
1191 (org-test-with-temp-text ""
1192 (org-insert-heading)
1194 ;; At the beginning of a line, turn it into a headline
1197 (org-test-with-temp-text "<point>P"
1198 (org-insert-heading)
1200 ;; In the middle of a line, split the line if allowed, otherwise,
1201 ;; insert the headline at its end.
1203 (equal "Para\n* graph"
1204 (org-test-with-temp-text "Para<point>graph"
1205 (let ((org-M-RET-may-split-line '((default . t
))))
1206 (org-insert-heading))
1209 (equal "Paragraph\n* "
1210 (org-test-with-temp-text "Para<point>graph"
1211 (let ((org-M-RET-may-split-line '((default . nil
))))
1212 (org-insert-heading))
1214 ;; At the beginning of a headline, create one above.
1217 (org-test-with-temp-text "* H"
1218 (org-insert-heading)
1220 ;; In the middle of a headline, split it if allowed.
1223 (org-test-with-temp-text "* H<point>1"
1224 (let ((org-M-RET-may-split-line '((headline . t
))))
1225 (org-insert-heading))
1229 (org-test-with-temp-text "* H<point>1"
1230 (let ((org-M-RET-may-split-line '((headline . nil
))))
1231 (org-insert-heading))
1233 ;; However, splitting cannot happen on TODO keywords, priorities or
1236 (equal "* TODO H1\n* "
1237 (org-test-with-temp-text "* TO<point>DO H1"
1238 (let ((org-M-RET-may-split-line '((headline . t
))))
1239 (org-insert-heading))
1242 (equal "* [#A] H1\n* "
1243 (org-test-with-temp-text "* [#<point>A] H1"
1244 (let ((org-M-RET-may-split-line '((headline . t
))))
1245 (org-insert-heading))
1248 (equal "* H1 :tag:\n* "
1249 (org-test-with-temp-text "* H1 :ta<point>g:"
1250 (let ((org-M-RET-may-split-line '((headline . t
))))
1251 (org-insert-heading))
1253 ;; When on a list, insert an item instead, unless called with an
1254 ;; universal argument or if list is invisible. In this case, create
1255 ;; a new headline after contents.
1257 (equal "* H\n- item\n- "
1258 (org-test-with-temp-text "* H\n- item<point>"
1259 (let ((org-insert-heading-respect-content nil
))
1260 (org-insert-heading))
1263 (equal "* H\n- item\n- item 2\n* "
1264 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1265 (let ((org-insert-heading-respect-content nil
))
1266 (org-insert-heading '(4)))
1269 (equal "* H\n- item\n* "
1270 (org-test-with-temp-text "* H\n- item"
1272 (goto-char (point-max))
1273 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1275 ;; Preserve list visibility when inserting an item.
1279 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1280 (let ((org-cycle-include-plain-lists t
))
1284 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1285 (list (get-char-property (line-beginning-position 0) 'invisible
)
1286 (get-char-property (line-end-position 2) 'invisible
))))))
1287 ;; When called with one universal argument, insert a new headline at
1288 ;; the end of the current subtree, independently on the position of
1293 (org-test-with-temp-text "* H1\n** H2"
1294 (let ((org-insert-heading-respect-content nil
))
1295 (org-insert-heading '(4)))
1300 (org-test-with-temp-text "* H<point>1\n** H2"
1301 (let ((org-insert-heading-respect-content nil
))
1302 (org-insert-heading '(4)))
1304 ;; When called with two universal arguments, insert a new headline
1305 ;; at the end of the grandparent subtree.
1307 (equal "* H1\n** H3\n- item\n** H2\n** "
1308 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1309 (let ((org-insert-heading-respect-content nil
))
1310 (org-insert-heading '(16)))
1312 ;; When optional TOP-LEVEL argument is non-nil, always insert
1313 ;; a level 1 heading.
1315 (equal "* H1\n** H2\n* "
1316 (org-test-with-temp-text "* H1\n** H2<point>"
1317 (org-insert-heading nil nil t
)
1320 (equal "* H1\n- item\n* "
1321 (org-test-with-temp-text "* H1\n- item<point>"
1322 (org-insert-heading nil nil t
)
1324 ;; Corner case: correctly insert a headline after an empty one.
1327 (org-test-with-temp-text "* <point>"
1328 (org-insert-heading)
1331 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1332 "Test `org-insert-todo-heading-respect-content' specifications."
1333 ;; Create a TODO heading.
1335 (org-test-with-temp-text "* H1\n Body"
1336 (org-insert-todo-heading-respect-content)
1337 (nth 2 (org-heading-components))))
1338 ;; Add headline at the end of the first subtree
1340 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1341 (search-forward "H1Body")
1342 (org-insert-todo-heading-respect-content)
1343 (and (eobp) (org-at-heading-p))))
1344 ;; In a list, do not create a new item.
1346 (org-test-with-temp-text "* H\n- an item\n- another one"
1347 (search-forward "an ")
1348 (org-insert-todo-heading-respect-content)
1349 (and (eobp) (org-at-heading-p)))))
1351 (ert-deftest test-org
/clone-with-time-shift
()
1352 "Test `org-clone-subtree-with-time-shift'."
1353 ;; Raise an error before first heading.
1355 (org-test-with-temp-text ""
1356 (org-clone-subtree-with-time-shift 1)))
1357 ;; Raise an error on invalid number of clones.
1359 (org-test-with-temp-text "* Clone me"
1360 (org-clone-subtree-with-time-shift -
1)))
1361 ;; Clone non-repeating once.
1367 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1368 (org-clone-subtree-with-time-shift 1 "+2d")
1369 (replace-regexp-in-string
1370 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1372 ;; Clone repeating once.
1377 * H1\n<2015-06-25 +1w>
1379 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1380 (org-clone-subtree-with-time-shift 1 "+2d")
1381 (replace-regexp-in-string
1382 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1384 ;; Clone non-repeating zero times.
1389 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1390 (org-clone-subtree-with-time-shift 0 "+2d")
1391 (replace-regexp-in-string
1392 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1394 ;; Clone repeating "zero" times.
1398 * H1\n<2015-06-23 +1w>
1400 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1401 (org-clone-subtree-with-time-shift 0 "+2d")
1402 (replace-regexp-in-string
1403 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1405 ;; Clone with blank SHIFT argument.
1409 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1410 (org-clone-subtree-with-time-shift 1 "")
1411 (buffer-substring-no-properties (line-beginning-position 2)
1412 (line-end-position 2)))))
1413 ;; Find time stamps before point. If SHIFT is not specified, ask
1414 ;; for a time shift.
1418 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1419 (org-clone-subtree-with-time-shift 1 "+1d")
1420 (buffer-substring-no-properties (line-beginning-position 2)
1421 (line-end-position 2)))))
1425 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1426 (cl-letf (((symbol-function 'read-from-minibuffer
)
1427 (lambda (&rest args
) "+1d")))
1428 (org-clone-subtree-with-time-shift 1))
1429 (buffer-substring-no-properties (line-beginning-position 2)
1430 (line-end-position 2))))))
1433 ;;; Fixed-Width Areas
1435 (ert-deftest test-org
/toggle-fixed-width
()
1436 "Test `org-toggle-fixed-width' specifications."
1437 ;; No region: Toggle on fixed-width marker in paragraphs.
1440 (org-test-with-temp-text "A"
1441 (org-toggle-fixed-width)
1443 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1446 (org-test-with-temp-text ": A"
1447 (org-toggle-fixed-width)
1449 ;; No region: Toggle on marker in blank lines after elements or just
1450 ;; after a headline.
1453 (org-test-with-temp-text "* H\n"
1455 (org-toggle-fixed-width)
1458 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1459 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1460 (goto-char (point-max))
1461 (org-toggle-fixed-width)
1463 ;; No region: Toggle on marker in front of one line elements (e.g.,
1464 ;; headlines, clocks)
1466 (equal ": * Headline"
1467 (org-test-with-temp-text "* Headline"
1468 (org-toggle-fixed-width)
1471 (equal ": #+KEYWORD: value"
1472 (org-test-with-temp-text "#+KEYWORD: value"
1473 (org-toggle-fixed-width)
1475 ;; No region: error in other situations.
1477 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1479 (org-toggle-fixed-width)
1481 ;; No region: Indentation is preserved.
1484 (org-test-with-temp-text "- A\n B"
1486 (org-toggle-fixed-width)
1488 ;; Region: If it contains only fixed-width elements and blank lines,
1489 ;; toggle off fixed-width markup.
1492 (org-test-with-temp-text ": A\n\n: B"
1493 (transient-mark-mode 1)
1494 (push-mark (point) t t
)
1495 (goto-char (point-max))
1496 (org-toggle-fixed-width)
1498 ;; Region: If it contains anything else, toggle on fixed-width but
1499 ;; not on fixed-width areas.
1501 (equal ": A\n: \n: B\n: \n: C"
1502 (org-test-with-temp-text "A\n\n: B\n\nC"
1503 (transient-mark-mode 1)
1504 (push-mark (point) t t
)
1505 (goto-char (point-max))
1506 (org-toggle-fixed-width)
1508 ;; Region: Ignore blank lines at its end, unless it contains only
1512 (org-test-with-temp-text "A\n\n"
1513 (transient-mark-mode 1)
1514 (push-mark (point) t t
)
1515 (goto-char (point-max))
1516 (org-toggle-fixed-width)
1520 (org-test-with-temp-text "\n\n"
1521 (transient-mark-mode 1)
1522 (push-mark (point) t t
)
1523 (goto-char (point-max))
1524 (org-toggle-fixed-width)
1531 (ert-deftest test-org
/get-heading
()
1532 "Test `org-get-heading' specifications."
1533 ;; Return current heading, even if point is not on it.
1536 (org-test-with-temp-text "* H"
1537 (org-get-heading))))
1540 (org-test-with-temp-text "* H\nText<point>"
1541 (org-get-heading))))
1542 ;; Without any optional argument, return TODO keywords and tags.
1545 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1546 (org-get-heading))))
1549 (org-test-with-temp-text "* H :tag:"
1550 (org-get-heading))))
1551 ;; With NO-TAGS argument, ignore tags.
1554 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1555 (org-get-heading t
))))
1558 (org-test-with-temp-text "* H :tag:"
1559 (org-get-heading t
))))
1560 ;; With NO-TODO, ignore TODO keyword.
1563 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1564 (org-get-heading nil t
))))
1567 (org-test-with-temp-text "* H :tag:"
1568 (org-get-heading nil t
))))
1569 ;; TODO keywords are case-sensitive.
1572 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1573 (org-get-heading nil t
))))
1574 ;; On an empty headline, return value is consistent.
1575 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1576 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1577 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1578 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1580 (ert-deftest test-org
/in-commented-heading-p
()
1581 "Test `org-in-commented-heading-p' specifications."
1582 ;; Commented headline.
1584 (org-test-with-temp-text "* COMMENT Headline\nBody"
1585 (goto-char (point-max))
1586 (org-in-commented-heading-p)))
1587 ;; Commented ancestor.
1589 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1590 (goto-char (point-max))
1591 (org-in-commented-heading-p)))
1592 ;; Comment keyword is case-sensitive.
1594 (org-test-with-temp-text "* Comment Headline\nBody"
1595 (goto-char (point-max))
1596 (org-in-commented-heading-p)))
1597 ;; Keyword is standalone.
1599 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1600 (goto-char (point-max))
1601 (org-in-commented-heading-p)))
1602 ;; Optional argument.
1604 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1605 (goto-char (point-max))
1606 (org-in-commented-heading-p t
))))
1608 (ert-deftest test-org
/entry-blocked-p
()
1609 ;; Check other dependencies.
1611 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1612 (let ((org-enforce-todo-dependencies t
)
1614 '(org-block-todo-from-children-or-siblings-or-parent)))
1615 (org-entry-blocked-p))))
1617 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1618 (let ((org-enforce-todo-dependencies t
)
1620 '(org-block-todo-from-children-or-siblings-or-parent)))
1621 (org-entry-blocked-p))))
1622 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1625 (org-test-with-temp-text "* Blocked\n** TODO one"
1626 (let ((org-enforce-todo-dependencies t
)
1628 '(org-block-todo-from-children-or-siblings-or-parent)))
1629 (org-entry-blocked-p))))
1631 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1632 (let ((org-enforce-todo-dependencies t
)
1634 '(org-block-todo-from-children-or-siblings-or-parent)))
1635 (org-entry-blocked-p))))
1636 ;; Follow :ORDERED: specifications.
1638 (org-test-with-temp-text
1639 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1640 (let ((org-enforce-todo-dependencies t
)
1642 '(org-block-todo-from-children-or-siblings-or-parent)))
1643 (org-entry-blocked-p))))
1645 (org-test-with-temp-text
1646 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1647 (let ((org-enforce-todo-dependencies t
)
1649 '(org-block-todo-from-children-or-siblings-or-parent)))
1650 (org-entry-blocked-p)))))
1652 (ert-deftest test-org
/get-outline-path
()
1653 "Test `org-get-outline-path' specifications."
1654 ;; Top-level headlines have no outline path.
1656 (org-test-with-temp-text "* H"
1657 (org-get-outline-path)))
1658 ;; Otherwise, outline path is the path leading to the headline.
1661 (org-test-with-temp-text "* H\n** S<point>"
1662 (org-get-outline-path))))
1663 ;; Find path even when point is not on a headline.
1666 (org-test-with-temp-text "* H\n** S\nText<point>"
1667 (org-get-outline-path))))
1668 ;; TODO keywords, tags and statistics cookies are ignored.
1671 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1672 (org-get-outline-path))))
1673 ;; Links are replaced with their description or their path.
1676 (org-test-with-temp-text
1677 "* [[http://orgmode.org][Org]]\n** S<point>"
1678 (org-get-outline-path))))
1680 (equal '("http://orgmode.org")
1681 (org-test-with-temp-text
1682 "* [[http://orgmode.org]]\n** S<point>"
1683 (org-get-outline-path))))
1684 ;; When WITH-SELF is non-nil, include current heading.
1687 (org-test-with-temp-text "* H"
1688 (org-get-outline-path t
))))
1691 (org-test-with-temp-text "* H\n** S\nText<point>"
1692 (org-get-outline-path t
))))
1693 ;; Using cache is transparent to the user.
1696 (org-test-with-temp-text "* H\n** S<point>"
1697 (setq org-outline-path-cache nil
)
1698 (org-get-outline-path nil t
))))
1699 ;; Do not corrupt cache when finding outline path in distant part of
1703 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1704 (setq org-outline-path-cache nil
)
1705 (org-get-outline-path nil t
)
1706 (search-forward "S2")
1707 (org-get-outline-path nil t
))))
1708 ;; Do not choke on empty headlines.
1710 (org-test-with-temp-text "* H\n** <point>"
1711 (org-get-outline-path)))
1713 (org-test-with-temp-text "* \n** H<point>"
1714 (org-get-outline-path))))
1716 (ert-deftest test-org
/format-outline-path
()
1717 "Test `org-format-outline-path' specifications."
1719 (string= (org-format-outline-path (list "one" "two" "three"))
1723 (string= (org-format-outline-path '())
1726 (string= (org-format-outline-path '(nil))
1728 ;; Empty path and prefix.
1730 (string= (org-format-outline-path '() nil
">>")
1732 ;; Trailing whitespace in headings.
1734 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1736 ;; Non-default prefix and separators.
1738 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1739 ">>|one|two|three"))
1742 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1744 ;; Give a very narrow width.
1746 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1748 ;; Give a prefix that extends beyond the width.
1750 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1754 (ert-deftest test-org
/map-entries
()
1755 "Test `org-map-entries' specifications."
1759 (org-test-with-temp-text "* Level 1\n** Level 2"
1760 (org-map-entries #'point
))))
1764 (org-test-with-temp-text "* Level 1\n** Level 2"
1765 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1768 (org-test-with-temp-text "* Level 1\n** Level 2"
1769 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1773 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1774 (org-map-entries #'point
"yes"))))
1777 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1778 (org-map-entries #'point
"+yes-a"))))
1781 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1782 (org-map-entries #'point
"{yes?}"))))
1786 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1787 (org-map-entries #'point
"PRIORITY=\"A\""))))
1791 (org-test-with-temp-text "
1793 SCHEDULED: <2012-03-29 thu.>
1795 SCHEDULED: <2014-03-04 tue.>"
1796 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1799 (org-test-with-temp-text "
1801 SCHEDULED: <2012-03-29 thu.>
1803 SCHEDULED: <2014-03-04 tue.>"
1804 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1805 ;; Regular property match.
1808 (org-test-with-temp-text "
1817 (org-map-entries #'point
"TEST=1"))))
1818 ;; Multiple criteria.
1821 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1822 (let (org-odd-levels-only
1823 (org-use-tag-inheritance nil
))
1824 (org-map-entries #'point
"yes+LEVEL=1")))))
1828 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1829 (let (org-odd-levels-only)
1830 (org-map-entries #'point
"LEVEL=2|no")))))
1833 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1834 (let (org-odd-levels-only)
1835 (org-map-entries #'point
"yes|no")))))
1839 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1840 (let (org-odd-levels-only)
1841 (org-map-entries #'point
"yes&no"))))))
1843 (ert-deftest test-org
/edit-headline
()
1844 "Test `org-edit-headline' specifications."
1847 (org-test-with-temp-text "* A"
1848 (org-edit-headline "B")
1850 ;; Handle empty headings.
1853 (org-test-with-temp-text "* A"
1854 (org-edit-headline "")
1858 (org-test-with-temp-text "* "
1859 (org-edit-headline "A")
1861 ;; Handle TODO keywords and priority cookies.
1864 (org-test-with-temp-text "* TODO A"
1865 (org-edit-headline "B")
1869 (org-test-with-temp-text "* [#A] A"
1870 (org-edit-headline "B")
1873 (equal "* TODO [#A] B"
1874 (org-test-with-temp-text "* TODO [#A] A"
1875 (org-edit-headline "B")
1879 (org-test-with-temp-text "* A :tag:"
1880 (let ((org-tags-column 4)) (org-edit-headline "B"))
1887 (ert-deftest test-org
/set-regexps-and-options
()
1888 "Test `org-set-regexps-and-options' specifications."
1892 (let ((org-tag-alist '(("A")))
1893 (org-tag-persistent-alist nil
))
1894 (org-test-with-temp-text ""
1896 org-current-tag-alist
))))
1899 (let ((org-tag-alist '(("A")))
1900 (org-tag-persistent-alist nil
))
1901 (org-test-with-temp-text "#+TAGS: B"
1903 org-current-tag-alist
))))
1905 (equal '(("C") ("B"))
1906 (let ((org-tag-alist '(("A")))
1907 (org-tag-persistent-alist '(("C"))))
1908 (org-test-with-temp-text "#+TAGS: B"
1910 org-current-tag-alist
))))
1913 (let ((org-tag-alist '(("A")))
1914 (org-tag-persistent-alist '(("C"))))
1915 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1917 org-current-tag-alist
))))
1919 (equal '(("A" . ?a
) ("B") ("C"))
1920 (let ((org-tag-persistant-alist nil
))
1921 (org-test-with-temp-text "#+TAGS: A(a) B C"
1923 org-current-tag-alist
))))
1925 (equal '(("A") (:newline
) ("B"))
1926 (let ((org-tag-persistent-alist nil
))
1927 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1929 org-current-tag-alist
))))
1931 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1932 (let ((org-tag-persistent-alist nil
))
1933 (org-test-with-temp-text "#+TAGS: { A B } C"
1935 org-current-tag-alist
))))
1937 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1938 (let ((org-tag-persistent-alist nil
))
1939 (org-test-with-temp-text "#+TAGS: { A : B C }"
1941 org-current-tag-alist
))))
1943 (equal '(("A" "B" "C"))
1944 (let ((org-tag-persistent-alist nil
))
1945 (org-test-with-temp-text "#+TAGS: { A : B C }"
1947 org-tag-groups-alist
))))
1949 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1950 (let ((org-tag-persistent-alist nil
))
1951 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1953 org-current-tag-alist
))))
1955 (equal '(("A" "B" "C"))
1956 (let ((org-tag-persistent-alist nil
))
1957 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1959 org-tag-groups-alist
))))
1960 ;; FILETAGS keyword.
1962 (equal '("A" "B" "C")
1963 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1966 ;; PROPERTY keyword. Property names are case-insensitive.
1969 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1971 (cdr (assoc "var" org-file-properties
)))))
1975 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1977 (cdr (assoc "var" org-file-properties
)))))
1981 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1983 (cdr (assoc "var" org-file-properties
)))))
1987 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1989 org-archive-location
)))
1990 ;; CATEGORY keyword.
1993 (org-test-with-temp-text "#+CATEGORY: test"
1998 (org-test-with-temp-text "#+CATEGORY: test"
2000 (cdr (assoc "CATEGORY" org-file-properties
)))))
2003 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2004 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2006 org-columns-default-format
)))
2007 ;; CONSTANTS keyword. Constants names are case sensitive.
2009 (equal '("299792458." "3.14")
2010 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2013 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2017 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2019 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2022 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2024 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2029 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2031 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2033 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2037 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2039 (list org-highest-priority org-lowest-priority org-default-priority
))))
2043 (org-test-with-temp-text "#+PRIORITIES: X Z"
2045 (list org-highest-priority org-lowest-priority org-default-priority
))))
2049 (org-test-with-temp-text "#+STARTUP: fold odd"
2051 (list org-startup-folded org-odd-levels-only
))))
2054 (equal '(("A" "B") ("C"))
2055 (org-test-with-temp-text "#+TODO: A B | C"
2057 (list org-not-done-keywords org-done-keywords
))))
2059 (equal '(("A" "C") ("B" "D"))
2060 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2062 (list org-not-done-keywords org-done-keywords
))))
2064 (equal '(("A" "B") ("C"))
2065 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2067 (list org-not-done-keywords org-done-keywords
))))
2069 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2070 (org-test-with-temp-text "#+TODO: A(a)"
2072 org-todo-key-alist
)))
2074 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2075 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2077 org-todo-log-states
)))
2078 ;; Enter SETUPFILE keyword.
2081 (org-test-with-temp-text
2082 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2084 (cdr (assoc "a" org-file-properties
))))))
2092 (ert-deftest test-org
/coderef
()
2093 "Test coderef links specifications."
2095 (org-test-with-temp-text "
2096 #+BEGIN_SRC emacs-lisp
2101 (looking-at "(ref:sc)")))
2102 ;; Find coderef even with alternate label format.
2104 (org-test-with-temp-text "
2105 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2110 (looking-at "{ref:sc}"))))
2114 (ert-deftest test-org
/custom-id
()
2115 "Test custom ID links specifications."
2117 (org-test-with-temp-text
2118 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2120 (looking-at-p "\\* H1")))
2121 ;; Throw an error on false positives.
2123 (org-test-with-temp-text
2124 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2126 (looking-at-p "\\* H1"))))
2130 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2131 ;; a named element (#+name: text) and to headlines (* Text).
2133 (ert-deftest test-org
/fuzzy-links
()
2134 "Test fuzzy links specifications."
2135 ;; Fuzzy link goes in priority to a matching target.
2137 (org-test-with-temp-text
2138 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2139 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2140 (looking-at "<<Test>>")))
2141 ;; Then fuzzy link points to an element with a given name.
2143 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2144 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2145 (looking-at "#\\+NAME: Test")))
2146 ;; A target still lead to a matching headline otherwise.
2148 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2149 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2150 (looking-at "\\* Head2")))
2151 ;; With a leading star in link, enforce heading match.
2153 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2154 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2155 (looking-at "\\* Test")))
2156 ;; With a leading star in link, enforce exact heading match, even
2157 ;; with `org-link-search-must-match-exact-headline' set to nil.
2159 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2160 (let ((org-link-search-must-match-exact-headline nil
))
2161 (org-open-at-point))))
2162 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2164 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2165 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2166 (looking-at "\\* Test")))
2168 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2169 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2170 (looking-at "\\* Test")))
2171 ;; Heading match should not care about spaces, cookies, TODO
2172 ;; keywords, priorities, and tags. However, TODO keywords are
2176 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2177 (org-test-with-temp-text
2178 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2179 (let ((org-link-search-must-match-exact-headline nil
)
2180 (org-todo-regexp "TODO"))
2181 (org-open-at-point))
2182 (looking-at (regexp-quote first-line
)))))
2184 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2185 (let ((org-link-search-must-match-exact-headline nil
)
2186 (org-todo-regexp "TODO"))
2187 (org-open-at-point))))
2188 ;; Heading match should still be exact.
2190 (org-test-with-temp-text "
2191 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2194 (let ((org-link-search-must-match-exact-headline nil
)
2195 (org-todo-regexp "TODO"))
2196 (org-open-at-point))))
2198 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2199 (let ((org-link-search-must-match-exact-headline nil
)
2200 (org-todo-regexp "TODO"))
2201 (org-open-at-point))
2202 (looking-at-p (regexp-quote "** Test 1 2"))))
2203 ;; Heading match ignores COMMENT keyword.
2205 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2207 (looking-at "\\* COMMENT Test")))
2209 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2211 (looking-at "\\* TODO COMMENT Test")))
2212 ;; Correctly un-hexify fuzzy links.
2214 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2218 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2221 ;; Match search strings containing newline characters, including
2224 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2225 (let ((file (buffer-file-name)))
2226 (goto-char (point-max))
2227 (insert (format "[[file:%s::line1 line2]]" file
))
2229 (let ((org-link-search-must-match-exact-headline nil
))
2230 (org-open-at-point 0))
2231 (looking-at-p "line1"))))
2233 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2234 (let ((file (buffer-file-name)))
2235 (goto-char (point-max))
2236 (insert (format "[[file:%s::line1 line2]]" file
))
2238 (let ((org-link-search-must-match-exact-headline nil
))
2239 (org-open-at-point 0))
2240 (looking-at-p "line1")))))
2244 (ert-deftest test-org
/org-link-escape-ascii-character
()
2245 "Escape an ascii character."
2249 (org-link-escape "["))))
2251 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2252 "Escape an ascii control character."
2256 (org-link-escape "\t"))))
2258 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2259 "Escape an unicode multibyte character."
2263 (org-link-escape "€"))))
2265 (ert-deftest test-org
/org-link-escape-custom-table
()
2266 "Escape string with custom character table."
2270 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2272 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2273 "Escape string with custom table merged with default table."
2276 "%5BF%6F%6F%3A%42ar%0A%5D"
2277 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2279 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2280 "Unescape an ascii character."
2284 (org-link-unescape "%5B"))))
2286 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2287 "Unescpae an ascii control character."
2291 (org-link-unescape "%0A"))))
2293 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2294 "Unescape unicode multibyte character."
2298 (org-link-unescape "%E2%82%AC"))))
2300 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2301 "Unescape old style percent escaped character."
2304 "à âçèéêîôùû"
2305 (decode-coding-string
2306 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2308 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2309 "Escape and unescape a URL that includes an escaped char.
2310 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2313 "http://some.host.com/form?&id=blah%2Bblah25"
2315 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2319 (ert-deftest test-org
/open-at-point-in-keyword
()
2320 "Does `org-open-at-point' open link in a keyword line?"
2322 (org-test-with-temp-text
2323 "<<top>>\n#+KEYWORD: <point>[[top]]"
2324 (org-open-at-point) t
)))
2326 (ert-deftest test-org
/open-at-point-in-property
()
2327 "Does `org-open-at-point' open link in property drawer?"
2329 (org-test-with-temp-text
2332 :URL: <point>[[*Headline]]
2334 (org-open-at-point) t
)))
2336 (ert-deftest test-org
/open-at-point-in-comment
()
2337 "Does `org-open-at-point' open link in a commented line?"
2339 (org-test-with-temp-text
2340 "<<top>>\n# <point>[[top]]"
2341 (org-open-at-point) t
)))
2343 (ert-deftest test-org
/open-at-point
/inline-image
()
2344 "Test `org-open-at-point' on nested links."
2346 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2350 (ert-deftest test-org
/open-at-point
/radio-target
()
2351 "Test `org-open-at-point' on radio targets."
2353 (org-test-with-temp-text "<<<target>>> <point>target"
2354 (org-update-radio-target-regexp)
2356 (eq (org-element-type (org-element-context)) 'radio-target
))))
2360 (ert-deftest test-org
/store-link
()
2361 "Test `org-store-link' specifications."
2362 ;; On a headline, link to that headline. Use heading as the
2363 ;; description of the link.
2365 (let (org-store-link-props org-stored-links
)
2366 (org-test-with-temp-text-in-file "* H1"
2367 (let ((file (buffer-file-name)))
2368 (equal (format "[[file:%s::*H1][H1]]" file
)
2369 (org-store-link nil
))))))
2370 ;; On a headline, remove any link from description.
2372 (let (org-store-link-props org-stored-links
)
2373 (org-test-with-temp-text-in-file "* [[#l][d]]"
2374 (let ((file (buffer-file-name)))
2375 (equal (format "[[file:%s::*%s][d]]"
2377 (org-link-escape "[[#l][d]]"))
2378 (org-store-link nil
))))))
2380 (let (org-store-link-props org-stored-links
)
2381 (org-test-with-temp-text-in-file "* [[l]]"
2382 (let ((file (buffer-file-name)))
2383 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2384 (org-store-link nil
))))))
2386 (let (org-store-link-props org-stored-links
)
2387 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2388 (let ((file (buffer-file-name)))
2389 (equal (format "[[file:%s::*%s][d1 d2]]"
2391 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2392 (org-store-link nil
))))))
2393 ;; On a named element, link to that element.
2395 (let (org-store-link-props org-stored-links
)
2396 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2397 (let ((file (buffer-file-name)))
2398 (equal (format "[[file:%s::foo][foo]]" file
)
2399 (org-store-link nil
)))))))
2404 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2405 "Ensure properties accumulate in subtree drawers."
2406 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2407 (org-babel-next-src-block)
2408 (should (equal '(2 1) (org-babel-execute-src-block)))))
2410 (ert-deftest test-org
/custom-properties
()
2411 "Test custom properties specifications."
2414 (let ((org-custom-properties '("FOO")))
2415 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2416 (org-toggle-custom-properties-visibility)
2417 (org-invisible-p2))))
2418 ;; Properties are case-insensitive.
2420 (let ((org-custom-properties '("FOO")))
2421 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2422 (org-toggle-custom-properties-visibility)
2423 (org-invisible-p2))))
2425 (let ((org-custom-properties '("foo")))
2426 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2427 (org-toggle-custom-properties-visibility)
2428 (org-invisible-p2))))
2429 ;; Multiple custom properties in the same drawer.
2431 (let ((org-custom-properties '("FOO" "BAR")))
2432 (org-test-with-temp-text
2433 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2434 (org-toggle-custom-properties-visibility)
2435 (and (org-invisible-p2)
2436 (not (progn (forward-line) (org-invisible-p2)))
2437 (progn (forward-line) (org-invisible-p2))))))
2438 ;; Hide custom properties with an empty value.
2440 (let ((org-custom-properties '("FOO")))
2441 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2442 (org-toggle-custom-properties-visibility)
2443 (org-invisible-p2))))
2444 ;; Do not hide fake properties.
2446 (let ((org-custom-properties '("FOO")))
2447 (org-test-with-temp-text ":FOO: val\n"
2448 (org-toggle-custom-properties-visibility)
2449 (org-invisible-p2))))
2451 (let ((org-custom-properties '("A")))
2452 (org-test-with-temp-text
2453 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2454 (org-toggle-custom-properties-visibility)
2455 (org-invisible-p2)))))
2461 (ert-deftest test-org
/mark-subtree
()
2462 "Test `org-mark-subtree' specifications."
2463 ;; Error when point is before first headline.
2465 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2466 (progn (transient-mark-mode 1)
2467 (org-mark-subtree))))
2468 ;; Without argument, mark current subtree.
2472 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2473 (progn (transient-mark-mode 1)
2476 (list (region-beginning) (region-end))))))
2477 ;; With an argument, move ARG up.
2481 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2482 (progn (transient-mark-mode 1)
2484 (org-mark-subtree 1)
2485 (list (region-beginning) (region-end))))))
2486 ;; Do not get fooled by inlinetasks.
2487 (when (featurep 'org-inlinetask
)
2490 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2491 (progn (transient-mark-mode 1)
2493 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2494 (region-beginning)))))))
2500 (ert-deftest test-org
/in-regexp
()
2501 "Test `org-in-regexp' specifications."
2504 (org-test-with-temp-text "xx ab<point>c xx"
2505 (org-in-regexp "abc")))
2507 (org-test-with-temp-text "xx abc <point>xx"
2508 (org-in-regexp "abc")))
2509 ;; Return non-nil even with multiple matching regexps in the same
2512 (org-test-with-temp-text "abc xx ab<point>c xx"
2513 (org-in-regexp "abc")))
2514 ;; With optional argument NLINES, check extra lines around point.
2516 (org-test-with-temp-text "A\nB<point>\nC"
2517 (org-in-regexp "A\nB\nC")))
2519 (org-test-with-temp-text "A\nB<point>\nC"
2520 (org-in-regexp "A\nB\nC" 1)))
2522 (org-test-with-temp-text "A\nB\nC<point>"
2523 (org-in-regexp "A\nB\nC" 1)))
2524 ;; When optional argument VISUALLY is non-nil, return nil if at
2525 ;; regexp boundaries.
2527 (org-test-with-temp-text "xx abc<point> xx"
2528 (org-in-regexp "abc")))
2530 (org-test-with-temp-text "xx abc<point> xx"
2531 (org-in-regexp "abc" nil t
))))
2536 (ert-deftest test-org
/end-of-meta-data
()
2537 "Test `org-end-of-meta-data' specifications."
2538 ;; Skip planning line.
2540 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2541 (org-end-of-meta-data)
2543 ;; Skip properties drawer.
2545 (org-test-with-temp-text
2546 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2547 (org-end-of-meta-data)
2551 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2552 (org-end-of-meta-data)
2554 ;; Nothing to skip, go to first line.
2556 (org-test-with-temp-text "* Headline\nContents"
2557 (org-end-of-meta-data)
2558 (looking-at "Contents")))
2559 ;; With option argument, skip empty lines, regular drawers and
2562 (org-test-with-temp-text "* Headline\n\nContents"
2563 (org-end-of-meta-data t
)
2564 (looking-at "Contents")))
2566 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2567 (org-end-of-meta-data t
)
2568 (looking-at "Contents")))
2570 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2571 (org-end-of-meta-data t
)
2572 (looking-at "Contents")))
2573 ;; Special case: do not skip incomplete drawers.
2575 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2576 (org-end-of-meta-data t
)
2577 (looking-at ":LOGBOOK:")))
2578 ;; Special case: Be careful about consecutive headlines.
2580 (org-test-with-temp-text "* H1\n*H2\nContents"
2581 (org-end-of-meta-data t
)
2582 (looking-at "Contents"))))
2584 (ert-deftest test-org
/beginning-of-line
()
2585 "Test `org-beginning-of-line' specifications."
2586 ;; Move to beginning of line. If current line in invisible, move to
2587 ;; beginning of visible line instead.
2589 (org-test-with-temp-text "Some text\nSome other text<point>"
2590 (org-beginning-of-line)
2593 (org-test-with-temp-text "* H1\n** H2<point>"
2595 (org-beginning-of-line)
2596 (= (line-beginning-position) 1)))
2597 ;; With `visual-line-mode' active, move to beginning of visual line.
2599 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2601 (dotimes (i 1000) (insert "very "))
2602 (org-beginning-of-line)
2604 ;; In a wide headline, with `visual-line-mode', prefer going to the
2605 ;; beginning of a visual line than to the logical beginning of line,
2606 ;; even if special movement is active.
2608 (org-test-with-temp-text "* A <point>long headline"
2610 (dotimes (i 1000) (insert "very "))
2611 (goto-char (point-max))
2612 (org-beginning-of-line)
2615 (org-test-with-temp-text "* A <point>long headline"
2617 (dotimes (i 1000) (insert "very "))
2618 (goto-char (point-max))
2619 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2621 ;; At an headline with special movement, first move at beginning of
2622 ;; title, then at the beginning of line, rinse, repeat.
2624 (org-test-with-temp-text "* TODO Headline<point>"
2625 (let ((org-special-ctrl-a/e t
))
2626 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2627 (progn (org-beginning-of-line) (bolp))
2628 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2630 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2631 (let ((org-special-ctrl-a/e t
))
2632 (org-beginning-of-line)
2633 (looking-at "Headline"))))
2635 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2636 (let ((org-special-ctrl-a/e
'(t . nil
)))
2637 (org-beginning-of-line)
2638 (looking-at "Headline"))))
2640 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2641 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2642 (org-beginning-of-line)
2643 (looking-at "Headline"))))
2644 ;; At an headline with reversed movement, first move to beginning of
2645 ;; line, then to the beginning of title.
2647 (org-test-with-temp-text "* TODO Headline<point>"
2648 (let ((org-special-ctrl-a/e
'reversed
)
2649 (this-command last-command
))
2650 (and (progn (org-beginning-of-line) (bolp))
2651 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2653 (org-test-with-temp-text "* TODO Headline<point>"
2654 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2655 (this-command last-command
))
2656 (and (progn (org-beginning-of-line) (bolp))
2657 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2659 (org-test-with-temp-text "* TODO Headline<point>"
2660 (let ((org-special-ctrl-a/e
'(t . nil
))
2661 (this-command last-command
))
2662 (and (progn (org-beginning-of-line) (bolp))
2663 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2664 ;; At an item with special movement, first move after to beginning
2665 ;; of title, then to the beginning of line, rinse, repeat.
2667 (org-test-with-temp-text "- [ ] Item<point>"
2668 (let ((org-special-ctrl-a/e t
))
2669 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2670 (progn (org-beginning-of-line) (bolp))
2671 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2672 ;; At an item with reversed movement, first move to beginning of
2673 ;; line, then to the beginning of title.
2675 (org-test-with-temp-text "- [X] Item<point>"
2676 (let ((org-special-ctrl-a/e
'reversed
)
2677 (this-command last-command
))
2678 (and (progn (org-beginning-of-line) (bolp))
2679 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2680 ;; Leave point before invisible characters at column 0.
2682 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2683 (let ((org-special-ctrl-a/e nil
))
2684 (org-beginning-of-line)
2687 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2688 (let ((org-special-ctrl-a/e t
))
2689 (org-beginning-of-line)
2692 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2694 (org-beginning-of-line)
2696 ;; Special case: Do not error when the buffer contains only a single
2699 (org-test-with-temp-text "*<point>"
2700 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2702 (org-test-with-temp-text "*<point>"
2703 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2705 (ert-deftest test-org
/end-of-line
()
2706 "Test `org-end-of-line' specifications."
2709 (org-test-with-temp-text "Some text\nSome other text"
2712 ;; With `visual-line-mode' active, move to end of visible line.
2713 ;; However, never go past ellipsis.
2715 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2717 (dotimes (i 1000) (insert "very "))
2718 (goto-char (point-min))
2722 (org-test-with-temp-text "* A short headline\nSome contents"
2727 ;; In a wide headline, with `visual-line-mode', prefer going to end
2728 ;; of visible line if tags, or end of line, are farther.
2730 (org-test-with-temp-text "* A <point>long headline"
2732 (dotimes (i 1000) (insert "very "))
2733 (goto-char (point-min))
2737 (org-test-with-temp-text "* A <point>long headline :tag:"
2739 (dotimes (i 1000) (insert "very "))
2740 (goto-char (point-min))
2743 ;; At an headline without special movement, go to end of line.
2744 ;; However, never go past ellipsis.
2746 (org-test-with-temp-text "* Headline2b :tag:\n"
2747 (let ((org-special-ctrl-a/e nil
))
2748 (and (progn (org-end-of-line) (eolp))
2749 (progn (org-end-of-line) (eolp))))))
2751 (org-test-with-temp-text "* Headline2b :tag:\n"
2752 (let ((org-special-ctrl-a/e
'(t . nil
)))
2753 (and (progn (org-end-of-line) (eolp))
2754 (progn (org-end-of-line) (eolp))))))
2756 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2758 (let ((org-special-ctrl-a/e nil
))
2760 (= 1 (line-beginning-position)))))
2761 ;; At an headline with special movement, first move before tags,
2762 ;; then at the end of line, rinse, repeat. However, never go past
2765 (org-test-with-temp-text "* Headline1 :tag:\n"
2766 (let ((org-special-ctrl-a/e t
))
2767 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2768 (progn (org-end-of-line) (eolp))
2769 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2771 (org-test-with-temp-text "* Headline1 :tag:\n"
2772 (let ((org-special-ctrl-a/e
'(nil . t
)))
2773 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2774 (progn (org-end-of-line) (eolp))
2775 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2777 (org-test-with-temp-text "* Headline1 :tag:\n"
2778 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2779 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2780 (progn (org-end-of-line) (eolp))
2781 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2783 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2785 (let ((org-special-ctrl-a/e t
))
2788 (= 1 (line-beginning-position)))))
2789 ;; At an headline, with reversed movement, first go to end of line,
2790 ;; then before tags. However, never go past ellipsis.
2792 (org-test-with-temp-text "* Headline3 :tag:\n"
2793 (let ((org-special-ctrl-a/e
'reversed
)
2794 (this-command last-command
))
2795 (and (progn (org-end-of-line) (eolp))
2796 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2798 (org-test-with-temp-text "* Headline3 :tag:\n"
2799 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2800 (this-command last-command
))
2801 (and (progn (org-end-of-line) (eolp))
2802 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2804 (org-test-with-temp-text "* Headline3 :tag:\n"
2805 (let ((org-special-ctrl-a/e
'(nil . t
))
2806 (this-command last-command
))
2807 (and (progn (org-end-of-line) (eolp))
2808 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2810 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2812 (let ((org-special-ctrl-a/e
'reversed
))
2814 (= 1 (line-beginning-position)))))
2815 ;; At a block without hidden contents.
2817 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2818 (progn (org-end-of-line) (eolp))))
2819 ;; At a block with hidden contents.
2821 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2822 (let ((org-special-ctrl-a/e t
))
2823 (org-hide-block-toggle)
2826 ;; Get past invisible characters at the end of line.
2828 (org-test-with-temp-text "[[http://orgmode.org]]"
2832 (ert-deftest test-org
/open-line
()
2833 "Test `org-open-line' specifications."
2834 ;; Call `open-line' outside of tables.
2837 (org-test-with-temp-text "Text"
2840 ;; At a table, create a row above.
2842 (equal "\n| |\n| a |"
2843 (org-test-with-temp-text "\n<point>| a |"
2846 ;; At the very first character of the buffer, also call `open-line'.
2849 (org-test-with-temp-text "| a |"
2852 ;; Narrowing does not count.
2854 (equal "Text\n| |\n| a |"
2855 (org-test-with-temp-text "Text\n<point>| a |"
2856 (narrow-to-region (point) (point-max))
2861 (ert-deftest test-org
/forward-sentence
()
2862 "Test `org-forward-sentence' specifications."
2863 ;; At the end of a table cell, move to the end of the next one.
2865 (org-test-with-temp-text "| a<point> | b |"
2866 (org-forward-sentence)
2867 (looking-at " |$")))
2868 ;; Elsewhere in a cell, move to its end.
2870 (org-test-with-temp-text "| a<point>c | b |"
2871 (org-forward-sentence)
2872 (looking-at " | b |$")))
2873 ;; Otherwise, simply call `forward-sentence'.
2875 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2876 (org-forward-sentence)
2877 (looking-at " Sentence 2.")))
2879 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2880 (org-forward-sentence)
2881 (org-forward-sentence)
2883 ;; At the end of an element, jump to the next one, without stopping
2884 ;; on blank lines in-between.
2886 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2887 (org-forward-sentence)
2890 (ert-deftest test-org
/backward-sentence
()
2891 "Test `org-backward-sentence' specifications."
2892 ;; At the beginning of a table cell, move to the beginning of the
2895 (org-test-with-temp-text "| a | <point>b |"
2896 (org-backward-sentence)
2897 (looking-at "a | b |$")))
2898 ;; Elsewhere in a cell, move to its beginning.
2900 (org-test-with-temp-text "| a | b<point>c |"
2901 (org-backward-sentence)
2902 (looking-at "bc |$")))
2903 ;; Otherwise, simply call `backward-sentence'.
2905 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2906 (org-backward-sentence)
2907 (looking-at "Sentence 2.")))
2909 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2910 (org-backward-sentence)
2911 (org-backward-sentence)
2913 ;; Make sure to hit the beginning of a sentence on the same line as
2916 (org-test-with-temp-text "- Line 1\n line <point>2."
2917 (org-backward-sentence)
2918 (looking-at "Line 1"))))
2920 (ert-deftest test-org
/forward-paragraph
()
2921 "Test `org-forward-paragraph' specifications."
2922 ;; At end of buffer, return an error.
2924 (org-test-with-temp-text "Paragraph"
2925 (goto-char (point-max))
2926 (org-forward-paragraph)))
2929 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2930 (org-forward-paragraph)
2934 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2935 (org-forward-paragraph)
2937 ;; Do not enter elements with invisible contents.
2939 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2940 (org-hide-block-toggle)
2941 (org-forward-paragraph)
2943 ;; On an affiliated keyword, jump to the beginning of the element.
2945 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2946 (org-forward-paragraph)
2947 (looking-at "Para")))
2948 ;; On an item or a footnote definition, move to the second element
2951 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2952 (org-forward-paragraph)
2953 (looking-at " Paragraph")))
2955 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2956 (org-forward-paragraph)
2957 (looking-at "Paragraph")))
2958 ;; On an item, or a footnote definition, when the first line is
2959 ;; empty, move to the first item.
2961 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2962 (org-forward-paragraph)
2963 (looking-at " Paragraph")))
2965 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2966 (org-forward-paragraph)
2967 (looking-at "Paragraph")))
2968 ;; On a table (resp. a property drawer) do not move through table
2969 ;; rows (resp. node properties).
2971 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2972 (org-forward-paragraph)
2973 (looking-at "Paragraph")))
2975 (org-test-with-temp-text
2976 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2977 (org-forward-paragraph)
2978 (looking-at "Paragraph")))
2979 ;; On a verse or source block, stop after blank lines.
2981 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2982 (org-forward-paragraph)
2985 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2986 (org-forward-paragraph)
2987 (looking-at "L2"))))
2989 (ert-deftest test-org
/backward-paragraph
()
2990 "Test `org-backward-paragraph' specifications."
2991 ;; Error at beginning of buffer.
2993 (org-test-with-temp-text "Paragraph"
2994 (org-backward-paragraph)))
2997 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2998 (goto-char (point-max))
2999 (org-backward-paragraph)
3002 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3003 (goto-char (point-max))
3005 (org-backward-paragraph)
3009 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3010 (goto-char (point-max))
3012 (org-backward-paragraph)
3014 ;; Ignore invisible elements.
3016 (org-test-with-temp-text "* H1\n P1\n* H2"
3018 (goto-char (point-max))
3020 (org-backward-paragraph)
3022 ;; On an affiliated keyword, jump to the first one.
3024 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3025 (search-forward "c2")
3026 (org-backward-paragraph)
3027 (looking-at "#\\+name")))
3028 ;; On the second element in an item or a footnote definition, jump
3029 ;; to item or the definition.
3031 (org-test-with-temp-text "- line1\n\n line2"
3032 (goto-char (point-max))
3034 (org-backward-paragraph)
3035 (looking-at "- line1")))
3037 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3038 (goto-char (point-max))
3040 (org-backward-paragraph)
3041 (looking-at "\\[fn:1\\] line1")))
3042 ;; On a table (resp. a property drawer), ignore table rows
3043 ;; (resp. node properties).
3045 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3046 (goto-char (point-max))
3048 (org-backward-paragraph)
3051 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3052 (org-backward-paragraph)
3053 (looking-at ":PROPERTIES:")))
3054 ;; On a source or verse block, stop before blank lines.
3056 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3057 (search-forward "L3")
3059 (org-backward-paragraph)
3062 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3063 (search-forward "L3")
3065 (org-backward-paragraph)
3066 (looking-at "L2"))))
3068 (ert-deftest test-org
/forward-element
()
3069 "Test `org-forward-element' specifications."
3070 ;; 1. At EOB: should error.
3071 (org-test-with-temp-text "Some text\n"
3072 (goto-char (point-max))
3073 (should-error (org-forward-element)))
3074 ;; 2. Standard move: expected to ignore blank lines.
3075 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3076 (org-forward-element)
3077 (should (looking-at (regexp-quote "Second paragraph."))))
3078 ;; 3. Headline tests.
3079 (org-test-with-temp-text "
3084 ;; 3.1. At an headline beginning: move to next headline at the
3087 (org-forward-element)
3088 (should (looking-at (regexp-quote "** Head 1.2")))
3089 ;; 3.2. At an headline beginning: move to parent headline if no
3090 ;; headline at the same level.
3092 (org-forward-element)
3093 (should (looking-at (regexp-quote "** Head 1.2"))))
3094 ;; 4. Greater element tests.
3095 (org-test-with-temp-text
3096 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3097 ;; 4.1. At a greater element: expected to skip contents.
3098 (org-forward-element)
3099 (should (looking-at (regexp-quote "Outside.")))
3100 ;; 4.2. At the end of greater element contents: expected to skip
3101 ;; to the end of the greater element.
3103 (org-forward-element)
3104 (should (looking-at (regexp-quote "Outside."))))
3106 (org-test-with-temp-text "
3120 ;; 5.1. At list top point: expected to move to the element after
3123 (org-forward-element)
3124 (should (looking-at (regexp-quote "Outside.")))
3125 ;; 5.2. Special case: at the first line of a sub-list, but not at
3126 ;; beginning of line, move to next item.
3129 (org-forward-element)
3130 (should (looking-at "- item2"))
3133 (org-forward-element)
3134 (should (looking-at " - sub2"))
3135 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3137 (org-forward-element)
3138 (should (looking-at (regexp-quote " Inner paragraph.")))
3139 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3141 (org-forward-element)
3142 (should (looking-at (regexp-quote " Inner paragraph.")))
3143 ;; 5.5. At an item: expected to move to next item, if any.
3145 (org-forward-element)
3146 (should (looking-at " - sub3"))))
3148 (ert-deftest test-org
/backward-element
()
3149 "Test `org-backward-element' specifications."
3150 ;; 1. Should error at BOB.
3151 (org-test-with-temp-text " \nParagraph."
3152 (should-error (org-backward-element)))
3153 ;; 2. Should move at BOB when called on the first element in buffer.
3155 (org-test-with-temp-text "\n#+TITLE: test"
3156 (progn (forward-line)
3157 (org-backward-element)
3159 ;; 3. Not at the beginning of an element: move at its beginning.
3160 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3163 (org-backward-element)
3164 (should (looking-at (regexp-quote "Paragraph2."))))
3165 ;; 4. Headline tests.
3166 (org-test-with-temp-text "
3171 ;; 4.1. At an headline beginning: move to previous headline at the
3174 (org-backward-element)
3175 (should (looking-at (regexp-quote "** Head 1.1")))
3176 ;; 4.2. At an headline beginning: move to parent headline if no
3177 ;; headline at the same level.
3179 (org-backward-element)
3180 (should (looking-at (regexp-quote "* Head 1")))
3181 ;; 4.3. At the first top-level headline: should error.
3183 (should-error (org-backward-element)))
3184 ;; 5. At beginning of first element inside a greater element:
3185 ;; expected to move to greater element's beginning.
3186 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3188 (org-backward-element)
3189 (should (looking-at "#\\+BEGIN_CENTER")))
3190 ;; 6. At the beginning of the first element in a section: should
3191 ;; move back to headline, if any.
3193 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3194 (progn (goto-char (point-max))
3196 (org-backward-element)
3197 (org-at-heading-p))))
3199 (org-test-with-temp-text "
3214 ;; 7.1. At beginning of sub-list: expected to move to the
3215 ;; paragraph before it.
3217 (org-backward-element)
3218 (should (looking-at "item1"))
3219 ;; 7.2. At an item in a list: expected to move at previous item.
3221 (org-backward-element)
3222 (should (looking-at " - sub2"))
3224 (org-backward-element)
3225 (should (looking-at "- item1"))
3226 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3229 (org-backward-element)
3230 (should (looking-at " - sub1"))
3232 (org-backward-element)
3233 (should (looking-at "- item1"))
3234 ;; 7.4. At blank-lines before list end: expected to move to top
3237 (org-backward-element)
3238 (should (looking-at "- item1"))))
3240 (ert-deftest test-org
/up-element
()
3241 "Test `org-up-element' specifications."
3242 ;; 1. At BOB or with no surrounding element: should error.
3243 (org-test-with-temp-text "Paragraph."
3244 (should-error (org-up-element)))
3245 (org-test-with-temp-text "* Head1\n* Head2"
3247 (should-error (org-up-element)))
3248 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3250 (should-error (org-up-element)))
3251 ;; 2. At an headline: move to parent headline.
3252 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3255 (should (looking-at "\\* Head1")))
3256 ;; 3. Inside a greater element: move to greater element beginning.
3257 (org-test-with-temp-text
3258 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3261 (should (looking-at "#\\+BEGIN_CENTER")))
3263 (org-test-with-temp-text "* Top
3270 Paragraph within sub2.
3273 ;; 4.1. Within an item: move to the item beginning.
3276 (should (looking-at " - sub2"))
3277 ;; 4.2. At an item in a sub-list: move to parent item.
3280 (should (looking-at "- item1"))
3281 ;; 4.3. At an item in top list: move to beginning of whole list.
3284 (should (looking-at "- item1"))
3285 ;; 4.4. Special case. At very top point: should move to parent of
3289 (should (looking-at "\\* Top"))))
3291 (ert-deftest test-org
/down-element
()
3292 "Test `org-down-element' specifications."
3293 ;; Error when the element hasn't got a recursive type.
3294 (org-test-with-temp-text "Paragraph."
3295 (should-error (org-down-element)))
3296 ;; Error when the element has no contents
3297 (org-test-with-temp-text "* Headline"
3298 (should-error (org-down-element)))
3299 ;; When at a plain-list, move to first item.
3300 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3303 (should (looking-at " - Item 1.1")))
3304 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3306 (should (looking-at " Item 1")))
3307 ;; When at a table, move to first row
3308 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3310 (should (looking-at " a | b |")))
3311 ;; Otherwise, move inside the greater element.
3312 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3314 (should (looking-at "Paragraph"))))
3316 (ert-deftest test-org
/drag-element-backward
()
3317 "Test `org-drag-element-backward' specifications."
3321 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3322 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3323 (org-drag-element-backward)
3327 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3328 (org-test-with-temp-text
3329 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3330 (org-drag-element-backward)
3332 ;; Preserve blank lines.
3334 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3335 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3336 (org-drag-element-backward)
3340 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3341 (org-drag-element-backward)
3342 (looking-at-p "2")))
3343 ;; Error when trying to move first element of buffer.
3345 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3346 (org-drag-element-backward))
3348 ;; Error when trying to swap nested elements.
3350 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3351 (org-drag-element-backward))
3353 ;; Error when trying to swap an headline element and a non-headline
3356 (org-test-with-temp-text "Test.\n<point>* Head 1"
3357 (org-drag-element-backward))
3359 ;; Error when called before first element.
3361 (org-test-with-temp-text "\n<point>"
3362 (org-drag-element-backward))
3364 ;; Preserve visibility of elements and their contents.
3366 (equal '((63 .
82) (26 .
48))
3367 (org-test-with-temp-text "
3375 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3376 (search-backward "- item 1")
3377 (org-drag-element-backward)
3378 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3379 (overlays-in (point-min) (point-max))))))
3380 ;; Pathological case: handle call with point in blank lines right
3381 ;; after a headline.
3383 (equal "* H2\n* H1\nText\n\n"
3384 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3385 (org-drag-element-backward)
3388 (ert-deftest test-org
/drag-element-forward
()
3389 "Test `org-drag-element-forward' specifications."
3390 ;; 1. Error when trying to move first element of buffer.
3391 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3393 (should-error (org-drag-element-forward)))
3394 ;; 2. Error when trying to swap nested elements.
3395 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3397 (should-error (org-drag-element-forward)))
3398 ;; 3. Error when trying to swap a non-headline element and an
3400 (org-test-with-temp-text "Test.\n* Head 1"
3401 (should-error (org-drag-element-forward)))
3402 ;; 4. Error when called before first element.
3404 (org-test-with-temp-text "\n"
3406 (org-drag-element-backward))
3408 ;; 5. Otherwise, swap elements, preserving column and blank lines
3409 ;; between elements.
3410 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3411 (search-forward "graph")
3412 (org-drag-element-forward)
3413 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3414 (should (looking-at " 1")))
3415 ;; 5. Preserve visibility of elements and their contents.
3416 (org-test-with-temp-text "
3424 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3425 (search-backward "#+BEGIN_CENTER")
3426 (org-drag-element-forward)
3429 '((63 .
82) (26 .
48))
3430 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3431 (overlays-in (point-min) (point-max)))))))
3433 (ert-deftest test-org
/next-block
()
3434 "Test `org-next-block' specifications."
3437 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3439 (looking-at "#\\+BEGIN_CENTER")))
3442 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3443 (let ((case-fold-search nil
))
3445 (looking-at "#\\+begin_center"))))
3446 ;; Ignore current line.
3448 (org-test-with-temp-text
3449 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3451 (looking-at "#\\+BEGIN_CENTER")))
3452 ;; Throw an error when no block is found.
3454 (org-test-with-temp-text "Paragraph"
3455 (org-next-block 1)))
3456 ;; With an argument, skip many blocks at once.
3458 (org-test-with-temp-text
3459 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3461 (looking-at "#\\+BEGIN_QUOTE")))
3462 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3464 (org-test-with-temp-text
3465 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3466 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3467 (looking-at "#\\+BEGIN_QUOTE")))
3468 ;; Optional argument is also case-insensitive.
3470 (org-test-with-temp-text
3471 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3472 (let ((case-fold-search nil
))
3473 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3474 (looking-at "#\\+begin_quote")))))
3476 (ert-deftest test-org
/previous-block
()
3477 "Test `org-previous-block' specifications."
3480 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3481 (org-previous-block 1)
3482 (looking-at "#\\+BEGIN_CENTER")))
3485 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3486 (let ((case-fold-search nil
))
3487 (org-previous-block 1)
3488 (looking-at "#\\+begin_center"))))
3489 ;; Ignore current line.
3491 (org-test-with-temp-text
3492 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3493 (org-previous-block 1)
3494 (looking-at "#\\+BEGIN_QUOTE")))
3495 ;; Throw an error when no block is found.
3497 (org-test-with-temp-text "Paragraph<point>"
3498 (org-previous-block 1)))
3499 ;; With an argument, skip many blocks at once.
3501 (org-test-with-temp-text
3502 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3503 (org-previous-block 2)
3504 (looking-at "#\\+BEGIN_CENTER")))
3505 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3507 (org-test-with-temp-text
3508 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3509 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3510 (looking-at "#\\+BEGIN_QUOTE")))
3511 ;; Optional argument is also case-insensitive.
3513 (org-test-with-temp-text
3514 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3515 (let ((case-fold-search nil
))
3516 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3517 (looking-at "#\\+begin_quote")))))
3520 ;;; Outline structure
3522 (ert-deftest test-org
/demote
()
3523 "Test `org-demote' specifications."
3524 ;; Add correct number of stars according to `org-odd-levels-only'.
3527 (org-test-with-temp-text "* H"
3528 (let ((org-odd-levels-only nil
)) (org-demote))
3529 (org-current-level))))
3532 (org-test-with-temp-text "* H"
3533 (let ((org-odd-levels-only t
)) (org-demote))
3534 (org-current-level))))
3535 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3537 (org-test-with-temp-text "* H :tag:"
3538 (let ((org-tags-column 10)
3539 (org-auto-align-tags t
)
3540 (org-odd-levels-only nil
))
3542 (org-move-to-column 10)
3543 (looking-at-p ":tag:$")))
3545 (org-test-with-temp-text "* H :tag:"
3546 (let ((org-tags-column 10)
3547 (org-auto-align-tags nil
)
3548 (org-odd-levels-only nil
))
3550 (org-move-to-column 10)
3551 (looking-at-p ":tag:$")))
3552 ;; When `org-adapt-indentation' is non-nil, always indent planning
3553 ;; info and property drawers accordingly.
3556 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3557 (let ((org-odd-levels-only nil
)
3558 (org-adapt-indentation t
))
3561 (org-get-indentation))))
3564 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3565 (let ((org-odd-levels-only nil
)
3566 (org-adapt-indentation t
))
3569 (org-get-indentation))))
3572 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3573 (let ((org-odd-levels-only nil
)
3574 (org-adapt-indentation nil
))
3577 (org-get-indentation))))
3578 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3579 ;; section accordingly. Ignore, however, footnote definitions and
3580 ;; inlinetasks boundaries.
3583 (org-test-with-temp-text "* H\n Paragraph"
3584 (let ((org-odd-levels-only nil
)
3585 (org-adapt-indentation t
))
3588 (org-get-indentation))))
3591 (org-test-with-temp-text "* H\n Paragraph"
3592 (let ((org-odd-levels-only nil
)
3593 (org-adapt-indentation nil
))
3596 (org-get-indentation))))
3599 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3600 (let ((org-odd-levels-only nil
)
3601 (org-adapt-indentation t
))
3603 (goto-char (point-max))
3604 (org-get-indentation))))
3607 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3608 (let ((org-odd-levels-only nil
)
3609 (org-adapt-indentation t
))
3611 (goto-char (point-max))
3612 (org-get-indentation))))
3613 (when (featurep 'org-inlinetask
)
3616 (let ((org-inlinetask-min-level 5)
3617 (org-adapt-indentation t
))
3618 (org-test-with-temp-text "* H\n***** I\n***** END"
3621 (org-get-indentation))))))
3622 (when (featurep 'org-inlinetask
)
3625 (let ((org-inlinetask-min-level 5)
3626 (org-adapt-indentation t
))
3627 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3630 (org-get-indentation))))))
3631 ;; Ignore contents of source blocks or example blocks when
3632 ;; indentation should be preserved (through
3633 ;; `org-src-preserve-indentation' or "-i" flag).
3636 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3637 (let ((org-adapt-indentation t
)
3638 (org-src-preserve-indentation nil
))
3641 (org-get-indentation))))
3644 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3645 (let ((org-adapt-indentation t
)
3646 (org-src-preserve-indentation t
))
3649 (org-get-indentation))))
3652 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3653 (let ((org-adapt-indentation t
)
3654 (org-src-preserve-indentation t
))
3657 (org-get-indentation))))
3660 (org-test-with-temp-text
3661 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3662 (let ((org-adapt-indentation t
)
3663 (org-src-preserve-indentation nil
))
3666 (org-get-indentation)))))
3668 (ert-deftest test-org
/promote
()
3669 "Test `org-promote' specifications."
3670 ;; Return an error if headline is to be promoted to level 0, unless
3671 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3672 ;; headline becomes a comment.
3674 (org-test-with-temp-text "* H"
3675 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3678 (org-test-with-temp-text "* H"
3679 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3681 ;; Remove correct number of stars according to
3682 ;; `org-odd-levels-only'.
3685 (org-test-with-temp-text "*** H"
3686 (let ((org-odd-levels-only nil
)) (org-promote))
3687 (org-current-level))))
3690 (org-test-with-temp-text "*** H"
3691 (let ((org-odd-levels-only t
)) (org-promote))
3692 (org-current-level))))
3693 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3695 (org-test-with-temp-text "** H :tag:"
3696 (let ((org-tags-column 10)
3697 (org-auto-align-tags t
)
3698 (org-odd-levels-only nil
))
3700 (org-move-to-column 10)
3701 (looking-at-p ":tag:$")))
3703 (org-test-with-temp-text "** H :tag:"
3704 (let ((org-tags-column 10)
3705 (org-auto-align-tags nil
)
3706 (org-odd-levels-only nil
))
3708 (org-move-to-column 10)
3709 (looking-at-p ":tag:$")))
3710 ;; When `org-adapt-indentation' is non-nil, always indent planning
3711 ;; info and property drawers.
3714 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3715 (let ((org-odd-levels-only nil
)
3716 (org-adapt-indentation t
))
3719 (org-get-indentation))))
3722 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3723 (let ((org-odd-levels-only nil
)
3724 (org-adapt-indentation t
))
3727 (org-get-indentation))))
3730 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3731 (let ((org-odd-levels-only nil
)
3732 (org-adapt-indentation nil
))
3735 (org-get-indentation))))
3736 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3737 ;; section accordingly. Ignore, however, footnote definitions and
3738 ;; inlinetasks boundaries.
3741 (org-test-with-temp-text "** H\n Paragraph"
3742 (let ((org-odd-levels-only nil
)
3743 (org-adapt-indentation t
))
3746 (org-get-indentation))))
3749 (org-test-with-temp-text "** H\n Paragraph"
3750 (let ((org-odd-levels-only nil
)
3751 (org-adapt-indentation nil
))
3754 (org-get-indentation))))
3757 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3758 (let ((org-odd-levels-only nil
)
3759 (org-adapt-indentation t
))
3762 (org-get-indentation))))
3763 (when (featurep 'org-inlinetask
)
3766 (let ((org-inlinetask-min-level 5)
3767 (org-adapt-indentation t
))
3768 (org-test-with-temp-text "** H\n***** I\n***** END"
3771 (org-get-indentation))))))
3772 (when (featurep 'org-inlinetask
)
3775 (let ((org-inlinetask-min-level 5)
3776 (org-adapt-indentation t
))
3777 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3780 (org-get-indentation))))))
3781 ;; Give up shifting if it would break document's structure
3785 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3786 (let ((org-odd-levels-only nil
)
3787 (org-adapt-indentation t
))
3790 (org-get-indentation))))
3793 (org-test-with-temp-text "** H\n Paragraph\n * list."
3794 (let ((org-odd-levels-only nil
)
3795 (org-adapt-indentation t
))
3798 (org-get-indentation))))
3799 ;; Ignore contents of source blocks or example blocks when
3800 ;; indentation should be preserved (through
3801 ;; `org-src-preserve-indentation' or "-i" flag).
3804 (org-test-with-temp-text
3805 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3806 (let ((org-adapt-indentation t
)
3807 (org-src-preserve-indentation nil
)
3808 (org-odd-levels-only nil
))
3811 (org-get-indentation))))
3814 (org-test-with-temp-text
3815 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3816 (let ((org-adapt-indentation t
)
3817 (org-src-preserve-indentation t
)
3818 (org-odd-levels-only nil
))
3821 (org-get-indentation))))
3824 (org-test-with-temp-text
3825 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3826 (let ((org-adapt-indentation t
)
3827 (org-src-preserve-indentation t
)
3828 (org-odd-levels-only nil
))
3831 (org-get-indentation))))
3834 (org-test-with-temp-text
3835 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3836 (let ((org-adapt-indentation t
)
3837 (org-src-preserve-indentation nil
)
3838 (org-odd-levels-only nil
))
3841 (org-get-indentation)))))
3846 (ert-deftest test-org
/at-planning-p
()
3847 "Test `org-at-planning-p' specifications."
3850 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3851 (org-at-planning-p)))
3853 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3854 (org-at-planning-p)))
3855 ;; Correctly find planning attached to inlinetasks.
3856 (when (featurep 'org-inlinetask
)
3858 (org-test-with-temp-text
3859 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3860 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3862 (org-test-with-temp-text
3863 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3864 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3866 (org-test-with-temp-text
3867 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3868 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3870 (org-test-with-temp-text
3871 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3872 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3874 (ert-deftest test-org
/add-planning-info
()
3875 "Test `org-add-planning-info'."
3876 ;; Create deadline when `org-adapt-indentation' is non-nil.
3878 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3879 (org-test-with-temp-text "* H\nParagraph<point>"
3880 (let ((org-adapt-indentation t
))
3881 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3882 (replace-regexp-in-string
3883 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3885 ;; Create deadline when `org-adapt-indentation' is nil.
3887 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3888 (org-test-with-temp-text "* H\nParagraph<point>"
3889 (let ((org-adapt-indentation nil
))
3890 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3891 (replace-regexp-in-string
3892 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3894 ;; Update deadline when `org-adapt-indentation' is non-nil.
3896 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3897 (org-test-with-temp-text "\
3899 DEADLINE: <2015-06-24 Wed>
3901 (let ((org-adapt-indentation t
))
3902 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3903 (replace-regexp-in-string
3904 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3906 ;; Update deadline when `org-adapt-indentation' is nil.
3908 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3909 (org-test-with-temp-text "\
3911 DEADLINE: <2015-06-24 Wed>
3913 (let ((org-adapt-indentation nil
))
3914 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3915 (replace-regexp-in-string
3916 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3918 ;; Schedule when `org-adapt-indentation' is non-nil.
3920 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3921 (org-test-with-temp-text "* H\nParagraph<point>"
3922 (let ((org-adapt-indentation t
))
3923 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3924 (replace-regexp-in-string
3925 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3927 ;; Schedule when `org-adapt-indentation' is nil.
3929 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3930 (org-test-with-temp-text "* H\nParagraph<point>"
3931 (let ((org-adapt-indentation nil
))
3932 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3933 (replace-regexp-in-string
3934 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3936 ;; Add deadline when scheduled.
3940 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3942 (org-test-with-temp-text "\
3944 SCHEDULED: <2015-06-24 Wed>
3946 (let ((org-adapt-indentation t
))
3947 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3948 (replace-regexp-in-string
3949 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3951 ;; Remove middle entry.
3955 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3957 (org-test-with-temp-text "\
3959 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3961 (let ((org-adapt-indentation t
))
3962 (org-add-planning-info nil nil
'deadline
))
3963 (replace-regexp-in-string
3964 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3966 ;; Remove last entry and then middle entry (order should not
3971 CLOSED: [2015-06-24]
3973 (org-test-with-temp-text "\
3975 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3977 (let ((org-adapt-indentation t
))
3978 (org-add-planning-info nil nil
'scheduled
'deadline
))
3979 (replace-regexp-in-string
3980 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3982 ;; Remove closed when `org-adapt-indentation' is non-nil.
3984 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3985 (org-test-with-temp-text "\
3987 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3989 (let ((org-adapt-indentation t
))
3990 (org-add-planning-info nil nil
'closed
))
3991 (replace-regexp-in-string
3992 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3995 (equal "* H\n Paragraph"
3996 (org-test-with-temp-text "\
3998 CLOSED: [2015-06-25 Thu]
4000 (let ((org-adapt-indentation t
))
4001 (org-add-planning-info nil nil
'closed
))
4002 (replace-regexp-in-string
4003 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4005 ;; Remove closed when `org-adapt-indentation' is nil.
4007 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4008 (org-test-with-temp-text "\
4010 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4012 (let ((org-adapt-indentation nil
))
4013 (org-add-planning-info nil nil
'closed
))
4014 (replace-regexp-in-string
4015 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4018 (equal "* H\nParagraph"
4019 (org-test-with-temp-text "\
4021 CLOSED: [2015-06-25 Thu]
4023 (let ((org-adapt-indentation nil
))
4024 (org-add-planning-info nil nil
'closed
))
4025 (replace-regexp-in-string
4026 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4028 ;; Remove closed entry and delete empty line.
4033 (org-test-with-temp-text "\
4035 CLOSED: [2015-06-24 Wed]
4037 (let ((org-adapt-indentation t
))
4038 (org-add-planning-info nil nil
'closed
))
4039 (replace-regexp-in-string
4040 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4042 ;; Remove one entry and update another.
4044 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4045 (org-test-with-temp-text "\
4047 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4049 (let ((org-adapt-indentation t
))
4050 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4051 (replace-regexp-in-string
4052 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4055 (ert-deftest test-org
/deadline
()
4056 "Test `org-deadline' specifications."
4057 ;; Insert a new value or replace existing one.
4059 (equal "* H\nDEADLINE: <2012-03-29>\n"
4060 (org-test-with-temp-text "* H"
4061 (let ((org-adapt-indentation nil
)
4062 (org-last-inserted-timestamp nil
))
4063 (org-deadline nil
"<2012-03-29 Tue>"))
4064 (replace-regexp-in-string
4065 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4068 (equal "* H\nDEADLINE: <2014-03-04>"
4069 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4070 (let ((org-adapt-indentation nil
)
4071 (org-last-inserted-timestamp nil
))
4072 (org-deadline nil
"<2014-03-04 Thu>"))
4073 (replace-regexp-in-string
4074 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4076 ;; Accept delta time, e.g., "+2d".
4078 (equal "* H\nDEADLINE: <2015-03-04>\n"
4079 (cl-letf (((symbol-function 'current-time
)
4080 (lambda (&rest args
)
4081 (apply #'encode-time
4082 (org-parse-time-string "2014-03-04")))))
4083 (org-test-with-temp-text "* H"
4084 (let ((org-adapt-indentation nil
)
4085 (org-last-inserted-timestamp nil
))
4086 (org-deadline nil
"+1y"))
4087 (replace-regexp-in-string
4088 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4089 ;; Preserve repeater.
4091 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4092 (org-test-with-temp-text "* H"
4093 (let ((org-adapt-indentation nil
)
4094 (org-last-inserted-timestamp nil
))
4095 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4096 (replace-regexp-in-string
4097 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4098 ;; Remove CLOSED keyword, if any.
4100 (equal "* H\nDEADLINE: <2012-03-29>"
4101 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4102 (let ((org-adapt-indentation nil
)
4103 (org-last-inserted-timestamp nil
))
4104 (org-deadline nil
"<2012-03-29 Tue>"))
4105 (replace-regexp-in-string
4106 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4107 ;; With C-u argument, remove DEADLINE keyword.
4110 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4111 (let ((org-adapt-indentation nil
)
4112 (org-last-inserted-timestamp nil
))
4113 (org-deadline '(4)))
4117 (org-test-with-temp-text "* H"
4118 (let ((org-adapt-indentation nil
)
4119 (org-last-inserted-timestamp nil
))
4120 (org-deadline '(4)))
4122 ;; With C-u C-u argument, prompt for a delay cookie.
4124 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4125 (cl-letf (((symbol-function 'org-read-date
)
4126 (lambda (&rest args
)
4127 (apply #'encode-time
4128 (org-parse-time-string "2014-03-04")))))
4129 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4130 (let ((org-adapt-indentation nil
)
4131 (org-last-inserted-timestamp nil
))
4132 (org-deadline '(16)))
4135 (cl-letf (((symbol-function 'org-read-date
)
4136 (lambda (&rest args
)
4137 (apply #'encode-time
4138 (org-parse-time-string "2014-03-04")))))
4139 (org-test-with-temp-text "* H"
4140 (let ((org-adapt-indentation nil
)
4141 (org-last-inserted-timestamp nil
))
4142 (org-deadline '(16)))
4144 ;; When a region is active and
4145 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4146 ;; same value in all headlines in region.
4148 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4149 (org-test-with-temp-text "* H1\n* H2"
4150 (let ((org-adapt-indentation nil
)
4151 (org-last-inserted-timestamp nil
)
4152 (org-loop-over-headlines-in-active-region t
))
4153 (transient-mark-mode 1)
4154 (push-mark (point) t t
)
4155 (goto-char (point-max))
4156 (org-deadline nil
"2012-03-29"))
4157 (replace-regexp-in-string
4158 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4160 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4161 (org-test-with-temp-text "* H1\n* H2"
4162 (let ((org-adapt-indentation nil
)
4163 (org-last-inserted-timestamp nil
)
4164 (org-loop-over-headlines-in-active-region nil
))
4165 (transient-mark-mode 1)
4166 (push-mark (point) t t
)
4167 (goto-char (point-max))
4168 (org-deadline nil
"2012-03-29"))
4169 (replace-regexp-in-string
4170 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4172 (ert-deftest test-org
/schedule
()
4173 "Test `org-schedule' specifications."
4174 ;; Insert a new value or replace existing one.
4176 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4177 (org-test-with-temp-text "* H"
4178 (let ((org-adapt-indentation nil
)
4179 (org-last-inserted-timestamp nil
))
4180 (org-schedule nil
"<2012-03-29 Tue>"))
4181 (replace-regexp-in-string
4182 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4185 (equal "* H\nSCHEDULED: <2014-03-04>"
4186 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4187 (let ((org-adapt-indentation nil
)
4188 (org-last-inserted-timestamp nil
))
4189 (org-schedule nil
"<2014-03-04 Thu>"))
4190 (replace-regexp-in-string
4191 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4193 ;; Accept delta time, e.g., "+2d".
4195 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4196 (cl-letf (((symbol-function 'current-time
)
4197 (lambda (&rest args
)
4198 (apply #'encode-time
4199 (org-parse-time-string "2014-03-04")))))
4200 (org-test-with-temp-text "* H"
4201 (let ((org-adapt-indentation nil
)
4202 (org-last-inserted-timestamp nil
))
4203 (org-schedule nil
"+1y"))
4204 (replace-regexp-in-string
4205 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4206 ;; Preserve repeater.
4208 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4209 (org-test-with-temp-text "* H"
4210 (let ((org-adapt-indentation nil
)
4211 (org-last-inserted-timestamp nil
))
4212 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4213 (replace-regexp-in-string
4214 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4215 ;; Remove CLOSED keyword, if any.
4217 (equal "* H\nSCHEDULED: <2012-03-29>"
4218 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4219 (let ((org-adapt-indentation nil
)
4220 (org-last-inserted-timestamp nil
))
4221 (org-schedule nil
"<2012-03-29 Tue>"))
4222 (replace-regexp-in-string
4223 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4224 ;; With C-u argument, remove SCHEDULED keyword.
4227 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4228 (let ((org-adapt-indentation nil
)
4229 (org-last-inserted-timestamp nil
))
4230 (org-schedule '(4)))
4234 (org-test-with-temp-text "* H"
4235 (let ((org-adapt-indentation nil
)
4236 (org-last-inserted-timestamp nil
))
4237 (org-schedule '(4)))
4239 ;; With C-u C-u argument, prompt for a delay cookie.
4241 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4242 (cl-letf (((symbol-function 'org-read-date
)
4243 (lambda (&rest args
)
4244 (apply #'encode-time
4245 (org-parse-time-string "2014-03-04")))))
4246 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4247 (let ((org-adapt-indentation nil
)
4248 (org-last-inserted-timestamp nil
))
4249 (org-schedule '(16)))
4252 (cl-letf (((symbol-function 'org-read-date
)
4253 (lambda (&rest args
)
4254 (apply #'encode-time
4255 (org-parse-time-string "2014-03-04")))))
4256 (org-test-with-temp-text "* H"
4257 (let ((org-adapt-indentation nil
)
4258 (org-last-inserted-timestamp nil
))
4259 (org-schedule '(16)))
4261 ;; When a region is active and
4262 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4263 ;; same value in all headlines in region.
4265 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4266 (org-test-with-temp-text "* H1\n* H2"
4267 (let ((org-adapt-indentation nil
)
4268 (org-last-inserted-timestamp nil
)
4269 (org-loop-over-headlines-in-active-region t
))
4270 (transient-mark-mode 1)
4271 (push-mark (point) t t
)
4272 (goto-char (point-max))
4273 (org-schedule nil
"2012-03-29"))
4274 (replace-regexp-in-string
4275 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4277 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4278 (org-test-with-temp-text "* H1\n* H2"
4279 (let ((org-adapt-indentation nil
)
4280 (org-last-inserted-timestamp nil
)
4281 (org-loop-over-headlines-in-active-region nil
))
4282 (transient-mark-mode 1)
4283 (push-mark (point) t t
)
4284 (goto-char (point-max))
4285 (org-schedule nil
"2012-03-29"))
4286 (replace-regexp-in-string
4287 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4289 ;; check if a repeater survives re-scheduling.
4291 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4292 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4293 (let ((org-adapt-indentation nil
)
4294 (org-last-inserted-timestamp nil
))
4295 (org-schedule nil
"2017-02-01"))
4301 (ert-deftest test-org
/buffer-property-keys
()
4302 "Test `org-buffer-property-keys' specifications."
4303 ;; Retrieve properties accross siblings.
4306 (org-test-with-temp-text "
4315 (org-buffer-property-keys))))
4316 ;; Retrieve properties accross children.
4319 (org-test-with-temp-text "
4328 (org-buffer-property-keys))))
4329 ;; Retrieve muliple properties in the same drawer.
4332 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4333 (org-buffer-property-keys))))
4334 ;; Ignore extension symbol in property name.
4337 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4338 (org-buffer-property-keys))))
4339 ;; With non-nil COLUMNS, extract property names from columns.
4342 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4343 (org-buffer-property-keys nil nil t
))))
4345 (equal '("A" "B" "COLUMNS")
4346 (org-test-with-temp-text
4347 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4348 (org-buffer-property-keys nil nil t
))))
4349 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4352 (org-test-with-temp-text
4353 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4354 (org-buffer-property-keys nil nil nil t
)))))
4356 (ert-deftest test-org
/property-values
()
4357 "Test `org-property-values' specifications."
4361 (org-test-with-temp-text
4362 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4363 (org-property-values "A"))))
4364 ;; Ignore empty values.
4366 (org-test-with-temp-text
4367 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4368 (org-property-values "A")))
4369 ;; Take into consideration extended values.
4372 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4373 (org-property-values "A")))))
4375 (ert-deftest test-org
/find-property
()
4376 "Test `org-find-property' specifications."
4380 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4381 (org-find-property "prop"))))
4382 ;; Ignore false positives.
4385 (org-test-with-temp-text
4386 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4387 (org-find-property "A"))))
4388 ;; Return first entry found in buffer.
4391 (org-test-with-temp-text
4392 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4393 (org-find-property "A"))))
4394 ;; Only search visible part of the buffer.
4397 (org-test-with-temp-text
4398 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4399 (org-narrow-to-subtree)
4400 (org-find-property "A"))))
4401 ;; With optional argument, only find entries with a specific value.
4403 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4404 (org-find-property "A" "2")))
4407 (org-test-with-temp-text
4408 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4409 (org-find-property "A" "2"))))
4410 ;; Use "nil" for explicit nil values.
4413 (org-test-with-temp-text
4414 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4415 (org-find-property "A" "nil")))))
4417 (ert-deftest test-org
/entry-delete
()
4418 "Test `org-entry-delete' specifications."
4422 " *:PROPERTIES:\n *:B: +2\n *:END:"
4423 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4424 (org-entry-delete (point) "A")
4426 ;; Also remove accumulated properties.
4430 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4431 (org-entry-delete (point) "A")
4433 ;; When last property is removed, remove the property drawer.
4437 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4438 (org-entry-delete (point) "A")
4440 ;; Return a non-nil value when some property was removed.
4442 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4443 (org-entry-delete (point) "A")))
4445 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4446 (org-entry-delete (point) "C")))
4447 ;; Special properties cannot be located in a drawer. Allow to
4448 ;; remove them anyway, in case of user error.
4450 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4451 (org-entry-delete (point) "SCHEDULED"))))
4453 (ert-deftest test-org
/entry-get
()
4454 "Test `org-entry-get' specifications."
4458 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4459 (org-entry-get (point) "A"))))
4463 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4464 (org-entry-get (point) "a"))))
4465 ;; Handle extended values, both before and after base value.
4468 (org-test-with-temp-text
4469 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4470 (org-entry-get (point) "A"))))
4471 ;; Empty values are returned as the empty string.
4474 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4475 (org-entry-get (point) "A"))))
4476 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4477 ;; otherwise, return nil.
4479 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4480 (org-entry-get (point) "A")))
4483 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4484 (org-entry-get (point) "A" nil t
))))
4485 ;; Return nil when no property is found, independently on the
4486 ;; LITERAL-NIL argument.
4488 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4489 (org-entry-get (point) "B")))
4491 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4492 (org-entry-get (point) "B" nil t
)))
4493 ;; Handle inheritance, when allowed. Include extended values and
4494 ;; possibly global values.
4498 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4499 (org-entry-get (point) "A" t
))))
4503 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4504 (let ((org-use-property-inheritance t
))
4505 (org-entry-get (point) "A" 'selective
)))))
4507 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4508 (let ((org-use-property-inheritance nil
))
4509 (org-entry-get (point) "A" 'selective
))))
4513 (org-test-with-temp-text
4514 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4515 (org-entry-get (point-max) "A" t
))))
4518 (org-test-with-temp-text
4519 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4521 (org-entry-get (point-max) "A" t
))))
4524 (org-test-with-temp-text
4525 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4527 (org-entry-get (point-max) "A" t
)))))
4529 (ert-deftest test-org
/entry-properties
()
4530 "Test `org-entry-properties' specifications."
4531 ;; Get "ITEM" property.
4534 (org-test-with-temp-text "* TODO H"
4535 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4538 (org-test-with-temp-text "* TODO H"
4539 (cdr (assoc "ITEM" (org-entry-properties))))))
4540 ;; Get "TODO" property. TODO keywords are case sensitive.
4543 (org-test-with-temp-text "* TODO H"
4544 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4547 (org-test-with-temp-text "* TODO H"
4548 (cdr (assoc "TODO" (org-entry-properties))))))
4550 (org-test-with-temp-text "* H"
4551 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4553 (org-test-with-temp-text "* todo H"
4554 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4555 ;; Get "PRIORITY" property.
4558 (org-test-with-temp-text "* [#A] H"
4559 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4562 (org-test-with-temp-text "* [#A] H"
4563 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4565 (equal (char-to-string org-default-priority
)
4566 (org-test-with-temp-text "* H"
4567 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4568 ;; Get "FILE" property.
4570 (org-test-with-temp-text-in-file "* H\nParagraph"
4571 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4572 (buffer-file-name))))
4574 (org-test-with-temp-text-in-file "* H\nParagraph"
4575 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4576 (buffer-file-name))))
4578 (org-test-with-temp-text "* H\nParagraph"
4579 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4580 ;; Get "TAGS" property.
4582 (equal ":tag1:tag2:"
4583 (org-test-with-temp-text "* H :tag1:tag2:"
4584 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4586 (equal ":tag1:tag2:"
4587 (org-test-with-temp-text "* H :tag1:tag2:"
4588 (cdr (assoc "TAGS" (org-entry-properties))))))
4590 (org-test-with-temp-text "* H"
4591 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4592 ;; Get "ALLTAGS" property.
4594 (equal ":tag1:tag2:"
4595 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4596 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4598 (equal ":tag1:tag2:"
4599 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4600 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4602 (org-test-with-temp-text "* H"
4603 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4604 ;; Get "BLOCKED" property.
4607 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4608 (let ((org-enforce-todo-dependencies t
)
4610 '(org-block-todo-from-children-or-siblings-or-parent)))
4611 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4614 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4615 (let ((org-enforce-todo-dependencies t
)
4617 '(org-block-todo-from-children-or-siblings-or-parent)))
4618 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4619 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4623 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4624 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4628 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4629 (cdr (assoc "CLOSED" (org-entry-properties))))))
4631 (org-test-with-temp-text "* H"
4632 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4636 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4637 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4641 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4642 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4644 (org-test-with-temp-text "* H"
4645 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4649 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4650 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4654 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4655 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4657 (org-test-with-temp-text "* H"
4658 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4662 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4663 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4666 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4667 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4670 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4671 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4674 (org-test-with-temp-text
4675 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4677 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4678 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4679 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4681 (equal "<2012-03-29 thu.>"
4682 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4683 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4685 (equal "[2012-03-29 thu.]"
4686 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4687 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4689 (equal "<2012-03-29 thu.>"
4690 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4691 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4693 (equal "[2014-03-04 tue.]"
4694 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4695 (cdr (assoc "TIMESTAMP_IA"
4696 (org-entry-properties nil
"TIMESTAMP_IA"))))))
4698 (equal "<2012-03-29 thu.>"
4699 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4700 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4701 ;; Get standard properties.
4704 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4705 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4706 ;; Handle extended properties.
4709 (org-test-with-temp-text
4710 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4711 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4714 (org-test-with-temp-text
4715 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4716 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4717 ;; Ignore forbidden (special) properties.
4719 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4720 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4722 (ert-deftest test-org
/entry-put
()
4723 "Test `org-entry-put' specifications."
4724 ;; Error when not a string or nil.
4726 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4727 (org-entry-put 1 "test" 2)))
4728 ;; Error when property name is invalid.
4730 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4731 (org-entry-put 1 "no space" "value")))
4733 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4734 (org-entry-put 1 "" "value")))
4735 ;; Set "TODO" property.
4737 (string-match (regexp-quote " TODO H")
4738 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4739 (org-entry-put (point) "TODO" "TODO")
4742 (string-match (regexp-quote "* H")
4743 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4744 (org-entry-put (point) "TODO" nil
)
4746 ;; Set "PRIORITY" property.
4749 (org-test-with-temp-text "* [#B] H"
4750 (org-entry-put (point) "PRIORITY" "A")
4754 (org-test-with-temp-text "* [#B] H"
4755 (org-entry-put (point) "PRIORITY" nil
)
4757 ;; Set "SCHEDULED" property.
4759 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4760 (org-test-with-temp-text "* H"
4761 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4765 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4766 (org-entry-put (point) "SCHEDULED" nil
)
4769 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4770 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4771 (org-entry-put (point) "SCHEDULED" "earlier")
4774 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4775 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4776 (org-entry-put (point) "SCHEDULED" "later")
4778 ;; Set "DEADLINE" property.
4780 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4781 (org-test-with-temp-text "* H"
4782 (org-entry-put (point) "DEADLINE" "2014-03-04")
4786 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4787 (org-entry-put (point) "DEADLINE" nil
)
4790 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4791 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4792 (org-entry-put (point) "DEADLINE" "earlier")
4795 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4796 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4797 (org-entry-put (point) "DEADLINE" "later")
4799 ;; Set "CATEGORY" property
4801 (string-match "^ *:CATEGORY: cat"
4802 (org-test-with-temp-text "* H"
4803 (org-entry-put (point) "CATEGORY" "cat")
4805 ;; Regular properties, with or without pre-existing drawer.
4807 (string-match "^ *:A: +2$"
4808 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4809 (org-entry-put (point) "A" "2")
4812 (string-match "^ *:A: +1$"
4813 (org-test-with-temp-text "* H"
4814 (org-entry-put (point) "A" "1")
4816 ;; Special case: two consecutive headlines.
4818 (string-match "\\* A\n *:PROPERTIES:"
4819 (org-test-with-temp-text "* A\n** B"
4820 (org-entry-put (point) "A" "1")
4823 (ert-deftest test-org
/refresh-properties
()
4824 "Test `org-refresh-properties' specifications."
4827 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4828 (org-refresh-properties "A" 'org-test
)
4829 (get-text-property (point) 'org-test
))))
4831 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4832 (org-refresh-properties "B" 'org-test
)
4833 (get-text-property (point) 'org-test
)))
4834 ;; Handle properties only defined with extension syntax, i.e.,
4838 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4839 (org-refresh-properties "A" 'org-test
)
4840 (get-text-property (point) 'org-test
))))
4841 ;; When property is inherited, add text property to the whole
4845 (org-test-with-temp-text
4846 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4847 (let ((org-use-property-inheritance t
))
4848 (org-refresh-properties "A" 'org-test
))
4849 (get-text-property (point) 'org-test
))))
4850 ;; When property is inherited, use global value across the whole
4851 ;; buffer. However local values have precedence.
4854 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4856 (let ((org-use-property-inheritance nil
))
4857 (org-refresh-properties "A" 'org-test
))
4858 (get-text-property (point) 'org-test
))))
4861 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4863 (let ((org-use-property-inheritance t
))
4864 (org-refresh-properties "A" 'org-test
))
4865 (get-text-property (point) 'org-test
))))
4868 (org-test-with-temp-text
4869 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4871 (let ((org-use-property-inheritance t
))
4872 (org-refresh-properties "A" 'org-test
))
4873 (get-text-property (point) 'org-test
)))))
4878 (ert-deftest test-org
/update-radio-target-regexp
()
4879 "Test `org-update-radio-target-regexp' specifications."
4880 ;; Properly update cache with no previous radio target regexp.
4883 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4884 (save-excursion (goto-char (point-max)) (org-element-context))
4886 (search-forward "o")
4888 (org-update-radio-target-regexp)
4889 (goto-char (point-max))
4890 (org-element-type (org-element-context)))))
4891 ;; Properly update cache with previous radio target regexp.
4894 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4895 (save-excursion (goto-char (point-max)) (org-element-context))
4897 (search-forward "o")
4899 (org-update-radio-target-regexp)
4900 (search-backward "r")
4903 (org-update-radio-target-regexp)
4904 (goto-char (point-max))
4905 (delete-region (line-beginning-position) (point))
4907 (org-element-type (org-element-context))))))
4912 (ert-deftest test-org
/match-sparse-tree
()
4913 "Test `org-match-sparse-tree' specifications."
4916 (org-test-with-temp-text "* H\n** H1 :tag:"
4917 (org-match-sparse-tree nil
"tag")
4918 (search-forward "H1")
4919 (org-invisible-p2)))
4921 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4922 (org-match-sparse-tree nil
"tag")
4923 (search-forward "H2")
4924 (org-invisible-p2)))
4925 ;; "-" operator for tags.
4927 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4928 (org-match-sparse-tree nil
"tag1-tag2")
4929 (search-forward "H1")
4930 (org-invisible-p2)))
4932 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4933 (org-match-sparse-tree nil
"tag1-tag2")
4934 (search-forward "H2")
4935 (org-invisible-p2)))
4936 ;; "&" operator for tags.
4938 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4939 (org-match-sparse-tree nil
"tag1&tag2")
4940 (search-forward "H1")
4941 (org-invisible-p2)))
4943 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4944 (org-match-sparse-tree nil
"tag1&tag2")
4945 (search-forward "H2")
4946 (org-invisible-p2)))
4947 ;; "|" operator for tags.
4949 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4950 (org-match-sparse-tree nil
"tag1|tag2")
4951 (search-forward "H1")
4952 (org-invisible-p2)))
4954 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4955 (org-match-sparse-tree nil
"tag1|tag2")
4956 (search-forward "H2")
4957 (org-invisible-p2)))
4958 ;; Regexp match on tags.
4960 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4961 (org-match-sparse-tree nil
"{^tag.*}")
4962 (search-forward "H1")
4963 (org-invisible-p2)))
4965 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4966 (org-match-sparse-tree nil
"{^tag.*}")
4967 (search-forward "H2")
4968 (org-invisible-p2)))
4969 ;; Match group tags.
4971 (org-test-with-temp-text
4972 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4973 (org-match-sparse-tree nil
"work")
4974 (search-forward "H1")
4975 (org-invisible-p2)))
4977 (org-test-with-temp-text
4978 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4979 (org-match-sparse-tree nil
"work")
4980 (search-forward "H2")
4981 (org-invisible-p2)))
4982 ;; Match group tags with hard brackets.
4984 (org-test-with-temp-text
4985 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4986 (org-match-sparse-tree nil
"work")
4987 (search-forward "H1")
4988 (org-invisible-p2)))
4990 (org-test-with-temp-text
4991 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4992 (org-match-sparse-tree nil
"work")
4993 (search-forward "H2")
4994 (org-invisible-p2)))
4995 ;; Match tags in hierarchies
4997 (org-test-with-temp-text
4998 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4999 #+TAGS: [ Lev_2 : Lev_3 ]\n
5000 #+TAGS: { Lev_3 : Lev_4 }\n
5001 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5002 (org-match-sparse-tree nil
"Lev_1")
5003 (search-forward "H4")
5004 (org-invisible-p2)))
5005 ;; Match regular expressions in tags
5007 (org-test-with-temp-text
5008 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5009 (org-match-sparse-tree nil
"Lev")
5010 (search-forward "H1")
5011 (org-invisible-p2)))
5013 (org-test-with-temp-text
5014 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5015 (org-match-sparse-tree nil
"Lev")
5016 (search-forward "H1")
5017 (org-invisible-p2)))
5018 ;; Match properties.
5020 (org-test-with-temp-text
5021 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5022 (org-match-sparse-tree nil
"A=\"1\"")
5023 (search-forward "H2")
5024 (org-invisible-p2)))
5026 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5027 (org-match-sparse-tree nil
"A=\"1\"")
5028 (search-forward "H2")
5029 (org-invisible-p2)))
5030 ;; Case is not significant when matching properties.
5032 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5033 (org-match-sparse-tree nil
"a=\"1\"")
5034 (search-forward "H2")
5035 (org-invisible-p2)))
5037 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5038 (org-match-sparse-tree nil
"A=\"1\"")
5039 (search-forward "H2")
5040 (org-invisible-p2)))
5041 ;; Match special LEVEL property.
5043 (org-test-with-temp-text "* H\n** H1\n*** H2"
5044 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5045 (search-forward "H1")
5046 (org-invisible-p2)))
5048 (org-test-with-temp-text "* H\n** H1\n*** H2"
5049 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5050 (search-forward "H2")
5051 (org-invisible-p2)))
5052 ;; Comparison operators when matching properties.
5054 (org-test-with-temp-text
5055 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5056 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5057 (search-forward "H1")
5058 (org-invisible-p2)))
5060 (org-test-with-temp-text
5061 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5062 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5063 (search-forward "H2")
5064 (org-invisible-p2)))
5065 ;; Regexp match on properties values.
5067 (org-test-with-temp-text
5068 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5069 (org-match-sparse-tree nil
"A={f.*}")
5070 (search-forward "H1")
5071 (org-invisible-p2)))
5073 (org-test-with-temp-text
5074 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5075 (org-match-sparse-tree nil
"A={f.*}")
5076 (search-forward "H2")
5077 (org-invisible-p2)))
5078 ;; With an optional argument, limit match to TODO entries.
5080 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5081 (org-match-sparse-tree t
"tag")
5082 (search-forward "H1")
5083 (org-invisible-p2)))
5085 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5086 (org-match-sparse-tree t
"tag")
5087 (search-forward "H2")
5088 (org-invisible-p2))))
5090 (ert-deftest test-org
/occur
()
5091 "Test `org-occur' specifications."
5092 ;; Count number of matches.
5095 (org-test-with-temp-text "* H\nA\n* H2"
5099 (org-test-with-temp-text "* H\nA\n* H2\nA"
5101 ;; Test CALLBACK optional argument.
5104 (org-test-with-temp-text "* H\nA\n* H2"
5105 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5108 (org-test-with-temp-text "* H\nA\n* H2\nA"
5109 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5110 ;; Case-fold searches according to `org-occur-case-fold-search'.
5113 (org-test-with-temp-text "Aa"
5114 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5117 (org-test-with-temp-text "Aa"
5118 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5121 (org-test-with-temp-text "Aa"
5122 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5125 (org-test-with-temp-text "Aa"
5126 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5129 (org-test-with-temp-text "Aa"
5130 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5133 (org-test-with-temp-text "Aa"
5134 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5139 (ert-deftest test-org
/tag-string-to-alist
()
5140 "Test `org-tag-string-to-alist' specifications."
5141 ;; Tag without selection key.
5142 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5143 ;; Tag with selection key.
5144 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5148 (org-tag-string-to-alist "[ group : t1 t2 ]")
5149 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5150 ;; Mutually exclusive tags.
5151 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5152 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5155 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5156 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5158 (ert-deftest test-org
/tag-alist-to-string
()
5159 "Test `org-tag-alist-to-string' specifications."
5160 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5161 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5164 (org-tag-alist-to-string
5165 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5166 "[ group : t1 t2 ]"))
5168 (equal (org-tag-alist-to-string
5169 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5173 (org-tag-alist-to-string
5174 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5175 "{ group : tag1 tag2 }")))
5177 (ert-deftest test-org
/tag-alist-to-groups
()
5178 "Test `org-tag-alist-to-groups' specifications."
5180 (equal (org-tag-alist-to-groups
5181 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5182 '(("group" "t1" "t2"))))
5185 (org-tag-alist-to-groups
5186 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5187 '(("group" "t1" "t2"))))
5189 (org-tag-alist-to-groups
5190 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5192 (ert-deftest test-org
/tag-align
()
5193 "Test tags alignment."
5194 ;; Test aligning tags with different display width.
5196 ;; 12345678901234567890
5197 (equal "* Test :abc:"
5198 (org-test-with-temp-text "* Test :abc:"
5199 (let ((org-tags-column -
20)
5200 (indent-tabs-mode nil
))
5201 (org-fix-tags-on-the-fly))
5204 ;; 12345678901234567890
5205 (equal "* Test :日本語:"
5206 (org-test-with-temp-text "* Test :日本語:"
5207 (let ((org-tags-column -
20)
5208 (indent-tabs-mode nil
))
5209 (org-fix-tags-on-the-fly))
5211 ;; Make sure aligning tags do not skip invisible text.
5213 (equal "* [[linkx]] :tag:"
5214 (org-test-with-temp-text "* [[link<point>]] :tag:"
5215 (let ((org-tags-column 0))
5216 (org-fix-tags-on-the-fly)
5218 (buffer-string))))))
5220 (ert-deftest test-org
/tags-at
()
5222 (equal '("foo" "bar")
5223 (org-test-with-temp-text
5224 "* T<point>est :foo:bar:"
5225 (org-get-tags-at)))))
5230 (ert-deftest test-org
/time-stamp
()
5231 "Test `org-time-stamp' specifications."
5232 ;; Insert chosen time stamp at point.
5235 "Te<2014-03-04 .*?>xt"
5236 (org-test-with-temp-text "Te<point>xt"
5237 (cl-letf (((symbol-function 'org-read-date
)
5238 (lambda (&rest args
)
5239 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5240 (org-time-stamp nil
)
5242 ;; With a prefix argument, also insert time.
5245 "Te<2014-03-04 .*? 00:41>xt"
5246 (org-test-with-temp-text "Te<point>xt"
5247 (cl-letf (((symbol-function 'org-read-date
)
5248 (lambda (&rest args
)
5249 (apply #'encode-time
5250 (org-parse-time-string "2014-03-04 00:41")))))
5251 (org-time-stamp '(4))
5253 ;; With two universal prefix arguments, insert an active timestamp
5254 ;; with the current time without prompting the user.
5257 "Te<2014-03-04 .*? 00:41>xt"
5258 (org-test-with-temp-text "Te<point>xt"
5259 (cl-letf (((symbol-function 'current-time
)
5261 (apply #'encode-time
5262 (org-parse-time-string "2014-03-04 00:41")))))
5263 (org-time-stamp '(16))
5265 ;; When optional argument is non-nil, insert an inactive timestamp.
5268 "Te\\[2014-03-04 .*?\\]xt"
5269 (org-test-with-temp-text "Te<point>xt"
5270 (cl-letf (((symbol-function 'org-read-date
)
5271 (lambda (&rest args
)
5272 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5273 (org-time-stamp nil t
)
5275 ;; When called from a timestamp, replace existing one.
5279 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5280 (cl-letf (((symbol-function 'org-read-date
)
5281 (lambda (&rest args
)
5282 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5283 (org-time-stamp nil
)
5287 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5288 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5289 (cl-letf (((symbol-function 'org-read-date
)
5290 (lambda (&rest args
)
5291 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5292 (org-time-stamp nil
)
5294 ;; When replacing a timestamp, preserve repeater, if any.
5297 "<2014-03-04 .*? \\+2y>"
5298 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5299 (cl-letf (((symbol-function 'org-read-date
)
5300 (lambda (&rest args
)
5301 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5302 (org-time-stamp nil
)
5304 ;; When called twice in a raw, build a date range.
5307 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5308 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5309 (cl-letf (((symbol-function 'org-read-date
)
5310 (lambda (&rest args
)
5311 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5312 (let ((last-command 'org-time-stamp
)
5313 (this-command 'org-time-stamp
))
5314 (org-time-stamp nil
))
5315 (buffer-string))))))
5317 (ert-deftest test-org
/timestamp-has-time-p
()
5318 "Test `org-timestamp-has-time-p' specifications."
5321 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5322 (org-timestamp-has-time-p (org-element-context))))
5325 (org-test-with-temp-text "<2012-03-29 Thu>"
5326 (org-timestamp-has-time-p (org-element-context)))))
5328 (ert-deftest test-org
/timestamp-format
()
5329 "Test `org-timestamp-format' specifications."
5334 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5335 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5340 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5341 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5343 (ert-deftest test-org
/timestamp-split-range
()
5344 "Test `org-timestamp-split-range' specifications."
5345 ;; Extract range start (active).
5348 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5349 (let ((ts (org-timestamp-split-range (org-element-context))))
5350 (mapcar (lambda (p) (org-element-property p ts
))
5351 '(:year-end
:month-end
:day-end
))))))
5352 ;; Extract range start (inactive)
5355 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5356 (let ((ts (org-timestamp-split-range (org-element-context))))
5357 (mapcar (lambda (p) (org-element-property p ts
))
5358 '(:year-end
:month-end
:day-end
))))))
5359 ;; Extract range end (active).
5362 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5363 (let ((ts (org-timestamp-split-range
5364 (org-element-context) t
)))
5365 (mapcar (lambda (p) (org-element-property p ts
))
5366 '(:year-end
:month-end
:day-end
))))))
5367 ;; Extract range end (inactive)
5370 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5371 (let ((ts (org-timestamp-split-range
5372 (org-element-context) t
)))
5373 (mapcar (lambda (p) (org-element-property p ts
))
5374 '(:year-end
:month-end
:day-end
))))))
5375 ;; Return the timestamp if not a range.
5377 (org-test-with-temp-text "[2012-03-29 Thu]"
5378 (let* ((ts-orig (org-element-context))
5379 (ts-copy (org-timestamp-split-range ts-orig
)))
5380 (eq ts-orig ts-copy
))))
5382 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5383 (let* ((ts-orig (org-element-context))
5384 (ts-copy (org-timestamp-split-range ts-orig
)))
5385 (eq ts-orig ts-copy
)))))
5387 (ert-deftest test-org
/timestamp-translate
()
5388 "Test `org-timestamp-translate' specifications."
5389 ;; Translate whole date range.
5392 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5393 (let ((org-display-custom-times t
)
5394 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5395 (org-timestamp-translate (org-element-context))))))
5396 ;; Translate date range start.
5399 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5400 (let ((org-display-custom-times t
)
5401 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5402 (org-timestamp-translate (org-element-context) 'start
)))))
5403 ;; Translate date range end.
5406 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5407 (let ((org-display-custom-times t
)
5408 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5409 (org-timestamp-translate (org-element-context) 'end
)))))
5410 ;; Translate time range.
5413 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5414 (let ((org-display-custom-times t
)
5415 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5416 (org-timestamp-translate (org-element-context))))))
5417 ;; Translate non-range timestamp.
5420 (org-test-with-temp-text "<2012-03-29 Thu>"
5421 (let ((org-display-custom-times t
)
5422 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5423 (org-timestamp-translate (org-element-context))))))
5424 ;; Do not change `diary' timestamps.
5426 (equal "<%%(org-float t 4 2)>"
5427 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5428 (let ((org-display-custom-times t
)
5429 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5430 (org-timestamp-translate (org-element-context)))))))
5436 (ert-deftest test-org
/flag-drawer
()
5437 "Test `org-flag-drawer' specifications."
5440 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5442 (get-char-property (line-end-position) 'invisible
)))
5445 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5447 (org-flag-drawer nil
)
5448 (get-char-property (line-end-position) 'invisible
)))
5449 ;; Test optional argument.
5451 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5452 (let ((drawer (save-excursion (search-forward ":D2")
5453 (org-element-at-point))))
5454 (org-flag-drawer t drawer
)
5455 (get-char-property (progn (search-forward ":D2") (line-end-position))
5458 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5459 (let ((drawer (save-excursion (search-forward ":D2")
5460 (org-element-at-point))))
5461 (org-flag-drawer t drawer
)
5462 (get-char-property (line-end-position) 'invisible
))))
5463 ;; Do not hide fake drawers.
5465 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5468 (get-char-property (line-end-position) 'invisible
)))
5469 ;; Do not hide incomplete drawers.
5471 (org-test-with-temp-text ":D:\nparagraph"
5474 (get-char-property (line-end-position) 'invisible
)))
5475 ;; Do not hide drawers when called from final blank lines.
5477 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5478 (goto-char (point-max))
5480 (goto-char (point-min))
5481 (get-char-property (line-end-position) 'invisible
)))
5482 ;; Don't leave point in an invisible part of the buffer when hiding
5485 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5486 (goto-char (point-max))
5488 (get-char-property (point) 'invisible
))))
5490 (ert-deftest test-org
/hide-block-toggle
()
5491 "Test `org-hide-block-toggle' specifications."
5492 ;; Error when not at a block.
5494 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5495 (org-hide-block-toggle 'off
)
5496 (get-char-property (line-end-position) 'invisible
)))
5499 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5500 (org-hide-block-toggle)
5501 (get-char-property (line-end-position) 'invisible
)))
5503 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5504 (org-hide-block-toggle)
5505 (get-char-property (line-end-position) 'invisible
)))
5506 ;; Show block unconditionally when optional argument is `off'.
5508 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5509 (org-hide-block-toggle)
5510 (org-hide-block-toggle 'off
)
5511 (get-char-property (line-end-position) 'invisible
)))
5513 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5514 (org-hide-block-toggle 'off
)
5515 (get-char-property (line-end-position) 'invisible
)))
5516 ;; Hide block unconditionally when optional argument is non-nil.
5518 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5519 (org-hide-block-toggle t
)
5520 (get-char-property (line-end-position) 'invisible
)))
5522 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5523 (org-hide-block-toggle)
5524 (org-hide-block-toggle t
)
5525 (get-char-property (line-end-position) 'invisible
)))
5526 ;; Do not hide block when called from final blank lines.
5528 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5529 (org-hide-block-toggle)
5530 (goto-char (point-min))
5531 (get-char-property (line-end-position) 'invisible
)))
5532 ;; Don't leave point in an invisible part of the buffer when hiding
5535 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5536 (org-hide-block-toggle)
5537 (get-char-property (point) 'invisible
))))
5539 (ert-deftest test-org
/hide-block-toggle-maybe
()
5540 "Test `org-hide-block-toggle-maybe' specifications."
5542 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5543 (org-hide-block-toggle-maybe)))
5545 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5547 (ert-deftest test-org
/set-tags
()
5548 "Test `org-set-tags' specifications."
5549 ;; Tags set via fast-tag-selection should be visible afterwards
5551 (let ((org-tag-alist '(("NEXT" . ?n
)))
5552 (org-fast-tag-selection-single-key t
))
5553 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5554 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5555 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5556 ;; Show only headlines
5558 ;; Set NEXT tag on current entry
5559 (org-set-tags nil nil
)
5560 ;; Move point to that NEXT tag
5561 (search-forward "NEXT") (backward-word)
5562 ;; And it should be visible (i.e. no overlays)
5563 (not (overlays-at (point))))))))
5565 (ert-deftest test-org
/show-set-visibility
()
5566 "Test `org-show-set-visibility' specifications."
5567 ;; Do not throw an error before first heading.
5569 (org-test-with-temp-text "Preamble\n* Headline"
5570 (org-show-set-visibility 'tree
)
5572 ;; Test all visibility spans, both on headline and in entry.
5573 (let ((list-visible-lines
5574 (lambda (state headerp
)
5575 (org-test-with-temp-text "* Grandmother (0)
5586 **** The other child (11)
5591 (search-forward (if headerp
"Self" "Match"))
5592 (org-show-set-visibility state
)
5593 (goto-char (point-min))
5594 (let (result (line 0))
5596 (unless (org-invisible-p2) (push line result
))
5599 (nreverse result
))))))
5600 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5601 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5602 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5603 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5604 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5605 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5606 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5607 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5608 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5609 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5610 (funcall list-visible-lines
'tree nil
)))
5611 (should (equal '(0 1 3 4 5 7 12 13)
5612 (funcall list-visible-lines
'canonical t
)))
5613 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5614 (funcall list-visible-lines
'canonical nil
))))
5615 ;; When point is hidden in a drawer or a block, make sure to make it
5618 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5619 (org-hide-block-toggle)
5620 (search-forward "Text")
5621 (org-show-set-visibility 'minimal
)
5622 (org-invisible-p2)))
5624 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5626 (search-forward "Text")
5627 (org-show-set-visibility 'minimal
)
5628 (org-invisible-p2)))
5630 (org-test-with-temp-text
5631 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5634 (org-hide-block-toggle)
5635 (search-forward "Text")
5636 (org-show-set-visibility 'minimal
)
5637 (org-invisible-p2))))
5642 ;;; test-org.el ends here