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 |\n"
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. If the last element
639 ;; is an item, indent like its contents. Otherwise, indent like the
643 (org-test-with-temp-text "* H\n- A\n - AA\n"
644 (goto-char (point-max))
645 (let ((org-adapt-indentation t
)) (org-indent-line))
646 (org-get-indentation))))
649 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
650 (goto-char (point-max))
651 (let ((org-adapt-indentation t
)) (org-indent-line))
652 (org-get-indentation))))
655 (org-test-with-temp-text "* H\n- A\n - \n"
656 (goto-char (point-max))
657 (let ((org-adapt-indentation t
)) (org-indent-line))
658 (org-get-indentation))))
659 ;; Likewise, on a blank line at the end of a footnote definition,
660 ;; indent at column 0 if line belongs to the definition. Otherwise,
661 ;; indent like the definition itself.
664 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
665 (goto-char (point-max))
666 (let ((org-adapt-indentation t
)) (org-indent-line))
667 (org-get-indentation))))
670 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
671 (goto-char (point-max))
672 (let ((org-adapt-indentation t
)) (org-indent-line))
673 (org-get-indentation))))
674 ;; After the end of the contents of a greater element, indent like
675 ;; the beginning of the element.
678 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
681 (org-get-indentation))))
682 ;; On blank lines after a paragraph, indent like its last non-empty
686 (org-test-with-temp-text " Paragraph\n\n<point>"
688 (org-get-indentation))))
689 ;; At the first line of an element, indent like previous element's
690 ;; first line, ignoring footnotes definitions and inline tasks, or
691 ;; according to parent.
694 (org-test-with-temp-text "A\n\n B\n\nC"
695 (goto-char (point-max))
697 (org-get-indentation))))
700 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
701 (goto-char (point-max))
703 (org-get-indentation))))
706 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
709 (org-get-indentation))))
710 ;; Within code part of a source block, use language major mode if
711 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
712 ;; according to line above.
715 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
717 (let ((org-src-tab-acts-natively t
)
718 (org-edit-src-content-indentation 0))
720 (org-get-indentation))))
723 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
725 (let ((org-src-tab-acts-natively nil
)
726 (org-edit-src-content-indentation 0))
728 (org-get-indentation))))
729 ;; Otherwise, indent like the first non-blank line above.
732 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
735 (org-get-indentation))))
736 ;; Align node properties according to `org-property-format'. Handle
737 ;; nicely empty values.
739 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
740 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
741 (let ((org-property-format "%-10s %s")) (org-indent-line))
744 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
745 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
746 (let ((org-property-format "%-10s %s")) (org-indent-line))
749 (ert-deftest test-org
/indent-region
()
750 "Test `org-indent-region' specifications."
754 (org-test-with-temp-text " A\nB\n C"
755 (org-indent-region (point-min) (point-max))
757 ;; Indent greater elements along with their contents.
759 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
760 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
761 (org-indent-region (point-min) (point-max))
763 ;; Ignore contents of verse blocks and example blocks.
765 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
766 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
767 (org-indent-region (point-min) (point-max))
770 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
771 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
772 (org-indent-region (point-min) (point-max))
774 ;; Indent according to mode if `org-src-tab-acts-natively' is
775 ;; non-nil. Otherwise, do not indent code at all.
777 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
778 (org-test-with-temp-text
779 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
780 (let ((org-src-tab-acts-natively t
)
781 (org-edit-src-content-indentation 0))
782 (org-indent-region (point-min) (point-max)))
785 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
786 (org-test-with-temp-text
787 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
788 (let ((org-src-tab-acts-natively nil
)
789 (org-edit-src-content-indentation 0))
790 (org-indent-region (point-min) (point-max)))
792 ;; Align node properties according to `org-property-format'. Handle
793 ;; nicely empty values.
795 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
796 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
797 (let ((org-property-format "%-10s %s")
798 (org-adapt-indentation nil
))
799 (org-indent-region (point) (point-max)))
802 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
803 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
804 (let ((org-property-format "%-10s %s")
805 (org-adapt-indentation nil
))
806 (org-indent-region (point) (point-max)))
808 ;; Indent plain lists.
810 (equal "- A\n B\n - C\n\n D"
811 (org-test-with-temp-text "- A\n B\n - C\n\n D"
812 (org-indent-region (point-min) (point-max))
816 (org-test-with-temp-text " - A\n\n - B"
817 (org-indent-region (point-min) (point-max))
819 ;; Indent footnote definitions.
821 (equal "[fn:1] Definition\n\nDefinition"
822 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
823 (org-indent-region (point-min) (point-max))
825 ;; Special case: Start indenting on a blank line.
828 (org-test-with-temp-text "\n Paragraph"
829 (org-indent-region (point-min) (point-max))
836 (ert-deftest test-org
/delete-indentation
()
837 "Test `org-delete-indentation' specifications."
839 (should (equal "foo bar"
840 (org-test-with-temp-text
842 (org-delete-indentation)
844 ;; With optional argument.
845 (should (equal "foo bar"
846 (org-test-with-temp-text
848 (org-delete-indentation t
)
850 ;; At headline text should be appended to the headline text.
852 (equal"* foo bar :tag:"
853 (let (org-auto-align-tags)
854 (org-test-with-temp-text
855 "* foo :tag:\n bar<point>"
856 (org-delete-indentation)
859 (equal "* foo bar :tag:"
860 (let (org-auto-align-tags)
861 (org-test-with-temp-text
862 "* foo <point>:tag:\n bar"
863 (org-delete-indentation t
)
866 (ert-deftest test-org
/return
()
867 "Test `org-return' specifications."
871 (org-test-with-temp-text "Para<point>graph"
874 ;; With optional argument, indent line.
876 (equal " Para\n graph"
877 (org-test-with-temp-text " Para<point>graph"
880 ;; On a table, call `org-table-next-row'.
882 (org-test-with-temp-text "| <point>a |\n| b |"
884 (org-looking-at-p "b")))
885 ;; Open link or timestamp under point when `org-return-follows-link'
888 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
889 (let ((org-return-follows-link t
)
890 (org-link-search-must-match-exact-headline nil
))
892 (org-looking-at-p "<<target>>")))
894 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
895 (let ((org-return-follows-link nil
)) (org-return))
896 (org-looking-at-p "<<target>>")))
898 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
899 (let ((org-return-follows-link t
)) (org-return))
900 (org-looking-at-p "* b")))
902 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
903 (let ((org-return-follows-link t
)
904 (org-link-search-must-match-exact-headline nil
))
906 (org-looking-at-p "<<target>>")))
907 ;; When `org-return-follows-link' is non-nil, tolerate links and
908 ;; timestamps in comments, node properties, etc.
910 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
911 (let ((org-return-follows-link t
)
912 (org-link-search-must-match-exact-headline nil
))
914 (org-looking-at-p "<<target>>")))
915 ;; However, do not open link when point is in a table.
917 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
918 (let ((org-return-follows-link t
)) (org-return))
919 (org-looking-at-p "between")))
920 ;; Special case: in a list, when indenting, do not break structure.
923 (org-test-with-temp-text "- A <point>B"
928 (org-test-with-temp-text "- A\n<point>- B"
931 ;; On tags part of a headline, add a newline below it instead of
935 (org-test-with-temp-text "* H :<point>tag:"
938 ;; Before headline text, add a newline below it instead of breaking
941 (equal "* TODO H :tag:\n"
942 (org-test-with-temp-text "* <point>TODO H :tag:"
946 (equal "* TODO [#B] H :tag:\n"
947 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
950 ;; At headline text, break headline text but preserve tags.
952 (equal "* TODO [#B] foo :tag:\nbar"
953 (let (org-auto-align-tags)
954 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
957 ;; At bol of headline insert newline.
960 (org-test-with-temp-text "<point>* h"
963 ;; Refuse to leave invalid headline in buffer.
966 (org-test-with-temp-text "*<point> h"
970 (ert-deftest test-org
/meta-return
()
971 "Test M-RET (`org-meta-return') specifications."
972 ;; In a table field insert a row above.
974 (org-test-with-temp-text "| a |"
978 (looking-at "| |$")))
979 ;; In a paragraph change current line into a header.
981 (org-test-with-temp-text "a"
984 (looking-at "\* a$")))
985 ;; In an item insert an item, in this case above.
987 (org-test-with-temp-text "- a"
991 ;; In a drawer and item insert an item, in this case above.
993 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
997 (looking-at "- $"))))
999 (ert-deftest test-org
/insert-heading
()
1000 "Test `org-insert-heading' specifications."
1001 ;; In an empty buffer, insert a new headline.
1004 (org-test-with-temp-text ""
1005 (org-insert-heading)
1007 ;; At the beginning of a line, turn it into a headline
1010 (org-test-with-temp-text "<point>P"
1011 (org-insert-heading)
1013 ;; In the middle of a line, split the line if allowed, otherwise,
1014 ;; insert the headline at its end.
1016 (equal "Para\n* graph"
1017 (org-test-with-temp-text "Para<point>graph"
1018 (let ((org-M-RET-may-split-line '((default . t
))))
1019 (org-insert-heading))
1022 (equal "Paragraph\n* "
1023 (org-test-with-temp-text "Para<point>graph"
1024 (let ((org-M-RET-may-split-line '((default . nil
))))
1025 (org-insert-heading))
1027 ;; When on a list, insert an item instead, unless called with an
1028 ;; universal argument or if list is invisible. In this case, create
1029 ;; a new headline after contents.
1031 (equal "* H\n- item\n- "
1032 (org-test-with-temp-text "* H\n- item<point>"
1033 (let ((org-insert-heading-respect-content nil
))
1034 (org-insert-heading))
1037 (equal "* H\n- item\n- item 2\n* "
1038 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1039 (let ((org-insert-heading-respect-content nil
))
1040 (org-insert-heading '(4)))
1043 (equal "* H\n- item\n* "
1044 (org-test-with-temp-text "* H\n- item"
1046 (goto-char (point-max))
1047 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1049 ;; When called with two universal arguments, insert a new headline
1050 ;; at the end of the grandparent subtree.
1052 (equal "* H1\n** H3\n- item\n** H2\n** "
1053 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1054 (let ((org-insert-heading-respect-content nil
))
1055 (org-insert-heading '(16)))
1057 ;; When optional TOP-LEVEL argument is non-nil, always insert
1058 ;; a level 1 heading.
1060 (equal "* H1\n** H2\n* "
1061 (org-test-with-temp-text "* H1\n** H2<point>"
1062 (org-insert-heading nil nil t
)
1065 (equal "* H1\n- item\n* "
1066 (org-test-with-temp-text "* H1\n- item<point>"
1067 (org-insert-heading nil nil t
)
1069 ;; Corner case: correctly insert a headline after an empty one.
1072 (org-test-with-temp-text "* <point>"
1073 (org-insert-heading)
1076 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1077 "Test `org-insert-todo-heading-respect-content' specifications."
1078 ;; Create a TODO heading.
1080 (org-test-with-temp-text "* H1\n Body"
1081 (org-insert-todo-heading-respect-content)
1082 (nth 2 (org-heading-components))))
1083 ;; Add headline at the end of the first subtree
1085 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1086 (search-forward "H1Body")
1087 (org-insert-todo-heading-respect-content)
1088 (and (eobp) (org-at-heading-p))))
1089 ;; In a list, do not create a new item.
1091 (org-test-with-temp-text "* H\n- an item\n- another one"
1092 (search-forward "an ")
1093 (org-insert-todo-heading-respect-content)
1094 (and (eobp) (org-at-heading-p)))))
1096 (ert-deftest test-org
/clone-with-time-shift
()
1097 "Test `org-clone-subtree-with-time-shift'."
1098 ;; Clone non-repeating once.
1104 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1105 (org-clone-subtree-with-time-shift 1 "+2d")
1106 (replace-regexp-in-string
1107 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1109 ;; Clone repeating once.
1114 * H1\n<2015-06-25 +1w>
1116 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1117 (org-clone-subtree-with-time-shift 1 "+2d")
1118 (replace-regexp-in-string
1119 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1121 ;; Clone non-repeating zero times.
1126 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1127 (org-clone-subtree-with-time-shift 0 "+2d")
1128 (replace-regexp-in-string
1129 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1131 ;; Clone repeating "zero" times.
1135 * H1\n<2015-06-23 +1w>
1137 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1138 (org-clone-subtree-with-time-shift 0 "+2d")
1139 (replace-regexp-in-string
1140 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1144 ;;; Fixed-Width Areas
1146 (ert-deftest test-org
/toggle-fixed-width
()
1147 "Test `org-toggle-fixed-width' specifications."
1148 ;; No region: Toggle on fixed-width marker in paragraphs.
1151 (org-test-with-temp-text "A"
1152 (org-toggle-fixed-width)
1154 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1157 (org-test-with-temp-text ": A"
1158 (org-toggle-fixed-width)
1160 ;; No region: Toggle on marker in blank lines after elements or just
1161 ;; after a headline.
1164 (org-test-with-temp-text "* H\n"
1166 (org-toggle-fixed-width)
1169 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1170 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1171 (goto-char (point-max))
1172 (org-toggle-fixed-width)
1174 ;; No region: Toggle on marker in front of one line elements (e.g.,
1175 ;; headlines, clocks)
1177 (equal ": * Headline"
1178 (org-test-with-temp-text "* Headline"
1179 (org-toggle-fixed-width)
1182 (equal ": #+KEYWORD: value"
1183 (org-test-with-temp-text "#+KEYWORD: value"
1184 (org-toggle-fixed-width)
1186 ;; No region: error in other situations.
1188 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1190 (org-toggle-fixed-width)
1192 ;; No region: Indentation is preserved.
1195 (org-test-with-temp-text "- A\n B"
1197 (org-toggle-fixed-width)
1199 ;; Region: If it contains only fixed-width elements and blank lines,
1200 ;; toggle off fixed-width markup.
1203 (org-test-with-temp-text ": A\n\n: B"
1204 (transient-mark-mode 1)
1205 (push-mark (point) t t
)
1206 (goto-char (point-max))
1207 (org-toggle-fixed-width)
1209 ;; Region: If it contains anything else, toggle on fixed-width but
1210 ;; not on fixed-width areas.
1212 (equal ": A\n: \n: B\n: \n: C"
1213 (org-test-with-temp-text "A\n\n: B\n\nC"
1214 (transient-mark-mode 1)
1215 (push-mark (point) t t
)
1216 (goto-char (point-max))
1217 (org-toggle-fixed-width)
1219 ;; Region: Ignore blank lines at its end, unless it contains only
1223 (org-test-with-temp-text "A\n\n"
1224 (transient-mark-mode 1)
1225 (push-mark (point) t t
)
1226 (goto-char (point-max))
1227 (org-toggle-fixed-width)
1231 (org-test-with-temp-text "\n\n"
1232 (transient-mark-mode 1)
1233 (push-mark (point) t t
)
1234 (goto-char (point-max))
1235 (org-toggle-fixed-width)
1242 (ert-deftest test-org
/in-commented-heading-p
()
1243 "Test `org-in-commented-heading-p' specifications."
1244 ;; Commented headline.
1246 (org-test-with-temp-text "* COMMENT Headline\nBody"
1247 (goto-char (point-max))
1248 (org-in-commented-heading-p)))
1249 ;; Commented ancestor.
1251 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1252 (goto-char (point-max))
1253 (org-in-commented-heading-p)))
1254 ;; Comment keyword is case-sensitive.
1256 (org-test-with-temp-text "* Comment Headline\nBody"
1257 (goto-char (point-max))
1258 (org-in-commented-heading-p)))
1259 ;; Keyword is standalone.
1261 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1262 (goto-char (point-max))
1263 (org-in-commented-heading-p)))
1264 ;; Optional argument.
1266 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1267 (goto-char (point-max))
1268 (org-in-commented-heading-p t
))))
1270 (ert-deftest test-org
/entry-blocked-p
()
1271 ;; Check other dependencies.
1273 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1274 (let ((org-enforce-todo-dependencies t
)
1276 '(org-block-todo-from-children-or-siblings-or-parent)))
1277 (org-entry-blocked-p))))
1279 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1280 (let ((org-enforce-todo-dependencies t
)
1282 '(org-block-todo-from-children-or-siblings-or-parent)))
1283 (org-entry-blocked-p))))
1284 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1287 (org-test-with-temp-text "* Blocked\n** TODO one"
1288 (let ((org-enforce-todo-dependencies t
)
1290 '(org-block-todo-from-children-or-siblings-or-parent)))
1291 (org-entry-blocked-p))))
1293 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1294 (let ((org-enforce-todo-dependencies t
)
1296 '(org-block-todo-from-children-or-siblings-or-parent)))
1297 (org-entry-blocked-p))))
1298 ;; Follow :ORDERED: specifications.
1300 (org-test-with-temp-text
1301 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1302 (let ((org-enforce-todo-dependencies t
)
1304 '(org-block-todo-from-children-or-siblings-or-parent)))
1305 (org-entry-blocked-p))))
1307 (org-test-with-temp-text
1308 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1309 (let ((org-enforce-todo-dependencies t
)
1311 '(org-block-todo-from-children-or-siblings-or-parent)))
1312 (org-entry-blocked-p)))))
1314 (ert-deftest test-org
/format-outline-path
()
1316 (string= (org-format-outline-path (list "one" "two" "three"))
1320 (string= (org-format-outline-path '())
1323 (string= (org-format-outline-path '(nil))
1325 ;; Empty path and prefix.
1327 (string= (org-format-outline-path '() nil
">>")
1329 ;; Trailing whitespace in headings.
1331 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1333 ;; Non-default prefix and separators.
1335 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1336 ">>|one|two|three"))
1339 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1341 ;; Give a very narrow width.
1343 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1345 ;; Give a prefix that extends beyond the width.
1347 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1354 (ert-deftest test-org
/set-regexps-and-options
()
1355 "Test `org-set-regexps-and-options' specifications."
1358 (equal '(("A" . ?a
) ("B") ("C"))
1359 (org-test-with-temp-text "#+TAGS: A(a) B C"
1363 (equal '(("A") (:newline
) ("B"))
1364 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1368 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1369 (org-test-with-temp-text "#+TAGS: { A B } C"
1373 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1374 (org-test-with-temp-text "#+TAGS: { A : B C }"
1378 (equal '(("A" "B" "C"))
1379 (org-test-with-temp-text "#+TAGS: { A : B C }"
1381 org-tag-groups-alist
)))
1383 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1384 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1388 (equal '(("A" "B" "C"))
1389 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1391 org-tag-groups-alist
)))
1392 ;; FILETAGS keyword.
1394 (equal '("A" "B" "C")
1395 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1398 ;; PROPERTY keyword. Property names are case-insensitive.
1401 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1403 (cdr (assoc "var" org-file-properties
)))))
1407 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1409 (cdr (assoc "var" org-file-properties
)))))
1413 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1415 (cdr (assoc "var" org-file-properties
)))))
1419 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1421 org-archive-location
)))
1422 ;; CATEGORY keyword.
1425 (org-test-with-temp-text "#+CATEGORY: test"
1430 (org-test-with-temp-text "#+CATEGORY: test"
1432 (cdr (assoc "CATEGORY" org-file-properties
)))))
1435 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1436 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1438 org-columns-default-format
)))
1439 ;; CONSTANTS keyword. Constants names are case sensitive.
1441 (equal '("299792458." "3.14")
1442 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1445 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1449 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1451 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1454 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1456 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1461 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1463 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1465 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1469 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1471 (list org-highest-priority org-lowest-priority org-default-priority
))))
1475 (org-test-with-temp-text "#+PRIORITIES: X Z"
1477 (list org-highest-priority org-lowest-priority org-default-priority
))))
1481 (org-test-with-temp-text "#+STARTUP: fold odd"
1483 (list org-startup-folded org-odd-levels-only
))))
1486 (equal '(("A" "B") ("C"))
1487 (org-test-with-temp-text "#+TODO: A B | C"
1489 (list org-not-done-keywords org-done-keywords
))))
1491 (equal '(("A" "C") ("B" "D"))
1492 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1494 (list org-not-done-keywords org-done-keywords
))))
1496 (equal '(("A" "B") ("C"))
1497 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1499 (list org-not-done-keywords org-done-keywords
))))
1501 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1502 (org-test-with-temp-text "#+TODO: A(a)"
1504 org-todo-key-alist
)))
1506 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1507 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1509 org-todo-log-states
)))
1510 ;; Enter SETUPFILE keyword.
1513 (org-test-with-temp-text
1514 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1516 (cdr (assoc "a" org-file-properties
))))))
1524 (ert-deftest test-org
/coderef
()
1525 "Test coderef links specifications."
1527 (org-test-with-temp-text "
1528 #+BEGIN_SRC emacs-lisp
1533 (looking-at "(ref:sc)")))
1534 ;; Find coderef even with alternate label format.
1536 (org-test-with-temp-text "
1537 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
1542 (looking-at "{ref:sc}"))))
1546 (ert-deftest test-org
/custom-id
()
1547 "Test custom ID links specifications."
1549 (org-test-with-temp-text
1550 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1552 (org-looking-at-p "\\* H1")))
1553 ;; Throw an error on false positives.
1555 (org-test-with-temp-text
1556 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1558 (org-looking-at-p "\\* H1"))))
1562 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1563 ;; a named element (#+name: text) and to headlines (* Text).
1565 (ert-deftest test-org
/fuzzy-links
()
1566 "Test fuzzy links specifications."
1567 ;; Fuzzy link goes in priority to a matching target.
1569 (org-test-with-temp-text
1570 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
1571 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1572 (looking-at "<<Test>>")))
1573 ;; Then fuzzy link points to an element with a given name.
1575 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
1576 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1577 (looking-at "#\\+NAME: Test")))
1578 ;; A target still lead to a matching headline otherwise.
1580 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
1581 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1582 (looking-at "\\* Head2")))
1583 ;; With a leading star in link, enforce heading match.
1585 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
1586 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1587 (looking-at "\\* Test")))
1588 ;; With a leading star in link, enforce exact heading match, even
1589 ;; with `org-link-search-must-match-exact-headline' set to nil.
1591 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1592 (let ((org-link-search-must-match-exact-headline nil
))
1593 (org-open-at-point))))
1594 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
1596 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
1597 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1598 (looking-at "\\* Test")))
1600 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
1601 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1602 (looking-at "\\* Test")))
1603 ;; Heading match should not care about spaces, cookies, TODO
1604 ;; keywords, priorities, and tags.
1607 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1608 (org-test-with-temp-text
1609 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1610 (let ((org-link-search-must-match-exact-headline nil
)
1611 (org-todo-regexp "TODO"))
1612 (org-open-at-point))
1613 (looking-at (regexp-quote first-line
)))))
1614 ;; Heading match should still be exact.
1617 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1618 (org-test-with-temp-text
1619 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1620 (let ((org-link-search-must-match-exact-headline nil
)
1621 (org-todo-regexp "TODO"))
1622 (org-open-at-point)))))
1623 ;; Heading match ignores COMMENT keyword.
1625 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1627 (looking-at "\\* COMMENT Test")))
1628 ;; Correctly un-hexify fuzzy links.
1630 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1631 (goto-char (point-max))
1637 (ert-deftest test-org
/org-link-escape-ascii-character
()
1638 "Escape an ascii character."
1642 (org-link-escape "["))))
1644 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1645 "Escape an ascii control character."
1649 (org-link-escape "\t"))))
1651 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1652 "Escape an unicode multibyte character."
1656 (org-link-escape "€"))))
1658 (ert-deftest test-org
/org-link-escape-custom-table
()
1659 "Escape string with custom character table."
1663 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1665 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1666 "Escape string with custom table merged with default table."
1669 "%5BF%6F%6F%3A%42ar%0A%5D"
1670 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1672 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1673 "Unescape an ascii character."
1677 (org-link-unescape "%5B"))))
1679 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1680 "Unescpae an ascii control character."
1684 (org-link-unescape "%0A"))))
1686 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1687 "Unescape unicode multibyte character."
1691 (org-link-unescape "%E2%82%AC"))))
1693 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1694 "Unescape old style percent escaped character."
1697 "à âçèéêîôùû"
1698 (decode-coding-string
1699 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1701 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1702 "Escape and unescape a URL that includes an escaped char.
1703 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1706 "http://some.host.com/form?&id=blah%2Bblah25"
1708 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1710 (ert-deftest test-org
/org-link-escape-chars-browser
()
1711 "Test of the constant `org-link-escape-chars-browser'.
1712 See there why this test is a candidate to be removed once Org
1713 drops support for Emacs 24.1 and 24.2."
1716 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1717 "%22Release%208.2%22&idxname=emacs-orgmode")
1718 (org-link-escape-browser ; Do not replace with `url-encode-url',
1719 ; see docstring above.
1720 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1721 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1725 (ert-deftest test-org
/open-at-point-in-keyword
()
1726 "Does `org-open-at-point' open link in a keyword line?"
1728 (org-test-with-temp-text
1729 "#+KEYWORD: <point>[[info:emacs#Top]]"
1730 (org-open-at-point) t
)))
1732 (ert-deftest test-org
/open-at-point-in-property
()
1733 "Does `org-open-at-point' open link in property drawer?"
1735 (org-test-with-temp-text
1738 :URL: <point>[[info:emacs#Top]]
1740 (org-open-at-point) t
)))
1742 (ert-deftest test-org
/open-at-point-in-comment
()
1743 "Does `org-open-at-point' open link in a commented line?"
1745 (org-test-with-temp-text
1746 "# <point>[[info:emacs#Top]]"
1747 (org-open-at-point) t
)))
1749 (ert-deftest test-org
/open-at-point
/info
()
1750 "Test `org-open-at-point' on info links."
1752 (org-test-with-temp-text
1753 "<point>[[info:emacs#Top]]"
1755 (and (switch-to-buffer "*info*")
1757 (looking-at "\nThe Emacs Editor")
1760 (ert-deftest test-org
/open-at-point
/inline-image
()
1761 "Test `org-open-at-point' on nested links."
1763 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1765 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1766 (kill-buffer "*info*")))))
1768 (ert-deftest test-org
/open-at-point
/radio-target
()
1769 "Test `org-open-at-point' on radio targets."
1771 (org-test-with-temp-text "<<<target>>> <point>target"
1772 (org-update-radio-target-regexp)
1774 (eq (org-element-type (org-element-context)) 'radio-target
))))
1779 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1780 "Ensure properties accumulate in subtree drawers."
1781 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1782 (org-babel-next-src-block)
1783 (should (equal '(2 1) (org-babel-execute-src-block)))))
1785 (ert-deftest test-org
/custom-properties
()
1786 "Test custom properties specifications."
1789 (let ((org-custom-properties '("FOO")))
1790 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1791 (org-toggle-custom-properties-visibility)
1792 (org-invisible-p2))))
1793 ;; Properties are case-insensitive.
1795 (let ((org-custom-properties '("FOO")))
1796 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1797 (org-toggle-custom-properties-visibility)
1798 (org-invisible-p2))))
1800 (let ((org-custom-properties '("foo")))
1801 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1802 (org-toggle-custom-properties-visibility)
1803 (org-invisible-p2))))
1804 ;; Multiple custom properties in the same drawer.
1806 (let ((org-custom-properties '("FOO" "BAR")))
1807 (org-test-with-temp-text
1808 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1809 (org-toggle-custom-properties-visibility)
1810 (and (org-invisible-p2)
1811 (not (progn (forward-line) (org-invisible-p2)))
1812 (progn (forward-line) (org-invisible-p2))))))
1813 ;; Hide custom properties with an empty value.
1815 (let ((org-custom-properties '("FOO")))
1816 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1817 (org-toggle-custom-properties-visibility)
1818 (org-invisible-p2))))
1819 ;; Do not hide fake properties.
1821 (let ((org-custom-properties '("FOO")))
1822 (org-test-with-temp-text ":FOO: val\n"
1823 (org-toggle-custom-properties-visibility)
1824 (org-invisible-p2))))
1826 (let ((org-custom-properties '("A")))
1827 (org-test-with-temp-text
1828 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1829 (org-toggle-custom-properties-visibility)
1830 (org-invisible-p2)))))
1836 (ert-deftest test-org
/mark-subtree
()
1837 "Test `org-mark-subtree' specifications."
1838 ;; Error when point is before first headline.
1840 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1841 (progn (transient-mark-mode 1)
1842 (org-mark-subtree))))
1843 ;; Without argument, mark current subtree.
1847 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1848 (progn (transient-mark-mode 1)
1851 (list (region-beginning) (region-end))))))
1852 ;; With an argument, move ARG up.
1856 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1857 (progn (transient-mark-mode 1)
1859 (org-mark-subtree 1)
1860 (list (region-beginning) (region-end))))))
1861 ;; Do not get fooled by inlinetasks.
1862 (when (featurep 'org-inlinetask
)
1865 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1866 (progn (transient-mark-mode 1)
1868 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1869 (region-beginning)))))))
1875 (ert-deftest test-org
/end-of-meta-data
()
1876 "Test `org-end-of-meta-data' specifications."
1877 ;; Skip planning line.
1879 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1880 (org-end-of-meta-data)
1882 ;; Skip properties drawer.
1884 (org-test-with-temp-text
1885 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1886 (org-end-of-meta-data)
1890 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1891 (org-end-of-meta-data)
1893 ;; Nothing to skip, go to first line.
1895 (org-test-with-temp-text "* Headline\nContents"
1896 (org-end-of-meta-data)
1897 (looking-at "Contents")))
1898 ;; With option argument, skip empty lines, regular drawers and
1901 (org-test-with-temp-text "* Headline\n\nContents"
1902 (org-end-of-meta-data t
)
1903 (looking-at "Contents")))
1905 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1906 (org-end-of-meta-data t
)
1907 (looking-at "Contents")))
1909 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1910 (org-end-of-meta-data t
)
1911 (looking-at "Contents")))
1912 ;; Special case: do not skip incomplete drawers.
1914 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1915 (org-end-of-meta-data t
)
1916 (looking-at ":LOGBOOK:")))
1917 ;; Special case: Be careful about consecutive headlines.
1919 (org-test-with-temp-text "* H1\n*H2\nContents"
1920 (org-end-of-meta-data t
)
1921 (looking-at "Contents"))))
1923 (ert-deftest test-org
/beginning-of-line
()
1924 "Test `org-beginning-of-line' specifications."
1927 (org-test-with-temp-text "Some text\nSome other text"
1928 (progn (org-beginning-of-line) (bolp))))
1929 ;; Standard test with `visual-line-mode'.
1931 (org-test-with-temp-text "A long line of text\nSome other text"
1932 (progn (visual-line-mode)
1934 (dotimes (i 1000) (insert "very "))
1935 (org-beginning-of-line)
1937 ;; At an headline with special movement.
1939 (org-test-with-temp-text "* TODO Headline"
1940 (let ((org-special-ctrl-a/e t
))
1942 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1943 (progn (org-beginning-of-line) (bolp))
1944 (progn (org-beginning-of-line) (looking-at "Headline"))))))
1945 ;; Special case: Do not error when the buffer contains only a single
1948 (org-test-with-temp-text "*<point>"
1949 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
1951 (org-test-with-temp-text "*<point>"
1952 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
1954 (ert-deftest test-org
/end-of-line
()
1955 "Test `org-end-of-line' specifications."
1958 (org-test-with-temp-text "Some text\nSome other text"
1959 (progn (org-end-of-line) (eolp))))
1960 ;; Standard test with `visual-line-mode'.
1962 (org-test-with-temp-text "A long line of text\nSome other text"
1963 (progn (visual-line-mode)
1965 (dotimes (i 1000) (insert "very "))
1966 (goto-char (point-min))
1969 ;; At an headline with special movement.
1971 (org-test-with-temp-text "* Headline1 :tag:\n"
1972 (let ((org-special-ctrl-a/e t
))
1973 (and (progn (org-end-of-line) (looking-at " :tag:"))
1974 (progn (org-end-of-line) (eolp))
1975 (progn (org-end-of-line) (looking-at " :tag:"))))))
1976 ;; At an headline without special movement.
1978 (org-test-with-temp-text "* Headline2 :tag:\n"
1979 (let ((org-special-ctrl-a/e nil
))
1980 (and (progn (org-end-of-line) (eolp))
1981 (progn (org-end-of-line) (eolp))))))
1982 ;; At an headline, with reversed movement.
1984 (org-test-with-temp-text "* Headline3 :tag:\n"
1985 (let ((org-special-ctrl-a/e
'reversed
)
1986 (this-command last-command
))
1987 (and (progn (org-end-of-line) (eolp))
1988 (progn (org-end-of-line) (looking-at " :tag:"))))))
1989 ;; At a block without hidden contents.
1991 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1992 (progn (org-end-of-line) (eolp))))
1993 ;; At a block with hidden contents.
1995 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1996 (let ((org-special-ctrl-a/e t
))
1997 (org-hide-block-toggle)
2001 (ert-deftest test-org
/forward-sentence
()
2002 "Test `org-forward-sentence' specifications."
2003 ;; At the end of a table cell, move to the end of the next one.
2005 (org-test-with-temp-text "| a<point> | b |"
2006 (org-forward-sentence)
2007 (looking-at " |$")))
2008 ;; Elsewhere in a cell, move to its end.
2010 (org-test-with-temp-text "| a<point>c | b |"
2011 (org-forward-sentence)
2012 (looking-at " | b |$")))
2013 ;; Otherwise, simply call `forward-sentence'.
2015 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2016 (org-forward-sentence)
2017 (looking-at " Sentence 2.")))
2019 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2020 (org-forward-sentence)
2021 (org-forward-sentence)
2023 ;; At the end of an element, jump to the next one, without stopping
2024 ;; on blank lines in-between.
2026 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2027 (org-forward-sentence)
2030 (ert-deftest test-org
/backward-sentence
()
2031 "Test `org-backward-sentence' specifications."
2032 ;; At the beginning of a table cell, move to the beginning of the
2035 (org-test-with-temp-text "| a | <point>b |"
2036 (org-backward-sentence)
2037 (looking-at "a | b |$")))
2038 ;; Elsewhere in a cell, move to its beginning.
2040 (org-test-with-temp-text "| a | b<point>c |"
2041 (org-backward-sentence)
2042 (looking-at "bc |$")))
2043 ;; Otherwise, simply call `backward-sentence'.
2045 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2046 (org-backward-sentence)
2047 (looking-at "Sentence 2.")))
2049 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2050 (org-backward-sentence)
2051 (org-backward-sentence)
2053 ;; Make sure to hit the beginning of a sentence on the same line as
2056 (org-test-with-temp-text "- Line 1\n line <point>2."
2057 (org-backward-sentence)
2058 (looking-at "Line 1"))))
2060 (ert-deftest test-org
/forward-paragraph
()
2061 "Test `org-forward-paragraph' specifications."
2062 ;; At end of buffer, return an error.
2064 (org-test-with-temp-text "Paragraph"
2065 (goto-char (point-max))
2066 (org-forward-paragraph)))
2069 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2070 (org-forward-paragraph)
2074 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2075 (org-forward-paragraph)
2077 ;; Do not enter elements with invisible contents.
2079 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2080 (org-hide-block-toggle)
2081 (org-forward-paragraph)
2083 ;; On an affiliated keyword, jump to the beginning of the element.
2085 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2086 (org-forward-paragraph)
2087 (looking-at "Para")))
2088 ;; On an item or a footnote definition, move to the second element
2091 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2092 (org-forward-paragraph)
2093 (looking-at " Paragraph")))
2095 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2096 (org-forward-paragraph)
2097 (looking-at "Paragraph")))
2098 ;; On an item, or a footnote definition, when the first line is
2099 ;; empty, move to the first item.
2101 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2102 (org-forward-paragraph)
2103 (looking-at " Paragraph")))
2105 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2106 (org-forward-paragraph)
2107 (looking-at "Paragraph")))
2108 ;; On a table (resp. a property drawer) do not move through table
2109 ;; rows (resp. node properties).
2111 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2112 (org-forward-paragraph)
2113 (looking-at "Paragraph")))
2115 (org-test-with-temp-text
2116 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2117 (org-forward-paragraph)
2118 (looking-at "Paragraph")))
2119 ;; On a verse or source block, stop after blank lines.
2121 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2122 (org-forward-paragraph)
2125 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2126 (org-forward-paragraph)
2127 (looking-at "L2"))))
2129 (ert-deftest test-org
/backward-paragraph
()
2130 "Test `org-backward-paragraph' specifications."
2131 ;; Error at beginning of buffer.
2133 (org-test-with-temp-text "Paragraph"
2134 (org-backward-paragraph)))
2137 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2138 (goto-char (point-max))
2139 (org-backward-paragraph)
2142 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2143 (goto-char (point-max))
2145 (org-backward-paragraph)
2149 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2150 (goto-char (point-max))
2152 (org-backward-paragraph)
2154 ;; Ignore invisible elements.
2156 (org-test-with-temp-text "* H1\n P1\n* H2"
2158 (goto-char (point-max))
2160 (org-backward-paragraph)
2162 ;; On an affiliated keyword, jump to the first one.
2164 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2165 (search-forward "c2")
2166 (org-backward-paragraph)
2167 (looking-at "#\\+name")))
2168 ;; On the second element in an item or a footnote definition, jump
2169 ;; to item or the definition.
2171 (org-test-with-temp-text "- line1\n\n line2"
2172 (goto-char (point-max))
2174 (org-backward-paragraph)
2175 (looking-at "- line1")))
2177 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2178 (goto-char (point-max))
2180 (org-backward-paragraph)
2181 (looking-at "\\[fn:1\\] line1")))
2182 ;; On a table (resp. a property drawer), ignore table rows
2183 ;; (resp. node properties).
2185 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2186 (goto-char (point-max))
2188 (org-backward-paragraph)
2191 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2192 (org-backward-paragraph)
2193 (looking-at ":PROPERTIES:")))
2194 ;; On a source or verse block, stop before blank lines.
2196 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2197 (search-forward "L3")
2199 (org-backward-paragraph)
2202 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2203 (search-forward "L3")
2205 (org-backward-paragraph)
2206 (looking-at "L2"))))
2208 (ert-deftest test-org
/forward-element
()
2209 "Test `org-forward-element' specifications."
2210 ;; 1. At EOB: should error.
2211 (org-test-with-temp-text "Some text\n"
2212 (goto-char (point-max))
2213 (should-error (org-forward-element)))
2214 ;; 2. Standard move: expected to ignore blank lines.
2215 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2216 (org-forward-element)
2217 (should (looking-at (regexp-quote "Second paragraph."))))
2218 ;; 3. Headline tests.
2219 (org-test-with-temp-text "
2224 ;; 3.1. At an headline beginning: move to next headline at the
2227 (org-forward-element)
2228 (should (looking-at (regexp-quote "** Head 1.2")))
2229 ;; 3.2. At an headline beginning: move to parent headline if no
2230 ;; headline at the same level.
2232 (org-forward-element)
2233 (should (looking-at (regexp-quote "** Head 1.2"))))
2234 ;; 4. Greater element tests.
2235 (org-test-with-temp-text
2236 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2237 ;; 4.1. At a greater element: expected to skip contents.
2238 (org-forward-element)
2239 (should (looking-at (regexp-quote "Outside.")))
2240 ;; 4.2. At the end of greater element contents: expected to skip
2241 ;; to the end of the greater element.
2243 (org-forward-element)
2244 (should (looking-at (regexp-quote "Outside."))))
2246 (org-test-with-temp-text "
2260 ;; 5.1. At list top point: expected to move to the element after
2263 (org-forward-element)
2264 (should (looking-at (regexp-quote "Outside.")))
2265 ;; 5.2. Special case: at the first line of a sub-list, but not at
2266 ;; beginning of line, move to next item.
2269 (org-forward-element)
2270 (should (looking-at "- item2"))
2273 (org-forward-element)
2274 (should (looking-at " - sub2"))
2275 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2277 (org-forward-element)
2278 (should (looking-at (regexp-quote " Inner paragraph.")))
2279 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2281 (org-forward-element)
2282 (should (looking-at (regexp-quote " Inner paragraph.")))
2283 ;; 5.5. At an item: expected to move to next item, if any.
2285 (org-forward-element)
2286 (should (looking-at " - sub3"))))
2288 (ert-deftest test-org
/backward-element
()
2289 "Test `org-backward-element' specifications."
2290 ;; 1. Should error at BOB.
2291 (org-test-with-temp-text " \nParagraph."
2292 (should-error (org-backward-element)))
2293 ;; 2. Should move at BOB when called on the first element in buffer.
2295 (org-test-with-temp-text "\n#+TITLE: test"
2296 (progn (forward-line)
2297 (org-backward-element)
2299 ;; 3. Not at the beginning of an element: move at its beginning.
2300 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2303 (org-backward-element)
2304 (should (looking-at (regexp-quote "Paragraph2."))))
2305 ;; 4. Headline tests.
2306 (org-test-with-temp-text "
2311 ;; 4.1. At an headline beginning: move to previous headline at the
2314 (org-backward-element)
2315 (should (looking-at (regexp-quote "** Head 1.1")))
2316 ;; 4.2. At an headline beginning: move to parent headline if no
2317 ;; headline at the same level.
2319 (org-backward-element)
2320 (should (looking-at (regexp-quote "* Head 1")))
2321 ;; 4.3. At the first top-level headline: should error.
2323 (should-error (org-backward-element)))
2324 ;; 5. At beginning of first element inside a greater element:
2325 ;; expected to move to greater element's beginning.
2326 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2328 (org-backward-element)
2329 (should (looking-at "#\\+BEGIN_CENTER")))
2330 ;; 6. At the beginning of the first element in a section: should
2331 ;; move back to headline, if any.
2333 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2334 (progn (goto-char (point-max))
2336 (org-backward-element)
2337 (org-at-heading-p))))
2339 (org-test-with-temp-text "
2354 ;; 7.1. At beginning of sub-list: expected to move to the
2355 ;; paragraph before it.
2357 (org-backward-element)
2358 (should (looking-at "item1"))
2359 ;; 7.2. At an item in a list: expected to move at previous item.
2361 (org-backward-element)
2362 (should (looking-at " - sub2"))
2364 (org-backward-element)
2365 (should (looking-at "- item1"))
2366 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2369 (org-backward-element)
2370 (should (looking-at " - sub1"))
2372 (org-backward-element)
2373 (should (looking-at "- item1"))
2374 ;; 7.4. At blank-lines before list end: expected to move to top
2377 (org-backward-element)
2378 (should (looking-at "- item1"))))
2380 (ert-deftest test-org
/up-element
()
2381 "Test `org-up-element' specifications."
2382 ;; 1. At BOB or with no surrounding element: should error.
2383 (org-test-with-temp-text "Paragraph."
2384 (should-error (org-up-element)))
2385 (org-test-with-temp-text "* Head1\n* Head2"
2387 (should-error (org-up-element)))
2388 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2390 (should-error (org-up-element)))
2391 ;; 2. At an headline: move to parent headline.
2392 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2395 (should (looking-at "\\* Head1")))
2396 ;; 3. Inside a greater element: move to greater element beginning.
2397 (org-test-with-temp-text
2398 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2401 (should (looking-at "#\\+BEGIN_CENTER")))
2403 (org-test-with-temp-text "* Top
2410 Paragraph within sub2.
2413 ;; 4.1. Within an item: move to the item beginning.
2416 (should (looking-at " - sub2"))
2417 ;; 4.2. At an item in a sub-list: move to parent item.
2420 (should (looking-at "- item1"))
2421 ;; 4.3. At an item in top list: move to beginning of whole list.
2424 (should (looking-at "- item1"))
2425 ;; 4.4. Special case. At very top point: should move to parent of
2429 (should (looking-at "\\* Top"))))
2431 (ert-deftest test-org
/down-element
()
2432 "Test `org-down-element' specifications."
2433 ;; Error when the element hasn't got a recursive type.
2434 (org-test-with-temp-text "Paragraph."
2435 (should-error (org-down-element)))
2436 ;; Error when the element has no contents
2437 (org-test-with-temp-text "* Headline"
2438 (should-error (org-down-element)))
2439 ;; When at a plain-list, move to first item.
2440 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2443 (should (looking-at " - Item 1.1")))
2444 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2446 (should (looking-at " Item 1")))
2447 ;; When at a table, move to first row
2448 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2450 (should (looking-at " a | b |")))
2451 ;; Otherwise, move inside the greater element.
2452 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2454 (should (looking-at "Paragraph"))))
2456 (ert-deftest test-org
/drag-element-backward
()
2457 "Test `org-drag-element-backward' specifications."
2461 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2462 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2463 (org-drag-element-backward)
2467 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2468 (org-test-with-temp-text
2469 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2470 (org-drag-element-backward)
2472 ;; Preserve blank lines.
2474 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2475 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2476 (org-drag-element-backward)
2480 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2481 (org-drag-element-backward)
2482 (org-looking-at-p "2")))
2483 ;; Error when trying to move first element of buffer.
2485 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2486 (org-drag-element-backward)))
2487 ;; Error when trying to swap nested elements.
2489 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2491 (org-drag-element-backward)))
2492 ;; Error when trying to swap an headline element and a non-headline
2495 (org-test-with-temp-text "Test.\n* Head 1"
2497 (org-drag-element-backward)))
2498 ;; Preserve visibility of elements and their contents.
2500 (equal '((63 .
82) (26 .
48))
2501 (org-test-with-temp-text "
2509 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2510 (search-backward "- item 1")
2511 (org-drag-element-backward)
2512 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2513 (overlays-in (point-min) (point-max)))))))
2515 (ert-deftest test-org
/drag-element-forward
()
2516 "Test `org-drag-element-forward' specifications."
2517 ;; 1. Error when trying to move first element of buffer.
2518 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2520 (should-error (org-drag-element-forward)))
2521 ;; 2. Error when trying to swap nested elements.
2522 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2524 (should-error (org-drag-element-forward)))
2525 ;; 3. Error when trying to swap a non-headline element and an
2527 (org-test-with-temp-text "Test.\n* Head 1"
2528 (should-error (org-drag-element-forward)))
2529 ;; 4. Otherwise, swap elements, preserving column and blank lines
2530 ;; between elements.
2531 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2532 (search-forward "graph")
2533 (org-drag-element-forward)
2534 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2535 (should (looking-at " 1")))
2536 ;; 5. Preserve visibility of elements and their contents.
2537 (org-test-with-temp-text "
2545 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2546 (search-backward "#+BEGIN_CENTER")
2547 (org-drag-element-forward)
2550 '((63 .
82) (26 .
48))
2551 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2552 (overlays-in (point-min) (point-max)))))))
2554 (ert-deftest test-org
/next-block
()
2555 "Test `org-next-block' specifications."
2558 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2560 (looking-at "#\\+BEGIN_CENTER")))
2563 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2564 (let ((case-fold-search nil
))
2566 (looking-at "#\\+begin_center"))))
2567 ;; Ignore current line.
2569 (org-test-with-temp-text
2570 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2572 (looking-at "#\\+BEGIN_CENTER")))
2573 ;; Throw an error when no block is found.
2575 (org-test-with-temp-text "Paragraph"
2576 (org-next-block 1)))
2577 ;; With an argument, skip many blocks at once.
2579 (org-test-with-temp-text
2580 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2582 (looking-at "#\\+BEGIN_QUOTE")))
2583 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2585 (org-test-with-temp-text
2586 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2587 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2588 (looking-at "#\\+BEGIN_QUOTE")))
2589 ;; Optional argument is also case-insensitive.
2591 (org-test-with-temp-text
2592 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2593 (let ((case-fold-search nil
))
2594 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2595 (looking-at "#\\+begin_quote")))))
2597 (ert-deftest test-org
/previous-block
()
2598 "Test `org-previous-block' specifications."
2601 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2602 (org-previous-block 1)
2603 (looking-at "#\\+BEGIN_CENTER")))
2606 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2607 (let ((case-fold-search nil
))
2608 (org-previous-block 1)
2609 (looking-at "#\\+begin_center"))))
2610 ;; Ignore current line.
2612 (org-test-with-temp-text
2613 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2614 (org-previous-block 1)
2615 (looking-at "#\\+BEGIN_QUOTE")))
2616 ;; Throw an error when no block is found.
2618 (org-test-with-temp-text "Paragraph<point>"
2619 (org-previous-block 1)))
2620 ;; With an argument, skip many blocks at once.
2622 (org-test-with-temp-text
2623 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2624 (org-previous-block 2)
2625 (looking-at "#\\+BEGIN_CENTER")))
2626 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2628 (org-test-with-temp-text
2629 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2630 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2631 (looking-at "#\\+BEGIN_QUOTE")))
2632 ;; Optional argument is also case-insensitive.
2634 (org-test-with-temp-text
2635 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2636 (let ((case-fold-search nil
))
2637 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2638 (looking-at "#\\+begin_quote")))))
2641 ;;; Outline structure
2643 (ert-deftest test-org
/demote
()
2644 "Test `org-demote' specifications."
2645 ;; Add correct number of stars according to `org-odd-levels-only'.
2648 (org-test-with-temp-text "* H"
2649 (let ((org-odd-levels-only nil
)) (org-demote))
2650 (org-current-level))))
2653 (org-test-with-temp-text "* H"
2654 (let ((org-odd-levels-only t
)) (org-demote))
2655 (org-current-level))))
2656 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2658 (org-test-with-temp-text "* H :tag:"
2659 (let ((org-tags-column 10)
2660 (org-auto-align-tags t
)
2661 (org-odd-levels-only nil
))
2663 (org-move-to-column 10)
2664 (org-looking-at-p ":tag:$")))
2666 (org-test-with-temp-text "* H :tag:"
2667 (let ((org-tags-column 10)
2668 (org-auto-align-tags nil
)
2669 (org-odd-levels-only nil
))
2671 (org-move-to-column 10)
2672 (org-looking-at-p ":tag:$")))
2673 ;; When `org-adapt-indentation' is non-nil, always indent planning
2674 ;; info and property drawers accordingly.
2677 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2678 (let ((org-odd-levels-only nil
)
2679 (org-adapt-indentation t
))
2682 (org-get-indentation))))
2685 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2686 (let ((org-odd-levels-only nil
)
2687 (org-adapt-indentation t
))
2690 (org-get-indentation))))
2693 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2694 (let ((org-odd-levels-only nil
)
2695 (org-adapt-indentation nil
))
2698 (org-get-indentation))))
2699 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2700 ;; section accordingly. Ignore, however, footnote definitions and
2701 ;; inlinetasks boundaries.
2704 (org-test-with-temp-text "* H\n Paragraph"
2705 (let ((org-odd-levels-only nil
)
2706 (org-adapt-indentation t
))
2709 (org-get-indentation))))
2712 (org-test-with-temp-text "* H\n Paragraph"
2713 (let ((org-odd-levels-only nil
)
2714 (org-adapt-indentation nil
))
2717 (org-get-indentation))))
2720 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2721 (let ((org-odd-levels-only nil
)
2722 (org-adapt-indentation t
))
2724 (goto-char (point-max))
2725 (org-get-indentation))))
2728 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2729 (let ((org-odd-levels-only nil
)
2730 (org-adapt-indentation t
))
2732 (goto-char (point-max))
2733 (org-get-indentation))))
2734 (when (featurep 'org-inlinetask
)
2737 (let ((org-inlinetask-min-level 5)
2738 (org-adapt-indentation t
))
2739 (org-test-with-temp-text "* H\n***** I\n***** END"
2742 (org-get-indentation))))))
2743 (when (featurep 'org-inlinetask
)
2746 (let ((org-inlinetask-min-level 5)
2747 (org-adapt-indentation t
))
2748 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2751 (org-get-indentation))))))
2752 ;; Ignore contents of source blocks or example blocks when
2753 ;; indentation should be preserved (through
2754 ;; `org-src-preserve-indentation' or "-i" flag).
2757 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2758 (let ((org-adapt-indentation t
)
2759 (org-src-preserve-indentation nil
))
2762 (org-get-indentation))))
2765 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2766 (let ((org-adapt-indentation t
)
2767 (org-src-preserve-indentation t
))
2770 (org-get-indentation))))
2773 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2774 (let ((org-adapt-indentation t
)
2775 (org-src-preserve-indentation t
))
2778 (org-get-indentation))))
2781 (org-test-with-temp-text
2782 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2783 (let ((org-adapt-indentation t
)
2784 (org-src-preserve-indentation nil
))
2787 (org-get-indentation)))))
2789 (ert-deftest test-org
/promote
()
2790 "Test `org-promote' specifications."
2791 ;; Return an error if headline is to be promoted to level 0, unless
2792 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2793 ;; headline becomes a comment.
2795 (org-test-with-temp-text "* H"
2796 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2799 (org-test-with-temp-text "* H"
2800 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2802 ;; Remove correct number of stars according to
2803 ;; `org-odd-levels-only'.
2806 (org-test-with-temp-text "*** H"
2807 (let ((org-odd-levels-only nil
)) (org-promote))
2808 (org-current-level))))
2811 (org-test-with-temp-text "*** H"
2812 (let ((org-odd-levels-only t
)) (org-promote))
2813 (org-current-level))))
2814 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2816 (org-test-with-temp-text "** H :tag:"
2817 (let ((org-tags-column 10)
2818 (org-auto-align-tags t
)
2819 (org-odd-levels-only nil
))
2821 (org-move-to-column 10)
2822 (org-looking-at-p ":tag:$")))
2824 (org-test-with-temp-text "** H :tag:"
2825 (let ((org-tags-column 10)
2826 (org-auto-align-tags nil
)
2827 (org-odd-levels-only nil
))
2829 (org-move-to-column 10)
2830 (org-looking-at-p ":tag:$")))
2831 ;; When `org-adapt-indentation' is non-nil, always indent planning
2832 ;; info and property drawers.
2835 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2836 (let ((org-odd-levels-only nil
)
2837 (org-adapt-indentation t
))
2840 (org-get-indentation))))
2843 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2844 (let ((org-odd-levels-only nil
)
2845 (org-adapt-indentation t
))
2848 (org-get-indentation))))
2851 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2852 (let ((org-odd-levels-only nil
)
2853 (org-adapt-indentation nil
))
2856 (org-get-indentation))))
2857 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2858 ;; section accordingly. Ignore, however, footnote definitions and
2859 ;; inlinetasks boundaries.
2862 (org-test-with-temp-text "** H\n Paragraph"
2863 (let ((org-odd-levels-only nil
)
2864 (org-adapt-indentation t
))
2867 (org-get-indentation))))
2870 (org-test-with-temp-text "** H\n Paragraph"
2871 (let ((org-odd-levels-only nil
)
2872 (org-adapt-indentation nil
))
2875 (org-get-indentation))))
2878 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2879 (let ((org-odd-levels-only nil
)
2880 (org-adapt-indentation t
))
2883 (org-get-indentation))))
2884 (when (featurep 'org-inlinetask
)
2887 (let ((org-inlinetask-min-level 5)
2888 (org-adapt-indentation t
))
2889 (org-test-with-temp-text "** H\n***** I\n***** END"
2892 (org-get-indentation))))))
2893 (when (featurep 'org-inlinetask
)
2896 (let ((org-inlinetask-min-level 5)
2897 (org-adapt-indentation t
))
2898 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2901 (org-get-indentation))))))
2902 ;; Give up shifting if it would break document's structure
2906 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2907 (let ((org-odd-levels-only nil
)
2908 (org-adapt-indentation t
))
2911 (org-get-indentation))))
2914 (org-test-with-temp-text "** H\n Paragraph\n * list."
2915 (let ((org-odd-levels-only nil
)
2916 (org-adapt-indentation t
))
2919 (org-get-indentation))))
2920 ;; Ignore contents of source blocks or example blocks when
2921 ;; indentation should be preserved (through
2922 ;; `org-src-preserve-indentation' or "-i" flag).
2925 (org-test-with-temp-text
2926 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2927 (let ((org-adapt-indentation t
)
2928 (org-src-preserve-indentation nil
)
2929 (org-odd-levels-only nil
))
2932 (org-get-indentation))))
2935 (org-test-with-temp-text
2936 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2937 (let ((org-adapt-indentation t
)
2938 (org-src-preserve-indentation t
)
2939 (org-odd-levels-only nil
))
2942 (org-get-indentation))))
2945 (org-test-with-temp-text
2946 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2947 (let ((org-adapt-indentation t
)
2948 (org-src-preserve-indentation t
)
2949 (org-odd-levels-only nil
))
2952 (org-get-indentation))))
2955 (org-test-with-temp-text
2956 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2957 (let ((org-adapt-indentation t
)
2958 (org-src-preserve-indentation nil
)
2959 (org-odd-levels-only nil
))
2962 (org-get-indentation)))))
2967 (ert-deftest test-org
/at-planning-p
()
2968 "Test `org-at-planning-p' specifications."
2971 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2972 (org-at-planning-p)))
2974 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2975 (org-at-planning-p)))
2976 ;; Correctly find planning attached to inlinetasks.
2977 (when (featurep 'org-inlinetask
)
2979 (org-test-with-temp-text
2980 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2981 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2983 (org-test-with-temp-text
2984 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2985 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2987 (org-test-with-temp-text
2988 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2989 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2991 (org-test-with-temp-text
2992 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2993 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2995 (ert-deftest test-org
/add-planning-info
()
2996 "Test `org-add-planning-info'."
2997 ;; Create deadline when `org-adapt-indentation' is non-nil.
2999 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3000 (org-test-with-temp-text "* H\nParagraph<point>"
3001 (let ((org-adapt-indentation t
))
3002 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3003 (replace-regexp-in-string
3004 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3006 ;; Create deadline when `org-adapt-indentation' is nil.
3008 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3009 (org-test-with-temp-text "* H\nParagraph<point>"
3010 (let ((org-adapt-indentation nil
))
3011 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3012 (replace-regexp-in-string
3013 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3015 ;; Update deadline when `org-adapt-indentation' is non-nil.
3017 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3018 (org-test-with-temp-text "\
3020 DEADLINE: <2015-06-24 Wed>
3022 (let ((org-adapt-indentation t
))
3023 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3024 (replace-regexp-in-string
3025 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3027 ;; Update deadline when `org-adapt-indentation' is nil.
3029 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3030 (org-test-with-temp-text "\
3032 DEADLINE: <2015-06-24 Wed>
3034 (let ((org-adapt-indentation nil
))
3035 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3036 (replace-regexp-in-string
3037 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3039 ;; Schedule when `org-adapt-indentation' is non-nil.
3041 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3042 (org-test-with-temp-text "* H\nParagraph<point>"
3043 (let ((org-adapt-indentation t
))
3044 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3045 (replace-regexp-in-string
3046 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3048 ;; Schedule when `org-adapt-indentation' is nil.
3050 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3051 (org-test-with-temp-text "* H\nParagraph<point>"
3052 (let ((org-adapt-indentation nil
))
3053 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3054 (replace-regexp-in-string
3055 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3057 ;; Add deadline when scheduled.
3061 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3063 (org-test-with-temp-text "\
3065 SCHEDULED: <2015-06-24 Wed>
3067 (let ((org-adapt-indentation t
))
3068 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3069 (replace-regexp-in-string
3070 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3072 ;; Remove middle entry.
3076 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3078 (org-test-with-temp-text "\
3080 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3082 (let ((org-adapt-indentation t
))
3083 (org-add-planning-info nil nil
'deadline
))
3084 (replace-regexp-in-string
3085 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3087 ;; Remove last entry and then middle entry (order should not
3092 CLOSED: [2015-06-24]
3094 (org-test-with-temp-text "\
3096 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3098 (let ((org-adapt-indentation t
))
3099 (org-add-planning-info nil nil
'scheduled
'deadline
))
3100 (replace-regexp-in-string
3101 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3103 ;; Remove closed when `org-adapt-indentation' is non-nil.
3105 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3106 (org-test-with-temp-text "\
3108 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3110 (let ((org-adapt-indentation t
))
3111 (org-add-planning-info nil nil
'closed
))
3112 (replace-regexp-in-string
3113 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3116 (equal "* H\n Paragraph"
3117 (org-test-with-temp-text "\
3119 CLOSED: [2015-06-25 Thu]
3121 (let ((org-adapt-indentation t
))
3122 (org-add-planning-info nil nil
'closed
))
3123 (replace-regexp-in-string
3124 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3126 ;; Remove closed when `org-adapt-indentation' is nil.
3128 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3129 (org-test-with-temp-text "\
3131 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3133 (let ((org-adapt-indentation nil
))
3134 (org-add-planning-info nil nil
'closed
))
3135 (replace-regexp-in-string
3136 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3139 (equal "* H\nParagraph"
3140 (org-test-with-temp-text "\
3142 CLOSED: [2015-06-25 Thu]
3144 (let ((org-adapt-indentation nil
))
3145 (org-add-planning-info nil nil
'closed
))
3146 (replace-regexp-in-string
3147 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3149 ;; Remove closed entry and delete empty line.
3154 (org-test-with-temp-text "\
3156 CLOSED: [2015-06-24 Wed]
3158 (let ((org-adapt-indentation t
))
3159 (org-add-planning-info nil nil
'closed
))
3160 (replace-regexp-in-string
3161 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3163 ;; Remove one entry and update another.
3165 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3166 (org-test-with-temp-text "\
3168 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3170 (let ((org-adapt-indentation t
))
3171 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3172 (replace-regexp-in-string
3173 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3179 (ert-deftest test-org
/buffer-property-keys
()
3180 "Test `org-buffer-property-keys' specifications."
3181 ;; Retrieve properties accross siblings.
3184 (org-test-with-temp-text "
3193 (org-buffer-property-keys))))
3194 ;; Retrieve properties accross children.
3197 (org-test-with-temp-text "
3206 (org-buffer-property-keys))))
3207 ;; Retrieve muliple properties in the same drawer.
3210 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3211 (org-buffer-property-keys))))
3212 ;; Ignore extension symbol in property name.
3215 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3216 (org-buffer-property-keys))))
3217 ;; With non-nil COLUMNS, extract property names from columns.
3220 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3221 (org-buffer-property-keys nil nil t
))))
3223 (equal '("A" "B" "COLUMNS")
3224 (org-test-with-temp-text
3225 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3226 (org-buffer-property-keys nil nil t
)))))
3228 (ert-deftest test-org
/property-values
()
3229 "Test `org-property-values' specifications."
3233 (org-test-with-temp-text
3234 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3235 (org-property-values "A"))))
3236 ;; Ignore empty values.
3238 (org-test-with-temp-text
3239 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3240 (org-property-values "A")))
3241 ;; Take into consideration extended values.
3244 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3245 (org-property-values "A")))))
3247 (ert-deftest test-org
/find-property
()
3248 "Test `org-find-property' specifications."
3252 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3253 (org-find-property "prop"))))
3254 ;; Ignore false positives.
3257 (org-test-with-temp-text
3258 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3259 (org-find-property "A"))))
3260 ;; Return first entry found in buffer.
3263 (org-test-with-temp-text
3264 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3265 (org-find-property "A"))))
3266 ;; Only search visible part of the buffer.
3269 (org-test-with-temp-text
3270 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3271 (org-narrow-to-subtree)
3272 (org-find-property "A"))))
3273 ;; With optional argument, only find entries with a specific value.
3275 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3276 (org-find-property "A" "2")))
3279 (org-test-with-temp-text
3280 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3281 (org-find-property "A" "2"))))
3282 ;; Use "nil" for explicit nil values.
3285 (org-test-with-temp-text
3286 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3287 (org-find-property "A" "nil")))))
3289 (ert-deftest test-org
/entry-delete
()
3290 "Test `org-entry-delete' specifications."
3294 " *:PROPERTIES:\n *:B: +2\n *:END:"
3295 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3296 (org-entry-delete (point) "A")
3298 ;; Also remove accumulated properties.
3302 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3303 (org-entry-delete (point) "A")
3305 ;; When last property is removed, remove the property drawer.
3309 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3310 (org-entry-delete (point) "A")
3312 ;; Return a non-nil value when some property was removed.
3314 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3315 (org-entry-delete (point) "A")))
3317 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3318 (org-entry-delete (point) "C"))))
3320 (ert-deftest test-org
/entry-get
()
3321 "Test `org-entry-get' specifications."
3325 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3326 (org-entry-get (point) "A"))))
3330 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3331 (org-entry-get (point) "a"))))
3332 ;; Handle extended values, both before and after base value.
3335 (org-test-with-temp-text
3336 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3337 (org-entry-get (point) "A"))))
3338 ;; Empty values are returned as the empty string.
3341 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3342 (org-entry-get (point) "A"))))
3343 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3344 ;; otherwise, return nil.
3346 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3347 (org-entry-get (point) "A")))
3350 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3351 (org-entry-get (point) "A" nil t
))))
3352 ;; Return nil when no property is found, independently on the
3353 ;; LITERAL-NIL argument.
3355 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3356 (org-entry-get (point) "B")))
3358 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3359 (org-entry-get (point) "B" nil t
)))
3360 ;; Handle inheritance, when allowed. Include extended values and
3361 ;; possibly global values.
3365 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3366 (org-entry-get (point) "A" t
))))
3370 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3371 (let ((org-use-property-inheritance t
))
3372 (org-entry-get (point) "A" 'selective
)))))
3374 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3375 (let ((org-use-property-inheritance nil
))
3376 (org-entry-get (point) "A" 'selective
))))
3380 (org-test-with-temp-text
3381 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3382 (org-entry-get (point-max) "A" t
))))
3385 (org-test-with-temp-text
3386 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3388 (org-entry-get (point-max) "A" t
))))
3391 (org-test-with-temp-text
3392 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3394 (org-entry-get (point-max) "A" t
)))))
3396 (ert-deftest test-org
/entry-properties
()
3397 "Test `org-entry-properties' specifications."
3398 ;; Get "ITEM" property.
3401 (org-test-with-temp-text "* TODO H"
3402 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3405 (org-test-with-temp-text "* TODO H"
3406 (cdr (assoc "ITEM" (org-entry-properties))))))
3407 ;; Get "TODO" property. TODO keywords are case sensitive.
3410 (org-test-with-temp-text "* TODO H"
3411 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3414 (org-test-with-temp-text "* TODO H"
3415 (cdr (assoc "TODO" (org-entry-properties))))))
3417 (org-test-with-temp-text "* H"
3418 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3420 (org-test-with-temp-text "* todo H"
3421 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3422 ;; Get "PRIORITY" property.
3425 (org-test-with-temp-text "* [#A] H"
3426 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3429 (org-test-with-temp-text "* [#A] H"
3430 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3432 (equal (char-to-string org-default-priority
)
3433 (org-test-with-temp-text "* H"
3434 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3435 ;; Get "FILE" property.
3437 (org-test-with-temp-text-in-file "* H\nParagraph"
3438 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3439 (buffer-file-name))))
3441 (org-test-with-temp-text-in-file "* H\nParagraph"
3442 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3443 (buffer-file-name))))
3445 (org-test-with-temp-text "* H\nParagraph"
3446 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3447 ;; Get "TAGS" property.
3449 (equal ":tag1:tag2:"
3450 (org-test-with-temp-text "* H :tag1:tag2:"
3451 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3453 (equal ":tag1:tag2:"
3454 (org-test-with-temp-text "* H :tag1:tag2:"
3455 (cdr (assoc "TAGS" (org-entry-properties))))))
3457 (org-test-with-temp-text "* H"
3458 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3459 ;; Get "ALLTAGS" property.
3461 (equal ":tag1:tag2:"
3462 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3463 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3465 (equal ":tag1:tag2:"
3466 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3467 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3469 (org-test-with-temp-text "* H"
3470 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3471 ;; Get "BLOCKED" property.
3474 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3475 (let ((org-enforce-todo-dependencies t
)
3477 '(org-block-todo-from-children-or-siblings-or-parent)))
3478 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3481 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
3482 (let ((org-enforce-todo-dependencies t
)
3484 '(org-block-todo-from-children-or-siblings-or-parent)))
3485 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3486 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3490 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3491 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3495 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3496 (cdr (assoc "CLOSED" (org-entry-properties))))))
3498 (org-test-with-temp-text "* H"
3499 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3503 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3504 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3508 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3509 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3511 (org-test-with-temp-text "* H"
3512 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3516 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3517 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3521 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3522 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3524 (org-test-with-temp-text "* H"
3525 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3529 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3530 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3533 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3534 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3537 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3538 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3541 (org-test-with-temp-text
3542 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3544 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3545 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3546 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
3548 (equal "<2012-03-29 thu.>"
3549 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
3550 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
3552 (equal "[2012-03-29 thu.]"
3553 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
3554 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
3556 (equal "<2012-03-29 thu.>"
3557 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
3558 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
3560 (equal "[2014-03-04 tue.]"
3561 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
3562 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
3563 ;; Get standard properties.
3566 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3567 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3568 ;; Handle extended properties.
3571 (org-test-with-temp-text
3572 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3573 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3576 (org-test-with-temp-text
3577 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3578 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3579 ;; Ignore forbidden (special) properties.
3581 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3582 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3584 (ert-deftest test-org
/entry-put
()
3585 "Test `org-entry-put' specifications."
3586 ;; Error when not a string or nil.
3588 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3589 (org-entry-put 1 "test" 2)))
3590 ;; Set "TODO" property.
3592 (string-match (regexp-quote " TODO H")
3593 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3594 (org-entry-put (point) "TODO" "TODO")
3597 (string-match (regexp-quote "* H")
3598 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3599 (org-entry-put (point) "TODO" nil
)
3601 ;; Set "PRIORITY" property.
3604 (org-test-with-temp-text "* [#B] H"
3605 (org-entry-put (point) "PRIORITY" "A")
3609 (org-test-with-temp-text "* [#B] H"
3610 (org-entry-put (point) "PRIORITY" nil
)
3612 ;; Set "SCHEDULED" property.
3614 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3615 (org-test-with-temp-text "* H"
3616 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3620 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3621 (org-entry-put (point) "SCHEDULED" nil
)
3624 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3625 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3626 (org-entry-put (point) "SCHEDULED" "earlier")
3629 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3630 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3631 (org-entry-put (point) "SCHEDULED" "later")
3633 ;; Set "DEADLINE" property.
3635 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3636 (org-test-with-temp-text "* H"
3637 (org-entry-put (point) "DEADLINE" "2014-03-04")
3641 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3642 (org-entry-put (point) "DEADLINE" nil
)
3645 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3646 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3647 (org-entry-put (point) "DEADLINE" "earlier")
3650 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3651 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3652 (org-entry-put (point) "DEADLINE" "later")
3654 ;; Set "CATEGORY" property
3656 (string-match "^ *:CATEGORY: cat"
3657 (org-test-with-temp-text "* H"
3658 (org-entry-put (point) "CATEGORY" "cat")
3660 ;; Regular properties, with or without pre-existing drawer.
3662 (string-match "^ *:A: +2$"
3663 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3664 (org-entry-put (point) "A" "2")
3667 (string-match "^ *:A: +1$"
3668 (org-test-with-temp-text "* H"
3669 (org-entry-put (point) "A" "1")
3671 ;; Special case: two consecutive headlines.
3673 (string-match "\\* A\n *:PROPERTIES:"
3674 (org-test-with-temp-text "* A\n** B"
3675 (org-entry-put (point) "A" "1")
3681 (ert-deftest test-org
/update-radio-target-regexp
()
3682 "Test `org-update-radio-target-regexp' specifications."
3683 ;; Properly update cache with no previous radio target regexp.
3686 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3687 (save-excursion (goto-char (point-max)) (org-element-context))
3689 (search-forward "o")
3691 (org-update-radio-target-regexp)
3692 (goto-char (point-max))
3693 (org-element-type (org-element-context)))))
3694 ;; Properly update cache with previous radio target regexp.
3697 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3698 (save-excursion (goto-char (point-max)) (org-element-context))
3700 (search-forward "o")
3702 (org-update-radio-target-regexp)
3703 (search-backward "r")
3706 (org-update-radio-target-regexp)
3707 (goto-char (point-max))
3708 (delete-region (line-beginning-position) (point))
3710 (org-element-type (org-element-context))))))
3715 (ert-deftest test-org
/match-sparse-tree
()
3716 "Test `org-match-sparse-tree' specifications."
3719 (org-test-with-temp-text "* H\n** H1 :tag:"
3720 (org-match-sparse-tree nil
"tag")
3721 (search-forward "H1")
3722 (org-invisible-p2)))
3724 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3725 (org-match-sparse-tree nil
"tag")
3726 (search-forward "H2")
3727 (org-invisible-p2)))
3728 ;; "-" operator for tags.
3730 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3731 (org-match-sparse-tree nil
"tag1-tag2")
3732 (search-forward "H1")
3733 (org-invisible-p2)))
3735 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3736 (org-match-sparse-tree nil
"tag1-tag2")
3737 (search-forward "H2")
3738 (org-invisible-p2)))
3739 ;; "&" operator for tags.
3741 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3742 (org-match-sparse-tree nil
"tag1&tag2")
3743 (search-forward "H1")
3744 (org-invisible-p2)))
3746 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3747 (org-match-sparse-tree nil
"tag1&tag2")
3748 (search-forward "H2")
3749 (org-invisible-p2)))
3750 ;; "|" operator for tags.
3752 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3753 (org-match-sparse-tree nil
"tag1|tag2")
3754 (search-forward "H1")
3755 (org-invisible-p2)))
3757 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3758 (org-match-sparse-tree nil
"tag1|tag2")
3759 (search-forward "H2")
3760 (org-invisible-p2)))
3761 ;; Regexp match on tags.
3763 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3764 (org-match-sparse-tree nil
"{^tag.*}")
3765 (search-forward "H1")
3766 (org-invisible-p2)))
3768 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3769 (org-match-sparse-tree nil
"{^tag.*}")
3770 (search-forward "H2")
3771 (org-invisible-p2)))
3772 ;; Match group tags.
3774 (org-test-with-temp-text
3775 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3776 (org-match-sparse-tree nil
"work")
3777 (search-forward "H1")
3778 (org-invisible-p2)))
3780 (org-test-with-temp-text
3781 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3782 (org-match-sparse-tree nil
"work")
3783 (search-forward "H2")
3784 (org-invisible-p2)))
3785 ;; Match group tags with hard brackets.
3787 (org-test-with-temp-text
3788 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3789 (org-match-sparse-tree nil
"work")
3790 (search-forward "H1")
3791 (org-invisible-p2)))
3793 (org-test-with-temp-text
3794 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3795 (org-match-sparse-tree nil
"work")
3796 (search-forward "H2")
3797 (org-invisible-p2)))
3798 ;; Match tags in hierarchies
3800 (org-test-with-temp-text
3801 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3802 #+TAGS: [ Lev_2 : Lev_3 ]\n
3803 #+TAGS: { Lev_3 : Lev_4 }\n
3804 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3805 (org-match-sparse-tree nil
"Lev_1")
3806 (search-forward "H4")
3807 (org-invisible-p2)))
3808 ;; Match regular expressions in tags
3810 (org-test-with-temp-text
3811 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3812 (org-match-sparse-tree nil
"Lev")
3813 (search-forward "H1")
3814 (org-invisible-p2)))
3816 (org-test-with-temp-text
3817 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3818 (org-match-sparse-tree nil
"Lev")
3819 (search-forward "H1")
3820 (org-invisible-p2)))
3821 ;; Match properties.
3823 (org-test-with-temp-text
3824 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3825 (org-match-sparse-tree nil
"A=\"1\"")
3826 (search-forward "H2")
3827 (org-invisible-p2)))
3829 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3830 (org-match-sparse-tree nil
"A=\"1\"")
3831 (search-forward "H2")
3832 (org-invisible-p2)))
3833 ;; Case is not significant when matching properties.
3835 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3836 (org-match-sparse-tree nil
"a=\"1\"")
3837 (search-forward "H2")
3838 (org-invisible-p2)))
3840 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3841 (org-match-sparse-tree nil
"A=\"1\"")
3842 (search-forward "H2")
3843 (org-invisible-p2)))
3844 ;; Match special LEVEL property.
3846 (org-test-with-temp-text "* H\n** H1\n*** H2"
3847 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3848 (search-forward "H1")
3849 (org-invisible-p2)))
3851 (org-test-with-temp-text "* H\n** H1\n*** H2"
3852 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3853 (search-forward "H2")
3854 (org-invisible-p2)))
3855 ;; Comparison operators when matching properties.
3857 (org-test-with-temp-text
3858 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3859 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3860 (search-forward "H1")
3861 (org-invisible-p2)))
3863 (org-test-with-temp-text
3864 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3865 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3866 (search-forward "H2")
3867 (org-invisible-p2)))
3868 ;; Regexp match on properties values.
3870 (org-test-with-temp-text
3871 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3872 (org-match-sparse-tree nil
"A={f.*}")
3873 (search-forward "H1")
3874 (org-invisible-p2)))
3876 (org-test-with-temp-text
3877 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3878 (org-match-sparse-tree nil
"A={f.*}")
3879 (search-forward "H2")
3880 (org-invisible-p2)))
3881 ;; With an optional argument, limit match to TODO entries.
3883 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3884 (org-match-sparse-tree t
"tag")
3885 (search-forward "H1")
3886 (org-invisible-p2)))
3888 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3889 (org-match-sparse-tree t
"tag")
3890 (search-forward "H2")
3891 (org-invisible-p2))))
3896 (ert-deftest test-org
/time-stamp
()
3897 "Test `org-time-stamp' specifications."
3898 ;; Insert chosen time stamp at point.
3901 "Te<2014-03-04 .*?>xt"
3902 (org-test-with-temp-text "Te<point>xt"
3903 (flet ((org-read-date
3905 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3906 (org-time-stamp nil
)
3908 ;; With a prefix argument, also insert time.
3911 "Te<2014-03-04 .*? 00:41>xt"
3912 (org-test-with-temp-text "Te<point>xt"
3913 (flet ((org-read-date
3915 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3916 (org-time-stamp '(4))
3918 ;; With two universal prefix arguments, insert an active timestamp
3919 ;; with the current time without prompting the user.
3922 "Te<2014-03-04 .*? 00:41>xt"
3923 (org-test-with-temp-text "Te<point>xt"
3924 (flet ((current-time
3926 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3927 (org-time-stamp '(16))
3929 ;; When optional argument is non-nil, insert an inactive timestamp.
3932 "Te\\[2014-03-04 .*?\\]xt"
3933 (org-test-with-temp-text "Te<point>xt"
3934 (flet ((org-read-date
3936 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3937 (org-time-stamp nil t
)
3939 ;; When called from a timestamp, replace existing one.
3943 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3944 (flet ((org-read-date
3946 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3947 (org-time-stamp nil
)
3951 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3952 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3953 (flet ((org-read-date
3955 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3956 (org-time-stamp nil
)
3958 ;; When replacing a timestamp, preserve repeater, if any.
3961 "<2014-03-04 .*? \\+2y>"
3962 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3963 (flet ((org-read-date
3965 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3966 (org-time-stamp nil
)
3968 ;; When called twice in a raw, build a date range.
3971 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3972 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3973 (flet ((org-read-date
3975 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3976 (let ((last-command 'org-time-stamp
)
3977 (this-command 'org-time-stamp
))
3978 (org-time-stamp nil
))
3979 (buffer-string))))))
3981 (ert-deftest test-org
/timestamp-has-time-p
()
3982 "Test `org-timestamp-has-time-p' specifications."
3985 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3986 (org-timestamp-has-time-p (org-element-context))))
3989 (org-test-with-temp-text "<2012-03-29 Thu>"
3990 (org-timestamp-has-time-p (org-element-context)))))
3992 (ert-deftest test-org
/timestamp-format
()
3993 "Test `org-timestamp-format' specifications."
3998 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3999 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4004 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4005 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4007 (ert-deftest test-org
/timestamp-split-range
()
4008 "Test `org-timestamp-split-range' specifications."
4009 ;; Extract range start (active).
4012 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4013 (let ((ts (org-timestamp-split-range (org-element-context))))
4014 (mapcar (lambda (p) (org-element-property p ts
))
4015 '(:year-end
:month-end
:day-end
))))))
4016 ;; Extract range start (inactive)
4019 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4020 (let ((ts (org-timestamp-split-range (org-element-context))))
4021 (mapcar (lambda (p) (org-element-property p ts
))
4022 '(:year-end
:month-end
:day-end
))))))
4023 ;; Extract range end (active).
4026 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4027 (let ((ts (org-timestamp-split-range
4028 (org-element-context) t
)))
4029 (mapcar (lambda (p) (org-element-property p ts
))
4030 '(:year-end
:month-end
:day-end
))))))
4031 ;; Extract range end (inactive)
4034 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4035 (let ((ts (org-timestamp-split-range
4036 (org-element-context) t
)))
4037 (mapcar (lambda (p) (org-element-property p ts
))
4038 '(:year-end
:month-end
:day-end
))))))
4039 ;; Return the timestamp if not a range.
4041 (org-test-with-temp-text "[2012-03-29 Thu]"
4042 (let* ((ts-orig (org-element-context))
4043 (ts-copy (org-timestamp-split-range ts-orig
)))
4044 (eq ts-orig ts-copy
))))
4046 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4047 (let* ((ts-orig (org-element-context))
4048 (ts-copy (org-timestamp-split-range ts-orig
)))
4049 (eq ts-orig ts-copy
)))))
4051 (ert-deftest test-org
/timestamp-translate
()
4052 "Test `org-timestamp-translate' specifications."
4053 ;; Translate whole date range.
4056 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4057 (let ((org-display-custom-times t
)
4058 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4059 (org-timestamp-translate (org-element-context))))))
4060 ;; Translate date range start.
4063 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4064 (let ((org-display-custom-times t
)
4065 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4066 (org-timestamp-translate (org-element-context) 'start
)))))
4067 ;; Translate date range end.
4070 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4071 (let ((org-display-custom-times t
)
4072 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4073 (org-timestamp-translate (org-element-context) 'end
)))))
4074 ;; Translate time range.
4077 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4078 (let ((org-display-custom-times t
)
4079 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4080 (org-timestamp-translate (org-element-context))))))
4081 ;; Translate non-range timestamp.
4084 (org-test-with-temp-text "<2012-03-29 Thu>"
4085 (let ((org-display-custom-times t
)
4086 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4087 (org-timestamp-translate (org-element-context))))))
4088 ;; Do not change `diary' timestamps.
4090 (equal "<%%(org-float t 4 2)>"
4091 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4092 (let ((org-display-custom-times t
)
4093 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4094 (org-timestamp-translate (org-element-context)))))))
4100 (ert-deftest test-org
/flag-drawer
()
4101 "Test `org-flag-drawer' specifications."
4104 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4106 (get-char-property (line-end-position) 'invisible
)))
4109 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4111 (org-flag-drawer nil
)
4112 (get-char-property (line-end-position) 'invisible
)))
4113 ;; Test optional argument.
4115 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4116 (let ((drawer (save-excursion (search-forward ":D2")
4117 (org-element-at-point))))
4118 (org-flag-drawer t drawer
)
4119 (get-char-property (progn (search-forward ":D2") (line-end-position))
4122 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4123 (let ((drawer (save-excursion (search-forward ":D2")
4124 (org-element-at-point))))
4125 (org-flag-drawer t drawer
)
4126 (get-char-property (line-end-position) 'invisible
))))
4127 ;; Do not hide fake drawers.
4129 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4132 (get-char-property (line-end-position) 'invisible
)))
4133 ;; Do not hide incomplete drawers.
4135 (org-test-with-temp-text ":D:\nparagraph"
4138 (get-char-property (line-end-position) 'invisible
)))
4139 ;; Do not hide drawers when called from final blank lines.
4141 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4142 (goto-char (point-max))
4144 (goto-char (point-min))
4145 (get-char-property (line-end-position) 'invisible
)))
4146 ;; Don't leave point in an invisible part of the buffer when hiding
4149 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4150 (goto-char (point-max))
4152 (get-char-property (point) 'invisible
))))
4154 (ert-deftest test-org
/hide-block-toggle
()
4155 "Test `org-hide-block-toggle' specifications."
4156 ;; Error when not at a block.
4158 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4159 (org-hide-block-toggle 'off
)
4160 (get-char-property (line-end-position) 'invisible
)))
4163 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4164 (org-hide-block-toggle)
4165 (get-char-property (line-end-position) 'invisible
)))
4167 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4168 (org-hide-block-toggle)
4169 (get-char-property (line-end-position) 'invisible
)))
4170 ;; Show block unconditionally when optional argument is `off'.
4172 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4173 (org-hide-block-toggle)
4174 (org-hide-block-toggle 'off
)
4175 (get-char-property (line-end-position) 'invisible
)))
4177 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4178 (org-hide-block-toggle 'off
)
4179 (get-char-property (line-end-position) 'invisible
)))
4180 ;; Hide block unconditionally when optional argument is non-nil.
4182 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4183 (org-hide-block-toggle t
)
4184 (get-char-property (line-end-position) 'invisible
)))
4186 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4187 (org-hide-block-toggle)
4188 (org-hide-block-toggle t
)
4189 (get-char-property (line-end-position) 'invisible
)))
4190 ;; Do not hide block when called from final blank lines.
4192 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4193 (org-hide-block-toggle)
4194 (goto-char (point-min))
4195 (get-char-property (line-end-position) 'invisible
)))
4196 ;; Don't leave point in an invisible part of the buffer when hiding
4199 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4200 (org-hide-block-toggle)
4201 (get-char-property (point) 'invisible
))))
4203 (ert-deftest test-org
/hide-block-toggle-maybe
()
4204 "Test `org-hide-block-toggle-maybe' specifications."
4206 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4207 (org-hide-block-toggle-maybe)))
4209 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4211 (ert-deftest test-org
/show-set-visibility
()
4212 "Test `org-show-set-visibility' specifications."
4213 ;; Do not throw an error before first heading.
4215 (org-test-with-temp-text "Preamble\n* Headline"
4216 (org-show-set-visibility 'tree
)
4218 ;; Test all visibility spans, both on headline and in entry.
4219 (let ((list-visible-lines
4220 (lambda (state headerp
)
4221 (org-test-with-temp-text "* Grandmother (0)
4232 **** The other child (11)
4237 (search-forward (if headerp
"Self" "Match"))
4238 (org-show-set-visibility state
)
4239 (goto-char (point-min))
4240 (let (result (line 0))
4242 (unless (org-invisible-p2) (push line result
))
4245 (nreverse result
))))))
4246 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4247 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4248 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4249 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4250 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4251 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4252 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4253 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4254 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4255 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4256 (funcall list-visible-lines
'tree nil
)))
4257 (should (equal '(0 1 3 4 5 7 12 13)
4258 (funcall list-visible-lines
'canonical t
)))
4259 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4260 (funcall list-visible-lines
'canonical nil
)))))
4265 ;;; test-org.el ends here