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 -\n\n<point>"
650 (let ((org-adapt-indentation t
)) (org-indent-line))
651 (org-get-indentation))))
654 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
655 (goto-char (point-max))
656 (let ((org-adapt-indentation t
)) (org-indent-line))
657 (org-get-indentation))))
660 (org-test-with-temp-text "* H\n- A\n - \n"
661 (goto-char (point-max))
662 (let ((org-adapt-indentation t
)) (org-indent-line))
663 (org-get-indentation))))
666 (org-test-with-temp-text "- A\n B\n\n<point>"
667 (let ((org-adapt-indentation nil
)) (org-indent-line))
668 (org-get-indentation))))
669 ;; Likewise, on a blank line at the end of a footnote definition,
670 ;; indent at column 0 if line belongs to the definition. Otherwise,
671 ;; indent like the definition itself.
674 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
675 (goto-char (point-max))
676 (let ((org-adapt-indentation t
)) (org-indent-line))
677 (org-get-indentation))))
680 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
681 (goto-char (point-max))
682 (let ((org-adapt-indentation t
)) (org-indent-line))
683 (org-get-indentation))))
684 ;; After the end of the contents of a greater element, indent like
685 ;; the beginning of the element.
688 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
691 (org-get-indentation))))
692 ;; On blank lines after a paragraph, indent like its last non-empty
696 (org-test-with-temp-text " Paragraph\n\n<point>"
698 (org-get-indentation))))
699 ;; At the first line of an element, indent like previous element's
700 ;; first line, ignoring footnotes definitions and inline tasks, or
701 ;; according to parent.
704 (org-test-with-temp-text "A\n\n B\n\nC"
705 (goto-char (point-max))
707 (org-get-indentation))))
710 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
711 (goto-char (point-max))
713 (org-get-indentation))))
716 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
719 (org-get-indentation))))
720 ;; Within code part of a source block, use language major mode if
721 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
722 ;; according to line above.
725 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
727 (let ((org-src-tab-acts-natively t
)
728 (org-edit-src-content-indentation 0))
730 (org-get-indentation))))
733 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
735 (let ((org-src-tab-acts-natively nil
)
736 (org-edit-src-content-indentation 0))
738 (org-get-indentation))))
739 ;; Otherwise, indent like the first non-blank line above.
742 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
745 (org-get-indentation))))
746 ;; Align node properties according to `org-property-format'. Handle
747 ;; nicely empty values.
749 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
750 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
751 (let ((org-property-format "%-10s %s")) (org-indent-line))
754 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
755 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
756 (let ((org-property-format "%-10s %s")) (org-indent-line))
759 (ert-deftest test-org
/indent-region
()
760 "Test `org-indent-region' specifications."
764 (org-test-with-temp-text " A\nB\n C"
765 (org-indent-region (point-min) (point-max))
767 ;; Indent greater elements along with their contents.
769 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
770 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
771 (org-indent-region (point-min) (point-max))
773 ;; Ignore contents of verse blocks and example blocks.
775 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
776 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
777 (org-indent-region (point-min) (point-max))
780 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
781 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
782 (org-indent-region (point-min) (point-max))
784 ;; Indent according to mode if `org-src-tab-acts-natively' is
785 ;; non-nil. Otherwise, do not indent code at all.
787 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
788 (org-test-with-temp-text
789 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
790 (let ((org-src-tab-acts-natively t
)
791 (org-edit-src-content-indentation 0))
792 (org-indent-region (point-min) (point-max)))
795 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
796 (org-test-with-temp-text
797 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
798 (let ((org-src-tab-acts-natively nil
)
799 (org-edit-src-content-indentation 0))
800 (org-indent-region (point-min) (point-max)))
802 ;; Align node properties according to `org-property-format'. Handle
803 ;; nicely empty values.
805 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
806 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
807 (let ((org-property-format "%-10s %s")
808 (org-adapt-indentation nil
))
809 (org-indent-region (point) (point-max)))
812 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
813 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
814 (let ((org-property-format "%-10s %s")
815 (org-adapt-indentation nil
))
816 (org-indent-region (point) (point-max)))
818 ;; Indent plain lists.
820 (equal "- A\n B\n - C\n\n D"
821 (org-test-with-temp-text "- A\n B\n - C\n\n D"
822 (org-indent-region (point-min) (point-max))
826 (org-test-with-temp-text " - A\n\n - B"
827 (org-indent-region (point-min) (point-max))
829 ;; Indent footnote definitions.
831 (equal "[fn:1] Definition\n\nDefinition"
832 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
833 (org-indent-region (point-min) (point-max))
835 ;; Special case: Start indenting on a blank line.
838 (org-test-with-temp-text "\n Paragraph"
839 (org-indent-region (point-min) (point-max))
846 (ert-deftest test-org
/delete-indentation
()
847 "Test `org-delete-indentation' specifications."
849 (should (equal "foo bar"
850 (org-test-with-temp-text
852 (org-delete-indentation)
854 ;; With optional argument.
855 (should (equal "foo bar"
856 (org-test-with-temp-text
858 (org-delete-indentation t
)
860 ;; At headline text should be appended to the headline text.
862 (equal"* foo bar :tag:"
863 (let (org-auto-align-tags)
864 (org-test-with-temp-text
865 "* foo :tag:\n bar<point>"
866 (org-delete-indentation)
869 (equal "* foo bar :tag:"
870 (let (org-auto-align-tags)
871 (org-test-with-temp-text
872 "* foo <point>:tag:\n bar"
873 (org-delete-indentation t
)
876 (ert-deftest test-org
/return
()
877 "Test `org-return' specifications."
881 (org-test-with-temp-text "Para<point>graph"
884 ;; With optional argument, indent line.
886 (equal " Para\n graph"
887 (org-test-with-temp-text " Para<point>graph"
890 ;; On a table, call `org-table-next-row'.
892 (org-test-with-temp-text "| <point>a |\n| b |"
894 (org-looking-at-p "b")))
895 ;; Open link or timestamp under point when `org-return-follows-link'
898 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
899 (let ((org-return-follows-link t
)
900 (org-link-search-must-match-exact-headline nil
))
902 (org-looking-at-p "<<target>>")))
904 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
905 (let ((org-return-follows-link nil
)) (org-return))
906 (org-looking-at-p "<<target>>")))
908 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
909 (let ((org-return-follows-link t
)) (org-return))
910 (org-looking-at-p "* b")))
912 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
913 (let ((org-return-follows-link t
)
914 (org-link-search-must-match-exact-headline nil
))
916 (org-looking-at-p "<<target>>")))
917 ;; When `org-return-follows-link' is non-nil, tolerate links and
918 ;; timestamps in comments, node properties, etc.
920 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
921 (let ((org-return-follows-link t
)
922 (org-link-search-must-match-exact-headline nil
))
924 (org-looking-at-p "<<target>>")))
925 ;; However, do not open link when point is in a table.
927 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
928 (let ((org-return-follows-link t
)) (org-return))
929 (org-looking-at-p "between")))
930 ;; Special case: in a list, when indenting, do not break structure.
933 (org-test-with-temp-text "- A <point>B"
938 (org-test-with-temp-text "- A\n<point>- B"
941 ;; On tags part of a headline, add a newline below it instead of
945 (org-test-with-temp-text "* H :<point>tag:"
948 ;; Before headline text, add a newline below it instead of breaking
951 (equal "* TODO H :tag:\n"
952 (org-test-with-temp-text "* <point>TODO H :tag:"
956 (equal "* TODO [#B] H :tag:\n"
957 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
960 ;; At headline text, break headline text but preserve tags.
962 (equal "* TODO [#B] foo :tag:\nbar"
963 (let (org-auto-align-tags)
964 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
967 ;; At bol of headline insert newline.
970 (org-test-with-temp-text "<point>* h"
973 ;; Refuse to leave invalid headline in buffer.
976 (org-test-with-temp-text "*<point> h"
980 (ert-deftest test-org
/meta-return
()
981 "Test M-RET (`org-meta-return') specifications."
982 ;; In a table field insert a row above.
984 (org-test-with-temp-text "| a |"
988 (looking-at "| |$")))
989 ;; In a paragraph change current line into a header.
991 (org-test-with-temp-text "a"
994 (looking-at "\* a$")))
995 ;; In an item insert an item, in this case above.
997 (org-test-with-temp-text "- a"
1000 (looking-at "- $")))
1001 ;; In a drawer and item insert an item, in this case above.
1003 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1007 (looking-at "- $"))))
1009 (ert-deftest test-org
/insert-heading
()
1010 "Test `org-insert-heading' specifications."
1011 ;; In an empty buffer, insert a new headline.
1014 (org-test-with-temp-text ""
1015 (org-insert-heading)
1017 ;; At the beginning of a line, turn it into a headline
1020 (org-test-with-temp-text "<point>P"
1021 (org-insert-heading)
1023 ;; In the middle of a line, split the line if allowed, otherwise,
1024 ;; insert the headline at its end.
1026 (equal "Para\n* graph"
1027 (org-test-with-temp-text "Para<point>graph"
1028 (let ((org-M-RET-may-split-line '((default . t
))))
1029 (org-insert-heading))
1032 (equal "Paragraph\n* "
1033 (org-test-with-temp-text "Para<point>graph"
1034 (let ((org-M-RET-may-split-line '((default . nil
))))
1035 (org-insert-heading))
1037 ;; When on a list, insert an item instead, unless called with an
1038 ;; universal argument or if list is invisible. In this case, create
1039 ;; a new headline after contents.
1041 (equal "* H\n- item\n- "
1042 (org-test-with-temp-text "* H\n- item<point>"
1043 (let ((org-insert-heading-respect-content nil
))
1044 (org-insert-heading))
1047 (equal "* H\n- item\n- item 2\n* "
1048 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1049 (let ((org-insert-heading-respect-content nil
))
1050 (org-insert-heading '(4)))
1053 (equal "* H\n- item\n* "
1054 (org-test-with-temp-text "* H\n- item"
1056 (goto-char (point-max))
1057 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1059 ;; When called with two universal arguments, insert a new headline
1060 ;; at the end of the grandparent subtree.
1062 (equal "* H1\n** H3\n- item\n** H2\n** "
1063 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1064 (let ((org-insert-heading-respect-content nil
))
1065 (org-insert-heading '(16)))
1067 ;; When optional TOP-LEVEL argument is non-nil, always insert
1068 ;; a level 1 heading.
1070 (equal "* H1\n** H2\n* "
1071 (org-test-with-temp-text "* H1\n** H2<point>"
1072 (org-insert-heading nil nil t
)
1075 (equal "* H1\n- item\n* "
1076 (org-test-with-temp-text "* H1\n- item<point>"
1077 (org-insert-heading nil nil t
)
1079 ;; Corner case: correctly insert a headline after an empty one.
1082 (org-test-with-temp-text "* <point>"
1083 (org-insert-heading)
1086 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1087 "Test `org-insert-todo-heading-respect-content' specifications."
1088 ;; Create a TODO heading.
1090 (org-test-with-temp-text "* H1\n Body"
1091 (org-insert-todo-heading-respect-content)
1092 (nth 2 (org-heading-components))))
1093 ;; Add headline at the end of the first subtree
1095 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1096 (search-forward "H1Body")
1097 (org-insert-todo-heading-respect-content)
1098 (and (eobp) (org-at-heading-p))))
1099 ;; In a list, do not create a new item.
1101 (org-test-with-temp-text "* H\n- an item\n- another one"
1102 (search-forward "an ")
1103 (org-insert-todo-heading-respect-content)
1104 (and (eobp) (org-at-heading-p)))))
1106 (ert-deftest test-org
/clone-with-time-shift
()
1107 "Test `org-clone-subtree-with-time-shift'."
1108 ;; Clone non-repeating once.
1114 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1115 (org-clone-subtree-with-time-shift 1 "+2d")
1116 (replace-regexp-in-string
1117 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1119 ;; Clone repeating once.
1124 * H1\n<2015-06-25 +1w>
1126 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1127 (org-clone-subtree-with-time-shift 1 "+2d")
1128 (replace-regexp-in-string
1129 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1131 ;; Clone non-repeating zero times.
1136 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1137 (org-clone-subtree-with-time-shift 0 "+2d")
1138 (replace-regexp-in-string
1139 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1141 ;; Clone repeating "zero" times.
1145 * H1\n<2015-06-23 +1w>
1147 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1148 (org-clone-subtree-with-time-shift 0 "+2d")
1149 (replace-regexp-in-string
1150 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1154 ;;; Fixed-Width Areas
1156 (ert-deftest test-org
/toggle-fixed-width
()
1157 "Test `org-toggle-fixed-width' specifications."
1158 ;; No region: Toggle on fixed-width marker in paragraphs.
1161 (org-test-with-temp-text "A"
1162 (org-toggle-fixed-width)
1164 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1167 (org-test-with-temp-text ": A"
1168 (org-toggle-fixed-width)
1170 ;; No region: Toggle on marker in blank lines after elements or just
1171 ;; after a headline.
1174 (org-test-with-temp-text "* H\n"
1176 (org-toggle-fixed-width)
1179 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1180 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1181 (goto-char (point-max))
1182 (org-toggle-fixed-width)
1184 ;; No region: Toggle on marker in front of one line elements (e.g.,
1185 ;; headlines, clocks)
1187 (equal ": * Headline"
1188 (org-test-with-temp-text "* Headline"
1189 (org-toggle-fixed-width)
1192 (equal ": #+KEYWORD: value"
1193 (org-test-with-temp-text "#+KEYWORD: value"
1194 (org-toggle-fixed-width)
1196 ;; No region: error in other situations.
1198 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1200 (org-toggle-fixed-width)
1202 ;; No region: Indentation is preserved.
1205 (org-test-with-temp-text "- A\n B"
1207 (org-toggle-fixed-width)
1209 ;; Region: If it contains only fixed-width elements and blank lines,
1210 ;; toggle off fixed-width markup.
1213 (org-test-with-temp-text ": A\n\n: B"
1214 (transient-mark-mode 1)
1215 (push-mark (point) t t
)
1216 (goto-char (point-max))
1217 (org-toggle-fixed-width)
1219 ;; Region: If it contains anything else, toggle on fixed-width but
1220 ;; not on fixed-width areas.
1222 (equal ": A\n: \n: B\n: \n: C"
1223 (org-test-with-temp-text "A\n\n: B\n\nC"
1224 (transient-mark-mode 1)
1225 (push-mark (point) t t
)
1226 (goto-char (point-max))
1227 (org-toggle-fixed-width)
1229 ;; Region: Ignore blank lines at its end, unless it contains only
1233 (org-test-with-temp-text "A\n\n"
1234 (transient-mark-mode 1)
1235 (push-mark (point) t t
)
1236 (goto-char (point-max))
1237 (org-toggle-fixed-width)
1241 (org-test-with-temp-text "\n\n"
1242 (transient-mark-mode 1)
1243 (push-mark (point) t t
)
1244 (goto-char (point-max))
1245 (org-toggle-fixed-width)
1252 (ert-deftest test-org
/in-commented-heading-p
()
1253 "Test `org-in-commented-heading-p' specifications."
1254 ;; Commented headline.
1256 (org-test-with-temp-text "* COMMENT Headline\nBody"
1257 (goto-char (point-max))
1258 (org-in-commented-heading-p)))
1259 ;; Commented ancestor.
1261 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1262 (goto-char (point-max))
1263 (org-in-commented-heading-p)))
1264 ;; Comment keyword is case-sensitive.
1266 (org-test-with-temp-text "* Comment Headline\nBody"
1267 (goto-char (point-max))
1268 (org-in-commented-heading-p)))
1269 ;; Keyword is standalone.
1271 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1272 (goto-char (point-max))
1273 (org-in-commented-heading-p)))
1274 ;; Optional argument.
1276 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1277 (goto-char (point-max))
1278 (org-in-commented-heading-p t
))))
1280 (ert-deftest test-org
/entry-blocked-p
()
1281 ;; Check other dependencies.
1283 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1284 (let ((org-enforce-todo-dependencies t
)
1286 '(org-block-todo-from-children-or-siblings-or-parent)))
1287 (org-entry-blocked-p))))
1289 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1290 (let ((org-enforce-todo-dependencies t
)
1292 '(org-block-todo-from-children-or-siblings-or-parent)))
1293 (org-entry-blocked-p))))
1294 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1297 (org-test-with-temp-text "* Blocked\n** TODO one"
1298 (let ((org-enforce-todo-dependencies t
)
1300 '(org-block-todo-from-children-or-siblings-or-parent)))
1301 (org-entry-blocked-p))))
1303 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1304 (let ((org-enforce-todo-dependencies t
)
1306 '(org-block-todo-from-children-or-siblings-or-parent)))
1307 (org-entry-blocked-p))))
1308 ;; Follow :ORDERED: specifications.
1310 (org-test-with-temp-text
1311 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1312 (let ((org-enforce-todo-dependencies t
)
1314 '(org-block-todo-from-children-or-siblings-or-parent)))
1315 (org-entry-blocked-p))))
1317 (org-test-with-temp-text
1318 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1319 (let ((org-enforce-todo-dependencies t
)
1321 '(org-block-todo-from-children-or-siblings-or-parent)))
1322 (org-entry-blocked-p)))))
1324 (ert-deftest test-org
/get-outline-path
()
1325 "Test `org-get-outline-path' specifications."
1326 ;; Top-level headlines have no outline path.
1328 (org-test-with-temp-text "* H"
1329 (org-get-outline-path)))
1330 ;; Otherwise, outline path is the path leading to the headline.
1333 (org-test-with-temp-text "* H\n** S<point>"
1334 (org-get-outline-path))))
1335 ;; Find path even when point is not on a headline.
1338 (org-test-with-temp-text "* H\n** S\nText<point>"
1339 (org-get-outline-path))))
1340 ;; TODO keywords, tags and statistics cookies are ignored.
1343 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1344 (org-get-outline-path))))
1345 ;; Links are replaced with their description or their path.
1348 (org-test-with-temp-text
1349 "* [[http://orgmode.org][Org]]\n** S<point>"
1350 (org-get-outline-path))))
1352 (equal '("http://orgmode.org")
1353 (org-test-with-temp-text
1354 "* [[http://orgmode.org]]\n** S<point>"
1355 (org-get-outline-path))))
1356 ;; When WITH-SELF is non-nil, include current heading.
1359 (org-test-with-temp-text "* H"
1360 (org-get-outline-path t
))))
1363 (org-test-with-temp-text "* H\n** S\nText<point>"
1364 (org-get-outline-path t
))))
1365 ;; Using cache is transparent to the user.
1368 (org-test-with-temp-text "* H\n** S<point>"
1369 (setq org-outline-path-cache nil
)
1370 (org-get-outline-path nil t
))))
1371 ;; Do not corrupt cache when finding outline path in distant part of
1375 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1376 (setq org-outline-path-cache nil
)
1377 (org-get-outline-path nil t
)
1378 (search-forward "S2")
1379 (org-get-outline-path nil t
))))
1380 ;; Do not choke on empty headlines.
1382 (org-test-with-temp-text "* H\n** <point>"
1383 (org-get-outline-path)))
1385 (org-test-with-temp-text "* \n** H<point>"
1386 (org-get-outline-path))))
1388 (ert-deftest test-org
/format-outline-path
()
1389 "Test `org-format-outline-path' specifications."
1391 (string= (org-format-outline-path (list "one" "two" "three"))
1395 (string= (org-format-outline-path '())
1398 (string= (org-format-outline-path '(nil))
1400 ;; Empty path and prefix.
1402 (string= (org-format-outline-path '() nil
">>")
1404 ;; Trailing whitespace in headings.
1406 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1408 ;; Non-default prefix and separators.
1410 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1411 ">>|one|two|three"))
1414 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1416 ;; Give a very narrow width.
1418 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1420 ;; Give a prefix that extends beyond the width.
1422 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1429 (ert-deftest test-org
/set-regexps-and-options
()
1430 "Test `org-set-regexps-and-options' specifications."
1433 (equal '(("A" . ?a
) ("B") ("C"))
1434 (org-test-with-temp-text "#+TAGS: A(a) B C"
1438 (equal '(("A") (:newline
) ("B"))
1439 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1443 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1444 (org-test-with-temp-text "#+TAGS: { A B } C"
1448 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1449 (org-test-with-temp-text "#+TAGS: { A : B C }"
1453 (equal '(("A" "B" "C"))
1454 (org-test-with-temp-text "#+TAGS: { A : B C }"
1456 org-tag-groups-alist
)))
1458 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1459 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1463 (equal '(("A" "B" "C"))
1464 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1466 org-tag-groups-alist
)))
1467 ;; FILETAGS keyword.
1469 (equal '("A" "B" "C")
1470 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1473 ;; PROPERTY keyword. Property names are case-insensitive.
1476 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1478 (cdr (assoc "var" org-file-properties
)))))
1482 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1484 (cdr (assoc "var" org-file-properties
)))))
1488 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1490 (cdr (assoc "var" org-file-properties
)))))
1494 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1496 org-archive-location
)))
1497 ;; CATEGORY keyword.
1500 (org-test-with-temp-text "#+CATEGORY: test"
1505 (org-test-with-temp-text "#+CATEGORY: test"
1507 (cdr (assoc "CATEGORY" org-file-properties
)))))
1510 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1511 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1513 org-columns-default-format
)))
1514 ;; CONSTANTS keyword. Constants names are case sensitive.
1516 (equal '("299792458." "3.14")
1517 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1520 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1524 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1526 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1529 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1531 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1536 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1538 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1540 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1544 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1546 (list org-highest-priority org-lowest-priority org-default-priority
))))
1550 (org-test-with-temp-text "#+PRIORITIES: X Z"
1552 (list org-highest-priority org-lowest-priority org-default-priority
))))
1556 (org-test-with-temp-text "#+STARTUP: fold odd"
1558 (list org-startup-folded org-odd-levels-only
))))
1561 (equal '(("A" "B") ("C"))
1562 (org-test-with-temp-text "#+TODO: A B | C"
1564 (list org-not-done-keywords org-done-keywords
))))
1566 (equal '(("A" "C") ("B" "D"))
1567 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1569 (list org-not-done-keywords org-done-keywords
))))
1571 (equal '(("A" "B") ("C"))
1572 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1574 (list org-not-done-keywords org-done-keywords
))))
1576 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1577 (org-test-with-temp-text "#+TODO: A(a)"
1579 org-todo-key-alist
)))
1581 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1582 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1584 org-todo-log-states
)))
1585 ;; Enter SETUPFILE keyword.
1588 (org-test-with-temp-text
1589 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1591 (cdr (assoc "a" org-file-properties
))))))
1599 (ert-deftest test-org
/coderef
()
1600 "Test coderef links specifications."
1602 (org-test-with-temp-text "
1603 #+BEGIN_SRC emacs-lisp
1608 (looking-at "(ref:sc)")))
1609 ;; Find coderef even with alternate label format.
1611 (org-test-with-temp-text "
1612 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
1617 (looking-at "{ref:sc}"))))
1621 (ert-deftest test-org
/custom-id
()
1622 "Test custom ID links specifications."
1624 (org-test-with-temp-text
1625 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1627 (org-looking-at-p "\\* H1")))
1628 ;; Throw an error on false positives.
1630 (org-test-with-temp-text
1631 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1633 (org-looking-at-p "\\* H1"))))
1637 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1638 ;; a named element (#+name: text) and to headlines (* Text).
1640 (ert-deftest test-org
/fuzzy-links
()
1641 "Test fuzzy links specifications."
1642 ;; Fuzzy link goes in priority to a matching target.
1644 (org-test-with-temp-text
1645 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
1646 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1647 (looking-at "<<Test>>")))
1648 ;; Then fuzzy link points to an element with a given name.
1650 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
1651 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1652 (looking-at "#\\+NAME: Test")))
1653 ;; A target still lead to a matching headline otherwise.
1655 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
1656 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1657 (looking-at "\\* Head2")))
1658 ;; With a leading star in link, enforce heading match.
1660 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
1661 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1662 (looking-at "\\* Test")))
1663 ;; With a leading star in link, enforce exact heading match, even
1664 ;; with `org-link-search-must-match-exact-headline' set to nil.
1666 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1667 (let ((org-link-search-must-match-exact-headline nil
))
1668 (org-open-at-point))))
1669 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
1671 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
1672 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1673 (looking-at "\\* Test")))
1675 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
1676 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1677 (looking-at "\\* Test")))
1678 ;; Heading match should not care about spaces, cookies, TODO
1679 ;; keywords, priorities, and tags.
1682 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1683 (org-test-with-temp-text
1684 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1685 (let ((org-link-search-must-match-exact-headline nil
)
1686 (org-todo-regexp "TODO"))
1687 (org-open-at-point))
1688 (looking-at (regexp-quote first-line
)))))
1689 ;; Heading match should still be exact.
1692 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1693 (org-test-with-temp-text
1694 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1695 (let ((org-link-search-must-match-exact-headline nil
)
1696 (org-todo-regexp "TODO"))
1697 (org-open-at-point)))))
1698 ;; Heading match ignores COMMENT keyword.
1700 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1702 (looking-at "\\* COMMENT Test")))
1703 ;; Correctly un-hexify fuzzy links.
1705 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1706 (goto-char (point-max))
1712 (ert-deftest test-org
/org-link-escape-ascii-character
()
1713 "Escape an ascii character."
1717 (org-link-escape "["))))
1719 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1720 "Escape an ascii control character."
1724 (org-link-escape "\t"))))
1726 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1727 "Escape an unicode multibyte character."
1731 (org-link-escape "€"))))
1733 (ert-deftest test-org
/org-link-escape-custom-table
()
1734 "Escape string with custom character table."
1738 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1740 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1741 "Escape string with custom table merged with default table."
1744 "%5BF%6F%6F%3A%42ar%0A%5D"
1745 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1747 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1748 "Unescape an ascii character."
1752 (org-link-unescape "%5B"))))
1754 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1755 "Unescpae an ascii control character."
1759 (org-link-unescape "%0A"))))
1761 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1762 "Unescape unicode multibyte character."
1766 (org-link-unescape "%E2%82%AC"))))
1768 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1769 "Unescape old style percent escaped character."
1772 "à âçèéêîôùû"
1773 (decode-coding-string
1774 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1776 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1777 "Escape and unescape a URL that includes an escaped char.
1778 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1781 "http://some.host.com/form?&id=blah%2Bblah25"
1783 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1785 (ert-deftest test-org
/org-link-escape-chars-browser
()
1786 "Test of the constant `org-link-escape-chars-browser'.
1787 See there why this test is a candidate to be removed once Org
1788 drops support for Emacs 24.1 and 24.2."
1791 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1792 "%22Release%208.2%22&idxname=emacs-orgmode")
1793 (org-link-escape-browser ; Do not replace with `url-encode-url',
1794 ; see docstring above.
1795 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1796 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1800 (ert-deftest test-org
/open-at-point-in-keyword
()
1801 "Does `org-open-at-point' open link in a keyword line?"
1803 (org-test-with-temp-text
1804 "#+KEYWORD: <point>[[info:emacs#Top]]"
1805 (org-open-at-point) t
)))
1807 (ert-deftest test-org
/open-at-point-in-property
()
1808 "Does `org-open-at-point' open link in property drawer?"
1810 (org-test-with-temp-text
1813 :URL: <point>[[info:emacs#Top]]
1815 (org-open-at-point) t
)))
1817 (ert-deftest test-org
/open-at-point-in-comment
()
1818 "Does `org-open-at-point' open link in a commented line?"
1820 (org-test-with-temp-text
1821 "# <point>[[info:emacs#Top]]"
1822 (org-open-at-point) t
)))
1824 (ert-deftest test-org
/open-at-point
/info
()
1825 "Test `org-open-at-point' on info links."
1827 (org-test-with-temp-text
1828 "<point>[[info:emacs#Top]]"
1830 (and (switch-to-buffer "*info*")
1832 (looking-at "\nThe Emacs Editor")
1835 (ert-deftest test-org
/open-at-point
/inline-image
()
1836 "Test `org-open-at-point' on nested links."
1838 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1840 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1841 (kill-buffer "*info*")))))
1843 (ert-deftest test-org
/open-at-point
/radio-target
()
1844 "Test `org-open-at-point' on radio targets."
1846 (org-test-with-temp-text "<<<target>>> <point>target"
1847 (org-update-radio-target-regexp)
1849 (eq (org-element-type (org-element-context)) 'radio-target
))))
1854 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1855 "Ensure properties accumulate in subtree drawers."
1856 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1857 (org-babel-next-src-block)
1858 (should (equal '(2 1) (org-babel-execute-src-block)))))
1860 (ert-deftest test-org
/custom-properties
()
1861 "Test custom properties specifications."
1864 (let ((org-custom-properties '("FOO")))
1865 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1866 (org-toggle-custom-properties-visibility)
1867 (org-invisible-p2))))
1868 ;; Properties are case-insensitive.
1870 (let ((org-custom-properties '("FOO")))
1871 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1872 (org-toggle-custom-properties-visibility)
1873 (org-invisible-p2))))
1875 (let ((org-custom-properties '("foo")))
1876 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1877 (org-toggle-custom-properties-visibility)
1878 (org-invisible-p2))))
1879 ;; Multiple custom properties in the same drawer.
1881 (let ((org-custom-properties '("FOO" "BAR")))
1882 (org-test-with-temp-text
1883 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1884 (org-toggle-custom-properties-visibility)
1885 (and (org-invisible-p2)
1886 (not (progn (forward-line) (org-invisible-p2)))
1887 (progn (forward-line) (org-invisible-p2))))))
1888 ;; Hide custom properties with an empty value.
1890 (let ((org-custom-properties '("FOO")))
1891 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1892 (org-toggle-custom-properties-visibility)
1893 (org-invisible-p2))))
1894 ;; Do not hide fake properties.
1896 (let ((org-custom-properties '("FOO")))
1897 (org-test-with-temp-text ":FOO: val\n"
1898 (org-toggle-custom-properties-visibility)
1899 (org-invisible-p2))))
1901 (let ((org-custom-properties '("A")))
1902 (org-test-with-temp-text
1903 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1904 (org-toggle-custom-properties-visibility)
1905 (org-invisible-p2)))))
1911 (ert-deftest test-org
/mark-subtree
()
1912 "Test `org-mark-subtree' specifications."
1913 ;; Error when point is before first headline.
1915 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1916 (progn (transient-mark-mode 1)
1917 (org-mark-subtree))))
1918 ;; Without argument, mark current subtree.
1922 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1923 (progn (transient-mark-mode 1)
1926 (list (region-beginning) (region-end))))))
1927 ;; With an argument, move ARG up.
1931 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1932 (progn (transient-mark-mode 1)
1934 (org-mark-subtree 1)
1935 (list (region-beginning) (region-end))))))
1936 ;; Do not get fooled by inlinetasks.
1937 (when (featurep 'org-inlinetask
)
1940 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1941 (progn (transient-mark-mode 1)
1943 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1944 (region-beginning)))))))
1950 (ert-deftest test-org
/end-of-meta-data
()
1951 "Test `org-end-of-meta-data' specifications."
1952 ;; Skip planning line.
1954 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1955 (org-end-of-meta-data)
1957 ;; Skip properties drawer.
1959 (org-test-with-temp-text
1960 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1961 (org-end-of-meta-data)
1965 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1966 (org-end-of-meta-data)
1968 ;; Nothing to skip, go to first line.
1970 (org-test-with-temp-text "* Headline\nContents"
1971 (org-end-of-meta-data)
1972 (looking-at "Contents")))
1973 ;; With option argument, skip empty lines, regular drawers and
1976 (org-test-with-temp-text "* Headline\n\nContents"
1977 (org-end-of-meta-data t
)
1978 (looking-at "Contents")))
1980 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1981 (org-end-of-meta-data t
)
1982 (looking-at "Contents")))
1984 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1985 (org-end-of-meta-data t
)
1986 (looking-at "Contents")))
1987 ;; Special case: do not skip incomplete drawers.
1989 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1990 (org-end-of-meta-data t
)
1991 (looking-at ":LOGBOOK:")))
1992 ;; Special case: Be careful about consecutive headlines.
1994 (org-test-with-temp-text "* H1\n*H2\nContents"
1995 (org-end-of-meta-data t
)
1996 (looking-at "Contents"))))
1998 (ert-deftest test-org
/beginning-of-line
()
1999 "Test `org-beginning-of-line' specifications."
2002 (org-test-with-temp-text "Some text\nSome other text"
2003 (progn (org-beginning-of-line) (bolp))))
2004 ;; Standard test with `visual-line-mode'.
2006 (org-test-with-temp-text "A long line of text\nSome other text"
2007 (progn (visual-line-mode)
2009 (dotimes (i 1000) (insert "very "))
2010 (org-beginning-of-line)
2012 ;; At an headline with special movement.
2014 (org-test-with-temp-text "* TODO Headline"
2015 (let ((org-special-ctrl-a/e t
))
2017 (and (progn (org-beginning-of-line) (looking-at "Headline"))
2018 (progn (org-beginning-of-line) (bolp))
2019 (progn (org-beginning-of-line) (looking-at "Headline"))))))
2020 ;; Special case: Do not error when the buffer contains only a single
2023 (org-test-with-temp-text "*<point>"
2024 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
2026 (org-test-with-temp-text "*<point>"
2027 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
2029 (ert-deftest test-org
/end-of-line
()
2030 "Test `org-end-of-line' specifications."
2033 (org-test-with-temp-text "Some text\nSome other text"
2034 (progn (org-end-of-line) (eolp))))
2035 ;; Standard test with `visual-line-mode'.
2037 (org-test-with-temp-text "A long line of text\nSome other text"
2038 (progn (visual-line-mode)
2040 (dotimes (i 1000) (insert "very "))
2041 (goto-char (point-min))
2044 ;; At an headline with special movement.
2046 (org-test-with-temp-text "* Headline1 :tag:\n"
2047 (let ((org-special-ctrl-a/e t
))
2048 (and (progn (org-end-of-line) (looking-at " :tag:"))
2049 (progn (org-end-of-line) (eolp))
2050 (progn (org-end-of-line) (looking-at " :tag:"))))))
2051 ;; At an headline without special movement.
2053 (org-test-with-temp-text "* Headline2 :tag:\n"
2054 (let ((org-special-ctrl-a/e nil
))
2055 (and (progn (org-end-of-line) (eolp))
2056 (progn (org-end-of-line) (eolp))))))
2057 ;; At an headline, with reversed movement.
2059 (org-test-with-temp-text "* Headline3 :tag:\n"
2060 (let ((org-special-ctrl-a/e
'reversed
)
2061 (this-command last-command
))
2062 (and (progn (org-end-of-line) (eolp))
2063 (progn (org-end-of-line) (looking-at " :tag:"))))))
2064 ;; At a block without hidden contents.
2066 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2067 (progn (org-end-of-line) (eolp))))
2068 ;; At a block with hidden contents.
2070 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2071 (let ((org-special-ctrl-a/e t
))
2072 (org-hide-block-toggle)
2076 (ert-deftest test-org
/forward-sentence
()
2077 "Test `org-forward-sentence' specifications."
2078 ;; At the end of a table cell, move to the end of the next one.
2080 (org-test-with-temp-text "| a<point> | b |"
2081 (org-forward-sentence)
2082 (looking-at " |$")))
2083 ;; Elsewhere in a cell, move to its end.
2085 (org-test-with-temp-text "| a<point>c | b |"
2086 (org-forward-sentence)
2087 (looking-at " | b |$")))
2088 ;; Otherwise, simply call `forward-sentence'.
2090 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2091 (org-forward-sentence)
2092 (looking-at " Sentence 2.")))
2094 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2095 (org-forward-sentence)
2096 (org-forward-sentence)
2098 ;; At the end of an element, jump to the next one, without stopping
2099 ;; on blank lines in-between.
2101 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2102 (org-forward-sentence)
2105 (ert-deftest test-org
/backward-sentence
()
2106 "Test `org-backward-sentence' specifications."
2107 ;; At the beginning of a table cell, move to the beginning of the
2110 (org-test-with-temp-text "| a | <point>b |"
2111 (org-backward-sentence)
2112 (looking-at "a | b |$")))
2113 ;; Elsewhere in a cell, move to its beginning.
2115 (org-test-with-temp-text "| a | b<point>c |"
2116 (org-backward-sentence)
2117 (looking-at "bc |$")))
2118 ;; Otherwise, simply call `backward-sentence'.
2120 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2121 (org-backward-sentence)
2122 (looking-at "Sentence 2.")))
2124 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2125 (org-backward-sentence)
2126 (org-backward-sentence)
2128 ;; Make sure to hit the beginning of a sentence on the same line as
2131 (org-test-with-temp-text "- Line 1\n line <point>2."
2132 (org-backward-sentence)
2133 (looking-at "Line 1"))))
2135 (ert-deftest test-org
/forward-paragraph
()
2136 "Test `org-forward-paragraph' specifications."
2137 ;; At end of buffer, return an error.
2139 (org-test-with-temp-text "Paragraph"
2140 (goto-char (point-max))
2141 (org-forward-paragraph)))
2144 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2145 (org-forward-paragraph)
2149 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2150 (org-forward-paragraph)
2152 ;; Do not enter elements with invisible contents.
2154 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2155 (org-hide-block-toggle)
2156 (org-forward-paragraph)
2158 ;; On an affiliated keyword, jump to the beginning of the element.
2160 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2161 (org-forward-paragraph)
2162 (looking-at "Para")))
2163 ;; On an item or a footnote definition, move to the second element
2166 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2167 (org-forward-paragraph)
2168 (looking-at " Paragraph")))
2170 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2171 (org-forward-paragraph)
2172 (looking-at "Paragraph")))
2173 ;; On an item, or a footnote definition, when the first line is
2174 ;; empty, move to the first item.
2176 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2177 (org-forward-paragraph)
2178 (looking-at " Paragraph")))
2180 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2181 (org-forward-paragraph)
2182 (looking-at "Paragraph")))
2183 ;; On a table (resp. a property drawer) do not move through table
2184 ;; rows (resp. node properties).
2186 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2187 (org-forward-paragraph)
2188 (looking-at "Paragraph")))
2190 (org-test-with-temp-text
2191 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2192 (org-forward-paragraph)
2193 (looking-at "Paragraph")))
2194 ;; On a verse or source block, stop after blank lines.
2196 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2197 (org-forward-paragraph)
2200 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2201 (org-forward-paragraph)
2202 (looking-at "L2"))))
2204 (ert-deftest test-org
/backward-paragraph
()
2205 "Test `org-backward-paragraph' specifications."
2206 ;; Error at beginning of buffer.
2208 (org-test-with-temp-text "Paragraph"
2209 (org-backward-paragraph)))
2212 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2213 (goto-char (point-max))
2214 (org-backward-paragraph)
2217 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2218 (goto-char (point-max))
2220 (org-backward-paragraph)
2224 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2225 (goto-char (point-max))
2227 (org-backward-paragraph)
2229 ;; Ignore invisible elements.
2231 (org-test-with-temp-text "* H1\n P1\n* H2"
2233 (goto-char (point-max))
2235 (org-backward-paragraph)
2237 ;; On an affiliated keyword, jump to the first one.
2239 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2240 (search-forward "c2")
2241 (org-backward-paragraph)
2242 (looking-at "#\\+name")))
2243 ;; On the second element in an item or a footnote definition, jump
2244 ;; to item or the definition.
2246 (org-test-with-temp-text "- line1\n\n line2"
2247 (goto-char (point-max))
2249 (org-backward-paragraph)
2250 (looking-at "- line1")))
2252 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2253 (goto-char (point-max))
2255 (org-backward-paragraph)
2256 (looking-at "\\[fn:1\\] line1")))
2257 ;; On a table (resp. a property drawer), ignore table rows
2258 ;; (resp. node properties).
2260 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2261 (goto-char (point-max))
2263 (org-backward-paragraph)
2266 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2267 (org-backward-paragraph)
2268 (looking-at ":PROPERTIES:")))
2269 ;; On a source or verse block, stop before blank lines.
2271 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2272 (search-forward "L3")
2274 (org-backward-paragraph)
2277 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2278 (search-forward "L3")
2280 (org-backward-paragraph)
2281 (looking-at "L2"))))
2283 (ert-deftest test-org
/forward-element
()
2284 "Test `org-forward-element' specifications."
2285 ;; 1. At EOB: should error.
2286 (org-test-with-temp-text "Some text\n"
2287 (goto-char (point-max))
2288 (should-error (org-forward-element)))
2289 ;; 2. Standard move: expected to ignore blank lines.
2290 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2291 (org-forward-element)
2292 (should (looking-at (regexp-quote "Second paragraph."))))
2293 ;; 3. Headline tests.
2294 (org-test-with-temp-text "
2299 ;; 3.1. At an headline beginning: move to next headline at the
2302 (org-forward-element)
2303 (should (looking-at (regexp-quote "** Head 1.2")))
2304 ;; 3.2. At an headline beginning: move to parent headline if no
2305 ;; headline at the same level.
2307 (org-forward-element)
2308 (should (looking-at (regexp-quote "** Head 1.2"))))
2309 ;; 4. Greater element tests.
2310 (org-test-with-temp-text
2311 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2312 ;; 4.1. At a greater element: expected to skip contents.
2313 (org-forward-element)
2314 (should (looking-at (regexp-quote "Outside.")))
2315 ;; 4.2. At the end of greater element contents: expected to skip
2316 ;; to the end of the greater element.
2318 (org-forward-element)
2319 (should (looking-at (regexp-quote "Outside."))))
2321 (org-test-with-temp-text "
2335 ;; 5.1. At list top point: expected to move to the element after
2338 (org-forward-element)
2339 (should (looking-at (regexp-quote "Outside.")))
2340 ;; 5.2. Special case: at the first line of a sub-list, but not at
2341 ;; beginning of line, move to next item.
2344 (org-forward-element)
2345 (should (looking-at "- item2"))
2348 (org-forward-element)
2349 (should (looking-at " - sub2"))
2350 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2352 (org-forward-element)
2353 (should (looking-at (regexp-quote " Inner paragraph.")))
2354 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2356 (org-forward-element)
2357 (should (looking-at (regexp-quote " Inner paragraph.")))
2358 ;; 5.5. At an item: expected to move to next item, if any.
2360 (org-forward-element)
2361 (should (looking-at " - sub3"))))
2363 (ert-deftest test-org
/backward-element
()
2364 "Test `org-backward-element' specifications."
2365 ;; 1. Should error at BOB.
2366 (org-test-with-temp-text " \nParagraph."
2367 (should-error (org-backward-element)))
2368 ;; 2. Should move at BOB when called on the first element in buffer.
2370 (org-test-with-temp-text "\n#+TITLE: test"
2371 (progn (forward-line)
2372 (org-backward-element)
2374 ;; 3. Not at the beginning of an element: move at its beginning.
2375 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2378 (org-backward-element)
2379 (should (looking-at (regexp-quote "Paragraph2."))))
2380 ;; 4. Headline tests.
2381 (org-test-with-temp-text "
2386 ;; 4.1. At an headline beginning: move to previous headline at the
2389 (org-backward-element)
2390 (should (looking-at (regexp-quote "** Head 1.1")))
2391 ;; 4.2. At an headline beginning: move to parent headline if no
2392 ;; headline at the same level.
2394 (org-backward-element)
2395 (should (looking-at (regexp-quote "* Head 1")))
2396 ;; 4.3. At the first top-level headline: should error.
2398 (should-error (org-backward-element)))
2399 ;; 5. At beginning of first element inside a greater element:
2400 ;; expected to move to greater element's beginning.
2401 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2403 (org-backward-element)
2404 (should (looking-at "#\\+BEGIN_CENTER")))
2405 ;; 6. At the beginning of the first element in a section: should
2406 ;; move back to headline, if any.
2408 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2409 (progn (goto-char (point-max))
2411 (org-backward-element)
2412 (org-at-heading-p))))
2414 (org-test-with-temp-text "
2429 ;; 7.1. At beginning of sub-list: expected to move to the
2430 ;; paragraph before it.
2432 (org-backward-element)
2433 (should (looking-at "item1"))
2434 ;; 7.2. At an item in a list: expected to move at previous item.
2436 (org-backward-element)
2437 (should (looking-at " - sub2"))
2439 (org-backward-element)
2440 (should (looking-at "- item1"))
2441 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2444 (org-backward-element)
2445 (should (looking-at " - sub1"))
2447 (org-backward-element)
2448 (should (looking-at "- item1"))
2449 ;; 7.4. At blank-lines before list end: expected to move to top
2452 (org-backward-element)
2453 (should (looking-at "- item1"))))
2455 (ert-deftest test-org
/up-element
()
2456 "Test `org-up-element' specifications."
2457 ;; 1. At BOB or with no surrounding element: should error.
2458 (org-test-with-temp-text "Paragraph."
2459 (should-error (org-up-element)))
2460 (org-test-with-temp-text "* Head1\n* Head2"
2462 (should-error (org-up-element)))
2463 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2465 (should-error (org-up-element)))
2466 ;; 2. At an headline: move to parent headline.
2467 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2470 (should (looking-at "\\* Head1")))
2471 ;; 3. Inside a greater element: move to greater element beginning.
2472 (org-test-with-temp-text
2473 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2476 (should (looking-at "#\\+BEGIN_CENTER")))
2478 (org-test-with-temp-text "* Top
2485 Paragraph within sub2.
2488 ;; 4.1. Within an item: move to the item beginning.
2491 (should (looking-at " - sub2"))
2492 ;; 4.2. At an item in a sub-list: move to parent item.
2495 (should (looking-at "- item1"))
2496 ;; 4.3. At an item in top list: move to beginning of whole list.
2499 (should (looking-at "- item1"))
2500 ;; 4.4. Special case. At very top point: should move to parent of
2504 (should (looking-at "\\* Top"))))
2506 (ert-deftest test-org
/down-element
()
2507 "Test `org-down-element' specifications."
2508 ;; Error when the element hasn't got a recursive type.
2509 (org-test-with-temp-text "Paragraph."
2510 (should-error (org-down-element)))
2511 ;; Error when the element has no contents
2512 (org-test-with-temp-text "* Headline"
2513 (should-error (org-down-element)))
2514 ;; When at a plain-list, move to first item.
2515 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2518 (should (looking-at " - Item 1.1")))
2519 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2521 (should (looking-at " Item 1")))
2522 ;; When at a table, move to first row
2523 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2525 (should (looking-at " a | b |")))
2526 ;; Otherwise, move inside the greater element.
2527 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2529 (should (looking-at "Paragraph"))))
2531 (ert-deftest test-org
/drag-element-backward
()
2532 "Test `org-drag-element-backward' specifications."
2536 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2537 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2538 (org-drag-element-backward)
2542 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2543 (org-test-with-temp-text
2544 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2545 (org-drag-element-backward)
2547 ;; Preserve blank lines.
2549 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2550 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2551 (org-drag-element-backward)
2555 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2556 (org-drag-element-backward)
2557 (org-looking-at-p "2")))
2558 ;; Error when trying to move first element of buffer.
2560 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2561 (org-drag-element-backward)))
2562 ;; Error when trying to swap nested elements.
2564 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2566 (org-drag-element-backward)))
2567 ;; Error when trying to swap an headline element and a non-headline
2570 (org-test-with-temp-text "Test.\n* Head 1"
2572 (org-drag-element-backward)))
2573 ;; Preserve visibility of elements and their contents.
2575 (equal '((63 .
82) (26 .
48))
2576 (org-test-with-temp-text "
2584 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2585 (search-backward "- item 1")
2586 (org-drag-element-backward)
2587 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2588 (overlays-in (point-min) (point-max)))))))
2590 (ert-deftest test-org
/drag-element-forward
()
2591 "Test `org-drag-element-forward' specifications."
2592 ;; 1. Error when trying to move first element of buffer.
2593 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2595 (should-error (org-drag-element-forward)))
2596 ;; 2. Error when trying to swap nested elements.
2597 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2599 (should-error (org-drag-element-forward)))
2600 ;; 3. Error when trying to swap a non-headline element and an
2602 (org-test-with-temp-text "Test.\n* Head 1"
2603 (should-error (org-drag-element-forward)))
2604 ;; 4. Otherwise, swap elements, preserving column and blank lines
2605 ;; between elements.
2606 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2607 (search-forward "graph")
2608 (org-drag-element-forward)
2609 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2610 (should (looking-at " 1")))
2611 ;; 5. Preserve visibility of elements and their contents.
2612 (org-test-with-temp-text "
2620 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2621 (search-backward "#+BEGIN_CENTER")
2622 (org-drag-element-forward)
2625 '((63 .
82) (26 .
48))
2626 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2627 (overlays-in (point-min) (point-max)))))))
2629 (ert-deftest test-org
/next-block
()
2630 "Test `org-next-block' specifications."
2633 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2635 (looking-at "#\\+BEGIN_CENTER")))
2638 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2639 (let ((case-fold-search nil
))
2641 (looking-at "#\\+begin_center"))))
2642 ;; Ignore current line.
2644 (org-test-with-temp-text
2645 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2647 (looking-at "#\\+BEGIN_CENTER")))
2648 ;; Throw an error when no block is found.
2650 (org-test-with-temp-text "Paragraph"
2651 (org-next-block 1)))
2652 ;; With an argument, skip many blocks at once.
2654 (org-test-with-temp-text
2655 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2657 (looking-at "#\\+BEGIN_QUOTE")))
2658 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2660 (org-test-with-temp-text
2661 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2662 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2663 (looking-at "#\\+BEGIN_QUOTE")))
2664 ;; Optional argument is also case-insensitive.
2666 (org-test-with-temp-text
2667 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2668 (let ((case-fold-search nil
))
2669 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2670 (looking-at "#\\+begin_quote")))))
2672 (ert-deftest test-org
/previous-block
()
2673 "Test `org-previous-block' specifications."
2676 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2677 (org-previous-block 1)
2678 (looking-at "#\\+BEGIN_CENTER")))
2681 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2682 (let ((case-fold-search nil
))
2683 (org-previous-block 1)
2684 (looking-at "#\\+begin_center"))))
2685 ;; Ignore current line.
2687 (org-test-with-temp-text
2688 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2689 (org-previous-block 1)
2690 (looking-at "#\\+BEGIN_QUOTE")))
2691 ;; Throw an error when no block is found.
2693 (org-test-with-temp-text "Paragraph<point>"
2694 (org-previous-block 1)))
2695 ;; With an argument, skip many blocks at once.
2697 (org-test-with-temp-text
2698 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2699 (org-previous-block 2)
2700 (looking-at "#\\+BEGIN_CENTER")))
2701 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2703 (org-test-with-temp-text
2704 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2705 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2706 (looking-at "#\\+BEGIN_QUOTE")))
2707 ;; Optional argument is also case-insensitive.
2709 (org-test-with-temp-text
2710 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2711 (let ((case-fold-search nil
))
2712 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2713 (looking-at "#\\+begin_quote")))))
2716 ;;; Outline structure
2718 (ert-deftest test-org
/demote
()
2719 "Test `org-demote' specifications."
2720 ;; Add correct number of stars according to `org-odd-levels-only'.
2723 (org-test-with-temp-text "* H"
2724 (let ((org-odd-levels-only nil
)) (org-demote))
2725 (org-current-level))))
2728 (org-test-with-temp-text "* H"
2729 (let ((org-odd-levels-only t
)) (org-demote))
2730 (org-current-level))))
2731 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2733 (org-test-with-temp-text "* H :tag:"
2734 (let ((org-tags-column 10)
2735 (org-auto-align-tags t
)
2736 (org-odd-levels-only nil
))
2738 (org-move-to-column 10)
2739 (org-looking-at-p ":tag:$")))
2741 (org-test-with-temp-text "* H :tag:"
2742 (let ((org-tags-column 10)
2743 (org-auto-align-tags nil
)
2744 (org-odd-levels-only nil
))
2746 (org-move-to-column 10)
2747 (org-looking-at-p ":tag:$")))
2748 ;; When `org-adapt-indentation' is non-nil, always indent planning
2749 ;; info and property drawers accordingly.
2752 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2753 (let ((org-odd-levels-only nil
)
2754 (org-adapt-indentation t
))
2757 (org-get-indentation))))
2760 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2761 (let ((org-odd-levels-only nil
)
2762 (org-adapt-indentation t
))
2765 (org-get-indentation))))
2768 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2769 (let ((org-odd-levels-only nil
)
2770 (org-adapt-indentation nil
))
2773 (org-get-indentation))))
2774 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2775 ;; section accordingly. Ignore, however, footnote definitions and
2776 ;; inlinetasks boundaries.
2779 (org-test-with-temp-text "* H\n Paragraph"
2780 (let ((org-odd-levels-only nil
)
2781 (org-adapt-indentation t
))
2784 (org-get-indentation))))
2787 (org-test-with-temp-text "* H\n Paragraph"
2788 (let ((org-odd-levels-only nil
)
2789 (org-adapt-indentation nil
))
2792 (org-get-indentation))))
2795 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2796 (let ((org-odd-levels-only nil
)
2797 (org-adapt-indentation t
))
2799 (goto-char (point-max))
2800 (org-get-indentation))))
2803 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2804 (let ((org-odd-levels-only nil
)
2805 (org-adapt-indentation t
))
2807 (goto-char (point-max))
2808 (org-get-indentation))))
2809 (when (featurep 'org-inlinetask
)
2812 (let ((org-inlinetask-min-level 5)
2813 (org-adapt-indentation t
))
2814 (org-test-with-temp-text "* H\n***** I\n***** END"
2817 (org-get-indentation))))))
2818 (when (featurep 'org-inlinetask
)
2821 (let ((org-inlinetask-min-level 5)
2822 (org-adapt-indentation t
))
2823 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2826 (org-get-indentation))))))
2827 ;; Ignore contents of source blocks or example blocks when
2828 ;; indentation should be preserved (through
2829 ;; `org-src-preserve-indentation' or "-i" flag).
2832 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2833 (let ((org-adapt-indentation t
)
2834 (org-src-preserve-indentation nil
))
2837 (org-get-indentation))))
2840 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2841 (let ((org-adapt-indentation t
)
2842 (org-src-preserve-indentation t
))
2845 (org-get-indentation))))
2848 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2849 (let ((org-adapt-indentation t
)
2850 (org-src-preserve-indentation t
))
2853 (org-get-indentation))))
2856 (org-test-with-temp-text
2857 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2858 (let ((org-adapt-indentation t
)
2859 (org-src-preserve-indentation nil
))
2862 (org-get-indentation)))))
2864 (ert-deftest test-org
/promote
()
2865 "Test `org-promote' specifications."
2866 ;; Return an error if headline is to be promoted to level 0, unless
2867 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2868 ;; headline becomes a comment.
2870 (org-test-with-temp-text "* H"
2871 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2874 (org-test-with-temp-text "* H"
2875 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2877 ;; Remove correct number of stars according to
2878 ;; `org-odd-levels-only'.
2881 (org-test-with-temp-text "*** H"
2882 (let ((org-odd-levels-only nil
)) (org-promote))
2883 (org-current-level))))
2886 (org-test-with-temp-text "*** H"
2887 (let ((org-odd-levels-only t
)) (org-promote))
2888 (org-current-level))))
2889 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2891 (org-test-with-temp-text "** H :tag:"
2892 (let ((org-tags-column 10)
2893 (org-auto-align-tags t
)
2894 (org-odd-levels-only nil
))
2896 (org-move-to-column 10)
2897 (org-looking-at-p ":tag:$")))
2899 (org-test-with-temp-text "** H :tag:"
2900 (let ((org-tags-column 10)
2901 (org-auto-align-tags nil
)
2902 (org-odd-levels-only nil
))
2904 (org-move-to-column 10)
2905 (org-looking-at-p ":tag:$")))
2906 ;; When `org-adapt-indentation' is non-nil, always indent planning
2907 ;; info and property drawers.
2910 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2911 (let ((org-odd-levels-only nil
)
2912 (org-adapt-indentation t
))
2915 (org-get-indentation))))
2918 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2919 (let ((org-odd-levels-only nil
)
2920 (org-adapt-indentation t
))
2923 (org-get-indentation))))
2926 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2927 (let ((org-odd-levels-only nil
)
2928 (org-adapt-indentation nil
))
2931 (org-get-indentation))))
2932 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2933 ;; section accordingly. Ignore, however, footnote definitions and
2934 ;; inlinetasks boundaries.
2937 (org-test-with-temp-text "** H\n Paragraph"
2938 (let ((org-odd-levels-only nil
)
2939 (org-adapt-indentation t
))
2942 (org-get-indentation))))
2945 (org-test-with-temp-text "** H\n Paragraph"
2946 (let ((org-odd-levels-only nil
)
2947 (org-adapt-indentation nil
))
2950 (org-get-indentation))))
2953 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2954 (let ((org-odd-levels-only nil
)
2955 (org-adapt-indentation t
))
2958 (org-get-indentation))))
2959 (when (featurep 'org-inlinetask
)
2962 (let ((org-inlinetask-min-level 5)
2963 (org-adapt-indentation t
))
2964 (org-test-with-temp-text "** H\n***** I\n***** END"
2967 (org-get-indentation))))))
2968 (when (featurep 'org-inlinetask
)
2971 (let ((org-inlinetask-min-level 5)
2972 (org-adapt-indentation t
))
2973 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2976 (org-get-indentation))))))
2977 ;; Give up shifting if it would break document's structure
2981 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2982 (let ((org-odd-levels-only nil
)
2983 (org-adapt-indentation t
))
2986 (org-get-indentation))))
2989 (org-test-with-temp-text "** H\n Paragraph\n * list."
2990 (let ((org-odd-levels-only nil
)
2991 (org-adapt-indentation t
))
2994 (org-get-indentation))))
2995 ;; Ignore contents of source blocks or example blocks when
2996 ;; indentation should be preserved (through
2997 ;; `org-src-preserve-indentation' or "-i" flag).
3000 (org-test-with-temp-text
3001 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3002 (let ((org-adapt-indentation t
)
3003 (org-src-preserve-indentation nil
)
3004 (org-odd-levels-only nil
))
3007 (org-get-indentation))))
3010 (org-test-with-temp-text
3011 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3012 (let ((org-adapt-indentation t
)
3013 (org-src-preserve-indentation t
)
3014 (org-odd-levels-only nil
))
3017 (org-get-indentation))))
3020 (org-test-with-temp-text
3021 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3022 (let ((org-adapt-indentation t
)
3023 (org-src-preserve-indentation t
)
3024 (org-odd-levels-only nil
))
3027 (org-get-indentation))))
3030 (org-test-with-temp-text
3031 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3032 (let ((org-adapt-indentation t
)
3033 (org-src-preserve-indentation nil
)
3034 (org-odd-levels-only nil
))
3037 (org-get-indentation)))))
3042 (ert-deftest test-org
/at-planning-p
()
3043 "Test `org-at-planning-p' specifications."
3046 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3047 (org-at-planning-p)))
3049 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3050 (org-at-planning-p)))
3051 ;; Correctly find planning attached to inlinetasks.
3052 (when (featurep 'org-inlinetask
)
3054 (org-test-with-temp-text
3055 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3056 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3058 (org-test-with-temp-text
3059 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3060 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3062 (org-test-with-temp-text
3063 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3064 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3066 (org-test-with-temp-text
3067 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3068 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3070 (ert-deftest test-org
/add-planning-info
()
3071 "Test `org-add-planning-info'."
3072 ;; Create deadline when `org-adapt-indentation' is non-nil.
3074 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3075 (org-test-with-temp-text "* H\nParagraph<point>"
3076 (let ((org-adapt-indentation t
))
3077 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3078 (replace-regexp-in-string
3079 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3081 ;; Create deadline when `org-adapt-indentation' is nil.
3083 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3084 (org-test-with-temp-text "* H\nParagraph<point>"
3085 (let ((org-adapt-indentation nil
))
3086 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3087 (replace-regexp-in-string
3088 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3090 ;; Update deadline when `org-adapt-indentation' is non-nil.
3092 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3093 (org-test-with-temp-text "\
3095 DEADLINE: <2015-06-24 Wed>
3097 (let ((org-adapt-indentation t
))
3098 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3099 (replace-regexp-in-string
3100 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3102 ;; Update deadline when `org-adapt-indentation' is nil.
3104 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3105 (org-test-with-temp-text "\
3107 DEADLINE: <2015-06-24 Wed>
3109 (let ((org-adapt-indentation nil
))
3110 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3111 (replace-regexp-in-string
3112 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3114 ;; Schedule when `org-adapt-indentation' is non-nil.
3116 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3117 (org-test-with-temp-text "* H\nParagraph<point>"
3118 (let ((org-adapt-indentation t
))
3119 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3120 (replace-regexp-in-string
3121 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3123 ;; Schedule when `org-adapt-indentation' is nil.
3125 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3126 (org-test-with-temp-text "* H\nParagraph<point>"
3127 (let ((org-adapt-indentation nil
))
3128 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3129 (replace-regexp-in-string
3130 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3132 ;; Add deadline when scheduled.
3136 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3138 (org-test-with-temp-text "\
3140 SCHEDULED: <2015-06-24 Wed>
3142 (let ((org-adapt-indentation t
))
3143 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3144 (replace-regexp-in-string
3145 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3147 ;; Remove middle entry.
3151 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3153 (org-test-with-temp-text "\
3155 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3157 (let ((org-adapt-indentation t
))
3158 (org-add-planning-info nil nil
'deadline
))
3159 (replace-regexp-in-string
3160 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3162 ;; Remove last entry and then middle entry (order should not
3167 CLOSED: [2015-06-24]
3169 (org-test-with-temp-text "\
3171 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3173 (let ((org-adapt-indentation t
))
3174 (org-add-planning-info nil nil
'scheduled
'deadline
))
3175 (replace-regexp-in-string
3176 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3178 ;; Remove closed when `org-adapt-indentation' is non-nil.
3180 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3181 (org-test-with-temp-text "\
3183 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3185 (let ((org-adapt-indentation t
))
3186 (org-add-planning-info nil nil
'closed
))
3187 (replace-regexp-in-string
3188 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3191 (equal "* H\n Paragraph"
3192 (org-test-with-temp-text "\
3194 CLOSED: [2015-06-25 Thu]
3196 (let ((org-adapt-indentation t
))
3197 (org-add-planning-info nil nil
'closed
))
3198 (replace-regexp-in-string
3199 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3201 ;; Remove closed when `org-adapt-indentation' is nil.
3203 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3204 (org-test-with-temp-text "\
3206 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3208 (let ((org-adapt-indentation nil
))
3209 (org-add-planning-info nil nil
'closed
))
3210 (replace-regexp-in-string
3211 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3214 (equal "* H\nParagraph"
3215 (org-test-with-temp-text "\
3217 CLOSED: [2015-06-25 Thu]
3219 (let ((org-adapt-indentation nil
))
3220 (org-add-planning-info nil nil
'closed
))
3221 (replace-regexp-in-string
3222 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3224 ;; Remove closed entry and delete empty line.
3229 (org-test-with-temp-text "\
3231 CLOSED: [2015-06-24 Wed]
3233 (let ((org-adapt-indentation t
))
3234 (org-add-planning-info nil nil
'closed
))
3235 (replace-regexp-in-string
3236 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3238 ;; Remove one entry and update another.
3240 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3241 (org-test-with-temp-text "\
3243 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3245 (let ((org-adapt-indentation t
))
3246 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3247 (replace-regexp-in-string
3248 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3254 (ert-deftest test-org
/buffer-property-keys
()
3255 "Test `org-buffer-property-keys' specifications."
3256 ;; Retrieve properties accross siblings.
3259 (org-test-with-temp-text "
3268 (org-buffer-property-keys))))
3269 ;; Retrieve properties accross children.
3272 (org-test-with-temp-text "
3281 (org-buffer-property-keys))))
3282 ;; Retrieve muliple properties in the same drawer.
3285 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3286 (org-buffer-property-keys))))
3287 ;; Ignore extension symbol in property name.
3290 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3291 (org-buffer-property-keys))))
3292 ;; With non-nil COLUMNS, extract property names from columns.
3295 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3296 (org-buffer-property-keys nil nil t
))))
3298 (equal '("A" "B" "COLUMNS")
3299 (org-test-with-temp-text
3300 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3301 (org-buffer-property-keys nil nil t
)))))
3303 (ert-deftest test-org
/property-values
()
3304 "Test `org-property-values' specifications."
3308 (org-test-with-temp-text
3309 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3310 (org-property-values "A"))))
3311 ;; Ignore empty values.
3313 (org-test-with-temp-text
3314 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3315 (org-property-values "A")))
3316 ;; Take into consideration extended values.
3319 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3320 (org-property-values "A")))))
3322 (ert-deftest test-org
/find-property
()
3323 "Test `org-find-property' specifications."
3327 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3328 (org-find-property "prop"))))
3329 ;; Ignore false positives.
3332 (org-test-with-temp-text
3333 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3334 (org-find-property "A"))))
3335 ;; Return first entry found in buffer.
3338 (org-test-with-temp-text
3339 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3340 (org-find-property "A"))))
3341 ;; Only search visible part of the buffer.
3344 (org-test-with-temp-text
3345 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3346 (org-narrow-to-subtree)
3347 (org-find-property "A"))))
3348 ;; With optional argument, only find entries with a specific value.
3350 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3351 (org-find-property "A" "2")))
3354 (org-test-with-temp-text
3355 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3356 (org-find-property "A" "2"))))
3357 ;; Use "nil" for explicit nil values.
3360 (org-test-with-temp-text
3361 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3362 (org-find-property "A" "nil")))))
3364 (ert-deftest test-org
/entry-delete
()
3365 "Test `org-entry-delete' specifications."
3369 " *:PROPERTIES:\n *:B: +2\n *:END:"
3370 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3371 (org-entry-delete (point) "A")
3373 ;; Also remove accumulated properties.
3377 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3378 (org-entry-delete (point) "A")
3380 ;; When last property is removed, remove the property drawer.
3384 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3385 (org-entry-delete (point) "A")
3387 ;; Return a non-nil value when some property was removed.
3389 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3390 (org-entry-delete (point) "A")))
3392 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3393 (org-entry-delete (point) "C"))))
3395 (ert-deftest test-org
/entry-get
()
3396 "Test `org-entry-get' specifications."
3400 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3401 (org-entry-get (point) "A"))))
3405 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3406 (org-entry-get (point) "a"))))
3407 ;; Handle extended values, both before and after base value.
3410 (org-test-with-temp-text
3411 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3412 (org-entry-get (point) "A"))))
3413 ;; Empty values are returned as the empty string.
3416 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3417 (org-entry-get (point) "A"))))
3418 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3419 ;; otherwise, return nil.
3421 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3422 (org-entry-get (point) "A")))
3425 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3426 (org-entry-get (point) "A" nil t
))))
3427 ;; Return nil when no property is found, independently on the
3428 ;; LITERAL-NIL argument.
3430 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3431 (org-entry-get (point) "B")))
3433 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3434 (org-entry-get (point) "B" nil t
)))
3435 ;; Handle inheritance, when allowed. Include extended values and
3436 ;; possibly global values.
3440 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3441 (org-entry-get (point) "A" t
))))
3445 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3446 (let ((org-use-property-inheritance t
))
3447 (org-entry-get (point) "A" 'selective
)))))
3449 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3450 (let ((org-use-property-inheritance nil
))
3451 (org-entry-get (point) "A" 'selective
))))
3455 (org-test-with-temp-text
3456 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3457 (org-entry-get (point-max) "A" t
))))
3460 (org-test-with-temp-text
3461 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3463 (org-entry-get (point-max) "A" t
))))
3466 (org-test-with-temp-text
3467 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3469 (org-entry-get (point-max) "A" t
)))))
3471 (ert-deftest test-org
/entry-properties
()
3472 "Test `org-entry-properties' specifications."
3473 ;; Get "ITEM" property.
3476 (org-test-with-temp-text "* TODO H"
3477 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3480 (org-test-with-temp-text "* TODO H"
3481 (cdr (assoc "ITEM" (org-entry-properties))))))
3482 ;; Get "TODO" property. TODO keywords are case sensitive.
3485 (org-test-with-temp-text "* TODO H"
3486 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3489 (org-test-with-temp-text "* TODO H"
3490 (cdr (assoc "TODO" (org-entry-properties))))))
3492 (org-test-with-temp-text "* H"
3493 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3495 (org-test-with-temp-text "* todo H"
3496 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3497 ;; Get "PRIORITY" property.
3500 (org-test-with-temp-text "* [#A] H"
3501 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3504 (org-test-with-temp-text "* [#A] H"
3505 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3507 (equal (char-to-string org-default-priority
)
3508 (org-test-with-temp-text "* H"
3509 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3510 ;; Get "FILE" property.
3512 (org-test-with-temp-text-in-file "* H\nParagraph"
3513 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3514 (buffer-file-name))))
3516 (org-test-with-temp-text-in-file "* H\nParagraph"
3517 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3518 (buffer-file-name))))
3520 (org-test-with-temp-text "* H\nParagraph"
3521 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3522 ;; Get "TAGS" property.
3524 (equal ":tag1:tag2:"
3525 (org-test-with-temp-text "* H :tag1:tag2:"
3526 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3528 (equal ":tag1:tag2:"
3529 (org-test-with-temp-text "* H :tag1:tag2:"
3530 (cdr (assoc "TAGS" (org-entry-properties))))))
3532 (org-test-with-temp-text "* H"
3533 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3534 ;; Get "ALLTAGS" property.
3536 (equal ":tag1:tag2:"
3537 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3538 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3540 (equal ":tag1:tag2:"
3541 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3542 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3544 (org-test-with-temp-text "* H"
3545 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3546 ;; Get "BLOCKED" property.
3549 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3550 (let ((org-enforce-todo-dependencies t
)
3552 '(org-block-todo-from-children-or-siblings-or-parent)))
3553 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3556 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
3557 (let ((org-enforce-todo-dependencies t
)
3559 '(org-block-todo-from-children-or-siblings-or-parent)))
3560 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3561 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3565 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3566 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3570 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3571 (cdr (assoc "CLOSED" (org-entry-properties))))))
3573 (org-test-with-temp-text "* H"
3574 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3578 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3579 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3583 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3584 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3586 (org-test-with-temp-text "* H"
3587 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3591 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3592 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3596 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3597 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3599 (org-test-with-temp-text "* H"
3600 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3604 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3605 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3608 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3609 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3612 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3613 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3616 (org-test-with-temp-text
3617 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3619 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3620 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3621 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
3623 (equal "<2012-03-29 thu.>"
3624 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
3625 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
3627 (equal "[2012-03-29 thu.]"
3628 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
3629 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
3631 (equal "<2012-03-29 thu.>"
3632 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
3633 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
3635 (equal "[2014-03-04 tue.]"
3636 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
3637 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
3638 ;; Get standard properties.
3641 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3642 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3643 ;; Handle extended properties.
3646 (org-test-with-temp-text
3647 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3648 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3651 (org-test-with-temp-text
3652 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3653 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3654 ;; Ignore forbidden (special) properties.
3656 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3657 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3659 (ert-deftest test-org
/entry-put
()
3660 "Test `org-entry-put' specifications."
3661 ;; Error when not a string or nil.
3663 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3664 (org-entry-put 1 "test" 2)))
3665 ;; Error when property name is invalid.
3667 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3668 (org-entry-put 1 "no space" "value")))
3670 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3671 (org-entry-put 1 "" "value")))
3672 ;; Set "TODO" property.
3674 (string-match (regexp-quote " TODO H")
3675 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3676 (org-entry-put (point) "TODO" "TODO")
3679 (string-match (regexp-quote "* H")
3680 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3681 (org-entry-put (point) "TODO" nil
)
3683 ;; Set "PRIORITY" property.
3686 (org-test-with-temp-text "* [#B] H"
3687 (org-entry-put (point) "PRIORITY" "A")
3691 (org-test-with-temp-text "* [#B] H"
3692 (org-entry-put (point) "PRIORITY" nil
)
3694 ;; Set "SCHEDULED" property.
3696 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3697 (org-test-with-temp-text "* H"
3698 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3702 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3703 (org-entry-put (point) "SCHEDULED" nil
)
3706 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3707 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3708 (org-entry-put (point) "SCHEDULED" "earlier")
3711 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3712 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3713 (org-entry-put (point) "SCHEDULED" "later")
3715 ;; Set "DEADLINE" property.
3717 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3718 (org-test-with-temp-text "* H"
3719 (org-entry-put (point) "DEADLINE" "2014-03-04")
3723 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3724 (org-entry-put (point) "DEADLINE" nil
)
3727 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3728 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3729 (org-entry-put (point) "DEADLINE" "earlier")
3732 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3733 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3734 (org-entry-put (point) "DEADLINE" "later")
3736 ;; Set "CATEGORY" property
3738 (string-match "^ *:CATEGORY: cat"
3739 (org-test-with-temp-text "* H"
3740 (org-entry-put (point) "CATEGORY" "cat")
3742 ;; Regular properties, with or without pre-existing drawer.
3744 (string-match "^ *:A: +2$"
3745 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3746 (org-entry-put (point) "A" "2")
3749 (string-match "^ *:A: +1$"
3750 (org-test-with-temp-text "* H"
3751 (org-entry-put (point) "A" "1")
3753 ;; Special case: two consecutive headlines.
3755 (string-match "\\* A\n *:PROPERTIES:"
3756 (org-test-with-temp-text "* A\n** B"
3757 (org-entry-put (point) "A" "1")
3763 (ert-deftest test-org
/update-radio-target-regexp
()
3764 "Test `org-update-radio-target-regexp' specifications."
3765 ;; Properly update cache with no previous radio target regexp.
3768 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3769 (save-excursion (goto-char (point-max)) (org-element-context))
3771 (search-forward "o")
3773 (org-update-radio-target-regexp)
3774 (goto-char (point-max))
3775 (org-element-type (org-element-context)))))
3776 ;; Properly update cache with previous radio target regexp.
3779 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3780 (save-excursion (goto-char (point-max)) (org-element-context))
3782 (search-forward "o")
3784 (org-update-radio-target-regexp)
3785 (search-backward "r")
3788 (org-update-radio-target-regexp)
3789 (goto-char (point-max))
3790 (delete-region (line-beginning-position) (point))
3792 (org-element-type (org-element-context))))))
3797 (ert-deftest test-org
/match-sparse-tree
()
3798 "Test `org-match-sparse-tree' specifications."
3801 (org-test-with-temp-text "* H\n** H1 :tag:"
3802 (org-match-sparse-tree nil
"tag")
3803 (search-forward "H1")
3804 (org-invisible-p2)))
3806 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3807 (org-match-sparse-tree nil
"tag")
3808 (search-forward "H2")
3809 (org-invisible-p2)))
3810 ;; "-" operator for tags.
3812 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3813 (org-match-sparse-tree nil
"tag1-tag2")
3814 (search-forward "H1")
3815 (org-invisible-p2)))
3817 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3818 (org-match-sparse-tree nil
"tag1-tag2")
3819 (search-forward "H2")
3820 (org-invisible-p2)))
3821 ;; "&" operator for tags.
3823 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3824 (org-match-sparse-tree nil
"tag1&tag2")
3825 (search-forward "H1")
3826 (org-invisible-p2)))
3828 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3829 (org-match-sparse-tree nil
"tag1&tag2")
3830 (search-forward "H2")
3831 (org-invisible-p2)))
3832 ;; "|" operator for tags.
3834 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3835 (org-match-sparse-tree nil
"tag1|tag2")
3836 (search-forward "H1")
3837 (org-invisible-p2)))
3839 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3840 (org-match-sparse-tree nil
"tag1|tag2")
3841 (search-forward "H2")
3842 (org-invisible-p2)))
3843 ;; Regexp match on tags.
3845 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3846 (org-match-sparse-tree nil
"{^tag.*}")
3847 (search-forward "H1")
3848 (org-invisible-p2)))
3850 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3851 (org-match-sparse-tree nil
"{^tag.*}")
3852 (search-forward "H2")
3853 (org-invisible-p2)))
3854 ;; Match group tags.
3856 (org-test-with-temp-text
3857 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3858 (org-match-sparse-tree nil
"work")
3859 (search-forward "H1")
3860 (org-invisible-p2)))
3862 (org-test-with-temp-text
3863 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3864 (org-match-sparse-tree nil
"work")
3865 (search-forward "H2")
3866 (org-invisible-p2)))
3867 ;; Match group tags with hard brackets.
3869 (org-test-with-temp-text
3870 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3871 (org-match-sparse-tree nil
"work")
3872 (search-forward "H1")
3873 (org-invisible-p2)))
3875 (org-test-with-temp-text
3876 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3877 (org-match-sparse-tree nil
"work")
3878 (search-forward "H2")
3879 (org-invisible-p2)))
3880 ;; Match tags in hierarchies
3882 (org-test-with-temp-text
3883 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3884 #+TAGS: [ Lev_2 : Lev_3 ]\n
3885 #+TAGS: { Lev_3 : Lev_4 }\n
3886 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3887 (org-match-sparse-tree nil
"Lev_1")
3888 (search-forward "H4")
3889 (org-invisible-p2)))
3890 ;; Match regular expressions in tags
3892 (org-test-with-temp-text
3893 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3894 (org-match-sparse-tree nil
"Lev")
3895 (search-forward "H1")
3896 (org-invisible-p2)))
3898 (org-test-with-temp-text
3899 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3900 (org-match-sparse-tree nil
"Lev")
3901 (search-forward "H1")
3902 (org-invisible-p2)))
3903 ;; Match properties.
3905 (org-test-with-temp-text
3906 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3907 (org-match-sparse-tree nil
"A=\"1\"")
3908 (search-forward "H2")
3909 (org-invisible-p2)))
3911 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3912 (org-match-sparse-tree nil
"A=\"1\"")
3913 (search-forward "H2")
3914 (org-invisible-p2)))
3915 ;; Case is not significant when matching properties.
3917 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3918 (org-match-sparse-tree nil
"a=\"1\"")
3919 (search-forward "H2")
3920 (org-invisible-p2)))
3922 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3923 (org-match-sparse-tree nil
"A=\"1\"")
3924 (search-forward "H2")
3925 (org-invisible-p2)))
3926 ;; Match special LEVEL property.
3928 (org-test-with-temp-text "* H\n** H1\n*** H2"
3929 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3930 (search-forward "H1")
3931 (org-invisible-p2)))
3933 (org-test-with-temp-text "* H\n** H1\n*** H2"
3934 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3935 (search-forward "H2")
3936 (org-invisible-p2)))
3937 ;; Comparison operators when matching properties.
3939 (org-test-with-temp-text
3940 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3941 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3942 (search-forward "H1")
3943 (org-invisible-p2)))
3945 (org-test-with-temp-text
3946 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3947 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3948 (search-forward "H2")
3949 (org-invisible-p2)))
3950 ;; Regexp match on properties values.
3952 (org-test-with-temp-text
3953 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3954 (org-match-sparse-tree nil
"A={f.*}")
3955 (search-forward "H1")
3956 (org-invisible-p2)))
3958 (org-test-with-temp-text
3959 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3960 (org-match-sparse-tree nil
"A={f.*}")
3961 (search-forward "H2")
3962 (org-invisible-p2)))
3963 ;; With an optional argument, limit match to TODO entries.
3965 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3966 (org-match-sparse-tree t
"tag")
3967 (search-forward "H1")
3968 (org-invisible-p2)))
3970 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3971 (org-match-sparse-tree t
"tag")
3972 (search-forward "H2")
3973 (org-invisible-p2))))
3978 (ert-deftest test-org
/time-stamp
()
3979 "Test `org-time-stamp' specifications."
3980 ;; Insert chosen time stamp at point.
3983 "Te<2014-03-04 .*?>xt"
3984 (org-test-with-temp-text "Te<point>xt"
3985 (flet ((org-read-date
3987 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3988 (org-time-stamp nil
)
3990 ;; With a prefix argument, also insert time.
3993 "Te<2014-03-04 .*? 00:41>xt"
3994 (org-test-with-temp-text "Te<point>xt"
3995 (flet ((org-read-date
3997 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3998 (org-time-stamp '(4))
4000 ;; With two universal prefix arguments, insert an active timestamp
4001 ;; with the current time without prompting the user.
4004 "Te<2014-03-04 .*? 00:41>xt"
4005 (org-test-with-temp-text "Te<point>xt"
4006 (flet ((current-time
4008 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
4009 (org-time-stamp '(16))
4011 ;; When optional argument is non-nil, insert an inactive timestamp.
4014 "Te\\[2014-03-04 .*?\\]xt"
4015 (org-test-with-temp-text "Te<point>xt"
4016 (flet ((org-read-date
4018 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4019 (org-time-stamp nil t
)
4021 ;; When called from a timestamp, replace existing one.
4025 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4026 (flet ((org-read-date
4028 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4029 (org-time-stamp nil
)
4033 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4034 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4035 (flet ((org-read-date
4037 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4038 (org-time-stamp nil
)
4040 ;; When replacing a timestamp, preserve repeater, if any.
4043 "<2014-03-04 .*? \\+2y>"
4044 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4045 (flet ((org-read-date
4047 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4048 (org-time-stamp nil
)
4050 ;; When called twice in a raw, build a date range.
4053 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4054 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4055 (flet ((org-read-date
4057 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4058 (let ((last-command 'org-time-stamp
)
4059 (this-command 'org-time-stamp
))
4060 (org-time-stamp nil
))
4061 (buffer-string))))))
4063 (ert-deftest test-org
/timestamp-has-time-p
()
4064 "Test `org-timestamp-has-time-p' specifications."
4067 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4068 (org-timestamp-has-time-p (org-element-context))))
4071 (org-test-with-temp-text "<2012-03-29 Thu>"
4072 (org-timestamp-has-time-p (org-element-context)))))
4074 (ert-deftest test-org
/timestamp-format
()
4075 "Test `org-timestamp-format' specifications."
4080 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4081 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4086 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4087 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4089 (ert-deftest test-org
/timestamp-split-range
()
4090 "Test `org-timestamp-split-range' specifications."
4091 ;; Extract range start (active).
4094 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4095 (let ((ts (org-timestamp-split-range (org-element-context))))
4096 (mapcar (lambda (p) (org-element-property p ts
))
4097 '(:year-end
:month-end
:day-end
))))))
4098 ;; Extract range start (inactive)
4101 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4102 (let ((ts (org-timestamp-split-range (org-element-context))))
4103 (mapcar (lambda (p) (org-element-property p ts
))
4104 '(:year-end
:month-end
:day-end
))))))
4105 ;; Extract range end (active).
4108 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4109 (let ((ts (org-timestamp-split-range
4110 (org-element-context) t
)))
4111 (mapcar (lambda (p) (org-element-property p ts
))
4112 '(:year-end
:month-end
:day-end
))))))
4113 ;; Extract range end (inactive)
4116 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4117 (let ((ts (org-timestamp-split-range
4118 (org-element-context) t
)))
4119 (mapcar (lambda (p) (org-element-property p ts
))
4120 '(:year-end
:month-end
:day-end
))))))
4121 ;; Return the timestamp if not a range.
4123 (org-test-with-temp-text "[2012-03-29 Thu]"
4124 (let* ((ts-orig (org-element-context))
4125 (ts-copy (org-timestamp-split-range ts-orig
)))
4126 (eq ts-orig ts-copy
))))
4128 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4129 (let* ((ts-orig (org-element-context))
4130 (ts-copy (org-timestamp-split-range ts-orig
)))
4131 (eq ts-orig ts-copy
)))))
4133 (ert-deftest test-org
/timestamp-translate
()
4134 "Test `org-timestamp-translate' specifications."
4135 ;; Translate whole date range.
4138 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4139 (let ((org-display-custom-times t
)
4140 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4141 (org-timestamp-translate (org-element-context))))))
4142 ;; Translate date range start.
4145 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4146 (let ((org-display-custom-times t
)
4147 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4148 (org-timestamp-translate (org-element-context) 'start
)))))
4149 ;; Translate date range end.
4152 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4153 (let ((org-display-custom-times t
)
4154 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4155 (org-timestamp-translate (org-element-context) 'end
)))))
4156 ;; Translate time range.
4159 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4160 (let ((org-display-custom-times t
)
4161 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4162 (org-timestamp-translate (org-element-context))))))
4163 ;; Translate non-range timestamp.
4166 (org-test-with-temp-text "<2012-03-29 Thu>"
4167 (let ((org-display-custom-times t
)
4168 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4169 (org-timestamp-translate (org-element-context))))))
4170 ;; Do not change `diary' timestamps.
4172 (equal "<%%(org-float t 4 2)>"
4173 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4174 (let ((org-display-custom-times t
)
4175 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4176 (org-timestamp-translate (org-element-context)))))))
4182 (ert-deftest test-org
/flag-drawer
()
4183 "Test `org-flag-drawer' specifications."
4186 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4188 (get-char-property (line-end-position) 'invisible
)))
4191 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4193 (org-flag-drawer nil
)
4194 (get-char-property (line-end-position) 'invisible
)))
4195 ;; Test optional argument.
4197 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4198 (let ((drawer (save-excursion (search-forward ":D2")
4199 (org-element-at-point))))
4200 (org-flag-drawer t drawer
)
4201 (get-char-property (progn (search-forward ":D2") (line-end-position))
4204 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4205 (let ((drawer (save-excursion (search-forward ":D2")
4206 (org-element-at-point))))
4207 (org-flag-drawer t drawer
)
4208 (get-char-property (line-end-position) 'invisible
))))
4209 ;; Do not hide fake drawers.
4211 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4214 (get-char-property (line-end-position) 'invisible
)))
4215 ;; Do not hide incomplete drawers.
4217 (org-test-with-temp-text ":D:\nparagraph"
4220 (get-char-property (line-end-position) 'invisible
)))
4221 ;; Do not hide drawers when called from final blank lines.
4223 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4224 (goto-char (point-max))
4226 (goto-char (point-min))
4227 (get-char-property (line-end-position) 'invisible
)))
4228 ;; Don't leave point in an invisible part of the buffer when hiding
4231 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4232 (goto-char (point-max))
4234 (get-char-property (point) 'invisible
))))
4236 (ert-deftest test-org
/hide-block-toggle
()
4237 "Test `org-hide-block-toggle' specifications."
4238 ;; Error when not at a block.
4240 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4241 (org-hide-block-toggle 'off
)
4242 (get-char-property (line-end-position) 'invisible
)))
4245 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4246 (org-hide-block-toggle)
4247 (get-char-property (line-end-position) 'invisible
)))
4249 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4250 (org-hide-block-toggle)
4251 (get-char-property (line-end-position) 'invisible
)))
4252 ;; Show block unconditionally when optional argument is `off'.
4254 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4255 (org-hide-block-toggle)
4256 (org-hide-block-toggle 'off
)
4257 (get-char-property (line-end-position) 'invisible
)))
4259 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4260 (org-hide-block-toggle 'off
)
4261 (get-char-property (line-end-position) 'invisible
)))
4262 ;; Hide block unconditionally when optional argument is non-nil.
4264 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4265 (org-hide-block-toggle t
)
4266 (get-char-property (line-end-position) 'invisible
)))
4268 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4269 (org-hide-block-toggle)
4270 (org-hide-block-toggle t
)
4271 (get-char-property (line-end-position) 'invisible
)))
4272 ;; Do not hide block when called from final blank lines.
4274 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4275 (org-hide-block-toggle)
4276 (goto-char (point-min))
4277 (get-char-property (line-end-position) 'invisible
)))
4278 ;; Don't leave point in an invisible part of the buffer when hiding
4281 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4282 (org-hide-block-toggle)
4283 (get-char-property (point) 'invisible
))))
4285 (ert-deftest test-org
/hide-block-toggle-maybe
()
4286 "Test `org-hide-block-toggle-maybe' specifications."
4288 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4289 (org-hide-block-toggle-maybe)))
4291 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4293 (ert-deftest test-org
/show-set-visibility
()
4294 "Test `org-show-set-visibility' specifications."
4295 ;; Do not throw an error before first heading.
4297 (org-test-with-temp-text "Preamble\n* Headline"
4298 (org-show-set-visibility 'tree
)
4300 ;; Test all visibility spans, both on headline and in entry.
4301 (let ((list-visible-lines
4302 (lambda (state headerp
)
4303 (org-test-with-temp-text "* Grandmother (0)
4314 **** The other child (11)
4319 (search-forward (if headerp
"Self" "Match"))
4320 (org-show-set-visibility state
)
4321 (goto-char (point-min))
4322 (let (result (line 0))
4324 (unless (org-invisible-p2) (push line result
))
4327 (nreverse result
))))))
4328 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4329 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4330 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4331 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4332 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4333 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4334 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4335 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4336 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4337 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4338 (funcall list-visible-lines
'tree nil
)))
4339 (should (equal '(0 1 3 4 5 7 12 13)
4340 (funcall list-visible-lines
'canonical t
)))
4341 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4342 (funcall list-visible-lines
'canonical nil
)))))
4347 ;;; test-org.el ends here