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 ;; At headline text, break headline text but preserve tags.
1097 (equal "* TODO [#B] foo :tag:\nbar"
1098 (let (org-auto-align-tags)
1099 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1102 ;; At bol of headline insert newline.
1105 (org-test-with-temp-text "<point>* h"
1108 ;; Refuse to leave invalid headline in buffer.
1111 (org-test-with-temp-text "*<point> h"
1115 (ert-deftest test-org
/meta-return
()
1116 "Test M-RET (`org-meta-return') specifications."
1117 ;; In a table field insert a row above.
1119 (org-test-with-temp-text "| a |"
1123 (looking-at "| |$")))
1124 ;; In a paragraph change current line into a header.
1126 (org-test-with-temp-text "a"
1129 (looking-at "\* a$")))
1130 ;; In an item insert an item, in this case above.
1132 (org-test-with-temp-text "- a"
1135 (looking-at "- $")))
1136 ;; In a drawer and item insert an item, in this case above.
1138 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1142 (looking-at "- $"))))
1144 (ert-deftest test-org
/insert-heading
()
1145 "Test `org-insert-heading' specifications."
1146 ;; In an empty buffer, insert a new headline.
1149 (org-test-with-temp-text ""
1150 (org-insert-heading)
1152 ;; At the beginning of a line, turn it into a headline
1155 (org-test-with-temp-text "<point>P"
1156 (org-insert-heading)
1158 ;; In the middle of a line, split the line if allowed, otherwise,
1159 ;; insert the headline at its end.
1161 (equal "Para\n* graph"
1162 (org-test-with-temp-text "Para<point>graph"
1163 (let ((org-M-RET-may-split-line '((default . t
))))
1164 (org-insert-heading))
1167 (equal "Paragraph\n* "
1168 (org-test-with-temp-text "Para<point>graph"
1169 (let ((org-M-RET-may-split-line '((default . nil
))))
1170 (org-insert-heading))
1172 ;; At the beginning of a headline, create one above.
1175 (org-test-with-temp-text "* H"
1176 (org-insert-heading)
1178 ;; In the middle of a headline, split it if allowed.
1181 (org-test-with-temp-text "* H<point>1"
1182 (let ((org-M-RET-may-split-line '((headline . t
))))
1183 (org-insert-heading))
1187 (org-test-with-temp-text "* H<point>1"
1188 (let ((org-M-RET-may-split-line '((headline . nil
))))
1189 (org-insert-heading))
1191 ;; However, splitting cannot happen on TODO keywords, priorities or
1194 (equal "* TODO H1\n* "
1195 (org-test-with-temp-text "* TO<point>DO H1"
1196 (let ((org-M-RET-may-split-line '((headline . t
))))
1197 (org-insert-heading))
1200 (equal "* [#A] H1\n* "
1201 (org-test-with-temp-text "* [#<point>A] H1"
1202 (let ((org-M-RET-may-split-line '((headline . t
))))
1203 (org-insert-heading))
1206 (equal "* H1 :tag:\n* "
1207 (org-test-with-temp-text "* H1 :ta<point>g:"
1208 (let ((org-M-RET-may-split-line '((headline . t
))))
1209 (org-insert-heading))
1211 ;; When on a list, insert an item instead, unless called with an
1212 ;; universal argument or if list is invisible. In this case, create
1213 ;; a new headline after contents.
1215 (equal "* H\n- item\n- "
1216 (org-test-with-temp-text "* H\n- item<point>"
1217 (let ((org-insert-heading-respect-content nil
))
1218 (org-insert-heading))
1221 (equal "* H\n- item\n- item 2\n* "
1222 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1223 (let ((org-insert-heading-respect-content nil
))
1224 (org-insert-heading '(4)))
1227 (equal "* H\n- item\n* "
1228 (org-test-with-temp-text "* H\n- item"
1230 (goto-char (point-max))
1231 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1233 ;; Preserve list visibility when inserting an item.
1237 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1238 (let ((org-cycle-include-plain-lists t
))
1242 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1243 (list (get-char-property (line-beginning-position 0) 'invisible
)
1244 (get-char-property (line-end-position 2) 'invisible
))))))
1245 ;; When called with one universal argument, insert a new headline at
1246 ;; the end of the current subtree, independently on the position of
1251 (org-test-with-temp-text "* H1\n** H2"
1252 (let ((org-insert-heading-respect-content nil
))
1253 (org-insert-heading '(4)))
1258 (org-test-with-temp-text "* H<point>1\n** H2"
1259 (let ((org-insert-heading-respect-content nil
))
1260 (org-insert-heading '(4)))
1262 ;; When called with two universal arguments, insert a new headline
1263 ;; at the end of the grandparent subtree.
1265 (equal "* H1\n** H3\n- item\n** H2\n** "
1266 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1267 (let ((org-insert-heading-respect-content nil
))
1268 (org-insert-heading '(16)))
1270 ;; When optional TOP-LEVEL argument is non-nil, always insert
1271 ;; a level 1 heading.
1273 (equal "* H1\n** H2\n* "
1274 (org-test-with-temp-text "* H1\n** H2<point>"
1275 (org-insert-heading nil nil t
)
1278 (equal "* H1\n- item\n* "
1279 (org-test-with-temp-text "* H1\n- item<point>"
1280 (org-insert-heading nil nil t
)
1282 ;; Corner case: correctly insert a headline after an empty one.
1285 (org-test-with-temp-text "* <point>"
1286 (org-insert-heading)
1289 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1290 "Test `org-insert-todo-heading-respect-content' specifications."
1291 ;; Create a TODO heading.
1293 (org-test-with-temp-text "* H1\n Body"
1294 (org-insert-todo-heading-respect-content)
1295 (nth 2 (org-heading-components))))
1296 ;; Add headline at the end of the first subtree
1298 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1299 (search-forward "H1Body")
1300 (org-insert-todo-heading-respect-content)
1301 (and (eobp) (org-at-heading-p))))
1302 ;; In a list, do not create a new item.
1304 (org-test-with-temp-text "* H\n- an item\n- another one"
1305 (search-forward "an ")
1306 (org-insert-todo-heading-respect-content)
1307 (and (eobp) (org-at-heading-p)))))
1309 (ert-deftest test-org
/clone-with-time-shift
()
1310 "Test `org-clone-subtree-with-time-shift'."
1311 ;; Clone non-repeating once.
1317 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1318 (org-clone-subtree-with-time-shift 1 "+2d")
1319 (replace-regexp-in-string
1320 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1322 ;; Clone repeating once.
1327 * H1\n<2015-06-25 +1w>
1329 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1330 (org-clone-subtree-with-time-shift 1 "+2d")
1331 (replace-regexp-in-string
1332 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1334 ;; Clone non-repeating zero times.
1339 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1340 (org-clone-subtree-with-time-shift 0 "+2d")
1341 (replace-regexp-in-string
1342 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1344 ;; Clone repeating "zero" times.
1348 * H1\n<2015-06-23 +1w>
1350 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1351 (org-clone-subtree-with-time-shift 0 "+2d")
1352 (replace-regexp-in-string
1353 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1357 ;;; Fixed-Width Areas
1359 (ert-deftest test-org
/toggle-fixed-width
()
1360 "Test `org-toggle-fixed-width' specifications."
1361 ;; No region: Toggle on fixed-width marker in paragraphs.
1364 (org-test-with-temp-text "A"
1365 (org-toggle-fixed-width)
1367 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1370 (org-test-with-temp-text ": A"
1371 (org-toggle-fixed-width)
1373 ;; No region: Toggle on marker in blank lines after elements or just
1374 ;; after a headline.
1377 (org-test-with-temp-text "* H\n"
1379 (org-toggle-fixed-width)
1382 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1383 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1384 (goto-char (point-max))
1385 (org-toggle-fixed-width)
1387 ;; No region: Toggle on marker in front of one line elements (e.g.,
1388 ;; headlines, clocks)
1390 (equal ": * Headline"
1391 (org-test-with-temp-text "* Headline"
1392 (org-toggle-fixed-width)
1395 (equal ": #+KEYWORD: value"
1396 (org-test-with-temp-text "#+KEYWORD: value"
1397 (org-toggle-fixed-width)
1399 ;; No region: error in other situations.
1401 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1403 (org-toggle-fixed-width)
1405 ;; No region: Indentation is preserved.
1408 (org-test-with-temp-text "- A\n B"
1410 (org-toggle-fixed-width)
1412 ;; Region: If it contains only fixed-width elements and blank lines,
1413 ;; toggle off fixed-width markup.
1416 (org-test-with-temp-text ": A\n\n: B"
1417 (transient-mark-mode 1)
1418 (push-mark (point) t t
)
1419 (goto-char (point-max))
1420 (org-toggle-fixed-width)
1422 ;; Region: If it contains anything else, toggle on fixed-width but
1423 ;; not on fixed-width areas.
1425 (equal ": A\n: \n: B\n: \n: C"
1426 (org-test-with-temp-text "A\n\n: B\n\nC"
1427 (transient-mark-mode 1)
1428 (push-mark (point) t t
)
1429 (goto-char (point-max))
1430 (org-toggle-fixed-width)
1432 ;; Region: Ignore blank lines at its end, unless it contains only
1436 (org-test-with-temp-text "A\n\n"
1437 (transient-mark-mode 1)
1438 (push-mark (point) t t
)
1439 (goto-char (point-max))
1440 (org-toggle-fixed-width)
1444 (org-test-with-temp-text "\n\n"
1445 (transient-mark-mode 1)
1446 (push-mark (point) t t
)
1447 (goto-char (point-max))
1448 (org-toggle-fixed-width)
1455 (ert-deftest test-org
/get-heading
()
1456 "Test `org-get-heading' specifications."
1457 ;; Return current heading, even if point is not on it.
1460 (org-test-with-temp-text "* H"
1461 (org-get-heading))))
1464 (org-test-with-temp-text "* H\nText<point>"
1465 (org-get-heading))))
1466 ;; Without any optional argument, return TODO keywords and tags.
1469 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1470 (org-get-heading))))
1473 (org-test-with-temp-text "* H :tag:"
1474 (org-get-heading))))
1475 ;; With NO-TAGS argument, ignore tags.
1478 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1479 (org-get-heading t
))))
1482 (org-test-with-temp-text "* H :tag:"
1483 (org-get-heading t
))))
1484 ;; With NO-TODO, ignore TODO keyword.
1487 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1488 (org-get-heading nil t
))))
1491 (org-test-with-temp-text "* H :tag:"
1492 (org-get-heading nil t
))))
1493 ;; TODO keywords are case-sensitive.
1496 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1497 (org-get-heading nil t
))))
1498 ;; On an empty headline, return value is consistent.
1499 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1500 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1501 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1502 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1504 (ert-deftest test-org
/in-commented-heading-p
()
1505 "Test `org-in-commented-heading-p' specifications."
1506 ;; Commented headline.
1508 (org-test-with-temp-text "* COMMENT Headline\nBody"
1509 (goto-char (point-max))
1510 (org-in-commented-heading-p)))
1511 ;; Commented ancestor.
1513 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1514 (goto-char (point-max))
1515 (org-in-commented-heading-p)))
1516 ;; Comment keyword is case-sensitive.
1518 (org-test-with-temp-text "* Comment Headline\nBody"
1519 (goto-char (point-max))
1520 (org-in-commented-heading-p)))
1521 ;; Keyword is standalone.
1523 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1524 (goto-char (point-max))
1525 (org-in-commented-heading-p)))
1526 ;; Optional argument.
1528 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1529 (goto-char (point-max))
1530 (org-in-commented-heading-p t
))))
1532 (ert-deftest test-org
/entry-blocked-p
()
1533 ;; Check other dependencies.
1535 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1536 (let ((org-enforce-todo-dependencies t
)
1538 '(org-block-todo-from-children-or-siblings-or-parent)))
1539 (org-entry-blocked-p))))
1541 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1542 (let ((org-enforce-todo-dependencies t
)
1544 '(org-block-todo-from-children-or-siblings-or-parent)))
1545 (org-entry-blocked-p))))
1546 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1549 (org-test-with-temp-text "* Blocked\n** TODO one"
1550 (let ((org-enforce-todo-dependencies t
)
1552 '(org-block-todo-from-children-or-siblings-or-parent)))
1553 (org-entry-blocked-p))))
1555 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1556 (let ((org-enforce-todo-dependencies t
)
1558 '(org-block-todo-from-children-or-siblings-or-parent)))
1559 (org-entry-blocked-p))))
1560 ;; Follow :ORDERED: specifications.
1562 (org-test-with-temp-text
1563 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1564 (let ((org-enforce-todo-dependencies t
)
1566 '(org-block-todo-from-children-or-siblings-or-parent)))
1567 (org-entry-blocked-p))))
1569 (org-test-with-temp-text
1570 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1571 (let ((org-enforce-todo-dependencies t
)
1573 '(org-block-todo-from-children-or-siblings-or-parent)))
1574 (org-entry-blocked-p)))))
1576 (ert-deftest test-org
/get-outline-path
()
1577 "Test `org-get-outline-path' specifications."
1578 ;; Top-level headlines have no outline path.
1580 (org-test-with-temp-text "* H"
1581 (org-get-outline-path)))
1582 ;; Otherwise, outline path is the path leading to the headline.
1585 (org-test-with-temp-text "* H\n** S<point>"
1586 (org-get-outline-path))))
1587 ;; Find path even when point is not on a headline.
1590 (org-test-with-temp-text "* H\n** S\nText<point>"
1591 (org-get-outline-path))))
1592 ;; TODO keywords, tags and statistics cookies are ignored.
1595 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1596 (org-get-outline-path))))
1597 ;; Links are replaced with their description or their path.
1600 (org-test-with-temp-text
1601 "* [[http://orgmode.org][Org]]\n** S<point>"
1602 (org-get-outline-path))))
1604 (equal '("http://orgmode.org")
1605 (org-test-with-temp-text
1606 "* [[http://orgmode.org]]\n** S<point>"
1607 (org-get-outline-path))))
1608 ;; When WITH-SELF is non-nil, include current heading.
1611 (org-test-with-temp-text "* H"
1612 (org-get-outline-path t
))))
1615 (org-test-with-temp-text "* H\n** S\nText<point>"
1616 (org-get-outline-path t
))))
1617 ;; Using cache is transparent to the user.
1620 (org-test-with-temp-text "* H\n** S<point>"
1621 (setq org-outline-path-cache nil
)
1622 (org-get-outline-path nil t
))))
1623 ;; Do not corrupt cache when finding outline path in distant part of
1627 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1628 (setq org-outline-path-cache nil
)
1629 (org-get-outline-path nil t
)
1630 (search-forward "S2")
1631 (org-get-outline-path nil t
))))
1632 ;; Do not choke on empty headlines.
1634 (org-test-with-temp-text "* H\n** <point>"
1635 (org-get-outline-path)))
1637 (org-test-with-temp-text "* \n** H<point>"
1638 (org-get-outline-path))))
1640 (ert-deftest test-org
/format-outline-path
()
1641 "Test `org-format-outline-path' specifications."
1643 (string= (org-format-outline-path (list "one" "two" "three"))
1647 (string= (org-format-outline-path '())
1650 (string= (org-format-outline-path '(nil))
1652 ;; Empty path and prefix.
1654 (string= (org-format-outline-path '() nil
">>")
1656 ;; Trailing whitespace in headings.
1658 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1660 ;; Non-default prefix and separators.
1662 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1663 ">>|one|two|three"))
1666 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1668 ;; Give a very narrow width.
1670 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1672 ;; Give a prefix that extends beyond the width.
1674 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1678 (ert-deftest test-org
/map-entries
()
1679 "Test `org-map-entries' specifications."
1683 (org-test-with-temp-text "* Level 1\n** Level 2"
1684 (org-map-entries #'point
))))
1688 (org-test-with-temp-text "* Level 1\n** Level 2"
1689 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1692 (org-test-with-temp-text "* Level 1\n** Level 2"
1693 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1697 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1698 (org-map-entries #'point
"yes"))))
1701 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1702 (org-map-entries #'point
"+yes-a"))))
1705 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1706 (org-map-entries #'point
"{yes?}"))))
1710 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1711 (org-map-entries #'point
"PRIORITY=\"A\""))))
1715 (org-test-with-temp-text "
1717 SCHEDULED: <2012-03-29 thu.>
1719 SCHEDULED: <2014-03-04 tue.>"
1720 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1723 (org-test-with-temp-text "
1725 SCHEDULED: <2012-03-29 thu.>
1727 SCHEDULED: <2014-03-04 tue.>"
1728 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1729 ;; Regular property match.
1732 (org-test-with-temp-text "
1741 (org-map-entries #'point
"TEST=1"))))
1742 ;; Multiple criteria.
1745 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1746 (let (org-odd-levels-only
1747 (org-use-tag-inheritance nil
))
1748 (org-map-entries #'point
"yes+LEVEL=1")))))
1752 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1753 (let (org-odd-levels-only)
1754 (org-map-entries #'point
"LEVEL=2|no")))))
1757 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1758 (let (org-odd-levels-only)
1759 (org-map-entries #'point
"yes|no")))))
1763 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1764 (let (org-odd-levels-only)
1765 (org-map-entries #'point
"yes&no"))))))
1767 (ert-deftest test-org
/edit-headline
()
1768 "Test `org-edit-headline' specifications."
1771 (org-test-with-temp-text "* A"
1772 (org-edit-headline "B")
1774 ;; Handle empty headings.
1777 (org-test-with-temp-text "* A"
1778 (org-edit-headline "")
1782 (org-test-with-temp-text "* "
1783 (org-edit-headline "A")
1785 ;; Handle TODO keywords and priority cookies.
1788 (org-test-with-temp-text "* TODO A"
1789 (org-edit-headline "B")
1793 (org-test-with-temp-text "* [#A] A"
1794 (org-edit-headline "B")
1797 (equal "* TODO [#A] B"
1798 (org-test-with-temp-text "* TODO [#A] A"
1799 (org-edit-headline "B")
1803 (org-test-with-temp-text "* A :tag:"
1804 (let ((org-tags-column 4)) (org-edit-headline "B"))
1811 (ert-deftest test-org
/set-regexps-and-options
()
1812 "Test `org-set-regexps-and-options' specifications."
1816 (let ((org-tag-alist '(("A")))
1817 (org-tag-persistent-alist nil
))
1818 (org-test-with-temp-text ""
1820 org-current-tag-alist
))))
1823 (let ((org-tag-alist '(("A")))
1824 (org-tag-persistent-alist nil
))
1825 (org-test-with-temp-text "#+TAGS: B"
1827 org-current-tag-alist
))))
1829 (equal '(("C") ("B"))
1830 (let ((org-tag-alist '(("A")))
1831 (org-tag-persistent-alist '(("C"))))
1832 (org-test-with-temp-text "#+TAGS: B"
1834 org-current-tag-alist
))))
1837 (let ((org-tag-alist '(("A")))
1838 (org-tag-persistent-alist '(("C"))))
1839 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1841 org-current-tag-alist
))))
1843 (equal '(("A" . ?a
) ("B") ("C"))
1844 (let ((org-tag-persistant-alist nil
))
1845 (org-test-with-temp-text "#+TAGS: A(a) B C"
1847 org-current-tag-alist
))))
1849 (equal '(("A") (:newline
) ("B"))
1850 (let ((org-tag-persistent-alist nil
))
1851 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1853 org-current-tag-alist
))))
1855 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1856 (let ((org-tag-persistent-alist nil
))
1857 (org-test-with-temp-text "#+TAGS: { A B } C"
1859 org-current-tag-alist
))))
1861 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1862 (let ((org-tag-persistent-alist nil
))
1863 (org-test-with-temp-text "#+TAGS: { A : B C }"
1865 org-current-tag-alist
))))
1867 (equal '(("A" "B" "C"))
1868 (let ((org-tag-persistent-alist nil
))
1869 (org-test-with-temp-text "#+TAGS: { A : B C }"
1871 org-tag-groups-alist
))))
1873 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1874 (let ((org-tag-persistent-alist nil
))
1875 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1877 org-current-tag-alist
))))
1879 (equal '(("A" "B" "C"))
1880 (let ((org-tag-persistent-alist nil
))
1881 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1883 org-tag-groups-alist
))))
1884 ;; FILETAGS keyword.
1886 (equal '("A" "B" "C")
1887 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1890 ;; PROPERTY keyword. Property names are case-insensitive.
1893 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1895 (cdr (assoc "var" org-file-properties
)))))
1899 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1901 (cdr (assoc "var" org-file-properties
)))))
1905 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1907 (cdr (assoc "var" org-file-properties
)))))
1911 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1913 org-archive-location
)))
1914 ;; CATEGORY keyword.
1917 (org-test-with-temp-text "#+CATEGORY: test"
1922 (org-test-with-temp-text "#+CATEGORY: test"
1924 (cdr (assoc "CATEGORY" org-file-properties
)))))
1927 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1928 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1930 org-columns-default-format
)))
1931 ;; CONSTANTS keyword. Constants names are case sensitive.
1933 (equal '("299792458." "3.14")
1934 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1937 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1941 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1943 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1946 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1948 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1953 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1955 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1957 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1961 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1963 (list org-highest-priority org-lowest-priority org-default-priority
))))
1967 (org-test-with-temp-text "#+PRIORITIES: X Z"
1969 (list org-highest-priority org-lowest-priority org-default-priority
))))
1973 (org-test-with-temp-text "#+STARTUP: fold odd"
1975 (list org-startup-folded org-odd-levels-only
))))
1978 (equal '(("A" "B") ("C"))
1979 (org-test-with-temp-text "#+TODO: A B | C"
1981 (list org-not-done-keywords org-done-keywords
))))
1983 (equal '(("A" "C") ("B" "D"))
1984 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1986 (list org-not-done-keywords org-done-keywords
))))
1988 (equal '(("A" "B") ("C"))
1989 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1991 (list org-not-done-keywords org-done-keywords
))))
1993 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1994 (org-test-with-temp-text "#+TODO: A(a)"
1996 org-todo-key-alist
)))
1998 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1999 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2001 org-todo-log-states
)))
2002 ;; Enter SETUPFILE keyword.
2005 (org-test-with-temp-text
2006 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2008 (cdr (assoc "a" org-file-properties
))))))
2016 (ert-deftest test-org
/coderef
()
2017 "Test coderef links specifications."
2019 (org-test-with-temp-text "
2020 #+BEGIN_SRC emacs-lisp
2025 (looking-at "(ref:sc)")))
2026 ;; Find coderef even with alternate label format.
2028 (org-test-with-temp-text "
2029 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2034 (looking-at "{ref:sc}"))))
2038 (ert-deftest test-org
/custom-id
()
2039 "Test custom ID links specifications."
2041 (org-test-with-temp-text
2042 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2044 (looking-at-p "\\* H1")))
2045 ;; Throw an error on false positives.
2047 (org-test-with-temp-text
2048 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2050 (looking-at-p "\\* H1"))))
2054 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2055 ;; a named element (#+name: text) and to headlines (* Text).
2057 (ert-deftest test-org
/fuzzy-links
()
2058 "Test fuzzy links specifications."
2059 ;; Fuzzy link goes in priority to a matching target.
2061 (org-test-with-temp-text
2062 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2063 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2064 (looking-at "<<Test>>")))
2065 ;; Then fuzzy link points to an element with a given name.
2067 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2068 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2069 (looking-at "#\\+NAME: Test")))
2070 ;; A target still lead to a matching headline otherwise.
2072 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2073 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2074 (looking-at "\\* Head2")))
2075 ;; With a leading star in link, enforce heading match.
2077 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2078 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2079 (looking-at "\\* Test")))
2080 ;; With a leading star in link, enforce exact heading match, even
2081 ;; with `org-link-search-must-match-exact-headline' set to nil.
2083 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2084 (let ((org-link-search-must-match-exact-headline nil
))
2085 (org-open-at-point))))
2086 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2088 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2089 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2090 (looking-at "\\* Test")))
2092 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2093 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2094 (looking-at "\\* Test")))
2095 ;; Heading match should not care about spaces, cookies, TODO
2096 ;; keywords, priorities, and tags.
2099 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2100 (org-test-with-temp-text
2101 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2102 (let ((org-link-search-must-match-exact-headline nil
)
2103 (org-todo-regexp "TODO"))
2104 (org-open-at-point))
2105 (looking-at (regexp-quote first-line
)))))
2106 ;; Heading match should still be exact.
2109 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2110 (org-test-with-temp-text
2111 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
2112 (let ((org-link-search-must-match-exact-headline nil
)
2113 (org-todo-regexp "TODO"))
2114 (org-open-at-point)))))
2115 ;; Heading match ignores COMMENT keyword.
2117 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2119 (looking-at "\\* COMMENT Test")))
2120 ;; Correctly un-hexify fuzzy links.
2122 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2128 (ert-deftest test-org
/org-link-escape-ascii-character
()
2129 "Escape an ascii character."
2133 (org-link-escape "["))))
2135 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2136 "Escape an ascii control character."
2140 (org-link-escape "\t"))))
2142 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2143 "Escape an unicode multibyte character."
2147 (org-link-escape "€"))))
2149 (ert-deftest test-org
/org-link-escape-custom-table
()
2150 "Escape string with custom character table."
2154 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2156 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2157 "Escape string with custom table merged with default table."
2160 "%5BF%6F%6F%3A%42ar%0A%5D"
2161 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2163 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2164 "Unescape an ascii character."
2168 (org-link-unescape "%5B"))))
2170 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2171 "Unescpae an ascii control character."
2175 (org-link-unescape "%0A"))))
2177 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2178 "Unescape unicode multibyte character."
2182 (org-link-unescape "%E2%82%AC"))))
2184 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2185 "Unescape old style percent escaped character."
2188 "à âçèéêîôùû"
2189 (decode-coding-string
2190 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2192 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2193 "Escape and unescape a URL that includes an escaped char.
2194 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2197 "http://some.host.com/form?&id=blah%2Bblah25"
2199 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2203 (ert-deftest test-org
/open-at-point-in-keyword
()
2204 "Does `org-open-at-point' open link in a keyword line?"
2206 (org-test-with-temp-text
2207 "<<top>>\n#+KEYWORD: <point>[[top]]"
2208 (org-open-at-point) t
)))
2210 (ert-deftest test-org
/open-at-point-in-property
()
2211 "Does `org-open-at-point' open link in property drawer?"
2213 (org-test-with-temp-text
2216 :URL: <point>[[*Headline]]
2218 (org-open-at-point) t
)))
2220 (ert-deftest test-org
/open-at-point-in-comment
()
2221 "Does `org-open-at-point' open link in a commented line?"
2223 (org-test-with-temp-text
2224 "<<top>>\n# <point>[[top]]"
2225 (org-open-at-point) t
)))
2227 (ert-deftest test-org
/open-at-point
/inline-image
()
2228 "Test `org-open-at-point' on nested links."
2230 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2234 (ert-deftest test-org
/open-at-point
/radio-target
()
2235 "Test `org-open-at-point' on radio targets."
2237 (org-test-with-temp-text "<<<target>>> <point>target"
2238 (org-update-radio-target-regexp)
2240 (eq (org-element-type (org-element-context)) 'radio-target
))))
2244 (ert-deftest test-org
/store-link
()
2245 "Test `org-store-link' specifications."
2246 ;; On a headline, link to that headline. Use heading as the
2247 ;; description of the link.
2249 (let (org-store-link-props org-stored-links
)
2250 (org-test-with-temp-text-in-file "* H1"
2251 (let ((file (buffer-file-name)))
2252 (equal (format "[[file:%s::*H1][H1]]" file
)
2253 (org-store-link nil
))))))
2254 ;; On a headline, remove any link from description.
2256 (let (org-store-link-props org-stored-links
)
2257 (org-test-with-temp-text-in-file "* [[#l][d]]"
2258 (let ((file (buffer-file-name)))
2259 (equal (format "[[file:%s::*%s][d]]"
2261 (org-link-escape "[[#l][d]]"))
2262 (org-store-link nil
))))))
2264 (let (org-store-link-props org-stored-links
)
2265 (org-test-with-temp-text-in-file "* [[l]]"
2266 (let ((file (buffer-file-name)))
2267 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2268 (org-store-link nil
))))))
2270 (let (org-store-link-props org-stored-links
)
2271 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2272 (let ((file (buffer-file-name)))
2273 (equal (format "[[file:%s::*%s][d1 d2]]"
2275 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2276 (org-store-link nil
))))))
2277 ;; On a named element, link to that element.
2279 (let (org-store-link-props org-stored-links
)
2280 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2281 (let ((file (buffer-file-name)))
2282 (equal (format "[[file:%s::foo][foo]]" file
)
2283 (org-store-link nil
)))))))
2288 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2289 "Ensure properties accumulate in subtree drawers."
2290 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2291 (org-babel-next-src-block)
2292 (should (equal '(2 1) (org-babel-execute-src-block)))))
2294 (ert-deftest test-org
/custom-properties
()
2295 "Test custom properties specifications."
2298 (let ((org-custom-properties '("FOO")))
2299 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2300 (org-toggle-custom-properties-visibility)
2301 (org-invisible-p2))))
2302 ;; Properties are case-insensitive.
2304 (let ((org-custom-properties '("FOO")))
2305 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2306 (org-toggle-custom-properties-visibility)
2307 (org-invisible-p2))))
2309 (let ((org-custom-properties '("foo")))
2310 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2311 (org-toggle-custom-properties-visibility)
2312 (org-invisible-p2))))
2313 ;; Multiple custom properties in the same drawer.
2315 (let ((org-custom-properties '("FOO" "BAR")))
2316 (org-test-with-temp-text
2317 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2318 (org-toggle-custom-properties-visibility)
2319 (and (org-invisible-p2)
2320 (not (progn (forward-line) (org-invisible-p2)))
2321 (progn (forward-line) (org-invisible-p2))))))
2322 ;; Hide custom properties with an empty value.
2324 (let ((org-custom-properties '("FOO")))
2325 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2326 (org-toggle-custom-properties-visibility)
2327 (org-invisible-p2))))
2328 ;; Do not hide fake properties.
2330 (let ((org-custom-properties '("FOO")))
2331 (org-test-with-temp-text ":FOO: val\n"
2332 (org-toggle-custom-properties-visibility)
2333 (org-invisible-p2))))
2335 (let ((org-custom-properties '("A")))
2336 (org-test-with-temp-text
2337 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2338 (org-toggle-custom-properties-visibility)
2339 (org-invisible-p2)))))
2345 (ert-deftest test-org
/mark-subtree
()
2346 "Test `org-mark-subtree' specifications."
2347 ;; Error when point is before first headline.
2349 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2350 (progn (transient-mark-mode 1)
2351 (org-mark-subtree))))
2352 ;; Without argument, mark current subtree.
2356 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2357 (progn (transient-mark-mode 1)
2360 (list (region-beginning) (region-end))))))
2361 ;; With an argument, move ARG up.
2365 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2366 (progn (transient-mark-mode 1)
2368 (org-mark-subtree 1)
2369 (list (region-beginning) (region-end))))))
2370 ;; Do not get fooled by inlinetasks.
2371 (when (featurep 'org-inlinetask
)
2374 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2375 (progn (transient-mark-mode 1)
2377 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2378 (region-beginning)))))))
2384 (ert-deftest test-org
/in-regexp
()
2385 "Test `org-in-regexp' specifications."
2388 (org-test-with-temp-text "xx ab<point>c xx"
2389 (org-in-regexp "abc")))
2391 (org-test-with-temp-text "xx abc <point>xx"
2392 (org-in-regexp "abc")))
2393 ;; Return non-nil even with multiple matching regexps in the same
2396 (org-test-with-temp-text "abc xx ab<point>c xx"
2397 (org-in-regexp "abc")))
2398 ;; With optional argument NLINES, check extra lines around point.
2400 (org-test-with-temp-text "A\nB<point>\nC"
2401 (org-in-regexp "A\nB\nC")))
2403 (org-test-with-temp-text "A\nB<point>\nC"
2404 (org-in-regexp "A\nB\nC" 1)))
2406 (org-test-with-temp-text "A\nB\nC<point>"
2407 (org-in-regexp "A\nB\nC" 1)))
2408 ;; When optional argument VISUALLY is non-nil, return nil if at
2409 ;; regexp boundaries.
2411 (org-test-with-temp-text "xx abc<point> xx"
2412 (org-in-regexp "abc")))
2414 (org-test-with-temp-text "xx abc<point> xx"
2415 (org-in-regexp "abc" nil t
))))
2420 (ert-deftest test-org
/end-of-meta-data
()
2421 "Test `org-end-of-meta-data' specifications."
2422 ;; Skip planning line.
2424 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2425 (org-end-of-meta-data)
2427 ;; Skip properties drawer.
2429 (org-test-with-temp-text
2430 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2431 (org-end-of-meta-data)
2435 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2436 (org-end-of-meta-data)
2438 ;; Nothing to skip, go to first line.
2440 (org-test-with-temp-text "* Headline\nContents"
2441 (org-end-of-meta-data)
2442 (looking-at "Contents")))
2443 ;; With option argument, skip empty lines, regular drawers and
2446 (org-test-with-temp-text "* Headline\n\nContents"
2447 (org-end-of-meta-data t
)
2448 (looking-at "Contents")))
2450 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2451 (org-end-of-meta-data t
)
2452 (looking-at "Contents")))
2454 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2455 (org-end-of-meta-data t
)
2456 (looking-at "Contents")))
2457 ;; Special case: do not skip incomplete drawers.
2459 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2460 (org-end-of-meta-data t
)
2461 (looking-at ":LOGBOOK:")))
2462 ;; Special case: Be careful about consecutive headlines.
2464 (org-test-with-temp-text "* H1\n*H2\nContents"
2465 (org-end-of-meta-data t
)
2466 (looking-at "Contents"))))
2468 (ert-deftest test-org
/beginning-of-line
()
2469 "Test `org-beginning-of-line' specifications."
2472 (org-test-with-temp-text "Some text\nSome other text"
2473 (progn (org-beginning-of-line) (bolp))))
2474 ;; Standard test with `visual-line-mode'.
2476 (org-test-with-temp-text "A long line of text\nSome other text"
2477 (progn (visual-line-mode)
2479 (dotimes (i 1000) (insert "very "))
2480 (org-beginning-of-line)
2482 ;; At an headline with special movement.
2484 (org-test-with-temp-text "* TODO Headline"
2485 (let ((org-special-ctrl-a/e t
))
2487 (and (progn (org-beginning-of-line) (looking-at "Headline"))
2488 (progn (org-beginning-of-line) (bolp))
2489 (progn (org-beginning-of-line) (looking-at "Headline"))))))
2490 ;; Special case: Do not error when the buffer contains only a single
2493 (org-test-with-temp-text "*<point>"
2494 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
2496 (org-test-with-temp-text "*<point>"
2497 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
2499 (ert-deftest test-org
/end-of-line
()
2500 "Test `org-end-of-line' specifications."
2503 (org-test-with-temp-text "Some text\nSome other text"
2504 (progn (org-end-of-line) (eolp))))
2505 ;; Standard test with `visual-line-mode'.
2507 (org-test-with-temp-text "A long line of text\nSome other text"
2508 (progn (visual-line-mode)
2510 (dotimes (i 1000) (insert "very "))
2511 (goto-char (point-min))
2514 ;; At an headline with special movement.
2516 (org-test-with-temp-text "* Headline1 :tag:\n"
2517 (let ((org-special-ctrl-a/e t
))
2518 (and (progn (org-end-of-line) (looking-at " :tag:"))
2519 (progn (org-end-of-line) (eolp))
2520 (progn (org-end-of-line) (looking-at " :tag:"))))))
2521 ;; At an headline without special movement.
2523 (org-test-with-temp-text "* Headline2 :tag:\n"
2524 (let ((org-special-ctrl-a/e nil
))
2525 (and (progn (org-end-of-line) (eolp))
2526 (progn (org-end-of-line) (eolp))))))
2527 ;; At an headline, with reversed movement.
2529 (org-test-with-temp-text "* Headline3 :tag:\n"
2530 (let ((org-special-ctrl-a/e
'reversed
)
2531 (this-command last-command
))
2532 (and (progn (org-end-of-line) (eolp))
2533 (progn (org-end-of-line) (looking-at " :tag:"))))))
2534 ;; At a block without hidden contents.
2536 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2537 (progn (org-end-of-line) (eolp))))
2538 ;; At a block with hidden contents.
2540 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2541 (let ((org-special-ctrl-a/e t
))
2542 (org-hide-block-toggle)
2546 (ert-deftest test-org
/open-line
()
2547 "Test `org-open-line' specifications."
2548 ;; Call `open-line' outside of tables.
2551 (org-test-with-temp-text "Text"
2554 ;; At a table, create a row above.
2556 (equal "\n| |\n| a |"
2557 (org-test-with-temp-text "\n<point>| a |"
2560 ;; At the very first character of the buffer, also call `open-line'.
2563 (org-test-with-temp-text "| a |"
2566 ;; Narrowing does not count.
2568 (equal "Text\n| |\n| a |"
2569 (org-test-with-temp-text "Text\n<point>| a |"
2570 (narrow-to-region (point) (point-max))
2575 (ert-deftest test-org
/forward-sentence
()
2576 "Test `org-forward-sentence' specifications."
2577 ;; At the end of a table cell, move to the end of the next one.
2579 (org-test-with-temp-text "| a<point> | b |"
2580 (org-forward-sentence)
2581 (looking-at " |$")))
2582 ;; Elsewhere in a cell, move to its end.
2584 (org-test-with-temp-text "| a<point>c | b |"
2585 (org-forward-sentence)
2586 (looking-at " | b |$")))
2587 ;; Otherwise, simply call `forward-sentence'.
2589 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2590 (org-forward-sentence)
2591 (looking-at " Sentence 2.")))
2593 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2594 (org-forward-sentence)
2595 (org-forward-sentence)
2597 ;; At the end of an element, jump to the next one, without stopping
2598 ;; on blank lines in-between.
2600 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2601 (org-forward-sentence)
2604 (ert-deftest test-org
/backward-sentence
()
2605 "Test `org-backward-sentence' specifications."
2606 ;; At the beginning of a table cell, move to the beginning of the
2609 (org-test-with-temp-text "| a | <point>b |"
2610 (org-backward-sentence)
2611 (looking-at "a | b |$")))
2612 ;; Elsewhere in a cell, move to its beginning.
2614 (org-test-with-temp-text "| a | b<point>c |"
2615 (org-backward-sentence)
2616 (looking-at "bc |$")))
2617 ;; Otherwise, simply call `backward-sentence'.
2619 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2620 (org-backward-sentence)
2621 (looking-at "Sentence 2.")))
2623 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2624 (org-backward-sentence)
2625 (org-backward-sentence)
2627 ;; Make sure to hit the beginning of a sentence on the same line as
2630 (org-test-with-temp-text "- Line 1\n line <point>2."
2631 (org-backward-sentence)
2632 (looking-at "Line 1"))))
2634 (ert-deftest test-org
/forward-paragraph
()
2635 "Test `org-forward-paragraph' specifications."
2636 ;; At end of buffer, return an error.
2638 (org-test-with-temp-text "Paragraph"
2639 (goto-char (point-max))
2640 (org-forward-paragraph)))
2643 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2644 (org-forward-paragraph)
2648 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2649 (org-forward-paragraph)
2651 ;; Do not enter elements with invisible contents.
2653 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2654 (org-hide-block-toggle)
2655 (org-forward-paragraph)
2657 ;; On an affiliated keyword, jump to the beginning of the element.
2659 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2660 (org-forward-paragraph)
2661 (looking-at "Para")))
2662 ;; On an item or a footnote definition, move to the second element
2665 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2666 (org-forward-paragraph)
2667 (looking-at " Paragraph")))
2669 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2670 (org-forward-paragraph)
2671 (looking-at "Paragraph")))
2672 ;; On an item, or a footnote definition, when the first line is
2673 ;; empty, move to the first item.
2675 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2676 (org-forward-paragraph)
2677 (looking-at " Paragraph")))
2679 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2680 (org-forward-paragraph)
2681 (looking-at "Paragraph")))
2682 ;; On a table (resp. a property drawer) do not move through table
2683 ;; rows (resp. node properties).
2685 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2686 (org-forward-paragraph)
2687 (looking-at "Paragraph")))
2689 (org-test-with-temp-text
2690 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2691 (org-forward-paragraph)
2692 (looking-at "Paragraph")))
2693 ;; On a verse or source block, stop after blank lines.
2695 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2696 (org-forward-paragraph)
2699 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2700 (org-forward-paragraph)
2701 (looking-at "L2"))))
2703 (ert-deftest test-org
/backward-paragraph
()
2704 "Test `org-backward-paragraph' specifications."
2705 ;; Error at beginning of buffer.
2707 (org-test-with-temp-text "Paragraph"
2708 (org-backward-paragraph)))
2711 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2712 (goto-char (point-max))
2713 (org-backward-paragraph)
2716 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2717 (goto-char (point-max))
2719 (org-backward-paragraph)
2723 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2724 (goto-char (point-max))
2726 (org-backward-paragraph)
2728 ;; Ignore invisible elements.
2730 (org-test-with-temp-text "* H1\n P1\n* H2"
2732 (goto-char (point-max))
2734 (org-backward-paragraph)
2736 ;; On an affiliated keyword, jump to the first one.
2738 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2739 (search-forward "c2")
2740 (org-backward-paragraph)
2741 (looking-at "#\\+name")))
2742 ;; On the second element in an item or a footnote definition, jump
2743 ;; to item or the definition.
2745 (org-test-with-temp-text "- line1\n\n line2"
2746 (goto-char (point-max))
2748 (org-backward-paragraph)
2749 (looking-at "- line1")))
2751 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2752 (goto-char (point-max))
2754 (org-backward-paragraph)
2755 (looking-at "\\[fn:1\\] line1")))
2756 ;; On a table (resp. a property drawer), ignore table rows
2757 ;; (resp. node properties).
2759 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2760 (goto-char (point-max))
2762 (org-backward-paragraph)
2765 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2766 (org-backward-paragraph)
2767 (looking-at ":PROPERTIES:")))
2768 ;; On a source or verse block, stop before blank lines.
2770 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2771 (search-forward "L3")
2773 (org-backward-paragraph)
2776 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2777 (search-forward "L3")
2779 (org-backward-paragraph)
2780 (looking-at "L2"))))
2782 (ert-deftest test-org
/forward-element
()
2783 "Test `org-forward-element' specifications."
2784 ;; 1. At EOB: should error.
2785 (org-test-with-temp-text "Some text\n"
2786 (goto-char (point-max))
2787 (should-error (org-forward-element)))
2788 ;; 2. Standard move: expected to ignore blank lines.
2789 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2790 (org-forward-element)
2791 (should (looking-at (regexp-quote "Second paragraph."))))
2792 ;; 3. Headline tests.
2793 (org-test-with-temp-text "
2798 ;; 3.1. At an headline beginning: move to next headline at the
2801 (org-forward-element)
2802 (should (looking-at (regexp-quote "** Head 1.2")))
2803 ;; 3.2. At an headline beginning: move to parent headline if no
2804 ;; headline at the same level.
2806 (org-forward-element)
2807 (should (looking-at (regexp-quote "** Head 1.2"))))
2808 ;; 4. Greater element tests.
2809 (org-test-with-temp-text
2810 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2811 ;; 4.1. At a greater element: expected to skip contents.
2812 (org-forward-element)
2813 (should (looking-at (regexp-quote "Outside.")))
2814 ;; 4.2. At the end of greater element contents: expected to skip
2815 ;; to the end of the greater element.
2817 (org-forward-element)
2818 (should (looking-at (regexp-quote "Outside."))))
2820 (org-test-with-temp-text "
2834 ;; 5.1. At list top point: expected to move to the element after
2837 (org-forward-element)
2838 (should (looking-at (regexp-quote "Outside.")))
2839 ;; 5.2. Special case: at the first line of a sub-list, but not at
2840 ;; beginning of line, move to next item.
2843 (org-forward-element)
2844 (should (looking-at "- item2"))
2847 (org-forward-element)
2848 (should (looking-at " - sub2"))
2849 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2851 (org-forward-element)
2852 (should (looking-at (regexp-quote " Inner paragraph.")))
2853 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2855 (org-forward-element)
2856 (should (looking-at (regexp-quote " Inner paragraph.")))
2857 ;; 5.5. At an item: expected to move to next item, if any.
2859 (org-forward-element)
2860 (should (looking-at " - sub3"))))
2862 (ert-deftest test-org
/backward-element
()
2863 "Test `org-backward-element' specifications."
2864 ;; 1. Should error at BOB.
2865 (org-test-with-temp-text " \nParagraph."
2866 (should-error (org-backward-element)))
2867 ;; 2. Should move at BOB when called on the first element in buffer.
2869 (org-test-with-temp-text "\n#+TITLE: test"
2870 (progn (forward-line)
2871 (org-backward-element)
2873 ;; 3. Not at the beginning of an element: move at its beginning.
2874 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2877 (org-backward-element)
2878 (should (looking-at (regexp-quote "Paragraph2."))))
2879 ;; 4. Headline tests.
2880 (org-test-with-temp-text "
2885 ;; 4.1. At an headline beginning: move to previous headline at the
2888 (org-backward-element)
2889 (should (looking-at (regexp-quote "** Head 1.1")))
2890 ;; 4.2. At an headline beginning: move to parent headline if no
2891 ;; headline at the same level.
2893 (org-backward-element)
2894 (should (looking-at (regexp-quote "* Head 1")))
2895 ;; 4.3. At the first top-level headline: should error.
2897 (should-error (org-backward-element)))
2898 ;; 5. At beginning of first element inside a greater element:
2899 ;; expected to move to greater element's beginning.
2900 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2902 (org-backward-element)
2903 (should (looking-at "#\\+BEGIN_CENTER")))
2904 ;; 6. At the beginning of the first element in a section: should
2905 ;; move back to headline, if any.
2907 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2908 (progn (goto-char (point-max))
2910 (org-backward-element)
2911 (org-at-heading-p))))
2913 (org-test-with-temp-text "
2928 ;; 7.1. At beginning of sub-list: expected to move to the
2929 ;; paragraph before it.
2931 (org-backward-element)
2932 (should (looking-at "item1"))
2933 ;; 7.2. At an item in a list: expected to move at previous item.
2935 (org-backward-element)
2936 (should (looking-at " - sub2"))
2938 (org-backward-element)
2939 (should (looking-at "- item1"))
2940 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2943 (org-backward-element)
2944 (should (looking-at " - sub1"))
2946 (org-backward-element)
2947 (should (looking-at "- item1"))
2948 ;; 7.4. At blank-lines before list end: expected to move to top
2951 (org-backward-element)
2952 (should (looking-at "- item1"))))
2954 (ert-deftest test-org
/up-element
()
2955 "Test `org-up-element' specifications."
2956 ;; 1. At BOB or with no surrounding element: should error.
2957 (org-test-with-temp-text "Paragraph."
2958 (should-error (org-up-element)))
2959 (org-test-with-temp-text "* Head1\n* Head2"
2961 (should-error (org-up-element)))
2962 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2964 (should-error (org-up-element)))
2965 ;; 2. At an headline: move to parent headline.
2966 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2969 (should (looking-at "\\* Head1")))
2970 ;; 3. Inside a greater element: move to greater element beginning.
2971 (org-test-with-temp-text
2972 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2975 (should (looking-at "#\\+BEGIN_CENTER")))
2977 (org-test-with-temp-text "* Top
2984 Paragraph within sub2.
2987 ;; 4.1. Within an item: move to the item beginning.
2990 (should (looking-at " - sub2"))
2991 ;; 4.2. At an item in a sub-list: move to parent item.
2994 (should (looking-at "- item1"))
2995 ;; 4.3. At an item in top list: move to beginning of whole list.
2998 (should (looking-at "- item1"))
2999 ;; 4.4. Special case. At very top point: should move to parent of
3003 (should (looking-at "\\* Top"))))
3005 (ert-deftest test-org
/down-element
()
3006 "Test `org-down-element' specifications."
3007 ;; Error when the element hasn't got a recursive type.
3008 (org-test-with-temp-text "Paragraph."
3009 (should-error (org-down-element)))
3010 ;; Error when the element has no contents
3011 (org-test-with-temp-text "* Headline"
3012 (should-error (org-down-element)))
3013 ;; When at a plain-list, move to first item.
3014 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3017 (should (looking-at " - Item 1.1")))
3018 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3020 (should (looking-at " Item 1")))
3021 ;; When at a table, move to first row
3022 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3024 (should (looking-at " a | b |")))
3025 ;; Otherwise, move inside the greater element.
3026 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3028 (should (looking-at "Paragraph"))))
3030 (ert-deftest test-org
/drag-element-backward
()
3031 "Test `org-drag-element-backward' specifications."
3035 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3036 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3037 (org-drag-element-backward)
3041 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3042 (org-test-with-temp-text
3043 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3044 (org-drag-element-backward)
3046 ;; Preserve blank lines.
3048 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3049 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3050 (org-drag-element-backward)
3054 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3055 (org-drag-element-backward)
3056 (looking-at-p "2")))
3057 ;; Error when trying to move first element of buffer.
3059 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3060 (org-drag-element-backward)))
3061 ;; Error when trying to swap nested elements.
3063 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3065 (org-drag-element-backward)))
3066 ;; Error when trying to swap an headline element and a non-headline
3069 (org-test-with-temp-text "Test.\n* Head 1"
3071 (org-drag-element-backward)))
3072 ;; Preserve visibility of elements and their contents.
3074 (equal '((63 .
82) (26 .
48))
3075 (org-test-with-temp-text "
3083 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3084 (search-backward "- item 1")
3085 (org-drag-element-backward)
3086 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3087 (overlays-in (point-min) (point-max)))))))
3089 (ert-deftest test-org
/drag-element-forward
()
3090 "Test `org-drag-element-forward' specifications."
3091 ;; 1. Error when trying to move first element of buffer.
3092 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3094 (should-error (org-drag-element-forward)))
3095 ;; 2. Error when trying to swap nested elements.
3096 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3098 (should-error (org-drag-element-forward)))
3099 ;; 3. Error when trying to swap a non-headline element and an
3101 (org-test-with-temp-text "Test.\n* Head 1"
3102 (should-error (org-drag-element-forward)))
3103 ;; 4. Otherwise, swap elements, preserving column and blank lines
3104 ;; between elements.
3105 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3106 (search-forward "graph")
3107 (org-drag-element-forward)
3108 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3109 (should (looking-at " 1")))
3110 ;; 5. Preserve visibility of elements and their contents.
3111 (org-test-with-temp-text "
3119 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3120 (search-backward "#+BEGIN_CENTER")
3121 (org-drag-element-forward)
3124 '((63 .
82) (26 .
48))
3125 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3126 (overlays-in (point-min) (point-max)))))))
3128 (ert-deftest test-org
/next-block
()
3129 "Test `org-next-block' specifications."
3132 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3134 (looking-at "#\\+BEGIN_CENTER")))
3137 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3138 (let ((case-fold-search nil
))
3140 (looking-at "#\\+begin_center"))))
3141 ;; Ignore current line.
3143 (org-test-with-temp-text
3144 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3146 (looking-at "#\\+BEGIN_CENTER")))
3147 ;; Throw an error when no block is found.
3149 (org-test-with-temp-text "Paragraph"
3150 (org-next-block 1)))
3151 ;; With an argument, skip many blocks at once.
3153 (org-test-with-temp-text
3154 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3156 (looking-at "#\\+BEGIN_QUOTE")))
3157 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3159 (org-test-with-temp-text
3160 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3161 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3162 (looking-at "#\\+BEGIN_QUOTE")))
3163 ;; Optional argument is also case-insensitive.
3165 (org-test-with-temp-text
3166 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3167 (let ((case-fold-search nil
))
3168 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3169 (looking-at "#\\+begin_quote")))))
3171 (ert-deftest test-org
/previous-block
()
3172 "Test `org-previous-block' specifications."
3175 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3176 (org-previous-block 1)
3177 (looking-at "#\\+BEGIN_CENTER")))
3180 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3181 (let ((case-fold-search nil
))
3182 (org-previous-block 1)
3183 (looking-at "#\\+begin_center"))))
3184 ;; Ignore current line.
3186 (org-test-with-temp-text
3187 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3188 (org-previous-block 1)
3189 (looking-at "#\\+BEGIN_QUOTE")))
3190 ;; Throw an error when no block is found.
3192 (org-test-with-temp-text "Paragraph<point>"
3193 (org-previous-block 1)))
3194 ;; With an argument, skip many blocks at once.
3196 (org-test-with-temp-text
3197 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3198 (org-previous-block 2)
3199 (looking-at "#\\+BEGIN_CENTER")))
3200 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3202 (org-test-with-temp-text
3203 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3204 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3205 (looking-at "#\\+BEGIN_QUOTE")))
3206 ;; Optional argument is also case-insensitive.
3208 (org-test-with-temp-text
3209 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3210 (let ((case-fold-search nil
))
3211 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3212 (looking-at "#\\+begin_quote")))))
3215 ;;; Outline structure
3217 (ert-deftest test-org
/demote
()
3218 "Test `org-demote' specifications."
3219 ;; Add correct number of stars according to `org-odd-levels-only'.
3222 (org-test-with-temp-text "* H"
3223 (let ((org-odd-levels-only nil
)) (org-demote))
3224 (org-current-level))))
3227 (org-test-with-temp-text "* H"
3228 (let ((org-odd-levels-only t
)) (org-demote))
3229 (org-current-level))))
3230 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3232 (org-test-with-temp-text "* H :tag:"
3233 (let ((org-tags-column 10)
3234 (org-auto-align-tags t
)
3235 (org-odd-levels-only nil
))
3237 (org-move-to-column 10)
3238 (looking-at-p ":tag:$")))
3240 (org-test-with-temp-text "* H :tag:"
3241 (let ((org-tags-column 10)
3242 (org-auto-align-tags nil
)
3243 (org-odd-levels-only nil
))
3245 (org-move-to-column 10)
3246 (looking-at-p ":tag:$")))
3247 ;; When `org-adapt-indentation' is non-nil, always indent planning
3248 ;; info and property drawers accordingly.
3251 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3252 (let ((org-odd-levels-only nil
)
3253 (org-adapt-indentation t
))
3256 (org-get-indentation))))
3259 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3260 (let ((org-odd-levels-only nil
)
3261 (org-adapt-indentation t
))
3264 (org-get-indentation))))
3267 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3268 (let ((org-odd-levels-only nil
)
3269 (org-adapt-indentation nil
))
3272 (org-get-indentation))))
3273 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3274 ;; section accordingly. Ignore, however, footnote definitions and
3275 ;; inlinetasks boundaries.
3278 (org-test-with-temp-text "* H\n Paragraph"
3279 (let ((org-odd-levels-only nil
)
3280 (org-adapt-indentation t
))
3283 (org-get-indentation))))
3286 (org-test-with-temp-text "* H\n Paragraph"
3287 (let ((org-odd-levels-only nil
)
3288 (org-adapt-indentation nil
))
3291 (org-get-indentation))))
3294 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3295 (let ((org-odd-levels-only nil
)
3296 (org-adapt-indentation t
))
3298 (goto-char (point-max))
3299 (org-get-indentation))))
3302 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3303 (let ((org-odd-levels-only nil
)
3304 (org-adapt-indentation t
))
3306 (goto-char (point-max))
3307 (org-get-indentation))))
3308 (when (featurep 'org-inlinetask
)
3311 (let ((org-inlinetask-min-level 5)
3312 (org-adapt-indentation t
))
3313 (org-test-with-temp-text "* H\n***** I\n***** END"
3316 (org-get-indentation))))))
3317 (when (featurep 'org-inlinetask
)
3320 (let ((org-inlinetask-min-level 5)
3321 (org-adapt-indentation t
))
3322 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3325 (org-get-indentation))))))
3326 ;; Ignore contents of source blocks or example blocks when
3327 ;; indentation should be preserved (through
3328 ;; `org-src-preserve-indentation' or "-i" flag).
3331 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3332 (let ((org-adapt-indentation t
)
3333 (org-src-preserve-indentation nil
))
3336 (org-get-indentation))))
3339 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3340 (let ((org-adapt-indentation t
)
3341 (org-src-preserve-indentation t
))
3344 (org-get-indentation))))
3347 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3348 (let ((org-adapt-indentation t
)
3349 (org-src-preserve-indentation t
))
3352 (org-get-indentation))))
3355 (org-test-with-temp-text
3356 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3357 (let ((org-adapt-indentation t
)
3358 (org-src-preserve-indentation nil
))
3361 (org-get-indentation)))))
3363 (ert-deftest test-org
/promote
()
3364 "Test `org-promote' specifications."
3365 ;; Return an error if headline is to be promoted to level 0, unless
3366 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3367 ;; headline becomes a comment.
3369 (org-test-with-temp-text "* H"
3370 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3373 (org-test-with-temp-text "* H"
3374 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3376 ;; Remove correct number of stars according to
3377 ;; `org-odd-levels-only'.
3380 (org-test-with-temp-text "*** H"
3381 (let ((org-odd-levels-only nil
)) (org-promote))
3382 (org-current-level))))
3385 (org-test-with-temp-text "*** H"
3386 (let ((org-odd-levels-only t
)) (org-promote))
3387 (org-current-level))))
3388 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3390 (org-test-with-temp-text "** H :tag:"
3391 (let ((org-tags-column 10)
3392 (org-auto-align-tags t
)
3393 (org-odd-levels-only nil
))
3395 (org-move-to-column 10)
3396 (looking-at-p ":tag:$")))
3398 (org-test-with-temp-text "** H :tag:"
3399 (let ((org-tags-column 10)
3400 (org-auto-align-tags nil
)
3401 (org-odd-levels-only nil
))
3403 (org-move-to-column 10)
3404 (looking-at-p ":tag:$")))
3405 ;; When `org-adapt-indentation' is non-nil, always indent planning
3406 ;; info and property drawers.
3409 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3410 (let ((org-odd-levels-only nil
)
3411 (org-adapt-indentation t
))
3414 (org-get-indentation))))
3417 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3418 (let ((org-odd-levels-only nil
)
3419 (org-adapt-indentation t
))
3422 (org-get-indentation))))
3425 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3426 (let ((org-odd-levels-only nil
)
3427 (org-adapt-indentation nil
))
3430 (org-get-indentation))))
3431 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3432 ;; section accordingly. Ignore, however, footnote definitions and
3433 ;; inlinetasks boundaries.
3436 (org-test-with-temp-text "** H\n Paragraph"
3437 (let ((org-odd-levels-only nil
)
3438 (org-adapt-indentation t
))
3441 (org-get-indentation))))
3444 (org-test-with-temp-text "** H\n Paragraph"
3445 (let ((org-odd-levels-only nil
)
3446 (org-adapt-indentation nil
))
3449 (org-get-indentation))))
3452 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3453 (let ((org-odd-levels-only nil
)
3454 (org-adapt-indentation t
))
3457 (org-get-indentation))))
3458 (when (featurep 'org-inlinetask
)
3461 (let ((org-inlinetask-min-level 5)
3462 (org-adapt-indentation t
))
3463 (org-test-with-temp-text "** H\n***** I\n***** END"
3466 (org-get-indentation))))))
3467 (when (featurep 'org-inlinetask
)
3470 (let ((org-inlinetask-min-level 5)
3471 (org-adapt-indentation t
))
3472 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3475 (org-get-indentation))))))
3476 ;; Give up shifting if it would break document's structure
3480 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3481 (let ((org-odd-levels-only nil
)
3482 (org-adapt-indentation t
))
3485 (org-get-indentation))))
3488 (org-test-with-temp-text "** H\n Paragraph\n * list."
3489 (let ((org-odd-levels-only nil
)
3490 (org-adapt-indentation t
))
3493 (org-get-indentation))))
3494 ;; Ignore contents of source blocks or example blocks when
3495 ;; indentation should be preserved (through
3496 ;; `org-src-preserve-indentation' or "-i" flag).
3499 (org-test-with-temp-text
3500 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3501 (let ((org-adapt-indentation t
)
3502 (org-src-preserve-indentation nil
)
3503 (org-odd-levels-only nil
))
3506 (org-get-indentation))))
3509 (org-test-with-temp-text
3510 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3511 (let ((org-adapt-indentation t
)
3512 (org-src-preserve-indentation t
)
3513 (org-odd-levels-only nil
))
3516 (org-get-indentation))))
3519 (org-test-with-temp-text
3520 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3521 (let ((org-adapt-indentation t
)
3522 (org-src-preserve-indentation t
)
3523 (org-odd-levels-only nil
))
3526 (org-get-indentation))))
3529 (org-test-with-temp-text
3530 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3531 (let ((org-adapt-indentation t
)
3532 (org-src-preserve-indentation nil
)
3533 (org-odd-levels-only nil
))
3536 (org-get-indentation)))))
3541 (ert-deftest test-org
/at-planning-p
()
3542 "Test `org-at-planning-p' specifications."
3545 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3546 (org-at-planning-p)))
3548 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3549 (org-at-planning-p)))
3550 ;; Correctly find planning attached to inlinetasks.
3551 (when (featurep 'org-inlinetask
)
3553 (org-test-with-temp-text
3554 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3555 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3557 (org-test-with-temp-text
3558 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3559 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3561 (org-test-with-temp-text
3562 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3563 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3565 (org-test-with-temp-text
3566 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3567 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3569 (ert-deftest test-org
/add-planning-info
()
3570 "Test `org-add-planning-info'."
3571 ;; Create deadline when `org-adapt-indentation' is non-nil.
3573 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3574 (org-test-with-temp-text "* H\nParagraph<point>"
3575 (let ((org-adapt-indentation t
))
3576 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3577 (replace-regexp-in-string
3578 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3580 ;; Create deadline when `org-adapt-indentation' is nil.
3582 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3583 (org-test-with-temp-text "* H\nParagraph<point>"
3584 (let ((org-adapt-indentation nil
))
3585 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3586 (replace-regexp-in-string
3587 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3589 ;; Update deadline when `org-adapt-indentation' is non-nil.
3591 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3592 (org-test-with-temp-text "\
3594 DEADLINE: <2015-06-24 Wed>
3596 (let ((org-adapt-indentation t
))
3597 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3598 (replace-regexp-in-string
3599 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3601 ;; Update deadline when `org-adapt-indentation' is nil.
3603 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3604 (org-test-with-temp-text "\
3606 DEADLINE: <2015-06-24 Wed>
3608 (let ((org-adapt-indentation nil
))
3609 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3610 (replace-regexp-in-string
3611 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3613 ;; Schedule when `org-adapt-indentation' is non-nil.
3615 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3616 (org-test-with-temp-text "* H\nParagraph<point>"
3617 (let ((org-adapt-indentation t
))
3618 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3619 (replace-regexp-in-string
3620 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3622 ;; Schedule when `org-adapt-indentation' is nil.
3624 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3625 (org-test-with-temp-text "* H\nParagraph<point>"
3626 (let ((org-adapt-indentation nil
))
3627 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3628 (replace-regexp-in-string
3629 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3631 ;; Add deadline when scheduled.
3635 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3637 (org-test-with-temp-text "\
3639 SCHEDULED: <2015-06-24 Wed>
3641 (let ((org-adapt-indentation t
))
3642 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3643 (replace-regexp-in-string
3644 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3646 ;; Remove middle entry.
3650 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3652 (org-test-with-temp-text "\
3654 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3656 (let ((org-adapt-indentation t
))
3657 (org-add-planning-info nil nil
'deadline
))
3658 (replace-regexp-in-string
3659 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3661 ;; Remove last entry and then middle entry (order should not
3666 CLOSED: [2015-06-24]
3668 (org-test-with-temp-text "\
3670 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3672 (let ((org-adapt-indentation t
))
3673 (org-add-planning-info nil nil
'scheduled
'deadline
))
3674 (replace-regexp-in-string
3675 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3677 ;; Remove closed when `org-adapt-indentation' is non-nil.
3679 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3680 (org-test-with-temp-text "\
3682 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3684 (let ((org-adapt-indentation t
))
3685 (org-add-planning-info nil nil
'closed
))
3686 (replace-regexp-in-string
3687 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3690 (equal "* H\n Paragraph"
3691 (org-test-with-temp-text "\
3693 CLOSED: [2015-06-25 Thu]
3695 (let ((org-adapt-indentation t
))
3696 (org-add-planning-info nil nil
'closed
))
3697 (replace-regexp-in-string
3698 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3700 ;; Remove closed when `org-adapt-indentation' is nil.
3702 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3703 (org-test-with-temp-text "\
3705 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3707 (let ((org-adapt-indentation nil
))
3708 (org-add-planning-info nil nil
'closed
))
3709 (replace-regexp-in-string
3710 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3713 (equal "* H\nParagraph"
3714 (org-test-with-temp-text "\
3716 CLOSED: [2015-06-25 Thu]
3718 (let ((org-adapt-indentation nil
))
3719 (org-add-planning-info nil nil
'closed
))
3720 (replace-regexp-in-string
3721 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3723 ;; Remove closed entry and delete empty line.
3728 (org-test-with-temp-text "\
3730 CLOSED: [2015-06-24 Wed]
3732 (let ((org-adapt-indentation t
))
3733 (org-add-planning-info nil nil
'closed
))
3734 (replace-regexp-in-string
3735 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3737 ;; Remove one entry and update another.
3739 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3740 (org-test-with-temp-text "\
3742 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3744 (let ((org-adapt-indentation t
))
3745 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3746 (replace-regexp-in-string
3747 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3753 (ert-deftest test-org
/buffer-property-keys
()
3754 "Test `org-buffer-property-keys' specifications."
3755 ;; Retrieve properties accross siblings.
3758 (org-test-with-temp-text "
3767 (org-buffer-property-keys))))
3768 ;; Retrieve properties accross children.
3771 (org-test-with-temp-text "
3780 (org-buffer-property-keys))))
3781 ;; Retrieve muliple properties in the same drawer.
3784 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3785 (org-buffer-property-keys))))
3786 ;; Ignore extension symbol in property name.
3789 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3790 (org-buffer-property-keys))))
3791 ;; With non-nil COLUMNS, extract property names from columns.
3794 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3795 (org-buffer-property-keys nil nil t
))))
3797 (equal '("A" "B" "COLUMNS")
3798 (org-test-with-temp-text
3799 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3800 (org-buffer-property-keys nil nil t
))))
3801 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
3804 (org-test-with-temp-text
3805 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
3806 (org-buffer-property-keys nil nil nil t
)))))
3808 (ert-deftest test-org
/property-values
()
3809 "Test `org-property-values' specifications."
3813 (org-test-with-temp-text
3814 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3815 (org-property-values "A"))))
3816 ;; Ignore empty values.
3818 (org-test-with-temp-text
3819 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3820 (org-property-values "A")))
3821 ;; Take into consideration extended values.
3824 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3825 (org-property-values "A")))))
3827 (ert-deftest test-org
/find-property
()
3828 "Test `org-find-property' specifications."
3832 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3833 (org-find-property "prop"))))
3834 ;; Ignore false positives.
3837 (org-test-with-temp-text
3838 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3839 (org-find-property "A"))))
3840 ;; Return first entry found in buffer.
3843 (org-test-with-temp-text
3844 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3845 (org-find-property "A"))))
3846 ;; Only search visible part of the buffer.
3849 (org-test-with-temp-text
3850 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3851 (org-narrow-to-subtree)
3852 (org-find-property "A"))))
3853 ;; With optional argument, only find entries with a specific value.
3855 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3856 (org-find-property "A" "2")))
3859 (org-test-with-temp-text
3860 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3861 (org-find-property "A" "2"))))
3862 ;; Use "nil" for explicit nil values.
3865 (org-test-with-temp-text
3866 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3867 (org-find-property "A" "nil")))))
3869 (ert-deftest test-org
/entry-delete
()
3870 "Test `org-entry-delete' specifications."
3874 " *:PROPERTIES:\n *:B: +2\n *:END:"
3875 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3876 (org-entry-delete (point) "A")
3878 ;; Also remove accumulated properties.
3882 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3883 (org-entry-delete (point) "A")
3885 ;; When last property is removed, remove the property drawer.
3889 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3890 (org-entry-delete (point) "A")
3892 ;; Return a non-nil value when some property was removed.
3894 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3895 (org-entry-delete (point) "A")))
3897 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3898 (org-entry-delete (point) "C"))))
3900 (ert-deftest test-org
/entry-get
()
3901 "Test `org-entry-get' specifications."
3905 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3906 (org-entry-get (point) "A"))))
3910 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3911 (org-entry-get (point) "a"))))
3912 ;; Handle extended values, both before and after base value.
3915 (org-test-with-temp-text
3916 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3917 (org-entry-get (point) "A"))))
3918 ;; Empty values are returned as the empty string.
3921 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3922 (org-entry-get (point) "A"))))
3923 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3924 ;; otherwise, return nil.
3926 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3927 (org-entry-get (point) "A")))
3930 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3931 (org-entry-get (point) "A" nil t
))))
3932 ;; Return nil when no property is found, independently on the
3933 ;; LITERAL-NIL argument.
3935 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3936 (org-entry-get (point) "B")))
3938 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3939 (org-entry-get (point) "B" nil t
)))
3940 ;; Handle inheritance, when allowed. Include extended values and
3941 ;; possibly global values.
3945 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3946 (org-entry-get (point) "A" t
))))
3950 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3951 (let ((org-use-property-inheritance t
))
3952 (org-entry-get (point) "A" 'selective
)))))
3954 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3955 (let ((org-use-property-inheritance nil
))
3956 (org-entry-get (point) "A" 'selective
))))
3960 (org-test-with-temp-text
3961 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3962 (org-entry-get (point-max) "A" t
))))
3965 (org-test-with-temp-text
3966 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3968 (org-entry-get (point-max) "A" t
))))
3971 (org-test-with-temp-text
3972 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3974 (org-entry-get (point-max) "A" t
)))))
3976 (ert-deftest test-org
/entry-properties
()
3977 "Test `org-entry-properties' specifications."
3978 ;; Get "ITEM" property.
3981 (org-test-with-temp-text "* TODO H"
3982 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3985 (org-test-with-temp-text "* TODO H"
3986 (cdr (assoc "ITEM" (org-entry-properties))))))
3987 ;; Get "TODO" property. TODO keywords are case sensitive.
3990 (org-test-with-temp-text "* TODO H"
3991 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3994 (org-test-with-temp-text "* TODO H"
3995 (cdr (assoc "TODO" (org-entry-properties))))))
3997 (org-test-with-temp-text "* H"
3998 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4000 (org-test-with-temp-text "* todo H"
4001 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4002 ;; Get "PRIORITY" property.
4005 (org-test-with-temp-text "* [#A] H"
4006 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4009 (org-test-with-temp-text "* [#A] H"
4010 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4012 (equal (char-to-string org-default-priority
)
4013 (org-test-with-temp-text "* H"
4014 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4015 ;; Get "FILE" property.
4017 (org-test-with-temp-text-in-file "* H\nParagraph"
4018 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4019 (buffer-file-name))))
4021 (org-test-with-temp-text-in-file "* H\nParagraph"
4022 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4023 (buffer-file-name))))
4025 (org-test-with-temp-text "* H\nParagraph"
4026 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4027 ;; Get "TAGS" property.
4029 (equal ":tag1:tag2:"
4030 (org-test-with-temp-text "* H :tag1:tag2:"
4031 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4033 (equal ":tag1:tag2:"
4034 (org-test-with-temp-text "* H :tag1:tag2:"
4035 (cdr (assoc "TAGS" (org-entry-properties))))))
4037 (org-test-with-temp-text "* H"
4038 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4039 ;; Get "ALLTAGS" property.
4041 (equal ":tag1:tag2:"
4042 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4043 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4045 (equal ":tag1:tag2:"
4046 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4047 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4049 (org-test-with-temp-text "* H"
4050 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4051 ;; Get "BLOCKED" property.
4054 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4055 (let ((org-enforce-todo-dependencies t
)
4057 '(org-block-todo-from-children-or-siblings-or-parent)))
4058 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4061 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4062 (let ((org-enforce-todo-dependencies t
)
4064 '(org-block-todo-from-children-or-siblings-or-parent)))
4065 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4066 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4070 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4071 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4075 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4076 (cdr (assoc "CLOSED" (org-entry-properties))))))
4078 (org-test-with-temp-text "* H"
4079 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4083 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4084 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4088 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4089 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4091 (org-test-with-temp-text "* H"
4092 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4096 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4097 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4101 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4102 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4104 (org-test-with-temp-text "* H"
4105 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4109 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4110 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4113 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4114 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4117 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4118 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4121 (org-test-with-temp-text
4122 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4124 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4125 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4126 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4128 (equal "<2012-03-29 thu.>"
4129 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4130 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4132 (equal "[2012-03-29 thu.]"
4133 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4134 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4136 (equal "<2012-03-29 thu.>"
4137 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4138 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4140 (equal "[2014-03-04 tue.]"
4141 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4142 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
4143 ;; Get standard properties.
4146 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4147 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4148 ;; Handle extended properties.
4151 (org-test-with-temp-text
4152 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4153 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4156 (org-test-with-temp-text
4157 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4158 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4159 ;; Ignore forbidden (special) properties.
4161 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4162 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4164 (ert-deftest test-org
/entry-put
()
4165 "Test `org-entry-put' specifications."
4166 ;; Error when not a string or nil.
4168 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4169 (org-entry-put 1 "test" 2)))
4170 ;; Error when property name is invalid.
4172 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4173 (org-entry-put 1 "no space" "value")))
4175 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4176 (org-entry-put 1 "" "value")))
4177 ;; Set "TODO" property.
4179 (string-match (regexp-quote " TODO H")
4180 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4181 (org-entry-put (point) "TODO" "TODO")
4184 (string-match (regexp-quote "* H")
4185 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4186 (org-entry-put (point) "TODO" nil
)
4188 ;; Set "PRIORITY" property.
4191 (org-test-with-temp-text "* [#B] H"
4192 (org-entry-put (point) "PRIORITY" "A")
4196 (org-test-with-temp-text "* [#B] H"
4197 (org-entry-put (point) "PRIORITY" nil
)
4199 ;; Set "SCHEDULED" property.
4201 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4202 (org-test-with-temp-text "* H"
4203 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4207 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4208 (org-entry-put (point) "SCHEDULED" nil
)
4211 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4212 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4213 (org-entry-put (point) "SCHEDULED" "earlier")
4216 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4217 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4218 (org-entry-put (point) "SCHEDULED" "later")
4220 ;; Set "DEADLINE" property.
4222 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4223 (org-test-with-temp-text "* H"
4224 (org-entry-put (point) "DEADLINE" "2014-03-04")
4228 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4229 (org-entry-put (point) "DEADLINE" nil
)
4232 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4233 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4234 (org-entry-put (point) "DEADLINE" "earlier")
4237 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4238 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4239 (org-entry-put (point) "DEADLINE" "later")
4241 ;; Set "CATEGORY" property
4243 (string-match "^ *:CATEGORY: cat"
4244 (org-test-with-temp-text "* H"
4245 (org-entry-put (point) "CATEGORY" "cat")
4247 ;; Regular properties, with or without pre-existing drawer.
4249 (string-match "^ *:A: +2$"
4250 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4251 (org-entry-put (point) "A" "2")
4254 (string-match "^ *:A: +1$"
4255 (org-test-with-temp-text "* H"
4256 (org-entry-put (point) "A" "1")
4258 ;; Special case: two consecutive headlines.
4260 (string-match "\\* A\n *:PROPERTIES:"
4261 (org-test-with-temp-text "* A\n** B"
4262 (org-entry-put (point) "A" "1")
4268 (ert-deftest test-org
/update-radio-target-regexp
()
4269 "Test `org-update-radio-target-regexp' specifications."
4270 ;; Properly update cache with no previous radio target regexp.
4273 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4274 (save-excursion (goto-char (point-max)) (org-element-context))
4276 (search-forward "o")
4278 (org-update-radio-target-regexp)
4279 (goto-char (point-max))
4280 (org-element-type (org-element-context)))))
4281 ;; Properly update cache with previous radio target regexp.
4284 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4285 (save-excursion (goto-char (point-max)) (org-element-context))
4287 (search-forward "o")
4289 (org-update-radio-target-regexp)
4290 (search-backward "r")
4293 (org-update-radio-target-regexp)
4294 (goto-char (point-max))
4295 (delete-region (line-beginning-position) (point))
4297 (org-element-type (org-element-context))))))
4302 (ert-deftest test-org
/match-sparse-tree
()
4303 "Test `org-match-sparse-tree' specifications."
4306 (org-test-with-temp-text "* H\n** H1 :tag:"
4307 (org-match-sparse-tree nil
"tag")
4308 (search-forward "H1")
4309 (org-invisible-p2)))
4311 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4312 (org-match-sparse-tree nil
"tag")
4313 (search-forward "H2")
4314 (org-invisible-p2)))
4315 ;; "-" operator for tags.
4317 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4318 (org-match-sparse-tree nil
"tag1-tag2")
4319 (search-forward "H1")
4320 (org-invisible-p2)))
4322 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4323 (org-match-sparse-tree nil
"tag1-tag2")
4324 (search-forward "H2")
4325 (org-invisible-p2)))
4326 ;; "&" operator for tags.
4328 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4329 (org-match-sparse-tree nil
"tag1&tag2")
4330 (search-forward "H1")
4331 (org-invisible-p2)))
4333 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4334 (org-match-sparse-tree nil
"tag1&tag2")
4335 (search-forward "H2")
4336 (org-invisible-p2)))
4337 ;; "|" operator for tags.
4339 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4340 (org-match-sparse-tree nil
"tag1|tag2")
4341 (search-forward "H1")
4342 (org-invisible-p2)))
4344 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4345 (org-match-sparse-tree nil
"tag1|tag2")
4346 (search-forward "H2")
4347 (org-invisible-p2)))
4348 ;; Regexp match on tags.
4350 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4351 (org-match-sparse-tree nil
"{^tag.*}")
4352 (search-forward "H1")
4353 (org-invisible-p2)))
4355 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4356 (org-match-sparse-tree nil
"{^tag.*}")
4357 (search-forward "H2")
4358 (org-invisible-p2)))
4359 ;; Match group tags.
4361 (org-test-with-temp-text
4362 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4363 (org-match-sparse-tree nil
"work")
4364 (search-forward "H1")
4365 (org-invisible-p2)))
4367 (org-test-with-temp-text
4368 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4369 (org-match-sparse-tree nil
"work")
4370 (search-forward "H2")
4371 (org-invisible-p2)))
4372 ;; Match group tags with hard brackets.
4374 (org-test-with-temp-text
4375 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4376 (org-match-sparse-tree nil
"work")
4377 (search-forward "H1")
4378 (org-invisible-p2)))
4380 (org-test-with-temp-text
4381 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4382 (org-match-sparse-tree nil
"work")
4383 (search-forward "H2")
4384 (org-invisible-p2)))
4385 ;; Match tags in hierarchies
4387 (org-test-with-temp-text
4388 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4389 #+TAGS: [ Lev_2 : Lev_3 ]\n
4390 #+TAGS: { Lev_3 : Lev_4 }\n
4391 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4392 (org-match-sparse-tree nil
"Lev_1")
4393 (search-forward "H4")
4394 (org-invisible-p2)))
4395 ;; Match regular expressions in tags
4397 (org-test-with-temp-text
4398 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4399 (org-match-sparse-tree nil
"Lev")
4400 (search-forward "H1")
4401 (org-invisible-p2)))
4403 (org-test-with-temp-text
4404 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4405 (org-match-sparse-tree nil
"Lev")
4406 (search-forward "H1")
4407 (org-invisible-p2)))
4408 ;; Match properties.
4410 (org-test-with-temp-text
4411 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4412 (org-match-sparse-tree nil
"A=\"1\"")
4413 (search-forward "H2")
4414 (org-invisible-p2)))
4416 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4417 (org-match-sparse-tree nil
"A=\"1\"")
4418 (search-forward "H2")
4419 (org-invisible-p2)))
4420 ;; Case is not significant when matching properties.
4422 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4423 (org-match-sparse-tree nil
"a=\"1\"")
4424 (search-forward "H2")
4425 (org-invisible-p2)))
4427 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4428 (org-match-sparse-tree nil
"A=\"1\"")
4429 (search-forward "H2")
4430 (org-invisible-p2)))
4431 ;; Match special LEVEL property.
4433 (org-test-with-temp-text "* H\n** H1\n*** H2"
4434 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4435 (search-forward "H1")
4436 (org-invisible-p2)))
4438 (org-test-with-temp-text "* H\n** H1\n*** H2"
4439 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4440 (search-forward "H2")
4441 (org-invisible-p2)))
4442 ;; Comparison operators when matching properties.
4444 (org-test-with-temp-text
4445 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4446 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4447 (search-forward "H1")
4448 (org-invisible-p2)))
4450 (org-test-with-temp-text
4451 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4452 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4453 (search-forward "H2")
4454 (org-invisible-p2)))
4455 ;; Regexp match on properties values.
4457 (org-test-with-temp-text
4458 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4459 (org-match-sparse-tree nil
"A={f.*}")
4460 (search-forward "H1")
4461 (org-invisible-p2)))
4463 (org-test-with-temp-text
4464 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4465 (org-match-sparse-tree nil
"A={f.*}")
4466 (search-forward "H2")
4467 (org-invisible-p2)))
4468 ;; With an optional argument, limit match to TODO entries.
4470 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4471 (org-match-sparse-tree t
"tag")
4472 (search-forward "H1")
4473 (org-invisible-p2)))
4475 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4476 (org-match-sparse-tree t
"tag")
4477 (search-forward "H2")
4478 (org-invisible-p2))))
4480 (ert-deftest test-org
/occur
()
4481 "Test `org-occur' specifications."
4482 ;; Count number of matches.
4485 (org-test-with-temp-text "* H\nA\n* H2"
4489 (org-test-with-temp-text "* H\nA\n* H2\nA"
4491 ;; Test CALLBACK optional argument.
4494 (org-test-with-temp-text "* H\nA\n* H2"
4495 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4498 (org-test-with-temp-text "* H\nA\n* H2\nA"
4499 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4500 ;; Case-fold searches according to `org-occur-case-fold-search'.
4503 (org-test-with-temp-text "Aa"
4504 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
4507 (org-test-with-temp-text "Aa"
4508 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
4511 (org-test-with-temp-text "Aa"
4512 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
4515 (org-test-with-temp-text "Aa"
4516 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
4519 (org-test-with-temp-text "Aa"
4520 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
4523 (org-test-with-temp-text "Aa"
4524 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
4529 (ert-deftest test-org
/tag-string-to-alist
()
4530 "Test `org-tag-string-to-alist' specifications."
4531 ;; Tag without selection key.
4532 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
4533 ;; Tag with selection key.
4534 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
4538 (org-tag-string-to-alist "[ group : t1 t2 ]")
4539 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
4540 ;; Mutually exclusive tags.
4541 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
4542 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
4545 (org-tag-string-to-alist "{ group : tag1 tag2 }")
4546 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
4548 (ert-deftest test-org
/tag-alist-to-string
()
4549 "Test `org-tag-alist-to-string' specifications."
4550 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
4551 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
4554 (org-tag-alist-to-string
4555 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4556 "[ group : t1 t2 ]"))
4558 (equal (org-tag-alist-to-string
4559 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
4563 (org-tag-alist-to-string
4564 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
4565 "{ group : tag1 tag2 }")))
4567 (ert-deftest test-org
/tag-alist-to-groups
()
4568 "Test `org-tag-alist-to-groups' specifications."
4570 (equal (org-tag-alist-to-groups
4571 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
4572 '(("group" "t1" "t2"))))
4575 (org-tag-alist-to-groups
4576 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4577 '(("group" "t1" "t2"))))
4579 (org-tag-alist-to-groups
4580 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
4582 (ert-deftest test-org
/tag-align
()
4583 "Test tags alignment."
4584 ;; Test aligning tags with different display width.
4586 ;; 12345678901234567890
4587 (equal "* Test :abc:"
4588 (org-test-with-temp-text "* Test :abc:"
4589 (let ((org-tags-column -
20)
4590 (indent-tabs-mode nil
))
4591 (org-fix-tags-on-the-fly))
4594 ;; 12345678901234567890
4595 (equal "* Test :日本語:"
4596 (org-test-with-temp-text "* Test :日本語:"
4597 (let ((org-tags-column -
20)
4598 (indent-tabs-mode nil
))
4599 (org-fix-tags-on-the-fly))
4601 ;; Make sure aligning tags do not skip invisible text.
4603 (equal "* [[linkx]] :tag:"
4604 (org-test-with-temp-text "* [[link<point>]] :tag:"
4605 (let ((org-tags-column 0))
4606 (org-fix-tags-on-the-fly)
4608 (buffer-string))))))
4610 (ert-deftest test-org
/tags-at
()
4612 (equal '("foo" "bar")
4613 (org-test-with-temp-text
4614 "* T<point>est :foo:bar:"
4615 (org-get-tags-at)))))
4620 (ert-deftest test-org
/time-stamp
()
4621 "Test `org-time-stamp' specifications."
4622 ;; Insert chosen time stamp at point.
4625 "Te<2014-03-04 .*?>xt"
4626 (org-test-with-temp-text "Te<point>xt"
4627 (cl-letf (((symbol-function 'org-read-date
)
4628 (lambda (&rest args
)
4629 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4630 (org-time-stamp nil
)
4632 ;; With a prefix argument, also insert time.
4635 "Te<2014-03-04 .*? 00:41>xt"
4636 (org-test-with-temp-text "Te<point>xt"
4637 (cl-letf (((symbol-function 'org-read-date
)
4638 (lambda (&rest args
)
4639 (apply #'encode-time
4640 (org-parse-time-string "2014-03-04 00:41")))))
4641 (org-time-stamp '(4))
4643 ;; With two universal prefix arguments, insert an active timestamp
4644 ;; with the current time without prompting the user.
4647 "Te<2014-03-04 .*? 00:41>xt"
4648 (org-test-with-temp-text "Te<point>xt"
4649 (cl-letf (((symbol-function 'current-time
)
4651 (apply #'encode-time
4652 (org-parse-time-string "2014-03-04 00:41")))))
4653 (org-time-stamp '(16))
4655 ;; When optional argument is non-nil, insert an inactive timestamp.
4658 "Te\\[2014-03-04 .*?\\]xt"
4659 (org-test-with-temp-text "Te<point>xt"
4660 (cl-letf (((symbol-function 'org-read-date
)
4661 (lambda (&rest args
)
4662 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4663 (org-time-stamp nil t
)
4665 ;; When called from a timestamp, replace existing one.
4669 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4670 (cl-letf (((symbol-function 'org-read-date
)
4671 (lambda (&rest args
)
4672 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4673 (org-time-stamp nil
)
4677 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4678 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4679 (cl-letf (((symbol-function 'org-read-date
)
4680 (lambda (&rest args
)
4681 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4682 (org-time-stamp nil
)
4684 ;; When replacing a timestamp, preserve repeater, if any.
4687 "<2014-03-04 .*? \\+2y>"
4688 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4689 (cl-letf (((symbol-function 'org-read-date
)
4690 (lambda (&rest args
)
4691 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4692 (org-time-stamp nil
)
4694 ;; When called twice in a raw, build a date range.
4697 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4698 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4699 (cl-letf (((symbol-function 'org-read-date
)
4700 (lambda (&rest args
)
4701 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4702 (let ((last-command 'org-time-stamp
)
4703 (this-command 'org-time-stamp
))
4704 (org-time-stamp nil
))
4705 (buffer-string))))))
4707 (ert-deftest test-org
/timestamp-has-time-p
()
4708 "Test `org-timestamp-has-time-p' specifications."
4711 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4712 (org-timestamp-has-time-p (org-element-context))))
4715 (org-test-with-temp-text "<2012-03-29 Thu>"
4716 (org-timestamp-has-time-p (org-element-context)))))
4718 (ert-deftest test-org
/timestamp-format
()
4719 "Test `org-timestamp-format' specifications."
4724 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4725 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4730 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4731 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4733 (ert-deftest test-org
/timestamp-split-range
()
4734 "Test `org-timestamp-split-range' specifications."
4735 ;; Extract range start (active).
4738 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4739 (let ((ts (org-timestamp-split-range (org-element-context))))
4740 (mapcar (lambda (p) (org-element-property p ts
))
4741 '(:year-end
:month-end
:day-end
))))))
4742 ;; Extract range start (inactive)
4745 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4746 (let ((ts (org-timestamp-split-range (org-element-context))))
4747 (mapcar (lambda (p) (org-element-property p ts
))
4748 '(:year-end
:month-end
:day-end
))))))
4749 ;; Extract range end (active).
4752 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4753 (let ((ts (org-timestamp-split-range
4754 (org-element-context) t
)))
4755 (mapcar (lambda (p) (org-element-property p ts
))
4756 '(:year-end
:month-end
:day-end
))))))
4757 ;; Extract range end (inactive)
4760 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4761 (let ((ts (org-timestamp-split-range
4762 (org-element-context) t
)))
4763 (mapcar (lambda (p) (org-element-property p ts
))
4764 '(:year-end
:month-end
:day-end
))))))
4765 ;; Return the timestamp if not a range.
4767 (org-test-with-temp-text "[2012-03-29 Thu]"
4768 (let* ((ts-orig (org-element-context))
4769 (ts-copy (org-timestamp-split-range ts-orig
)))
4770 (eq ts-orig ts-copy
))))
4772 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4773 (let* ((ts-orig (org-element-context))
4774 (ts-copy (org-timestamp-split-range ts-orig
)))
4775 (eq ts-orig ts-copy
)))))
4777 (ert-deftest test-org
/timestamp-translate
()
4778 "Test `org-timestamp-translate' specifications."
4779 ;; Translate whole date range.
4782 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4783 (let ((org-display-custom-times t
)
4784 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4785 (org-timestamp-translate (org-element-context))))))
4786 ;; Translate date range start.
4789 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4790 (let ((org-display-custom-times t
)
4791 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4792 (org-timestamp-translate (org-element-context) 'start
)))))
4793 ;; Translate date range end.
4796 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4797 (let ((org-display-custom-times t
)
4798 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4799 (org-timestamp-translate (org-element-context) 'end
)))))
4800 ;; Translate time range.
4803 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4804 (let ((org-display-custom-times t
)
4805 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4806 (org-timestamp-translate (org-element-context))))))
4807 ;; Translate non-range timestamp.
4810 (org-test-with-temp-text "<2012-03-29 Thu>"
4811 (let ((org-display-custom-times t
)
4812 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4813 (org-timestamp-translate (org-element-context))))))
4814 ;; Do not change `diary' timestamps.
4816 (equal "<%%(org-float t 4 2)>"
4817 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4818 (let ((org-display-custom-times t
)
4819 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4820 (org-timestamp-translate (org-element-context)))))))
4826 (ert-deftest test-org
/flag-drawer
()
4827 "Test `org-flag-drawer' specifications."
4830 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4832 (get-char-property (line-end-position) 'invisible
)))
4835 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4837 (org-flag-drawer nil
)
4838 (get-char-property (line-end-position) 'invisible
)))
4839 ;; Test optional argument.
4841 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4842 (let ((drawer (save-excursion (search-forward ":D2")
4843 (org-element-at-point))))
4844 (org-flag-drawer t drawer
)
4845 (get-char-property (progn (search-forward ":D2") (line-end-position))
4848 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4849 (let ((drawer (save-excursion (search-forward ":D2")
4850 (org-element-at-point))))
4851 (org-flag-drawer t drawer
)
4852 (get-char-property (line-end-position) 'invisible
))))
4853 ;; Do not hide fake drawers.
4855 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4858 (get-char-property (line-end-position) 'invisible
)))
4859 ;; Do not hide incomplete drawers.
4861 (org-test-with-temp-text ":D:\nparagraph"
4864 (get-char-property (line-end-position) 'invisible
)))
4865 ;; Do not hide drawers when called from final blank lines.
4867 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4868 (goto-char (point-max))
4870 (goto-char (point-min))
4871 (get-char-property (line-end-position) 'invisible
)))
4872 ;; Don't leave point in an invisible part of the buffer when hiding
4875 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4876 (goto-char (point-max))
4878 (get-char-property (point) 'invisible
))))
4880 (ert-deftest test-org
/hide-block-toggle
()
4881 "Test `org-hide-block-toggle' specifications."
4882 ;; Error when not at a block.
4884 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4885 (org-hide-block-toggle 'off
)
4886 (get-char-property (line-end-position) 'invisible
)))
4889 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4890 (org-hide-block-toggle)
4891 (get-char-property (line-end-position) 'invisible
)))
4893 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4894 (org-hide-block-toggle)
4895 (get-char-property (line-end-position) 'invisible
)))
4896 ;; Show block unconditionally when optional argument is `off'.
4898 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4899 (org-hide-block-toggle)
4900 (org-hide-block-toggle 'off
)
4901 (get-char-property (line-end-position) 'invisible
)))
4903 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4904 (org-hide-block-toggle 'off
)
4905 (get-char-property (line-end-position) 'invisible
)))
4906 ;; Hide block unconditionally when optional argument is non-nil.
4908 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4909 (org-hide-block-toggle t
)
4910 (get-char-property (line-end-position) 'invisible
)))
4912 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4913 (org-hide-block-toggle)
4914 (org-hide-block-toggle t
)
4915 (get-char-property (line-end-position) 'invisible
)))
4916 ;; Do not hide block when called from final blank lines.
4918 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4919 (org-hide-block-toggle)
4920 (goto-char (point-min))
4921 (get-char-property (line-end-position) 'invisible
)))
4922 ;; Don't leave point in an invisible part of the buffer when hiding
4925 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4926 (org-hide-block-toggle)
4927 (get-char-property (point) 'invisible
))))
4929 (ert-deftest test-org
/hide-block-toggle-maybe
()
4930 "Test `org-hide-block-toggle-maybe' specifications."
4932 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4933 (org-hide-block-toggle-maybe)))
4935 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4937 (ert-deftest test-org
/show-set-visibility
()
4938 "Test `org-show-set-visibility' specifications."
4939 ;; Do not throw an error before first heading.
4941 (org-test-with-temp-text "Preamble\n* Headline"
4942 (org-show-set-visibility 'tree
)
4944 ;; Test all visibility spans, both on headline and in entry.
4945 (let ((list-visible-lines
4946 (lambda (state headerp
)
4947 (org-test-with-temp-text "* Grandmother (0)
4958 **** The other child (11)
4963 (search-forward (if headerp
"Self" "Match"))
4964 (org-show-set-visibility state
)
4965 (goto-char (point-min))
4966 (let (result (line 0))
4968 (unless (org-invisible-p2) (push line result
))
4971 (nreverse result
))))))
4972 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4973 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4974 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4975 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4976 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4977 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4978 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4979 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4980 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4981 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4982 (funcall list-visible-lines
'tree nil
)))
4983 (should (equal '(0 1 3 4 5 7 12 13)
4984 (funcall list-visible-lines
'canonical t
)))
4985 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4986 (funcall list-visible-lines
'canonical nil
))))
4987 ;; When point is hidden in a drawer or a block, make sure to make it
4990 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
4991 (org-hide-block-toggle)
4992 (search-forward "Text")
4993 (org-show-set-visibility 'minimal
)
4994 (org-invisible-p2)))
4996 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
4998 (search-forward "Text")
4999 (org-show-set-visibility 'minimal
)
5000 (org-invisible-p2)))
5002 (org-test-with-temp-text
5003 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5006 (org-hide-block-toggle)
5007 (search-forward "Text")
5008 (org-show-set-visibility 'minimal
)
5009 (org-invisible-p2))))
5014 ;;; test-org.el ends here