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-mode 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 (flet ((current-time () (apply #'encode-time
201 (org-parse-time-string "2014-03-04"))))
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (flet ((current-time () (apply #'encode-time
209 (org-parse-time-string "2014-03-04"))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (flet ((current-time () (apply #'encode-time
220 (org-parse-time-string "2014-03-04"))))
221 (let ((org-read-date-prefer-future t
))
222 (org-read-date t nil
"1")))))
226 (flet ((current-time () (apply #'encode-time
227 (org-parse-time-string "2012-03-29"))))
228 (let ((org-read-date-prefer-future t
))
229 (org-read-date t nil
"3-4")))))
233 (flet ((current-time () (apply #'encode-time
234 (org-parse-time-string "2012-03-29"))))
235 (let ((org-read-date-prefer-future nil
))
236 (org-read-date t nil
"3-4")))))
237 ;; When set to `org-read-date-prefer-future' is set to `time', read
238 ;; day is moved to tomorrow if specified hour is before current
239 ;; time. However, it only happens in no other part of the date is
244 (flet ((current-time () (apply #'encode-time
245 (org-parse-time-string "2012-03-29 16:40"))))
246 (let ((org-read-date-prefer-future 'time
))
247 (org-read-date t nil
"00:40" nil
)))))
251 (flet ((current-time () (apply #'encode-time
252 (org-parse-time-string "2012-03-29 16:40"))))
253 (let ((org-read-date-prefer-future 'time
))
254 (org-read-date t nil
"29 00:40" nil
)))))
255 ;; Caveat: `org-read-date-prefer-future' always refers to current
256 ;; time, not default time, when they differ.
261 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
262 (let ((org-read-date-prefer-future t
))
265 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
270 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
271 (let ((org-read-date-prefer-future t
))
274 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
276 (ert-deftest test-org
/org-parse-time-string
()
277 "Test `org-parse-time-string'."
278 (should (equal (org-parse-time-string "2012-03-29 16:40")
279 '(0 40 16 29 3 2012 nil nil nil
)))
280 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
281 '(0 40 16 29 3 2012 nil nil nil
)))
282 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
283 '(0 40 16 29 3 2012 nil nil nil
)))
284 (should (equal (org-parse-time-string "<2012-03-29>")
285 '(0 0 0 29 3 2012 nil nil nil
)))
286 (should (equal (org-parse-time-string "<2012-03-29>" t
)
287 '(0 nil nil
29 3 2012 nil nil nil
))))
292 (ert-deftest test-org
/insert-property-drawer
()
293 "Test `org-insert-property-drawer' specifications."
294 ;; Error before first headline.
295 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
296 ;; Insert drawer right after headline if there is no planning line,
297 ;; or after it otherwise.
299 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
300 (org-test-with-temp-text "* H\nParagraph<point>"
301 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
304 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
305 (org-test-with-temp-text
306 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
307 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
309 ;; Indent inserted drawer.
311 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
312 (org-test-with-temp-text "* H\nParagraph<point>"
313 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
315 ;; Handle insertion at eob.
317 (equal "* H\n:PROPERTIES:\n:END:\n"
318 (org-test-with-temp-text "* H"
319 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
321 ;; Skip inlinetasks before point.
322 (when (featurep 'org-inlinetask
)
324 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
325 (org-test-with-temp-text
326 "* H\n*************** I\n*************** END\nP<point>"
327 (let ((org-adapt-indentation nil
)
328 (org-inlinetask-min-level 15))
329 (org-insert-property-drawer))
331 ;; Correctly set drawer in an inlinetask.
332 (when (featurep 'org-inlinetask
)
334 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
335 (org-test-with-temp-text
336 "* H\n*************** I\nP<point>\n*************** END"
337 (let ((org-adapt-indentation nil
)
338 (org-inlinetask-min-level 15))
339 (org-insert-property-drawer))
345 (ert-deftest test-org
/fill-paragraph
()
346 "Test `org-fill-paragraph' specifications."
347 ;; At an Org table, align it.
350 (org-test-with-temp-text "|a|"
354 (equal "#+name: table\n| a |\n"
355 (org-test-with-temp-text "#+name: table\n| a |"
358 ;; At a paragraph, preserve line breaks.
359 (org-test-with-temp-text "some \\\\\nlong\ntext"
360 (let ((fill-column 20))
362 (should (equal (buffer-string) "some \\\\\nlong text"))))
363 ;; Correctly fill a paragraph when point is at its very end.
366 (org-test-with-temp-text "A\nB"
367 (let ((fill-column 20))
368 (goto-char (point-max))
371 ;; Correctly fill the last paragraph of a greater element.
373 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
374 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
375 (let ((fill-column 8))
380 ;; Correctly fill an element in a narrowed buffer.
383 (org-test-with-temp-text "01234 6789"
384 (let ((fill-column 5))
385 (narrow-to-region 1 8)
388 ;; Handle `adaptive-fill-regexp' in paragraphs.
391 (org-test-with-temp-text "> a\n> b"
392 (let ((fill-column 5)
393 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
396 ;; Special case: Fill first paragraph when point is at an item or
397 ;; a plain-list or a footnote reference.
400 (org-test-with-temp-text "- A\n B"
401 (let ((fill-column 20))
406 (org-test-with-temp-text "[fn:1] A\nB"
407 (let ((fill-column 20))
410 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
411 (let ((fill-column 20))
413 (should (equal (buffer-string)
414 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
415 ;; Fill contents of `comment-block' elements.
418 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
419 (let ((fill-column 20))
423 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
424 ;; Fill `comment' elements.
427 (org-test-with-temp-text " # A\n # B"
428 (let ((fill-column 20))
431 ;; Do not mix consecutive comments when filling one of them.
433 (equal "# A B\n\n# C"
434 (org-test-with-temp-text "# A\n# B\n\n# C"
435 (let ((fill-column 20))
438 ;; Use commented empty lines as separators when filling comments.
440 (equal "# A B\n#\n# C"
441 (org-test-with-temp-text "# A\n# B\n#\n# C"
442 (let ((fill-column 20))
445 ;; Handle `adaptive-fill-regexp' in comments.
448 (org-test-with-temp-text "# > a\n# > b"
449 (let ((fill-column 20)
450 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
453 ;; Do nothing at affiliated keywords.
454 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
455 (let ((fill-column 20))
457 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
458 ;; Do not move point after table when filling a table.
460 (org-test-with-temp-text "| a | b |\n| c | d |\n"
465 (ert-deftest test-org
/auto-fill-function
()
466 "Test auto-filling features."
467 ;; Auto fill paragraph.
470 (org-test-with-temp-text "12345 7890"
471 (let ((fill-column 5))
473 (org-auto-fill-function)
475 ;; Auto fill first paragraph in an item.
477 (equal "- 12345\n 7890"
478 (org-test-with-temp-text "- 12345 7890"
479 (let ((fill-column 7))
481 (org-auto-fill-function)
483 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
485 (equal "> 12345\n 7890"
486 (org-test-with-temp-text "> 12345 7890"
487 (let ((fill-column 10)
488 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
489 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
491 (org-auto-fill-function)
494 (equal "> 12345\n> 12345\n> 7890"
495 (org-test-with-temp-text "> 12345\n> 12345 7890"
496 (let ((fill-column 10)
497 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
498 (goto-char (point-max))
499 (org-auto-fill-function)
502 (equal " 12345\n *12345\n *12345"
503 (org-test-with-temp-text " 12345\n *12345 12345"
504 (let ((fill-column 10)
505 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
506 (goto-char (point-max))
507 (org-auto-fill-function)
509 ;; Auto fill comments.
511 (equal " # 12345\n # 7890"
512 (org-test-with-temp-text " # 12345 7890"
513 (let ((fill-column 10))
515 (org-auto-fill-function)
517 ;; A hash within a line isn't a comment.
519 (equal "12345 # 7890\n# 1"
520 (org-test-with-temp-text "12345 # 7890 1"
521 (let ((fill-column 12))
523 (org-auto-fill-function)
525 ;; Correctly interpret empty prefix.
527 (equal "# a\n# b\nRegular\n# paragraph"
528 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
529 (let ((fill-column 12))
531 (org-auto-fill-function)
533 ;; Comment block: auto fill contents.
535 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
536 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
537 (let ((fill-column 5))
540 (org-auto-fill-function)
543 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
544 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
545 (let ((fill-column 5))
548 (org-auto-fill-function)
550 ;; Do not fill if a new item could be created.
553 (org-test-with-temp-text "12345 - 90"
554 (let ((fill-column 5))
556 (org-auto-fill-function)
558 ;; Do not fill if a line break could be introduced.
560 (equal "123\\\\\n7890"
561 (org-test-with-temp-text "123\\\\ 7890"
562 (let ((fill-column 6))
564 (org-auto-fill-function)
566 ;; Do not fill affiliated keywords.
568 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
569 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
570 (let ((fill-column 20))
572 (org-auto-fill-function)
579 (ert-deftest test-org
/indent-line
()
580 "Test `org-indent-line' specifications."
581 ;; Do not indent footnote definitions or headlines.
584 (org-test-with-temp-text "* H"
586 (org-get-indentation))))
589 (org-test-with-temp-text "[fn:1] fn"
590 (let ((org-adapt-indentation t
)) (org-indent-line))
591 (org-get-indentation))))
592 ;; Do not indent before first headline.
595 (org-test-with-temp-text ""
597 (org-get-indentation))))
598 ;; Indent according to headline level otherwise, unless
599 ;; `org-adapt-indentation' is nil.
602 (org-test-with-temp-text "* H\nA"
604 (let ((org-adapt-indentation t
)) (org-indent-line))
605 (org-get-indentation))))
608 (org-test-with-temp-text "* H\n\nA"
610 (let ((org-adapt-indentation t
)) (org-indent-line))
611 (org-get-indentation))))
614 (org-test-with-temp-text "* H\nA"
616 (let ((org-adapt-indentation nil
)) (org-indent-line))
617 (org-get-indentation))))
618 ;; Indenting preserves point position.
620 (org-test-with-temp-text "* H\nAB"
623 (let ((org-adapt-indentation t
)) (org-indent-line))
625 ;; Do not change indentation at an item.
628 (org-test-with-temp-text "* H\n - A"
630 (let ((org-adapt-indentation t
)) (org-indent-line))
631 (org-get-indentation))))
632 ;; On blank lines at the end of a list, indent like last element
633 ;; within it if the line is still in the list. Otherwise, indent
634 ;; like the whole list.
637 (org-test-with-temp-text "* H\n- A\n - AA\n"
638 (goto-char (point-max))
639 (let ((org-adapt-indentation t
)) (org-indent-line))
640 (org-get-indentation))))
643 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
644 (goto-char (point-max))
645 (let ((org-adapt-indentation t
)) (org-indent-line))
646 (org-get-indentation))))
647 ;; Likewise, on a blank line at the end of a footnote definition,
648 ;; indent at column 0 if line belongs to the definition. Otherwise,
649 ;; indent like the definition itself.
652 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
653 (goto-char (point-max))
654 (let ((org-adapt-indentation t
)) (org-indent-line))
655 (org-get-indentation))))
658 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
659 (goto-char (point-max))
660 (let ((org-adapt-indentation t
)) (org-indent-line))
661 (org-get-indentation))))
662 ;; After the end of the contents of a greater element, indent like
663 ;; the beginning of the element.
666 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
669 (org-get-indentation))))
670 ;; On blank lines after a paragraph, indent like its last non-empty
674 (org-test-with-temp-text " Paragraph\n\n<point>"
676 (org-get-indentation))))
677 ;; At the first line of an element, indent like previous element's
678 ;; first line, ignoring footnotes definitions and inline tasks, or
679 ;; according to parent.
682 (org-test-with-temp-text "A\n\n B\n\nC"
683 (goto-char (point-max))
685 (org-get-indentation))))
688 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
689 (goto-char (point-max))
691 (org-get-indentation))))
694 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
697 (org-get-indentation))))
698 ;; Within code part of a source block, use language major mode if
699 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
700 ;; according to line above.
703 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
705 (let ((org-src-tab-acts-natively t
)
706 (org-edit-src-content-indentation 0))
708 (org-get-indentation))))
711 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
713 (let ((org-src-tab-acts-natively nil
)
714 (org-edit-src-content-indentation 0))
716 (org-get-indentation))))
717 ;; Otherwise, indent like the first non-blank line above.
720 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
723 (org-get-indentation))))
724 ;; Align node properties according to `org-property-format'. Handle
725 ;; nicely empty values.
727 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
728 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
729 (let ((org-property-format "%-10s %s")) (org-indent-line))
732 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
733 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
734 (let ((org-property-format "%-10s %s")) (org-indent-line))
737 (ert-deftest test-org
/indent-region
()
738 "Test `org-indent-region' specifications."
742 (org-test-with-temp-text " A\nB\n C"
743 (org-indent-region (point-min) (point-max))
745 ;; Indent greater elements along with their contents.
747 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
748 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
749 (org-indent-region (point-min) (point-max))
751 ;; Ignore contents of verse blocks and example blocks.
753 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
754 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
755 (org-indent-region (point-min) (point-max))
758 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
759 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
760 (org-indent-region (point-min) (point-max))
762 ;; Indent according to mode if `org-src-tab-acts-natively' is
763 ;; non-nil. Otherwise, do not indent code at all.
765 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
766 (org-test-with-temp-text
767 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
768 (let ((org-src-tab-acts-natively t
)
769 (org-edit-src-content-indentation 0))
770 (org-indent-region (point-min) (point-max)))
773 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
774 (org-test-with-temp-text
775 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
776 (let ((org-src-tab-acts-natively nil
)
777 (org-edit-src-content-indentation 0))
778 (org-indent-region (point-min) (point-max)))
780 ;; Align node properties according to `org-property-format'. Handle
781 ;; nicely empty values.
783 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
784 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
785 (let ((org-property-format "%-10s %s")
786 (org-adapt-indentation nil
))
787 (org-indent-region (point) (point-max)))
790 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
791 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
792 (let ((org-property-format "%-10s %s")
793 (org-adapt-indentation nil
))
794 (org-indent-region (point) (point-max)))
796 ;; Indent plain lists.
798 (equal "- A\n B\n - C\n\n D"
799 (org-test-with-temp-text "- A\n B\n - C\n\n D"
800 (org-indent-region (point-min) (point-max))
804 (org-test-with-temp-text " - A\n\n - B"
805 (org-indent-region (point-min) (point-max))
807 ;; Indent footnote definitions.
809 (equal "[fn:1] Definition\n\nDefinition"
810 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
811 (org-indent-region (point-min) (point-max))
813 ;; Special case: Start indenting on a blank line.
816 (org-test-with-temp-text "\n Paragraph"
817 (org-indent-region (point-min) (point-max))
824 (ert-deftest test-org
/return
()
825 "Test RET (`org-return') specifications."
829 (org-test-with-temp-text "Para<point>graph"
832 ;; With optional argument, indent line.
834 (equal " Para\n graph"
835 (org-test-with-temp-text " Para<point>graph"
838 ;; On a table, call `org-table-next-row'.
840 (org-test-with-temp-text "| <point>a |\n| b |"
842 (org-looking-at-p "b")))
843 ;; Open link or timestamp under point when `org-return-follows-link'
846 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
847 (let ((org-return-follows-link t
)) (org-return))
848 (org-looking-at-p "<<target>>")))
850 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
851 (let ((org-return-follows-link nil
)) (org-return))
852 (org-looking-at-p "<<target>>")))
853 ;; However, do not open link when point is in a table.
855 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
856 (let ((org-return-follows-link t
)) (org-return))
857 (org-looking-at-p "between")))
858 ;; Special case: in a list, when indenting, do not break structure.
861 (org-test-with-temp-text "- A <point>B"
866 (org-test-with-temp-text "- A\n<point>- B"
869 ;; Special case: on tags part of a headline, add a newline below it
870 ;; instead of breaking it.
873 (org-test-with-temp-text "* H :<point>tag:"
877 (ert-deftest test-org
/meta-return
()
878 "Test M-RET (`org-meta-return') specifications."
879 ;; In a table field insert a row above.
881 (org-test-with-temp-text "| a |"
885 (looking-at "| |$")))
886 ;; In a paragraph change current line into a header.
888 (org-test-with-temp-text "a"
891 (looking-at "\* a$")))
892 ;; In an item insert an item, in this case above.
894 (org-test-with-temp-text "- a"
898 ;; In a drawer and item insert an item, in this case above.
900 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
904 (looking-at "- $"))))
906 (ert-deftest test-org
/insert-heading
()
907 "Test `org-insert-heading' specifications."
908 ;; In an empty buffer, insert a new headline.
911 (org-test-with-temp-text ""
914 ;; At the beginning of a line, turn it into a headline
917 (org-test-with-temp-text "<point>P"
920 ;; In the middle of a line, split the line if allowed, otherwise,
921 ;; insert the headline at its end.
923 (equal "Para\n* graph"
924 (org-test-with-temp-text "Para<point>graph"
925 (let ((org-M-RET-may-split-line '((default . t
))))
926 (org-insert-heading))
929 (equal "Paragraph\n* "
930 (org-test-with-temp-text "Para<point>graph"
931 (let ((org-M-RET-may-split-line '((default . nil
))))
932 (org-insert-heading))
934 ;; When on a list, insert an item instead, unless called with an
935 ;; universal argument or if list is invisible. In this case, create
936 ;; a new headline after contents.
938 (equal "* H\n- item\n- "
939 (org-test-with-temp-text "* H\n- item<point>"
940 (let ((org-insert-heading-respect-content nil
))
941 (org-insert-heading))
944 (equal "* H\n- item\n- item 2\n* "
945 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
946 (let ((org-insert-heading-respect-content nil
))
947 (org-insert-heading '(4)))
950 (equal "* H\n- item\n* "
951 (org-test-with-temp-text "* H\n- item"
953 (goto-char (point-max))
954 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
956 ;; When called with two universal arguments, insert a new headline
957 ;; at the end of the grandparent subtree.
959 (equal "* H1\n** H3\n- item\n** H2\n** "
960 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
961 (let ((org-insert-heading-respect-content nil
))
962 (org-insert-heading '(16)))
964 ;; When optional TOP-LEVEL argument is non-nil, always insert
965 ;; a level 1 heading.
967 (equal "* H1\n** H2\n* "
968 (org-test-with-temp-text "* H1\n** H2<point>"
969 (org-insert-heading nil nil t
)
972 (equal "* H1\n- item\n* "
973 (org-test-with-temp-text "* H1\n- item<point>"
974 (org-insert-heading nil nil t
)
976 ;; Corner case: correctly insert a headline after an empty one.
979 (org-test-with-temp-text "* <point>"
983 (ert-deftest test-org
/insert-todo-heading-respect-content
()
984 "Test `org-insert-todo-heading-respect-content' specifications."
985 ;; Create a TODO heading.
987 (org-test-with-temp-text "* H1\n Body"
988 (org-insert-todo-heading-respect-content)
989 (nth 2 (org-heading-components))))
990 ;; Add headline at the end of the first subtree
992 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
993 (search-forward "H1Body")
994 (org-insert-todo-heading-respect-content)
995 (and (eobp) (org-at-heading-p))))
996 ;; In a list, do not create a new item.
998 (org-test-with-temp-text "* H\n- an item\n- another one"
999 (search-forward "an ")
1000 (org-insert-todo-heading-respect-content)
1001 (and (eobp) (org-at-heading-p)))))
1005 ;;; Fixed-Width Areas
1007 (ert-deftest test-org
/toggle-fixed-width
()
1008 "Test `org-toggle-fixed-width' specifications."
1009 ;; No region: Toggle on fixed-width marker in paragraphs.
1012 (org-test-with-temp-text "A"
1013 (org-toggle-fixed-width)
1015 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1018 (org-test-with-temp-text ": A"
1019 (org-toggle-fixed-width)
1021 ;; No region: Toggle on marker in blank lines after elements or just
1022 ;; after a headline.
1025 (org-test-with-temp-text "* H\n"
1027 (org-toggle-fixed-width)
1030 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1031 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1032 (goto-char (point-max))
1033 (org-toggle-fixed-width)
1035 ;; No region: Toggle on marker in front of one line elements (e.g.,
1036 ;; headlines, clocks)
1038 (equal ": * Headline"
1039 (org-test-with-temp-text "* Headline"
1040 (org-toggle-fixed-width)
1043 (equal ": #+KEYWORD: value"
1044 (org-test-with-temp-text "#+KEYWORD: value"
1045 (org-toggle-fixed-width)
1047 ;; No region: error in other situations.
1049 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1051 (org-toggle-fixed-width)
1053 ;; No region: Indentation is preserved.
1056 (org-test-with-temp-text "- A\n B"
1058 (org-toggle-fixed-width)
1060 ;; Region: If it contains only fixed-width elements and blank lines,
1061 ;; toggle off fixed-width markup.
1064 (org-test-with-temp-text ": A\n\n: B"
1065 (transient-mark-mode 1)
1066 (push-mark (point) t t
)
1067 (goto-char (point-max))
1068 (org-toggle-fixed-width)
1070 ;; Region: If it contains anything else, toggle on fixed-width but
1071 ;; not on fixed-width areas.
1073 (equal ": A\n: \n: B\n: \n: C"
1074 (org-test-with-temp-text "A\n\n: B\n\nC"
1075 (transient-mark-mode 1)
1076 (push-mark (point) t t
)
1077 (goto-char (point-max))
1078 (org-toggle-fixed-width)
1080 ;; Region: Ignore blank lines at its end, unless it contains only
1084 (org-test-with-temp-text "A\n\n"
1085 (transient-mark-mode 1)
1086 (push-mark (point) t t
)
1087 (goto-char (point-max))
1088 (org-toggle-fixed-width)
1092 (org-test-with-temp-text "\n\n"
1093 (transient-mark-mode 1)
1094 (push-mark (point) t t
)
1095 (goto-char (point-max))
1096 (org-toggle-fixed-width)
1103 (ert-deftest test-org
/in-commented-heading-p
()
1104 "Test `org-in-commented-heading-p' specifications."
1105 ;; Commented headline.
1107 (org-test-with-temp-text "* COMMENT Headline\nBody"
1108 (goto-char (point-max))
1109 (org-in-commented-heading-p)))
1110 ;; Commented ancestor.
1112 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1113 (goto-char (point-max))
1114 (org-in-commented-heading-p)))
1115 ;; Comment keyword is case-sensitive.
1117 (org-test-with-temp-text "* Comment Headline\nBody"
1118 (goto-char (point-max))
1119 (org-in-commented-heading-p)))
1120 ;; Keyword is standalone.
1122 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1123 (goto-char (point-max))
1124 (org-in-commented-heading-p)))
1125 ;; Optional argument.
1127 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1128 (goto-char (point-max))
1129 (org-in-commented-heading-p t
))))
1135 (ert-deftest test-org
/set-regexps-and-options
()
1136 "Test `org-set-regexps-and-options' specifications."
1139 (equal '(("A" . ?a
) ("B") ("C"))
1140 (org-test-with-temp-text "#+TAGS: A(a) B C"
1144 (equal '(("A") (:newline
) ("B"))
1145 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1149 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1150 (org-test-with-temp-text "#+TAGS: { A B } C"
1154 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1155 (org-test-with-temp-text "#+TAGS: { A : B C }"
1159 (equal '(("A" "B" "C"))
1160 (org-test-with-temp-text "#+TAGS: { A : B C }"
1162 org-tag-groups-alist
)))
1164 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1165 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1169 (equal '(("A" "B" "C"))
1170 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1172 org-tag-groups-alist
)))
1173 ;; FILETAGS keyword.
1175 (equal '("A" "B" "C")
1176 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1179 ;; PROPERTY keyword. Property names are case-insensitive.
1182 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1184 (cdr (assoc "var" org-file-properties
)))))
1188 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1190 (cdr (assoc "var" org-file-properties
)))))
1194 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1196 (cdr (assoc "var" org-file-properties
)))))
1200 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1202 org-archive-location
)))
1203 ;; CATEGORY keyword.
1206 (org-test-with-temp-text "#+CATEGORY: test"
1211 (org-test-with-temp-text "#+CATEGORY: test"
1213 (cdr (assoc "CATEGORY" org-file-properties
)))))
1216 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1217 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1219 org-columns-default-format
)))
1220 ;; CONSTANTS keyword. Constants names are case sensitive.
1222 (equal '("299792458." "3.14")
1223 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1226 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1230 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1232 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1235 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1237 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1242 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1244 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1246 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1250 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1252 (list org-highest-priority org-lowest-priority org-default-priority
))))
1256 (org-test-with-temp-text "#+PRIORITIES: X Z"
1258 (list org-highest-priority org-lowest-priority org-default-priority
))))
1262 (org-test-with-temp-text "#+STARTUP: fold odd"
1264 (list org-startup-folded org-odd-levels-only
))))
1267 (equal '(("A" "B") ("C"))
1268 (org-test-with-temp-text "#+TODO: A B | C"
1270 (list org-not-done-keywords org-done-keywords
))))
1272 (equal '(("A" "C") ("B" "D"))
1273 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1275 (list org-not-done-keywords org-done-keywords
))))
1277 (equal '(("A" "B") ("C"))
1278 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1280 (list org-not-done-keywords org-done-keywords
))))
1282 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1283 (org-test-with-temp-text "#+TODO: A(a)"
1285 org-todo-key-alist
)))
1287 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1288 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1290 org-todo-log-states
)))
1291 ;; Enter SETUPFILE keyword.
1294 (org-test-with-temp-text
1295 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1297 (cdr (assoc "a" org-file-properties
))))))
1305 (ert-deftest test-org
/coderef
()
1306 "Test coderef links specifications."
1308 (org-test-with-temp-text "
1309 #+BEGIN_SRC emacs-lisp
1313 (goto-char (point-max))
1315 (looking-at "(ref:sc)"))))
1319 (ert-deftest test-org
/custom-id
()
1320 "Test custom ID links specifications."
1322 (org-test-with-temp-text
1323 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1324 (goto-char (point-max))
1326 (org-looking-at-p "\\* H1")))
1327 ;; Ignore false positives.
1329 (org-test-with-temp-text
1330 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1331 (goto-char (point-max))
1332 (let (org-link-search-must-match-exact-headline) (org-open-at-point))
1333 (org-looking-at-p "\\* H1"))))
1337 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1338 ;; a named element (#+name: text) and to headlines (* Text).
1340 (ert-deftest test-org
/fuzzy-links
()
1341 "Test fuzzy links specifications."
1342 ;; Fuzzy link goes in priority to a matching target.
1344 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1347 (looking-at "<<Test>>")))
1348 ;; Then fuzzy link points to an element with a given name.
1350 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1353 (looking-at "#\\+NAME: Test")))
1354 ;; A target still lead to a matching headline otherwise.
1356 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1359 (looking-at "\\* Head2")))
1360 ;; With a leading star in link, enforce heading match.
1362 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1365 (looking-at "\\* Test")))
1366 ;; With a leading star in link, enforce exact heading match, even
1367 ;; with `org-link-search-must-match-exact-headline' set to nil.
1369 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1370 (let ((org-link-search-must-match-exact-headline nil
))
1371 (org-open-at-point))))
1372 ;; Heading match should not care about spaces, cookies, todo
1373 ;; keywords, priorities, and tags.
1376 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1377 (org-test-with-temp-text
1378 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1379 (let ((org-link-search-must-match-exact-headline nil
)
1380 (org-todo-regexp "TODO"))
1381 (org-open-at-point))
1382 (looking-at (regexp-quote first-line
)))))
1383 ;; Heading match should still be exact.
1386 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1387 (org-test-with-temp-text
1388 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1389 (let ((org-link-search-must-match-exact-headline nil
)
1390 (org-todo-regexp "TODO"))
1391 (org-open-at-point)))))
1392 ;; Correctly un-hexify fuzzy links.
1394 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1395 (goto-char (point-max))
1401 (ert-deftest test-org
/org-link-escape-ascii-character
()
1402 "Escape an ascii character."
1406 (org-link-escape "["))))
1408 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1409 "Escape an ascii control character."
1413 (org-link-escape "\t"))))
1415 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1416 "Escape an unicode multibyte character."
1420 (org-link-escape "€"))))
1422 (ert-deftest test-org
/org-link-escape-custom-table
()
1423 "Escape string with custom character table."
1427 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1429 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1430 "Escape string with custom table merged with default table."
1433 "%5BF%6F%6F%3A%42ar%0A%5D"
1434 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1436 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1437 "Unescape an ascii character."
1441 (org-link-unescape "%5B"))))
1443 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1444 "Unescpae an ascii control character."
1448 (org-link-unescape "%0A"))))
1450 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1451 "Unescape unicode multibyte character."
1455 (org-link-unescape "%E2%82%AC"))))
1457 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1458 "Unescape old style percent escaped character."
1461 "à âçèéêîôùû"
1462 (decode-coding-string
1463 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1465 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1466 "Escape and unescape a URL that includes an escaped char.
1467 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1470 "http://some.host.com/form?&id=blah%2Bblah25"
1472 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1474 (ert-deftest test-org
/org-link-escape-chars-browser
()
1475 "Test of the constant `org-link-escape-chars-browser'.
1476 See there why this test is a candidate to be removed once Org
1477 drops support for Emacs 24.1 and 24.2."
1480 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1481 "%22Release%208.2%22&idxname=emacs-orgmode")
1482 (org-link-escape-browser ; Do not replace with `url-encode-url',
1483 ; see docstring above.
1484 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1485 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1489 (ert-deftest test-org
/open-at-point-in-property
()
1490 "Does `org-open-at-point' open link in property drawer?"
1492 (org-test-with-temp-text
1495 :URL: <point>[[info:emacs#Top]]
1497 (org-open-at-point) t
)))
1499 (ert-deftest test-org
/open-at-point-in-comment
()
1500 "Does `org-open-at-point' open link in a commented line?"
1502 (org-test-with-temp-text
1503 "# <point>[[info:emacs#Top]]"
1504 (org-open-at-point) t
)))
1506 (ert-deftest test-org
/open-at-point
/info
()
1507 "Test `org-open-at-point' on info links."
1509 (org-test-with-temp-text
1510 "<point>[[info:emacs#Top]]"
1512 (and (switch-to-buffer "*info*")
1514 (looking-at "\nThe Emacs Editor")
1517 (ert-deftest test-org
/open-at-point
/inline-image
()
1518 "Test `org-open-at-point' on nested links."
1520 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1522 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1523 (kill-buffer "*info*")))))
1528 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1529 "Ensure properties accumulate in subtree drawers."
1530 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1531 (org-babel-next-src-block)
1532 (should (equal '(2 1) (org-babel-execute-src-block)))))
1534 (ert-deftest test-org
/custom-properties
()
1535 "Test custom properties specifications."
1538 (let ((org-custom-properties '("FOO")))
1539 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1540 (org-toggle-custom-properties-visibility)
1541 (org-invisible-p2))))
1542 ;; Properties are case-insensitive.
1544 (let ((org-custom-properties '("FOO")))
1545 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1546 (org-toggle-custom-properties-visibility)
1547 (org-invisible-p2))))
1549 (let ((org-custom-properties '("foo")))
1550 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1551 (org-toggle-custom-properties-visibility)
1552 (org-invisible-p2))))
1553 ;; Multiple custom properties in the same drawer.
1555 (let ((org-custom-properties '("FOO" "BAR")))
1556 (org-test-with-temp-text
1557 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1558 (org-toggle-custom-properties-visibility)
1559 (and (org-invisible-p2)
1560 (not (progn (forward-line) (org-invisible-p2)))
1561 (progn (forward-line) (org-invisible-p2))))))
1562 ;; Hide custom properties with an empty value.
1564 (let ((org-custom-properties '("FOO")))
1565 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1566 (org-toggle-custom-properties-visibility)
1567 (org-invisible-p2))))
1568 ;; Do not hide fake properties.
1570 (let ((org-custom-properties '("FOO")))
1571 (org-test-with-temp-text ":FOO: val\n"
1572 (org-toggle-custom-properties-visibility)
1573 (org-invisible-p2))))
1575 (let ((org-custom-properties '("A")))
1576 (org-test-with-temp-text
1577 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1578 (org-toggle-custom-properties-visibility)
1579 (org-invisible-p2)))))
1585 (ert-deftest test-org
/mark-subtree
()
1586 "Test `org-mark-subtree' specifications."
1587 ;; Error when point is before first headline.
1589 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1590 (progn (transient-mark-mode 1)
1591 (org-mark-subtree))))
1592 ;; Without argument, mark current subtree.
1596 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1597 (progn (transient-mark-mode 1)
1600 (list (region-beginning) (region-end))))))
1601 ;; With an argument, move ARG up.
1605 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1606 (progn (transient-mark-mode 1)
1608 (org-mark-subtree 1)
1609 (list (region-beginning) (region-end))))))
1610 ;; Do not get fooled by inlinetasks.
1611 (when (featurep 'org-inlinetask
)
1614 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1615 (progn (transient-mark-mode 1)
1617 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1618 (region-beginning)))))))
1624 (ert-deftest test-org
/end-of-meta-data
()
1625 "Test `org-end-of-meta-data' specifications."
1626 ;; Skip planning line.
1628 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1629 (org-end-of-meta-data)
1631 ;; Skip properties drawer.
1633 (org-test-with-temp-text
1634 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1635 (org-end-of-meta-data)
1639 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1640 (org-end-of-meta-data)
1642 ;; Nothing to skip, go to first line.
1644 (org-test-with-temp-text "* Headline\nContents"
1645 (org-end-of-meta-data)
1646 (looking-at "Contents")))
1647 ;; With option argument, skip empty lines, regular drawers and
1650 (org-test-with-temp-text "* Headline\n\nContents"
1651 (org-end-of-meta-data t
)
1652 (looking-at "Contents")))
1654 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1655 (org-end-of-meta-data t
)
1656 (looking-at "Contents")))
1658 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1659 (org-end-of-meta-data t
)
1660 (looking-at "Contents")))
1661 ;; Special case: do not skip incomplete drawers.
1663 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1664 (org-end-of-meta-data t
)
1665 (looking-at ":LOGBOOK:")))
1666 ;; Special case: Be careful about consecutive headlines.
1668 (org-test-with-temp-text "* H1\n*H2\nContents"
1669 (org-end-of-meta-data t
)
1670 (looking-at "Contents"))))
1672 (ert-deftest test-org
/beginning-of-line
()
1673 "Test `org-beginning-of-line' specifications."
1676 (org-test-with-temp-text "Some text\nSome other text"
1677 (progn (org-beginning-of-line) (bolp))))
1678 ;; Standard test with `visual-line-mode'.
1680 (org-test-with-temp-text "A long line of text\nSome other text"
1681 (progn (visual-line-mode)
1683 (dotimes (i 1000) (insert "very "))
1684 (org-beginning-of-line)
1686 ;; At an headline with special movement.
1688 (org-test-with-temp-text "* TODO Headline"
1689 (let ((org-special-ctrl-a/e t
))
1691 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1692 (progn (org-beginning-of-line) (bolp))
1693 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1695 (ert-deftest test-org
/end-of-line
()
1696 "Test `org-end-of-line' specifications."
1699 (org-test-with-temp-text "Some text\nSome other text"
1700 (progn (org-end-of-line) (eolp))))
1701 ;; Standard test with `visual-line-mode'.
1703 (org-test-with-temp-text "A long line of text\nSome other text"
1704 (progn (visual-line-mode)
1706 (dotimes (i 1000) (insert "very "))
1707 (goto-char (point-min))
1710 ;; At an headline with special movement.
1712 (org-test-with-temp-text "* Headline1 :tag:\n"
1713 (let ((org-special-ctrl-a/e t
))
1714 (and (progn (org-end-of-line) (looking-at " :tag:"))
1715 (progn (org-end-of-line) (eolp))
1716 (progn (org-end-of-line) (looking-at " :tag:"))))))
1717 ;; At an headline without special movement.
1719 (org-test-with-temp-text "* Headline2 :tag:\n"
1720 (let ((org-special-ctrl-a/e nil
))
1721 (and (progn (org-end-of-line) (eolp))
1722 (progn (org-end-of-line) (eolp))))))
1723 ;; At an headline, with reversed movement.
1725 (org-test-with-temp-text "* Headline3 :tag:\n"
1726 (let ((org-special-ctrl-a/e
'reversed
)
1727 (this-command last-command
))
1728 (and (progn (org-end-of-line) (eolp))
1729 (progn (org-end-of-line) (looking-at " :tag:"))))))
1730 ;; At a block without hidden contents.
1732 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1733 (progn (org-end-of-line) (eolp))))
1734 ;; At a block with hidden contents.
1736 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1737 (let ((org-special-ctrl-a/e t
))
1738 (org-hide-block-toggle)
1742 (ert-deftest test-org
/forward-paragraph
()
1743 "Test `org-forward-paragraph' specifications."
1744 ;; At end of buffer, return an error.
1746 (org-test-with-temp-text "Paragraph"
1747 (goto-char (point-max))
1748 (org-forward-paragraph)))
1751 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1752 (org-forward-paragraph)
1756 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1757 (org-forward-paragraph)
1759 ;; Do not enter elements with invisible contents.
1761 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1762 (org-hide-block-toggle)
1763 (org-forward-paragraph)
1765 ;; On an affiliated keyword, jump to the beginning of the element.
1767 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1768 (org-forward-paragraph)
1769 (looking-at "Para")))
1770 ;; On an item or a footnote definition, move to the second element
1773 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1774 (org-forward-paragraph)
1775 (looking-at " Paragraph")))
1777 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1778 (org-forward-paragraph)
1779 (looking-at "Paragraph")))
1780 ;; On an item, or a footnote definition, when the first line is
1781 ;; empty, move to the first item.
1783 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1784 (org-forward-paragraph)
1785 (looking-at " Paragraph")))
1787 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1788 (org-forward-paragraph)
1789 (looking-at "Paragraph")))
1790 ;; On a table (resp. a property drawer) do not move through table
1791 ;; rows (resp. node properties).
1793 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1794 (org-forward-paragraph)
1795 (looking-at "Paragraph")))
1797 (org-test-with-temp-text
1798 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1799 (org-forward-paragraph)
1800 (looking-at "Paragraph")))
1801 ;; On a verse or source block, stop after blank lines.
1803 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1804 (org-forward-paragraph)
1807 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1808 (org-forward-paragraph)
1809 (looking-at "L2"))))
1811 (ert-deftest test-org
/backward-paragraph
()
1812 "Test `org-backward-paragraph' specifications."
1813 ;; Error at beginning of buffer.
1815 (org-test-with-temp-text "Paragraph"
1816 (org-backward-paragraph)))
1819 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1820 (goto-char (point-max))
1821 (org-backward-paragraph)
1824 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1825 (goto-char (point-max))
1827 (org-backward-paragraph)
1831 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1832 (goto-char (point-max))
1834 (org-backward-paragraph)
1836 ;; Ignore invisible elements.
1838 (org-test-with-temp-text "* H1\n P1\n* H2"
1840 (goto-char (point-max))
1842 (org-backward-paragraph)
1844 ;; On an affiliated keyword, jump to the first one.
1846 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1847 (search-forward "c2")
1848 (org-backward-paragraph)
1849 (looking-at "#\\+name")))
1850 ;; On the second element in an item or a footnote definition, jump
1851 ;; to item or the definition.
1853 (org-test-with-temp-text "- line1\n\n line2"
1854 (goto-char (point-max))
1856 (org-backward-paragraph)
1857 (looking-at "- line1")))
1859 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1860 (goto-char (point-max))
1862 (org-backward-paragraph)
1863 (looking-at "\\[fn:1\\] line1")))
1864 ;; On a table (resp. a property drawer), ignore table rows
1865 ;; (resp. node properties).
1867 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1868 (goto-char (point-max))
1870 (org-backward-paragraph)
1873 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1874 (org-backward-paragraph)
1875 (looking-at ":PROPERTIES:")))
1876 ;; On a source or verse block, stop before blank lines.
1878 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1879 (search-forward "L3")
1881 (org-backward-paragraph)
1884 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1885 (search-forward "L3")
1887 (org-backward-paragraph)
1888 (looking-at "L2"))))
1890 (ert-deftest test-org
/forward-element
()
1891 "Test `org-forward-element' specifications."
1892 ;; 1. At EOB: should error.
1893 (org-test-with-temp-text "Some text\n"
1894 (goto-char (point-max))
1895 (should-error (org-forward-element)))
1896 ;; 2. Standard move: expected to ignore blank lines.
1897 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1898 (org-forward-element)
1899 (should (looking-at (regexp-quote "Second paragraph."))))
1900 ;; 3. Headline tests.
1901 (org-test-with-temp-text "
1906 ;; 3.1. At an headline beginning: move to next headline at the
1909 (org-forward-element)
1910 (should (looking-at (regexp-quote "** Head 1.2")))
1911 ;; 3.2. At an headline beginning: move to parent headline if no
1912 ;; headline at the same level.
1914 (org-forward-element)
1915 (should (looking-at (regexp-quote "** Head 1.2"))))
1916 ;; 4. Greater element tests.
1917 (org-test-with-temp-text
1918 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1919 ;; 4.1. At a greater element: expected to skip contents.
1920 (org-forward-element)
1921 (should (looking-at (regexp-quote "Outside.")))
1922 ;; 4.2. At the end of greater element contents: expected to skip
1923 ;; to the end of the greater element.
1925 (org-forward-element)
1926 (should (looking-at (regexp-quote "Outside."))))
1928 (org-test-with-temp-text "
1942 ;; 5.1. At list top point: expected to move to the element after
1945 (org-forward-element)
1946 (should (looking-at (regexp-quote "Outside.")))
1947 ;; 5.2. Special case: at the first line of a sub-list, but not at
1948 ;; beginning of line, move to next item.
1951 (org-forward-element)
1952 (should (looking-at "- item2"))
1955 (org-forward-element)
1956 (should (looking-at " - sub2"))
1957 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1959 (org-forward-element)
1960 (should (looking-at (regexp-quote " Inner paragraph.")))
1961 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1963 (org-forward-element)
1964 (should (looking-at (regexp-quote " Inner paragraph.")))
1965 ;; 5.5. At an item: expected to move to next item, if any.
1967 (org-forward-element)
1968 (should (looking-at " - sub3"))))
1970 (ert-deftest test-org
/backward-element
()
1971 "Test `org-backward-element' specifications."
1972 ;; 1. Should error at BOB.
1973 (org-test-with-temp-text " \nParagraph."
1974 (should-error (org-backward-element)))
1975 ;; 2. Should move at BOB when called on the first element in buffer.
1977 (org-test-with-temp-text "\n#+TITLE: test"
1978 (progn (forward-line)
1979 (org-backward-element)
1981 ;; 3. Not at the beginning of an element: move at its beginning.
1982 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1985 (org-backward-element)
1986 (should (looking-at (regexp-quote "Paragraph2."))))
1987 ;; 4. Headline tests.
1988 (org-test-with-temp-text "
1993 ;; 4.1. At an headline beginning: move to previous headline at the
1996 (org-backward-element)
1997 (should (looking-at (regexp-quote "** Head 1.1")))
1998 ;; 4.2. At an headline beginning: move to parent headline if no
1999 ;; headline at the same level.
2001 (org-backward-element)
2002 (should (looking-at (regexp-quote "* Head 1")))
2003 ;; 4.3. At the first top-level headline: should error.
2005 (should-error (org-backward-element)))
2006 ;; 5. At beginning of first element inside a greater element:
2007 ;; expected to move to greater element's beginning.
2008 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2010 (org-backward-element)
2011 (should (looking-at "#\\+BEGIN_CENTER")))
2012 ;; 6. At the beginning of the first element in a section: should
2013 ;; move back to headline, if any.
2015 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2016 (progn (goto-char (point-max))
2018 (org-backward-element)
2019 (org-at-heading-p))))
2021 (org-test-with-temp-text "
2036 ;; 7.1. At beginning of sub-list: expected to move to the
2037 ;; paragraph before it.
2039 (org-backward-element)
2040 (should (looking-at "item1"))
2041 ;; 7.2. At an item in a list: expected to move at previous item.
2043 (org-backward-element)
2044 (should (looking-at " - sub2"))
2046 (org-backward-element)
2047 (should (looking-at "- item1"))
2048 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2051 (org-backward-element)
2052 (should (looking-at " - sub1"))
2054 (org-backward-element)
2055 (should (looking-at "- item1"))
2056 ;; 7.4. At blank-lines before list end: expected to move to top
2059 (org-backward-element)
2060 (should (looking-at "- item1"))))
2062 (ert-deftest test-org
/up-element
()
2063 "Test `org-up-element' specifications."
2064 ;; 1. At BOB or with no surrounding element: should error.
2065 (org-test-with-temp-text "Paragraph."
2066 (should-error (org-up-element)))
2067 (org-test-with-temp-text "* Head1\n* Head2"
2069 (should-error (org-up-element)))
2070 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2072 (should-error (org-up-element)))
2073 ;; 2. At an headline: move to parent headline.
2074 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2077 (should (looking-at "\\* Head1")))
2078 ;; 3. Inside a greater element: move to greater element beginning.
2079 (org-test-with-temp-text
2080 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2083 (should (looking-at "#\\+BEGIN_CENTER")))
2085 (org-test-with-temp-text "* Top
2092 Paragraph within sub2.
2095 ;; 4.1. Within an item: move to the item beginning.
2098 (should (looking-at " - sub2"))
2099 ;; 4.2. At an item in a sub-list: move to parent item.
2102 (should (looking-at "- item1"))
2103 ;; 4.3. At an item in top list: move to beginning of whole list.
2106 (should (looking-at "- item1"))
2107 ;; 4.4. Special case. At very top point: should move to parent of
2111 (should (looking-at "\\* Top"))))
2113 (ert-deftest test-org
/down-element
()
2114 "Test `org-down-element' specifications."
2115 ;; Error when the element hasn't got a recursive type.
2116 (org-test-with-temp-text "Paragraph."
2117 (should-error (org-down-element)))
2118 ;; Error when the element has no contents
2119 (org-test-with-temp-text "* Headline"
2120 (should-error (org-down-element)))
2121 ;; When at a plain-list, move to first item.
2122 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2125 (should (looking-at " - Item 1.1")))
2126 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2128 (should (looking-at " Item 1")))
2129 ;; When at a table, move to first row
2130 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2132 (should (looking-at " a | b |")))
2133 ;; Otherwise, move inside the greater element.
2134 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2136 (should (looking-at "Paragraph"))))
2138 (ert-deftest test-org
/drag-element-backward
()
2139 "Test `org-drag-element-backward' specifications."
2143 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2144 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2145 (org-drag-element-backward)
2149 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2150 (org-test-with-temp-text
2151 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2152 (org-drag-element-backward)
2154 ;; Preserve blank lines.
2156 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2157 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2158 (org-drag-element-backward)
2162 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2163 (org-drag-element-backward)
2164 (org-looking-at-p "2")))
2165 ;; Error when trying to move first element of buffer.
2167 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2168 (org-drag-element-backward)))
2169 ;; Error when trying to swap nested elements.
2171 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2173 (org-drag-element-backward)))
2174 ;; Error when trying to swap an headline element and a non-headline
2177 (org-test-with-temp-text "Test.\n* Head 1"
2179 (org-drag-element-backward)))
2180 ;; Preserve visibility of elements and their contents.
2182 (equal '((63 .
82) (26 .
48))
2183 (org-test-with-temp-text "
2191 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2192 (search-backward "- item 1")
2193 (org-drag-element-backward)
2194 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2195 (overlays-in (point-min) (point-max)))))))
2197 (ert-deftest test-org
/drag-element-forward
()
2198 "Test `org-drag-element-forward' specifications."
2199 ;; 1. Error when trying to move first element of buffer.
2200 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2202 (should-error (org-drag-element-forward)))
2203 ;; 2. Error when trying to swap nested elements.
2204 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2206 (should-error (org-drag-element-forward)))
2207 ;; 3. Error when trying to swap a non-headline element and an
2209 (org-test-with-temp-text "Test.\n* Head 1"
2210 (should-error (org-drag-element-forward)))
2211 ;; 4. Otherwise, swap elements, preserving column and blank lines
2212 ;; between elements.
2213 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2214 (search-forward "graph")
2215 (org-drag-element-forward)
2216 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2217 (should (looking-at " 1")))
2218 ;; 5. Preserve visibility of elements and their contents.
2219 (org-test-with-temp-text "
2227 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2228 (search-backward "#+BEGIN_CENTER")
2229 (org-drag-element-forward)
2232 '((63 .
82) (26 .
48))
2233 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2234 (overlays-in (point-min) (point-max)))))))
2237 ;;; Outline structure
2239 (ert-deftest test-org
/demote
()
2240 "Test `org-demote' specifications."
2241 ;; Add correct number of stars according to `org-odd-levels-only'.
2244 (org-test-with-temp-text "* H"
2245 (let ((org-odd-levels-only nil
)) (org-demote))
2246 (org-current-level))))
2249 (org-test-with-temp-text "* H"
2250 (let ((org-odd-levels-only t
)) (org-demote))
2251 (org-current-level))))
2252 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2254 (org-test-with-temp-text "* H :tag:"
2255 (let ((org-tags-column 10)
2256 (org-auto-align-tags t
)
2257 (org-odd-levels-only nil
))
2259 (org-move-to-column 10)
2260 (org-looking-at-p ":tag:$")))
2262 (org-test-with-temp-text "* H :tag:"
2263 (let ((org-tags-column 10)
2264 (org-auto-align-tags nil
)
2265 (org-odd-levels-only nil
))
2267 (org-move-to-column 10)
2268 (org-looking-at-p ":tag:$")))
2269 ;; When `org-adapt-indentation' is non-nil, always indent planning
2270 ;; info and property drawers accordingly.
2273 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2274 (let ((org-odd-levels-only nil
)
2275 (org-adapt-indentation t
))
2278 (org-get-indentation))))
2281 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2282 (let ((org-odd-levels-only nil
)
2283 (org-adapt-indentation t
))
2286 (org-get-indentation))))
2289 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2290 (let ((org-odd-levels-only nil
)
2291 (org-adapt-indentation nil
))
2294 (org-get-indentation))))
2295 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2296 ;; section accordingly. Ignore, however, footnote definitions and
2297 ;; inlinetasks boundaries.
2300 (org-test-with-temp-text "* H\n Paragraph"
2301 (let ((org-odd-levels-only nil
)
2302 (org-adapt-indentation t
))
2305 (org-get-indentation))))
2308 (org-test-with-temp-text "* H\n Paragraph"
2309 (let ((org-odd-levels-only nil
)
2310 (org-adapt-indentation nil
))
2313 (org-get-indentation))))
2316 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2317 (let ((org-odd-levels-only nil
)
2318 (org-adapt-indentation t
))
2320 (goto-char (point-max))
2321 (org-get-indentation))))
2324 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2325 (let ((org-odd-levels-only nil
)
2326 (org-adapt-indentation t
))
2328 (goto-char (point-max))
2329 (org-get-indentation))))
2330 (when (featurep 'org-inlinetask
)
2333 (let ((org-inlinetask-min-level 5)
2334 (org-adapt-indentation t
))
2335 (org-test-with-temp-text "* H\n***** I\n***** END"
2338 (org-get-indentation))))))
2339 (when (featurep 'org-inlinetask
)
2342 (let ((org-inlinetask-min-level 5)
2343 (org-adapt-indentation t
))
2344 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2347 (org-get-indentation))))))
2348 ;; Ignore contents of source blocks or example blocks when
2349 ;; indentation should be preserved (through
2350 ;; `org-src-preserve-indentation' or "-i" flag).
2353 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2354 (let ((org-adapt-indentation t
)
2355 (org-src-preserve-indentation nil
))
2358 (org-get-indentation))))
2361 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2362 (let ((org-adapt-indentation t
)
2363 (org-src-preserve-indentation t
))
2366 (org-get-indentation))))
2369 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2370 (let ((org-adapt-indentation t
)
2371 (org-src-preserve-indentation t
))
2374 (org-get-indentation))))
2377 (org-test-with-temp-text
2378 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2379 (let ((org-adapt-indentation t
)
2380 (org-src-preserve-indentation nil
))
2383 (org-get-indentation)))))
2385 (ert-deftest test-org
/promote
()
2386 "Test `org-promote' specifications."
2387 ;; Return an error if headline is to be promoted to level 0, unless
2388 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2389 ;; headline becomes a comment.
2391 (org-test-with-temp-text "* H"
2392 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2395 (org-test-with-temp-text "* H"
2396 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2398 ;; Remove correct number of stars according to
2399 ;; `org-odd-levels-only'.
2402 (org-test-with-temp-text "*** H"
2403 (let ((org-odd-levels-only nil
)) (org-promote))
2404 (org-current-level))))
2407 (org-test-with-temp-text "*** H"
2408 (let ((org-odd-levels-only t
)) (org-promote))
2409 (org-current-level))))
2410 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2412 (org-test-with-temp-text "** H :tag:"
2413 (let ((org-tags-column 10)
2414 (org-auto-align-tags t
)
2415 (org-odd-levels-only nil
))
2417 (org-move-to-column 10)
2418 (org-looking-at-p ":tag:$")))
2420 (org-test-with-temp-text "** H :tag:"
2421 (let ((org-tags-column 10)
2422 (org-auto-align-tags nil
)
2423 (org-odd-levels-only nil
))
2425 (org-move-to-column 10)
2426 (org-looking-at-p ":tag:$")))
2427 ;; When `org-adapt-indentation' is non-nil, always indent planning
2428 ;; info and property drawers.
2431 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2432 (let ((org-odd-levels-only nil
)
2433 (org-adapt-indentation t
))
2436 (org-get-indentation))))
2439 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2440 (let ((org-odd-levels-only nil
)
2441 (org-adapt-indentation t
))
2444 (org-get-indentation))))
2447 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2448 (let ((org-odd-levels-only nil
)
2449 (org-adapt-indentation nil
))
2452 (org-get-indentation))))
2453 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2454 ;; section accordingly. Ignore, however, footnote definitions and
2455 ;; inlinetasks boundaries.
2458 (org-test-with-temp-text "** H\n Paragraph"
2459 (let ((org-odd-levels-only nil
)
2460 (org-adapt-indentation t
))
2463 (org-get-indentation))))
2466 (org-test-with-temp-text "** H\n Paragraph"
2467 (let ((org-odd-levels-only nil
)
2468 (org-adapt-indentation nil
))
2471 (org-get-indentation))))
2474 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2475 (let ((org-odd-levels-only nil
)
2476 (org-adapt-indentation t
))
2479 (org-get-indentation))))
2480 (when (featurep 'org-inlinetask
)
2483 (let ((org-inlinetask-min-level 5)
2484 (org-adapt-indentation t
))
2485 (org-test-with-temp-text "** H\n***** I\n***** END"
2488 (org-get-indentation))))))
2489 (when (featurep 'org-inlinetask
)
2492 (let ((org-inlinetask-min-level 5)
2493 (org-adapt-indentation t
))
2494 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2497 (org-get-indentation))))))
2498 ;; Give up shifting if it would break document's structure
2502 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2503 (let ((org-odd-levels-only nil
)
2504 (org-adapt-indentation t
))
2507 (org-get-indentation))))
2510 (org-test-with-temp-text "** H\n Paragraph\n * list."
2511 (let ((org-odd-levels-only nil
)
2512 (org-adapt-indentation t
))
2515 (org-get-indentation))))
2516 ;; Ignore contents of source blocks or example blocks when
2517 ;; indentation should be preserved (through
2518 ;; `org-src-preserve-indentation' or "-i" flag).
2521 (org-test-with-temp-text
2522 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2523 (let ((org-adapt-indentation t
)
2524 (org-src-preserve-indentation nil
)
2525 (org-odd-levels-only nil
))
2528 (org-get-indentation))))
2531 (org-test-with-temp-text
2532 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2533 (let ((org-adapt-indentation t
)
2534 (org-src-preserve-indentation t
)
2535 (org-odd-levels-only nil
))
2538 (org-get-indentation))))
2541 (org-test-with-temp-text
2542 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2543 (let ((org-adapt-indentation t
)
2544 (org-src-preserve-indentation t
)
2545 (org-odd-levels-only nil
))
2548 (org-get-indentation))))
2551 (org-test-with-temp-text
2552 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2553 (let ((org-adapt-indentation t
)
2554 (org-src-preserve-indentation nil
)
2555 (org-odd-levels-only nil
))
2558 (org-get-indentation)))))
2563 (ert-deftest test-org
/at-planning-p
()
2564 "Test `org-at-planning-p' specifications."
2567 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2568 (org-at-planning-p)))
2570 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2571 (org-at-planning-p)))
2572 ;; Correctly find planning attached to inlinetasks.
2573 (when (featurep 'org-inlinetask
)
2575 (org-test-with-temp-text
2576 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2577 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2579 (org-test-with-temp-text
2580 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2581 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2583 (org-test-with-temp-text
2584 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2585 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2587 (org-test-with-temp-text
2588 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2589 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2594 (ert-deftest test-org
/buffer-property-keys
()
2595 "Test `org-buffer-property-keys' specifications."
2596 ;; Retrieve properties accross siblings.
2599 (org-test-with-temp-text "
2608 (org-buffer-property-keys))))
2609 ;; Retrieve properties accross children.
2612 (org-test-with-temp-text "
2621 (org-buffer-property-keys))))
2622 ;; Retrieve muliple properties in the same drawer.
2625 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2626 (org-buffer-property-keys))))
2627 ;; Ignore extension symbol in property name.
2630 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2631 (org-buffer-property-keys))))
2632 ;; With non-nil COLUMNS, extract property names from columns.
2635 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2636 (org-buffer-property-keys nil nil t
))))
2638 (equal '("A" "B" "COLUMNS")
2639 (org-test-with-temp-text
2640 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2641 (org-buffer-property-keys nil nil t
)))))
2643 (ert-deftest test-org
/property-values
()
2644 "Test `org-property-values' specifications."
2648 (org-test-with-temp-text
2649 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2650 (org-property-values "A"))))
2651 ;; Ignore empty values.
2653 (org-test-with-temp-text
2654 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2655 (org-property-values "A")))
2656 ;; Take into consideration extended values.
2659 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2660 (org-property-values "A")))))
2662 (ert-deftest test-org
/find-property
()
2663 "Test `org-find-property' specifications."
2667 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
2668 (org-find-property "prop"))))
2669 ;; Ignore false positives.
2672 (org-test-with-temp-text
2673 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
2674 (org-find-property "A"))))
2675 ;; Return first entry found in buffer.
2678 (org-test-with-temp-text
2679 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2680 (org-find-property "A"))))
2681 ;; Only search visible part of the buffer.
2684 (org-test-with-temp-text
2685 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2686 (org-narrow-to-subtree)
2687 (org-find-property "A"))))
2688 ;; With optional argument, only find entries with a specific value.
2690 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2691 (org-find-property "A" "2")))
2694 (org-test-with-temp-text
2695 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
2696 (org-find-property "A" "2"))))
2697 ;; Use "nil" for explicit nil values.
2700 (org-test-with-temp-text
2701 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
2702 (org-find-property "A" "nil"))))
2703 ;; Optional argument is matched against real value, including PROP+
2707 (org-test-with-temp-text "* H1\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2708 (org-find-property "A" "1 2")))))
2710 (ert-deftest test-org
/entry-delete
()
2711 "Test `org-entry-delete' specifications."
2715 " *:PROPERTIES:\n *:B: +2\n *:END:"
2716 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2717 (org-entry-delete (point) "A")
2719 ;; Also remove accumulated properties.
2723 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
2724 (org-entry-delete (point) "A")
2726 ;; When last property is removed, remove the property drawer.
2730 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2731 (org-entry-delete (point) "A")
2733 ;; Return a non-nil value when some property was removed.
2735 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2736 (org-entry-delete (point) "A")))
2738 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2739 (org-entry-delete (point) "C"))))
2741 (ert-deftest test-org
/entry-get
()
2742 "Test `org-entry-get' specifications."
2746 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2747 (org-entry-get (point) "A"))))
2751 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2752 (org-entry-get (point) "a"))))
2753 ;; Handle extended values, both before and after base value.
2756 (org-test-with-temp-text
2757 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2758 (org-entry-get (point) "A"))))
2759 ;; Empty values are returned as the empty string.
2762 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2763 (org-entry-get (point) "A"))))
2764 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2765 ;; otherwise, return nil.
2767 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2768 (org-entry-get (point) "A")))
2771 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2772 (org-entry-get (point) "A" nil t
))))
2773 ;; Return nil when no property is found, independently on the
2774 ;; LITERAL-NIL argument.
2776 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2777 (org-entry-get (point) "B")))
2779 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2780 (org-entry-get (point) "B" nil t
)))
2781 ;; Handle inheritance, when allowed.
2785 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2786 (org-entry-get (point) "A" t
))))
2790 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2791 (let ((org-use-property-inheritance t
))
2792 (org-entry-get (point) "A" 'selective
)))))
2794 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2795 (let ((org-use-property-inheritance nil
))
2796 (org-entry-get (point) "A" 'selective
)))))
2798 (ert-deftest test-org
/entry-properties
()
2799 "Test `org-entry-properties' specifications."
2800 ;; Get "ITEM" property.
2803 (org-test-with-temp-text "* TODO H"
2804 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
2807 (org-test-with-temp-text "* TODO H"
2808 (cdr (assoc "ITEM" (org-entry-properties))))))
2809 ;; Get "TODO" property.
2812 (org-test-with-temp-text "* TODO H"
2813 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
2816 (org-test-with-temp-text "* TODO H"
2817 (cdr (assoc "TODO" (org-entry-properties))))))
2819 (org-test-with-temp-text "* H"
2820 (assoc "TODO" (org-entry-properties nil
"TODO"))))
2821 ;; Get "PRIORITY" property.
2824 (org-test-with-temp-text "* [#A] H"
2825 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
2828 (org-test-with-temp-text "* [#A] H"
2829 (cdr (assoc "PRIORITY" (org-entry-properties))))))
2831 (org-test-with-temp-text "* H"
2832 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
2833 ;; Get "FILE" property.
2835 (org-test-with-temp-text-in-file "* H\nParagraph"
2836 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
2837 (buffer-file-name))))
2839 (org-test-with-temp-text-in-file "* H\nParagraph"
2840 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
2841 (buffer-file-name))))
2843 (org-test-with-temp-text "* H\nParagraph"
2844 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
2845 ;; Get "TAGS" property.
2847 (equal ":tag1:tag2:"
2848 (org-test-with-temp-text "* H :tag1:tag2:"
2849 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
2851 (equal ":tag1:tag2:"
2852 (org-test-with-temp-text "* H :tag1:tag2:"
2853 (cdr (assoc "TAGS" (org-entry-properties))))))
2855 (org-test-with-temp-text "* H"
2856 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
2857 ;; Get "ALLTAGS" property.
2859 (equal ":tag1:tag2:"
2860 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2861 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
2863 (equal ":tag1:tag2:"
2864 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2865 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
2867 (org-test-with-temp-text "* H"
2868 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
2869 ;; Get "BLOCKED" property.
2872 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2873 (let ((org-enforce-todo-dependencies t
)
2875 '(org-block-todo-from-children-or-siblings-or-parent)))
2876 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2879 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2880 (let ((org-enforce-todo-dependencies t
)
2882 '(org-block-todo-from-children-or-siblings-or-parent)))
2883 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
2886 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2887 (let ((org-enforce-todo-dependencies t
))
2888 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2889 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2893 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2894 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
2898 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2899 (cdr (assoc "CLOSED" (org-entry-properties))))))
2901 (org-test-with-temp-text "* H"
2902 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
2906 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2907 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
2911 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2912 (cdr (assoc "DEADLINE" (org-entry-properties))))))
2914 (org-test-with-temp-text "* H"
2915 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
2919 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2920 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
2924 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2925 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
2927 (org-test-with-temp-text "* H"
2928 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
2932 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2933 (cdr (assoc "CATEGORY" (org-entry-properties))))))
2936 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2937 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2940 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2941 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2942 ;; Get standard properties.
2945 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2946 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2947 ;; Handle extended properties.
2950 (org-test-with-temp-text
2951 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2952 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2955 (org-test-with-temp-text
2956 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2957 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2958 ;; Ignore forbidden (special) properties.
2960 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2961 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
2963 (ert-deftest test-org
/entry-put
()
2964 "Test `org-entry-put' specifications."
2965 ;; Error when not a string or nil.
2967 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2968 (org-entry-put 1 "test" 2)))
2969 ;; Set "TODO" property.
2971 (string-match (regexp-quote " TODO H")
2972 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2973 (org-entry-put (point) "TODO" "TODO")
2976 (string-match (regexp-quote "* H")
2977 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2978 (org-entry-put (point) "TODO" nil
)
2980 ;; Set "PRIORITY" property.
2983 (org-test-with-temp-text "* [#B] H"
2984 (org-entry-put (point) "PRIORITY" "A")
2988 (org-test-with-temp-text "* [#B] H"
2989 (org-entry-put (point) "PRIORITY" nil
)
2991 ;; Set "SCHEDULED" property.
2993 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2994 (org-test-with-temp-text "* H"
2995 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2999 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3000 (org-entry-put (point) "SCHEDULED" nil
)
3003 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3004 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3005 (org-entry-put (point) "SCHEDULED" "earlier")
3008 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3009 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3010 (org-entry-put (point) "SCHEDULED" "later")
3012 ;; Set "DEADLINE" property.
3014 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3015 (org-test-with-temp-text "* H"
3016 (org-entry-put (point) "DEADLINE" "2014-03-04")
3020 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3021 (org-entry-put (point) "DEADLINE" nil
)
3024 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3025 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3026 (org-entry-put (point) "DEADLINE" "earlier")
3029 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3030 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3031 (org-entry-put (point) "DEADLINE" "later")
3033 ;; Set "CATEGORY" property
3035 (string-match "^ *:CATEGORY: cat"
3036 (org-test-with-temp-text "* H"
3037 (org-entry-put (point) "CATEGORY" "cat")
3039 ;; Regular properties, with or without pre-existing drawer.
3041 (string-match "^ *:A: +2$"
3042 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3043 (org-entry-put (point) "A" "2")
3046 (string-match "^ *:A: +1$"
3047 (org-test-with-temp-text "* H"
3048 (org-entry-put (point) "A" "1")
3050 ;; Special case: two consecutive headlines.
3052 (string-match "\\* A\n *:PROPERTIES:"
3053 (org-test-with-temp-text "* A\n** B"
3054 (org-entry-put (point) "A" "1")
3060 (ert-deftest test-org
/update-radio-target-regexp
()
3061 "Test `org-update-radio-target-regexp' specifications."
3062 ;; Properly update cache with no previous radio target regexp.
3065 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3066 (save-excursion (goto-char (point-max)) (org-element-context))
3068 (search-forward "o")
3070 (org-update-radio-target-regexp)
3071 (goto-char (point-max))
3072 (org-element-type (org-element-context)))))
3073 ;; Properly update cache with previous radio target regexp.
3076 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3077 (save-excursion (goto-char (point-max)) (org-element-context))
3079 (search-forward "o")
3081 (org-update-radio-target-regexp)
3082 (search-backward "r")
3085 (org-update-radio-target-regexp)
3086 (goto-char (point-max))
3087 (delete-region (line-beginning-position) (point))
3089 (org-element-type (org-element-context))))))
3094 (ert-deftest test-org
/match-sparse-tree
()
3095 "Test `org-match-sparse-tree' specifications."
3098 (org-test-with-temp-text "* H\n** H1 :tag:"
3099 (org-match-sparse-tree nil
"tag")
3100 (search-forward "H1")
3101 (org-invisible-p2)))
3103 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3104 (org-match-sparse-tree nil
"tag")
3105 (search-forward "H2")
3106 (org-invisible-p2)))
3107 ;; "-" operator for tags.
3109 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3110 (org-match-sparse-tree nil
"tag1-tag2")
3111 (search-forward "H1")
3112 (org-invisible-p2)))
3114 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3115 (org-match-sparse-tree nil
"tag1-tag2")
3116 (search-forward "H2")
3117 (org-invisible-p2)))
3118 ;; "&" operator for tags.
3120 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3121 (org-match-sparse-tree nil
"tag1&tag2")
3122 (search-forward "H1")
3123 (org-invisible-p2)))
3125 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3126 (org-match-sparse-tree nil
"tag1&tag2")
3127 (search-forward "H2")
3128 (org-invisible-p2)))
3129 ;; "|" operator for tags.
3131 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3132 (org-match-sparse-tree nil
"tag1|tag2")
3133 (search-forward "H1")
3134 (org-invisible-p2)))
3136 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3137 (org-match-sparse-tree nil
"tag1|tag2")
3138 (search-forward "H2")
3139 (org-invisible-p2)))
3140 ;; Regexp match on tags.
3142 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3143 (org-match-sparse-tree nil
"{^tag.*}")
3144 (search-forward "H1")
3145 (org-invisible-p2)))
3147 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3148 (org-match-sparse-tree nil
"{^tag.*}")
3149 (search-forward "H2")
3150 (org-invisible-p2)))
3151 ;; Match group tags.
3153 (org-test-with-temp-text
3154 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3155 (org-match-sparse-tree nil
"work")
3156 (search-forward "H1")
3157 (org-invisible-p2)))
3159 (org-test-with-temp-text
3160 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3161 (org-match-sparse-tree nil
"work")
3162 (search-forward "H2")
3163 (org-invisible-p2)))
3164 ;; Match group tags with hard brackets.
3166 (org-test-with-temp-text
3167 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3168 (org-match-sparse-tree nil
"work")
3169 (search-forward "H1")
3170 (org-invisible-p2)))
3172 (org-test-with-temp-text
3173 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3174 (org-match-sparse-tree nil
"work")
3175 (search-forward "H2")
3176 (org-invisible-p2)))
3177 ;; Match regular expressions in tags
3179 (org-test-with-temp-text
3180 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3181 (org-match-sparse-tree nil
"Lev")
3182 (search-forward "H1")
3183 (org-invisible-p2)))
3185 (org-test-with-temp-text
3186 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3187 (org-match-sparse-tree nil
"Lev")
3188 (search-forward "H1")
3189 (org-invisible-p2)))
3190 ;; Match properties.
3192 (org-test-with-temp-text
3193 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3194 (org-match-sparse-tree nil
"A=\"1\"")
3195 (search-forward "H2")
3196 (org-invisible-p2)))
3198 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3199 (org-match-sparse-tree nil
"A=\"1\"")
3200 (search-forward "H2")
3201 (org-invisible-p2)))
3202 ;; Case is not significant when matching properties.
3204 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3205 (org-match-sparse-tree nil
"a=\"1\"")
3206 (search-forward "H2")
3207 (org-invisible-p2)))
3209 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3210 (org-match-sparse-tree nil
"A=\"1\"")
3211 (search-forward "H2")
3212 (org-invisible-p2)))
3213 ;; Match special LEVEL property.
3215 (org-test-with-temp-text "* H\n** H1\n*** H2"
3216 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3217 (search-forward "H1")
3218 (org-invisible-p2)))
3220 (org-test-with-temp-text "* H\n** H1\n*** H2"
3221 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3222 (search-forward "H2")
3223 (org-invisible-p2)))
3224 ;; Comparison operators when matching properties.
3226 (org-test-with-temp-text
3227 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3228 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3229 (search-forward "H1")
3230 (org-invisible-p2)))
3232 (org-test-with-temp-text
3233 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3234 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3235 (search-forward "H2")
3236 (org-invisible-p2)))
3237 ;; Regexp match on properties values.
3239 (org-test-with-temp-text
3240 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3241 (org-match-sparse-tree nil
"A={f.*}")
3242 (search-forward "H1")
3243 (org-invisible-p2)))
3245 (org-test-with-temp-text
3246 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3247 (org-match-sparse-tree nil
"A={f.*}")
3248 (search-forward "H2")
3249 (org-invisible-p2)))
3250 ;; With an optional argument, limit match to TODO entries.
3252 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3253 (org-match-sparse-tree t
"tag")
3254 (search-forward "H1")
3255 (org-invisible-p2)))
3257 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3258 (org-match-sparse-tree t
"tag")
3259 (search-forward "H2")
3260 (org-invisible-p2))))
3265 (ert-deftest test-org
/time-stamp
()
3266 "Test `org-time-stamp' specifications."
3267 ;; Insert chosen time stamp at point.
3270 "Te<2014-03-04 .*?>xt"
3271 (org-test-with-temp-text "Te<point>xt"
3272 (flet ((org-read-date
3274 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3275 (org-time-stamp nil
)
3277 ;; With a prefix argument, also insert time.
3280 "Te<2014-03-04 .*? 00:41>xt"
3281 (org-test-with-temp-text "Te<point>xt"
3282 (flet ((org-read-date
3284 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3285 (org-time-stamp '(4))
3287 ;; With two universal prefix arguments, insert an active timestamp
3288 ;; with the current time without prompting the user.
3291 "Te<2014-03-04 .*? 00:41>xt"
3292 (org-test-with-temp-text "Te<point>xt"
3293 (flet ((current-time
3295 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3296 (org-time-stamp '(16))
3298 ;; When optional argument is non-nil, insert an inactive timestamp.
3301 "Te\\[2014-03-04 .*?\\]xt"
3302 (org-test-with-temp-text "Te<point>xt"
3303 (flet ((org-read-date
3305 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3306 (org-time-stamp nil t
)
3308 ;; When called from a timestamp, replace existing one.
3312 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3313 (flet ((org-read-date
3315 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3316 (org-time-stamp nil
)
3320 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3321 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3322 (flet ((org-read-date
3324 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3325 (org-time-stamp nil
)
3327 ;; When replacing a timestamp, preserve repeater, if any.
3330 "<2014-03-04 .*? \\+2y>"
3331 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3332 (flet ((org-read-date
3334 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3335 (org-time-stamp nil
)
3337 ;; When called twice in a raw, build a date range.
3340 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3341 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3342 (flet ((org-read-date
3344 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3345 (let ((last-command 'org-time-stamp
)
3346 (this-command 'org-time-stamp
))
3347 (org-time-stamp nil
))
3348 (buffer-string))))))
3350 (ert-deftest test-org
/timestamp-has-time-p
()
3351 "Test `org-timestamp-has-time-p' specifications."
3354 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3355 (org-timestamp-has-time-p (org-element-context))))
3358 (org-test-with-temp-text "<2012-03-29 Thu>"
3359 (org-timestamp-has-time-p (org-element-context)))))
3361 (ert-deftest test-org
/timestamp-format
()
3362 "Test `org-timestamp-format' specifications."
3367 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3368 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3373 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3374 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3376 (ert-deftest test-org
/timestamp-split-range
()
3377 "Test `org-timestamp-split-range' specifications."
3378 ;; Extract range start (active).
3381 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3382 (let ((ts (org-timestamp-split-range (org-element-context))))
3383 (mapcar (lambda (p) (org-element-property p ts
))
3384 '(:year-end
:month-end
:day-end
))))))
3385 ;; Extract range start (inactive)
3388 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3389 (let ((ts (org-timestamp-split-range (org-element-context))))
3390 (mapcar (lambda (p) (org-element-property p ts
))
3391 '(:year-end
:month-end
:day-end
))))))
3392 ;; Extract range end (active).
3395 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3396 (let ((ts (org-timestamp-split-range
3397 (org-element-context) t
)))
3398 (mapcar (lambda (p) (org-element-property p ts
))
3399 '(:year-end
:month-end
:day-end
))))))
3400 ;; Extract range end (inactive)
3403 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3404 (let ((ts (org-timestamp-split-range
3405 (org-element-context) t
)))
3406 (mapcar (lambda (p) (org-element-property p ts
))
3407 '(:year-end
:month-end
:day-end
))))))
3408 ;; Return the timestamp if not a range.
3410 (org-test-with-temp-text "[2012-03-29 Thu]"
3411 (let* ((ts-orig (org-element-context))
3412 (ts-copy (org-timestamp-split-range ts-orig
)))
3413 (eq ts-orig ts-copy
))))
3415 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3416 (let* ((ts-orig (org-element-context))
3417 (ts-copy (org-timestamp-split-range ts-orig
)))
3418 (eq ts-orig ts-copy
)))))
3420 (ert-deftest test-org
/timestamp-translate
()
3421 "Test `org-timestamp-translate' specifications."
3422 ;; Translate whole date range.
3425 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3426 (let ((org-display-custom-times t
)
3427 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3428 (org-timestamp-translate (org-element-context))))))
3429 ;; Translate date range start.
3432 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3433 (let ((org-display-custom-times t
)
3434 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3435 (org-timestamp-translate (org-element-context) 'start
)))))
3436 ;; Translate date range end.
3439 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3440 (let ((org-display-custom-times t
)
3441 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3442 (org-timestamp-translate (org-element-context) 'end
)))))
3443 ;; Translate time range.
3446 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3447 (let ((org-display-custom-times t
)
3448 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3449 (org-timestamp-translate (org-element-context))))))
3450 ;; Translate non-range timestamp.
3453 (org-test-with-temp-text "<2012-03-29 Thu>"
3454 (let ((org-display-custom-times t
)
3455 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3456 (org-timestamp-translate (org-element-context))))))
3457 ;; Do not change `diary' timestamps.
3459 (equal "<%%(org-float t 4 2)>"
3460 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3461 (let ((org-display-custom-times t
)
3462 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3463 (org-timestamp-translate (org-element-context)))))))
3469 (ert-deftest test-org
/flag-drawer
()
3470 "Test `org-flag-drawer' specifications."
3473 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3475 (get-char-property (line-end-position) 'invisible
)))
3478 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3480 (org-flag-drawer nil
)
3481 (get-char-property (line-end-position) 'invisible
)))
3482 ;; Test optional argument.
3484 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3485 (let ((drawer (save-excursion (search-forward ":D2")
3486 (org-element-at-point))))
3487 (org-flag-drawer t drawer
)
3488 (get-char-property (progn (search-forward ":D2") (line-end-position))
3491 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3492 (let ((drawer (save-excursion (search-forward ":D2")
3493 (org-element-at-point))))
3494 (org-flag-drawer t drawer
)
3495 (get-char-property (line-end-position) 'invisible
))))
3496 ;; Do not hide fake drawers.
3498 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3501 (get-char-property (line-end-position) 'invisible
)))
3502 ;; Do not hide incomplete drawers.
3504 (org-test-with-temp-text ":D:\nparagraph"
3507 (get-char-property (line-end-position) 'invisible
)))
3508 ;; Do not hide drawers when called from final blank lines.
3510 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3511 (goto-char (point-max))
3513 (goto-char (point-min))
3514 (get-char-property (line-end-position) 'invisible
)))
3515 ;; Don't leave point in an invisible part of the buffer when hiding
3518 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3519 (goto-char (point-max))
3521 (get-char-property (point) 'invisible
))))
3523 (ert-deftest test-org
/hide-block-toggle
()
3524 "Test `org-hide-block-toggle' specifications."
3525 ;; Error when not at a block.
3527 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3528 (org-hide-block-toggle 'off
)
3529 (get-char-property (line-end-position) 'invisible
)))
3532 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3533 (org-hide-block-toggle)
3534 (get-char-property (line-end-position) 'invisible
)))
3536 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3537 (org-hide-block-toggle)
3538 (get-char-property (line-end-position) 'invisible
)))
3539 ;; Show block unconditionally when optional argument is `off'.
3541 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3542 (org-hide-block-toggle)
3543 (org-hide-block-toggle 'off
)
3544 (get-char-property (line-end-position) 'invisible
)))
3546 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3547 (org-hide-block-toggle 'off
)
3548 (get-char-property (line-end-position) 'invisible
)))
3549 ;; Hide block unconditionally when optional argument is non-nil.
3551 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3552 (org-hide-block-toggle t
)
3553 (get-char-property (line-end-position) 'invisible
)))
3555 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3556 (org-hide-block-toggle)
3557 (org-hide-block-toggle t
)
3558 (get-char-property (line-end-position) 'invisible
)))
3559 ;; Do not hide block when called from final blank lines.
3561 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3562 (org-hide-block-toggle)
3563 (goto-char (point-min))
3564 (get-char-property (line-end-position) 'invisible
)))
3565 ;; Don't leave point in an invisible part of the buffer when hiding
3568 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3569 (org-hide-block-toggle)
3570 (get-char-property (point) 'invisible
))))
3572 (ert-deftest test-org
/hide-block-toggle-maybe
()
3573 "Test `org-hide-block-toggle-maybe' specifications."
3575 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3576 (org-hide-block-toggle-maybe)))
3578 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3580 (ert-deftest test-org
/show-set-visibility
()
3581 "Test `org-show-set-visibility' specifications."
3582 ;; Do not throw an error before first heading.
3584 (org-test-with-temp-text "Preamble\n* Headline"
3585 (org-show-set-visibility 'tree
)
3587 ;; Test all visibility spans, both on headline and in entry.
3588 (let ((list-visible-lines
3589 (lambda (state headerp
)
3590 (org-test-with-temp-text "* Grandmother (0)
3601 **** The other child (11)
3606 (search-forward (if headerp
"Self" "Match"))
3607 (org-show-set-visibility state
)
3608 (goto-char (point-min))
3609 (let (result (line 0))
3611 (unless (org-invisible-p2) (push line result
))
3614 (nreverse result
))))))
3615 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
3616 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
3617 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
3618 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
3619 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
3620 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
3621 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
3622 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
3623 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
3624 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3625 (funcall list-visible-lines
'tree nil
)))
3626 (should (equal '(0 1 3 4 5 7 12 13)
3627 (funcall list-visible-lines
'canonical t
)))
3628 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3629 (funcall list-visible-lines
'canonical nil
)))))
3634 ;;; test-org.el ends here