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\nA"
725 (let ((org-adapt-indentation t
)) (org-indent-line))
726 (org-get-indentation))))
729 (org-test-with-temp-text "* H\n\nA"
731 (let ((org-adapt-indentation t
)) (org-indent-line))
732 (org-get-indentation))))
735 (org-test-with-temp-text "* H\nA"
737 (let ((org-adapt-indentation nil
)) (org-indent-line))
738 (org-get-indentation))))
739 ;; Indenting preserves point position.
741 (org-test-with-temp-text "* H\nAB"
744 (let ((org-adapt-indentation t
)) (org-indent-line))
746 ;; Do not change indentation at an item.
749 (org-test-with-temp-text "* H\n - A"
751 (let ((org-adapt-indentation t
)) (org-indent-line))
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 and example blocks.
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_EXAMPLE\n A\n B\n#+END_EXAMPLE"
900 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
901 (org-indent-region (point-min) (point-max))
903 ;; Indent according to mode if `org-src-tab-acts-natively' is
904 ;; non-nil. Otherwise, do not indent code at all.
906 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
907 (org-test-with-temp-text
908 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
909 (let ((org-src-tab-acts-natively t
)
910 (org-edit-src-content-indentation 0))
911 (org-indent-region (point-min) (point-max)))
914 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
915 (org-test-with-temp-text
916 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
917 (let ((org-src-tab-acts-natively nil
)
918 (org-edit-src-content-indentation 0))
919 (org-indent-region (point-min) (point-max)))
921 ;; Align node properties according to `org-property-format'. Handle
922 ;; nicely empty values.
924 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
925 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
926 (let ((org-property-format "%-10s %s")
927 (org-adapt-indentation nil
))
928 (org-indent-region (point) (point-max)))
931 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
932 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
933 (let ((org-property-format "%-10s %s")
934 (org-adapt-indentation nil
))
935 (org-indent-region (point) (point-max)))
937 ;; Indent plain lists.
939 (equal "- A\n B\n - C\n\n D"
940 (org-test-with-temp-text "- A\n B\n - C\n\n D"
941 (org-indent-region (point-min) (point-max))
945 (org-test-with-temp-text " - A\n\n - B"
946 (org-indent-region (point-min) (point-max))
948 ;; Indent footnote definitions.
950 (equal "[fn:1] Definition\n\nDefinition"
951 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
952 (org-indent-region (point-min) (point-max))
954 ;; Special case: Start indenting on a blank line.
957 (org-test-with-temp-text "\n Paragraph"
958 (org-indent-region (point-min) (point-max))
965 (ert-deftest test-org
/delete-indentation
()
966 "Test `org-delete-indentation' specifications."
968 (should (equal "foo bar"
969 (org-test-with-temp-text
971 (org-delete-indentation)
973 ;; With optional argument.
974 (should (equal "foo bar"
975 (org-test-with-temp-text
977 (org-delete-indentation t
)
979 ;; At headline text should be appended to the headline text.
981 (equal"* foo bar :tag:"
982 (let (org-auto-align-tags)
983 (org-test-with-temp-text
984 "* foo :tag:\n bar<point>"
985 (org-delete-indentation)
988 (equal "* foo bar :tag:"
989 (let (org-auto-align-tags)
990 (org-test-with-temp-text
991 "* foo <point>:tag:\n bar"
992 (org-delete-indentation t
)
995 (ert-deftest test-org
/return
()
996 "Test `org-return' specifications."
1000 (org-test-with-temp-text "Para<point>graph"
1003 ;; With optional argument, indent line.
1005 (equal " Para\n graph"
1006 (org-test-with-temp-text " Para<point>graph"
1009 ;; On a table, call `org-table-next-row'.
1011 (org-test-with-temp-text "| <point>a |\n| b |"
1013 (looking-at-p "b")))
1014 ;; Open link or timestamp under point when `org-return-follows-link'
1017 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1018 (let ((org-return-follows-link t
)
1019 (org-link-search-must-match-exact-headline nil
))
1021 (looking-at-p "<<target>>")))
1023 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1024 (let ((org-return-follows-link nil
)) (org-return))
1025 (looking-at-p "<<target>>")))
1027 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1028 (let ((org-return-follows-link t
)) (org-return))
1029 (looking-at-p "* b")))
1031 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1032 (let ((org-return-follows-link t
)
1033 (org-link-search-must-match-exact-headline nil
))
1035 (looking-at-p "<<target>>")))
1037 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1038 (let ((org-return-follows-link t
)
1039 (org-link-search-must-match-exact-headline nil
))
1041 (looking-at-p "<<target>>")))
1042 ;; When `org-return-follows-link' is non-nil, tolerate links and
1043 ;; timestamps in comments, node properties, etc.
1045 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1046 (let ((org-return-follows-link t
)
1047 (org-link-search-must-match-exact-headline nil
))
1049 (looking-at-p "<<target>>")))
1051 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1052 (let ((org-return-follows-link nil
)) (org-return))
1053 (looking-at-p "<<target>>")))
1055 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1056 (let ((org-return-follows-link t
)
1057 (org-link-search-must-match-exact-headline nil
))
1059 (looking-at-p "<<target>>")))
1060 ;; However, do not open link when point is in a table.
1062 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1063 (let ((org-return-follows-link t
)) (org-return))
1064 (looking-at-p "between")))
1065 ;; Special case: in a list, when indenting, do not break structure.
1068 (org-test-with-temp-text "- A <point>B"
1073 (org-test-with-temp-text "- A\n<point>- B"
1076 ;; On tags part of a headline, add a newline below it instead of
1079 (equal "* H :tag:\n"
1080 (org-test-with-temp-text "* H :<point>tag:"
1083 ;; Before headline text, add a newline below it instead of breaking
1086 (equal "* TODO H :tag:\n"
1087 (org-test-with-temp-text "* <point>TODO H :tag:"
1091 (equal "* TODO [#B] H :tag:\n"
1092 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1095 (should ;TODO are case-sensitive
1097 (org-test-with-temp-text "* <point>Todo"
1100 ;; At headline text, break headline text but preserve tags.
1102 (equal "* TODO [#B] foo :tag:\nbar"
1103 (let (org-auto-align-tags)
1104 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1107 ;; At bol of headline insert newline.
1110 (org-test-with-temp-text "<point>* h"
1113 ;; Refuse to leave invalid headline in buffer.
1116 (org-test-with-temp-text "*<point> h"
1120 (ert-deftest test-org
/meta-return
()
1121 "Test M-RET (`org-meta-return') specifications."
1122 ;; In a table field insert a row above.
1124 (org-test-with-temp-text "| a |"
1128 (looking-at "| |$")))
1129 ;; In a paragraph change current line into a header.
1131 (org-test-with-temp-text "a"
1134 (looking-at "\* a$")))
1135 ;; In an item insert an item, in this case above.
1137 (org-test-with-temp-text "- a"
1140 (looking-at "- $")))
1141 ;; In a drawer and item insert an item, in this case above.
1143 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1147 (looking-at "- $"))))
1149 (ert-deftest test-org
/insert-heading
()
1150 "Test `org-insert-heading' specifications."
1151 ;; In an empty buffer, insert a new headline.
1154 (org-test-with-temp-text ""
1155 (org-insert-heading)
1157 ;; At the beginning of a line, turn it into a headline
1160 (org-test-with-temp-text "<point>P"
1161 (org-insert-heading)
1163 ;; In the middle of a line, split the line if allowed, otherwise,
1164 ;; insert the headline at its end.
1166 (equal "Para\n* graph"
1167 (org-test-with-temp-text "Para<point>graph"
1168 (let ((org-M-RET-may-split-line '((default . t
))))
1169 (org-insert-heading))
1172 (equal "Paragraph\n* "
1173 (org-test-with-temp-text "Para<point>graph"
1174 (let ((org-M-RET-may-split-line '((default . nil
))))
1175 (org-insert-heading))
1177 ;; At the beginning of a headline, create one above.
1180 (org-test-with-temp-text "* H"
1181 (org-insert-heading)
1183 ;; In the middle of a headline, split it if allowed.
1186 (org-test-with-temp-text "* H<point>1"
1187 (let ((org-M-RET-may-split-line '((headline . t
))))
1188 (org-insert-heading))
1192 (org-test-with-temp-text "* H<point>1"
1193 (let ((org-M-RET-may-split-line '((headline . nil
))))
1194 (org-insert-heading))
1196 ;; However, splitting cannot happen on TODO keywords, priorities or
1199 (equal "* TODO H1\n* "
1200 (org-test-with-temp-text "* TO<point>DO H1"
1201 (let ((org-M-RET-may-split-line '((headline . t
))))
1202 (org-insert-heading))
1205 (equal "* [#A] H1\n* "
1206 (org-test-with-temp-text "* [#<point>A] H1"
1207 (let ((org-M-RET-may-split-line '((headline . t
))))
1208 (org-insert-heading))
1211 (equal "* H1 :tag:\n* "
1212 (org-test-with-temp-text "* H1 :ta<point>g:"
1213 (let ((org-M-RET-may-split-line '((headline . t
))))
1214 (org-insert-heading))
1216 ;; When on a list, insert an item instead, unless called with an
1217 ;; universal argument or if list is invisible. In this case, create
1218 ;; a new headline after contents.
1220 (equal "* H\n- item\n- "
1221 (org-test-with-temp-text "* H\n- item<point>"
1222 (let ((org-insert-heading-respect-content nil
))
1223 (org-insert-heading))
1226 (equal "* H\n- item\n- item 2\n* "
1227 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1228 (let ((org-insert-heading-respect-content nil
))
1229 (org-insert-heading '(4)))
1232 (equal "* H\n- item\n* "
1233 (org-test-with-temp-text "* H\n- item"
1235 (goto-char (point-max))
1236 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1238 ;; Preserve list visibility when inserting an item.
1242 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1243 (let ((org-cycle-include-plain-lists t
))
1247 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1248 (list (get-char-property (line-beginning-position 0) 'invisible
)
1249 (get-char-property (line-end-position 2) 'invisible
))))))
1250 ;; When called with one universal argument, insert a new headline at
1251 ;; the end of the current subtree, independently on the position of
1256 (org-test-with-temp-text "* H1\n** H2"
1257 (let ((org-insert-heading-respect-content nil
))
1258 (org-insert-heading '(4)))
1263 (org-test-with-temp-text "* H<point>1\n** H2"
1264 (let ((org-insert-heading-respect-content nil
))
1265 (org-insert-heading '(4)))
1267 ;; When called with two universal arguments, insert a new headline
1268 ;; at the end of the grandparent subtree.
1270 (equal "* H1\n** H3\n- item\n** H2\n** "
1271 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1272 (let ((org-insert-heading-respect-content nil
))
1273 (org-insert-heading '(16)))
1275 ;; When optional TOP-LEVEL argument is non-nil, always insert
1276 ;; a level 1 heading.
1278 (equal "* H1\n** H2\n* "
1279 (org-test-with-temp-text "* H1\n** H2<point>"
1280 (org-insert-heading nil nil t
)
1283 (equal "* H1\n- item\n* "
1284 (org-test-with-temp-text "* H1\n- item<point>"
1285 (org-insert-heading nil nil t
)
1287 ;; Corner case: correctly insert a headline after an empty one.
1290 (org-test-with-temp-text "* <point>"
1291 (org-insert-heading)
1294 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1295 "Test `org-insert-todo-heading-respect-content' specifications."
1296 ;; Create a TODO heading.
1298 (org-test-with-temp-text "* H1\n Body"
1299 (org-insert-todo-heading-respect-content)
1300 (nth 2 (org-heading-components))))
1301 ;; Add headline at the end of the first subtree
1303 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1304 (search-forward "H1Body")
1305 (org-insert-todo-heading-respect-content)
1306 (and (eobp) (org-at-heading-p))))
1307 ;; In a list, do not create a new item.
1309 (org-test-with-temp-text "* H\n- an item\n- another one"
1310 (search-forward "an ")
1311 (org-insert-todo-heading-respect-content)
1312 (and (eobp) (org-at-heading-p)))))
1314 (ert-deftest test-org
/clone-with-time-shift
()
1315 "Test `org-clone-subtree-with-time-shift'."
1316 ;; Raise an error before first heading.
1318 (org-test-with-temp-text ""
1319 (org-clone-subtree-with-time-shift 1)))
1320 ;; Raise an error on invalid number of clones.
1322 (org-test-with-temp-text "* Clone me"
1323 (org-clone-subtree-with-time-shift -
1)))
1324 ;; Clone non-repeating once.
1330 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1331 (org-clone-subtree-with-time-shift 1 "+2d")
1332 (replace-regexp-in-string
1333 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1335 ;; Clone repeating once.
1340 * H1\n<2015-06-25 +1w>
1342 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1343 (org-clone-subtree-with-time-shift 1 "+2d")
1344 (replace-regexp-in-string
1345 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1347 ;; Clone non-repeating zero times.
1352 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1353 (org-clone-subtree-with-time-shift 0 "+2d")
1354 (replace-regexp-in-string
1355 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1357 ;; Clone repeating "zero" times.
1361 * H1\n<2015-06-23 +1w>
1363 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1364 (org-clone-subtree-with-time-shift 0 "+2d")
1365 (replace-regexp-in-string
1366 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1368 ;; Clone with blank SHIFT argument.
1372 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1373 (org-clone-subtree-with-time-shift 1 "")
1374 (buffer-substring-no-properties (line-beginning-position 2)
1375 (line-end-position 2)))))
1376 ;; Find time stamps before point. If SHIFT is not specified, ask
1377 ;; for a time shift.
1381 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1382 (org-clone-subtree-with-time-shift 1 "+1d")
1383 (buffer-substring-no-properties (line-beginning-position 2)
1384 (line-end-position 2)))))
1388 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1389 (cl-letf (((symbol-function 'read-from-minibuffer
)
1390 (lambda (&rest args
) "+1d")))
1391 (org-clone-subtree-with-time-shift 1))
1392 (buffer-substring-no-properties (line-beginning-position 2)
1393 (line-end-position 2))))))
1396 ;;; Fixed-Width Areas
1398 (ert-deftest test-org
/toggle-fixed-width
()
1399 "Test `org-toggle-fixed-width' specifications."
1400 ;; No region: Toggle on fixed-width marker in paragraphs.
1403 (org-test-with-temp-text "A"
1404 (org-toggle-fixed-width)
1406 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1409 (org-test-with-temp-text ": A"
1410 (org-toggle-fixed-width)
1412 ;; No region: Toggle on marker in blank lines after elements or just
1413 ;; after a headline.
1416 (org-test-with-temp-text "* H\n"
1418 (org-toggle-fixed-width)
1421 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1422 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1423 (goto-char (point-max))
1424 (org-toggle-fixed-width)
1426 ;; No region: Toggle on marker in front of one line elements (e.g.,
1427 ;; headlines, clocks)
1429 (equal ": * Headline"
1430 (org-test-with-temp-text "* Headline"
1431 (org-toggle-fixed-width)
1434 (equal ": #+KEYWORD: value"
1435 (org-test-with-temp-text "#+KEYWORD: value"
1436 (org-toggle-fixed-width)
1438 ;; No region: error in other situations.
1440 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1442 (org-toggle-fixed-width)
1444 ;; No region: Indentation is preserved.
1447 (org-test-with-temp-text "- A\n B"
1449 (org-toggle-fixed-width)
1451 ;; Region: If it contains only fixed-width elements and blank lines,
1452 ;; toggle off fixed-width markup.
1455 (org-test-with-temp-text ": A\n\n: B"
1456 (transient-mark-mode 1)
1457 (push-mark (point) t t
)
1458 (goto-char (point-max))
1459 (org-toggle-fixed-width)
1461 ;; Region: If it contains anything else, toggle on fixed-width but
1462 ;; not on fixed-width areas.
1464 (equal ": A\n: \n: B\n: \n: C"
1465 (org-test-with-temp-text "A\n\n: B\n\nC"
1466 (transient-mark-mode 1)
1467 (push-mark (point) t t
)
1468 (goto-char (point-max))
1469 (org-toggle-fixed-width)
1471 ;; Region: Ignore blank lines at its end, unless it contains only
1475 (org-test-with-temp-text "A\n\n"
1476 (transient-mark-mode 1)
1477 (push-mark (point) t t
)
1478 (goto-char (point-max))
1479 (org-toggle-fixed-width)
1483 (org-test-with-temp-text "\n\n"
1484 (transient-mark-mode 1)
1485 (push-mark (point) t t
)
1486 (goto-char (point-max))
1487 (org-toggle-fixed-width)
1494 (ert-deftest test-org
/get-heading
()
1495 "Test `org-get-heading' specifications."
1496 ;; Return current heading, even if point is not on it.
1499 (org-test-with-temp-text "* H"
1500 (org-get-heading))))
1503 (org-test-with-temp-text "* H\nText<point>"
1504 (org-get-heading))))
1505 ;; Without any optional argument, return TODO keywords and tags.
1508 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1509 (org-get-heading))))
1512 (org-test-with-temp-text "* H :tag:"
1513 (org-get-heading))))
1514 ;; With NO-TAGS argument, ignore tags.
1517 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1518 (org-get-heading t
))))
1521 (org-test-with-temp-text "* H :tag:"
1522 (org-get-heading t
))))
1523 ;; With NO-TODO, ignore TODO keyword.
1526 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1527 (org-get-heading nil t
))))
1530 (org-test-with-temp-text "* H :tag:"
1531 (org-get-heading nil t
))))
1532 ;; TODO keywords are case-sensitive.
1535 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1536 (org-get-heading nil t
))))
1537 ;; On an empty headline, return value is consistent.
1538 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1539 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1540 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1541 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1543 (ert-deftest test-org
/in-commented-heading-p
()
1544 "Test `org-in-commented-heading-p' specifications."
1545 ;; Commented headline.
1547 (org-test-with-temp-text "* COMMENT Headline\nBody"
1548 (goto-char (point-max))
1549 (org-in-commented-heading-p)))
1550 ;; Commented ancestor.
1552 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1553 (goto-char (point-max))
1554 (org-in-commented-heading-p)))
1555 ;; Comment keyword is case-sensitive.
1557 (org-test-with-temp-text "* Comment Headline\nBody"
1558 (goto-char (point-max))
1559 (org-in-commented-heading-p)))
1560 ;; Keyword is standalone.
1562 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1563 (goto-char (point-max))
1564 (org-in-commented-heading-p)))
1565 ;; Optional argument.
1567 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1568 (goto-char (point-max))
1569 (org-in-commented-heading-p t
))))
1571 (ert-deftest test-org
/entry-blocked-p
()
1572 ;; Check other dependencies.
1574 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1575 (let ((org-enforce-todo-dependencies t
)
1577 '(org-block-todo-from-children-or-siblings-or-parent)))
1578 (org-entry-blocked-p))))
1580 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1581 (let ((org-enforce-todo-dependencies t
)
1583 '(org-block-todo-from-children-or-siblings-or-parent)))
1584 (org-entry-blocked-p))))
1585 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1588 (org-test-with-temp-text "* Blocked\n** TODO one"
1589 (let ((org-enforce-todo-dependencies t
)
1591 '(org-block-todo-from-children-or-siblings-or-parent)))
1592 (org-entry-blocked-p))))
1594 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1595 (let ((org-enforce-todo-dependencies t
)
1597 '(org-block-todo-from-children-or-siblings-or-parent)))
1598 (org-entry-blocked-p))))
1599 ;; Follow :ORDERED: specifications.
1601 (org-test-with-temp-text
1602 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1603 (let ((org-enforce-todo-dependencies t
)
1605 '(org-block-todo-from-children-or-siblings-or-parent)))
1606 (org-entry-blocked-p))))
1608 (org-test-with-temp-text
1609 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1610 (let ((org-enforce-todo-dependencies t
)
1612 '(org-block-todo-from-children-or-siblings-or-parent)))
1613 (org-entry-blocked-p)))))
1615 (ert-deftest test-org
/get-outline-path
()
1616 "Test `org-get-outline-path' specifications."
1617 ;; Top-level headlines have no outline path.
1619 (org-test-with-temp-text "* H"
1620 (org-get-outline-path)))
1621 ;; Otherwise, outline path is the path leading to the headline.
1624 (org-test-with-temp-text "* H\n** S<point>"
1625 (org-get-outline-path))))
1626 ;; Find path even when point is not on a headline.
1629 (org-test-with-temp-text "* H\n** S\nText<point>"
1630 (org-get-outline-path))))
1631 ;; TODO keywords, tags and statistics cookies are ignored.
1634 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1635 (org-get-outline-path))))
1636 ;; Links are replaced with their description or their path.
1639 (org-test-with-temp-text
1640 "* [[http://orgmode.org][Org]]\n** S<point>"
1641 (org-get-outline-path))))
1643 (equal '("http://orgmode.org")
1644 (org-test-with-temp-text
1645 "* [[http://orgmode.org]]\n** S<point>"
1646 (org-get-outline-path))))
1647 ;; When WITH-SELF is non-nil, include current heading.
1650 (org-test-with-temp-text "* H"
1651 (org-get-outline-path t
))))
1654 (org-test-with-temp-text "* H\n** S\nText<point>"
1655 (org-get-outline-path t
))))
1656 ;; Using cache is transparent to the user.
1659 (org-test-with-temp-text "* H\n** S<point>"
1660 (setq org-outline-path-cache nil
)
1661 (org-get-outline-path nil t
))))
1662 ;; Do not corrupt cache when finding outline path in distant part of
1666 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1667 (setq org-outline-path-cache nil
)
1668 (org-get-outline-path nil t
)
1669 (search-forward "S2")
1670 (org-get-outline-path nil t
))))
1671 ;; Do not choke on empty headlines.
1673 (org-test-with-temp-text "* H\n** <point>"
1674 (org-get-outline-path)))
1676 (org-test-with-temp-text "* \n** H<point>"
1677 (org-get-outline-path))))
1679 (ert-deftest test-org
/format-outline-path
()
1680 "Test `org-format-outline-path' specifications."
1682 (string= (org-format-outline-path (list "one" "two" "three"))
1686 (string= (org-format-outline-path '())
1689 (string= (org-format-outline-path '(nil))
1691 ;; Empty path and prefix.
1693 (string= (org-format-outline-path '() nil
">>")
1695 ;; Trailing whitespace in headings.
1697 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1699 ;; Non-default prefix and separators.
1701 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1702 ">>|one|two|three"))
1705 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1707 ;; Give a very narrow width.
1709 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1711 ;; Give a prefix that extends beyond the width.
1713 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1717 (ert-deftest test-org
/map-entries
()
1718 "Test `org-map-entries' specifications."
1722 (org-test-with-temp-text "* Level 1\n** Level 2"
1723 (org-map-entries #'point
))))
1727 (org-test-with-temp-text "* Level 1\n** Level 2"
1728 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1731 (org-test-with-temp-text "* Level 1\n** Level 2"
1732 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1736 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1737 (org-map-entries #'point
"yes"))))
1740 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1741 (org-map-entries #'point
"+yes-a"))))
1744 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1745 (org-map-entries #'point
"{yes?}"))))
1749 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1750 (org-map-entries #'point
"PRIORITY=\"A\""))))
1754 (org-test-with-temp-text "
1756 SCHEDULED: <2012-03-29 thu.>
1758 SCHEDULED: <2014-03-04 tue.>"
1759 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1762 (org-test-with-temp-text "
1764 SCHEDULED: <2012-03-29 thu.>
1766 SCHEDULED: <2014-03-04 tue.>"
1767 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1768 ;; Regular property match.
1771 (org-test-with-temp-text "
1780 (org-map-entries #'point
"TEST=1"))))
1781 ;; Multiple criteria.
1784 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1785 (let (org-odd-levels-only
1786 (org-use-tag-inheritance nil
))
1787 (org-map-entries #'point
"yes+LEVEL=1")))))
1791 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1792 (let (org-odd-levels-only)
1793 (org-map-entries #'point
"LEVEL=2|no")))))
1796 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1797 (let (org-odd-levels-only)
1798 (org-map-entries #'point
"yes|no")))))
1802 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1803 (let (org-odd-levels-only)
1804 (org-map-entries #'point
"yes&no"))))))
1806 (ert-deftest test-org
/edit-headline
()
1807 "Test `org-edit-headline' specifications."
1810 (org-test-with-temp-text "* A"
1811 (org-edit-headline "B")
1813 ;; Handle empty headings.
1816 (org-test-with-temp-text "* A"
1817 (org-edit-headline "")
1821 (org-test-with-temp-text "* "
1822 (org-edit-headline "A")
1824 ;; Handle TODO keywords and priority cookies.
1827 (org-test-with-temp-text "* TODO A"
1828 (org-edit-headline "B")
1832 (org-test-with-temp-text "* [#A] A"
1833 (org-edit-headline "B")
1836 (equal "* TODO [#A] B"
1837 (org-test-with-temp-text "* TODO [#A] A"
1838 (org-edit-headline "B")
1842 (org-test-with-temp-text "* A :tag:"
1843 (let ((org-tags-column 4)) (org-edit-headline "B"))
1850 (ert-deftest test-org
/set-regexps-and-options
()
1851 "Test `org-set-regexps-and-options' specifications."
1855 (let ((org-tag-alist '(("A")))
1856 (org-tag-persistent-alist nil
))
1857 (org-test-with-temp-text ""
1859 org-current-tag-alist
))))
1862 (let ((org-tag-alist '(("A")))
1863 (org-tag-persistent-alist nil
))
1864 (org-test-with-temp-text "#+TAGS: B"
1866 org-current-tag-alist
))))
1868 (equal '(("C") ("B"))
1869 (let ((org-tag-alist '(("A")))
1870 (org-tag-persistent-alist '(("C"))))
1871 (org-test-with-temp-text "#+TAGS: B"
1873 org-current-tag-alist
))))
1876 (let ((org-tag-alist '(("A")))
1877 (org-tag-persistent-alist '(("C"))))
1878 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1880 org-current-tag-alist
))))
1882 (equal '(("A" . ?a
) ("B") ("C"))
1883 (let ((org-tag-persistant-alist nil
))
1884 (org-test-with-temp-text "#+TAGS: A(a) B C"
1886 org-current-tag-alist
))))
1888 (equal '(("A") (:newline
) ("B"))
1889 (let ((org-tag-persistent-alist nil
))
1890 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1892 org-current-tag-alist
))))
1894 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1895 (let ((org-tag-persistent-alist nil
))
1896 (org-test-with-temp-text "#+TAGS: { A B } C"
1898 org-current-tag-alist
))))
1900 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1901 (let ((org-tag-persistent-alist nil
))
1902 (org-test-with-temp-text "#+TAGS: { A : B C }"
1904 org-current-tag-alist
))))
1906 (equal '(("A" "B" "C"))
1907 (let ((org-tag-persistent-alist nil
))
1908 (org-test-with-temp-text "#+TAGS: { A : B C }"
1910 org-tag-groups-alist
))))
1912 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1913 (let ((org-tag-persistent-alist nil
))
1914 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1916 org-current-tag-alist
))))
1918 (equal '(("A" "B" "C"))
1919 (let ((org-tag-persistent-alist nil
))
1920 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1922 org-tag-groups-alist
))))
1923 ;; FILETAGS keyword.
1925 (equal '("A" "B" "C")
1926 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1929 ;; PROPERTY keyword. Property names are case-insensitive.
1932 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1934 (cdr (assoc "var" org-file-properties
)))))
1938 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1940 (cdr (assoc "var" org-file-properties
)))))
1944 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1946 (cdr (assoc "var" org-file-properties
)))))
1950 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1952 org-archive-location
)))
1953 ;; CATEGORY keyword.
1956 (org-test-with-temp-text "#+CATEGORY: test"
1961 (org-test-with-temp-text "#+CATEGORY: test"
1963 (cdr (assoc "CATEGORY" org-file-properties
)))))
1966 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1967 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1969 org-columns-default-format
)))
1970 ;; CONSTANTS keyword. Constants names are case sensitive.
1972 (equal '("299792458." "3.14")
1973 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1976 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1980 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1982 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1985 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1987 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1992 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1994 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1996 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2000 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2002 (list org-highest-priority org-lowest-priority org-default-priority
))))
2006 (org-test-with-temp-text "#+PRIORITIES: X Z"
2008 (list org-highest-priority org-lowest-priority org-default-priority
))))
2012 (org-test-with-temp-text "#+STARTUP: fold odd"
2014 (list org-startup-folded org-odd-levels-only
))))
2017 (equal '(("A" "B") ("C"))
2018 (org-test-with-temp-text "#+TODO: A B | C"
2020 (list org-not-done-keywords org-done-keywords
))))
2022 (equal '(("A" "C") ("B" "D"))
2023 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2025 (list org-not-done-keywords org-done-keywords
))))
2027 (equal '(("A" "B") ("C"))
2028 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2030 (list org-not-done-keywords org-done-keywords
))))
2032 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2033 (org-test-with-temp-text "#+TODO: A(a)"
2035 org-todo-key-alist
)))
2037 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2038 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2040 org-todo-log-states
)))
2041 ;; Enter SETUPFILE keyword.
2044 (org-test-with-temp-text
2045 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2047 (cdr (assoc "a" org-file-properties
))))))
2055 (ert-deftest test-org
/coderef
()
2056 "Test coderef links specifications."
2058 (org-test-with-temp-text "
2059 #+BEGIN_SRC emacs-lisp
2064 (looking-at "(ref:sc)")))
2065 ;; Find coderef even with alternate label format.
2067 (org-test-with-temp-text "
2068 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2073 (looking-at "{ref:sc}"))))
2077 (ert-deftest test-org
/custom-id
()
2078 "Test custom ID links specifications."
2080 (org-test-with-temp-text
2081 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2083 (looking-at-p "\\* H1")))
2084 ;; Throw an error on false positives.
2086 (org-test-with-temp-text
2087 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2089 (looking-at-p "\\* H1"))))
2093 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2094 ;; a named element (#+name: text) and to headlines (* Text).
2096 (ert-deftest test-org
/fuzzy-links
()
2097 "Test fuzzy links specifications."
2098 ;; Fuzzy link goes in priority to a matching target.
2100 (org-test-with-temp-text
2101 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2102 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2103 (looking-at "<<Test>>")))
2104 ;; Then fuzzy link points to an element with a given name.
2106 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2107 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2108 (looking-at "#\\+NAME: Test")))
2109 ;; A target still lead to a matching headline otherwise.
2111 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2112 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2113 (looking-at "\\* Head2")))
2114 ;; With a leading star in link, enforce heading match.
2116 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2117 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2118 (looking-at "\\* Test")))
2119 ;; With a leading star in link, enforce exact heading match, even
2120 ;; with `org-link-search-must-match-exact-headline' set to nil.
2122 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2123 (let ((org-link-search-must-match-exact-headline nil
))
2124 (org-open-at-point))))
2125 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2127 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2128 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2129 (looking-at "\\* Test")))
2131 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2132 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2133 (looking-at "\\* Test")))
2134 ;; Heading match should not care about spaces, cookies, TODO
2135 ;; keywords, priorities, and tags. However, TODO keywords are
2139 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2140 (org-test-with-temp-text
2141 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2142 (let ((org-link-search-must-match-exact-headline nil
)
2143 (org-todo-regexp "TODO"))
2144 (org-open-at-point))
2145 (looking-at (regexp-quote first-line
)))))
2147 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2148 (let ((org-link-search-must-match-exact-headline nil
)
2149 (org-todo-regexp "TODO"))
2150 (org-open-at-point))))
2151 ;; Heading match should still be exact.
2153 (org-test-with-temp-text "
2154 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2157 (let ((org-link-search-must-match-exact-headline nil
)
2158 (org-todo-regexp "TODO"))
2159 (org-open-at-point))))
2161 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2162 (let ((org-link-search-must-match-exact-headline nil
)
2163 (org-todo-regexp "TODO"))
2164 (org-open-at-point))
2165 (looking-at-p (regexp-quote "** Test 1 2"))))
2166 ;; Heading match ignores COMMENT keyword.
2168 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2170 (looking-at "\\* COMMENT Test")))
2172 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2174 (looking-at "\\* TODO COMMENT Test")))
2175 ;; Correctly un-hexify fuzzy links.
2177 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2181 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2187 (ert-deftest test-org
/org-link-escape-ascii-character
()
2188 "Escape an ascii character."
2192 (org-link-escape "["))))
2194 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2195 "Escape an ascii control character."
2199 (org-link-escape "\t"))))
2201 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2202 "Escape an unicode multibyte character."
2206 (org-link-escape "€"))))
2208 (ert-deftest test-org
/org-link-escape-custom-table
()
2209 "Escape string with custom character table."
2213 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2215 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2216 "Escape string with custom table merged with default table."
2219 "%5BF%6F%6F%3A%42ar%0A%5D"
2220 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2222 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2223 "Unescape an ascii character."
2227 (org-link-unescape "%5B"))))
2229 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2230 "Unescpae an ascii control character."
2234 (org-link-unescape "%0A"))))
2236 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2237 "Unescape unicode multibyte character."
2241 (org-link-unescape "%E2%82%AC"))))
2243 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2244 "Unescape old style percent escaped character."
2247 "à âçèéêîôùû"
2248 (decode-coding-string
2249 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2251 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2252 "Escape and unescape a URL that includes an escaped char.
2253 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2256 "http://some.host.com/form?&id=blah%2Bblah25"
2258 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2262 (ert-deftest test-org
/open-at-point-in-keyword
()
2263 "Does `org-open-at-point' open link in a keyword line?"
2265 (org-test-with-temp-text
2266 "<<top>>\n#+KEYWORD: <point>[[top]]"
2267 (org-open-at-point) t
)))
2269 (ert-deftest test-org
/open-at-point-in-property
()
2270 "Does `org-open-at-point' open link in property drawer?"
2272 (org-test-with-temp-text
2275 :URL: <point>[[*Headline]]
2277 (org-open-at-point) t
)))
2279 (ert-deftest test-org
/open-at-point-in-comment
()
2280 "Does `org-open-at-point' open link in a commented line?"
2282 (org-test-with-temp-text
2283 "<<top>>\n# <point>[[top]]"
2284 (org-open-at-point) t
)))
2286 (ert-deftest test-org
/open-at-point
/inline-image
()
2287 "Test `org-open-at-point' on nested links."
2289 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2293 (ert-deftest test-org
/open-at-point
/radio-target
()
2294 "Test `org-open-at-point' on radio targets."
2296 (org-test-with-temp-text "<<<target>>> <point>target"
2297 (org-update-radio-target-regexp)
2299 (eq (org-element-type (org-element-context)) 'radio-target
))))
2303 (ert-deftest test-org
/store-link
()
2304 "Test `org-store-link' specifications."
2305 ;; On a headline, link to that headline. Use heading as the
2306 ;; description of the link.
2308 (let (org-store-link-props org-stored-links
)
2309 (org-test-with-temp-text-in-file "* H1"
2310 (let ((file (buffer-file-name)))
2311 (equal (format "[[file:%s::*H1][H1]]" file
)
2312 (org-store-link nil
))))))
2313 ;; On a headline, remove any link from description.
2315 (let (org-store-link-props org-stored-links
)
2316 (org-test-with-temp-text-in-file "* [[#l][d]]"
2317 (let ((file (buffer-file-name)))
2318 (equal (format "[[file:%s::*%s][d]]"
2320 (org-link-escape "[[#l][d]]"))
2321 (org-store-link nil
))))))
2323 (let (org-store-link-props org-stored-links
)
2324 (org-test-with-temp-text-in-file "* [[l]]"
2325 (let ((file (buffer-file-name)))
2326 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2327 (org-store-link nil
))))))
2329 (let (org-store-link-props org-stored-links
)
2330 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2331 (let ((file (buffer-file-name)))
2332 (equal (format "[[file:%s::*%s][d1 d2]]"
2334 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2335 (org-store-link nil
))))))
2336 ;; On a named element, link to that element.
2338 (let (org-store-link-props org-stored-links
)
2339 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2340 (let ((file (buffer-file-name)))
2341 (equal (format "[[file:%s::foo][foo]]" file
)
2342 (org-store-link nil
)))))))
2347 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2348 "Ensure properties accumulate in subtree drawers."
2349 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2350 (org-babel-next-src-block)
2351 (should (equal '(2 1) (org-babel-execute-src-block)))))
2353 (ert-deftest test-org
/custom-properties
()
2354 "Test custom properties specifications."
2357 (let ((org-custom-properties '("FOO")))
2358 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2359 (org-toggle-custom-properties-visibility)
2360 (org-invisible-p2))))
2361 ;; Properties are case-insensitive.
2363 (let ((org-custom-properties '("FOO")))
2364 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2365 (org-toggle-custom-properties-visibility)
2366 (org-invisible-p2))))
2368 (let ((org-custom-properties '("foo")))
2369 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2370 (org-toggle-custom-properties-visibility)
2371 (org-invisible-p2))))
2372 ;; Multiple custom properties in the same drawer.
2374 (let ((org-custom-properties '("FOO" "BAR")))
2375 (org-test-with-temp-text
2376 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2377 (org-toggle-custom-properties-visibility)
2378 (and (org-invisible-p2)
2379 (not (progn (forward-line) (org-invisible-p2)))
2380 (progn (forward-line) (org-invisible-p2))))))
2381 ;; Hide custom properties with an empty value.
2383 (let ((org-custom-properties '("FOO")))
2384 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2385 (org-toggle-custom-properties-visibility)
2386 (org-invisible-p2))))
2387 ;; Do not hide fake properties.
2389 (let ((org-custom-properties '("FOO")))
2390 (org-test-with-temp-text ":FOO: val\n"
2391 (org-toggle-custom-properties-visibility)
2392 (org-invisible-p2))))
2394 (let ((org-custom-properties '("A")))
2395 (org-test-with-temp-text
2396 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2397 (org-toggle-custom-properties-visibility)
2398 (org-invisible-p2)))))
2404 (ert-deftest test-org
/mark-subtree
()
2405 "Test `org-mark-subtree' specifications."
2406 ;; Error when point is before first headline.
2408 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2409 (progn (transient-mark-mode 1)
2410 (org-mark-subtree))))
2411 ;; Without argument, mark current subtree.
2415 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2416 (progn (transient-mark-mode 1)
2419 (list (region-beginning) (region-end))))))
2420 ;; With an argument, move ARG up.
2424 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2425 (progn (transient-mark-mode 1)
2427 (org-mark-subtree 1)
2428 (list (region-beginning) (region-end))))))
2429 ;; Do not get fooled by inlinetasks.
2430 (when (featurep 'org-inlinetask
)
2433 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2434 (progn (transient-mark-mode 1)
2436 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2437 (region-beginning)))))))
2443 (ert-deftest test-org
/in-regexp
()
2444 "Test `org-in-regexp' specifications."
2447 (org-test-with-temp-text "xx ab<point>c xx"
2448 (org-in-regexp "abc")))
2450 (org-test-with-temp-text "xx abc <point>xx"
2451 (org-in-regexp "abc")))
2452 ;; Return non-nil even with multiple matching regexps in the same
2455 (org-test-with-temp-text "abc xx ab<point>c xx"
2456 (org-in-regexp "abc")))
2457 ;; With optional argument NLINES, check extra lines around point.
2459 (org-test-with-temp-text "A\nB<point>\nC"
2460 (org-in-regexp "A\nB\nC")))
2462 (org-test-with-temp-text "A\nB<point>\nC"
2463 (org-in-regexp "A\nB\nC" 1)))
2465 (org-test-with-temp-text "A\nB\nC<point>"
2466 (org-in-regexp "A\nB\nC" 1)))
2467 ;; When optional argument VISUALLY is non-nil, return nil if at
2468 ;; regexp boundaries.
2470 (org-test-with-temp-text "xx abc<point> xx"
2471 (org-in-regexp "abc")))
2473 (org-test-with-temp-text "xx abc<point> xx"
2474 (org-in-regexp "abc" nil t
))))
2479 (ert-deftest test-org
/end-of-meta-data
()
2480 "Test `org-end-of-meta-data' specifications."
2481 ;; Skip planning line.
2483 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2484 (org-end-of-meta-data)
2486 ;; Skip properties drawer.
2488 (org-test-with-temp-text
2489 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2490 (org-end-of-meta-data)
2494 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2495 (org-end-of-meta-data)
2497 ;; Nothing to skip, go to first line.
2499 (org-test-with-temp-text "* Headline\nContents"
2500 (org-end-of-meta-data)
2501 (looking-at "Contents")))
2502 ;; With option argument, skip empty lines, regular drawers and
2505 (org-test-with-temp-text "* Headline\n\nContents"
2506 (org-end-of-meta-data t
)
2507 (looking-at "Contents")))
2509 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2510 (org-end-of-meta-data t
)
2511 (looking-at "Contents")))
2513 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2514 (org-end-of-meta-data t
)
2515 (looking-at "Contents")))
2516 ;; Special case: do not skip incomplete drawers.
2518 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2519 (org-end-of-meta-data t
)
2520 (looking-at ":LOGBOOK:")))
2521 ;; Special case: Be careful about consecutive headlines.
2523 (org-test-with-temp-text "* H1\n*H2\nContents"
2524 (org-end-of-meta-data t
)
2525 (looking-at "Contents"))))
2527 (ert-deftest test-org
/beginning-of-line
()
2528 "Test `org-beginning-of-line' specifications."
2529 ;; Move to beginning of line. If current line in invisible, move to
2530 ;; beginning of visible line instead.
2532 (org-test-with-temp-text "Some text\nSome other text<point>"
2533 (org-beginning-of-line)
2536 (org-test-with-temp-text "* H1\n** H2<point>"
2538 (org-beginning-of-line)
2539 (= (line-beginning-position) 1)))
2540 ;; With `visual-line-mode' active, move to beginning of visual line.
2542 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2544 (dotimes (i 1000) (insert "very "))
2545 (org-beginning-of-line)
2547 ;; In a wide headline, with `visual-line-mode', prefer going to the
2548 ;; beginning of a visual line than to the logical beginning of line,
2549 ;; even if special movement is active.
2551 (org-test-with-temp-text "* A <point>long headline"
2553 (dotimes (i 1000) (insert "very "))
2554 (goto-char (point-max))
2555 (org-beginning-of-line)
2558 (org-test-with-temp-text "* A <point>long headline"
2560 (dotimes (i 1000) (insert "very "))
2561 (goto-char (point-max))
2562 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2564 ;; At an headline with special movement, first move at beginning of
2565 ;; title, then at the beginning of line, rinse, repeat.
2567 (org-test-with-temp-text "* TODO Headline<point>"
2568 (let ((org-special-ctrl-a/e t
))
2569 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2570 (progn (org-beginning-of-line) (bolp))
2571 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2573 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2574 (let ((org-special-ctrl-a/e t
))
2575 (org-beginning-of-line)
2576 (looking-at "Headline"))))
2578 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2579 (let ((org-special-ctrl-a/e
'(t . nil
)))
2580 (org-beginning-of-line)
2581 (looking-at "Headline"))))
2583 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2584 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2585 (org-beginning-of-line)
2586 (looking-at "Headline"))))
2587 ;; At an headline with reversed movement, first move to beginning of
2588 ;; line, then to the beginning of title.
2590 (org-test-with-temp-text "* TODO Headline<point>"
2591 (let ((org-special-ctrl-a/e
'reversed
)
2592 (this-command last-command
))
2593 (and (progn (org-beginning-of-line) (bolp))
2594 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2596 (org-test-with-temp-text "* TODO Headline<point>"
2597 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2598 (this-command last-command
))
2599 (and (progn (org-beginning-of-line) (bolp))
2600 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2602 (org-test-with-temp-text "* TODO Headline<point>"
2603 (let ((org-special-ctrl-a/e
'(t . nil
))
2604 (this-command last-command
))
2605 (and (progn (org-beginning-of-line) (bolp))
2606 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2607 ;; At an item with special movement, first move after to beginning
2608 ;; of title, then to the beginning of line, rinse, repeat.
2610 (org-test-with-temp-text "- [ ] Item<point>"
2611 (let ((org-special-ctrl-a/e t
))
2612 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2613 (progn (org-beginning-of-line) (bolp))
2614 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2615 ;; At an item with reversed movement, first move to beginning of
2616 ;; line, then to the beginning of title.
2618 (org-test-with-temp-text "- [X] Item<point>"
2619 (let ((org-special-ctrl-a/e
'reversed
)
2620 (this-command last-command
))
2621 (and (progn (org-beginning-of-line) (bolp))
2622 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2623 ;; Leave point before invisible characters at column 0.
2625 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2626 (let ((org-special-ctrl-a/e nil
))
2627 (org-beginning-of-line)
2630 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2631 (let ((org-special-ctrl-a/e t
))
2632 (org-beginning-of-line)
2635 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2637 (org-beginning-of-line)
2639 ;; Special case: Do not error when the buffer contains only a single
2642 (org-test-with-temp-text "*<point>"
2643 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2645 (org-test-with-temp-text "*<point>"
2646 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2648 (ert-deftest test-org
/end-of-line
()
2649 "Test `org-end-of-line' specifications."
2652 (org-test-with-temp-text "Some text\nSome other text"
2655 ;; With `visual-line-mode' active, move to end of visible line.
2656 ;; However, never go past ellipsis.
2658 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2660 (dotimes (i 1000) (insert "very "))
2661 (goto-char (point-min))
2665 (org-test-with-temp-text "* A short headline\nSome contents"
2670 ;; In a wide headline, with `visual-line-mode', prefer going to end
2671 ;; of visible line if tags, or end of line, are farther.
2673 (org-test-with-temp-text "* A <point>long headline"
2675 (dotimes (i 1000) (insert "very "))
2676 (goto-char (point-min))
2680 (org-test-with-temp-text "* A <point>long headline :tag:"
2682 (dotimes (i 1000) (insert "very "))
2683 (goto-char (point-min))
2686 ;; At an headline without special movement, go to end of line.
2687 ;; However, never go past ellipsis.
2689 (org-test-with-temp-text "* Headline2b :tag:\n"
2690 (let ((org-special-ctrl-a/e nil
))
2691 (and (progn (org-end-of-line) (eolp))
2692 (progn (org-end-of-line) (eolp))))))
2694 (org-test-with-temp-text "* Headline2b :tag:\n"
2695 (let ((org-special-ctrl-a/e
'(t . nil
)))
2696 (and (progn (org-end-of-line) (eolp))
2697 (progn (org-end-of-line) (eolp))))))
2699 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2701 (let ((org-special-ctrl-a/e nil
))
2703 (= 1 (line-beginning-position)))))
2704 ;; At an headline with special movement, first move before tags,
2705 ;; then at the end of line, rinse, repeat. However, never go past
2708 (org-test-with-temp-text "* Headline1 :tag:\n"
2709 (let ((org-special-ctrl-a/e t
))
2710 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2711 (progn (org-end-of-line) (eolp))
2712 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2714 (org-test-with-temp-text "* Headline1 :tag:\n"
2715 (let ((org-special-ctrl-a/e
'(nil . t
)))
2716 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2717 (progn (org-end-of-line) (eolp))
2718 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2720 (org-test-with-temp-text "* Headline1 :tag:\n"
2721 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2722 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2723 (progn (org-end-of-line) (eolp))
2724 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2726 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2728 (let ((org-special-ctrl-a/e t
))
2731 (= 1 (line-beginning-position)))))
2732 ;; At an headline, with reversed movement, first go to end of line,
2733 ;; then before tags. However, never go past ellipsis.
2735 (org-test-with-temp-text "* Headline3 :tag:\n"
2736 (let ((org-special-ctrl-a/e
'reversed
)
2737 (this-command last-command
))
2738 (and (progn (org-end-of-line) (eolp))
2739 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2741 (org-test-with-temp-text "* Headline3 :tag:\n"
2742 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2743 (this-command last-command
))
2744 (and (progn (org-end-of-line) (eolp))
2745 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2747 (org-test-with-temp-text "* Headline3 :tag:\n"
2748 (let ((org-special-ctrl-a/e
'(nil . t
))
2749 (this-command last-command
))
2750 (and (progn (org-end-of-line) (eolp))
2751 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2753 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2755 (let ((org-special-ctrl-a/e
'reversed
))
2757 (= 1 (line-beginning-position)))))
2758 ;; At a block without hidden contents.
2760 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2761 (progn (org-end-of-line) (eolp))))
2762 ;; At a block with hidden contents.
2764 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2765 (let ((org-special-ctrl-a/e t
))
2766 (org-hide-block-toggle)
2769 ;; Get past invisible characters at the end of line.
2771 (org-test-with-temp-text "[[http://orgmode.org]]"
2775 (ert-deftest test-org
/open-line
()
2776 "Test `org-open-line' specifications."
2777 ;; Call `open-line' outside of tables.
2780 (org-test-with-temp-text "Text"
2783 ;; At a table, create a row above.
2785 (equal "\n| |\n| a |"
2786 (org-test-with-temp-text "\n<point>| a |"
2789 ;; At the very first character of the buffer, also call `open-line'.
2792 (org-test-with-temp-text "| a |"
2795 ;; Narrowing does not count.
2797 (equal "Text\n| |\n| a |"
2798 (org-test-with-temp-text "Text\n<point>| a |"
2799 (narrow-to-region (point) (point-max))
2804 (ert-deftest test-org
/forward-sentence
()
2805 "Test `org-forward-sentence' specifications."
2806 ;; At the end of a table cell, move to the end of the next one.
2808 (org-test-with-temp-text "| a<point> | b |"
2809 (org-forward-sentence)
2810 (looking-at " |$")))
2811 ;; Elsewhere in a cell, move to its end.
2813 (org-test-with-temp-text "| a<point>c | b |"
2814 (org-forward-sentence)
2815 (looking-at " | b |$")))
2816 ;; Otherwise, simply call `forward-sentence'.
2818 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2819 (org-forward-sentence)
2820 (looking-at " Sentence 2.")))
2822 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2823 (org-forward-sentence)
2824 (org-forward-sentence)
2826 ;; At the end of an element, jump to the next one, without stopping
2827 ;; on blank lines in-between.
2829 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2830 (org-forward-sentence)
2833 (ert-deftest test-org
/backward-sentence
()
2834 "Test `org-backward-sentence' specifications."
2835 ;; At the beginning of a table cell, move to the beginning of the
2838 (org-test-with-temp-text "| a | <point>b |"
2839 (org-backward-sentence)
2840 (looking-at "a | b |$")))
2841 ;; Elsewhere in a cell, move to its beginning.
2843 (org-test-with-temp-text "| a | b<point>c |"
2844 (org-backward-sentence)
2845 (looking-at "bc |$")))
2846 ;; Otherwise, simply call `backward-sentence'.
2848 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2849 (org-backward-sentence)
2850 (looking-at "Sentence 2.")))
2852 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2853 (org-backward-sentence)
2854 (org-backward-sentence)
2856 ;; Make sure to hit the beginning of a sentence on the same line as
2859 (org-test-with-temp-text "- Line 1\n line <point>2."
2860 (org-backward-sentence)
2861 (looking-at "Line 1"))))
2863 (ert-deftest test-org
/forward-paragraph
()
2864 "Test `org-forward-paragraph' specifications."
2865 ;; At end of buffer, return an error.
2867 (org-test-with-temp-text "Paragraph"
2868 (goto-char (point-max))
2869 (org-forward-paragraph)))
2872 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2873 (org-forward-paragraph)
2877 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2878 (org-forward-paragraph)
2880 ;; Do not enter elements with invisible contents.
2882 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2883 (org-hide-block-toggle)
2884 (org-forward-paragraph)
2886 ;; On an affiliated keyword, jump to the beginning of the element.
2888 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2889 (org-forward-paragraph)
2890 (looking-at "Para")))
2891 ;; On an item or a footnote definition, move to the second element
2894 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2895 (org-forward-paragraph)
2896 (looking-at " Paragraph")))
2898 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2899 (org-forward-paragraph)
2900 (looking-at "Paragraph")))
2901 ;; On an item, or a footnote definition, when the first line is
2902 ;; empty, move to the first item.
2904 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2905 (org-forward-paragraph)
2906 (looking-at " Paragraph")))
2908 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2909 (org-forward-paragraph)
2910 (looking-at "Paragraph")))
2911 ;; On a table (resp. a property drawer) do not move through table
2912 ;; rows (resp. node properties).
2914 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2915 (org-forward-paragraph)
2916 (looking-at "Paragraph")))
2918 (org-test-with-temp-text
2919 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2920 (org-forward-paragraph)
2921 (looking-at "Paragraph")))
2922 ;; On a verse or source block, stop after blank lines.
2924 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2925 (org-forward-paragraph)
2928 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2929 (org-forward-paragraph)
2930 (looking-at "L2"))))
2932 (ert-deftest test-org
/backward-paragraph
()
2933 "Test `org-backward-paragraph' specifications."
2934 ;; Error at beginning of buffer.
2936 (org-test-with-temp-text "Paragraph"
2937 (org-backward-paragraph)))
2940 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2941 (goto-char (point-max))
2942 (org-backward-paragraph)
2945 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2946 (goto-char (point-max))
2948 (org-backward-paragraph)
2952 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2953 (goto-char (point-max))
2955 (org-backward-paragraph)
2957 ;; Ignore invisible elements.
2959 (org-test-with-temp-text "* H1\n P1\n* H2"
2961 (goto-char (point-max))
2963 (org-backward-paragraph)
2965 ;; On an affiliated keyword, jump to the first one.
2967 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2968 (search-forward "c2")
2969 (org-backward-paragraph)
2970 (looking-at "#\\+name")))
2971 ;; On the second element in an item or a footnote definition, jump
2972 ;; to item or the definition.
2974 (org-test-with-temp-text "- line1\n\n line2"
2975 (goto-char (point-max))
2977 (org-backward-paragraph)
2978 (looking-at "- line1")))
2980 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2981 (goto-char (point-max))
2983 (org-backward-paragraph)
2984 (looking-at "\\[fn:1\\] line1")))
2985 ;; On a table (resp. a property drawer), ignore table rows
2986 ;; (resp. node properties).
2988 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2989 (goto-char (point-max))
2991 (org-backward-paragraph)
2994 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2995 (org-backward-paragraph)
2996 (looking-at ":PROPERTIES:")))
2997 ;; On a source or verse block, stop before blank lines.
2999 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3000 (search-forward "L3")
3002 (org-backward-paragraph)
3005 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3006 (search-forward "L3")
3008 (org-backward-paragraph)
3009 (looking-at "L2"))))
3011 (ert-deftest test-org
/forward-element
()
3012 "Test `org-forward-element' specifications."
3013 ;; 1. At EOB: should error.
3014 (org-test-with-temp-text "Some text\n"
3015 (goto-char (point-max))
3016 (should-error (org-forward-element)))
3017 ;; 2. Standard move: expected to ignore blank lines.
3018 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3019 (org-forward-element)
3020 (should (looking-at (regexp-quote "Second paragraph."))))
3021 ;; 3. Headline tests.
3022 (org-test-with-temp-text "
3027 ;; 3.1. At an headline beginning: move to next headline at the
3030 (org-forward-element)
3031 (should (looking-at (regexp-quote "** Head 1.2")))
3032 ;; 3.2. At an headline beginning: move to parent headline if no
3033 ;; headline at the same level.
3035 (org-forward-element)
3036 (should (looking-at (regexp-quote "** Head 1.2"))))
3037 ;; 4. Greater element tests.
3038 (org-test-with-temp-text
3039 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3040 ;; 4.1. At a greater element: expected to skip contents.
3041 (org-forward-element)
3042 (should (looking-at (regexp-quote "Outside.")))
3043 ;; 4.2. At the end of greater element contents: expected to skip
3044 ;; to the end of the greater element.
3046 (org-forward-element)
3047 (should (looking-at (regexp-quote "Outside."))))
3049 (org-test-with-temp-text "
3063 ;; 5.1. At list top point: expected to move to the element after
3066 (org-forward-element)
3067 (should (looking-at (regexp-quote "Outside.")))
3068 ;; 5.2. Special case: at the first line of a sub-list, but not at
3069 ;; beginning of line, move to next item.
3072 (org-forward-element)
3073 (should (looking-at "- item2"))
3076 (org-forward-element)
3077 (should (looking-at " - sub2"))
3078 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3080 (org-forward-element)
3081 (should (looking-at (regexp-quote " Inner paragraph.")))
3082 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3084 (org-forward-element)
3085 (should (looking-at (regexp-quote " Inner paragraph.")))
3086 ;; 5.5. At an item: expected to move to next item, if any.
3088 (org-forward-element)
3089 (should (looking-at " - sub3"))))
3091 (ert-deftest test-org
/backward-element
()
3092 "Test `org-backward-element' specifications."
3093 ;; 1. Should error at BOB.
3094 (org-test-with-temp-text " \nParagraph."
3095 (should-error (org-backward-element)))
3096 ;; 2. Should move at BOB when called on the first element in buffer.
3098 (org-test-with-temp-text "\n#+TITLE: test"
3099 (progn (forward-line)
3100 (org-backward-element)
3102 ;; 3. Not at the beginning of an element: move at its beginning.
3103 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3106 (org-backward-element)
3107 (should (looking-at (regexp-quote "Paragraph2."))))
3108 ;; 4. Headline tests.
3109 (org-test-with-temp-text "
3114 ;; 4.1. At an headline beginning: move to previous headline at the
3117 (org-backward-element)
3118 (should (looking-at (regexp-quote "** Head 1.1")))
3119 ;; 4.2. At an headline beginning: move to parent headline if no
3120 ;; headline at the same level.
3122 (org-backward-element)
3123 (should (looking-at (regexp-quote "* Head 1")))
3124 ;; 4.3. At the first top-level headline: should error.
3126 (should-error (org-backward-element)))
3127 ;; 5. At beginning of first element inside a greater element:
3128 ;; expected to move to greater element's beginning.
3129 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3131 (org-backward-element)
3132 (should (looking-at "#\\+BEGIN_CENTER")))
3133 ;; 6. At the beginning of the first element in a section: should
3134 ;; move back to headline, if any.
3136 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3137 (progn (goto-char (point-max))
3139 (org-backward-element)
3140 (org-at-heading-p))))
3142 (org-test-with-temp-text "
3157 ;; 7.1. At beginning of sub-list: expected to move to the
3158 ;; paragraph before it.
3160 (org-backward-element)
3161 (should (looking-at "item1"))
3162 ;; 7.2. At an item in a list: expected to move at previous item.
3164 (org-backward-element)
3165 (should (looking-at " - sub2"))
3167 (org-backward-element)
3168 (should (looking-at "- item1"))
3169 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3172 (org-backward-element)
3173 (should (looking-at " - sub1"))
3175 (org-backward-element)
3176 (should (looking-at "- item1"))
3177 ;; 7.4. At blank-lines before list end: expected to move to top
3180 (org-backward-element)
3181 (should (looking-at "- item1"))))
3183 (ert-deftest test-org
/up-element
()
3184 "Test `org-up-element' specifications."
3185 ;; 1. At BOB or with no surrounding element: should error.
3186 (org-test-with-temp-text "Paragraph."
3187 (should-error (org-up-element)))
3188 (org-test-with-temp-text "* Head1\n* Head2"
3190 (should-error (org-up-element)))
3191 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3193 (should-error (org-up-element)))
3194 ;; 2. At an headline: move to parent headline.
3195 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3198 (should (looking-at "\\* Head1")))
3199 ;; 3. Inside a greater element: move to greater element beginning.
3200 (org-test-with-temp-text
3201 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3204 (should (looking-at "#\\+BEGIN_CENTER")))
3206 (org-test-with-temp-text "* Top
3213 Paragraph within sub2.
3216 ;; 4.1. Within an item: move to the item beginning.
3219 (should (looking-at " - sub2"))
3220 ;; 4.2. At an item in a sub-list: move to parent item.
3223 (should (looking-at "- item1"))
3224 ;; 4.3. At an item in top list: move to beginning of whole list.
3227 (should (looking-at "- item1"))
3228 ;; 4.4. Special case. At very top point: should move to parent of
3232 (should (looking-at "\\* Top"))))
3234 (ert-deftest test-org
/down-element
()
3235 "Test `org-down-element' specifications."
3236 ;; Error when the element hasn't got a recursive type.
3237 (org-test-with-temp-text "Paragraph."
3238 (should-error (org-down-element)))
3239 ;; Error when the element has no contents
3240 (org-test-with-temp-text "* Headline"
3241 (should-error (org-down-element)))
3242 ;; When at a plain-list, move to first item.
3243 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3246 (should (looking-at " - Item 1.1")))
3247 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3249 (should (looking-at " Item 1")))
3250 ;; When at a table, move to first row
3251 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3253 (should (looking-at " a | b |")))
3254 ;; Otherwise, move inside the greater element.
3255 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3257 (should (looking-at "Paragraph"))))
3259 (ert-deftest test-org
/drag-element-backward
()
3260 "Test `org-drag-element-backward' specifications."
3264 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3265 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3266 (org-drag-element-backward)
3270 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3271 (org-test-with-temp-text
3272 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3273 (org-drag-element-backward)
3275 ;; Preserve blank lines.
3277 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3278 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3279 (org-drag-element-backward)
3283 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3284 (org-drag-element-backward)
3285 (looking-at-p "2")))
3286 ;; Error when trying to move first element of buffer.
3288 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3289 (org-drag-element-backward))
3291 ;; Error when trying to swap nested elements.
3293 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3294 (org-drag-element-backward))
3296 ;; Error when trying to swap an headline element and a non-headline
3299 (org-test-with-temp-text "Test.\n<point>* Head 1"
3300 (org-drag-element-backward))
3302 ;; Error when called before first element.
3304 (org-test-with-temp-text "\n<point>"
3305 (org-drag-element-backward))
3307 ;; Preserve visibility of elements and their contents.
3309 (equal '((63 .
82) (26 .
48))
3310 (org-test-with-temp-text "
3318 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3319 (search-backward "- item 1")
3320 (org-drag-element-backward)
3321 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3322 (overlays-in (point-min) (point-max))))))
3323 ;; Pathological case: handle call with point in blank lines right
3324 ;; after a headline.
3326 (equal "* H2\n* H1\nText\n\n"
3327 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3328 (org-drag-element-backward)
3331 (ert-deftest test-org
/drag-element-forward
()
3332 "Test `org-drag-element-forward' specifications."
3333 ;; 1. Error when trying to move first element of buffer.
3334 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3336 (should-error (org-drag-element-forward)))
3337 ;; 2. Error when trying to swap nested elements.
3338 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3340 (should-error (org-drag-element-forward)))
3341 ;; 3. Error when trying to swap a non-headline element and an
3343 (org-test-with-temp-text "Test.\n* Head 1"
3344 (should-error (org-drag-element-forward)))
3345 ;; 4. Error when called before first element.
3347 (org-test-with-temp-text "\n"
3349 (org-drag-element-backward))
3351 ;; 5. Otherwise, swap elements, preserving column and blank lines
3352 ;; between elements.
3353 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3354 (search-forward "graph")
3355 (org-drag-element-forward)
3356 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3357 (should (looking-at " 1")))
3358 ;; 5. Preserve visibility of elements and their contents.
3359 (org-test-with-temp-text "
3367 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3368 (search-backward "#+BEGIN_CENTER")
3369 (org-drag-element-forward)
3372 '((63 .
82) (26 .
48))
3373 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3374 (overlays-in (point-min) (point-max)))))))
3376 (ert-deftest test-org
/next-block
()
3377 "Test `org-next-block' specifications."
3380 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3382 (looking-at "#\\+BEGIN_CENTER")))
3385 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3386 (let ((case-fold-search nil
))
3388 (looking-at "#\\+begin_center"))))
3389 ;; Ignore current line.
3391 (org-test-with-temp-text
3392 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3394 (looking-at "#\\+BEGIN_CENTER")))
3395 ;; Throw an error when no block is found.
3397 (org-test-with-temp-text "Paragraph"
3398 (org-next-block 1)))
3399 ;; With an argument, skip many blocks at once.
3401 (org-test-with-temp-text
3402 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3404 (looking-at "#\\+BEGIN_QUOTE")))
3405 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3407 (org-test-with-temp-text
3408 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3409 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3410 (looking-at "#\\+BEGIN_QUOTE")))
3411 ;; Optional argument is also case-insensitive.
3413 (org-test-with-temp-text
3414 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3415 (let ((case-fold-search nil
))
3416 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3417 (looking-at "#\\+begin_quote")))))
3419 (ert-deftest test-org
/previous-block
()
3420 "Test `org-previous-block' specifications."
3423 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3424 (org-previous-block 1)
3425 (looking-at "#\\+BEGIN_CENTER")))
3428 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3429 (let ((case-fold-search nil
))
3430 (org-previous-block 1)
3431 (looking-at "#\\+begin_center"))))
3432 ;; Ignore current line.
3434 (org-test-with-temp-text
3435 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3436 (org-previous-block 1)
3437 (looking-at "#\\+BEGIN_QUOTE")))
3438 ;; Throw an error when no block is found.
3440 (org-test-with-temp-text "Paragraph<point>"
3441 (org-previous-block 1)))
3442 ;; With an argument, skip many blocks at once.
3444 (org-test-with-temp-text
3445 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3446 (org-previous-block 2)
3447 (looking-at "#\\+BEGIN_CENTER")))
3448 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3450 (org-test-with-temp-text
3451 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3452 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3453 (looking-at "#\\+BEGIN_QUOTE")))
3454 ;; Optional argument is also case-insensitive.
3456 (org-test-with-temp-text
3457 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3458 (let ((case-fold-search nil
))
3459 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3460 (looking-at "#\\+begin_quote")))))
3463 ;;; Outline structure
3465 (ert-deftest test-org
/demote
()
3466 "Test `org-demote' specifications."
3467 ;; Add correct number of stars according to `org-odd-levels-only'.
3470 (org-test-with-temp-text "* H"
3471 (let ((org-odd-levels-only nil
)) (org-demote))
3472 (org-current-level))))
3475 (org-test-with-temp-text "* H"
3476 (let ((org-odd-levels-only t
)) (org-demote))
3477 (org-current-level))))
3478 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3480 (org-test-with-temp-text "* H :tag:"
3481 (let ((org-tags-column 10)
3482 (org-auto-align-tags t
)
3483 (org-odd-levels-only nil
))
3485 (org-move-to-column 10)
3486 (looking-at-p ":tag:$")))
3488 (org-test-with-temp-text "* H :tag:"
3489 (let ((org-tags-column 10)
3490 (org-auto-align-tags nil
)
3491 (org-odd-levels-only nil
))
3493 (org-move-to-column 10)
3494 (looking-at-p ":tag:$")))
3495 ;; When `org-adapt-indentation' is non-nil, always indent planning
3496 ;; info and property drawers accordingly.
3499 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3500 (let ((org-odd-levels-only nil
)
3501 (org-adapt-indentation t
))
3504 (org-get-indentation))))
3507 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3508 (let ((org-odd-levels-only nil
)
3509 (org-adapt-indentation t
))
3512 (org-get-indentation))))
3515 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3516 (let ((org-odd-levels-only nil
)
3517 (org-adapt-indentation nil
))
3520 (org-get-indentation))))
3521 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3522 ;; section accordingly. Ignore, however, footnote definitions and
3523 ;; inlinetasks boundaries.
3526 (org-test-with-temp-text "* H\n Paragraph"
3527 (let ((org-odd-levels-only nil
)
3528 (org-adapt-indentation t
))
3531 (org-get-indentation))))
3534 (org-test-with-temp-text "* H\n Paragraph"
3535 (let ((org-odd-levels-only nil
)
3536 (org-adapt-indentation nil
))
3539 (org-get-indentation))))
3542 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3543 (let ((org-odd-levels-only nil
)
3544 (org-adapt-indentation t
))
3546 (goto-char (point-max))
3547 (org-get-indentation))))
3550 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3551 (let ((org-odd-levels-only nil
)
3552 (org-adapt-indentation t
))
3554 (goto-char (point-max))
3555 (org-get-indentation))))
3556 (when (featurep 'org-inlinetask
)
3559 (let ((org-inlinetask-min-level 5)
3560 (org-adapt-indentation t
))
3561 (org-test-with-temp-text "* H\n***** I\n***** END"
3564 (org-get-indentation))))))
3565 (when (featurep 'org-inlinetask
)
3568 (let ((org-inlinetask-min-level 5)
3569 (org-adapt-indentation t
))
3570 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3573 (org-get-indentation))))))
3574 ;; Ignore contents of source blocks or example blocks when
3575 ;; indentation should be preserved (through
3576 ;; `org-src-preserve-indentation' or "-i" flag).
3579 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3580 (let ((org-adapt-indentation t
)
3581 (org-src-preserve-indentation nil
))
3584 (org-get-indentation))))
3587 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3588 (let ((org-adapt-indentation t
)
3589 (org-src-preserve-indentation t
))
3592 (org-get-indentation))))
3595 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3596 (let ((org-adapt-indentation t
)
3597 (org-src-preserve-indentation t
))
3600 (org-get-indentation))))
3603 (org-test-with-temp-text
3604 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3605 (let ((org-adapt-indentation t
)
3606 (org-src-preserve-indentation nil
))
3609 (org-get-indentation)))))
3611 (ert-deftest test-org
/promote
()
3612 "Test `org-promote' specifications."
3613 ;; Return an error if headline is to be promoted to level 0, unless
3614 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3615 ;; headline becomes a comment.
3617 (org-test-with-temp-text "* H"
3618 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3621 (org-test-with-temp-text "* H"
3622 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3624 ;; Remove correct number of stars according to
3625 ;; `org-odd-levels-only'.
3628 (org-test-with-temp-text "*** H"
3629 (let ((org-odd-levels-only nil
)) (org-promote))
3630 (org-current-level))))
3633 (org-test-with-temp-text "*** H"
3634 (let ((org-odd-levels-only t
)) (org-promote))
3635 (org-current-level))))
3636 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3638 (org-test-with-temp-text "** H :tag:"
3639 (let ((org-tags-column 10)
3640 (org-auto-align-tags t
)
3641 (org-odd-levels-only nil
))
3643 (org-move-to-column 10)
3644 (looking-at-p ":tag:$")))
3646 (org-test-with-temp-text "** H :tag:"
3647 (let ((org-tags-column 10)
3648 (org-auto-align-tags nil
)
3649 (org-odd-levels-only nil
))
3651 (org-move-to-column 10)
3652 (looking-at-p ":tag:$")))
3653 ;; When `org-adapt-indentation' is non-nil, always indent planning
3654 ;; info and property drawers.
3657 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3658 (let ((org-odd-levels-only nil
)
3659 (org-adapt-indentation t
))
3662 (org-get-indentation))))
3665 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3666 (let ((org-odd-levels-only nil
)
3667 (org-adapt-indentation t
))
3670 (org-get-indentation))))
3673 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3674 (let ((org-odd-levels-only nil
)
3675 (org-adapt-indentation nil
))
3678 (org-get-indentation))))
3679 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3680 ;; section accordingly. Ignore, however, footnote definitions and
3681 ;; inlinetasks boundaries.
3684 (org-test-with-temp-text "** H\n Paragraph"
3685 (let ((org-odd-levels-only nil
)
3686 (org-adapt-indentation t
))
3689 (org-get-indentation))))
3692 (org-test-with-temp-text "** H\n Paragraph"
3693 (let ((org-odd-levels-only nil
)
3694 (org-adapt-indentation nil
))
3697 (org-get-indentation))))
3700 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3701 (let ((org-odd-levels-only nil
)
3702 (org-adapt-indentation t
))
3705 (org-get-indentation))))
3706 (when (featurep 'org-inlinetask
)
3709 (let ((org-inlinetask-min-level 5)
3710 (org-adapt-indentation t
))
3711 (org-test-with-temp-text "** H\n***** I\n***** END"
3714 (org-get-indentation))))))
3715 (when (featurep 'org-inlinetask
)
3718 (let ((org-inlinetask-min-level 5)
3719 (org-adapt-indentation t
))
3720 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3723 (org-get-indentation))))))
3724 ;; Give up shifting if it would break document's structure
3728 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3729 (let ((org-odd-levels-only nil
)
3730 (org-adapt-indentation t
))
3733 (org-get-indentation))))
3736 (org-test-with-temp-text "** H\n Paragraph\n * list."
3737 (let ((org-odd-levels-only nil
)
3738 (org-adapt-indentation t
))
3741 (org-get-indentation))))
3742 ;; Ignore contents of source blocks or example blocks when
3743 ;; indentation should be preserved (through
3744 ;; `org-src-preserve-indentation' or "-i" flag).
3747 (org-test-with-temp-text
3748 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3749 (let ((org-adapt-indentation t
)
3750 (org-src-preserve-indentation nil
)
3751 (org-odd-levels-only nil
))
3754 (org-get-indentation))))
3757 (org-test-with-temp-text
3758 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3759 (let ((org-adapt-indentation t
)
3760 (org-src-preserve-indentation t
)
3761 (org-odd-levels-only nil
))
3764 (org-get-indentation))))
3767 (org-test-with-temp-text
3768 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3769 (let ((org-adapt-indentation t
)
3770 (org-src-preserve-indentation t
)
3771 (org-odd-levels-only nil
))
3774 (org-get-indentation))))
3777 (org-test-with-temp-text
3778 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3779 (let ((org-adapt-indentation t
)
3780 (org-src-preserve-indentation nil
)
3781 (org-odd-levels-only nil
))
3784 (org-get-indentation)))))
3789 (ert-deftest test-org
/at-planning-p
()
3790 "Test `org-at-planning-p' specifications."
3793 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3794 (org-at-planning-p)))
3796 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3797 (org-at-planning-p)))
3798 ;; Correctly find planning attached to inlinetasks.
3799 (when (featurep 'org-inlinetask
)
3801 (org-test-with-temp-text
3802 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3803 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3805 (org-test-with-temp-text
3806 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3807 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3809 (org-test-with-temp-text
3810 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3811 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3813 (org-test-with-temp-text
3814 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3815 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3817 (ert-deftest test-org
/add-planning-info
()
3818 "Test `org-add-planning-info'."
3819 ;; Create deadline when `org-adapt-indentation' is non-nil.
3821 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3822 (org-test-with-temp-text "* H\nParagraph<point>"
3823 (let ((org-adapt-indentation t
))
3824 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3825 (replace-regexp-in-string
3826 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3828 ;; Create deadline when `org-adapt-indentation' is nil.
3830 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3831 (org-test-with-temp-text "* H\nParagraph<point>"
3832 (let ((org-adapt-indentation nil
))
3833 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3834 (replace-regexp-in-string
3835 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3837 ;; Update deadline when `org-adapt-indentation' is non-nil.
3839 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3840 (org-test-with-temp-text "\
3842 DEADLINE: <2015-06-24 Wed>
3844 (let ((org-adapt-indentation t
))
3845 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3846 (replace-regexp-in-string
3847 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3849 ;; Update deadline when `org-adapt-indentation' is nil.
3851 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3852 (org-test-with-temp-text "\
3854 DEADLINE: <2015-06-24 Wed>
3856 (let ((org-adapt-indentation nil
))
3857 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3858 (replace-regexp-in-string
3859 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3861 ;; Schedule when `org-adapt-indentation' is non-nil.
3863 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3864 (org-test-with-temp-text "* H\nParagraph<point>"
3865 (let ((org-adapt-indentation t
))
3866 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3867 (replace-regexp-in-string
3868 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3870 ;; Schedule when `org-adapt-indentation' is nil.
3872 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3873 (org-test-with-temp-text "* H\nParagraph<point>"
3874 (let ((org-adapt-indentation nil
))
3875 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3876 (replace-regexp-in-string
3877 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3879 ;; Add deadline when scheduled.
3883 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3885 (org-test-with-temp-text "\
3887 SCHEDULED: <2015-06-24 Wed>
3889 (let ((org-adapt-indentation t
))
3890 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3891 (replace-regexp-in-string
3892 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3894 ;; Remove middle entry.
3898 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3900 (org-test-with-temp-text "\
3902 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3904 (let ((org-adapt-indentation t
))
3905 (org-add-planning-info nil nil
'deadline
))
3906 (replace-regexp-in-string
3907 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3909 ;; Remove last entry and then middle entry (order should not
3914 CLOSED: [2015-06-24]
3916 (org-test-with-temp-text "\
3918 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3920 (let ((org-adapt-indentation t
))
3921 (org-add-planning-info nil nil
'scheduled
'deadline
))
3922 (replace-regexp-in-string
3923 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3925 ;; Remove closed when `org-adapt-indentation' is non-nil.
3927 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3928 (org-test-with-temp-text "\
3930 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3932 (let ((org-adapt-indentation t
))
3933 (org-add-planning-info nil nil
'closed
))
3934 (replace-regexp-in-string
3935 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3938 (equal "* H\n Paragraph"
3939 (org-test-with-temp-text "\
3941 CLOSED: [2015-06-25 Thu]
3943 (let ((org-adapt-indentation t
))
3944 (org-add-planning-info nil nil
'closed
))
3945 (replace-regexp-in-string
3946 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3948 ;; Remove closed when `org-adapt-indentation' is nil.
3950 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3951 (org-test-with-temp-text "\
3953 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3955 (let ((org-adapt-indentation nil
))
3956 (org-add-planning-info nil nil
'closed
))
3957 (replace-regexp-in-string
3958 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3961 (equal "* H\nParagraph"
3962 (org-test-with-temp-text "\
3964 CLOSED: [2015-06-25 Thu]
3966 (let ((org-adapt-indentation nil
))
3967 (org-add-planning-info nil nil
'closed
))
3968 (replace-regexp-in-string
3969 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3971 ;; Remove closed entry and delete empty line.
3976 (org-test-with-temp-text "\
3978 CLOSED: [2015-06-24 Wed]
3980 (let ((org-adapt-indentation t
))
3981 (org-add-planning-info nil nil
'closed
))
3982 (replace-regexp-in-string
3983 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3985 ;; Remove one entry and update another.
3987 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3988 (org-test-with-temp-text "\
3990 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3992 (let ((org-adapt-indentation t
))
3993 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3994 (replace-regexp-in-string
3995 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4001 (ert-deftest test-org
/buffer-property-keys
()
4002 "Test `org-buffer-property-keys' specifications."
4003 ;; Retrieve properties accross siblings.
4006 (org-test-with-temp-text "
4015 (org-buffer-property-keys))))
4016 ;; Retrieve properties accross children.
4019 (org-test-with-temp-text "
4028 (org-buffer-property-keys))))
4029 ;; Retrieve muliple properties in the same drawer.
4032 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4033 (org-buffer-property-keys))))
4034 ;; Ignore extension symbol in property name.
4037 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4038 (org-buffer-property-keys))))
4039 ;; With non-nil COLUMNS, extract property names from columns.
4042 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4043 (org-buffer-property-keys nil nil t
))))
4045 (equal '("A" "B" "COLUMNS")
4046 (org-test-with-temp-text
4047 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4048 (org-buffer-property-keys nil nil t
))))
4049 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4052 (org-test-with-temp-text
4053 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4054 (org-buffer-property-keys nil nil nil t
)))))
4056 (ert-deftest test-org
/property-values
()
4057 "Test `org-property-values' specifications."
4061 (org-test-with-temp-text
4062 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4063 (org-property-values "A"))))
4064 ;; Ignore empty values.
4066 (org-test-with-temp-text
4067 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4068 (org-property-values "A")))
4069 ;; Take into consideration extended values.
4072 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4073 (org-property-values "A")))))
4075 (ert-deftest test-org
/find-property
()
4076 "Test `org-find-property' specifications."
4080 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4081 (org-find-property "prop"))))
4082 ;; Ignore false positives.
4085 (org-test-with-temp-text
4086 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4087 (org-find-property "A"))))
4088 ;; Return first entry found in buffer.
4091 (org-test-with-temp-text
4092 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4093 (org-find-property "A"))))
4094 ;; Only search visible part of the buffer.
4097 (org-test-with-temp-text
4098 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4099 (org-narrow-to-subtree)
4100 (org-find-property "A"))))
4101 ;; With optional argument, only find entries with a specific value.
4103 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4104 (org-find-property "A" "2")))
4107 (org-test-with-temp-text
4108 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4109 (org-find-property "A" "2"))))
4110 ;; Use "nil" for explicit nil values.
4113 (org-test-with-temp-text
4114 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4115 (org-find-property "A" "nil")))))
4117 (ert-deftest test-org
/entry-delete
()
4118 "Test `org-entry-delete' specifications."
4122 " *:PROPERTIES:\n *:B: +2\n *:END:"
4123 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4124 (org-entry-delete (point) "A")
4126 ;; Also remove accumulated properties.
4130 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4131 (org-entry-delete (point) "A")
4133 ;; When last property is removed, remove the property drawer.
4137 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4138 (org-entry-delete (point) "A")
4140 ;; Return a non-nil value when some property was removed.
4142 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4143 (org-entry-delete (point) "A")))
4145 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4146 (org-entry-delete (point) "C"))))
4148 (ert-deftest test-org
/entry-get
()
4149 "Test `org-entry-get' specifications."
4153 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4154 (org-entry-get (point) "A"))))
4158 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4159 (org-entry-get (point) "a"))))
4160 ;; Handle extended values, both before and after base value.
4163 (org-test-with-temp-text
4164 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4165 (org-entry-get (point) "A"))))
4166 ;; Empty values are returned as the empty string.
4169 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4170 (org-entry-get (point) "A"))))
4171 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4172 ;; otherwise, return nil.
4174 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4175 (org-entry-get (point) "A")))
4178 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4179 (org-entry-get (point) "A" nil t
))))
4180 ;; Return nil when no property is found, independently on the
4181 ;; LITERAL-NIL argument.
4183 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4184 (org-entry-get (point) "B")))
4186 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4187 (org-entry-get (point) "B" nil t
)))
4188 ;; Handle inheritance, when allowed. Include extended values and
4189 ;; possibly global values.
4193 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4194 (org-entry-get (point) "A" t
))))
4198 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4199 (let ((org-use-property-inheritance t
))
4200 (org-entry-get (point) "A" 'selective
)))))
4202 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4203 (let ((org-use-property-inheritance nil
))
4204 (org-entry-get (point) "A" 'selective
))))
4208 (org-test-with-temp-text
4209 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4210 (org-entry-get (point-max) "A" t
))))
4213 (org-test-with-temp-text
4214 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4216 (org-entry-get (point-max) "A" t
))))
4219 (org-test-with-temp-text
4220 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4222 (org-entry-get (point-max) "A" t
)))))
4224 (ert-deftest test-org
/entry-properties
()
4225 "Test `org-entry-properties' specifications."
4226 ;; Get "ITEM" property.
4229 (org-test-with-temp-text "* TODO H"
4230 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4233 (org-test-with-temp-text "* TODO H"
4234 (cdr (assoc "ITEM" (org-entry-properties))))))
4235 ;; Get "TODO" property. TODO keywords are case sensitive.
4238 (org-test-with-temp-text "* TODO H"
4239 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4242 (org-test-with-temp-text "* TODO H"
4243 (cdr (assoc "TODO" (org-entry-properties))))))
4245 (org-test-with-temp-text "* H"
4246 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4248 (org-test-with-temp-text "* todo H"
4249 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4250 ;; Get "PRIORITY" property.
4253 (org-test-with-temp-text "* [#A] H"
4254 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4257 (org-test-with-temp-text "* [#A] H"
4258 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4260 (equal (char-to-string org-default-priority
)
4261 (org-test-with-temp-text "* H"
4262 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4263 ;; Get "FILE" property.
4265 (org-test-with-temp-text-in-file "* H\nParagraph"
4266 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4267 (buffer-file-name))))
4269 (org-test-with-temp-text-in-file "* H\nParagraph"
4270 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4271 (buffer-file-name))))
4273 (org-test-with-temp-text "* H\nParagraph"
4274 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4275 ;; Get "TAGS" property.
4277 (equal ":tag1:tag2:"
4278 (org-test-with-temp-text "* H :tag1:tag2:"
4279 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4281 (equal ":tag1:tag2:"
4282 (org-test-with-temp-text "* H :tag1:tag2:"
4283 (cdr (assoc "TAGS" (org-entry-properties))))))
4285 (org-test-with-temp-text "* H"
4286 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4287 ;; Get "ALLTAGS" property.
4289 (equal ":tag1:tag2:"
4290 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4291 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4293 (equal ":tag1:tag2:"
4294 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4295 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4297 (org-test-with-temp-text "* H"
4298 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4299 ;; Get "BLOCKED" property.
4302 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4303 (let ((org-enforce-todo-dependencies t
)
4305 '(org-block-todo-from-children-or-siblings-or-parent)))
4306 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4309 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4310 (let ((org-enforce-todo-dependencies t
)
4312 '(org-block-todo-from-children-or-siblings-or-parent)))
4313 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4314 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4318 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4319 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4323 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4324 (cdr (assoc "CLOSED" (org-entry-properties))))))
4326 (org-test-with-temp-text "* H"
4327 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4331 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4332 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4336 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4337 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4339 (org-test-with-temp-text "* H"
4340 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4344 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4345 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4349 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4350 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4352 (org-test-with-temp-text "* H"
4353 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4357 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4358 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4361 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4362 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4365 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4366 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4369 (org-test-with-temp-text
4370 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4372 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4373 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4374 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4376 (equal "<2012-03-29 thu.>"
4377 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4378 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4380 (equal "[2012-03-29 thu.]"
4381 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4382 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4384 (equal "<2012-03-29 thu.>"
4385 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4386 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4388 (equal "[2014-03-04 tue.]"
4389 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4390 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
4391 ;; Get standard properties.
4394 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4395 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4396 ;; Handle extended properties.
4399 (org-test-with-temp-text
4400 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4401 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4404 (org-test-with-temp-text
4405 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4406 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4407 ;; Ignore forbidden (special) properties.
4409 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4410 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4412 (ert-deftest test-org
/entry-put
()
4413 "Test `org-entry-put' specifications."
4414 ;; Error when not a string or nil.
4416 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4417 (org-entry-put 1 "test" 2)))
4418 ;; Error when property name is invalid.
4420 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4421 (org-entry-put 1 "no space" "value")))
4423 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4424 (org-entry-put 1 "" "value")))
4425 ;; Set "TODO" property.
4427 (string-match (regexp-quote " TODO H")
4428 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4429 (org-entry-put (point) "TODO" "TODO")
4432 (string-match (regexp-quote "* H")
4433 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4434 (org-entry-put (point) "TODO" nil
)
4436 ;; Set "PRIORITY" property.
4439 (org-test-with-temp-text "* [#B] H"
4440 (org-entry-put (point) "PRIORITY" "A")
4444 (org-test-with-temp-text "* [#B] H"
4445 (org-entry-put (point) "PRIORITY" nil
)
4447 ;; Set "SCHEDULED" property.
4449 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4450 (org-test-with-temp-text "* H"
4451 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4455 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4456 (org-entry-put (point) "SCHEDULED" nil
)
4459 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4460 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4461 (org-entry-put (point) "SCHEDULED" "earlier")
4464 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4465 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4466 (org-entry-put (point) "SCHEDULED" "later")
4468 ;; Set "DEADLINE" property.
4470 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4471 (org-test-with-temp-text "* H"
4472 (org-entry-put (point) "DEADLINE" "2014-03-04")
4476 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4477 (org-entry-put (point) "DEADLINE" nil
)
4480 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4481 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4482 (org-entry-put (point) "DEADLINE" "earlier")
4485 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4486 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4487 (org-entry-put (point) "DEADLINE" "later")
4489 ;; Set "CATEGORY" property
4491 (string-match "^ *:CATEGORY: cat"
4492 (org-test-with-temp-text "* H"
4493 (org-entry-put (point) "CATEGORY" "cat")
4495 ;; Regular properties, with or without pre-existing drawer.
4497 (string-match "^ *:A: +2$"
4498 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4499 (org-entry-put (point) "A" "2")
4502 (string-match "^ *:A: +1$"
4503 (org-test-with-temp-text "* H"
4504 (org-entry-put (point) "A" "1")
4506 ;; Special case: two consecutive headlines.
4508 (string-match "\\* A\n *:PROPERTIES:"
4509 (org-test-with-temp-text "* A\n** B"
4510 (org-entry-put (point) "A" "1")
4516 (ert-deftest test-org
/update-radio-target-regexp
()
4517 "Test `org-update-radio-target-regexp' specifications."
4518 ;; Properly update cache with no previous radio target regexp.
4521 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4522 (save-excursion (goto-char (point-max)) (org-element-context))
4524 (search-forward "o")
4526 (org-update-radio-target-regexp)
4527 (goto-char (point-max))
4528 (org-element-type (org-element-context)))))
4529 ;; Properly update cache with previous radio target regexp.
4532 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4533 (save-excursion (goto-char (point-max)) (org-element-context))
4535 (search-forward "o")
4537 (org-update-radio-target-regexp)
4538 (search-backward "r")
4541 (org-update-radio-target-regexp)
4542 (goto-char (point-max))
4543 (delete-region (line-beginning-position) (point))
4545 (org-element-type (org-element-context))))))
4550 (ert-deftest test-org
/match-sparse-tree
()
4551 "Test `org-match-sparse-tree' specifications."
4554 (org-test-with-temp-text "* H\n** H1 :tag:"
4555 (org-match-sparse-tree nil
"tag")
4556 (search-forward "H1")
4557 (org-invisible-p2)))
4559 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4560 (org-match-sparse-tree nil
"tag")
4561 (search-forward "H2")
4562 (org-invisible-p2)))
4563 ;; "-" operator for tags.
4565 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4566 (org-match-sparse-tree nil
"tag1-tag2")
4567 (search-forward "H1")
4568 (org-invisible-p2)))
4570 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4571 (org-match-sparse-tree nil
"tag1-tag2")
4572 (search-forward "H2")
4573 (org-invisible-p2)))
4574 ;; "&" operator for tags.
4576 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4577 (org-match-sparse-tree nil
"tag1&tag2")
4578 (search-forward "H1")
4579 (org-invisible-p2)))
4581 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4582 (org-match-sparse-tree nil
"tag1&tag2")
4583 (search-forward "H2")
4584 (org-invisible-p2)))
4585 ;; "|" operator for tags.
4587 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4588 (org-match-sparse-tree nil
"tag1|tag2")
4589 (search-forward "H1")
4590 (org-invisible-p2)))
4592 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4593 (org-match-sparse-tree nil
"tag1|tag2")
4594 (search-forward "H2")
4595 (org-invisible-p2)))
4596 ;; Regexp match on tags.
4598 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4599 (org-match-sparse-tree nil
"{^tag.*}")
4600 (search-forward "H1")
4601 (org-invisible-p2)))
4603 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4604 (org-match-sparse-tree nil
"{^tag.*}")
4605 (search-forward "H2")
4606 (org-invisible-p2)))
4607 ;; Match group tags.
4609 (org-test-with-temp-text
4610 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4611 (org-match-sparse-tree nil
"work")
4612 (search-forward "H1")
4613 (org-invisible-p2)))
4615 (org-test-with-temp-text
4616 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4617 (org-match-sparse-tree nil
"work")
4618 (search-forward "H2")
4619 (org-invisible-p2)))
4620 ;; Match group tags with hard brackets.
4622 (org-test-with-temp-text
4623 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4624 (org-match-sparse-tree nil
"work")
4625 (search-forward "H1")
4626 (org-invisible-p2)))
4628 (org-test-with-temp-text
4629 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4630 (org-match-sparse-tree nil
"work")
4631 (search-forward "H2")
4632 (org-invisible-p2)))
4633 ;; Match tags in hierarchies
4635 (org-test-with-temp-text
4636 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4637 #+TAGS: [ Lev_2 : Lev_3 ]\n
4638 #+TAGS: { Lev_3 : Lev_4 }\n
4639 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4640 (org-match-sparse-tree nil
"Lev_1")
4641 (search-forward "H4")
4642 (org-invisible-p2)))
4643 ;; Match regular expressions in tags
4645 (org-test-with-temp-text
4646 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4647 (org-match-sparse-tree nil
"Lev")
4648 (search-forward "H1")
4649 (org-invisible-p2)))
4651 (org-test-with-temp-text
4652 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4653 (org-match-sparse-tree nil
"Lev")
4654 (search-forward "H1")
4655 (org-invisible-p2)))
4656 ;; Match properties.
4658 (org-test-with-temp-text
4659 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4660 (org-match-sparse-tree nil
"A=\"1\"")
4661 (search-forward "H2")
4662 (org-invisible-p2)))
4664 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4665 (org-match-sparse-tree nil
"A=\"1\"")
4666 (search-forward "H2")
4667 (org-invisible-p2)))
4668 ;; Case is not significant when matching properties.
4670 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4671 (org-match-sparse-tree nil
"a=\"1\"")
4672 (search-forward "H2")
4673 (org-invisible-p2)))
4675 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4676 (org-match-sparse-tree nil
"A=\"1\"")
4677 (search-forward "H2")
4678 (org-invisible-p2)))
4679 ;; Match special LEVEL property.
4681 (org-test-with-temp-text "* H\n** H1\n*** H2"
4682 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4683 (search-forward "H1")
4684 (org-invisible-p2)))
4686 (org-test-with-temp-text "* H\n** H1\n*** H2"
4687 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4688 (search-forward "H2")
4689 (org-invisible-p2)))
4690 ;; Comparison operators when matching properties.
4692 (org-test-with-temp-text
4693 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4694 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4695 (search-forward "H1")
4696 (org-invisible-p2)))
4698 (org-test-with-temp-text
4699 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4700 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4701 (search-forward "H2")
4702 (org-invisible-p2)))
4703 ;; Regexp match on properties values.
4705 (org-test-with-temp-text
4706 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4707 (org-match-sparse-tree nil
"A={f.*}")
4708 (search-forward "H1")
4709 (org-invisible-p2)))
4711 (org-test-with-temp-text
4712 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4713 (org-match-sparse-tree nil
"A={f.*}")
4714 (search-forward "H2")
4715 (org-invisible-p2)))
4716 ;; With an optional argument, limit match to TODO entries.
4718 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4719 (org-match-sparse-tree t
"tag")
4720 (search-forward "H1")
4721 (org-invisible-p2)))
4723 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4724 (org-match-sparse-tree t
"tag")
4725 (search-forward "H2")
4726 (org-invisible-p2))))
4728 (ert-deftest test-org
/occur
()
4729 "Test `org-occur' specifications."
4730 ;; Count number of matches.
4733 (org-test-with-temp-text "* H\nA\n* H2"
4737 (org-test-with-temp-text "* H\nA\n* H2\nA"
4739 ;; Test CALLBACK optional argument.
4742 (org-test-with-temp-text "* H\nA\n* H2"
4743 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4746 (org-test-with-temp-text "* H\nA\n* H2\nA"
4747 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4748 ;; Case-fold searches according to `org-occur-case-fold-search'.
4751 (org-test-with-temp-text "Aa"
4752 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
4755 (org-test-with-temp-text "Aa"
4756 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
4759 (org-test-with-temp-text "Aa"
4760 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
4763 (org-test-with-temp-text "Aa"
4764 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
4767 (org-test-with-temp-text "Aa"
4768 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
4771 (org-test-with-temp-text "Aa"
4772 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
4777 (ert-deftest test-org
/tag-string-to-alist
()
4778 "Test `org-tag-string-to-alist' specifications."
4779 ;; Tag without selection key.
4780 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
4781 ;; Tag with selection key.
4782 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
4786 (org-tag-string-to-alist "[ group : t1 t2 ]")
4787 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
4788 ;; Mutually exclusive tags.
4789 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
4790 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
4793 (org-tag-string-to-alist "{ group : tag1 tag2 }")
4794 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
4796 (ert-deftest test-org
/tag-alist-to-string
()
4797 "Test `org-tag-alist-to-string' specifications."
4798 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
4799 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
4802 (org-tag-alist-to-string
4803 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4804 "[ group : t1 t2 ]"))
4806 (equal (org-tag-alist-to-string
4807 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
4811 (org-tag-alist-to-string
4812 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
4813 "{ group : tag1 tag2 }")))
4815 (ert-deftest test-org
/tag-alist-to-groups
()
4816 "Test `org-tag-alist-to-groups' specifications."
4818 (equal (org-tag-alist-to-groups
4819 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
4820 '(("group" "t1" "t2"))))
4823 (org-tag-alist-to-groups
4824 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4825 '(("group" "t1" "t2"))))
4827 (org-tag-alist-to-groups
4828 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
4830 (ert-deftest test-org
/tag-align
()
4831 "Test tags alignment."
4832 ;; Test aligning tags with different display width.
4834 ;; 12345678901234567890
4835 (equal "* Test :abc:"
4836 (org-test-with-temp-text "* Test :abc:"
4837 (let ((org-tags-column -
20)
4838 (indent-tabs-mode nil
))
4839 (org-fix-tags-on-the-fly))
4842 ;; 12345678901234567890
4843 (equal "* Test :日本語:"
4844 (org-test-with-temp-text "* Test :日本語:"
4845 (let ((org-tags-column -
20)
4846 (indent-tabs-mode nil
))
4847 (org-fix-tags-on-the-fly))
4849 ;; Make sure aligning tags do not skip invisible text.
4851 (equal "* [[linkx]] :tag:"
4852 (org-test-with-temp-text "* [[link<point>]] :tag:"
4853 (let ((org-tags-column 0))
4854 (org-fix-tags-on-the-fly)
4856 (buffer-string))))))
4858 (ert-deftest test-org
/tags-at
()
4860 (equal '("foo" "bar")
4861 (org-test-with-temp-text
4862 "* T<point>est :foo:bar:"
4863 (org-get-tags-at)))))
4868 (ert-deftest test-org
/time-stamp
()
4869 "Test `org-time-stamp' specifications."
4870 ;; Insert chosen time stamp at point.
4873 "Te<2014-03-04 .*?>xt"
4874 (org-test-with-temp-text "Te<point>xt"
4875 (cl-letf (((symbol-function 'org-read-date
)
4876 (lambda (&rest args
)
4877 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4878 (org-time-stamp nil
)
4880 ;; With a prefix argument, also insert time.
4883 "Te<2014-03-04 .*? 00:41>xt"
4884 (org-test-with-temp-text "Te<point>xt"
4885 (cl-letf (((symbol-function 'org-read-date
)
4886 (lambda (&rest args
)
4887 (apply #'encode-time
4888 (org-parse-time-string "2014-03-04 00:41")))))
4889 (org-time-stamp '(4))
4891 ;; With two universal prefix arguments, insert an active timestamp
4892 ;; with the current time without prompting the user.
4895 "Te<2014-03-04 .*? 00:41>xt"
4896 (org-test-with-temp-text "Te<point>xt"
4897 (cl-letf (((symbol-function 'current-time
)
4899 (apply #'encode-time
4900 (org-parse-time-string "2014-03-04 00:41")))))
4901 (org-time-stamp '(16))
4903 ;; When optional argument is non-nil, insert an inactive timestamp.
4906 "Te\\[2014-03-04 .*?\\]xt"
4907 (org-test-with-temp-text "Te<point>xt"
4908 (cl-letf (((symbol-function 'org-read-date
)
4909 (lambda (&rest args
)
4910 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4911 (org-time-stamp nil t
)
4913 ;; When called from a timestamp, replace existing one.
4917 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4918 (cl-letf (((symbol-function 'org-read-date
)
4919 (lambda (&rest args
)
4920 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4921 (org-time-stamp nil
)
4925 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4926 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4927 (cl-letf (((symbol-function 'org-read-date
)
4928 (lambda (&rest args
)
4929 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4930 (org-time-stamp nil
)
4932 ;; When replacing a timestamp, preserve repeater, if any.
4935 "<2014-03-04 .*? \\+2y>"
4936 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4937 (cl-letf (((symbol-function 'org-read-date
)
4938 (lambda (&rest args
)
4939 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4940 (org-time-stamp nil
)
4942 ;; When called twice in a raw, build a date range.
4945 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4946 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4947 (cl-letf (((symbol-function 'org-read-date
)
4948 (lambda (&rest args
)
4949 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4950 (let ((last-command 'org-time-stamp
)
4951 (this-command 'org-time-stamp
))
4952 (org-time-stamp nil
))
4953 (buffer-string))))))
4955 (ert-deftest test-org
/timestamp-has-time-p
()
4956 "Test `org-timestamp-has-time-p' specifications."
4959 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4960 (org-timestamp-has-time-p (org-element-context))))
4963 (org-test-with-temp-text "<2012-03-29 Thu>"
4964 (org-timestamp-has-time-p (org-element-context)))))
4966 (ert-deftest test-org
/timestamp-format
()
4967 "Test `org-timestamp-format' specifications."
4972 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4973 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4978 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4979 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4981 (ert-deftest test-org
/timestamp-split-range
()
4982 "Test `org-timestamp-split-range' specifications."
4983 ;; Extract range start (active).
4986 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4987 (let ((ts (org-timestamp-split-range (org-element-context))))
4988 (mapcar (lambda (p) (org-element-property p ts
))
4989 '(:year-end
:month-end
:day-end
))))))
4990 ;; Extract range start (inactive)
4993 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4994 (let ((ts (org-timestamp-split-range (org-element-context))))
4995 (mapcar (lambda (p) (org-element-property p ts
))
4996 '(:year-end
:month-end
:day-end
))))))
4997 ;; Extract range end (active).
5000 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5001 (let ((ts (org-timestamp-split-range
5002 (org-element-context) t
)))
5003 (mapcar (lambda (p) (org-element-property p ts
))
5004 '(:year-end
:month-end
:day-end
))))))
5005 ;; Extract range end (inactive)
5008 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5009 (let ((ts (org-timestamp-split-range
5010 (org-element-context) t
)))
5011 (mapcar (lambda (p) (org-element-property p ts
))
5012 '(:year-end
:month-end
:day-end
))))))
5013 ;; Return the timestamp if not a range.
5015 (org-test-with-temp-text "[2012-03-29 Thu]"
5016 (let* ((ts-orig (org-element-context))
5017 (ts-copy (org-timestamp-split-range ts-orig
)))
5018 (eq ts-orig ts-copy
))))
5020 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5021 (let* ((ts-orig (org-element-context))
5022 (ts-copy (org-timestamp-split-range ts-orig
)))
5023 (eq ts-orig ts-copy
)))))
5025 (ert-deftest test-org
/timestamp-translate
()
5026 "Test `org-timestamp-translate' specifications."
5027 ;; Translate whole date range.
5030 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5031 (let ((org-display-custom-times t
)
5032 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5033 (org-timestamp-translate (org-element-context))))))
5034 ;; Translate date range start.
5037 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5038 (let ((org-display-custom-times t
)
5039 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5040 (org-timestamp-translate (org-element-context) 'start
)))))
5041 ;; Translate date range end.
5044 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5045 (let ((org-display-custom-times t
)
5046 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5047 (org-timestamp-translate (org-element-context) 'end
)))))
5048 ;; Translate time range.
5051 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5052 (let ((org-display-custom-times t
)
5053 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5054 (org-timestamp-translate (org-element-context))))))
5055 ;; Translate non-range timestamp.
5058 (org-test-with-temp-text "<2012-03-29 Thu>"
5059 (let ((org-display-custom-times t
)
5060 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5061 (org-timestamp-translate (org-element-context))))))
5062 ;; Do not change `diary' timestamps.
5064 (equal "<%%(org-float t 4 2)>"
5065 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5066 (let ((org-display-custom-times t
)
5067 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5068 (org-timestamp-translate (org-element-context)))))))
5074 (ert-deftest test-org
/flag-drawer
()
5075 "Test `org-flag-drawer' specifications."
5078 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5080 (get-char-property (line-end-position) 'invisible
)))
5083 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5085 (org-flag-drawer nil
)
5086 (get-char-property (line-end-position) 'invisible
)))
5087 ;; Test optional argument.
5089 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5090 (let ((drawer (save-excursion (search-forward ":D2")
5091 (org-element-at-point))))
5092 (org-flag-drawer t drawer
)
5093 (get-char-property (progn (search-forward ":D2") (line-end-position))
5096 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5097 (let ((drawer (save-excursion (search-forward ":D2")
5098 (org-element-at-point))))
5099 (org-flag-drawer t drawer
)
5100 (get-char-property (line-end-position) 'invisible
))))
5101 ;; Do not hide fake drawers.
5103 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5106 (get-char-property (line-end-position) 'invisible
)))
5107 ;; Do not hide incomplete drawers.
5109 (org-test-with-temp-text ":D:\nparagraph"
5112 (get-char-property (line-end-position) 'invisible
)))
5113 ;; Do not hide drawers when called from final blank lines.
5115 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5116 (goto-char (point-max))
5118 (goto-char (point-min))
5119 (get-char-property (line-end-position) 'invisible
)))
5120 ;; Don't leave point in an invisible part of the buffer when hiding
5123 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5124 (goto-char (point-max))
5126 (get-char-property (point) 'invisible
))))
5128 (ert-deftest test-org
/hide-block-toggle
()
5129 "Test `org-hide-block-toggle' specifications."
5130 ;; Error when not at a block.
5132 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5133 (org-hide-block-toggle 'off
)
5134 (get-char-property (line-end-position) 'invisible
)))
5137 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5138 (org-hide-block-toggle)
5139 (get-char-property (line-end-position) 'invisible
)))
5141 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5142 (org-hide-block-toggle)
5143 (get-char-property (line-end-position) 'invisible
)))
5144 ;; Show block unconditionally when optional argument is `off'.
5146 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5147 (org-hide-block-toggle)
5148 (org-hide-block-toggle 'off
)
5149 (get-char-property (line-end-position) 'invisible
)))
5151 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5152 (org-hide-block-toggle 'off
)
5153 (get-char-property (line-end-position) 'invisible
)))
5154 ;; Hide block unconditionally when optional argument is non-nil.
5156 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5157 (org-hide-block-toggle t
)
5158 (get-char-property (line-end-position) 'invisible
)))
5160 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5161 (org-hide-block-toggle)
5162 (org-hide-block-toggle t
)
5163 (get-char-property (line-end-position) 'invisible
)))
5164 ;; Do not hide block when called from final blank lines.
5166 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5167 (org-hide-block-toggle)
5168 (goto-char (point-min))
5169 (get-char-property (line-end-position) 'invisible
)))
5170 ;; Don't leave point in an invisible part of the buffer when hiding
5173 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5174 (org-hide-block-toggle)
5175 (get-char-property (point) 'invisible
))))
5177 (ert-deftest test-org
/hide-block-toggle-maybe
()
5178 "Test `org-hide-block-toggle-maybe' specifications."
5180 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5181 (org-hide-block-toggle-maybe)))
5183 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5185 (ert-deftest test-org
/set-tags
()
5186 "Test `org-set-tags' specifications."
5187 ;; Tags set via fast-tag-selection should be visible afterwards
5189 (let ((org-tag-alist '(("NEXT" . ?n
)))
5190 (org-fast-tag-selection-single-key t
))
5191 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5192 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5193 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5194 ;; Show only headlines
5196 ;; Set NEXT tag on current entry
5197 (org-set-tags nil nil
)
5198 ;; Move point to that NEXT tag
5199 (search-forward "NEXT") (backward-word)
5200 ;; And it should be visible (i.e. no overlays)
5201 (not (overlays-at (point))))))))
5203 (ert-deftest test-org
/show-set-visibility
()
5204 "Test `org-show-set-visibility' specifications."
5205 ;; Do not throw an error before first heading.
5207 (org-test-with-temp-text "Preamble\n* Headline"
5208 (org-show-set-visibility 'tree
)
5210 ;; Test all visibility spans, both on headline and in entry.
5211 (let ((list-visible-lines
5212 (lambda (state headerp
)
5213 (org-test-with-temp-text "* Grandmother (0)
5224 **** The other child (11)
5229 (search-forward (if headerp
"Self" "Match"))
5230 (org-show-set-visibility state
)
5231 (goto-char (point-min))
5232 (let (result (line 0))
5234 (unless (org-invisible-p2) (push line result
))
5237 (nreverse result
))))))
5238 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5239 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5240 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5241 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5242 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5243 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5244 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5245 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5246 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5247 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5248 (funcall list-visible-lines
'tree nil
)))
5249 (should (equal '(0 1 3 4 5 7 12 13)
5250 (funcall list-visible-lines
'canonical t
)))
5251 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5252 (funcall list-visible-lines
'canonical nil
))))
5253 ;; When point is hidden in a drawer or a block, make sure to make it
5256 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5257 (org-hide-block-toggle)
5258 (search-forward "Text")
5259 (org-show-set-visibility 'minimal
)
5260 (org-invisible-p2)))
5262 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5264 (search-forward "Text")
5265 (org-show-set-visibility 'minimal
)
5266 (org-invisible-p2)))
5268 (org-test-with-temp-text
5269 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5272 (org-hide-block-toggle)
5273 (search-forward "Text")
5274 (org-show-set-visibility 'minimal
)
5275 (org-invisible-p2))))
5280 ;;; test-org.el ends here