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 diary sexps, footnote definitions or headlines.
584 (org-test-with-temp-text "%%(org-calendar-holiday)"
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))))
594 (org-test-with-temp-text "* H"
596 (org-get-indentation))))
597 ;; Do not indent before first headline.
600 (org-test-with-temp-text ""
602 (org-get-indentation))))
603 ;; Indent according to headline level otherwise, unless
604 ;; `org-adapt-indentation' is nil.
607 (org-test-with-temp-text "* H\nA"
609 (let ((org-adapt-indentation t
)) (org-indent-line))
610 (org-get-indentation))))
613 (org-test-with-temp-text "* H\n\nA"
615 (let ((org-adapt-indentation t
)) (org-indent-line))
616 (org-get-indentation))))
619 (org-test-with-temp-text "* H\nA"
621 (let ((org-adapt-indentation nil
)) (org-indent-line))
622 (org-get-indentation))))
623 ;; Indenting preserves point position.
625 (org-test-with-temp-text "* H\nAB"
628 (let ((org-adapt-indentation t
)) (org-indent-line))
630 ;; Do not change indentation at an item.
633 (org-test-with-temp-text "* H\n - A"
635 (let ((org-adapt-indentation t
)) (org-indent-line))
636 (org-get-indentation))))
637 ;; On blank lines at the end of a list, indent like last element
638 ;; within it if the line is still in the list. Otherwise, indent
639 ;; like the whole list.
642 (org-test-with-temp-text "* H\n- A\n - AA\n"
643 (goto-char (point-max))
644 (let ((org-adapt-indentation t
)) (org-indent-line))
645 (org-get-indentation))))
648 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
649 (goto-char (point-max))
650 (let ((org-adapt-indentation t
)) (org-indent-line))
651 (org-get-indentation))))
652 ;; Likewise, on a blank line at the end of a footnote definition,
653 ;; indent at column 0 if line belongs to the definition. Otherwise,
654 ;; indent like the definition itself.
657 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
658 (goto-char (point-max))
659 (let ((org-adapt-indentation t
)) (org-indent-line))
660 (org-get-indentation))))
663 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
664 (goto-char (point-max))
665 (let ((org-adapt-indentation t
)) (org-indent-line))
666 (org-get-indentation))))
667 ;; After the end of the contents of a greater element, indent like
668 ;; the beginning of the element.
671 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
674 (org-get-indentation))))
675 ;; On blank lines after a paragraph, indent like its last non-empty
679 (org-test-with-temp-text " Paragraph\n\n<point>"
681 (org-get-indentation))))
682 ;; At the first line of an element, indent like previous element's
683 ;; first line, ignoring footnotes definitions and inline tasks, or
684 ;; according to parent.
687 (org-test-with-temp-text "A\n\n B\n\nC"
688 (goto-char (point-max))
690 (org-get-indentation))))
693 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
694 (goto-char (point-max))
696 (org-get-indentation))))
699 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
702 (org-get-indentation))))
703 ;; Within code part of a source block, use language major mode if
704 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
705 ;; according to line above.
708 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
710 (let ((org-src-tab-acts-natively t
)
711 (org-edit-src-content-indentation 0))
713 (org-get-indentation))))
716 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
718 (let ((org-src-tab-acts-natively nil
)
719 (org-edit-src-content-indentation 0))
721 (org-get-indentation))))
722 ;; Otherwise, indent like the first non-blank line above.
725 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
728 (org-get-indentation))))
729 ;; Align node properties according to `org-property-format'. Handle
730 ;; nicely empty values.
732 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
733 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
734 (let ((org-property-format "%-10s %s")) (org-indent-line))
737 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
738 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
739 (let ((org-property-format "%-10s %s")) (org-indent-line))
742 (ert-deftest test-org
/indent-region
()
743 "Test `org-indent-region' specifications."
747 (org-test-with-temp-text " A\nB\n C"
748 (org-indent-region (point-min) (point-max))
750 ;; Indent greater elements along with their contents.
752 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
753 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
754 (org-indent-region (point-min) (point-max))
756 ;; Ignore contents of verse blocks and example blocks.
758 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
759 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
760 (org-indent-region (point-min) (point-max))
763 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
764 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
765 (org-indent-region (point-min) (point-max))
767 ;; Indent according to mode if `org-src-tab-acts-natively' is
768 ;; non-nil. Otherwise, do not indent code at all.
770 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
771 (org-test-with-temp-text
772 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
773 (let ((org-src-tab-acts-natively t
)
774 (org-edit-src-content-indentation 0))
775 (org-indent-region (point-min) (point-max)))
778 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
779 (org-test-with-temp-text
780 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
781 (let ((org-src-tab-acts-natively nil
)
782 (org-edit-src-content-indentation 0))
783 (org-indent-region (point-min) (point-max)))
785 ;; Align node properties according to `org-property-format'. Handle
786 ;; nicely empty values.
788 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
789 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
790 (let ((org-property-format "%-10s %s")
791 (org-adapt-indentation nil
))
792 (org-indent-region (point) (point-max)))
795 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
796 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
797 (let ((org-property-format "%-10s %s")
798 (org-adapt-indentation nil
))
799 (org-indent-region (point) (point-max)))
801 ;; Indent plain lists.
803 (equal "- A\n B\n - C\n\n D"
804 (org-test-with-temp-text "- A\n B\n - C\n\n D"
805 (org-indent-region (point-min) (point-max))
809 (org-test-with-temp-text " - A\n\n - B"
810 (org-indent-region (point-min) (point-max))
812 ;; Indent footnote definitions.
814 (equal "[fn:1] Definition\n\nDefinition"
815 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
816 (org-indent-region (point-min) (point-max))
818 ;; Special case: Start indenting on a blank line.
821 (org-test-with-temp-text "\n Paragraph"
822 (org-indent-region (point-min) (point-max))
829 (ert-deftest test-org
/return
()
830 "Test RET (`org-return') specifications."
834 (org-test-with-temp-text "Para<point>graph"
837 ;; With optional argument, indent line.
839 (equal " Para\n graph"
840 (org-test-with-temp-text " Para<point>graph"
843 ;; On a table, call `org-table-next-row'.
845 (org-test-with-temp-text "| <point>a |\n| b |"
847 (org-looking-at-p "b")))
848 ;; Open link or timestamp under point when `org-return-follows-link'
851 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
852 (let ((org-return-follows-link t
)) (org-return))
853 (org-looking-at-p "<<target>>")))
855 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
856 (let ((org-return-follows-link nil
)) (org-return))
857 (org-looking-at-p "<<target>>")))
858 ;; However, do not open link when point is in a table.
860 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
861 (let ((org-return-follows-link t
)) (org-return))
862 (org-looking-at-p "between")))
863 ;; Special case: in a list, when indenting, do not break structure.
866 (org-test-with-temp-text "- A <point>B"
871 (org-test-with-temp-text "- A\n<point>- B"
874 ;; Special case: on tags part of a headline, add a newline below it
875 ;; instead of breaking it.
878 (org-test-with-temp-text "* H :<point>tag:"
882 (ert-deftest test-org
/meta-return
()
883 "Test M-RET (`org-meta-return') specifications."
884 ;; In a table field insert a row above.
886 (org-test-with-temp-text "| a |"
890 (looking-at "| |$")))
891 ;; In a paragraph change current line into a header.
893 (org-test-with-temp-text "a"
896 (looking-at "\* a$")))
897 ;; In an item insert an item, in this case above.
899 (org-test-with-temp-text "- a"
903 ;; In a drawer and item insert an item, in this case above.
905 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
909 (looking-at "- $"))))
911 (ert-deftest test-org
/insert-heading
()
912 "Test `org-insert-heading' specifications."
913 ;; In an empty buffer, insert a new headline.
916 (org-test-with-temp-text ""
919 ;; At the beginning of a line, turn it into a headline
922 (org-test-with-temp-text "<point>P"
925 ;; In the middle of a line, split the line if allowed, otherwise,
926 ;; insert the headline at its end.
928 (equal "Para\n* graph"
929 (org-test-with-temp-text "Para<point>graph"
930 (let ((org-M-RET-may-split-line '((default . t
))))
931 (org-insert-heading))
934 (equal "Paragraph\n* "
935 (org-test-with-temp-text "Para<point>graph"
936 (let ((org-M-RET-may-split-line '((default . nil
))))
937 (org-insert-heading))
939 ;; When on a list, insert an item instead, unless called with an
940 ;; universal argument or if list is invisible. In this case, create
941 ;; a new headline after contents.
943 (equal "* H\n- item\n- "
944 (org-test-with-temp-text "* H\n- item<point>"
945 (let ((org-insert-heading-respect-content nil
))
946 (org-insert-heading))
949 (equal "* H\n- item\n- item 2\n* "
950 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
951 (let ((org-insert-heading-respect-content nil
))
952 (org-insert-heading '(4)))
955 (equal "* H\n- item\n* "
956 (org-test-with-temp-text "* H\n- item"
958 (goto-char (point-max))
959 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
961 ;; When called with two universal arguments, insert a new headline
962 ;; at the end of the grandparent subtree.
964 (equal "* H1\n** H3\n- item\n** H2\n** "
965 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
966 (let ((org-insert-heading-respect-content nil
))
967 (org-insert-heading '(16)))
969 ;; When optional TOP-LEVEL argument is non-nil, always insert
970 ;; a level 1 heading.
972 (equal "* H1\n** H2\n* "
973 (org-test-with-temp-text "* H1\n** H2<point>"
974 (org-insert-heading nil nil t
)
977 (equal "* H1\n- item\n* "
978 (org-test-with-temp-text "* H1\n- item<point>"
979 (org-insert-heading nil nil t
)
981 ;; Corner case: correctly insert a headline after an empty one.
984 (org-test-with-temp-text "* <point>"
988 (ert-deftest test-org
/insert-todo-heading-respect-content
()
989 "Test `org-insert-todo-heading-respect-content' specifications."
990 ;; Create a TODO heading.
992 (org-test-with-temp-text "* H1\n Body"
993 (org-insert-todo-heading-respect-content)
994 (nth 2 (org-heading-components))))
995 ;; Add headline at the end of the first subtree
997 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
998 (search-forward "H1Body")
999 (org-insert-todo-heading-respect-content)
1000 (and (eobp) (org-at-heading-p))))
1001 ;; In a list, do not create a new item.
1003 (org-test-with-temp-text "* H\n- an item\n- another one"
1004 (search-forward "an ")
1005 (org-insert-todo-heading-respect-content)
1006 (and (eobp) (org-at-heading-p)))))
1010 ;;; Fixed-Width Areas
1012 (ert-deftest test-org
/toggle-fixed-width
()
1013 "Test `org-toggle-fixed-width' specifications."
1014 ;; No region: Toggle on fixed-width marker in paragraphs.
1017 (org-test-with-temp-text "A"
1018 (org-toggle-fixed-width)
1020 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1023 (org-test-with-temp-text ": A"
1024 (org-toggle-fixed-width)
1026 ;; No region: Toggle on marker in blank lines after elements or just
1027 ;; after a headline.
1030 (org-test-with-temp-text "* H\n"
1032 (org-toggle-fixed-width)
1035 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1036 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1037 (goto-char (point-max))
1038 (org-toggle-fixed-width)
1040 ;; No region: Toggle on marker in front of one line elements (e.g.,
1041 ;; headlines, clocks)
1043 (equal ": * Headline"
1044 (org-test-with-temp-text "* Headline"
1045 (org-toggle-fixed-width)
1048 (equal ": #+KEYWORD: value"
1049 (org-test-with-temp-text "#+KEYWORD: value"
1050 (org-toggle-fixed-width)
1052 ;; No region: error in other situations.
1054 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1056 (org-toggle-fixed-width)
1058 ;; No region: Indentation is preserved.
1061 (org-test-with-temp-text "- A\n B"
1063 (org-toggle-fixed-width)
1065 ;; Region: If it contains only fixed-width elements and blank lines,
1066 ;; toggle off fixed-width markup.
1069 (org-test-with-temp-text ": A\n\n: B"
1070 (transient-mark-mode 1)
1071 (push-mark (point) t t
)
1072 (goto-char (point-max))
1073 (org-toggle-fixed-width)
1075 ;; Region: If it contains anything else, toggle on fixed-width but
1076 ;; not on fixed-width areas.
1078 (equal ": A\n: \n: B\n: \n: C"
1079 (org-test-with-temp-text "A\n\n: B\n\nC"
1080 (transient-mark-mode 1)
1081 (push-mark (point) t t
)
1082 (goto-char (point-max))
1083 (org-toggle-fixed-width)
1085 ;; Region: Ignore blank lines at its end, unless it contains only
1089 (org-test-with-temp-text "A\n\n"
1090 (transient-mark-mode 1)
1091 (push-mark (point) t t
)
1092 (goto-char (point-max))
1093 (org-toggle-fixed-width)
1097 (org-test-with-temp-text "\n\n"
1098 (transient-mark-mode 1)
1099 (push-mark (point) t t
)
1100 (goto-char (point-max))
1101 (org-toggle-fixed-width)
1108 (ert-deftest test-org
/in-commented-heading-p
()
1109 "Test `org-in-commented-heading-p' specifications."
1110 ;; Commented headline.
1112 (org-test-with-temp-text "* COMMENT Headline\nBody"
1113 (goto-char (point-max))
1114 (org-in-commented-heading-p)))
1115 ;; Commented ancestor.
1117 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1118 (goto-char (point-max))
1119 (org-in-commented-heading-p)))
1120 ;; Comment keyword is case-sensitive.
1122 (org-test-with-temp-text "* Comment Headline\nBody"
1123 (goto-char (point-max))
1124 (org-in-commented-heading-p)))
1125 ;; Keyword is standalone.
1127 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1128 (goto-char (point-max))
1129 (org-in-commented-heading-p)))
1130 ;; Optional argument.
1132 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1133 (goto-char (point-max))
1134 (org-in-commented-heading-p t
))))
1140 (ert-deftest test-org
/set-regexps-and-options
()
1141 "Test `org-set-regexps-and-options' specifications."
1144 (equal '(("A" . ?a
) ("B") ("C"))
1145 (org-test-with-temp-text "#+TAGS: A(a) B C"
1149 (equal '(("A") (:newline
) ("B"))
1150 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1154 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1155 (org-test-with-temp-text "#+TAGS: { A B } C"
1159 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1160 (org-test-with-temp-text "#+TAGS: { A : B C }"
1164 (equal '(("A" "B" "C"))
1165 (org-test-with-temp-text "#+TAGS: { A : B C }"
1167 org-tag-groups-alist
)))
1169 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1170 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1174 (equal '(("A" "B" "C"))
1175 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1177 org-tag-groups-alist
)))
1178 ;; FILETAGS keyword.
1180 (equal '("A" "B" "C")
1181 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1184 ;; PROPERTY keyword. Property names are case-insensitive.
1187 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1189 (cdr (assoc "var" org-file-properties
)))))
1193 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1195 (cdr (assoc "var" org-file-properties
)))))
1199 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1201 (cdr (assoc "var" org-file-properties
)))))
1205 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1207 org-archive-location
)))
1208 ;; CATEGORY keyword.
1211 (org-test-with-temp-text "#+CATEGORY: test"
1216 (org-test-with-temp-text "#+CATEGORY: test"
1218 (cdr (assoc "CATEGORY" org-file-properties
)))))
1221 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1222 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1224 org-columns-default-format
)))
1225 ;; CONSTANTS keyword. Constants names are case sensitive.
1227 (equal '("299792458." "3.14")
1228 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1231 (lambda (n) (cdr (assoc n 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
)))))
1240 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1242 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1247 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1249 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1251 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1255 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1257 (list org-highest-priority org-lowest-priority org-default-priority
))))
1261 (org-test-with-temp-text "#+PRIORITIES: X Z"
1263 (list org-highest-priority org-lowest-priority org-default-priority
))))
1267 (org-test-with-temp-text "#+STARTUP: fold odd"
1269 (list org-startup-folded org-odd-levels-only
))))
1272 (equal '(("A" "B") ("C"))
1273 (org-test-with-temp-text "#+TODO: A B | C"
1275 (list org-not-done-keywords org-done-keywords
))))
1277 (equal '(("A" "C") ("B" "D"))
1278 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1280 (list org-not-done-keywords org-done-keywords
))))
1282 (equal '(("A" "B") ("C"))
1283 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1285 (list org-not-done-keywords org-done-keywords
))))
1287 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1288 (org-test-with-temp-text "#+TODO: A(a)"
1290 org-todo-key-alist
)))
1292 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1293 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1295 org-todo-log-states
)))
1296 ;; Enter SETUPFILE keyword.
1299 (org-test-with-temp-text
1300 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1302 (cdr (assoc "a" org-file-properties
))))))
1310 (ert-deftest test-org
/coderef
()
1311 "Test coderef links specifications."
1313 (org-test-with-temp-text "
1314 #+BEGIN_SRC emacs-lisp
1318 (goto-char (point-max))
1320 (looking-at "(ref:sc)"))))
1324 (ert-deftest test-org
/custom-id
()
1325 "Test custom ID links specifications."
1327 (org-test-with-temp-text
1328 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1329 (goto-char (point-max))
1331 (org-looking-at-p "\\* H1")))
1332 ;; Ignore false positives.
1334 (org-test-with-temp-text
1335 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1336 (goto-char (point-max))
1337 (let (org-link-search-must-match-exact-headline) (org-open-at-point))
1338 (org-looking-at-p "\\* H1"))))
1342 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1343 ;; a named element (#+name: text) and to headlines (* Text).
1345 (ert-deftest test-org
/fuzzy-links
()
1346 "Test fuzzy links specifications."
1347 ;; Fuzzy link goes in priority to a matching target.
1349 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1352 (looking-at "<<Test>>")))
1353 ;; Then fuzzy link points to an element with a given name.
1355 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1358 (looking-at "#\\+NAME: Test")))
1359 ;; A target still lead to a matching headline otherwise.
1361 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1364 (looking-at "\\* Head2")))
1365 ;; With a leading star in link, enforce heading match.
1367 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1370 (looking-at "\\* Test")))
1371 ;; With a leading star in link, enforce exact heading match, even
1372 ;; with `org-link-search-must-match-exact-headline' set to nil.
1374 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1375 (let ((org-link-search-must-match-exact-headline nil
))
1376 (org-open-at-point))))
1377 ;; Heading match should not care about spaces, cookies, todo
1378 ;; keywords, priorities, and tags.
1381 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1382 (org-test-with-temp-text
1383 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1384 (let ((org-link-search-must-match-exact-headline nil
)
1385 (org-todo-regexp "TODO"))
1386 (org-open-at-point))
1387 (looking-at (regexp-quote first-line
)))))
1388 ;; Heading match should still be exact.
1391 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1392 (org-test-with-temp-text
1393 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1394 (let ((org-link-search-must-match-exact-headline nil
)
1395 (org-todo-regexp "TODO"))
1396 (org-open-at-point)))))
1397 ;; Heading match ignores COMMENT keyword.
1399 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1401 (looking-at "\\* COMMENT Test")))
1402 ;; Correctly un-hexify fuzzy links.
1404 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1405 (goto-char (point-max))
1411 (ert-deftest test-org
/org-link-escape-ascii-character
()
1412 "Escape an ascii character."
1416 (org-link-escape "["))))
1418 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1419 "Escape an ascii control character."
1423 (org-link-escape "\t"))))
1425 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1426 "Escape an unicode multibyte character."
1430 (org-link-escape "€"))))
1432 (ert-deftest test-org
/org-link-escape-custom-table
()
1433 "Escape string with custom character table."
1437 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1439 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1440 "Escape string with custom table merged with default table."
1443 "%5BF%6F%6F%3A%42ar%0A%5D"
1444 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1446 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1447 "Unescape an ascii character."
1451 (org-link-unescape "%5B"))))
1453 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1454 "Unescpae an ascii control character."
1458 (org-link-unescape "%0A"))))
1460 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1461 "Unescape unicode multibyte character."
1465 (org-link-unescape "%E2%82%AC"))))
1467 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1468 "Unescape old style percent escaped character."
1471 "à âçèéêîôùû"
1472 (decode-coding-string
1473 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1475 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1476 "Escape and unescape a URL that includes an escaped char.
1477 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1480 "http://some.host.com/form?&id=blah%2Bblah25"
1482 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1484 (ert-deftest test-org
/org-link-escape-chars-browser
()
1485 "Test of the constant `org-link-escape-chars-browser'.
1486 See there why this test is a candidate to be removed once Org
1487 drops support for Emacs 24.1 and 24.2."
1490 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1491 "%22Release%208.2%22&idxname=emacs-orgmode")
1492 (org-link-escape-browser ; Do not replace with `url-encode-url',
1493 ; see docstring above.
1494 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1495 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1499 (ert-deftest test-org
/open-at-point-in-property
()
1500 "Does `org-open-at-point' open link in property drawer?"
1502 (org-test-with-temp-text
1505 :URL: <point>[[info:emacs#Top]]
1507 (org-open-at-point) t
)))
1509 (ert-deftest test-org
/open-at-point-in-comment
()
1510 "Does `org-open-at-point' open link in a commented line?"
1512 (org-test-with-temp-text
1513 "# <point>[[info:emacs#Top]]"
1514 (org-open-at-point) t
)))
1516 (ert-deftest test-org
/open-at-point
/info
()
1517 "Test `org-open-at-point' on info links."
1519 (org-test-with-temp-text
1520 "<point>[[info:emacs#Top]]"
1522 (and (switch-to-buffer "*info*")
1524 (looking-at "\nThe Emacs Editor")
1527 (ert-deftest test-org
/open-at-point
/inline-image
()
1528 "Test `org-open-at-point' on nested links."
1530 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1532 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1533 (kill-buffer "*info*")))))
1538 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1539 "Ensure properties accumulate in subtree drawers."
1540 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1541 (org-babel-next-src-block)
1542 (should (equal '(2 1) (org-babel-execute-src-block)))))
1544 (ert-deftest test-org
/custom-properties
()
1545 "Test custom properties specifications."
1548 (let ((org-custom-properties '("FOO")))
1549 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1550 (org-toggle-custom-properties-visibility)
1551 (org-invisible-p2))))
1552 ;; Properties are case-insensitive.
1554 (let ((org-custom-properties '("FOO")))
1555 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1556 (org-toggle-custom-properties-visibility)
1557 (org-invisible-p2))))
1559 (let ((org-custom-properties '("foo")))
1560 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1561 (org-toggle-custom-properties-visibility)
1562 (org-invisible-p2))))
1563 ;; Multiple custom properties in the same drawer.
1565 (let ((org-custom-properties '("FOO" "BAR")))
1566 (org-test-with-temp-text
1567 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1568 (org-toggle-custom-properties-visibility)
1569 (and (org-invisible-p2)
1570 (not (progn (forward-line) (org-invisible-p2)))
1571 (progn (forward-line) (org-invisible-p2))))))
1572 ;; Hide custom properties with an empty value.
1574 (let ((org-custom-properties '("FOO")))
1575 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1576 (org-toggle-custom-properties-visibility)
1577 (org-invisible-p2))))
1578 ;; Do not hide fake properties.
1580 (let ((org-custom-properties '("FOO")))
1581 (org-test-with-temp-text ":FOO: val\n"
1582 (org-toggle-custom-properties-visibility)
1583 (org-invisible-p2))))
1585 (let ((org-custom-properties '("A")))
1586 (org-test-with-temp-text
1587 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1588 (org-toggle-custom-properties-visibility)
1589 (org-invisible-p2)))))
1595 (ert-deftest test-org
/mark-subtree
()
1596 "Test `org-mark-subtree' specifications."
1597 ;; Error when point is before first headline.
1599 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1600 (progn (transient-mark-mode 1)
1601 (org-mark-subtree))))
1602 ;; Without argument, mark current subtree.
1606 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1607 (progn (transient-mark-mode 1)
1610 (list (region-beginning) (region-end))))))
1611 ;; With an argument, move ARG up.
1615 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1616 (progn (transient-mark-mode 1)
1618 (org-mark-subtree 1)
1619 (list (region-beginning) (region-end))))))
1620 ;; Do not get fooled by inlinetasks.
1621 (when (featurep 'org-inlinetask
)
1624 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1625 (progn (transient-mark-mode 1)
1627 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1628 (region-beginning)))))))
1634 (ert-deftest test-org
/end-of-meta-data
()
1635 "Test `org-end-of-meta-data' specifications."
1636 ;; Skip planning line.
1638 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1639 (org-end-of-meta-data)
1641 ;; Skip properties drawer.
1643 (org-test-with-temp-text
1644 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1645 (org-end-of-meta-data)
1649 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1650 (org-end-of-meta-data)
1652 ;; Nothing to skip, go to first line.
1654 (org-test-with-temp-text "* Headline\nContents"
1655 (org-end-of-meta-data)
1656 (looking-at "Contents")))
1657 ;; With option argument, skip empty lines, regular drawers and
1660 (org-test-with-temp-text "* Headline\n\nContents"
1661 (org-end-of-meta-data t
)
1662 (looking-at "Contents")))
1664 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1665 (org-end-of-meta-data t
)
1666 (looking-at "Contents")))
1668 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1669 (org-end-of-meta-data t
)
1670 (looking-at "Contents")))
1671 ;; Special case: do not skip incomplete drawers.
1673 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1674 (org-end-of-meta-data t
)
1675 (looking-at ":LOGBOOK:")))
1676 ;; Special case: Be careful about consecutive headlines.
1678 (org-test-with-temp-text "* H1\n*H2\nContents"
1679 (org-end-of-meta-data t
)
1680 (looking-at "Contents"))))
1682 (ert-deftest test-org
/beginning-of-line
()
1683 "Test `org-beginning-of-line' specifications."
1686 (org-test-with-temp-text "Some text\nSome other text"
1687 (progn (org-beginning-of-line) (bolp))))
1688 ;; Standard test with `visual-line-mode'.
1690 (org-test-with-temp-text "A long line of text\nSome other text"
1691 (progn (visual-line-mode)
1693 (dotimes (i 1000) (insert "very "))
1694 (org-beginning-of-line)
1696 ;; At an headline with special movement.
1698 (org-test-with-temp-text "* TODO Headline"
1699 (let ((org-special-ctrl-a/e t
))
1701 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1702 (progn (org-beginning-of-line) (bolp))
1703 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1705 (ert-deftest test-org
/end-of-line
()
1706 "Test `org-end-of-line' specifications."
1709 (org-test-with-temp-text "Some text\nSome other text"
1710 (progn (org-end-of-line) (eolp))))
1711 ;; Standard test with `visual-line-mode'.
1713 (org-test-with-temp-text "A long line of text\nSome other text"
1714 (progn (visual-line-mode)
1716 (dotimes (i 1000) (insert "very "))
1717 (goto-char (point-min))
1720 ;; At an headline with special movement.
1722 (org-test-with-temp-text "* Headline1 :tag:\n"
1723 (let ((org-special-ctrl-a/e t
))
1724 (and (progn (org-end-of-line) (looking-at " :tag:"))
1725 (progn (org-end-of-line) (eolp))
1726 (progn (org-end-of-line) (looking-at " :tag:"))))))
1727 ;; At an headline without special movement.
1729 (org-test-with-temp-text "* Headline2 :tag:\n"
1730 (let ((org-special-ctrl-a/e nil
))
1731 (and (progn (org-end-of-line) (eolp))
1732 (progn (org-end-of-line) (eolp))))))
1733 ;; At an headline, with reversed movement.
1735 (org-test-with-temp-text "* Headline3 :tag:\n"
1736 (let ((org-special-ctrl-a/e
'reversed
)
1737 (this-command last-command
))
1738 (and (progn (org-end-of-line) (eolp))
1739 (progn (org-end-of-line) (looking-at " :tag:"))))))
1740 ;; At a block without hidden contents.
1742 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1743 (progn (org-end-of-line) (eolp))))
1744 ;; At a block with hidden contents.
1746 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1747 (let ((org-special-ctrl-a/e t
))
1748 (org-hide-block-toggle)
1752 (ert-deftest test-org
/forward-sentence
()
1753 "Test `org-forward-sentence' specifications."
1754 ;; At the end of a table cell, move to the end of the next one.
1756 (org-test-with-temp-text "| a<point> | b |"
1757 (org-forward-sentence)
1758 (looking-at " |$")))
1759 ;; Elsewhere in a cell, move to its end.
1761 (org-test-with-temp-text "| a<point>c | b |"
1762 (org-forward-sentence)
1763 (looking-at " | b |$")))
1764 ;; Otherwise, simply call `forward-sentence'.
1766 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1767 (org-forward-sentence)
1768 (looking-at " Sentence 2.")))
1770 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1771 (org-forward-sentence)
1772 (org-forward-sentence)
1774 ;; At the end of an element, jump to the next one, without stopping
1775 ;; on blank lines in-between.
1777 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
1778 (org-forward-sentence)
1781 (ert-deftest test-org
/backward-sentence
()
1782 "Test `org-backward-sentence' specifications."
1783 ;; At the beginning of a table cell, move to the beginning of the
1786 (org-test-with-temp-text "| a | <point>b |"
1787 (org-backward-sentence)
1788 (looking-at "a | b |$")))
1789 ;; Elsewhere in a cell, move to its beginning.
1791 (org-test-with-temp-text "| a | b<point>c |"
1792 (org-backward-sentence)
1793 (looking-at "bc |$")))
1794 ;; Otherwise, simply call `backward-sentence'.
1796 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1797 (org-backward-sentence)
1798 (looking-at "Sentence 2.")))
1800 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1801 (org-backward-sentence)
1802 (org-backward-sentence)
1804 ;; Make sure to hit the beginning of a sentence on the same line as
1807 (org-test-with-temp-text "- Line 1\n line <point>2."
1808 (org-backward-sentence)
1809 (looking-at "Line 1"))))
1811 (ert-deftest test-org
/forward-paragraph
()
1812 "Test `org-forward-paragraph' specifications."
1813 ;; At end of buffer, return an error.
1815 (org-test-with-temp-text "Paragraph"
1816 (goto-char (point-max))
1817 (org-forward-paragraph)))
1820 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1821 (org-forward-paragraph)
1825 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1826 (org-forward-paragraph)
1828 ;; Do not enter elements with invisible contents.
1830 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1831 (org-hide-block-toggle)
1832 (org-forward-paragraph)
1834 ;; On an affiliated keyword, jump to the beginning of the element.
1836 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1837 (org-forward-paragraph)
1838 (looking-at "Para")))
1839 ;; On an item or a footnote definition, move to the second element
1842 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1843 (org-forward-paragraph)
1844 (looking-at " Paragraph")))
1846 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1847 (org-forward-paragraph)
1848 (looking-at "Paragraph")))
1849 ;; On an item, or a footnote definition, when the first line is
1850 ;; empty, move to the first item.
1852 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1853 (org-forward-paragraph)
1854 (looking-at " Paragraph")))
1856 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1857 (org-forward-paragraph)
1858 (looking-at "Paragraph")))
1859 ;; On a table (resp. a property drawer) do not move through table
1860 ;; rows (resp. node properties).
1862 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1863 (org-forward-paragraph)
1864 (looking-at "Paragraph")))
1866 (org-test-with-temp-text
1867 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1868 (org-forward-paragraph)
1869 (looking-at "Paragraph")))
1870 ;; On a verse or source block, stop after blank lines.
1872 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1873 (org-forward-paragraph)
1876 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1877 (org-forward-paragraph)
1878 (looking-at "L2"))))
1880 (ert-deftest test-org
/backward-paragraph
()
1881 "Test `org-backward-paragraph' specifications."
1882 ;; Error at beginning of buffer.
1884 (org-test-with-temp-text "Paragraph"
1885 (org-backward-paragraph)))
1888 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1889 (goto-char (point-max))
1890 (org-backward-paragraph)
1893 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1894 (goto-char (point-max))
1896 (org-backward-paragraph)
1900 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1901 (goto-char (point-max))
1903 (org-backward-paragraph)
1905 ;; Ignore invisible elements.
1907 (org-test-with-temp-text "* H1\n P1\n* H2"
1909 (goto-char (point-max))
1911 (org-backward-paragraph)
1913 ;; On an affiliated keyword, jump to the first one.
1915 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1916 (search-forward "c2")
1917 (org-backward-paragraph)
1918 (looking-at "#\\+name")))
1919 ;; On the second element in an item or a footnote definition, jump
1920 ;; to item or the definition.
1922 (org-test-with-temp-text "- line1\n\n line2"
1923 (goto-char (point-max))
1925 (org-backward-paragraph)
1926 (looking-at "- line1")))
1928 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1929 (goto-char (point-max))
1931 (org-backward-paragraph)
1932 (looking-at "\\[fn:1\\] line1")))
1933 ;; On a table (resp. a property drawer), ignore table rows
1934 ;; (resp. node properties).
1936 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1937 (goto-char (point-max))
1939 (org-backward-paragraph)
1942 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1943 (org-backward-paragraph)
1944 (looking-at ":PROPERTIES:")))
1945 ;; On a source or verse block, stop before blank lines.
1947 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1948 (search-forward "L3")
1950 (org-backward-paragraph)
1953 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1954 (search-forward "L3")
1956 (org-backward-paragraph)
1957 (looking-at "L2"))))
1959 (ert-deftest test-org
/forward-element
()
1960 "Test `org-forward-element' specifications."
1961 ;; 1. At EOB: should error.
1962 (org-test-with-temp-text "Some text\n"
1963 (goto-char (point-max))
1964 (should-error (org-forward-element)))
1965 ;; 2. Standard move: expected to ignore blank lines.
1966 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1967 (org-forward-element)
1968 (should (looking-at (regexp-quote "Second paragraph."))))
1969 ;; 3. Headline tests.
1970 (org-test-with-temp-text "
1975 ;; 3.1. At an headline beginning: move to next headline at the
1978 (org-forward-element)
1979 (should (looking-at (regexp-quote "** Head 1.2")))
1980 ;; 3.2. At an headline beginning: move to parent headline if no
1981 ;; headline at the same level.
1983 (org-forward-element)
1984 (should (looking-at (regexp-quote "** Head 1.2"))))
1985 ;; 4. Greater element tests.
1986 (org-test-with-temp-text
1987 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1988 ;; 4.1. At a greater element: expected to skip contents.
1989 (org-forward-element)
1990 (should (looking-at (regexp-quote "Outside.")))
1991 ;; 4.2. At the end of greater element contents: expected to skip
1992 ;; to the end of the greater element.
1994 (org-forward-element)
1995 (should (looking-at (regexp-quote "Outside."))))
1997 (org-test-with-temp-text "
2011 ;; 5.1. At list top point: expected to move to the element after
2014 (org-forward-element)
2015 (should (looking-at (regexp-quote "Outside.")))
2016 ;; 5.2. Special case: at the first line of a sub-list, but not at
2017 ;; beginning of line, move to next item.
2020 (org-forward-element)
2021 (should (looking-at "- item2"))
2024 (org-forward-element)
2025 (should (looking-at " - sub2"))
2026 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2028 (org-forward-element)
2029 (should (looking-at (regexp-quote " Inner paragraph.")))
2030 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2032 (org-forward-element)
2033 (should (looking-at (regexp-quote " Inner paragraph.")))
2034 ;; 5.5. At an item: expected to move to next item, if any.
2036 (org-forward-element)
2037 (should (looking-at " - sub3"))))
2039 (ert-deftest test-org
/backward-element
()
2040 "Test `org-backward-element' specifications."
2041 ;; 1. Should error at BOB.
2042 (org-test-with-temp-text " \nParagraph."
2043 (should-error (org-backward-element)))
2044 ;; 2. Should move at BOB when called on the first element in buffer.
2046 (org-test-with-temp-text "\n#+TITLE: test"
2047 (progn (forward-line)
2048 (org-backward-element)
2050 ;; 3. Not at the beginning of an element: move at its beginning.
2051 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2054 (org-backward-element)
2055 (should (looking-at (regexp-quote "Paragraph2."))))
2056 ;; 4. Headline tests.
2057 (org-test-with-temp-text "
2062 ;; 4.1. At an headline beginning: move to previous headline at the
2065 (org-backward-element)
2066 (should (looking-at (regexp-quote "** Head 1.1")))
2067 ;; 4.2. At an headline beginning: move to parent headline if no
2068 ;; headline at the same level.
2070 (org-backward-element)
2071 (should (looking-at (regexp-quote "* Head 1")))
2072 ;; 4.3. At the first top-level headline: should error.
2074 (should-error (org-backward-element)))
2075 ;; 5. At beginning of first element inside a greater element:
2076 ;; expected to move to greater element's beginning.
2077 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2079 (org-backward-element)
2080 (should (looking-at "#\\+BEGIN_CENTER")))
2081 ;; 6. At the beginning of the first element in a section: should
2082 ;; move back to headline, if any.
2084 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2085 (progn (goto-char (point-max))
2087 (org-backward-element)
2088 (org-at-heading-p))))
2090 (org-test-with-temp-text "
2105 ;; 7.1. At beginning of sub-list: expected to move to the
2106 ;; paragraph before it.
2108 (org-backward-element)
2109 (should (looking-at "item1"))
2110 ;; 7.2. At an item in a list: expected to move at previous item.
2112 (org-backward-element)
2113 (should (looking-at " - sub2"))
2115 (org-backward-element)
2116 (should (looking-at "- item1"))
2117 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2120 (org-backward-element)
2121 (should (looking-at " - sub1"))
2123 (org-backward-element)
2124 (should (looking-at "- item1"))
2125 ;; 7.4. At blank-lines before list end: expected to move to top
2128 (org-backward-element)
2129 (should (looking-at "- item1"))))
2131 (ert-deftest test-org
/up-element
()
2132 "Test `org-up-element' specifications."
2133 ;; 1. At BOB or with no surrounding element: should error.
2134 (org-test-with-temp-text "Paragraph."
2135 (should-error (org-up-element)))
2136 (org-test-with-temp-text "* Head1\n* Head2"
2138 (should-error (org-up-element)))
2139 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2141 (should-error (org-up-element)))
2142 ;; 2. At an headline: move to parent headline.
2143 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2146 (should (looking-at "\\* Head1")))
2147 ;; 3. Inside a greater element: move to greater element beginning.
2148 (org-test-with-temp-text
2149 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2152 (should (looking-at "#\\+BEGIN_CENTER")))
2154 (org-test-with-temp-text "* Top
2161 Paragraph within sub2.
2164 ;; 4.1. Within an item: move to the item beginning.
2167 (should (looking-at " - sub2"))
2168 ;; 4.2. At an item in a sub-list: move to parent item.
2171 (should (looking-at "- item1"))
2172 ;; 4.3. At an item in top list: move to beginning of whole list.
2175 (should (looking-at "- item1"))
2176 ;; 4.4. Special case. At very top point: should move to parent of
2180 (should (looking-at "\\* Top"))))
2182 (ert-deftest test-org
/down-element
()
2183 "Test `org-down-element' specifications."
2184 ;; Error when the element hasn't got a recursive type.
2185 (org-test-with-temp-text "Paragraph."
2186 (should-error (org-down-element)))
2187 ;; Error when the element has no contents
2188 (org-test-with-temp-text "* Headline"
2189 (should-error (org-down-element)))
2190 ;; When at a plain-list, move to first item.
2191 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2194 (should (looking-at " - Item 1.1")))
2195 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2197 (should (looking-at " Item 1")))
2198 ;; When at a table, move to first row
2199 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2201 (should (looking-at " a | b |")))
2202 ;; Otherwise, move inside the greater element.
2203 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2205 (should (looking-at "Paragraph"))))
2207 (ert-deftest test-org
/drag-element-backward
()
2208 "Test `org-drag-element-backward' specifications."
2212 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2213 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2214 (org-drag-element-backward)
2218 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2219 (org-test-with-temp-text
2220 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2221 (org-drag-element-backward)
2223 ;; Preserve blank lines.
2225 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2226 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2227 (org-drag-element-backward)
2231 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2232 (org-drag-element-backward)
2233 (org-looking-at-p "2")))
2234 ;; Error when trying to move first element of buffer.
2236 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2237 (org-drag-element-backward)))
2238 ;; Error when trying to swap nested elements.
2240 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2242 (org-drag-element-backward)))
2243 ;; Error when trying to swap an headline element and a non-headline
2246 (org-test-with-temp-text "Test.\n* Head 1"
2248 (org-drag-element-backward)))
2249 ;; Preserve visibility of elements and their contents.
2251 (equal '((63 .
82) (26 .
48))
2252 (org-test-with-temp-text "
2260 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2261 (search-backward "- item 1")
2262 (org-drag-element-backward)
2263 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2264 (overlays-in (point-min) (point-max)))))))
2266 (ert-deftest test-org
/drag-element-forward
()
2267 "Test `org-drag-element-forward' specifications."
2268 ;; 1. Error when trying to move first element of buffer.
2269 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2271 (should-error (org-drag-element-forward)))
2272 ;; 2. Error when trying to swap nested elements.
2273 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2275 (should-error (org-drag-element-forward)))
2276 ;; 3. Error when trying to swap a non-headline element and an
2278 (org-test-with-temp-text "Test.\n* Head 1"
2279 (should-error (org-drag-element-forward)))
2280 ;; 4. Otherwise, swap elements, preserving column and blank lines
2281 ;; between elements.
2282 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2283 (search-forward "graph")
2284 (org-drag-element-forward)
2285 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2286 (should (looking-at " 1")))
2287 ;; 5. Preserve visibility of elements and their contents.
2288 (org-test-with-temp-text "
2296 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2297 (search-backward "#+BEGIN_CENTER")
2298 (org-drag-element-forward)
2301 '((63 .
82) (26 .
48))
2302 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2303 (overlays-in (point-min) (point-max)))))))
2306 ;;; Outline structure
2308 (ert-deftest test-org
/demote
()
2309 "Test `org-demote' specifications."
2310 ;; Add correct number of stars according to `org-odd-levels-only'.
2313 (org-test-with-temp-text "* H"
2314 (let ((org-odd-levels-only nil
)) (org-demote))
2315 (org-current-level))))
2318 (org-test-with-temp-text "* H"
2319 (let ((org-odd-levels-only t
)) (org-demote))
2320 (org-current-level))))
2321 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2323 (org-test-with-temp-text "* H :tag:"
2324 (let ((org-tags-column 10)
2325 (org-auto-align-tags t
)
2326 (org-odd-levels-only nil
))
2328 (org-move-to-column 10)
2329 (org-looking-at-p ":tag:$")))
2331 (org-test-with-temp-text "* H :tag:"
2332 (let ((org-tags-column 10)
2333 (org-auto-align-tags nil
)
2334 (org-odd-levels-only nil
))
2336 (org-move-to-column 10)
2337 (org-looking-at-p ":tag:$")))
2338 ;; When `org-adapt-indentation' is non-nil, always indent planning
2339 ;; info and property drawers accordingly.
2342 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2343 (let ((org-odd-levels-only nil
)
2344 (org-adapt-indentation t
))
2347 (org-get-indentation))))
2350 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2351 (let ((org-odd-levels-only nil
)
2352 (org-adapt-indentation t
))
2355 (org-get-indentation))))
2358 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2359 (let ((org-odd-levels-only nil
)
2360 (org-adapt-indentation nil
))
2363 (org-get-indentation))))
2364 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2365 ;; section accordingly. Ignore, however, footnote definitions and
2366 ;; inlinetasks boundaries.
2369 (org-test-with-temp-text "* H\n Paragraph"
2370 (let ((org-odd-levels-only nil
)
2371 (org-adapt-indentation t
))
2374 (org-get-indentation))))
2377 (org-test-with-temp-text "* H\n Paragraph"
2378 (let ((org-odd-levels-only nil
)
2379 (org-adapt-indentation nil
))
2382 (org-get-indentation))))
2385 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2386 (let ((org-odd-levels-only nil
)
2387 (org-adapt-indentation t
))
2389 (goto-char (point-max))
2390 (org-get-indentation))))
2393 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2394 (let ((org-odd-levels-only nil
)
2395 (org-adapt-indentation t
))
2397 (goto-char (point-max))
2398 (org-get-indentation))))
2399 (when (featurep 'org-inlinetask
)
2402 (let ((org-inlinetask-min-level 5)
2403 (org-adapt-indentation t
))
2404 (org-test-with-temp-text "* H\n***** I\n***** END"
2407 (org-get-indentation))))))
2408 (when (featurep 'org-inlinetask
)
2411 (let ((org-inlinetask-min-level 5)
2412 (org-adapt-indentation t
))
2413 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2416 (org-get-indentation))))))
2417 ;; Ignore contents of source blocks or example blocks when
2418 ;; indentation should be preserved (through
2419 ;; `org-src-preserve-indentation' or "-i" flag).
2422 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2423 (let ((org-adapt-indentation t
)
2424 (org-src-preserve-indentation nil
))
2427 (org-get-indentation))))
2430 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2431 (let ((org-adapt-indentation t
)
2432 (org-src-preserve-indentation t
))
2435 (org-get-indentation))))
2438 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2439 (let ((org-adapt-indentation t
)
2440 (org-src-preserve-indentation t
))
2443 (org-get-indentation))))
2446 (org-test-with-temp-text
2447 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2448 (let ((org-adapt-indentation t
)
2449 (org-src-preserve-indentation nil
))
2452 (org-get-indentation)))))
2454 (ert-deftest test-org
/promote
()
2455 "Test `org-promote' specifications."
2456 ;; Return an error if headline is to be promoted to level 0, unless
2457 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2458 ;; headline becomes a comment.
2460 (org-test-with-temp-text "* H"
2461 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2464 (org-test-with-temp-text "* H"
2465 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2467 ;; Remove correct number of stars according to
2468 ;; `org-odd-levels-only'.
2471 (org-test-with-temp-text "*** H"
2472 (let ((org-odd-levels-only nil
)) (org-promote))
2473 (org-current-level))))
2476 (org-test-with-temp-text "*** H"
2477 (let ((org-odd-levels-only t
)) (org-promote))
2478 (org-current-level))))
2479 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2481 (org-test-with-temp-text "** H :tag:"
2482 (let ((org-tags-column 10)
2483 (org-auto-align-tags t
)
2484 (org-odd-levels-only nil
))
2486 (org-move-to-column 10)
2487 (org-looking-at-p ":tag:$")))
2489 (org-test-with-temp-text "** H :tag:"
2490 (let ((org-tags-column 10)
2491 (org-auto-align-tags nil
)
2492 (org-odd-levels-only nil
))
2494 (org-move-to-column 10)
2495 (org-looking-at-p ":tag:$")))
2496 ;; When `org-adapt-indentation' is non-nil, always indent planning
2497 ;; info and property drawers.
2500 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2501 (let ((org-odd-levels-only nil
)
2502 (org-adapt-indentation t
))
2505 (org-get-indentation))))
2508 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2509 (let ((org-odd-levels-only nil
)
2510 (org-adapt-indentation t
))
2513 (org-get-indentation))))
2516 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2517 (let ((org-odd-levels-only nil
)
2518 (org-adapt-indentation nil
))
2521 (org-get-indentation))))
2522 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2523 ;; section accordingly. Ignore, however, footnote definitions and
2524 ;; inlinetasks boundaries.
2527 (org-test-with-temp-text "** H\n Paragraph"
2528 (let ((org-odd-levels-only nil
)
2529 (org-adapt-indentation t
))
2532 (org-get-indentation))))
2535 (org-test-with-temp-text "** H\n Paragraph"
2536 (let ((org-odd-levels-only nil
)
2537 (org-adapt-indentation nil
))
2540 (org-get-indentation))))
2543 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2544 (let ((org-odd-levels-only nil
)
2545 (org-adapt-indentation t
))
2548 (org-get-indentation))))
2549 (when (featurep 'org-inlinetask
)
2552 (let ((org-inlinetask-min-level 5)
2553 (org-adapt-indentation t
))
2554 (org-test-with-temp-text "** H\n***** I\n***** END"
2557 (org-get-indentation))))))
2558 (when (featurep 'org-inlinetask
)
2561 (let ((org-inlinetask-min-level 5)
2562 (org-adapt-indentation t
))
2563 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2566 (org-get-indentation))))))
2567 ;; Give up shifting if it would break document's structure
2571 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2572 (let ((org-odd-levels-only nil
)
2573 (org-adapt-indentation t
))
2576 (org-get-indentation))))
2579 (org-test-with-temp-text "** H\n Paragraph\n * list."
2580 (let ((org-odd-levels-only nil
)
2581 (org-adapt-indentation t
))
2584 (org-get-indentation))))
2585 ;; Ignore contents of source blocks or example blocks when
2586 ;; indentation should be preserved (through
2587 ;; `org-src-preserve-indentation' or "-i" flag).
2590 (org-test-with-temp-text
2591 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2592 (let ((org-adapt-indentation t
)
2593 (org-src-preserve-indentation nil
)
2594 (org-odd-levels-only nil
))
2597 (org-get-indentation))))
2600 (org-test-with-temp-text
2601 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2602 (let ((org-adapt-indentation t
)
2603 (org-src-preserve-indentation t
)
2604 (org-odd-levels-only nil
))
2607 (org-get-indentation))))
2610 (org-test-with-temp-text
2611 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2612 (let ((org-adapt-indentation t
)
2613 (org-src-preserve-indentation t
)
2614 (org-odd-levels-only nil
))
2617 (org-get-indentation))))
2620 (org-test-with-temp-text
2621 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2622 (let ((org-adapt-indentation t
)
2623 (org-src-preserve-indentation nil
)
2624 (org-odd-levels-only nil
))
2627 (org-get-indentation)))))
2632 (ert-deftest test-org
/at-planning-p
()
2633 "Test `org-at-planning-p' specifications."
2636 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2637 (org-at-planning-p)))
2639 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2640 (org-at-planning-p)))
2641 ;; Correctly find planning attached to inlinetasks.
2642 (when (featurep 'org-inlinetask
)
2644 (org-test-with-temp-text
2645 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2646 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2648 (org-test-with-temp-text
2649 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2650 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2652 (org-test-with-temp-text
2653 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2654 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2656 (org-test-with-temp-text
2657 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2658 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2663 (ert-deftest test-org
/buffer-property-keys
()
2664 "Test `org-buffer-property-keys' specifications."
2665 ;; Retrieve properties accross siblings.
2668 (org-test-with-temp-text "
2677 (org-buffer-property-keys))))
2678 ;; Retrieve properties accross children.
2681 (org-test-with-temp-text "
2690 (org-buffer-property-keys))))
2691 ;; Retrieve muliple properties in the same drawer.
2694 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2695 (org-buffer-property-keys))))
2696 ;; Ignore extension symbol in property name.
2699 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2700 (org-buffer-property-keys))))
2701 ;; With non-nil COLUMNS, extract property names from columns.
2704 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2705 (org-buffer-property-keys nil nil t
))))
2707 (equal '("A" "B" "COLUMNS")
2708 (org-test-with-temp-text
2709 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2710 (org-buffer-property-keys nil nil t
)))))
2712 (ert-deftest test-org
/property-values
()
2713 "Test `org-property-values' specifications."
2717 (org-test-with-temp-text
2718 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2719 (org-property-values "A"))))
2720 ;; Ignore empty values.
2722 (org-test-with-temp-text
2723 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2724 (org-property-values "A")))
2725 ;; Take into consideration extended values.
2728 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2729 (org-property-values "A")))))
2731 (ert-deftest test-org
/find-property
()
2732 "Test `org-find-property' specifications."
2736 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
2737 (org-find-property "prop"))))
2738 ;; Ignore false positives.
2741 (org-test-with-temp-text
2742 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
2743 (org-find-property "A"))))
2744 ;; Return first entry found in buffer.
2747 (org-test-with-temp-text
2748 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2749 (org-find-property "A"))))
2750 ;; Only search visible part of the buffer.
2753 (org-test-with-temp-text
2754 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2755 (org-narrow-to-subtree)
2756 (org-find-property "A"))))
2757 ;; With optional argument, only find entries with a specific value.
2759 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2760 (org-find-property "A" "2")))
2763 (org-test-with-temp-text
2764 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
2765 (org-find-property "A" "2"))))
2766 ;; Use "nil" for explicit nil values.
2769 (org-test-with-temp-text
2770 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
2771 (org-find-property "A" "nil")))))
2773 (ert-deftest test-org
/entry-delete
()
2774 "Test `org-entry-delete' specifications."
2778 " *:PROPERTIES:\n *:B: +2\n *:END:"
2779 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2780 (org-entry-delete (point) "A")
2782 ;; Also remove accumulated properties.
2786 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
2787 (org-entry-delete (point) "A")
2789 ;; When last property is removed, remove the property drawer.
2793 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2794 (org-entry-delete (point) "A")
2796 ;; Return a non-nil value when some property was removed.
2798 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2799 (org-entry-delete (point) "A")))
2801 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2802 (org-entry-delete (point) "C"))))
2804 (ert-deftest test-org
/entry-get
()
2805 "Test `org-entry-get' specifications."
2809 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2810 (org-entry-get (point) "A"))))
2814 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2815 (org-entry-get (point) "a"))))
2816 ;; Handle extended values, both before and after base value.
2819 (org-test-with-temp-text
2820 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2821 (org-entry-get (point) "A"))))
2822 ;; Empty values are returned as the empty string.
2825 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2826 (org-entry-get (point) "A"))))
2827 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2828 ;; otherwise, return nil.
2830 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2831 (org-entry-get (point) "A")))
2834 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2835 (org-entry-get (point) "A" nil t
))))
2836 ;; Return nil when no property is found, independently on the
2837 ;; LITERAL-NIL argument.
2839 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2840 (org-entry-get (point) "B")))
2842 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2843 (org-entry-get (point) "B" nil t
)))
2844 ;; Handle inheritance, when allowed.
2848 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2849 (org-entry-get (point) "A" t
))))
2853 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2854 (let ((org-use-property-inheritance t
))
2855 (org-entry-get (point) "A" 'selective
)))))
2857 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2858 (let ((org-use-property-inheritance nil
))
2859 (org-entry-get (point) "A" 'selective
)))))
2861 (ert-deftest test-org
/entry-properties
()
2862 "Test `org-entry-properties' specifications."
2863 ;; Get "ITEM" property.
2866 (org-test-with-temp-text "* TODO H"
2867 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
2870 (org-test-with-temp-text "* TODO H"
2871 (cdr (assoc "ITEM" (org-entry-properties))))))
2872 ;; Get "TODO" property.
2875 (org-test-with-temp-text "* TODO H"
2876 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
2879 (org-test-with-temp-text "* TODO H"
2880 (cdr (assoc "TODO" (org-entry-properties))))))
2882 (org-test-with-temp-text "* H"
2883 (assoc "TODO" (org-entry-properties nil
"TODO"))))
2884 ;; Get "PRIORITY" property.
2887 (org-test-with-temp-text "* [#A] H"
2888 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
2891 (org-test-with-temp-text "* [#A] H"
2892 (cdr (assoc "PRIORITY" (org-entry-properties))))))
2894 (org-test-with-temp-text "* H"
2895 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
2896 ;; Get "FILE" property.
2898 (org-test-with-temp-text-in-file "* H\nParagraph"
2899 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
2900 (buffer-file-name))))
2902 (org-test-with-temp-text-in-file "* H\nParagraph"
2903 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
2904 (buffer-file-name))))
2906 (org-test-with-temp-text "* H\nParagraph"
2907 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
2908 ;; Get "TAGS" property.
2910 (equal ":tag1:tag2:"
2911 (org-test-with-temp-text "* H :tag1:tag2:"
2912 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
2914 (equal ":tag1:tag2:"
2915 (org-test-with-temp-text "* H :tag1:tag2:"
2916 (cdr (assoc "TAGS" (org-entry-properties))))))
2918 (org-test-with-temp-text "* H"
2919 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
2920 ;; Get "ALLTAGS" property.
2922 (equal ":tag1:tag2:"
2923 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2924 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
2926 (equal ":tag1:tag2:"
2927 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2928 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
2930 (org-test-with-temp-text "* H"
2931 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
2932 ;; Get "BLOCKED" property.
2935 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2936 (let ((org-enforce-todo-dependencies t
)
2938 '(org-block-todo-from-children-or-siblings-or-parent)))
2939 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2942 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2943 (let ((org-enforce-todo-dependencies t
)
2945 '(org-block-todo-from-children-or-siblings-or-parent)))
2946 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
2949 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2950 (let ((org-enforce-todo-dependencies t
))
2951 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2952 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2956 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2957 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
2961 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2962 (cdr (assoc "CLOSED" (org-entry-properties))))))
2964 (org-test-with-temp-text "* H"
2965 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
2969 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2970 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
2974 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2975 (cdr (assoc "DEADLINE" (org-entry-properties))))))
2977 (org-test-with-temp-text "* H"
2978 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
2982 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2983 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
2987 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2988 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
2990 (org-test-with-temp-text "* H"
2991 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
2995 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2996 (cdr (assoc "CATEGORY" (org-entry-properties))))))
2999 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3000 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3003 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3004 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3005 ;; Get standard properties.
3008 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3009 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3010 ;; Handle extended properties.
3013 (org-test-with-temp-text
3014 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3015 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3018 (org-test-with-temp-text
3019 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3020 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3021 ;; Ignore forbidden (special) properties.
3023 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3024 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3026 (ert-deftest test-org
/entry-put
()
3027 "Test `org-entry-put' specifications."
3028 ;; Error when not a string or nil.
3030 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3031 (org-entry-put 1 "test" 2)))
3032 ;; Set "TODO" property.
3034 (string-match (regexp-quote " TODO H")
3035 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3036 (org-entry-put (point) "TODO" "TODO")
3039 (string-match (regexp-quote "* H")
3040 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3041 (org-entry-put (point) "TODO" nil
)
3043 ;; Set "PRIORITY" property.
3046 (org-test-with-temp-text "* [#B] H"
3047 (org-entry-put (point) "PRIORITY" "A")
3051 (org-test-with-temp-text "* [#B] H"
3052 (org-entry-put (point) "PRIORITY" nil
)
3054 ;; Set "SCHEDULED" property.
3056 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3057 (org-test-with-temp-text "* H"
3058 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3062 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3063 (org-entry-put (point) "SCHEDULED" nil
)
3066 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3067 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3068 (org-entry-put (point) "SCHEDULED" "earlier")
3071 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3072 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3073 (org-entry-put (point) "SCHEDULED" "later")
3075 ;; Set "DEADLINE" property.
3077 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3078 (org-test-with-temp-text "* H"
3079 (org-entry-put (point) "DEADLINE" "2014-03-04")
3083 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3084 (org-entry-put (point) "DEADLINE" nil
)
3087 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3088 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3089 (org-entry-put (point) "DEADLINE" "earlier")
3092 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3093 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3094 (org-entry-put (point) "DEADLINE" "later")
3096 ;; Set "CATEGORY" property
3098 (string-match "^ *:CATEGORY: cat"
3099 (org-test-with-temp-text "* H"
3100 (org-entry-put (point) "CATEGORY" "cat")
3102 ;; Regular properties, with or without pre-existing drawer.
3104 (string-match "^ *:A: +2$"
3105 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3106 (org-entry-put (point) "A" "2")
3109 (string-match "^ *:A: +1$"
3110 (org-test-with-temp-text "* H"
3111 (org-entry-put (point) "A" "1")
3113 ;; Special case: two consecutive headlines.
3115 (string-match "\\* A\n *:PROPERTIES:"
3116 (org-test-with-temp-text "* A\n** B"
3117 (org-entry-put (point) "A" "1")
3123 (ert-deftest test-org
/update-radio-target-regexp
()
3124 "Test `org-update-radio-target-regexp' specifications."
3125 ;; Properly update cache with no previous radio target regexp.
3128 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3129 (save-excursion (goto-char (point-max)) (org-element-context))
3131 (search-forward "o")
3133 (org-update-radio-target-regexp)
3134 (goto-char (point-max))
3135 (org-element-type (org-element-context)))))
3136 ;; Properly update cache with previous radio target regexp.
3139 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3140 (save-excursion (goto-char (point-max)) (org-element-context))
3142 (search-forward "o")
3144 (org-update-radio-target-regexp)
3145 (search-backward "r")
3148 (org-update-radio-target-regexp)
3149 (goto-char (point-max))
3150 (delete-region (line-beginning-position) (point))
3152 (org-element-type (org-element-context))))))
3157 (ert-deftest test-org
/match-sparse-tree
()
3158 "Test `org-match-sparse-tree' specifications."
3161 (org-test-with-temp-text "* H\n** H1 :tag:"
3162 (org-match-sparse-tree nil
"tag")
3163 (search-forward "H1")
3164 (org-invisible-p2)))
3166 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3167 (org-match-sparse-tree nil
"tag")
3168 (search-forward "H2")
3169 (org-invisible-p2)))
3170 ;; "-" operator for tags.
3172 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3173 (org-match-sparse-tree nil
"tag1-tag2")
3174 (search-forward "H1")
3175 (org-invisible-p2)))
3177 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3178 (org-match-sparse-tree nil
"tag1-tag2")
3179 (search-forward "H2")
3180 (org-invisible-p2)))
3181 ;; "&" operator for tags.
3183 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3184 (org-match-sparse-tree nil
"tag1&tag2")
3185 (search-forward "H1")
3186 (org-invisible-p2)))
3188 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3189 (org-match-sparse-tree nil
"tag1&tag2")
3190 (search-forward "H2")
3191 (org-invisible-p2)))
3192 ;; "|" operator for tags.
3194 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3195 (org-match-sparse-tree nil
"tag1|tag2")
3196 (search-forward "H1")
3197 (org-invisible-p2)))
3199 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3200 (org-match-sparse-tree nil
"tag1|tag2")
3201 (search-forward "H2")
3202 (org-invisible-p2)))
3203 ;; Regexp match on tags.
3205 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3206 (org-match-sparse-tree nil
"{^tag.*}")
3207 (search-forward "H1")
3208 (org-invisible-p2)))
3210 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3211 (org-match-sparse-tree nil
"{^tag.*}")
3212 (search-forward "H2")
3213 (org-invisible-p2)))
3214 ;; Match group tags.
3216 (org-test-with-temp-text
3217 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3218 (org-match-sparse-tree nil
"work")
3219 (search-forward "H1")
3220 (org-invisible-p2)))
3222 (org-test-with-temp-text
3223 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3224 (org-match-sparse-tree nil
"work")
3225 (search-forward "H2")
3226 (org-invisible-p2)))
3227 ;; Match group tags with hard brackets.
3229 (org-test-with-temp-text
3230 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3231 (org-match-sparse-tree nil
"work")
3232 (search-forward "H1")
3233 (org-invisible-p2)))
3235 (org-test-with-temp-text
3236 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3237 (org-match-sparse-tree nil
"work")
3238 (search-forward "H2")
3239 (org-invisible-p2)))
3240 ;; Match tags in hierarchies
3242 (org-test-with-temp-text
3243 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3244 #+TAGS: [ Lev_2 : Lev_3 ]\n
3245 #+TAGS: { Lev_3 : Lev_4 }\n
3246 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3247 (org-match-sparse-tree nil
"Lev_1")
3248 (search-forward "H4")
3249 (org-invisible-p2)))
3250 ;; Match regular expressions in tags
3252 (org-test-with-temp-text
3253 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3254 (org-match-sparse-tree nil
"Lev")
3255 (search-forward "H1")
3256 (org-invisible-p2)))
3258 (org-test-with-temp-text
3259 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3260 (org-match-sparse-tree nil
"Lev")
3261 (search-forward "H1")
3262 (org-invisible-p2)))
3263 ;; Match properties.
3265 (org-test-with-temp-text
3266 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3267 (org-match-sparse-tree nil
"A=\"1\"")
3268 (search-forward "H2")
3269 (org-invisible-p2)))
3271 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3272 (org-match-sparse-tree nil
"A=\"1\"")
3273 (search-forward "H2")
3274 (org-invisible-p2)))
3275 ;; Case is not significant when matching properties.
3277 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3278 (org-match-sparse-tree nil
"a=\"1\"")
3279 (search-forward "H2")
3280 (org-invisible-p2)))
3282 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3283 (org-match-sparse-tree nil
"A=\"1\"")
3284 (search-forward "H2")
3285 (org-invisible-p2)))
3286 ;; Match special LEVEL property.
3288 (org-test-with-temp-text "* H\n** H1\n*** H2"
3289 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3290 (search-forward "H1")
3291 (org-invisible-p2)))
3293 (org-test-with-temp-text "* H\n** H1\n*** H2"
3294 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3295 (search-forward "H2")
3296 (org-invisible-p2)))
3297 ;; Comparison operators when matching properties.
3299 (org-test-with-temp-text
3300 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3301 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3302 (search-forward "H1")
3303 (org-invisible-p2)))
3305 (org-test-with-temp-text
3306 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3307 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3308 (search-forward "H2")
3309 (org-invisible-p2)))
3310 ;; Regexp match on properties values.
3312 (org-test-with-temp-text
3313 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3314 (org-match-sparse-tree nil
"A={f.*}")
3315 (search-forward "H1")
3316 (org-invisible-p2)))
3318 (org-test-with-temp-text
3319 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3320 (org-match-sparse-tree nil
"A={f.*}")
3321 (search-forward "H2")
3322 (org-invisible-p2)))
3323 ;; With an optional argument, limit match to TODO entries.
3325 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3326 (org-match-sparse-tree t
"tag")
3327 (search-forward "H1")
3328 (org-invisible-p2)))
3330 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3331 (org-match-sparse-tree t
"tag")
3332 (search-forward "H2")
3333 (org-invisible-p2))))
3338 (ert-deftest test-org
/time-stamp
()
3339 "Test `org-time-stamp' specifications."
3340 ;; Insert chosen time stamp at point.
3343 "Te<2014-03-04 .*?>xt"
3344 (org-test-with-temp-text "Te<point>xt"
3345 (flet ((org-read-date
3347 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3348 (org-time-stamp nil
)
3350 ;; With a prefix argument, also insert time.
3353 "Te<2014-03-04 .*? 00:41>xt"
3354 (org-test-with-temp-text "Te<point>xt"
3355 (flet ((org-read-date
3357 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3358 (org-time-stamp '(4))
3360 ;; With two universal prefix arguments, insert an active timestamp
3361 ;; with the current time without prompting the user.
3364 "Te<2014-03-04 .*? 00:41>xt"
3365 (org-test-with-temp-text "Te<point>xt"
3366 (flet ((current-time
3368 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3369 (org-time-stamp '(16))
3371 ;; When optional argument is non-nil, insert an inactive timestamp.
3374 "Te\\[2014-03-04 .*?\\]xt"
3375 (org-test-with-temp-text "Te<point>xt"
3376 (flet ((org-read-date
3378 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3379 (org-time-stamp nil t
)
3381 ;; When called from a timestamp, replace existing one.
3385 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3386 (flet ((org-read-date
3388 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3389 (org-time-stamp nil
)
3393 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3394 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3395 (flet ((org-read-date
3397 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3398 (org-time-stamp nil
)
3400 ;; When replacing a timestamp, preserve repeater, if any.
3403 "<2014-03-04 .*? \\+2y>"
3404 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3405 (flet ((org-read-date
3407 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3408 (org-time-stamp nil
)
3410 ;; When called twice in a raw, build a date range.
3413 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3414 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3415 (flet ((org-read-date
3417 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3418 (let ((last-command 'org-time-stamp
)
3419 (this-command 'org-time-stamp
))
3420 (org-time-stamp nil
))
3421 (buffer-string))))))
3423 (ert-deftest test-org
/timestamp-has-time-p
()
3424 "Test `org-timestamp-has-time-p' specifications."
3427 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3428 (org-timestamp-has-time-p (org-element-context))))
3431 (org-test-with-temp-text "<2012-03-29 Thu>"
3432 (org-timestamp-has-time-p (org-element-context)))))
3434 (ert-deftest test-org
/timestamp-format
()
3435 "Test `org-timestamp-format' specifications."
3440 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3441 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3446 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3447 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3449 (ert-deftest test-org
/timestamp-split-range
()
3450 "Test `org-timestamp-split-range' specifications."
3451 ;; Extract range start (active).
3454 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3455 (let ((ts (org-timestamp-split-range (org-element-context))))
3456 (mapcar (lambda (p) (org-element-property p ts
))
3457 '(:year-end
:month-end
:day-end
))))))
3458 ;; Extract range start (inactive)
3461 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3462 (let ((ts (org-timestamp-split-range (org-element-context))))
3463 (mapcar (lambda (p) (org-element-property p ts
))
3464 '(:year-end
:month-end
:day-end
))))))
3465 ;; Extract range end (active).
3468 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3469 (let ((ts (org-timestamp-split-range
3470 (org-element-context) t
)))
3471 (mapcar (lambda (p) (org-element-property p ts
))
3472 '(:year-end
:month-end
:day-end
))))))
3473 ;; Extract range end (inactive)
3476 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3477 (let ((ts (org-timestamp-split-range
3478 (org-element-context) t
)))
3479 (mapcar (lambda (p) (org-element-property p ts
))
3480 '(:year-end
:month-end
:day-end
))))))
3481 ;; Return the timestamp if not a range.
3483 (org-test-with-temp-text "[2012-03-29 Thu]"
3484 (let* ((ts-orig (org-element-context))
3485 (ts-copy (org-timestamp-split-range ts-orig
)))
3486 (eq ts-orig ts-copy
))))
3488 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3489 (let* ((ts-orig (org-element-context))
3490 (ts-copy (org-timestamp-split-range ts-orig
)))
3491 (eq ts-orig ts-copy
)))))
3493 (ert-deftest test-org
/timestamp-translate
()
3494 "Test `org-timestamp-translate' specifications."
3495 ;; Translate whole date range.
3498 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3499 (let ((org-display-custom-times t
)
3500 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3501 (org-timestamp-translate (org-element-context))))))
3502 ;; Translate date range start.
3505 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3506 (let ((org-display-custom-times t
)
3507 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3508 (org-timestamp-translate (org-element-context) 'start
)))))
3509 ;; Translate date range end.
3512 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3513 (let ((org-display-custom-times t
)
3514 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3515 (org-timestamp-translate (org-element-context) 'end
)))))
3516 ;; Translate time range.
3519 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3520 (let ((org-display-custom-times t
)
3521 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3522 (org-timestamp-translate (org-element-context))))))
3523 ;; Translate non-range timestamp.
3526 (org-test-with-temp-text "<2012-03-29 Thu>"
3527 (let ((org-display-custom-times t
)
3528 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3529 (org-timestamp-translate (org-element-context))))))
3530 ;; Do not change `diary' timestamps.
3532 (equal "<%%(org-float t 4 2)>"
3533 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3534 (let ((org-display-custom-times t
)
3535 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3536 (org-timestamp-translate (org-element-context)))))))
3542 (ert-deftest test-org
/flag-drawer
()
3543 "Test `org-flag-drawer' specifications."
3546 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3548 (get-char-property (line-end-position) 'invisible
)))
3551 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3553 (org-flag-drawer nil
)
3554 (get-char-property (line-end-position) 'invisible
)))
3555 ;; Test optional argument.
3557 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3558 (let ((drawer (save-excursion (search-forward ":D2")
3559 (org-element-at-point))))
3560 (org-flag-drawer t drawer
)
3561 (get-char-property (progn (search-forward ":D2") (line-end-position))
3564 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3565 (let ((drawer (save-excursion (search-forward ":D2")
3566 (org-element-at-point))))
3567 (org-flag-drawer t drawer
)
3568 (get-char-property (line-end-position) 'invisible
))))
3569 ;; Do not hide fake drawers.
3571 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3574 (get-char-property (line-end-position) 'invisible
)))
3575 ;; Do not hide incomplete drawers.
3577 (org-test-with-temp-text ":D:\nparagraph"
3580 (get-char-property (line-end-position) 'invisible
)))
3581 ;; Do not hide drawers when called from final blank lines.
3583 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3584 (goto-char (point-max))
3586 (goto-char (point-min))
3587 (get-char-property (line-end-position) 'invisible
)))
3588 ;; Don't leave point in an invisible part of the buffer when hiding
3591 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3592 (goto-char (point-max))
3594 (get-char-property (point) 'invisible
))))
3596 (ert-deftest test-org
/hide-block-toggle
()
3597 "Test `org-hide-block-toggle' specifications."
3598 ;; Error when not at a block.
3600 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3601 (org-hide-block-toggle 'off
)
3602 (get-char-property (line-end-position) 'invisible
)))
3605 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3606 (org-hide-block-toggle)
3607 (get-char-property (line-end-position) 'invisible
)))
3609 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3610 (org-hide-block-toggle)
3611 (get-char-property (line-end-position) 'invisible
)))
3612 ;; Show block unconditionally when optional argument is `off'.
3614 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3615 (org-hide-block-toggle)
3616 (org-hide-block-toggle 'off
)
3617 (get-char-property (line-end-position) 'invisible
)))
3619 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3620 (org-hide-block-toggle 'off
)
3621 (get-char-property (line-end-position) 'invisible
)))
3622 ;; Hide block unconditionally when optional argument is non-nil.
3624 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3625 (org-hide-block-toggle t
)
3626 (get-char-property (line-end-position) 'invisible
)))
3628 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3629 (org-hide-block-toggle)
3630 (org-hide-block-toggle t
)
3631 (get-char-property (line-end-position) 'invisible
)))
3632 ;; Do not hide block when called from final blank lines.
3634 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3635 (org-hide-block-toggle)
3636 (goto-char (point-min))
3637 (get-char-property (line-end-position) 'invisible
)))
3638 ;; Don't leave point in an invisible part of the buffer when hiding
3641 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3642 (org-hide-block-toggle)
3643 (get-char-property (point) 'invisible
))))
3645 (ert-deftest test-org
/hide-block-toggle-maybe
()
3646 "Test `org-hide-block-toggle-maybe' specifications."
3648 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3649 (org-hide-block-toggle-maybe)))
3651 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3653 (ert-deftest test-org
/show-set-visibility
()
3654 "Test `org-show-set-visibility' specifications."
3655 ;; Do not throw an error before first heading.
3657 (org-test-with-temp-text "Preamble\n* Headline"
3658 (org-show-set-visibility 'tree
)
3660 ;; Test all visibility spans, both on headline and in entry.
3661 (let ((list-visible-lines
3662 (lambda (state headerp
)
3663 (org-test-with-temp-text "* Grandmother (0)
3674 **** The other child (11)
3679 (search-forward (if headerp
"Self" "Match"))
3680 (org-show-set-visibility state
)
3681 (goto-char (point-min))
3682 (let (result (line 0))
3684 (unless (org-invisible-p2) (push line result
))
3687 (nreverse result
))))))
3688 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
3689 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
3690 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
3691 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
3692 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
3693 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
3694 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
3695 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
3696 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
3697 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3698 (funcall list-visible-lines
'tree nil
)))
3699 (should (equal '(0 1 3 4 5 7 12 13)
3700 (funcall list-visible-lines
'canonical t
)))
3701 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3702 (funcall list-visible-lines
'canonical nil
)))))
3707 ;;; test-org.el ends here