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
/open-line
()
2491 "Test `org-open-line' specifications."
2492 ;; Call `open-line' outside of tables.
2495 (org-test-with-temp-text "Text"
2498 ;; At a table, create a row above.
2500 (equal "\n| |\n| a |"
2501 (org-test-with-temp-text "\n<point>| a |"
2504 ;; At the very first character of the buffer, also call `open-line'.
2507 (org-test-with-temp-text "| a |"
2510 ;; Narrowing does not count.
2512 (equal "Text\n| |\n| a |"
2513 (org-test-with-temp-text "Text\n<point>| a |"
2514 (narrow-to-region (point) (point-max))
2519 (ert-deftest test-org
/forward-sentence
()
2520 "Test `org-forward-sentence' specifications."
2521 ;; At the end of a table cell, move to the end of the next one.
2523 (org-test-with-temp-text "| a<point> | b |"
2524 (org-forward-sentence)
2525 (looking-at " |$")))
2526 ;; Elsewhere in a cell, move to its end.
2528 (org-test-with-temp-text "| a<point>c | b |"
2529 (org-forward-sentence)
2530 (looking-at " | b |$")))
2531 ;; Otherwise, simply call `forward-sentence'.
2533 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2534 (org-forward-sentence)
2535 (looking-at " Sentence 2.")))
2537 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2538 (org-forward-sentence)
2539 (org-forward-sentence)
2541 ;; At the end of an element, jump to the next one, without stopping
2542 ;; on blank lines in-between.
2544 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2545 (org-forward-sentence)
2548 (ert-deftest test-org
/backward-sentence
()
2549 "Test `org-backward-sentence' specifications."
2550 ;; At the beginning of a table cell, move to the beginning of the
2553 (org-test-with-temp-text "| a | <point>b |"
2554 (org-backward-sentence)
2555 (looking-at "a | b |$")))
2556 ;; Elsewhere in a cell, move to its beginning.
2558 (org-test-with-temp-text "| a | b<point>c |"
2559 (org-backward-sentence)
2560 (looking-at "bc |$")))
2561 ;; Otherwise, simply call `backward-sentence'.
2563 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2564 (org-backward-sentence)
2565 (looking-at "Sentence 2.")))
2567 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2568 (org-backward-sentence)
2569 (org-backward-sentence)
2571 ;; Make sure to hit the beginning of a sentence on the same line as
2574 (org-test-with-temp-text "- Line 1\n line <point>2."
2575 (org-backward-sentence)
2576 (looking-at "Line 1"))))
2578 (ert-deftest test-org
/forward-paragraph
()
2579 "Test `org-forward-paragraph' specifications."
2580 ;; At end of buffer, return an error.
2582 (org-test-with-temp-text "Paragraph"
2583 (goto-char (point-max))
2584 (org-forward-paragraph)))
2587 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2588 (org-forward-paragraph)
2592 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2593 (org-forward-paragraph)
2595 ;; Do not enter elements with invisible contents.
2597 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2598 (org-hide-block-toggle)
2599 (org-forward-paragraph)
2601 ;; On an affiliated keyword, jump to the beginning of the element.
2603 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2604 (org-forward-paragraph)
2605 (looking-at "Para")))
2606 ;; On an item or a footnote definition, move to the second element
2609 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2610 (org-forward-paragraph)
2611 (looking-at " Paragraph")))
2613 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2614 (org-forward-paragraph)
2615 (looking-at "Paragraph")))
2616 ;; On an item, or a footnote definition, when the first line is
2617 ;; empty, move to the first item.
2619 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2620 (org-forward-paragraph)
2621 (looking-at " Paragraph")))
2623 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2624 (org-forward-paragraph)
2625 (looking-at "Paragraph")))
2626 ;; On a table (resp. a property drawer) do not move through table
2627 ;; rows (resp. node properties).
2629 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2630 (org-forward-paragraph)
2631 (looking-at "Paragraph")))
2633 (org-test-with-temp-text
2634 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2635 (org-forward-paragraph)
2636 (looking-at "Paragraph")))
2637 ;; On a verse or source block, stop after blank lines.
2639 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2640 (org-forward-paragraph)
2643 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2644 (org-forward-paragraph)
2645 (looking-at "L2"))))
2647 (ert-deftest test-org
/backward-paragraph
()
2648 "Test `org-backward-paragraph' specifications."
2649 ;; Error at beginning of buffer.
2651 (org-test-with-temp-text "Paragraph"
2652 (org-backward-paragraph)))
2655 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2656 (goto-char (point-max))
2657 (org-backward-paragraph)
2660 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2661 (goto-char (point-max))
2663 (org-backward-paragraph)
2667 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2668 (goto-char (point-max))
2670 (org-backward-paragraph)
2672 ;; Ignore invisible elements.
2674 (org-test-with-temp-text "* H1\n P1\n* H2"
2676 (goto-char (point-max))
2678 (org-backward-paragraph)
2680 ;; On an affiliated keyword, jump to the first one.
2682 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2683 (search-forward "c2")
2684 (org-backward-paragraph)
2685 (looking-at "#\\+name")))
2686 ;; On the second element in an item or a footnote definition, jump
2687 ;; to item or the definition.
2689 (org-test-with-temp-text "- line1\n\n line2"
2690 (goto-char (point-max))
2692 (org-backward-paragraph)
2693 (looking-at "- line1")))
2695 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2696 (goto-char (point-max))
2698 (org-backward-paragraph)
2699 (looking-at "\\[fn:1\\] line1")))
2700 ;; On a table (resp. a property drawer), ignore table rows
2701 ;; (resp. node properties).
2703 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2704 (goto-char (point-max))
2706 (org-backward-paragraph)
2709 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2710 (org-backward-paragraph)
2711 (looking-at ":PROPERTIES:")))
2712 ;; On a source or verse block, stop before blank lines.
2714 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2715 (search-forward "L3")
2717 (org-backward-paragraph)
2720 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2721 (search-forward "L3")
2723 (org-backward-paragraph)
2724 (looking-at "L2"))))
2726 (ert-deftest test-org
/forward-element
()
2727 "Test `org-forward-element' specifications."
2728 ;; 1. At EOB: should error.
2729 (org-test-with-temp-text "Some text\n"
2730 (goto-char (point-max))
2731 (should-error (org-forward-element)))
2732 ;; 2. Standard move: expected to ignore blank lines.
2733 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2734 (org-forward-element)
2735 (should (looking-at (regexp-quote "Second paragraph."))))
2736 ;; 3. Headline tests.
2737 (org-test-with-temp-text "
2742 ;; 3.1. At an headline beginning: move to next headline at the
2745 (org-forward-element)
2746 (should (looking-at (regexp-quote "** Head 1.2")))
2747 ;; 3.2. At an headline beginning: move to parent headline if no
2748 ;; headline at the same level.
2750 (org-forward-element)
2751 (should (looking-at (regexp-quote "** Head 1.2"))))
2752 ;; 4. Greater element tests.
2753 (org-test-with-temp-text
2754 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2755 ;; 4.1. At a greater element: expected to skip contents.
2756 (org-forward-element)
2757 (should (looking-at (regexp-quote "Outside.")))
2758 ;; 4.2. At the end of greater element contents: expected to skip
2759 ;; to the end of the greater element.
2761 (org-forward-element)
2762 (should (looking-at (regexp-quote "Outside."))))
2764 (org-test-with-temp-text "
2778 ;; 5.1. At list top point: expected to move to the element after
2781 (org-forward-element)
2782 (should (looking-at (regexp-quote "Outside.")))
2783 ;; 5.2. Special case: at the first line of a sub-list, but not at
2784 ;; beginning of line, move to next item.
2787 (org-forward-element)
2788 (should (looking-at "- item2"))
2791 (org-forward-element)
2792 (should (looking-at " - sub2"))
2793 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2795 (org-forward-element)
2796 (should (looking-at (regexp-quote " Inner paragraph.")))
2797 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2799 (org-forward-element)
2800 (should (looking-at (regexp-quote " Inner paragraph.")))
2801 ;; 5.5. At an item: expected to move to next item, if any.
2803 (org-forward-element)
2804 (should (looking-at " - sub3"))))
2806 (ert-deftest test-org
/backward-element
()
2807 "Test `org-backward-element' specifications."
2808 ;; 1. Should error at BOB.
2809 (org-test-with-temp-text " \nParagraph."
2810 (should-error (org-backward-element)))
2811 ;; 2. Should move at BOB when called on the first element in buffer.
2813 (org-test-with-temp-text "\n#+TITLE: test"
2814 (progn (forward-line)
2815 (org-backward-element)
2817 ;; 3. Not at the beginning of an element: move at its beginning.
2818 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2821 (org-backward-element)
2822 (should (looking-at (regexp-quote "Paragraph2."))))
2823 ;; 4. Headline tests.
2824 (org-test-with-temp-text "
2829 ;; 4.1. At an headline beginning: move to previous headline at the
2832 (org-backward-element)
2833 (should (looking-at (regexp-quote "** Head 1.1")))
2834 ;; 4.2. At an headline beginning: move to parent headline if no
2835 ;; headline at the same level.
2837 (org-backward-element)
2838 (should (looking-at (regexp-quote "* Head 1")))
2839 ;; 4.3. At the first top-level headline: should error.
2841 (should-error (org-backward-element)))
2842 ;; 5. At beginning of first element inside a greater element:
2843 ;; expected to move to greater element's beginning.
2844 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2846 (org-backward-element)
2847 (should (looking-at "#\\+BEGIN_CENTER")))
2848 ;; 6. At the beginning of the first element in a section: should
2849 ;; move back to headline, if any.
2851 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2852 (progn (goto-char (point-max))
2854 (org-backward-element)
2855 (org-at-heading-p))))
2857 (org-test-with-temp-text "
2872 ;; 7.1. At beginning of sub-list: expected to move to the
2873 ;; paragraph before it.
2875 (org-backward-element)
2876 (should (looking-at "item1"))
2877 ;; 7.2. At an item in a list: expected to move at previous item.
2879 (org-backward-element)
2880 (should (looking-at " - sub2"))
2882 (org-backward-element)
2883 (should (looking-at "- item1"))
2884 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2887 (org-backward-element)
2888 (should (looking-at " - sub1"))
2890 (org-backward-element)
2891 (should (looking-at "- item1"))
2892 ;; 7.4. At blank-lines before list end: expected to move to top
2895 (org-backward-element)
2896 (should (looking-at "- item1"))))
2898 (ert-deftest test-org
/up-element
()
2899 "Test `org-up-element' specifications."
2900 ;; 1. At BOB or with no surrounding element: should error.
2901 (org-test-with-temp-text "Paragraph."
2902 (should-error (org-up-element)))
2903 (org-test-with-temp-text "* Head1\n* Head2"
2905 (should-error (org-up-element)))
2906 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2908 (should-error (org-up-element)))
2909 ;; 2. At an headline: move to parent headline.
2910 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2913 (should (looking-at "\\* Head1")))
2914 ;; 3. Inside a greater element: move to greater element beginning.
2915 (org-test-with-temp-text
2916 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2919 (should (looking-at "#\\+BEGIN_CENTER")))
2921 (org-test-with-temp-text "* Top
2928 Paragraph within sub2.
2931 ;; 4.1. Within an item: move to the item beginning.
2934 (should (looking-at " - sub2"))
2935 ;; 4.2. At an item in a sub-list: move to parent item.
2938 (should (looking-at "- item1"))
2939 ;; 4.3. At an item in top list: move to beginning of whole list.
2942 (should (looking-at "- item1"))
2943 ;; 4.4. Special case. At very top point: should move to parent of
2947 (should (looking-at "\\* Top"))))
2949 (ert-deftest test-org
/down-element
()
2950 "Test `org-down-element' specifications."
2951 ;; Error when the element hasn't got a recursive type.
2952 (org-test-with-temp-text "Paragraph."
2953 (should-error (org-down-element)))
2954 ;; Error when the element has no contents
2955 (org-test-with-temp-text "* Headline"
2956 (should-error (org-down-element)))
2957 ;; When at a plain-list, move to first item.
2958 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2961 (should (looking-at " - Item 1.1")))
2962 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2964 (should (looking-at " Item 1")))
2965 ;; When at a table, move to first row
2966 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2968 (should (looking-at " a | b |")))
2969 ;; Otherwise, move inside the greater element.
2970 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2972 (should (looking-at "Paragraph"))))
2974 (ert-deftest test-org
/drag-element-backward
()
2975 "Test `org-drag-element-backward' specifications."
2979 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2980 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2981 (org-drag-element-backward)
2985 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2986 (org-test-with-temp-text
2987 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2988 (org-drag-element-backward)
2990 ;; Preserve blank lines.
2992 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2993 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2994 (org-drag-element-backward)
2998 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2999 (org-drag-element-backward)
3000 (looking-at-p "2")))
3001 ;; Error when trying to move first element of buffer.
3003 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3004 (org-drag-element-backward)))
3005 ;; Error when trying to swap nested elements.
3007 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3009 (org-drag-element-backward)))
3010 ;; Error when trying to swap an headline element and a non-headline
3013 (org-test-with-temp-text "Test.\n* Head 1"
3015 (org-drag-element-backward)))
3016 ;; Preserve visibility of elements and their contents.
3018 (equal '((63 .
82) (26 .
48))
3019 (org-test-with-temp-text "
3027 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3028 (search-backward "- item 1")
3029 (org-drag-element-backward)
3030 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3031 (overlays-in (point-min) (point-max)))))))
3033 (ert-deftest test-org
/drag-element-forward
()
3034 "Test `org-drag-element-forward' specifications."
3035 ;; 1. Error when trying to move first element of buffer.
3036 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3038 (should-error (org-drag-element-forward)))
3039 ;; 2. Error when trying to swap nested elements.
3040 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3042 (should-error (org-drag-element-forward)))
3043 ;; 3. Error when trying to swap a non-headline element and an
3045 (org-test-with-temp-text "Test.\n* Head 1"
3046 (should-error (org-drag-element-forward)))
3047 ;; 4. Otherwise, swap elements, preserving column and blank lines
3048 ;; between elements.
3049 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3050 (search-forward "graph")
3051 (org-drag-element-forward)
3052 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3053 (should (looking-at " 1")))
3054 ;; 5. Preserve visibility of elements and their contents.
3055 (org-test-with-temp-text "
3063 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3064 (search-backward "#+BEGIN_CENTER")
3065 (org-drag-element-forward)
3068 '((63 .
82) (26 .
48))
3069 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3070 (overlays-in (point-min) (point-max)))))))
3072 (ert-deftest test-org
/next-block
()
3073 "Test `org-next-block' specifications."
3076 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3078 (looking-at "#\\+BEGIN_CENTER")))
3081 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3082 (let ((case-fold-search nil
))
3084 (looking-at "#\\+begin_center"))))
3085 ;; Ignore current line.
3087 (org-test-with-temp-text
3088 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3090 (looking-at "#\\+BEGIN_CENTER")))
3091 ;; Throw an error when no block is found.
3093 (org-test-with-temp-text "Paragraph"
3094 (org-next-block 1)))
3095 ;; With an argument, skip many blocks at once.
3097 (org-test-with-temp-text
3098 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3100 (looking-at "#\\+BEGIN_QUOTE")))
3101 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3103 (org-test-with-temp-text
3104 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3105 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3106 (looking-at "#\\+BEGIN_QUOTE")))
3107 ;; Optional argument is also case-insensitive.
3109 (org-test-with-temp-text
3110 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3111 (let ((case-fold-search nil
))
3112 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3113 (looking-at "#\\+begin_quote")))))
3115 (ert-deftest test-org
/previous-block
()
3116 "Test `org-previous-block' specifications."
3119 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3120 (org-previous-block 1)
3121 (looking-at "#\\+BEGIN_CENTER")))
3124 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3125 (let ((case-fold-search nil
))
3126 (org-previous-block 1)
3127 (looking-at "#\\+begin_center"))))
3128 ;; Ignore current line.
3130 (org-test-with-temp-text
3131 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3132 (org-previous-block 1)
3133 (looking-at "#\\+BEGIN_QUOTE")))
3134 ;; Throw an error when no block is found.
3136 (org-test-with-temp-text "Paragraph<point>"
3137 (org-previous-block 1)))
3138 ;; With an argument, skip many blocks at once.
3140 (org-test-with-temp-text
3141 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3142 (org-previous-block 2)
3143 (looking-at "#\\+BEGIN_CENTER")))
3144 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3146 (org-test-with-temp-text
3147 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3148 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3149 (looking-at "#\\+BEGIN_QUOTE")))
3150 ;; Optional argument is also case-insensitive.
3152 (org-test-with-temp-text
3153 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3154 (let ((case-fold-search nil
))
3155 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3156 (looking-at "#\\+begin_quote")))))
3159 ;;; Outline structure
3161 (ert-deftest test-org
/demote
()
3162 "Test `org-demote' specifications."
3163 ;; Add correct number of stars according to `org-odd-levels-only'.
3166 (org-test-with-temp-text "* H"
3167 (let ((org-odd-levels-only nil
)) (org-demote))
3168 (org-current-level))))
3171 (org-test-with-temp-text "* H"
3172 (let ((org-odd-levels-only t
)) (org-demote))
3173 (org-current-level))))
3174 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3176 (org-test-with-temp-text "* H :tag:"
3177 (let ((org-tags-column 10)
3178 (org-auto-align-tags t
)
3179 (org-odd-levels-only nil
))
3181 (org-move-to-column 10)
3182 (looking-at-p ":tag:$")))
3184 (org-test-with-temp-text "* H :tag:"
3185 (let ((org-tags-column 10)
3186 (org-auto-align-tags nil
)
3187 (org-odd-levels-only nil
))
3189 (org-move-to-column 10)
3190 (looking-at-p ":tag:$")))
3191 ;; When `org-adapt-indentation' is non-nil, always indent planning
3192 ;; info and property drawers accordingly.
3195 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3196 (let ((org-odd-levels-only nil
)
3197 (org-adapt-indentation t
))
3200 (org-get-indentation))))
3203 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3204 (let ((org-odd-levels-only nil
)
3205 (org-adapt-indentation t
))
3208 (org-get-indentation))))
3211 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3212 (let ((org-odd-levels-only nil
)
3213 (org-adapt-indentation nil
))
3216 (org-get-indentation))))
3217 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3218 ;; section accordingly. Ignore, however, footnote definitions and
3219 ;; inlinetasks boundaries.
3222 (org-test-with-temp-text "* H\n Paragraph"
3223 (let ((org-odd-levels-only nil
)
3224 (org-adapt-indentation t
))
3227 (org-get-indentation))))
3230 (org-test-with-temp-text "* H\n Paragraph"
3231 (let ((org-odd-levels-only nil
)
3232 (org-adapt-indentation nil
))
3235 (org-get-indentation))))
3238 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3239 (let ((org-odd-levels-only nil
)
3240 (org-adapt-indentation t
))
3242 (goto-char (point-max))
3243 (org-get-indentation))))
3246 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3247 (let ((org-odd-levels-only nil
)
3248 (org-adapt-indentation t
))
3250 (goto-char (point-max))
3251 (org-get-indentation))))
3252 (when (featurep 'org-inlinetask
)
3255 (let ((org-inlinetask-min-level 5)
3256 (org-adapt-indentation t
))
3257 (org-test-with-temp-text "* H\n***** I\n***** END"
3260 (org-get-indentation))))))
3261 (when (featurep 'org-inlinetask
)
3264 (let ((org-inlinetask-min-level 5)
3265 (org-adapt-indentation t
))
3266 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3269 (org-get-indentation))))))
3270 ;; Ignore contents of source blocks or example blocks when
3271 ;; indentation should be preserved (through
3272 ;; `org-src-preserve-indentation' or "-i" flag).
3275 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3276 (let ((org-adapt-indentation t
)
3277 (org-src-preserve-indentation nil
))
3280 (org-get-indentation))))
3283 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3284 (let ((org-adapt-indentation t
)
3285 (org-src-preserve-indentation t
))
3288 (org-get-indentation))))
3291 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3292 (let ((org-adapt-indentation t
)
3293 (org-src-preserve-indentation t
))
3296 (org-get-indentation))))
3299 (org-test-with-temp-text
3300 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3301 (let ((org-adapt-indentation t
)
3302 (org-src-preserve-indentation nil
))
3305 (org-get-indentation)))))
3307 (ert-deftest test-org
/promote
()
3308 "Test `org-promote' specifications."
3309 ;; Return an error if headline is to be promoted to level 0, unless
3310 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3311 ;; headline becomes a comment.
3313 (org-test-with-temp-text "* H"
3314 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3317 (org-test-with-temp-text "* H"
3318 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3320 ;; Remove correct number of stars according to
3321 ;; `org-odd-levels-only'.
3324 (org-test-with-temp-text "*** H"
3325 (let ((org-odd-levels-only nil
)) (org-promote))
3326 (org-current-level))))
3329 (org-test-with-temp-text "*** H"
3330 (let ((org-odd-levels-only t
)) (org-promote))
3331 (org-current-level))))
3332 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3334 (org-test-with-temp-text "** H :tag:"
3335 (let ((org-tags-column 10)
3336 (org-auto-align-tags t
)
3337 (org-odd-levels-only nil
))
3339 (org-move-to-column 10)
3340 (looking-at-p ":tag:$")))
3342 (org-test-with-temp-text "** H :tag:"
3343 (let ((org-tags-column 10)
3344 (org-auto-align-tags nil
)
3345 (org-odd-levels-only nil
))
3347 (org-move-to-column 10)
3348 (looking-at-p ":tag:$")))
3349 ;; When `org-adapt-indentation' is non-nil, always indent planning
3350 ;; info and property drawers.
3353 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3354 (let ((org-odd-levels-only nil
)
3355 (org-adapt-indentation t
))
3358 (org-get-indentation))))
3361 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3362 (let ((org-odd-levels-only nil
)
3363 (org-adapt-indentation t
))
3366 (org-get-indentation))))
3369 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3370 (let ((org-odd-levels-only nil
)
3371 (org-adapt-indentation nil
))
3374 (org-get-indentation))))
3375 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3376 ;; section accordingly. Ignore, however, footnote definitions and
3377 ;; inlinetasks boundaries.
3380 (org-test-with-temp-text "** H\n Paragraph"
3381 (let ((org-odd-levels-only nil
)
3382 (org-adapt-indentation t
))
3385 (org-get-indentation))))
3388 (org-test-with-temp-text "** H\n Paragraph"
3389 (let ((org-odd-levels-only nil
)
3390 (org-adapt-indentation nil
))
3393 (org-get-indentation))))
3396 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3397 (let ((org-odd-levels-only nil
)
3398 (org-adapt-indentation t
))
3401 (org-get-indentation))))
3402 (when (featurep 'org-inlinetask
)
3405 (let ((org-inlinetask-min-level 5)
3406 (org-adapt-indentation t
))
3407 (org-test-with-temp-text "** H\n***** I\n***** END"
3410 (org-get-indentation))))))
3411 (when (featurep 'org-inlinetask
)
3414 (let ((org-inlinetask-min-level 5)
3415 (org-adapt-indentation t
))
3416 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3419 (org-get-indentation))))))
3420 ;; Give up shifting if it would break document's structure
3424 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3425 (let ((org-odd-levels-only nil
)
3426 (org-adapt-indentation t
))
3429 (org-get-indentation))))
3432 (org-test-with-temp-text "** H\n Paragraph\n * list."
3433 (let ((org-odd-levels-only nil
)
3434 (org-adapt-indentation t
))
3437 (org-get-indentation))))
3438 ;; Ignore contents of source blocks or example blocks when
3439 ;; indentation should be preserved (through
3440 ;; `org-src-preserve-indentation' or "-i" flag).
3443 (org-test-with-temp-text
3444 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3445 (let ((org-adapt-indentation t
)
3446 (org-src-preserve-indentation nil
)
3447 (org-odd-levels-only nil
))
3450 (org-get-indentation))))
3453 (org-test-with-temp-text
3454 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3455 (let ((org-adapt-indentation t
)
3456 (org-src-preserve-indentation t
)
3457 (org-odd-levels-only nil
))
3460 (org-get-indentation))))
3463 (org-test-with-temp-text
3464 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3465 (let ((org-adapt-indentation t
)
3466 (org-src-preserve-indentation t
)
3467 (org-odd-levels-only nil
))
3470 (org-get-indentation))))
3473 (org-test-with-temp-text
3474 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3475 (let ((org-adapt-indentation t
)
3476 (org-src-preserve-indentation nil
)
3477 (org-odd-levels-only nil
))
3480 (org-get-indentation)))))
3485 (ert-deftest test-org
/at-planning-p
()
3486 "Test `org-at-planning-p' specifications."
3489 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3490 (org-at-planning-p)))
3492 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3493 (org-at-planning-p)))
3494 ;; Correctly find planning attached to inlinetasks.
3495 (when (featurep 'org-inlinetask
)
3497 (org-test-with-temp-text
3498 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3499 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3501 (org-test-with-temp-text
3502 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3503 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3505 (org-test-with-temp-text
3506 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3507 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3509 (org-test-with-temp-text
3510 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3511 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3513 (ert-deftest test-org
/add-planning-info
()
3514 "Test `org-add-planning-info'."
3515 ;; Create deadline when `org-adapt-indentation' is non-nil.
3517 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3518 (org-test-with-temp-text "* H\nParagraph<point>"
3519 (let ((org-adapt-indentation t
))
3520 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3521 (replace-regexp-in-string
3522 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3524 ;; Create deadline when `org-adapt-indentation' is nil.
3526 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3527 (org-test-with-temp-text "* H\nParagraph<point>"
3528 (let ((org-adapt-indentation nil
))
3529 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3530 (replace-regexp-in-string
3531 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3533 ;; Update deadline when `org-adapt-indentation' is non-nil.
3535 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3536 (org-test-with-temp-text "\
3538 DEADLINE: <2015-06-24 Wed>
3540 (let ((org-adapt-indentation t
))
3541 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3542 (replace-regexp-in-string
3543 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3545 ;; Update deadline when `org-adapt-indentation' is nil.
3547 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3548 (org-test-with-temp-text "\
3550 DEADLINE: <2015-06-24 Wed>
3552 (let ((org-adapt-indentation nil
))
3553 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3554 (replace-regexp-in-string
3555 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3557 ;; Schedule when `org-adapt-indentation' is non-nil.
3559 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3560 (org-test-with-temp-text "* H\nParagraph<point>"
3561 (let ((org-adapt-indentation t
))
3562 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3563 (replace-regexp-in-string
3564 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3566 ;; Schedule when `org-adapt-indentation' is nil.
3568 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3569 (org-test-with-temp-text "* H\nParagraph<point>"
3570 (let ((org-adapt-indentation nil
))
3571 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3572 (replace-regexp-in-string
3573 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3575 ;; Add deadline when scheduled.
3579 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3581 (org-test-with-temp-text "\
3583 SCHEDULED: <2015-06-24 Wed>
3585 (let ((org-adapt-indentation t
))
3586 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3587 (replace-regexp-in-string
3588 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3590 ;; Remove middle entry.
3594 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3596 (org-test-with-temp-text "\
3598 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3600 (let ((org-adapt-indentation t
))
3601 (org-add-planning-info nil nil
'deadline
))
3602 (replace-regexp-in-string
3603 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3605 ;; Remove last entry and then middle entry (order should not
3610 CLOSED: [2015-06-24]
3612 (org-test-with-temp-text "\
3614 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3616 (let ((org-adapt-indentation t
))
3617 (org-add-planning-info nil nil
'scheduled
'deadline
))
3618 (replace-regexp-in-string
3619 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3621 ;; Remove closed when `org-adapt-indentation' is non-nil.
3623 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3624 (org-test-with-temp-text "\
3626 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3628 (let ((org-adapt-indentation t
))
3629 (org-add-planning-info nil nil
'closed
))
3630 (replace-regexp-in-string
3631 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3634 (equal "* H\n Paragraph"
3635 (org-test-with-temp-text "\
3637 CLOSED: [2015-06-25 Thu]
3639 (let ((org-adapt-indentation t
))
3640 (org-add-planning-info nil nil
'closed
))
3641 (replace-regexp-in-string
3642 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3644 ;; Remove closed when `org-adapt-indentation' is nil.
3646 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3647 (org-test-with-temp-text "\
3649 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3651 (let ((org-adapt-indentation nil
))
3652 (org-add-planning-info nil nil
'closed
))
3653 (replace-regexp-in-string
3654 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3657 (equal "* H\nParagraph"
3658 (org-test-with-temp-text "\
3660 CLOSED: [2015-06-25 Thu]
3662 (let ((org-adapt-indentation nil
))
3663 (org-add-planning-info nil nil
'closed
))
3664 (replace-regexp-in-string
3665 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3667 ;; Remove closed entry and delete empty line.
3672 (org-test-with-temp-text "\
3674 CLOSED: [2015-06-24 Wed]
3676 (let ((org-adapt-indentation t
))
3677 (org-add-planning-info nil nil
'closed
))
3678 (replace-regexp-in-string
3679 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3681 ;; Remove one entry and update another.
3683 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3684 (org-test-with-temp-text "\
3686 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3688 (let ((org-adapt-indentation t
))
3689 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3690 (replace-regexp-in-string
3691 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3697 (ert-deftest test-org
/buffer-property-keys
()
3698 "Test `org-buffer-property-keys' specifications."
3699 ;; Retrieve properties accross siblings.
3702 (org-test-with-temp-text "
3711 (org-buffer-property-keys))))
3712 ;; Retrieve properties accross children.
3715 (org-test-with-temp-text "
3724 (org-buffer-property-keys))))
3725 ;; Retrieve muliple properties in the same drawer.
3728 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3729 (org-buffer-property-keys))))
3730 ;; Ignore extension symbol in property name.
3733 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3734 (org-buffer-property-keys))))
3735 ;; With non-nil COLUMNS, extract property names from columns.
3738 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3739 (org-buffer-property-keys nil nil t
))))
3741 (equal '("A" "B" "COLUMNS")
3742 (org-test-with-temp-text
3743 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3744 (org-buffer-property-keys nil nil t
))))
3745 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
3748 (org-test-with-temp-text
3749 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
3750 (org-buffer-property-keys nil nil nil t
)))))
3752 (ert-deftest test-org
/property-values
()
3753 "Test `org-property-values' specifications."
3757 (org-test-with-temp-text
3758 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3759 (org-property-values "A"))))
3760 ;; Ignore empty values.
3762 (org-test-with-temp-text
3763 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3764 (org-property-values "A")))
3765 ;; Take into consideration extended values.
3768 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3769 (org-property-values "A")))))
3771 (ert-deftest test-org
/find-property
()
3772 "Test `org-find-property' specifications."
3776 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3777 (org-find-property "prop"))))
3778 ;; Ignore false positives.
3781 (org-test-with-temp-text
3782 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3783 (org-find-property "A"))))
3784 ;; Return first entry found in buffer.
3787 (org-test-with-temp-text
3788 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3789 (org-find-property "A"))))
3790 ;; Only search visible part of the buffer.
3793 (org-test-with-temp-text
3794 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3795 (org-narrow-to-subtree)
3796 (org-find-property "A"))))
3797 ;; With optional argument, only find entries with a specific value.
3799 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3800 (org-find-property "A" "2")))
3803 (org-test-with-temp-text
3804 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3805 (org-find-property "A" "2"))))
3806 ;; Use "nil" for explicit nil values.
3809 (org-test-with-temp-text
3810 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3811 (org-find-property "A" "nil")))))
3813 (ert-deftest test-org
/entry-delete
()
3814 "Test `org-entry-delete' specifications."
3818 " *:PROPERTIES:\n *:B: +2\n *:END:"
3819 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3820 (org-entry-delete (point) "A")
3822 ;; Also remove accumulated properties.
3826 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3827 (org-entry-delete (point) "A")
3829 ;; When last property is removed, remove the property drawer.
3833 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3834 (org-entry-delete (point) "A")
3836 ;; Return a non-nil value when some property was removed.
3838 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3839 (org-entry-delete (point) "A")))
3841 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3842 (org-entry-delete (point) "C"))))
3844 (ert-deftest test-org
/entry-get
()
3845 "Test `org-entry-get' specifications."
3849 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3850 (org-entry-get (point) "A"))))
3854 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3855 (org-entry-get (point) "a"))))
3856 ;; Handle extended values, both before and after base value.
3859 (org-test-with-temp-text
3860 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3861 (org-entry-get (point) "A"))))
3862 ;; Empty values are returned as the empty string.
3865 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3866 (org-entry-get (point) "A"))))
3867 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3868 ;; otherwise, return nil.
3870 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3871 (org-entry-get (point) "A")))
3874 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3875 (org-entry-get (point) "A" nil t
))))
3876 ;; Return nil when no property is found, independently on the
3877 ;; LITERAL-NIL argument.
3879 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3880 (org-entry-get (point) "B")))
3882 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3883 (org-entry-get (point) "B" nil t
)))
3884 ;; Handle inheritance, when allowed. Include extended values and
3885 ;; possibly global values.
3889 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3890 (org-entry-get (point) "A" t
))))
3894 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3895 (let ((org-use-property-inheritance t
))
3896 (org-entry-get (point) "A" 'selective
)))))
3898 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3899 (let ((org-use-property-inheritance nil
))
3900 (org-entry-get (point) "A" 'selective
))))
3904 (org-test-with-temp-text
3905 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3906 (org-entry-get (point-max) "A" t
))))
3909 (org-test-with-temp-text
3910 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3912 (org-entry-get (point-max) "A" t
))))
3915 (org-test-with-temp-text
3916 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3918 (org-entry-get (point-max) "A" t
)))))
3920 (ert-deftest test-org
/entry-properties
()
3921 "Test `org-entry-properties' specifications."
3922 ;; Get "ITEM" property.
3925 (org-test-with-temp-text "* TODO H"
3926 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3929 (org-test-with-temp-text "* TODO H"
3930 (cdr (assoc "ITEM" (org-entry-properties))))))
3931 ;; Get "TODO" property. TODO keywords are case sensitive.
3934 (org-test-with-temp-text "* TODO H"
3935 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3938 (org-test-with-temp-text "* TODO H"
3939 (cdr (assoc "TODO" (org-entry-properties))))))
3941 (org-test-with-temp-text "* H"
3942 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3944 (org-test-with-temp-text "* todo H"
3945 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3946 ;; Get "PRIORITY" property.
3949 (org-test-with-temp-text "* [#A] H"
3950 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3953 (org-test-with-temp-text "* [#A] H"
3954 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3956 (equal (char-to-string org-default-priority
)
3957 (org-test-with-temp-text "* H"
3958 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3959 ;; Get "FILE" property.
3961 (org-test-with-temp-text-in-file "* H\nParagraph"
3962 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3963 (buffer-file-name))))
3965 (org-test-with-temp-text-in-file "* H\nParagraph"
3966 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3967 (buffer-file-name))))
3969 (org-test-with-temp-text "* H\nParagraph"
3970 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3971 ;; Get "TAGS" property.
3973 (equal ":tag1:tag2:"
3974 (org-test-with-temp-text "* H :tag1:tag2:"
3975 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3977 (equal ":tag1:tag2:"
3978 (org-test-with-temp-text "* H :tag1:tag2:"
3979 (cdr (assoc "TAGS" (org-entry-properties))))))
3981 (org-test-with-temp-text "* H"
3982 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3983 ;; Get "ALLTAGS" property.
3985 (equal ":tag1:tag2:"
3986 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3987 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3989 (equal ":tag1:tag2:"
3990 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3991 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3993 (org-test-with-temp-text "* H"
3994 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3995 ;; Get "BLOCKED" property.
3998 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3999 (let ((org-enforce-todo-dependencies t
)
4001 '(org-block-todo-from-children-or-siblings-or-parent)))
4002 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4005 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4006 (let ((org-enforce-todo-dependencies t
)
4008 '(org-block-todo-from-children-or-siblings-or-parent)))
4009 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4010 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4014 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4015 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4019 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4020 (cdr (assoc "CLOSED" (org-entry-properties))))))
4022 (org-test-with-temp-text "* H"
4023 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4027 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4028 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4032 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4033 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4035 (org-test-with-temp-text "* H"
4036 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4040 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4041 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4045 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4046 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4048 (org-test-with-temp-text "* H"
4049 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4053 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4054 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4057 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4058 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4061 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4062 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4065 (org-test-with-temp-text
4066 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4068 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4069 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4070 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4072 (equal "<2012-03-29 thu.>"
4073 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4074 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4076 (equal "[2012-03-29 thu.]"
4077 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4078 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4080 (equal "<2012-03-29 thu.>"
4081 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4082 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4084 (equal "[2014-03-04 tue.]"
4085 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4086 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
4087 ;; Get standard properties.
4090 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4091 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4092 ;; Handle extended properties.
4095 (org-test-with-temp-text
4096 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4097 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4100 (org-test-with-temp-text
4101 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4102 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4103 ;; Ignore forbidden (special) properties.
4105 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4106 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4108 (ert-deftest test-org
/entry-put
()
4109 "Test `org-entry-put' specifications."
4110 ;; Error when not a string or nil.
4112 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4113 (org-entry-put 1 "test" 2)))
4114 ;; Error when property name is invalid.
4116 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4117 (org-entry-put 1 "no space" "value")))
4119 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4120 (org-entry-put 1 "" "value")))
4121 ;; Set "TODO" property.
4123 (string-match (regexp-quote " TODO H")
4124 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4125 (org-entry-put (point) "TODO" "TODO")
4128 (string-match (regexp-quote "* H")
4129 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4130 (org-entry-put (point) "TODO" nil
)
4132 ;; Set "PRIORITY" property.
4135 (org-test-with-temp-text "* [#B] H"
4136 (org-entry-put (point) "PRIORITY" "A")
4140 (org-test-with-temp-text "* [#B] H"
4141 (org-entry-put (point) "PRIORITY" nil
)
4143 ;; Set "SCHEDULED" property.
4145 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4146 (org-test-with-temp-text "* H"
4147 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4151 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4152 (org-entry-put (point) "SCHEDULED" nil
)
4155 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4156 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4157 (org-entry-put (point) "SCHEDULED" "earlier")
4160 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4161 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4162 (org-entry-put (point) "SCHEDULED" "later")
4164 ;; Set "DEADLINE" property.
4166 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4167 (org-test-with-temp-text "* H"
4168 (org-entry-put (point) "DEADLINE" "2014-03-04")
4172 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4173 (org-entry-put (point) "DEADLINE" nil
)
4176 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4177 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4178 (org-entry-put (point) "DEADLINE" "earlier")
4181 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4182 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4183 (org-entry-put (point) "DEADLINE" "later")
4185 ;; Set "CATEGORY" property
4187 (string-match "^ *:CATEGORY: cat"
4188 (org-test-with-temp-text "* H"
4189 (org-entry-put (point) "CATEGORY" "cat")
4191 ;; Regular properties, with or without pre-existing drawer.
4193 (string-match "^ *:A: +2$"
4194 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4195 (org-entry-put (point) "A" "2")
4198 (string-match "^ *:A: +1$"
4199 (org-test-with-temp-text "* H"
4200 (org-entry-put (point) "A" "1")
4202 ;; Special case: two consecutive headlines.
4204 (string-match "\\* A\n *:PROPERTIES:"
4205 (org-test-with-temp-text "* A\n** B"
4206 (org-entry-put (point) "A" "1")
4212 (ert-deftest test-org
/update-radio-target-regexp
()
4213 "Test `org-update-radio-target-regexp' specifications."
4214 ;; Properly update cache with no previous radio target regexp.
4217 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4218 (save-excursion (goto-char (point-max)) (org-element-context))
4220 (search-forward "o")
4222 (org-update-radio-target-regexp)
4223 (goto-char (point-max))
4224 (org-element-type (org-element-context)))))
4225 ;; Properly update cache with previous radio target regexp.
4228 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4229 (save-excursion (goto-char (point-max)) (org-element-context))
4231 (search-forward "o")
4233 (org-update-radio-target-regexp)
4234 (search-backward "r")
4237 (org-update-radio-target-regexp)
4238 (goto-char (point-max))
4239 (delete-region (line-beginning-position) (point))
4241 (org-element-type (org-element-context))))))
4246 (ert-deftest test-org
/match-sparse-tree
()
4247 "Test `org-match-sparse-tree' specifications."
4250 (org-test-with-temp-text "* H\n** H1 :tag:"
4251 (org-match-sparse-tree nil
"tag")
4252 (search-forward "H1")
4253 (org-invisible-p2)))
4255 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4256 (org-match-sparse-tree nil
"tag")
4257 (search-forward "H2")
4258 (org-invisible-p2)))
4259 ;; "-" operator for tags.
4261 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4262 (org-match-sparse-tree nil
"tag1-tag2")
4263 (search-forward "H1")
4264 (org-invisible-p2)))
4266 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4267 (org-match-sparse-tree nil
"tag1-tag2")
4268 (search-forward "H2")
4269 (org-invisible-p2)))
4270 ;; "&" operator for tags.
4272 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4273 (org-match-sparse-tree nil
"tag1&tag2")
4274 (search-forward "H1")
4275 (org-invisible-p2)))
4277 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4278 (org-match-sparse-tree nil
"tag1&tag2")
4279 (search-forward "H2")
4280 (org-invisible-p2)))
4281 ;; "|" operator for tags.
4283 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4284 (org-match-sparse-tree nil
"tag1|tag2")
4285 (search-forward "H1")
4286 (org-invisible-p2)))
4288 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4289 (org-match-sparse-tree nil
"tag1|tag2")
4290 (search-forward "H2")
4291 (org-invisible-p2)))
4292 ;; Regexp match on tags.
4294 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4295 (org-match-sparse-tree nil
"{^tag.*}")
4296 (search-forward "H1")
4297 (org-invisible-p2)))
4299 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4300 (org-match-sparse-tree nil
"{^tag.*}")
4301 (search-forward "H2")
4302 (org-invisible-p2)))
4303 ;; Match group tags.
4305 (org-test-with-temp-text
4306 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4307 (org-match-sparse-tree nil
"work")
4308 (search-forward "H1")
4309 (org-invisible-p2)))
4311 (org-test-with-temp-text
4312 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4313 (org-match-sparse-tree nil
"work")
4314 (search-forward "H2")
4315 (org-invisible-p2)))
4316 ;; Match group tags with hard brackets.
4318 (org-test-with-temp-text
4319 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4320 (org-match-sparse-tree nil
"work")
4321 (search-forward "H1")
4322 (org-invisible-p2)))
4324 (org-test-with-temp-text
4325 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4326 (org-match-sparse-tree nil
"work")
4327 (search-forward "H2")
4328 (org-invisible-p2)))
4329 ;; Match tags in hierarchies
4331 (org-test-with-temp-text
4332 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4333 #+TAGS: [ Lev_2 : Lev_3 ]\n
4334 #+TAGS: { Lev_3 : Lev_4 }\n
4335 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4336 (org-match-sparse-tree nil
"Lev_1")
4337 (search-forward "H4")
4338 (org-invisible-p2)))
4339 ;; Match regular expressions in tags
4341 (org-test-with-temp-text
4342 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4343 (org-match-sparse-tree nil
"Lev")
4344 (search-forward "H1")
4345 (org-invisible-p2)))
4347 (org-test-with-temp-text
4348 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4349 (org-match-sparse-tree nil
"Lev")
4350 (search-forward "H1")
4351 (org-invisible-p2)))
4352 ;; Match properties.
4354 (org-test-with-temp-text
4355 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4356 (org-match-sparse-tree nil
"A=\"1\"")
4357 (search-forward "H2")
4358 (org-invisible-p2)))
4360 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4361 (org-match-sparse-tree nil
"A=\"1\"")
4362 (search-forward "H2")
4363 (org-invisible-p2)))
4364 ;; Case is not significant when matching properties.
4366 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4367 (org-match-sparse-tree nil
"a=\"1\"")
4368 (search-forward "H2")
4369 (org-invisible-p2)))
4371 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4372 (org-match-sparse-tree nil
"A=\"1\"")
4373 (search-forward "H2")
4374 (org-invisible-p2)))
4375 ;; Match special LEVEL property.
4377 (org-test-with-temp-text "* H\n** H1\n*** H2"
4378 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4379 (search-forward "H1")
4380 (org-invisible-p2)))
4382 (org-test-with-temp-text "* H\n** H1\n*** H2"
4383 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4384 (search-forward "H2")
4385 (org-invisible-p2)))
4386 ;; Comparison operators when matching properties.
4388 (org-test-with-temp-text
4389 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4390 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4391 (search-forward "H1")
4392 (org-invisible-p2)))
4394 (org-test-with-temp-text
4395 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4396 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4397 (search-forward "H2")
4398 (org-invisible-p2)))
4399 ;; Regexp match on properties values.
4401 (org-test-with-temp-text
4402 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4403 (org-match-sparse-tree nil
"A={f.*}")
4404 (search-forward "H1")
4405 (org-invisible-p2)))
4407 (org-test-with-temp-text
4408 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4409 (org-match-sparse-tree nil
"A={f.*}")
4410 (search-forward "H2")
4411 (org-invisible-p2)))
4412 ;; With an optional argument, limit match to TODO entries.
4414 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4415 (org-match-sparse-tree t
"tag")
4416 (search-forward "H1")
4417 (org-invisible-p2)))
4419 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4420 (org-match-sparse-tree t
"tag")
4421 (search-forward "H2")
4422 (org-invisible-p2))))
4424 (ert-deftest test-org
/occur
()
4425 "Test `org-occur' specifications."
4426 ;; Count number of matches.
4429 (org-test-with-temp-text "* H\nA\n* H2"
4433 (org-test-with-temp-text "* H\nA\n* H2\nA"
4435 ;; Test CALLBACK optional argument.
4438 (org-test-with-temp-text "* H\nA\n* H2"
4439 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4442 (org-test-with-temp-text "* H\nA\n* H2\nA"
4443 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4444 ;; Case-fold searches according to `org-occur-case-fold-search'.
4447 (org-test-with-temp-text "Aa"
4448 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
4451 (org-test-with-temp-text "Aa"
4452 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
4455 (org-test-with-temp-text "Aa"
4456 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
4459 (org-test-with-temp-text "Aa"
4460 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
4463 (org-test-with-temp-text "Aa"
4464 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
4467 (org-test-with-temp-text "Aa"
4468 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
4473 (ert-deftest test-org
/tag-string-to-alist
()
4474 "Test `org-tag-string-to-alist' specifications."
4475 ;; Tag without selection key.
4476 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
4477 ;; Tag with selection key.
4478 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
4482 (org-tag-string-to-alist "[ group : t1 t2 ]")
4483 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
4484 ;; Mutually exclusive tags.
4485 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
4486 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
4489 (org-tag-string-to-alist "{ group : tag1 tag2 }")
4490 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
4492 (ert-deftest test-org
/tag-alist-to-string
()
4493 "Test `org-tag-alist-to-string' specifications."
4494 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
4495 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
4498 (org-tag-alist-to-string
4499 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4500 "[ group : t1 t2 ]"))
4502 (equal (org-tag-alist-to-string
4503 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
4507 (org-tag-alist-to-string
4508 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
4509 "{ group : tag1 tag2 }")))
4511 (ert-deftest test-org
/tag-alist-to-groups
()
4512 "Test `org-tag-alist-to-groups' specifications."
4514 (equal (org-tag-alist-to-groups
4515 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
4516 '(("group" "t1" "t2"))))
4519 (org-tag-alist-to-groups
4520 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4521 '(("group" "t1" "t2"))))
4523 (org-tag-alist-to-groups
4524 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
4526 (ert-deftest test-org
/tag-align
()
4527 "Test `org-align-tags-here' with different display width."
4529 ;; 12345678901234567890
4530 (equal "* Test :abc:"
4531 (org-test-with-temp-text "* Test :abc:"
4532 (let ((org-tags-column -
20)
4533 (indent-tabs-mode nil
))
4534 (org-fix-tags-on-the-fly))
4537 ;; 12345678901234567890
4538 (equal "* Test :日本語:"
4539 (org-test-with-temp-text "* Test :日本語:"
4540 (let ((org-tags-column -
20)
4541 (indent-tabs-mode nil
))
4542 (org-fix-tags-on-the-fly))
4545 (ert-deftest test-org
/tags-at
()
4547 (equal '("foo" "bar")
4548 (org-test-with-temp-text
4549 "* T<point>est :foo:bar:"
4550 (org-get-tags-at)))))
4555 (ert-deftest test-org
/time-stamp
()
4556 "Test `org-time-stamp' specifications."
4557 ;; Insert chosen time stamp at point.
4560 "Te<2014-03-04 .*?>xt"
4561 (org-test-with-temp-text "Te<point>xt"
4562 (cl-letf (((symbol-function 'org-read-date
)
4563 (lambda (&rest args
)
4564 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4565 (org-time-stamp nil
)
4567 ;; With a prefix argument, also insert time.
4570 "Te<2014-03-04 .*? 00:41>xt"
4571 (org-test-with-temp-text "Te<point>xt"
4572 (cl-letf (((symbol-function 'org-read-date
)
4573 (lambda (&rest args
)
4574 (apply #'encode-time
4575 (org-parse-time-string "2014-03-04 00:41")))))
4576 (org-time-stamp '(4))
4578 ;; With two universal prefix arguments, insert an active timestamp
4579 ;; with the current time without prompting the user.
4582 "Te<2014-03-04 .*? 00:41>xt"
4583 (org-test-with-temp-text "Te<point>xt"
4584 (cl-letf (((symbol-function 'current-time
)
4586 (apply #'encode-time
4587 (org-parse-time-string "2014-03-04 00:41")))))
4588 (org-time-stamp '(16))
4590 ;; When optional argument is non-nil, insert an inactive timestamp.
4593 "Te\\[2014-03-04 .*?\\]xt"
4594 (org-test-with-temp-text "Te<point>xt"
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 t
)
4600 ;; When called from a timestamp, replace existing one.
4604 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4605 (cl-letf (((symbol-function 'org-read-date
)
4606 (lambda (&rest args
)
4607 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4608 (org-time-stamp nil
)
4612 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4613 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4614 (cl-letf (((symbol-function 'org-read-date
)
4615 (lambda (&rest args
)
4616 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4617 (org-time-stamp nil
)
4619 ;; When replacing a timestamp, preserve repeater, if any.
4622 "<2014-03-04 .*? \\+2y>"
4623 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4624 (cl-letf (((symbol-function 'org-read-date
)
4625 (lambda (&rest args
)
4626 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4627 (org-time-stamp nil
)
4629 ;; When called twice in a raw, build a date range.
4632 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4633 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4634 (cl-letf (((symbol-function 'org-read-date
)
4635 (lambda (&rest args
)
4636 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4637 (let ((last-command 'org-time-stamp
)
4638 (this-command 'org-time-stamp
))
4639 (org-time-stamp nil
))
4640 (buffer-string))))))
4642 (ert-deftest test-org
/timestamp-has-time-p
()
4643 "Test `org-timestamp-has-time-p' specifications."
4646 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4647 (org-timestamp-has-time-p (org-element-context))))
4650 (org-test-with-temp-text "<2012-03-29 Thu>"
4651 (org-timestamp-has-time-p (org-element-context)))))
4653 (ert-deftest test-org
/timestamp-format
()
4654 "Test `org-timestamp-format' specifications."
4659 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4660 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4665 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4666 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4668 (ert-deftest test-org
/timestamp-split-range
()
4669 "Test `org-timestamp-split-range' specifications."
4670 ;; Extract range start (active).
4673 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4674 (let ((ts (org-timestamp-split-range (org-element-context))))
4675 (mapcar (lambda (p) (org-element-property p ts
))
4676 '(:year-end
:month-end
:day-end
))))))
4677 ;; Extract range start (inactive)
4680 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4681 (let ((ts (org-timestamp-split-range (org-element-context))))
4682 (mapcar (lambda (p) (org-element-property p ts
))
4683 '(:year-end
:month-end
:day-end
))))))
4684 ;; Extract range end (active).
4687 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4688 (let ((ts (org-timestamp-split-range
4689 (org-element-context) t
)))
4690 (mapcar (lambda (p) (org-element-property p ts
))
4691 '(:year-end
:month-end
:day-end
))))))
4692 ;; Extract range end (inactive)
4695 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4696 (let ((ts (org-timestamp-split-range
4697 (org-element-context) t
)))
4698 (mapcar (lambda (p) (org-element-property p ts
))
4699 '(:year-end
:month-end
:day-end
))))))
4700 ;; Return the timestamp if not a range.
4702 (org-test-with-temp-text "[2012-03-29 Thu]"
4703 (let* ((ts-orig (org-element-context))
4704 (ts-copy (org-timestamp-split-range ts-orig
)))
4705 (eq ts-orig ts-copy
))))
4707 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4708 (let* ((ts-orig (org-element-context))
4709 (ts-copy (org-timestamp-split-range ts-orig
)))
4710 (eq ts-orig ts-copy
)))))
4712 (ert-deftest test-org
/timestamp-translate
()
4713 "Test `org-timestamp-translate' specifications."
4714 ;; Translate whole date range.
4717 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4718 (let ((org-display-custom-times t
)
4719 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4720 (org-timestamp-translate (org-element-context))))))
4721 ;; Translate date range start.
4724 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4725 (let ((org-display-custom-times t
)
4726 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4727 (org-timestamp-translate (org-element-context) 'start
)))))
4728 ;; Translate date range end.
4731 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4732 (let ((org-display-custom-times t
)
4733 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4734 (org-timestamp-translate (org-element-context) 'end
)))))
4735 ;; Translate time range.
4738 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4739 (let ((org-display-custom-times t
)
4740 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4741 (org-timestamp-translate (org-element-context))))))
4742 ;; Translate non-range timestamp.
4745 (org-test-with-temp-text "<2012-03-29 Thu>"
4746 (let ((org-display-custom-times t
)
4747 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4748 (org-timestamp-translate (org-element-context))))))
4749 ;; Do not change `diary' timestamps.
4751 (equal "<%%(org-float t 4 2)>"
4752 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4753 (let ((org-display-custom-times t
)
4754 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4755 (org-timestamp-translate (org-element-context)))))))
4761 (ert-deftest test-org
/flag-drawer
()
4762 "Test `org-flag-drawer' specifications."
4765 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4767 (get-char-property (line-end-position) 'invisible
)))
4770 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4772 (org-flag-drawer nil
)
4773 (get-char-property (line-end-position) 'invisible
)))
4774 ;; Test optional argument.
4776 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4777 (let ((drawer (save-excursion (search-forward ":D2")
4778 (org-element-at-point))))
4779 (org-flag-drawer t drawer
)
4780 (get-char-property (progn (search-forward ":D2") (line-end-position))
4783 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4784 (let ((drawer (save-excursion (search-forward ":D2")
4785 (org-element-at-point))))
4786 (org-flag-drawer t drawer
)
4787 (get-char-property (line-end-position) 'invisible
))))
4788 ;; Do not hide fake drawers.
4790 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4793 (get-char-property (line-end-position) 'invisible
)))
4794 ;; Do not hide incomplete drawers.
4796 (org-test-with-temp-text ":D:\nparagraph"
4799 (get-char-property (line-end-position) 'invisible
)))
4800 ;; Do not hide drawers when called from final blank lines.
4802 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4803 (goto-char (point-max))
4805 (goto-char (point-min))
4806 (get-char-property (line-end-position) 'invisible
)))
4807 ;; Don't leave point in an invisible part of the buffer when hiding
4810 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4811 (goto-char (point-max))
4813 (get-char-property (point) 'invisible
))))
4815 (ert-deftest test-org
/hide-block-toggle
()
4816 "Test `org-hide-block-toggle' specifications."
4817 ;; Error when not at a block.
4819 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4820 (org-hide-block-toggle 'off
)
4821 (get-char-property (line-end-position) 'invisible
)))
4824 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4825 (org-hide-block-toggle)
4826 (get-char-property (line-end-position) 'invisible
)))
4828 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4829 (org-hide-block-toggle)
4830 (get-char-property (line-end-position) 'invisible
)))
4831 ;; Show block unconditionally when optional argument is `off'.
4833 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4834 (org-hide-block-toggle)
4835 (org-hide-block-toggle 'off
)
4836 (get-char-property (line-end-position) 'invisible
)))
4838 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4839 (org-hide-block-toggle 'off
)
4840 (get-char-property (line-end-position) 'invisible
)))
4841 ;; Hide block unconditionally when optional argument is non-nil.
4843 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4844 (org-hide-block-toggle t
)
4845 (get-char-property (line-end-position) 'invisible
)))
4847 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4848 (org-hide-block-toggle)
4849 (org-hide-block-toggle t
)
4850 (get-char-property (line-end-position) 'invisible
)))
4851 ;; Do not hide block when called from final blank lines.
4853 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4854 (org-hide-block-toggle)
4855 (goto-char (point-min))
4856 (get-char-property (line-end-position) 'invisible
)))
4857 ;; Don't leave point in an invisible part of the buffer when hiding
4860 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4861 (org-hide-block-toggle)
4862 (get-char-property (point) 'invisible
))))
4864 (ert-deftest test-org
/hide-block-toggle-maybe
()
4865 "Test `org-hide-block-toggle-maybe' specifications."
4867 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4868 (org-hide-block-toggle-maybe)))
4870 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4872 (ert-deftest test-org
/show-set-visibility
()
4873 "Test `org-show-set-visibility' specifications."
4874 ;; Do not throw an error before first heading.
4876 (org-test-with-temp-text "Preamble\n* Headline"
4877 (org-show-set-visibility 'tree
)
4879 ;; Test all visibility spans, both on headline and in entry.
4880 (let ((list-visible-lines
4881 (lambda (state headerp
)
4882 (org-test-with-temp-text "* Grandmother (0)
4893 **** The other child (11)
4898 (search-forward (if headerp
"Self" "Match"))
4899 (org-show-set-visibility state
)
4900 (goto-char (point-min))
4901 (let (result (line 0))
4903 (unless (org-invisible-p2) (push line result
))
4906 (nreverse result
))))))
4907 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4908 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4909 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4910 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4911 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4912 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4913 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4914 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4915 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4916 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4917 (funcall list-visible-lines
'tree nil
)))
4918 (should (equal '(0 1 3 4 5 7 12 13)
4919 (funcall list-visible-lines
'canonical t
)))
4920 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4921 (funcall list-visible-lines
'canonical nil
))))
4922 ;; When point is hidden in a drawer or a block, make sure to make it
4925 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
4926 (org-hide-block-toggle)
4927 (search-forward "Text")
4928 (org-show-set-visibility 'minimal
)
4929 (org-invisible-p2)))
4931 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
4933 (search-forward "Text")
4934 (org-show-set-visibility 'minimal
)
4935 (org-invisible-p2)))
4937 (org-test-with-temp-text
4938 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
4941 (org-hide-block-toggle)
4942 (search-forward "Text")
4943 (org-show-set-visibility 'minimal
)
4944 (org-invisible-p2))))
4949 ;;; test-org.el ends here