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 ;; When on a list, insert an item instead, unless called with an
1173 ;; universal argument or if list is invisible. In this case, create
1174 ;; a new headline after contents.
1176 (equal "* H\n- item\n- "
1177 (org-test-with-temp-text "* H\n- item<point>"
1178 (let ((org-insert-heading-respect-content nil
))
1179 (org-insert-heading))
1182 (equal "* H\n- item\n- item 2\n* "
1183 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1184 (let ((org-insert-heading-respect-content nil
))
1185 (org-insert-heading '(4)))
1188 (equal "* H\n- item\n* "
1189 (org-test-with-temp-text "* H\n- item"
1191 (goto-char (point-max))
1192 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1194 ;; Preserve list visibility when inserting an item.
1198 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1199 (let ((org-cycle-include-plain-lists t
))
1203 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1204 (list (get-char-property (line-beginning-position 0) 'invisible
)
1205 (get-char-property (line-end-position 2) 'invisible
))))))
1206 ;; When called with two universal arguments, insert a new headline
1207 ;; at the end of the grandparent subtree.
1209 (equal "* H1\n** H3\n- item\n** H2\n** "
1210 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1211 (let ((org-insert-heading-respect-content nil
))
1212 (org-insert-heading '(16)))
1214 ;; When optional TOP-LEVEL argument is non-nil, always insert
1215 ;; a level 1 heading.
1217 (equal "* H1\n** H2\n* "
1218 (org-test-with-temp-text "* H1\n** H2<point>"
1219 (org-insert-heading nil nil t
)
1222 (equal "* H1\n- item\n* "
1223 (org-test-with-temp-text "* H1\n- item<point>"
1224 (org-insert-heading nil nil t
)
1226 ;; Corner case: correctly insert a headline after an empty one.
1229 (org-test-with-temp-text "* <point>"
1230 (org-insert-heading)
1233 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1234 "Test `org-insert-todo-heading-respect-content' specifications."
1235 ;; Create a TODO heading.
1237 (org-test-with-temp-text "* H1\n Body"
1238 (org-insert-todo-heading-respect-content)
1239 (nth 2 (org-heading-components))))
1240 ;; Add headline at the end of the first subtree
1242 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1243 (search-forward "H1Body")
1244 (org-insert-todo-heading-respect-content)
1245 (and (eobp) (org-at-heading-p))))
1246 ;; In a list, do not create a new item.
1248 (org-test-with-temp-text "* H\n- an item\n- another one"
1249 (search-forward "an ")
1250 (org-insert-todo-heading-respect-content)
1251 (and (eobp) (org-at-heading-p)))))
1253 (ert-deftest test-org
/clone-with-time-shift
()
1254 "Test `org-clone-subtree-with-time-shift'."
1255 ;; Clone non-repeating once.
1261 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1262 (org-clone-subtree-with-time-shift 1 "+2d")
1263 (replace-regexp-in-string
1264 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1266 ;; Clone repeating once.
1271 * H1\n<2015-06-25 +1w>
1273 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1274 (org-clone-subtree-with-time-shift 1 "+2d")
1275 (replace-regexp-in-string
1276 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1278 ;; Clone non-repeating zero times.
1283 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1284 (org-clone-subtree-with-time-shift 0 "+2d")
1285 (replace-regexp-in-string
1286 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1288 ;; Clone repeating "zero" times.
1292 * H1\n<2015-06-23 +1w>
1294 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1295 (org-clone-subtree-with-time-shift 0 "+2d")
1296 (replace-regexp-in-string
1297 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1301 ;;; Fixed-Width Areas
1303 (ert-deftest test-org
/toggle-fixed-width
()
1304 "Test `org-toggle-fixed-width' specifications."
1305 ;; No region: Toggle on fixed-width marker in paragraphs.
1308 (org-test-with-temp-text "A"
1309 (org-toggle-fixed-width)
1311 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1314 (org-test-with-temp-text ": A"
1315 (org-toggle-fixed-width)
1317 ;; No region: Toggle on marker in blank lines after elements or just
1318 ;; after a headline.
1321 (org-test-with-temp-text "* H\n"
1323 (org-toggle-fixed-width)
1326 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1327 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1328 (goto-char (point-max))
1329 (org-toggle-fixed-width)
1331 ;; No region: Toggle on marker in front of one line elements (e.g.,
1332 ;; headlines, clocks)
1334 (equal ": * Headline"
1335 (org-test-with-temp-text "* Headline"
1336 (org-toggle-fixed-width)
1339 (equal ": #+KEYWORD: value"
1340 (org-test-with-temp-text "#+KEYWORD: value"
1341 (org-toggle-fixed-width)
1343 ;; No region: error in other situations.
1345 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1347 (org-toggle-fixed-width)
1349 ;; No region: Indentation is preserved.
1352 (org-test-with-temp-text "- A\n B"
1354 (org-toggle-fixed-width)
1356 ;; Region: If it contains only fixed-width elements and blank lines,
1357 ;; toggle off fixed-width markup.
1360 (org-test-with-temp-text ": A\n\n: B"
1361 (transient-mark-mode 1)
1362 (push-mark (point) t t
)
1363 (goto-char (point-max))
1364 (org-toggle-fixed-width)
1366 ;; Region: If it contains anything else, toggle on fixed-width but
1367 ;; not on fixed-width areas.
1369 (equal ": A\n: \n: B\n: \n: C"
1370 (org-test-with-temp-text "A\n\n: B\n\nC"
1371 (transient-mark-mode 1)
1372 (push-mark (point) t t
)
1373 (goto-char (point-max))
1374 (org-toggle-fixed-width)
1376 ;; Region: Ignore blank lines at its end, unless it contains only
1380 (org-test-with-temp-text "A\n\n"
1381 (transient-mark-mode 1)
1382 (push-mark (point) t t
)
1383 (goto-char (point-max))
1384 (org-toggle-fixed-width)
1388 (org-test-with-temp-text "\n\n"
1389 (transient-mark-mode 1)
1390 (push-mark (point) t t
)
1391 (goto-char (point-max))
1392 (org-toggle-fixed-width)
1399 (ert-deftest test-org
/get-heading
()
1400 "Test `org-get-heading' specifications."
1401 ;; Return current heading, even if point is not on it.
1404 (org-test-with-temp-text "* H"
1405 (org-get-heading))))
1408 (org-test-with-temp-text "* H\nText<point>"
1409 (org-get-heading))))
1410 ;; Without any optional argument, return TODO keywords and tags.
1413 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1414 (org-get-heading))))
1417 (org-test-with-temp-text "* H :tag:"
1418 (org-get-heading))))
1419 ;; With NO-TAGS argument, ignore tags.
1422 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1423 (org-get-heading t
))))
1426 (org-test-with-temp-text "* H :tag:"
1427 (org-get-heading t
))))
1428 ;; With NO-TODO, ignore TODO keyword.
1431 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1432 (org-get-heading nil t
))))
1435 (org-test-with-temp-text "* H :tag:"
1436 (org-get-heading nil t
))))
1437 ;; TODO keywords are case-sensitive.
1440 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1441 (org-get-heading nil t
))))
1442 ;; On an empty headline, return value is consistent.
1443 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1444 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1445 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1446 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1448 (ert-deftest test-org
/in-commented-heading-p
()
1449 "Test `org-in-commented-heading-p' specifications."
1450 ;; Commented headline.
1452 (org-test-with-temp-text "* COMMENT Headline\nBody"
1453 (goto-char (point-max))
1454 (org-in-commented-heading-p)))
1455 ;; Commented ancestor.
1457 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1458 (goto-char (point-max))
1459 (org-in-commented-heading-p)))
1460 ;; Comment keyword is case-sensitive.
1462 (org-test-with-temp-text "* Comment Headline\nBody"
1463 (goto-char (point-max))
1464 (org-in-commented-heading-p)))
1465 ;; Keyword is standalone.
1467 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1468 (goto-char (point-max))
1469 (org-in-commented-heading-p)))
1470 ;; Optional argument.
1472 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1473 (goto-char (point-max))
1474 (org-in-commented-heading-p t
))))
1476 (ert-deftest test-org
/entry-blocked-p
()
1477 ;; Check other dependencies.
1479 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1480 (let ((org-enforce-todo-dependencies t
)
1482 '(org-block-todo-from-children-or-siblings-or-parent)))
1483 (org-entry-blocked-p))))
1485 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1486 (let ((org-enforce-todo-dependencies t
)
1488 '(org-block-todo-from-children-or-siblings-or-parent)))
1489 (org-entry-blocked-p))))
1490 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1493 (org-test-with-temp-text "* Blocked\n** TODO one"
1494 (let ((org-enforce-todo-dependencies t
)
1496 '(org-block-todo-from-children-or-siblings-or-parent)))
1497 (org-entry-blocked-p))))
1499 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1500 (let ((org-enforce-todo-dependencies t
)
1502 '(org-block-todo-from-children-or-siblings-or-parent)))
1503 (org-entry-blocked-p))))
1504 ;; Follow :ORDERED: specifications.
1506 (org-test-with-temp-text
1507 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1508 (let ((org-enforce-todo-dependencies t
)
1510 '(org-block-todo-from-children-or-siblings-or-parent)))
1511 (org-entry-blocked-p))))
1513 (org-test-with-temp-text
1514 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1515 (let ((org-enforce-todo-dependencies t
)
1517 '(org-block-todo-from-children-or-siblings-or-parent)))
1518 (org-entry-blocked-p)))))
1520 (ert-deftest test-org
/get-outline-path
()
1521 "Test `org-get-outline-path' specifications."
1522 ;; Top-level headlines have no outline path.
1524 (org-test-with-temp-text "* H"
1525 (org-get-outline-path)))
1526 ;; Otherwise, outline path is the path leading to the headline.
1529 (org-test-with-temp-text "* H\n** S<point>"
1530 (org-get-outline-path))))
1531 ;; Find path even when point is not on a headline.
1534 (org-test-with-temp-text "* H\n** S\nText<point>"
1535 (org-get-outline-path))))
1536 ;; TODO keywords, tags and statistics cookies are ignored.
1539 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1540 (org-get-outline-path))))
1541 ;; Links are replaced with their description or their path.
1544 (org-test-with-temp-text
1545 "* [[http://orgmode.org][Org]]\n** S<point>"
1546 (org-get-outline-path))))
1548 (equal '("http://orgmode.org")
1549 (org-test-with-temp-text
1550 "* [[http://orgmode.org]]\n** S<point>"
1551 (org-get-outline-path))))
1552 ;; When WITH-SELF is non-nil, include current heading.
1555 (org-test-with-temp-text "* H"
1556 (org-get-outline-path t
))))
1559 (org-test-with-temp-text "* H\n** S\nText<point>"
1560 (org-get-outline-path t
))))
1561 ;; Using cache is transparent to the user.
1564 (org-test-with-temp-text "* H\n** S<point>"
1565 (setq org-outline-path-cache nil
)
1566 (org-get-outline-path nil t
))))
1567 ;; Do not corrupt cache when finding outline path in distant part of
1571 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1572 (setq org-outline-path-cache nil
)
1573 (org-get-outline-path nil t
)
1574 (search-forward "S2")
1575 (org-get-outline-path nil t
))))
1576 ;; Do not choke on empty headlines.
1578 (org-test-with-temp-text "* H\n** <point>"
1579 (org-get-outline-path)))
1581 (org-test-with-temp-text "* \n** H<point>"
1582 (org-get-outline-path))))
1584 (ert-deftest test-org
/format-outline-path
()
1585 "Test `org-format-outline-path' specifications."
1587 (string= (org-format-outline-path (list "one" "two" "three"))
1591 (string= (org-format-outline-path '())
1594 (string= (org-format-outline-path '(nil))
1596 ;; Empty path and prefix.
1598 (string= (org-format-outline-path '() nil
">>")
1600 ;; Trailing whitespace in headings.
1602 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1604 ;; Non-default prefix and separators.
1606 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1607 ">>|one|two|three"))
1610 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1612 ;; Give a very narrow width.
1614 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1616 ;; Give a prefix that extends beyond the width.
1618 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1622 (ert-deftest test-org
/map-entries
()
1623 "Test `org-map-entries' specifications."
1627 (org-test-with-temp-text "* Level 1\n** Level 2"
1628 (org-map-entries #'point
))))
1632 (org-test-with-temp-text "* Level 1\n** Level 2"
1633 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1636 (org-test-with-temp-text "* Level 1\n** Level 2"
1637 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1641 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1642 (org-map-entries #'point
"yes"))))
1645 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1646 (org-map-entries #'point
"+yes-a"))))
1649 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1650 (org-map-entries #'point
"{yes?}"))))
1654 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1655 (org-map-entries #'point
"PRIORITY=\"A\""))))
1659 (org-test-with-temp-text "
1661 SCHEDULED: <2012-03-29 thu.>
1663 SCHEDULED: <2014-03-04 tue.>"
1664 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1667 (org-test-with-temp-text "
1669 SCHEDULED: <2012-03-29 thu.>
1671 SCHEDULED: <2014-03-04 tue.>"
1672 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1673 ;; Regular property match.
1676 (org-test-with-temp-text "
1685 (org-map-entries #'point
"TEST=1"))))
1686 ;; Multiple criteria.
1689 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1690 (let (org-odd-levels-only
1691 (org-use-tag-inheritance nil
))
1692 (org-map-entries #'point
"yes+LEVEL=1")))))
1696 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1697 (let (org-odd-levels-only)
1698 (org-map-entries #'point
"LEVEL=2|no")))))
1701 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1702 (let (org-odd-levels-only)
1703 (org-map-entries #'point
"yes|no")))))
1707 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1708 (let (org-odd-levels-only)
1709 (org-map-entries #'point
"yes&no"))))))
1711 (ert-deftest test-org
/edit-headline
()
1712 "Test `org-edit-headline' specifications."
1715 (org-test-with-temp-text "* A"
1716 (org-edit-headline "B")
1718 ;; Handle empty headings.
1721 (org-test-with-temp-text "* A"
1722 (org-edit-headline "")
1726 (org-test-with-temp-text "* "
1727 (org-edit-headline "A")
1729 ;; Handle TODO keywords and priority cookies.
1732 (org-test-with-temp-text "* TODO A"
1733 (org-edit-headline "B")
1737 (org-test-with-temp-text "* [#A] A"
1738 (org-edit-headline "B")
1741 (equal "* TODO [#A] B"
1742 (org-test-with-temp-text "* TODO [#A] A"
1743 (org-edit-headline "B")
1747 (org-test-with-temp-text "* A :tag:"
1748 (let ((org-tags-column 4)) (org-edit-headline "B"))
1755 (ert-deftest test-org
/set-regexps-and-options
()
1756 "Test `org-set-regexps-and-options' specifications."
1760 (let ((org-tag-alist '(("A")))
1761 (org-tag-persistent-alist nil
))
1762 (org-test-with-temp-text ""
1764 org-current-tag-alist
))))
1767 (let ((org-tag-alist '(("A")))
1768 (org-tag-persistent-alist nil
))
1769 (org-test-with-temp-text "#+TAGS: B"
1771 org-current-tag-alist
))))
1773 (equal '(("C") ("B"))
1774 (let ((org-tag-alist '(("A")))
1775 (org-tag-persistent-alist '(("C"))))
1776 (org-test-with-temp-text "#+TAGS: B"
1778 org-current-tag-alist
))))
1781 (let ((org-tag-alist '(("A")))
1782 (org-tag-persistent-alist '(("C"))))
1783 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1785 org-current-tag-alist
))))
1787 (equal '(("A" . ?a
) ("B") ("C"))
1788 (let ((org-tag-persistant-alist nil
))
1789 (org-test-with-temp-text "#+TAGS: A(a) B C"
1791 org-current-tag-alist
))))
1793 (equal '(("A") (:newline
) ("B"))
1794 (let ((org-tag-persistent-alist nil
))
1795 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1797 org-current-tag-alist
))))
1799 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1800 (let ((org-tag-persistent-alist nil
))
1801 (org-test-with-temp-text "#+TAGS: { A B } C"
1803 org-current-tag-alist
))))
1805 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1806 (let ((org-tag-persistent-alist nil
))
1807 (org-test-with-temp-text "#+TAGS: { A : B C }"
1809 org-current-tag-alist
))))
1811 (equal '(("A" "B" "C"))
1812 (let ((org-tag-persistent-alist nil
))
1813 (org-test-with-temp-text "#+TAGS: { A : B C }"
1815 org-tag-groups-alist
))))
1817 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1818 (let ((org-tag-persistent-alist nil
))
1819 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1821 org-current-tag-alist
))))
1823 (equal '(("A" "B" "C"))
1824 (let ((org-tag-persistent-alist nil
))
1825 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1827 org-tag-groups-alist
))))
1828 ;; FILETAGS keyword.
1830 (equal '("A" "B" "C")
1831 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1834 ;; PROPERTY keyword. Property names are case-insensitive.
1837 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1839 (cdr (assoc "var" org-file-properties
)))))
1843 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1845 (cdr (assoc "var" org-file-properties
)))))
1849 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1851 (cdr (assoc "var" org-file-properties
)))))
1855 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1857 org-archive-location
)))
1858 ;; CATEGORY keyword.
1861 (org-test-with-temp-text "#+CATEGORY: test"
1866 (org-test-with-temp-text "#+CATEGORY: test"
1868 (cdr (assoc "CATEGORY" org-file-properties
)))))
1871 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1872 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1874 org-columns-default-format
)))
1875 ;; CONSTANTS keyword. Constants names are case sensitive.
1877 (equal '("299792458." "3.14")
1878 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1881 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1885 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1887 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1890 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1892 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1897 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1899 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1901 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1905 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1907 (list org-highest-priority org-lowest-priority org-default-priority
))))
1911 (org-test-with-temp-text "#+PRIORITIES: X Z"
1913 (list org-highest-priority org-lowest-priority org-default-priority
))))
1917 (org-test-with-temp-text "#+STARTUP: fold odd"
1919 (list org-startup-folded org-odd-levels-only
))))
1922 (equal '(("A" "B") ("C"))
1923 (org-test-with-temp-text "#+TODO: A B | C"
1925 (list org-not-done-keywords org-done-keywords
))))
1927 (equal '(("A" "C") ("B" "D"))
1928 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1930 (list org-not-done-keywords org-done-keywords
))))
1932 (equal '(("A" "B") ("C"))
1933 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1935 (list org-not-done-keywords org-done-keywords
))))
1937 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1938 (org-test-with-temp-text "#+TODO: A(a)"
1940 org-todo-key-alist
)))
1942 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1943 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1945 org-todo-log-states
)))
1946 ;; Enter SETUPFILE keyword.
1949 (org-test-with-temp-text
1950 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1952 (cdr (assoc "a" org-file-properties
))))))
1960 (ert-deftest test-org
/coderef
()
1961 "Test coderef links specifications."
1963 (org-test-with-temp-text "
1964 #+BEGIN_SRC emacs-lisp
1969 (looking-at "(ref:sc)")))
1970 ;; Find coderef even with alternate label format.
1972 (org-test-with-temp-text "
1973 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
1978 (looking-at "{ref:sc}"))))
1982 (ert-deftest test-org
/custom-id
()
1983 "Test custom ID links specifications."
1985 (org-test-with-temp-text
1986 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1988 (looking-at-p "\\* H1")))
1989 ;; Throw an error on false positives.
1991 (org-test-with-temp-text
1992 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1994 (looking-at-p "\\* H1"))))
1998 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1999 ;; a named element (#+name: text) and to headlines (* Text).
2001 (ert-deftest test-org
/fuzzy-links
()
2002 "Test fuzzy links specifications."
2003 ;; Fuzzy link goes in priority to a matching target.
2005 (org-test-with-temp-text
2006 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2007 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2008 (looking-at "<<Test>>")))
2009 ;; Then fuzzy link points to an element with a given name.
2011 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2012 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2013 (looking-at "#\\+NAME: Test")))
2014 ;; A target still lead to a matching headline otherwise.
2016 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2017 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2018 (looking-at "\\* Head2")))
2019 ;; With a leading star in link, enforce heading match.
2021 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2022 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2023 (looking-at "\\* Test")))
2024 ;; With a leading star in link, enforce exact heading match, even
2025 ;; with `org-link-search-must-match-exact-headline' set to nil.
2027 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2028 (let ((org-link-search-must-match-exact-headline nil
))
2029 (org-open-at-point))))
2030 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2032 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2033 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2034 (looking-at "\\* Test")))
2036 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2037 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2038 (looking-at "\\* Test")))
2039 ;; Heading match should not care about spaces, cookies, TODO
2040 ;; keywords, priorities, and tags.
2043 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2044 (org-test-with-temp-text
2045 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2046 (let ((org-link-search-must-match-exact-headline nil
)
2047 (org-todo-regexp "TODO"))
2048 (org-open-at-point))
2049 (looking-at (regexp-quote first-line
)))))
2050 ;; Heading match should still be exact.
2053 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2054 (org-test-with-temp-text
2055 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
2056 (let ((org-link-search-must-match-exact-headline nil
)
2057 (org-todo-regexp "TODO"))
2058 (org-open-at-point)))))
2059 ;; Heading match ignores COMMENT keyword.
2061 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2063 (looking-at "\\* COMMENT Test")))
2064 ;; Correctly un-hexify fuzzy links.
2066 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2072 (ert-deftest test-org
/org-link-escape-ascii-character
()
2073 "Escape an ascii character."
2077 (org-link-escape "["))))
2079 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2080 "Escape an ascii control character."
2084 (org-link-escape "\t"))))
2086 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2087 "Escape an unicode multibyte character."
2091 (org-link-escape "€"))))
2093 (ert-deftest test-org
/org-link-escape-custom-table
()
2094 "Escape string with custom character table."
2098 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2100 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2101 "Escape string with custom table merged with default table."
2104 "%5BF%6F%6F%3A%42ar%0A%5D"
2105 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2107 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2108 "Unescape an ascii character."
2112 (org-link-unescape "%5B"))))
2114 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2115 "Unescpae an ascii control character."
2119 (org-link-unescape "%0A"))))
2121 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2122 "Unescape unicode multibyte character."
2126 (org-link-unescape "%E2%82%AC"))))
2128 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2129 "Unescape old style percent escaped character."
2132 "à âçèéêîôùû"
2133 (decode-coding-string
2134 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2136 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2137 "Escape and unescape a URL that includes an escaped char.
2138 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2141 "http://some.host.com/form?&id=blah%2Bblah25"
2143 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2147 (ert-deftest test-org
/open-at-point-in-keyword
()
2148 "Does `org-open-at-point' open link in a keyword line?"
2150 (org-test-with-temp-text
2151 "<<top>>\n#+KEYWORD: <point>[[top]]"
2152 (org-open-at-point) t
)))
2154 (ert-deftest test-org
/open-at-point-in-property
()
2155 "Does `org-open-at-point' open link in property drawer?"
2157 (org-test-with-temp-text
2160 :URL: <point>[[*Headline]]
2162 (org-open-at-point) t
)))
2164 (ert-deftest test-org
/open-at-point-in-comment
()
2165 "Does `org-open-at-point' open link in a commented line?"
2167 (org-test-with-temp-text
2168 "<<top>>\n# <point>[[top]]"
2169 (org-open-at-point) t
)))
2171 (ert-deftest test-org
/open-at-point
/inline-image
()
2172 "Test `org-open-at-point' on nested links."
2174 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2178 (ert-deftest test-org
/open-at-point
/radio-target
()
2179 "Test `org-open-at-point' on radio targets."
2181 (org-test-with-temp-text "<<<target>>> <point>target"
2182 (org-update-radio-target-regexp)
2184 (eq (org-element-type (org-element-context)) 'radio-target
))))
2188 (ert-deftest test-org
/store-link
()
2189 "Test `org-store-link' specifications."
2190 ;; On a headline, link to that headline. Use heading as the
2191 ;; description of the link.
2193 (let (org-store-link-props org-stored-links
)
2194 (org-test-with-temp-text-in-file "* H1"
2195 (let ((file (buffer-file-name)))
2196 (equal (format "[[file:%s::*H1][H1]]" file
)
2197 (org-store-link nil
))))))
2198 ;; On a headline, remove any link from description.
2200 (let (org-store-link-props org-stored-links
)
2201 (org-test-with-temp-text-in-file "* [[#l][d]]"
2202 (let ((file (buffer-file-name)))
2203 (equal (format "[[file:%s::*%s][d]]"
2205 (org-link-escape "[[#l][d]]"))
2206 (org-store-link nil
))))))
2208 (let (org-store-link-props org-stored-links
)
2209 (org-test-with-temp-text-in-file "* [[l]]"
2210 (let ((file (buffer-file-name)))
2211 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2212 (org-store-link nil
))))))
2214 (let (org-store-link-props org-stored-links
)
2215 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2216 (let ((file (buffer-file-name)))
2217 (equal (format "[[file:%s::*%s][d1 d2]]"
2219 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2220 (org-store-link nil
))))))
2221 ;; On a named element, link to that element.
2223 (let (org-store-link-props org-stored-links
)
2224 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2225 (let ((file (buffer-file-name)))
2226 (equal (format "[[file:%s::foo][foo]]" file
)
2227 (org-store-link nil
)))))))
2232 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2233 "Ensure properties accumulate in subtree drawers."
2234 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2235 (org-babel-next-src-block)
2236 (should (equal '(2 1) (org-babel-execute-src-block)))))
2238 (ert-deftest test-org
/custom-properties
()
2239 "Test custom properties specifications."
2242 (let ((org-custom-properties '("FOO")))
2243 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2244 (org-toggle-custom-properties-visibility)
2245 (org-invisible-p2))))
2246 ;; Properties are case-insensitive.
2248 (let ((org-custom-properties '("FOO")))
2249 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2250 (org-toggle-custom-properties-visibility)
2251 (org-invisible-p2))))
2253 (let ((org-custom-properties '("foo")))
2254 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2255 (org-toggle-custom-properties-visibility)
2256 (org-invisible-p2))))
2257 ;; Multiple custom properties in the same drawer.
2259 (let ((org-custom-properties '("FOO" "BAR")))
2260 (org-test-with-temp-text
2261 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2262 (org-toggle-custom-properties-visibility)
2263 (and (org-invisible-p2)
2264 (not (progn (forward-line) (org-invisible-p2)))
2265 (progn (forward-line) (org-invisible-p2))))))
2266 ;; Hide custom properties with an empty value.
2268 (let ((org-custom-properties '("FOO")))
2269 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2270 (org-toggle-custom-properties-visibility)
2271 (org-invisible-p2))))
2272 ;; Do not hide fake properties.
2274 (let ((org-custom-properties '("FOO")))
2275 (org-test-with-temp-text ":FOO: val\n"
2276 (org-toggle-custom-properties-visibility)
2277 (org-invisible-p2))))
2279 (let ((org-custom-properties '("A")))
2280 (org-test-with-temp-text
2281 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2282 (org-toggle-custom-properties-visibility)
2283 (org-invisible-p2)))))
2289 (ert-deftest test-org
/mark-subtree
()
2290 "Test `org-mark-subtree' specifications."
2291 ;; Error when point is before first headline.
2293 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2294 (progn (transient-mark-mode 1)
2295 (org-mark-subtree))))
2296 ;; Without argument, mark current subtree.
2300 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2301 (progn (transient-mark-mode 1)
2304 (list (region-beginning) (region-end))))))
2305 ;; With an argument, move ARG up.
2309 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2310 (progn (transient-mark-mode 1)
2312 (org-mark-subtree 1)
2313 (list (region-beginning) (region-end))))))
2314 ;; Do not get fooled by inlinetasks.
2315 (when (featurep 'org-inlinetask
)
2318 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2319 (progn (transient-mark-mode 1)
2321 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2322 (region-beginning)))))))
2328 (ert-deftest test-org
/in-regexp
()
2329 "Test `org-in-regexp' specifications."
2332 (org-test-with-temp-text "xx ab<point>c xx"
2333 (org-in-regexp "abc")))
2335 (org-test-with-temp-text "xx abc <point>xx"
2336 (org-in-regexp "abc")))
2337 ;; Return non-nil even with multiple matching regexps in the same
2340 (org-test-with-temp-text "abc xx ab<point>c xx"
2341 (org-in-regexp "abc")))
2342 ;; With optional argument NLINES, check extra lines around point.
2344 (org-test-with-temp-text "A\nB<point>\nC"
2345 (org-in-regexp "A\nB\nC")))
2347 (org-test-with-temp-text "A\nB<point>\nC"
2348 (org-in-regexp "A\nB\nC" 1)))
2350 (org-test-with-temp-text "A\nB\nC<point>"
2351 (org-in-regexp "A\nB\nC" 1)))
2352 ;; When optional argument VISUALLY is non-nil, return nil if at
2353 ;; regexp boundaries.
2355 (org-test-with-temp-text "xx abc<point> xx"
2356 (org-in-regexp "abc")))
2358 (org-test-with-temp-text "xx abc<point> xx"
2359 (org-in-regexp "abc" nil t
))))
2364 (ert-deftest test-org
/end-of-meta-data
()
2365 "Test `org-end-of-meta-data' specifications."
2366 ;; Skip planning line.
2368 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2369 (org-end-of-meta-data)
2371 ;; Skip properties drawer.
2373 (org-test-with-temp-text
2374 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2375 (org-end-of-meta-data)
2379 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2380 (org-end-of-meta-data)
2382 ;; Nothing to skip, go to first line.
2384 (org-test-with-temp-text "* Headline\nContents"
2385 (org-end-of-meta-data)
2386 (looking-at "Contents")))
2387 ;; With option argument, skip empty lines, regular drawers and
2390 (org-test-with-temp-text "* Headline\n\nContents"
2391 (org-end-of-meta-data t
)
2392 (looking-at "Contents")))
2394 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2395 (org-end-of-meta-data t
)
2396 (looking-at "Contents")))
2398 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2399 (org-end-of-meta-data t
)
2400 (looking-at "Contents")))
2401 ;; Special case: do not skip incomplete drawers.
2403 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2404 (org-end-of-meta-data t
)
2405 (looking-at ":LOGBOOK:")))
2406 ;; Special case: Be careful about consecutive headlines.
2408 (org-test-with-temp-text "* H1\n*H2\nContents"
2409 (org-end-of-meta-data t
)
2410 (looking-at "Contents"))))
2412 (ert-deftest test-org
/beginning-of-line
()
2413 "Test `org-beginning-of-line' specifications."
2416 (org-test-with-temp-text "Some text\nSome other text"
2417 (progn (org-beginning-of-line) (bolp))))
2418 ;; Standard test with `visual-line-mode'.
2420 (org-test-with-temp-text "A long line of text\nSome other text"
2421 (progn (visual-line-mode)
2423 (dotimes (i 1000) (insert "very "))
2424 (org-beginning-of-line)
2426 ;; At an headline with special movement.
2428 (org-test-with-temp-text "* TODO Headline"
2429 (let ((org-special-ctrl-a/e t
))
2431 (and (progn (org-beginning-of-line) (looking-at "Headline"))
2432 (progn (org-beginning-of-line) (bolp))
2433 (progn (org-beginning-of-line) (looking-at "Headline"))))))
2434 ;; Special case: Do not error when the buffer contains only a single
2437 (org-test-with-temp-text "*<point>"
2438 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
2440 (org-test-with-temp-text "*<point>"
2441 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
2443 (ert-deftest test-org
/end-of-line
()
2444 "Test `org-end-of-line' specifications."
2447 (org-test-with-temp-text "Some text\nSome other text"
2448 (progn (org-end-of-line) (eolp))))
2449 ;; Standard test with `visual-line-mode'.
2451 (org-test-with-temp-text "A long line of text\nSome other text"
2452 (progn (visual-line-mode)
2454 (dotimes (i 1000) (insert "very "))
2455 (goto-char (point-min))
2458 ;; At an headline with special movement.
2460 (org-test-with-temp-text "* Headline1 :tag:\n"
2461 (let ((org-special-ctrl-a/e t
))
2462 (and (progn (org-end-of-line) (looking-at " :tag:"))
2463 (progn (org-end-of-line) (eolp))
2464 (progn (org-end-of-line) (looking-at " :tag:"))))))
2465 ;; At an headline without special movement.
2467 (org-test-with-temp-text "* Headline2 :tag:\n"
2468 (let ((org-special-ctrl-a/e nil
))
2469 (and (progn (org-end-of-line) (eolp))
2470 (progn (org-end-of-line) (eolp))))))
2471 ;; At an headline, with reversed movement.
2473 (org-test-with-temp-text "* Headline3 :tag:\n"
2474 (let ((org-special-ctrl-a/e
'reversed
)
2475 (this-command last-command
))
2476 (and (progn (org-end-of-line) (eolp))
2477 (progn (org-end-of-line) (looking-at " :tag:"))))))
2478 ;; At a block without hidden contents.
2480 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2481 (progn (org-end-of-line) (eolp))))
2482 ;; At a block with hidden contents.
2484 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2485 (let ((org-special-ctrl-a/e t
))
2486 (org-hide-block-toggle)
2490 (ert-deftest test-org
/forward-sentence
()
2491 "Test `org-forward-sentence' specifications."
2492 ;; At the end of a table cell, move to the end of the next one.
2494 (org-test-with-temp-text "| a<point> | b |"
2495 (org-forward-sentence)
2496 (looking-at " |$")))
2497 ;; Elsewhere in a cell, move to its end.
2499 (org-test-with-temp-text "| a<point>c | b |"
2500 (org-forward-sentence)
2501 (looking-at " | b |$")))
2502 ;; Otherwise, simply call `forward-sentence'.
2504 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2505 (org-forward-sentence)
2506 (looking-at " Sentence 2.")))
2508 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2509 (org-forward-sentence)
2510 (org-forward-sentence)
2512 ;; At the end of an element, jump to the next one, without stopping
2513 ;; on blank lines in-between.
2515 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2516 (org-forward-sentence)
2519 (ert-deftest test-org
/backward-sentence
()
2520 "Test `org-backward-sentence' specifications."
2521 ;; At the beginning of a table cell, move to the beginning of the
2524 (org-test-with-temp-text "| a | <point>b |"
2525 (org-backward-sentence)
2526 (looking-at "a | b |$")))
2527 ;; Elsewhere in a cell, move to its beginning.
2529 (org-test-with-temp-text "| a | b<point>c |"
2530 (org-backward-sentence)
2531 (looking-at "bc |$")))
2532 ;; Otherwise, simply call `backward-sentence'.
2534 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2535 (org-backward-sentence)
2536 (looking-at "Sentence 2.")))
2538 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2539 (org-backward-sentence)
2540 (org-backward-sentence)
2542 ;; Make sure to hit the beginning of a sentence on the same line as
2545 (org-test-with-temp-text "- Line 1\n line <point>2."
2546 (org-backward-sentence)
2547 (looking-at "Line 1"))))
2549 (ert-deftest test-org
/forward-paragraph
()
2550 "Test `org-forward-paragraph' specifications."
2551 ;; At end of buffer, return an error.
2553 (org-test-with-temp-text "Paragraph"
2554 (goto-char (point-max))
2555 (org-forward-paragraph)))
2558 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2559 (org-forward-paragraph)
2563 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2564 (org-forward-paragraph)
2566 ;; Do not enter elements with invisible contents.
2568 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2569 (org-hide-block-toggle)
2570 (org-forward-paragraph)
2572 ;; On an affiliated keyword, jump to the beginning of the element.
2574 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2575 (org-forward-paragraph)
2576 (looking-at "Para")))
2577 ;; On an item or a footnote definition, move to the second element
2580 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2581 (org-forward-paragraph)
2582 (looking-at " Paragraph")))
2584 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2585 (org-forward-paragraph)
2586 (looking-at "Paragraph")))
2587 ;; On an item, or a footnote definition, when the first line is
2588 ;; empty, move to the first item.
2590 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2591 (org-forward-paragraph)
2592 (looking-at " Paragraph")))
2594 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2595 (org-forward-paragraph)
2596 (looking-at "Paragraph")))
2597 ;; On a table (resp. a property drawer) do not move through table
2598 ;; rows (resp. node properties).
2600 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2601 (org-forward-paragraph)
2602 (looking-at "Paragraph")))
2604 (org-test-with-temp-text
2605 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2606 (org-forward-paragraph)
2607 (looking-at "Paragraph")))
2608 ;; On a verse or source block, stop after blank lines.
2610 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2611 (org-forward-paragraph)
2614 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2615 (org-forward-paragraph)
2616 (looking-at "L2"))))
2618 (ert-deftest test-org
/backward-paragraph
()
2619 "Test `org-backward-paragraph' specifications."
2620 ;; Error at beginning of buffer.
2622 (org-test-with-temp-text "Paragraph"
2623 (org-backward-paragraph)))
2626 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2627 (goto-char (point-max))
2628 (org-backward-paragraph)
2631 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2632 (goto-char (point-max))
2634 (org-backward-paragraph)
2638 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2639 (goto-char (point-max))
2641 (org-backward-paragraph)
2643 ;; Ignore invisible elements.
2645 (org-test-with-temp-text "* H1\n P1\n* H2"
2647 (goto-char (point-max))
2649 (org-backward-paragraph)
2651 ;; On an affiliated keyword, jump to the first one.
2653 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2654 (search-forward "c2")
2655 (org-backward-paragraph)
2656 (looking-at "#\\+name")))
2657 ;; On the second element in an item or a footnote definition, jump
2658 ;; to item or the definition.
2660 (org-test-with-temp-text "- line1\n\n line2"
2661 (goto-char (point-max))
2663 (org-backward-paragraph)
2664 (looking-at "- line1")))
2666 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2667 (goto-char (point-max))
2669 (org-backward-paragraph)
2670 (looking-at "\\[fn:1\\] line1")))
2671 ;; On a table (resp. a property drawer), ignore table rows
2672 ;; (resp. node properties).
2674 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2675 (goto-char (point-max))
2677 (org-backward-paragraph)
2680 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2681 (org-backward-paragraph)
2682 (looking-at ":PROPERTIES:")))
2683 ;; On a source or verse block, stop before blank lines.
2685 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2686 (search-forward "L3")
2688 (org-backward-paragraph)
2691 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2692 (search-forward "L3")
2694 (org-backward-paragraph)
2695 (looking-at "L2"))))
2697 (ert-deftest test-org
/forward-element
()
2698 "Test `org-forward-element' specifications."
2699 ;; 1. At EOB: should error.
2700 (org-test-with-temp-text "Some text\n"
2701 (goto-char (point-max))
2702 (should-error (org-forward-element)))
2703 ;; 2. Standard move: expected to ignore blank lines.
2704 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2705 (org-forward-element)
2706 (should (looking-at (regexp-quote "Second paragraph."))))
2707 ;; 3. Headline tests.
2708 (org-test-with-temp-text "
2713 ;; 3.1. At an headline beginning: move to next headline at the
2716 (org-forward-element)
2717 (should (looking-at (regexp-quote "** Head 1.2")))
2718 ;; 3.2. At an headline beginning: move to parent headline if no
2719 ;; headline at the same level.
2721 (org-forward-element)
2722 (should (looking-at (regexp-quote "** Head 1.2"))))
2723 ;; 4. Greater element tests.
2724 (org-test-with-temp-text
2725 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2726 ;; 4.1. At a greater element: expected to skip contents.
2727 (org-forward-element)
2728 (should (looking-at (regexp-quote "Outside.")))
2729 ;; 4.2. At the end of greater element contents: expected to skip
2730 ;; to the end of the greater element.
2732 (org-forward-element)
2733 (should (looking-at (regexp-quote "Outside."))))
2735 (org-test-with-temp-text "
2749 ;; 5.1. At list top point: expected to move to the element after
2752 (org-forward-element)
2753 (should (looking-at (regexp-quote "Outside.")))
2754 ;; 5.2. Special case: at the first line of a sub-list, but not at
2755 ;; beginning of line, move to next item.
2758 (org-forward-element)
2759 (should (looking-at "- item2"))
2762 (org-forward-element)
2763 (should (looking-at " - sub2"))
2764 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2766 (org-forward-element)
2767 (should (looking-at (regexp-quote " Inner paragraph.")))
2768 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2770 (org-forward-element)
2771 (should (looking-at (regexp-quote " Inner paragraph.")))
2772 ;; 5.5. At an item: expected to move to next item, if any.
2774 (org-forward-element)
2775 (should (looking-at " - sub3"))))
2777 (ert-deftest test-org
/backward-element
()
2778 "Test `org-backward-element' specifications."
2779 ;; 1. Should error at BOB.
2780 (org-test-with-temp-text " \nParagraph."
2781 (should-error (org-backward-element)))
2782 ;; 2. Should move at BOB when called on the first element in buffer.
2784 (org-test-with-temp-text "\n#+TITLE: test"
2785 (progn (forward-line)
2786 (org-backward-element)
2788 ;; 3. Not at the beginning of an element: move at its beginning.
2789 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2792 (org-backward-element)
2793 (should (looking-at (regexp-quote "Paragraph2."))))
2794 ;; 4. Headline tests.
2795 (org-test-with-temp-text "
2800 ;; 4.1. At an headline beginning: move to previous headline at the
2803 (org-backward-element)
2804 (should (looking-at (regexp-quote "** Head 1.1")))
2805 ;; 4.2. At an headline beginning: move to parent headline if no
2806 ;; headline at the same level.
2808 (org-backward-element)
2809 (should (looking-at (regexp-quote "* Head 1")))
2810 ;; 4.3. At the first top-level headline: should error.
2812 (should-error (org-backward-element)))
2813 ;; 5. At beginning of first element inside a greater element:
2814 ;; expected to move to greater element's beginning.
2815 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2817 (org-backward-element)
2818 (should (looking-at "#\\+BEGIN_CENTER")))
2819 ;; 6. At the beginning of the first element in a section: should
2820 ;; move back to headline, if any.
2822 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2823 (progn (goto-char (point-max))
2825 (org-backward-element)
2826 (org-at-heading-p))))
2828 (org-test-with-temp-text "
2843 ;; 7.1. At beginning of sub-list: expected to move to the
2844 ;; paragraph before it.
2846 (org-backward-element)
2847 (should (looking-at "item1"))
2848 ;; 7.2. At an item in a list: expected to move at previous item.
2850 (org-backward-element)
2851 (should (looking-at " - sub2"))
2853 (org-backward-element)
2854 (should (looking-at "- item1"))
2855 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2858 (org-backward-element)
2859 (should (looking-at " - sub1"))
2861 (org-backward-element)
2862 (should (looking-at "- item1"))
2863 ;; 7.4. At blank-lines before list end: expected to move to top
2866 (org-backward-element)
2867 (should (looking-at "- item1"))))
2869 (ert-deftest test-org
/up-element
()
2870 "Test `org-up-element' specifications."
2871 ;; 1. At BOB or with no surrounding element: should error.
2872 (org-test-with-temp-text "Paragraph."
2873 (should-error (org-up-element)))
2874 (org-test-with-temp-text "* Head1\n* Head2"
2876 (should-error (org-up-element)))
2877 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2879 (should-error (org-up-element)))
2880 ;; 2. At an headline: move to parent headline.
2881 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2884 (should (looking-at "\\* Head1")))
2885 ;; 3. Inside a greater element: move to greater element beginning.
2886 (org-test-with-temp-text
2887 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2890 (should (looking-at "#\\+BEGIN_CENTER")))
2892 (org-test-with-temp-text "* Top
2899 Paragraph within sub2.
2902 ;; 4.1. Within an item: move to the item beginning.
2905 (should (looking-at " - sub2"))
2906 ;; 4.2. At an item in a sub-list: move to parent item.
2909 (should (looking-at "- item1"))
2910 ;; 4.3. At an item in top list: move to beginning of whole list.
2913 (should (looking-at "- item1"))
2914 ;; 4.4. Special case. At very top point: should move to parent of
2918 (should (looking-at "\\* Top"))))
2920 (ert-deftest test-org
/down-element
()
2921 "Test `org-down-element' specifications."
2922 ;; Error when the element hasn't got a recursive type.
2923 (org-test-with-temp-text "Paragraph."
2924 (should-error (org-down-element)))
2925 ;; Error when the element has no contents
2926 (org-test-with-temp-text "* Headline"
2927 (should-error (org-down-element)))
2928 ;; When at a plain-list, move to first item.
2929 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2932 (should (looking-at " - Item 1.1")))
2933 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2935 (should (looking-at " Item 1")))
2936 ;; When at a table, move to first row
2937 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2939 (should (looking-at " a | b |")))
2940 ;; Otherwise, move inside the greater element.
2941 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2943 (should (looking-at "Paragraph"))))
2945 (ert-deftest test-org
/drag-element-backward
()
2946 "Test `org-drag-element-backward' specifications."
2950 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2951 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2952 (org-drag-element-backward)
2956 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2957 (org-test-with-temp-text
2958 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2959 (org-drag-element-backward)
2961 ;; Preserve blank lines.
2963 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2964 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2965 (org-drag-element-backward)
2969 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2970 (org-drag-element-backward)
2971 (looking-at-p "2")))
2972 ;; Error when trying to move first element of buffer.
2974 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2975 (org-drag-element-backward)))
2976 ;; Error when trying to swap nested elements.
2978 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2980 (org-drag-element-backward)))
2981 ;; Error when trying to swap an headline element and a non-headline
2984 (org-test-with-temp-text "Test.\n* Head 1"
2986 (org-drag-element-backward)))
2987 ;; Preserve visibility of elements and their contents.
2989 (equal '((63 .
82) (26 .
48))
2990 (org-test-with-temp-text "
2998 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2999 (search-backward "- item 1")
3000 (org-drag-element-backward)
3001 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3002 (overlays-in (point-min) (point-max)))))))
3004 (ert-deftest test-org
/drag-element-forward
()
3005 "Test `org-drag-element-forward' specifications."
3006 ;; 1. Error when trying to move first element of buffer.
3007 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3009 (should-error (org-drag-element-forward)))
3010 ;; 2. Error when trying to swap nested elements.
3011 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3013 (should-error (org-drag-element-forward)))
3014 ;; 3. Error when trying to swap a non-headline element and an
3016 (org-test-with-temp-text "Test.\n* Head 1"
3017 (should-error (org-drag-element-forward)))
3018 ;; 4. Otherwise, swap elements, preserving column and blank lines
3019 ;; between elements.
3020 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3021 (search-forward "graph")
3022 (org-drag-element-forward)
3023 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3024 (should (looking-at " 1")))
3025 ;; 5. Preserve visibility of elements and their contents.
3026 (org-test-with-temp-text "
3034 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3035 (search-backward "#+BEGIN_CENTER")
3036 (org-drag-element-forward)
3039 '((63 .
82) (26 .
48))
3040 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3041 (overlays-in (point-min) (point-max)))))))
3043 (ert-deftest test-org
/next-block
()
3044 "Test `org-next-block' specifications."
3047 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3049 (looking-at "#\\+BEGIN_CENTER")))
3052 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3053 (let ((case-fold-search nil
))
3055 (looking-at "#\\+begin_center"))))
3056 ;; Ignore current line.
3058 (org-test-with-temp-text
3059 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3061 (looking-at "#\\+BEGIN_CENTER")))
3062 ;; Throw an error when no block is found.
3064 (org-test-with-temp-text "Paragraph"
3065 (org-next-block 1)))
3066 ;; With an argument, skip many blocks at once.
3068 (org-test-with-temp-text
3069 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3071 (looking-at "#\\+BEGIN_QUOTE")))
3072 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3074 (org-test-with-temp-text
3075 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3076 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3077 (looking-at "#\\+BEGIN_QUOTE")))
3078 ;; Optional argument is also case-insensitive.
3080 (org-test-with-temp-text
3081 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3082 (let ((case-fold-search nil
))
3083 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3084 (looking-at "#\\+begin_quote")))))
3086 (ert-deftest test-org
/previous-block
()
3087 "Test `org-previous-block' specifications."
3090 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3091 (org-previous-block 1)
3092 (looking-at "#\\+BEGIN_CENTER")))
3095 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3096 (let ((case-fold-search nil
))
3097 (org-previous-block 1)
3098 (looking-at "#\\+begin_center"))))
3099 ;; Ignore current line.
3101 (org-test-with-temp-text
3102 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3103 (org-previous-block 1)
3104 (looking-at "#\\+BEGIN_QUOTE")))
3105 ;; Throw an error when no block is found.
3107 (org-test-with-temp-text "Paragraph<point>"
3108 (org-previous-block 1)))
3109 ;; With an argument, skip many blocks at once.
3111 (org-test-with-temp-text
3112 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3113 (org-previous-block 2)
3114 (looking-at "#\\+BEGIN_CENTER")))
3115 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3117 (org-test-with-temp-text
3118 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3119 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3120 (looking-at "#\\+BEGIN_QUOTE")))
3121 ;; Optional argument is also case-insensitive.
3123 (org-test-with-temp-text
3124 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3125 (let ((case-fold-search nil
))
3126 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3127 (looking-at "#\\+begin_quote")))))
3130 ;;; Outline structure
3132 (ert-deftest test-org
/demote
()
3133 "Test `org-demote' specifications."
3134 ;; Add correct number of stars according to `org-odd-levels-only'.
3137 (org-test-with-temp-text "* H"
3138 (let ((org-odd-levels-only nil
)) (org-demote))
3139 (org-current-level))))
3142 (org-test-with-temp-text "* H"
3143 (let ((org-odd-levels-only t
)) (org-demote))
3144 (org-current-level))))
3145 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3147 (org-test-with-temp-text "* H :tag:"
3148 (let ((org-tags-column 10)
3149 (org-auto-align-tags t
)
3150 (org-odd-levels-only nil
))
3152 (org-move-to-column 10)
3153 (looking-at-p ":tag:$")))
3155 (org-test-with-temp-text "* H :tag:"
3156 (let ((org-tags-column 10)
3157 (org-auto-align-tags nil
)
3158 (org-odd-levels-only nil
))
3160 (org-move-to-column 10)
3161 (looking-at-p ":tag:$")))
3162 ;; When `org-adapt-indentation' is non-nil, always indent planning
3163 ;; info and property drawers accordingly.
3166 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3167 (let ((org-odd-levels-only nil
)
3168 (org-adapt-indentation t
))
3171 (org-get-indentation))))
3174 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3175 (let ((org-odd-levels-only nil
)
3176 (org-adapt-indentation t
))
3179 (org-get-indentation))))
3182 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3183 (let ((org-odd-levels-only nil
)
3184 (org-adapt-indentation nil
))
3187 (org-get-indentation))))
3188 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3189 ;; section accordingly. Ignore, however, footnote definitions and
3190 ;; inlinetasks boundaries.
3193 (org-test-with-temp-text "* H\n Paragraph"
3194 (let ((org-odd-levels-only nil
)
3195 (org-adapt-indentation t
))
3198 (org-get-indentation))))
3201 (org-test-with-temp-text "* H\n Paragraph"
3202 (let ((org-odd-levels-only nil
)
3203 (org-adapt-indentation nil
))
3206 (org-get-indentation))))
3209 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3210 (let ((org-odd-levels-only nil
)
3211 (org-adapt-indentation t
))
3213 (goto-char (point-max))
3214 (org-get-indentation))))
3217 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3218 (let ((org-odd-levels-only nil
)
3219 (org-adapt-indentation t
))
3221 (goto-char (point-max))
3222 (org-get-indentation))))
3223 (when (featurep 'org-inlinetask
)
3226 (let ((org-inlinetask-min-level 5)
3227 (org-adapt-indentation t
))
3228 (org-test-with-temp-text "* H\n***** I\n***** END"
3231 (org-get-indentation))))))
3232 (when (featurep 'org-inlinetask
)
3235 (let ((org-inlinetask-min-level 5)
3236 (org-adapt-indentation t
))
3237 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3240 (org-get-indentation))))))
3241 ;; Ignore contents of source blocks or example blocks when
3242 ;; indentation should be preserved (through
3243 ;; `org-src-preserve-indentation' or "-i" flag).
3246 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3247 (let ((org-adapt-indentation t
)
3248 (org-src-preserve-indentation nil
))
3251 (org-get-indentation))))
3254 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3255 (let ((org-adapt-indentation t
)
3256 (org-src-preserve-indentation t
))
3259 (org-get-indentation))))
3262 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3263 (let ((org-adapt-indentation t
)
3264 (org-src-preserve-indentation t
))
3267 (org-get-indentation))))
3270 (org-test-with-temp-text
3271 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3272 (let ((org-adapt-indentation t
)
3273 (org-src-preserve-indentation nil
))
3276 (org-get-indentation)))))
3278 (ert-deftest test-org
/promote
()
3279 "Test `org-promote' specifications."
3280 ;; Return an error if headline is to be promoted to level 0, unless
3281 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3282 ;; headline becomes a comment.
3284 (org-test-with-temp-text "* H"
3285 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3288 (org-test-with-temp-text "* H"
3289 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3291 ;; Remove correct number of stars according to
3292 ;; `org-odd-levels-only'.
3295 (org-test-with-temp-text "*** H"
3296 (let ((org-odd-levels-only nil
)) (org-promote))
3297 (org-current-level))))
3300 (org-test-with-temp-text "*** H"
3301 (let ((org-odd-levels-only t
)) (org-promote))
3302 (org-current-level))))
3303 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3305 (org-test-with-temp-text "** H :tag:"
3306 (let ((org-tags-column 10)
3307 (org-auto-align-tags t
)
3308 (org-odd-levels-only nil
))
3310 (org-move-to-column 10)
3311 (looking-at-p ":tag:$")))
3313 (org-test-with-temp-text "** H :tag:"
3314 (let ((org-tags-column 10)
3315 (org-auto-align-tags nil
)
3316 (org-odd-levels-only nil
))
3318 (org-move-to-column 10)
3319 (looking-at-p ":tag:$")))
3320 ;; When `org-adapt-indentation' is non-nil, always indent planning
3321 ;; info and property drawers.
3324 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3325 (let ((org-odd-levels-only nil
)
3326 (org-adapt-indentation t
))
3329 (org-get-indentation))))
3332 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3333 (let ((org-odd-levels-only nil
)
3334 (org-adapt-indentation t
))
3337 (org-get-indentation))))
3340 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3341 (let ((org-odd-levels-only nil
)
3342 (org-adapt-indentation nil
))
3345 (org-get-indentation))))
3346 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3347 ;; section accordingly. Ignore, however, footnote definitions and
3348 ;; inlinetasks boundaries.
3351 (org-test-with-temp-text "** H\n Paragraph"
3352 (let ((org-odd-levels-only nil
)
3353 (org-adapt-indentation t
))
3356 (org-get-indentation))))
3359 (org-test-with-temp-text "** H\n Paragraph"
3360 (let ((org-odd-levels-only nil
)
3361 (org-adapt-indentation nil
))
3364 (org-get-indentation))))
3367 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3368 (let ((org-odd-levels-only nil
)
3369 (org-adapt-indentation t
))
3372 (org-get-indentation))))
3373 (when (featurep 'org-inlinetask
)
3376 (let ((org-inlinetask-min-level 5)
3377 (org-adapt-indentation t
))
3378 (org-test-with-temp-text "** H\n***** I\n***** END"
3381 (org-get-indentation))))))
3382 (when (featurep 'org-inlinetask
)
3385 (let ((org-inlinetask-min-level 5)
3386 (org-adapt-indentation t
))
3387 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3390 (org-get-indentation))))))
3391 ;; Give up shifting if it would break document's structure
3395 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3396 (let ((org-odd-levels-only nil
)
3397 (org-adapt-indentation t
))
3400 (org-get-indentation))))
3403 (org-test-with-temp-text "** H\n Paragraph\n * list."
3404 (let ((org-odd-levels-only nil
)
3405 (org-adapt-indentation t
))
3408 (org-get-indentation))))
3409 ;; Ignore contents of source blocks or example blocks when
3410 ;; indentation should be preserved (through
3411 ;; `org-src-preserve-indentation' or "-i" flag).
3414 (org-test-with-temp-text
3415 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3416 (let ((org-adapt-indentation t
)
3417 (org-src-preserve-indentation nil
)
3418 (org-odd-levels-only nil
))
3421 (org-get-indentation))))
3424 (org-test-with-temp-text
3425 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3426 (let ((org-adapt-indentation t
)
3427 (org-src-preserve-indentation t
)
3428 (org-odd-levels-only nil
))
3431 (org-get-indentation))))
3434 (org-test-with-temp-text
3435 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3436 (let ((org-adapt-indentation t
)
3437 (org-src-preserve-indentation t
)
3438 (org-odd-levels-only nil
))
3441 (org-get-indentation))))
3444 (org-test-with-temp-text
3445 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3446 (let ((org-adapt-indentation t
)
3447 (org-src-preserve-indentation nil
)
3448 (org-odd-levels-only nil
))
3451 (org-get-indentation)))))
3456 (ert-deftest test-org
/at-planning-p
()
3457 "Test `org-at-planning-p' specifications."
3460 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3461 (org-at-planning-p)))
3463 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3464 (org-at-planning-p)))
3465 ;; Correctly find planning attached to inlinetasks.
3466 (when (featurep 'org-inlinetask
)
3468 (org-test-with-temp-text
3469 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3470 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3472 (org-test-with-temp-text
3473 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3474 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3476 (org-test-with-temp-text
3477 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3478 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3480 (org-test-with-temp-text
3481 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3482 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3484 (ert-deftest test-org
/add-planning-info
()
3485 "Test `org-add-planning-info'."
3486 ;; Create deadline when `org-adapt-indentation' is non-nil.
3488 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3489 (org-test-with-temp-text "* H\nParagraph<point>"
3490 (let ((org-adapt-indentation t
))
3491 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3492 (replace-regexp-in-string
3493 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3495 ;; Create deadline when `org-adapt-indentation' is nil.
3497 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3498 (org-test-with-temp-text "* H\nParagraph<point>"
3499 (let ((org-adapt-indentation nil
))
3500 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3501 (replace-regexp-in-string
3502 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3504 ;; Update deadline when `org-adapt-indentation' is non-nil.
3506 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3507 (org-test-with-temp-text "\
3509 DEADLINE: <2015-06-24 Wed>
3511 (let ((org-adapt-indentation t
))
3512 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3513 (replace-regexp-in-string
3514 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3516 ;; Update deadline when `org-adapt-indentation' is nil.
3518 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3519 (org-test-with-temp-text "\
3521 DEADLINE: <2015-06-24 Wed>
3523 (let ((org-adapt-indentation nil
))
3524 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3525 (replace-regexp-in-string
3526 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3528 ;; Schedule when `org-adapt-indentation' is non-nil.
3530 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3531 (org-test-with-temp-text "* H\nParagraph<point>"
3532 (let ((org-adapt-indentation t
))
3533 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3534 (replace-regexp-in-string
3535 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3537 ;; Schedule when `org-adapt-indentation' is nil.
3539 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3540 (org-test-with-temp-text "* H\nParagraph<point>"
3541 (let ((org-adapt-indentation nil
))
3542 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3543 (replace-regexp-in-string
3544 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3546 ;; Add deadline when scheduled.
3550 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3552 (org-test-with-temp-text "\
3554 SCHEDULED: <2015-06-24 Wed>
3556 (let ((org-adapt-indentation t
))
3557 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3558 (replace-regexp-in-string
3559 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3561 ;; Remove middle entry.
3565 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3567 (org-test-with-temp-text "\
3569 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3571 (let ((org-adapt-indentation t
))
3572 (org-add-planning-info nil nil
'deadline
))
3573 (replace-regexp-in-string
3574 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3576 ;; Remove last entry and then middle entry (order should not
3581 CLOSED: [2015-06-24]
3583 (org-test-with-temp-text "\
3585 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3587 (let ((org-adapt-indentation t
))
3588 (org-add-planning-info nil nil
'scheduled
'deadline
))
3589 (replace-regexp-in-string
3590 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3592 ;; Remove closed when `org-adapt-indentation' is non-nil.
3594 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3595 (org-test-with-temp-text "\
3597 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3599 (let ((org-adapt-indentation t
))
3600 (org-add-planning-info nil nil
'closed
))
3601 (replace-regexp-in-string
3602 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3605 (equal "* H\n Paragraph"
3606 (org-test-with-temp-text "\
3608 CLOSED: [2015-06-25 Thu]
3610 (let ((org-adapt-indentation t
))
3611 (org-add-planning-info nil nil
'closed
))
3612 (replace-regexp-in-string
3613 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3615 ;; Remove closed when `org-adapt-indentation' is nil.
3617 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3618 (org-test-with-temp-text "\
3620 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3622 (let ((org-adapt-indentation nil
))
3623 (org-add-planning-info nil nil
'closed
))
3624 (replace-regexp-in-string
3625 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3628 (equal "* H\nParagraph"
3629 (org-test-with-temp-text "\
3631 CLOSED: [2015-06-25 Thu]
3633 (let ((org-adapt-indentation nil
))
3634 (org-add-planning-info nil nil
'closed
))
3635 (replace-regexp-in-string
3636 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3638 ;; Remove closed entry and delete empty line.
3643 (org-test-with-temp-text "\
3645 CLOSED: [2015-06-24 Wed]
3647 (let ((org-adapt-indentation t
))
3648 (org-add-planning-info nil nil
'closed
))
3649 (replace-regexp-in-string
3650 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3652 ;; Remove one entry and update another.
3654 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3655 (org-test-with-temp-text "\
3657 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3659 (let ((org-adapt-indentation t
))
3660 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3661 (replace-regexp-in-string
3662 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3668 (ert-deftest test-org
/buffer-property-keys
()
3669 "Test `org-buffer-property-keys' specifications."
3670 ;; Retrieve properties accross siblings.
3673 (org-test-with-temp-text "
3682 (org-buffer-property-keys))))
3683 ;; Retrieve properties accross children.
3686 (org-test-with-temp-text "
3695 (org-buffer-property-keys))))
3696 ;; Retrieve muliple properties in the same drawer.
3699 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3700 (org-buffer-property-keys))))
3701 ;; Ignore extension symbol in property name.
3704 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3705 (org-buffer-property-keys))))
3706 ;; With non-nil COLUMNS, extract property names from columns.
3709 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3710 (org-buffer-property-keys nil nil t
))))
3712 (equal '("A" "B" "COLUMNS")
3713 (org-test-with-temp-text
3714 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3715 (org-buffer-property-keys nil nil t
))))
3716 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
3719 (org-test-with-temp-text
3720 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
3721 (org-buffer-property-keys nil nil nil t
)))))
3723 (ert-deftest test-org
/property-values
()
3724 "Test `org-property-values' specifications."
3728 (org-test-with-temp-text
3729 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3730 (org-property-values "A"))))
3731 ;; Ignore empty values.
3733 (org-test-with-temp-text
3734 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3735 (org-property-values "A")))
3736 ;; Take into consideration extended values.
3739 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3740 (org-property-values "A")))))
3742 (ert-deftest test-org
/find-property
()
3743 "Test `org-find-property' specifications."
3747 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3748 (org-find-property "prop"))))
3749 ;; Ignore false positives.
3752 (org-test-with-temp-text
3753 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3754 (org-find-property "A"))))
3755 ;; Return first entry found in buffer.
3758 (org-test-with-temp-text
3759 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3760 (org-find-property "A"))))
3761 ;; Only search visible part of the buffer.
3764 (org-test-with-temp-text
3765 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3766 (org-narrow-to-subtree)
3767 (org-find-property "A"))))
3768 ;; With optional argument, only find entries with a specific value.
3770 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3771 (org-find-property "A" "2")))
3774 (org-test-with-temp-text
3775 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3776 (org-find-property "A" "2"))))
3777 ;; Use "nil" for explicit nil values.
3780 (org-test-with-temp-text
3781 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3782 (org-find-property "A" "nil")))))
3784 (ert-deftest test-org
/entry-delete
()
3785 "Test `org-entry-delete' specifications."
3789 " *:PROPERTIES:\n *:B: +2\n *:END:"
3790 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3791 (org-entry-delete (point) "A")
3793 ;; Also remove accumulated properties.
3797 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3798 (org-entry-delete (point) "A")
3800 ;; When last property is removed, remove the property drawer.
3804 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3805 (org-entry-delete (point) "A")
3807 ;; Return a non-nil value when some property was removed.
3809 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3810 (org-entry-delete (point) "A")))
3812 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3813 (org-entry-delete (point) "C"))))
3815 (ert-deftest test-org
/entry-get
()
3816 "Test `org-entry-get' specifications."
3820 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3821 (org-entry-get (point) "A"))))
3825 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3826 (org-entry-get (point) "a"))))
3827 ;; Handle extended values, both before and after base value.
3830 (org-test-with-temp-text
3831 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3832 (org-entry-get (point) "A"))))
3833 ;; Empty values are returned as the empty string.
3836 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3837 (org-entry-get (point) "A"))))
3838 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3839 ;; otherwise, return nil.
3841 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3842 (org-entry-get (point) "A")))
3845 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3846 (org-entry-get (point) "A" nil t
))))
3847 ;; Return nil when no property is found, independently on the
3848 ;; LITERAL-NIL argument.
3850 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3851 (org-entry-get (point) "B")))
3853 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3854 (org-entry-get (point) "B" nil t
)))
3855 ;; Handle inheritance, when allowed. Include extended values and
3856 ;; possibly global values.
3860 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3861 (org-entry-get (point) "A" t
))))
3865 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3866 (let ((org-use-property-inheritance t
))
3867 (org-entry-get (point) "A" 'selective
)))))
3869 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3870 (let ((org-use-property-inheritance nil
))
3871 (org-entry-get (point) "A" 'selective
))))
3875 (org-test-with-temp-text
3876 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3877 (org-entry-get (point-max) "A" t
))))
3880 (org-test-with-temp-text
3881 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3883 (org-entry-get (point-max) "A" t
))))
3886 (org-test-with-temp-text
3887 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3889 (org-entry-get (point-max) "A" t
)))))
3891 (ert-deftest test-org
/entry-properties
()
3892 "Test `org-entry-properties' specifications."
3893 ;; Get "ITEM" property.
3896 (org-test-with-temp-text "* TODO H"
3897 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3900 (org-test-with-temp-text "* TODO H"
3901 (cdr (assoc "ITEM" (org-entry-properties))))))
3902 ;; Get "TODO" property. TODO keywords are case sensitive.
3905 (org-test-with-temp-text "* TODO H"
3906 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3909 (org-test-with-temp-text "* TODO H"
3910 (cdr (assoc "TODO" (org-entry-properties))))))
3912 (org-test-with-temp-text "* H"
3913 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3915 (org-test-with-temp-text "* todo H"
3916 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3917 ;; Get "PRIORITY" property.
3920 (org-test-with-temp-text "* [#A] H"
3921 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3924 (org-test-with-temp-text "* [#A] H"
3925 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3927 (equal (char-to-string org-default-priority
)
3928 (org-test-with-temp-text "* H"
3929 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3930 ;; Get "FILE" property.
3932 (org-test-with-temp-text-in-file "* H\nParagraph"
3933 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3934 (buffer-file-name))))
3936 (org-test-with-temp-text-in-file "* H\nParagraph"
3937 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3938 (buffer-file-name))))
3940 (org-test-with-temp-text "* H\nParagraph"
3941 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3942 ;; Get "TAGS" property.
3944 (equal ":tag1:tag2:"
3945 (org-test-with-temp-text "* H :tag1:tag2:"
3946 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3948 (equal ":tag1:tag2:"
3949 (org-test-with-temp-text "* H :tag1:tag2:"
3950 (cdr (assoc "TAGS" (org-entry-properties))))))
3952 (org-test-with-temp-text "* H"
3953 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3954 ;; Get "ALLTAGS" property.
3956 (equal ":tag1:tag2:"
3957 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3958 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3960 (equal ":tag1:tag2:"
3961 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3962 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3964 (org-test-with-temp-text "* H"
3965 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3966 ;; Get "BLOCKED" property.
3969 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3970 (let ((org-enforce-todo-dependencies t
)
3972 '(org-block-todo-from-children-or-siblings-or-parent)))
3973 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3976 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
3977 (let ((org-enforce-todo-dependencies t
)
3979 '(org-block-todo-from-children-or-siblings-or-parent)))
3980 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3981 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3985 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3986 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3990 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3991 (cdr (assoc "CLOSED" (org-entry-properties))))))
3993 (org-test-with-temp-text "* H"
3994 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3998 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3999 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4003 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4004 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4006 (org-test-with-temp-text "* H"
4007 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4011 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4012 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4016 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4017 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4019 (org-test-with-temp-text "* H"
4020 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4024 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4025 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4028 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4029 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4032 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4033 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4036 (org-test-with-temp-text
4037 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4039 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4040 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4041 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4043 (equal "<2012-03-29 thu.>"
4044 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4045 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4047 (equal "[2012-03-29 thu.]"
4048 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4049 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4051 (equal "<2012-03-29 thu.>"
4052 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4053 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4055 (equal "[2014-03-04 tue.]"
4056 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4057 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
4058 ;; Get standard properties.
4061 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4062 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4063 ;; Handle extended properties.
4066 (org-test-with-temp-text
4067 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4068 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4071 (org-test-with-temp-text
4072 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4073 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4074 ;; Ignore forbidden (special) properties.
4076 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4077 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4079 (ert-deftest test-org
/entry-put
()
4080 "Test `org-entry-put' specifications."
4081 ;; Error when not a string or nil.
4083 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4084 (org-entry-put 1 "test" 2)))
4085 ;; Error when property name is invalid.
4087 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4088 (org-entry-put 1 "no space" "value")))
4090 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4091 (org-entry-put 1 "" "value")))
4092 ;; Set "TODO" property.
4094 (string-match (regexp-quote " TODO H")
4095 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4096 (org-entry-put (point) "TODO" "TODO")
4099 (string-match (regexp-quote "* H")
4100 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4101 (org-entry-put (point) "TODO" nil
)
4103 ;; Set "PRIORITY" property.
4106 (org-test-with-temp-text "* [#B] H"
4107 (org-entry-put (point) "PRIORITY" "A")
4111 (org-test-with-temp-text "* [#B] H"
4112 (org-entry-put (point) "PRIORITY" nil
)
4114 ;; Set "SCHEDULED" property.
4116 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4117 (org-test-with-temp-text "* H"
4118 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4122 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4123 (org-entry-put (point) "SCHEDULED" nil
)
4126 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4127 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4128 (org-entry-put (point) "SCHEDULED" "earlier")
4131 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4132 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4133 (org-entry-put (point) "SCHEDULED" "later")
4135 ;; Set "DEADLINE" property.
4137 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4138 (org-test-with-temp-text "* H"
4139 (org-entry-put (point) "DEADLINE" "2014-03-04")
4143 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4144 (org-entry-put (point) "DEADLINE" nil
)
4147 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4148 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4149 (org-entry-put (point) "DEADLINE" "earlier")
4152 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4153 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4154 (org-entry-put (point) "DEADLINE" "later")
4156 ;; Set "CATEGORY" property
4158 (string-match "^ *:CATEGORY: cat"
4159 (org-test-with-temp-text "* H"
4160 (org-entry-put (point) "CATEGORY" "cat")
4162 ;; Regular properties, with or without pre-existing drawer.
4164 (string-match "^ *:A: +2$"
4165 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4166 (org-entry-put (point) "A" "2")
4169 (string-match "^ *:A: +1$"
4170 (org-test-with-temp-text "* H"
4171 (org-entry-put (point) "A" "1")
4173 ;; Special case: two consecutive headlines.
4175 (string-match "\\* A\n *:PROPERTIES:"
4176 (org-test-with-temp-text "* A\n** B"
4177 (org-entry-put (point) "A" "1")
4183 (ert-deftest test-org
/update-radio-target-regexp
()
4184 "Test `org-update-radio-target-regexp' specifications."
4185 ;; Properly update cache with no previous radio target regexp.
4188 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4189 (save-excursion (goto-char (point-max)) (org-element-context))
4191 (search-forward "o")
4193 (org-update-radio-target-regexp)
4194 (goto-char (point-max))
4195 (org-element-type (org-element-context)))))
4196 ;; Properly update cache with previous radio target regexp.
4199 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4200 (save-excursion (goto-char (point-max)) (org-element-context))
4202 (search-forward "o")
4204 (org-update-radio-target-regexp)
4205 (search-backward "r")
4208 (org-update-radio-target-regexp)
4209 (goto-char (point-max))
4210 (delete-region (line-beginning-position) (point))
4212 (org-element-type (org-element-context))))))
4217 (ert-deftest test-org
/match-sparse-tree
()
4218 "Test `org-match-sparse-tree' specifications."
4221 (org-test-with-temp-text "* H\n** H1 :tag:"
4222 (org-match-sparse-tree nil
"tag")
4223 (search-forward "H1")
4224 (org-invisible-p2)))
4226 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4227 (org-match-sparse-tree nil
"tag")
4228 (search-forward "H2")
4229 (org-invisible-p2)))
4230 ;; "-" operator for tags.
4232 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4233 (org-match-sparse-tree nil
"tag1-tag2")
4234 (search-forward "H1")
4235 (org-invisible-p2)))
4237 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4238 (org-match-sparse-tree nil
"tag1-tag2")
4239 (search-forward "H2")
4240 (org-invisible-p2)))
4241 ;; "&" operator for tags.
4243 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4244 (org-match-sparse-tree nil
"tag1&tag2")
4245 (search-forward "H1")
4246 (org-invisible-p2)))
4248 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4249 (org-match-sparse-tree nil
"tag1&tag2")
4250 (search-forward "H2")
4251 (org-invisible-p2)))
4252 ;; "|" operator for tags.
4254 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4255 (org-match-sparse-tree nil
"tag1|tag2")
4256 (search-forward "H1")
4257 (org-invisible-p2)))
4259 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4260 (org-match-sparse-tree nil
"tag1|tag2")
4261 (search-forward "H2")
4262 (org-invisible-p2)))
4263 ;; Regexp match on tags.
4265 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4266 (org-match-sparse-tree nil
"{^tag.*}")
4267 (search-forward "H1")
4268 (org-invisible-p2)))
4270 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4271 (org-match-sparse-tree nil
"{^tag.*}")
4272 (search-forward "H2")
4273 (org-invisible-p2)))
4274 ;; Match group tags.
4276 (org-test-with-temp-text
4277 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4278 (org-match-sparse-tree nil
"work")
4279 (search-forward "H1")
4280 (org-invisible-p2)))
4282 (org-test-with-temp-text
4283 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4284 (org-match-sparse-tree nil
"work")
4285 (search-forward "H2")
4286 (org-invisible-p2)))
4287 ;; Match group tags with hard brackets.
4289 (org-test-with-temp-text
4290 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4291 (org-match-sparse-tree nil
"work")
4292 (search-forward "H1")
4293 (org-invisible-p2)))
4295 (org-test-with-temp-text
4296 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4297 (org-match-sparse-tree nil
"work")
4298 (search-forward "H2")
4299 (org-invisible-p2)))
4300 ;; Match tags in hierarchies
4302 (org-test-with-temp-text
4303 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4304 #+TAGS: [ Lev_2 : Lev_3 ]\n
4305 #+TAGS: { Lev_3 : Lev_4 }\n
4306 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4307 (org-match-sparse-tree nil
"Lev_1")
4308 (search-forward "H4")
4309 (org-invisible-p2)))
4310 ;; Match regular expressions in tags
4312 (org-test-with-temp-text
4313 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4314 (org-match-sparse-tree nil
"Lev")
4315 (search-forward "H1")
4316 (org-invisible-p2)))
4318 (org-test-with-temp-text
4319 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4320 (org-match-sparse-tree nil
"Lev")
4321 (search-forward "H1")
4322 (org-invisible-p2)))
4323 ;; Match properties.
4325 (org-test-with-temp-text
4326 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4327 (org-match-sparse-tree nil
"A=\"1\"")
4328 (search-forward "H2")
4329 (org-invisible-p2)))
4331 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4332 (org-match-sparse-tree nil
"A=\"1\"")
4333 (search-forward "H2")
4334 (org-invisible-p2)))
4335 ;; Case is not significant when matching properties.
4337 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4338 (org-match-sparse-tree nil
"a=\"1\"")
4339 (search-forward "H2")
4340 (org-invisible-p2)))
4342 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4343 (org-match-sparse-tree nil
"A=\"1\"")
4344 (search-forward "H2")
4345 (org-invisible-p2)))
4346 ;; Match special LEVEL property.
4348 (org-test-with-temp-text "* H\n** H1\n*** H2"
4349 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4350 (search-forward "H1")
4351 (org-invisible-p2)))
4353 (org-test-with-temp-text "* H\n** H1\n*** H2"
4354 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4355 (search-forward "H2")
4356 (org-invisible-p2)))
4357 ;; Comparison operators when matching properties.
4359 (org-test-with-temp-text
4360 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4361 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4362 (search-forward "H1")
4363 (org-invisible-p2)))
4365 (org-test-with-temp-text
4366 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4367 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4368 (search-forward "H2")
4369 (org-invisible-p2)))
4370 ;; Regexp match on properties values.
4372 (org-test-with-temp-text
4373 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4374 (org-match-sparse-tree nil
"A={f.*}")
4375 (search-forward "H1")
4376 (org-invisible-p2)))
4378 (org-test-with-temp-text
4379 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4380 (org-match-sparse-tree nil
"A={f.*}")
4381 (search-forward "H2")
4382 (org-invisible-p2)))
4383 ;; With an optional argument, limit match to TODO entries.
4385 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4386 (org-match-sparse-tree t
"tag")
4387 (search-forward "H1")
4388 (org-invisible-p2)))
4390 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4391 (org-match-sparse-tree t
"tag")
4392 (search-forward "H2")
4393 (org-invisible-p2))))
4395 (ert-deftest test-org
/occur
()
4396 "Test `org-occur' specifications."
4397 ;; Count number of matches.
4400 (org-test-with-temp-text "* H\nA\n* H2"
4404 (org-test-with-temp-text "* H\nA\n* H2\nA"
4406 ;; Test CALLBACK optional argument.
4409 (org-test-with-temp-text "* H\nA\n* H2"
4410 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4413 (org-test-with-temp-text "* H\nA\n* H2\nA"
4414 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4415 ;; Case-fold searches according to `org-occur-case-fold-search'.
4418 (org-test-with-temp-text "Aa"
4419 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
4422 (org-test-with-temp-text "Aa"
4423 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
4426 (org-test-with-temp-text "Aa"
4427 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
4430 (org-test-with-temp-text "Aa"
4431 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
4434 (org-test-with-temp-text "Aa"
4435 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
4438 (org-test-with-temp-text "Aa"
4439 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
4444 (ert-deftest test-org
/tag-string-to-alist
()
4445 "Test `org-tag-string-to-alist' specifications."
4446 ;; Tag without selection key.
4447 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
4448 ;; Tag with selection key.
4449 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
4453 (org-tag-string-to-alist "[ group : t1 t2 ]")
4454 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
4455 ;; Mutually exclusive tags.
4456 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
4457 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
4460 (org-tag-string-to-alist "{ group : tag1 tag2 }")
4461 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
4463 (ert-deftest test-org
/tag-alist-to-string
()
4464 "Test `org-tag-alist-to-string' specifications."
4465 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
4466 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
4469 (org-tag-alist-to-string
4470 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4471 "[ group : t1 t2 ]"))
4473 (equal (org-tag-alist-to-string
4474 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
4478 (org-tag-alist-to-string
4479 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
4480 "{ group : tag1 tag2 }")))
4482 (ert-deftest test-org
/tag-alist-to-groups
()
4483 "Test `org-tag-alist-to-groups' specifications."
4485 (equal (org-tag-alist-to-groups
4486 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
4487 '(("group" "t1" "t2"))))
4490 (org-tag-alist-to-groups
4491 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4492 '(("group" "t1" "t2"))))
4494 (org-tag-alist-to-groups
4495 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
4497 (ert-deftest test-org
/tag-align
()
4498 "Test `org-align-tags-here' with different display width."
4500 ;; 12345678901234567890
4501 (equal "* Test :abc:"
4502 (org-test-with-temp-text "* Test :abc:"
4503 (let ((org-tags-column -
20)
4504 (indent-tabs-mode nil
))
4505 (org-fix-tags-on-the-fly))
4508 ;; 12345678901234567890
4509 (equal "* Test :日本語:"
4510 (org-test-with-temp-text "* Test :日本語:"
4511 (let ((org-tags-column -
20)
4512 (indent-tabs-mode nil
))
4513 (org-fix-tags-on-the-fly))
4516 (ert-deftest test-org
/tags-at
()
4518 (equal '("foo" "bar")
4519 (org-test-with-temp-text
4520 "* T<point>est :foo:bar:"
4521 (org-get-tags-at)))))
4526 (ert-deftest test-org
/time-stamp
()
4527 "Test `org-time-stamp' specifications."
4528 ;; Insert chosen time stamp at point.
4531 "Te<2014-03-04 .*?>xt"
4532 (org-test-with-temp-text "Te<point>xt"
4533 (cl-letf (((symbol-function 'org-read-date
)
4534 (lambda (&rest args
)
4535 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4536 (org-time-stamp nil
)
4538 ;; With a prefix argument, also insert time.
4541 "Te<2014-03-04 .*? 00:41>xt"
4542 (org-test-with-temp-text "Te<point>xt"
4543 (cl-letf (((symbol-function 'org-read-date
)
4544 (lambda (&rest args
)
4545 (apply #'encode-time
4546 (org-parse-time-string "2014-03-04 00:41")))))
4547 (org-time-stamp '(4))
4549 ;; With two universal prefix arguments, insert an active timestamp
4550 ;; with the current time without prompting the user.
4553 "Te<2014-03-04 .*? 00:41>xt"
4554 (org-test-with-temp-text "Te<point>xt"
4555 (cl-letf (((symbol-function 'current-time
)
4557 (apply #'encode-time
4558 (org-parse-time-string "2014-03-04 00:41")))))
4559 (org-time-stamp '(16))
4561 ;; When optional argument is non-nil, insert an inactive timestamp.
4564 "Te\\[2014-03-04 .*?\\]xt"
4565 (org-test-with-temp-text "Te<point>xt"
4566 (cl-letf (((symbol-function 'org-read-date
)
4567 (lambda (&rest args
)
4568 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4569 (org-time-stamp nil t
)
4571 ;; When called from a timestamp, replace existing one.
4575 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4576 (cl-letf (((symbol-function 'org-read-date
)
4577 (lambda (&rest args
)
4578 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4579 (org-time-stamp nil
)
4583 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4584 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4585 (cl-letf (((symbol-function 'org-read-date
)
4586 (lambda (&rest args
)
4587 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4588 (org-time-stamp nil
)
4590 ;; When replacing a timestamp, preserve repeater, if any.
4593 "<2014-03-04 .*? \\+2y>"
4594 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4595 (cl-letf (((symbol-function 'org-read-date
)
4596 (lambda (&rest args
)
4597 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4598 (org-time-stamp nil
)
4600 ;; When called twice in a raw, build a date range.
4603 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4604 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4605 (cl-letf (((symbol-function 'org-read-date
)
4606 (lambda (&rest args
)
4607 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4608 (let ((last-command 'org-time-stamp
)
4609 (this-command 'org-time-stamp
))
4610 (org-time-stamp nil
))
4611 (buffer-string))))))
4613 (ert-deftest test-org
/timestamp-has-time-p
()
4614 "Test `org-timestamp-has-time-p' specifications."
4617 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4618 (org-timestamp-has-time-p (org-element-context))))
4621 (org-test-with-temp-text "<2012-03-29 Thu>"
4622 (org-timestamp-has-time-p (org-element-context)))))
4624 (ert-deftest test-org
/timestamp-format
()
4625 "Test `org-timestamp-format' specifications."
4630 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4631 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4636 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4637 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4639 (ert-deftest test-org
/timestamp-split-range
()
4640 "Test `org-timestamp-split-range' specifications."
4641 ;; Extract range start (active).
4644 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4645 (let ((ts (org-timestamp-split-range (org-element-context))))
4646 (mapcar (lambda (p) (org-element-property p ts
))
4647 '(:year-end
:month-end
:day-end
))))))
4648 ;; Extract range start (inactive)
4651 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4652 (let ((ts (org-timestamp-split-range (org-element-context))))
4653 (mapcar (lambda (p) (org-element-property p ts
))
4654 '(:year-end
:month-end
:day-end
))))))
4655 ;; Extract range end (active).
4658 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4659 (let ((ts (org-timestamp-split-range
4660 (org-element-context) t
)))
4661 (mapcar (lambda (p) (org-element-property p ts
))
4662 '(:year-end
:month-end
:day-end
))))))
4663 ;; Extract range end (inactive)
4666 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4667 (let ((ts (org-timestamp-split-range
4668 (org-element-context) t
)))
4669 (mapcar (lambda (p) (org-element-property p ts
))
4670 '(:year-end
:month-end
:day-end
))))))
4671 ;; Return the timestamp if not a range.
4673 (org-test-with-temp-text "[2012-03-29 Thu]"
4674 (let* ((ts-orig (org-element-context))
4675 (ts-copy (org-timestamp-split-range ts-orig
)))
4676 (eq ts-orig ts-copy
))))
4678 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4679 (let* ((ts-orig (org-element-context))
4680 (ts-copy (org-timestamp-split-range ts-orig
)))
4681 (eq ts-orig ts-copy
)))))
4683 (ert-deftest test-org
/timestamp-translate
()
4684 "Test `org-timestamp-translate' specifications."
4685 ;; Translate whole date range.
4688 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4689 (let ((org-display-custom-times t
)
4690 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4691 (org-timestamp-translate (org-element-context))))))
4692 ;; Translate date range start.
4695 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4696 (let ((org-display-custom-times t
)
4697 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4698 (org-timestamp-translate (org-element-context) 'start
)))))
4699 ;; Translate date range end.
4702 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4703 (let ((org-display-custom-times t
)
4704 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4705 (org-timestamp-translate (org-element-context) 'end
)))))
4706 ;; Translate time range.
4709 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4710 (let ((org-display-custom-times t
)
4711 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4712 (org-timestamp-translate (org-element-context))))))
4713 ;; Translate non-range timestamp.
4716 (org-test-with-temp-text "<2012-03-29 Thu>"
4717 (let ((org-display-custom-times t
)
4718 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4719 (org-timestamp-translate (org-element-context))))))
4720 ;; Do not change `diary' timestamps.
4722 (equal "<%%(org-float t 4 2)>"
4723 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4724 (let ((org-display-custom-times t
)
4725 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4726 (org-timestamp-translate (org-element-context)))))))
4732 (ert-deftest test-org
/flag-drawer
()
4733 "Test `org-flag-drawer' specifications."
4736 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4738 (get-char-property (line-end-position) 'invisible
)))
4741 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4743 (org-flag-drawer nil
)
4744 (get-char-property (line-end-position) 'invisible
)))
4745 ;; Test optional argument.
4747 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4748 (let ((drawer (save-excursion (search-forward ":D2")
4749 (org-element-at-point))))
4750 (org-flag-drawer t drawer
)
4751 (get-char-property (progn (search-forward ":D2") (line-end-position))
4754 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4755 (let ((drawer (save-excursion (search-forward ":D2")
4756 (org-element-at-point))))
4757 (org-flag-drawer t drawer
)
4758 (get-char-property (line-end-position) 'invisible
))))
4759 ;; Do not hide fake drawers.
4761 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4764 (get-char-property (line-end-position) 'invisible
)))
4765 ;; Do not hide incomplete drawers.
4767 (org-test-with-temp-text ":D:\nparagraph"
4770 (get-char-property (line-end-position) 'invisible
)))
4771 ;; Do not hide drawers when called from final blank lines.
4773 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4774 (goto-char (point-max))
4776 (goto-char (point-min))
4777 (get-char-property (line-end-position) 'invisible
)))
4778 ;; Don't leave point in an invisible part of the buffer when hiding
4781 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4782 (goto-char (point-max))
4784 (get-char-property (point) 'invisible
))))
4786 (ert-deftest test-org
/hide-block-toggle
()
4787 "Test `org-hide-block-toggle' specifications."
4788 ;; Error when not at a block.
4790 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4791 (org-hide-block-toggle 'off
)
4792 (get-char-property (line-end-position) 'invisible
)))
4795 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4796 (org-hide-block-toggle)
4797 (get-char-property (line-end-position) 'invisible
)))
4799 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4800 (org-hide-block-toggle)
4801 (get-char-property (line-end-position) 'invisible
)))
4802 ;; Show block unconditionally when optional argument is `off'.
4804 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4805 (org-hide-block-toggle)
4806 (org-hide-block-toggle 'off
)
4807 (get-char-property (line-end-position) 'invisible
)))
4809 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4810 (org-hide-block-toggle 'off
)
4811 (get-char-property (line-end-position) 'invisible
)))
4812 ;; Hide block unconditionally when optional argument is non-nil.
4814 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4815 (org-hide-block-toggle t
)
4816 (get-char-property (line-end-position) 'invisible
)))
4818 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4819 (org-hide-block-toggle)
4820 (org-hide-block-toggle t
)
4821 (get-char-property (line-end-position) 'invisible
)))
4822 ;; Do not hide block when called from final blank lines.
4824 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4825 (org-hide-block-toggle)
4826 (goto-char (point-min))
4827 (get-char-property (line-end-position) 'invisible
)))
4828 ;; Don't leave point in an invisible part of the buffer when hiding
4831 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4832 (org-hide-block-toggle)
4833 (get-char-property (point) 'invisible
))))
4835 (ert-deftest test-org
/hide-block-toggle-maybe
()
4836 "Test `org-hide-block-toggle-maybe' specifications."
4838 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4839 (org-hide-block-toggle-maybe)))
4841 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4843 (ert-deftest test-org
/show-set-visibility
()
4844 "Test `org-show-set-visibility' specifications."
4845 ;; Do not throw an error before first heading.
4847 (org-test-with-temp-text "Preamble\n* Headline"
4848 (org-show-set-visibility 'tree
)
4850 ;; Test all visibility spans, both on headline and in entry.
4851 (let ((list-visible-lines
4852 (lambda (state headerp
)
4853 (org-test-with-temp-text "* Grandmother (0)
4864 **** The other child (11)
4869 (search-forward (if headerp
"Self" "Match"))
4870 (org-show-set-visibility state
)
4871 (goto-char (point-min))
4872 (let (result (line 0))
4874 (unless (org-invisible-p2) (push line result
))
4877 (nreverse result
))))))
4878 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4879 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4880 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4881 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4882 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4883 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4884 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4885 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4886 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4887 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4888 (funcall list-visible-lines
'tree nil
)))
4889 (should (equal '(0 1 3 4 5 7 12 13)
4890 (funcall list-visible-lines
'canonical t
)))
4891 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4892 (funcall list-visible-lines
'canonical nil
))))
4893 ;; When point is hidden in a drawer or a block, make sure to make it
4896 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
4897 (org-hide-block-toggle)
4898 (search-forward "Text")
4899 (org-show-set-visibility 'minimal
)
4900 (org-invisible-p2)))
4902 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
4904 (search-forward "Text")
4905 (org-show-set-visibility 'minimal
)
4906 (org-invisible-p2)))
4908 (org-test-with-temp-text
4909 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
4912 (org-hide-block-toggle)
4913 (search-forward "Text")
4914 (org-show-set-visibility 'minimal
)
4915 (org-invisible-p2))))
4920 ;;; test-org.el ends here