1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Template test file for Org-mode tests
30 (ert-deftest test-org
/toggle-comment
()
31 "Test `org-toggle-comment' specifications."
35 (org-test-with-temp-text "* COMMENT Test"
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
43 ;; Headline with a regular keyword.
46 (org-test-with-temp-text "* TODO COMMENT Test"
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
57 (org-test-with-temp-text "* COMMENT"
62 (org-test-with-temp-text "* "
65 ;; Headline with a single keyword.
68 (org-test-with-temp-text "* TODO COMMENT"
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
76 ;; Headline with a keyword, a priority cookie and contents.
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
88 (ert-deftest test-org
/comment-dwim
()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim
)
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim
)
104 ;; No region selected, and a comment on this line: indent it.
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t
))
110 (call-interactively 'comment-dwim
))
112 ;; Also recognize single # at column 0 as comments.
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim
)
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
125 (transient-mark-mode 1)
126 (push-mark (point) t t
)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim
)
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
136 (transient-mark-mode 1)
137 (push-mark (point) t t
)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil
))
140 (call-interactively 'comment-dwim
))
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
146 (transient-mark-mode 1)
147 (push-mark (point) t t
)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t
))
150 (call-interactively 'comment-dwim
))
152 ;; In front of a keyword without region, insert a new comment.
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim
)
158 ;; In a source block, use appropriate syntax.
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim
))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
170 (transient-mark-mode 1)
171 (push-mark (point) t t
)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim
))
179 ;;; Date and time analysis
181 (ert-deftest test-org
/org-read-date
()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t
))
186 (org-read-date t nil
"12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t
))
190 (org-read-date t nil
"29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t
))
194 (org-read-date t nil
"29.03. 16:40"))))
195 ;; Relative date applied to current time if there is single
196 ;; plus/minus, or to default date when there are two of them.
200 (flet ((current-time () (apply #'encode-time
201 (org-parse-time-string "2014-03-04"))))
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (flet ((current-time () (apply #'encode-time
209 (org-parse-time-string "2014-03-04"))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (flet ((current-time () (apply #'encode-time
220 (org-parse-time-string "2014-03-04"))))
221 (let ((org-read-date-prefer-future t
))
222 (org-read-date t nil
"1")))))
226 (flet ((current-time () (apply #'encode-time
227 (org-parse-time-string "2012-03-29"))))
228 (let ((org-read-date-prefer-future t
))
229 (org-read-date t nil
"3-4")))))
233 (flet ((current-time () (apply #'encode-time
234 (org-parse-time-string "2012-03-29"))))
235 (let ((org-read-date-prefer-future nil
))
236 (org-read-date t nil
"3-4")))))
237 ;; When set to `org-read-date-prefer-future' is set to `time', read
238 ;; day is moved to tomorrow if specified hour is before current
239 ;; time. However, it only happens in no other part of the date is
244 (flet ((current-time () (apply #'encode-time
245 (org-parse-time-string "2012-03-29 16:40"))))
246 (let ((org-read-date-prefer-future 'time
))
247 (org-read-date t nil
"00:40" nil
)))))
251 (flet ((current-time () (apply #'encode-time
252 (org-parse-time-string "2012-03-29 16:40"))))
253 (let ((org-read-date-prefer-future 'time
))
254 (org-read-date t nil
"29 00:40" nil
)))))
255 ;; Caveat: `org-read-date-prefer-future' always refers to current
256 ;; time, not default time, when they differ.
261 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
262 (let ((org-read-date-prefer-future t
))
265 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
270 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
271 (let ((org-read-date-prefer-future t
))
274 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
276 (ert-deftest test-org
/org-parse-time-string
()
277 "Test `org-parse-time-string'."
278 (should (equal (org-parse-time-string "2012-03-29 16:40")
279 '(0 40 16 29 3 2012 nil nil nil
)))
280 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
281 '(0 40 16 29 3 2012 nil nil nil
)))
282 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
283 '(0 40 16 29 3 2012 nil nil nil
)))
284 (should (equal (org-parse-time-string "<2012-03-29>")
285 '(0 0 0 29 3 2012 nil nil nil
)))
286 (should (equal (org-parse-time-string "<2012-03-29>" t
)
287 '(0 nil nil
29 3 2012 nil nil nil
))))
292 (ert-deftest test-org
/insert-property-drawer
()
293 "Test `org-insert-property-drawer' specifications."
294 ;; Error before first headline.
295 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
296 ;; Insert drawer right after headline if there is no planning line,
297 ;; or after it otherwise.
299 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
300 (org-test-with-temp-text "* H\nParagraph<point>"
301 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
304 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
305 (org-test-with-temp-text
306 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
307 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
309 ;; Indent inserted drawer.
311 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
312 (org-test-with-temp-text "* H\nParagraph<point>"
313 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
315 ;; Handle insertion at eob.
317 (equal "* H\n:PROPERTIES:\n:END:\n"
318 (org-test-with-temp-text "* H"
319 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
321 ;; Skip inlinetasks before point.
322 (when (featurep 'org-inlinetask
)
324 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
325 (org-test-with-temp-text
326 "* H\n*************** I\n*************** END\nP<point>"
327 (let ((org-adapt-indentation nil
)
328 (org-inlinetask-min-level 15))
329 (org-insert-property-drawer))
331 ;; Correctly set drawer in an inlinetask.
332 (when (featurep 'org-inlinetask
)
334 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
335 (org-test-with-temp-text
336 "* H\n*************** I\nP<point>\n*************** END"
337 (let ((org-adapt-indentation nil
)
338 (org-inlinetask-min-level 15))
339 (org-insert-property-drawer))
345 (ert-deftest test-org
/fill-paragraph
()
346 "Test `org-fill-paragraph' specifications."
347 ;; At an Org table, align it.
350 (org-test-with-temp-text "|a|"
354 (equal "#+name: table\n| a |\n"
355 (org-test-with-temp-text "#+name: table\n| a |"
358 ;; At a paragraph, preserve line breaks.
359 (org-test-with-temp-text "some \\\\\nlong\ntext"
360 (let ((fill-column 20))
362 (should (equal (buffer-string) "some \\\\\nlong text"))))
363 ;; Correctly fill a paragraph when point is at its very end.
366 (org-test-with-temp-text "A\nB"
367 (let ((fill-column 20))
368 (goto-char (point-max))
371 ;; Correctly fill the last paragraph of a greater element.
373 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
374 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
375 (let ((fill-column 8))
380 ;; Correctly fill an element in a narrowed buffer.
383 (org-test-with-temp-text "01234 6789"
384 (let ((fill-column 5))
385 (narrow-to-region 1 8)
388 ;; Handle `adaptive-fill-regexp' in paragraphs.
391 (org-test-with-temp-text "> a\n> b"
392 (let ((fill-column 5)
393 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
396 ;; Special case: Fill first paragraph when point is at an item or
397 ;; a plain-list or a footnote reference.
400 (org-test-with-temp-text "- A\n B"
401 (let ((fill-column 20))
406 (org-test-with-temp-text "[fn:1] A\nB"
407 (let ((fill-column 20))
410 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
411 (let ((fill-column 20))
413 (should (equal (buffer-string)
414 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
415 ;; Fill contents of `comment-block' elements.
418 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
419 (let ((fill-column 20))
423 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
424 ;; Fill `comment' elements.
427 (org-test-with-temp-text " # A\n # B"
428 (let ((fill-column 20))
431 ;; Do not mix consecutive comments when filling one of them.
433 (equal "# A B\n\n# C"
434 (org-test-with-temp-text "# A\n# B\n\n# C"
435 (let ((fill-column 20))
438 ;; Use commented empty lines as separators when filling comments.
440 (equal "# A B\n#\n# C"
441 (org-test-with-temp-text "# A\n# B\n#\n# C"
442 (let ((fill-column 20))
445 ;; Handle `adaptive-fill-regexp' in comments.
448 (org-test-with-temp-text "# > a\n# > b"
449 (let ((fill-column 20)
450 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
453 ;; Do nothing at affiliated keywords.
454 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
455 (let ((fill-column 20))
457 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
458 ;; Do not move point after table when filling a table.
460 (org-test-with-temp-text "| a | b |\n| c | d |\n"
465 (ert-deftest test-org
/auto-fill-function
()
466 "Test auto-filling features."
467 ;; Auto fill paragraph.
470 (org-test-with-temp-text "12345 7890"
471 (let ((fill-column 5))
473 (org-auto-fill-function)
475 ;; Auto fill first paragraph in an item.
477 (equal "- 12345\n 7890"
478 (org-test-with-temp-text "- 12345 7890"
479 (let ((fill-column 7))
481 (org-auto-fill-function)
483 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
485 (equal "> 12345\n 7890"
486 (org-test-with-temp-text "> 12345 7890"
487 (let ((fill-column 10)
488 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
489 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
491 (org-auto-fill-function)
494 (equal "> 12345\n> 12345\n> 7890"
495 (org-test-with-temp-text "> 12345\n> 12345 7890"
496 (let ((fill-column 10)
497 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
498 (goto-char (point-max))
499 (org-auto-fill-function)
502 (equal " 12345\n *12345\n *12345"
503 (org-test-with-temp-text " 12345\n *12345 12345"
504 (let ((fill-column 10)
505 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
506 (goto-char (point-max))
507 (org-auto-fill-function)
509 ;; Auto fill comments.
511 (equal " # 12345\n # 7890"
512 (org-test-with-temp-text " # 12345 7890"
513 (let ((fill-column 10))
515 (org-auto-fill-function)
517 ;; A hash within a line isn't a comment.
519 (equal "12345 # 7890\n# 1"
520 (org-test-with-temp-text "12345 # 7890 1"
521 (let ((fill-column 12))
523 (org-auto-fill-function)
525 ;; Correctly interpret empty prefix.
527 (equal "# a\n# b\nRegular\n# paragraph"
528 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
529 (let ((fill-column 12))
531 (org-auto-fill-function)
533 ;; Comment block: auto fill contents.
535 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
536 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
537 (let ((fill-column 5))
540 (org-auto-fill-function)
543 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
544 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
545 (let ((fill-column 5))
548 (org-auto-fill-function)
550 ;; Do not fill if a new item could be created.
553 (org-test-with-temp-text "12345 - 90"
554 (let ((fill-column 5))
556 (org-auto-fill-function)
558 ;; Do not fill if a line break could be introduced.
560 (equal "123\\\\\n7890"
561 (org-test-with-temp-text "123\\\\ 7890"
562 (let ((fill-column 6))
564 (org-auto-fill-function)
566 ;; Do not fill affiliated keywords.
568 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
569 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
570 (let ((fill-column 20))
572 (org-auto-fill-function)
579 (ert-deftest test-org
/indent-line
()
580 "Test `org-indent-line' specifications."
581 ;; Do not indent footnote definitions or headlines.
584 (org-test-with-temp-text "* H"
586 (org-get-indentation))))
589 (org-test-with-temp-text "[fn:1] fn"
590 (let ((org-adapt-indentation t
)) (org-indent-line))
591 (org-get-indentation))))
592 ;; Do not indent before first headline.
595 (org-test-with-temp-text ""
597 (org-get-indentation))))
598 ;; Indent according to headline level otherwise, unless
599 ;; `org-adapt-indentation' is nil.
602 (org-test-with-temp-text "* H\nA"
604 (let ((org-adapt-indentation t
)) (org-indent-line))
605 (org-get-indentation))))
608 (org-test-with-temp-text "* H\n\nA"
610 (let ((org-adapt-indentation t
)) (org-indent-line))
611 (org-get-indentation))))
614 (org-test-with-temp-text "* H\nA"
616 (let ((org-adapt-indentation nil
)) (org-indent-line))
617 (org-get-indentation))))
618 ;; Indenting preserves point position.
620 (org-test-with-temp-text "* H\nAB"
623 (let ((org-adapt-indentation t
)) (org-indent-line))
625 ;; Do not change indentation at an item.
628 (org-test-with-temp-text "* H\n - A"
630 (let ((org-adapt-indentation t
)) (org-indent-line))
631 (org-get-indentation))))
632 ;; On blank lines at the end of a list, indent like last element
633 ;; within it if the line is still in the list. Otherwise, indent
634 ;; like the whole list.
637 (org-test-with-temp-text "* H\n- A\n - AA\n"
638 (goto-char (point-max))
639 (let ((org-adapt-indentation t
)) (org-indent-line))
640 (org-get-indentation))))
643 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
644 (goto-char (point-max))
645 (let ((org-adapt-indentation t
)) (org-indent-line))
646 (org-get-indentation))))
647 ;; Likewise, on a blank line at the end of a footnote definition,
648 ;; indent at column 0 if line belongs to the definition. Otherwise,
649 ;; indent like the definition itself.
652 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
653 (goto-char (point-max))
654 (let ((org-adapt-indentation t
)) (org-indent-line))
655 (org-get-indentation))))
658 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
659 (goto-char (point-max))
660 (let ((org-adapt-indentation t
)) (org-indent-line))
661 (org-get-indentation))))
662 ;; After the end of the contents of a greater element, indent like
663 ;; the beginning of the element.
666 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
669 (org-get-indentation))))
670 ;; On blank lines after a paragraph, indent like its last non-empty
674 (org-test-with-temp-text " Paragraph\n\n<point>"
676 (org-get-indentation))))
677 ;; At the first line of an element, indent like previous element's
678 ;; first line, ignoring footnotes definitions and inline tasks, or
679 ;; according to parent.
682 (org-test-with-temp-text "A\n\n B\n\nC"
683 (goto-char (point-max))
685 (org-get-indentation))))
688 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
689 (goto-char (point-max))
691 (org-get-indentation))))
694 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
697 (org-get-indentation))))
698 ;; Within code part of a source block, use language major mode if
699 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
700 ;; according to line above.
703 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
705 (let ((org-src-tab-acts-natively t
)
706 (org-edit-src-content-indentation 0))
708 (org-get-indentation))))
711 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
713 (let ((org-src-tab-acts-natively nil
)
714 (org-edit-src-content-indentation 0))
716 (org-get-indentation))))
717 ;; Otherwise, indent like the first non-blank line above.
720 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
723 (org-get-indentation))))
724 ;; Align node properties according to `org-property-format'. Handle
725 ;; nicely empty values.
727 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
728 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
729 (let ((org-property-format "%-10s %s")) (org-indent-line))
732 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
733 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
734 (let ((org-property-format "%-10s %s")) (org-indent-line))
737 (ert-deftest test-org
/indent-region
()
738 "Test `org-indent-region' specifications."
742 (org-test-with-temp-text " A\nB\n C"
743 (org-indent-region (point-min) (point-max))
745 ;; Indent greater elements along with their contents.
747 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
748 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
749 (org-indent-region (point-min) (point-max))
751 ;; Ignore contents of verse blocks and example blocks.
753 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
754 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
755 (org-indent-region (point-min) (point-max))
758 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
759 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
760 (org-indent-region (point-min) (point-max))
762 ;; Indent according to mode if `org-src-tab-acts-natively' is
763 ;; non-nil. Otherwise, do not indent code at all.
765 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
766 (org-test-with-temp-text
767 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
768 (let ((org-src-tab-acts-natively t
)
769 (org-edit-src-content-indentation 0))
770 (org-indent-region (point-min) (point-max)))
773 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
774 (org-test-with-temp-text
775 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
776 (let ((org-src-tab-acts-natively nil
)
777 (org-edit-src-content-indentation 0))
778 (org-indent-region (point-min) (point-max)))
780 ;; Align node properties according to `org-property-format'. Handle
781 ;; nicely empty values.
783 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
784 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
785 (let ((org-property-format "%-10s %s")
786 (org-adapt-indentation nil
))
787 (org-indent-region (point) (point-max)))
790 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
791 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
792 (let ((org-property-format "%-10s %s")
793 (org-adapt-indentation nil
))
794 (org-indent-region (point) (point-max)))
796 ;; Indent plain lists.
798 (equal "- A\n B\n - C\n\n D"
799 (org-test-with-temp-text "- A\n B\n - C\n\n D"
800 (org-indent-region (point-min) (point-max))
804 (org-test-with-temp-text " - A\n\n - B"
805 (org-indent-region (point-min) (point-max))
807 ;; Indent footnote definitions.
809 (equal "[fn:1] Definition\n\nDefinition"
810 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
811 (org-indent-region (point-min) (point-max))
813 ;; Special case: Start indenting on a blank line.
816 (org-test-with-temp-text "\n Paragraph"
817 (org-indent-region (point-min) (point-max))
824 (ert-deftest test-org
/return
()
825 "Test RET (`org-return') specifications."
829 (org-test-with-temp-text "Para<point>graph"
832 ;; With optional argument, indent line.
834 (equal " Para\n graph"
835 (org-test-with-temp-text " Para<point>graph"
838 ;; On a table, call `org-table-next-row'.
840 (org-test-with-temp-text "| <point>a |\n| b |"
842 (org-looking-at-p "b")))
843 ;; Open link or timestamp under point when `org-return-follows-link'
846 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
847 (let ((org-return-follows-link t
)) (org-return))
848 (org-looking-at-p "<<target>>")))
850 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
851 (let ((org-return-follows-link nil
)) (org-return))
852 (org-looking-at-p "<<target>>")))
853 ;; However, do not open link when point is in a table.
855 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
856 (let ((org-return-follows-link t
)) (org-return))
857 (org-looking-at-p "between")))
858 ;; Special case: in a list, when indenting, do not break structure.
861 (org-test-with-temp-text "- A <point>B"
864 ;; Special case: on tags part of a headline, add a newline below it
865 ;; instead of breaking it.
868 (org-test-with-temp-text "* H :<point>tag:"
872 (ert-deftest test-org
/meta-return
()
873 "Test M-RET (`org-meta-return') specifications."
874 ;; In a table field insert a row above.
876 (org-test-with-temp-text "| a |"
880 (looking-at "| |$")))
881 ;; In a paragraph change current line into a header.
883 (org-test-with-temp-text "a"
886 (looking-at "\* a$")))
887 ;; In an item insert an item, in this case above.
889 (org-test-with-temp-text "- a"
893 ;; In a drawer and item insert an item, in this case above.
895 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
899 (looking-at "- $"))))
901 (ert-deftest test-org
/insert-heading
()
902 "Test `org-insert-heading' specifications."
903 ;; FIXME: Test coverage is incomplete yet.
905 ;; In an empty buffer, insert a new headline.
908 (org-test-with-temp-text ""
911 ;; At the beginning of a line, turn it into a headline
914 (org-test-with-temp-text "<point>P"
917 ;; In the middle of a line, split the line if allowed, otherwise,
918 ;; insert the headline at its end.
920 (equal "Para\n* graph"
921 (org-test-with-temp-text "Para<point>graph"
922 (let ((org-M-RET-may-split-line '((default . t
))))
923 (org-insert-heading))
926 (equal "Paragraph\n* "
927 (org-test-with-temp-text "Para<point>graph"
928 (let ((org-M-RET-may-split-line '((default . nil
))))
929 (org-insert-heading))
931 ;; When on a list, insert an item instead, unless called with an
932 ;; universal argument or if list is invisible. In this case, create
933 ;; a new headline after contents.
935 (equal "* H\n- item\n- "
936 (org-test-with-temp-text "* H\n- item<point>"
937 (let ((org-insert-heading-respect-content nil
))
938 (org-insert-heading))
941 (equal "* H\n- item\n- item 2\n* "
942 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
943 (let ((org-insert-heading-respect-content nil
))
944 (org-insert-heading '(4)))
947 (equal "* H\n- item\n* "
948 (org-test-with-temp-text "* H\n- item"
950 (goto-char (point-max))
951 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
953 ;; When called with two universal arguments, insert a new headline
954 ;; at the end of the grandparent subtree.
956 (equal "* H1\n** H3\n- item\n** H2\n** "
957 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
958 (let ((org-insert-heading-respect-content nil
))
959 (org-insert-heading '(16)))
961 ;; Corner case: correctly insert a headline after an empty one.
964 (org-test-with-temp-text "* <point>"
968 (ert-deftest test-org
/insert-todo-heading-respect-content
()
969 "Test `org-insert-todo-heading-respect-content' specifications."
970 ;; Create a TODO heading.
972 (org-test-with-temp-text "* H1\n Body"
973 (org-insert-todo-heading-respect-content)
974 (nth 2 (org-heading-components))))
975 ;; Add headline at the end of the first subtree
977 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
978 (search-forward "H1Body")
979 (org-insert-todo-heading-respect-content)
980 (and (eobp) (org-at-heading-p))))
981 ;; In a list, do not create a new item.
983 (org-test-with-temp-text "* H\n- an item\n- another one"
984 (search-forward "an ")
985 (org-insert-todo-heading-respect-content)
986 (and (eobp) (org-at-heading-p)))))
990 ;;; Fixed-Width Areas
992 (ert-deftest test-org
/toggle-fixed-width
()
993 "Test `org-toggle-fixed-width' specifications."
994 ;; No region: Toggle on fixed-width marker in paragraphs.
997 (org-test-with-temp-text "A"
998 (org-toggle-fixed-width)
1000 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1003 (org-test-with-temp-text ": A"
1004 (org-toggle-fixed-width)
1006 ;; No region: Toggle on marker in blank lines after elements or just
1007 ;; after a headline.
1010 (org-test-with-temp-text "* H\n"
1012 (org-toggle-fixed-width)
1015 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1016 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1017 (goto-char (point-max))
1018 (org-toggle-fixed-width)
1020 ;; No region: Toggle on marker in front of one line elements (e.g.,
1021 ;; headlines, clocks)
1023 (equal ": * Headline"
1024 (org-test-with-temp-text "* Headline"
1025 (org-toggle-fixed-width)
1028 (equal ": #+KEYWORD: value"
1029 (org-test-with-temp-text "#+KEYWORD: value"
1030 (org-toggle-fixed-width)
1032 ;; No region: error in other situations.
1034 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1036 (org-toggle-fixed-width)
1038 ;; No region: Indentation is preserved.
1041 (org-test-with-temp-text "- A\n B"
1043 (org-toggle-fixed-width)
1045 ;; Region: If it contains only fixed-width elements and blank lines,
1046 ;; toggle off fixed-width markup.
1049 (org-test-with-temp-text ": A\n\n: B"
1050 (transient-mark-mode 1)
1051 (push-mark (point) t t
)
1052 (goto-char (point-max))
1053 (org-toggle-fixed-width)
1055 ;; Region: If it contains anything else, toggle on fixed-width but
1056 ;; not on fixed-width areas.
1058 (equal ": A\n: \n: B\n: \n: C"
1059 (org-test-with-temp-text "A\n\n: B\n\nC"
1060 (transient-mark-mode 1)
1061 (push-mark (point) t t
)
1062 (goto-char (point-max))
1063 (org-toggle-fixed-width)
1065 ;; Region: Ignore blank lines at its end, unless it contains only
1069 (org-test-with-temp-text "A\n\n"
1070 (transient-mark-mode 1)
1071 (push-mark (point) t t
)
1072 (goto-char (point-max))
1073 (org-toggle-fixed-width)
1077 (org-test-with-temp-text "\n\n"
1078 (transient-mark-mode 1)
1079 (push-mark (point) t t
)
1080 (goto-char (point-max))
1081 (org-toggle-fixed-width)
1088 (ert-deftest test-org
/in-commented-heading-p
()
1089 "Test `org-in-commented-heading-p' specifications."
1090 ;; Commented headline.
1092 (org-test-with-temp-text "* COMMENT Headline\nBody"
1093 (goto-char (point-max))
1094 (org-in-commented-heading-p)))
1095 ;; Commented ancestor.
1097 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1098 (goto-char (point-max))
1099 (org-in-commented-heading-p)))
1100 ;; Comment keyword is case-sensitive.
1102 (org-test-with-temp-text "* Comment Headline\nBody"
1103 (goto-char (point-max))
1104 (org-in-commented-heading-p)))
1105 ;; Keyword is standalone.
1107 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1108 (goto-char (point-max))
1109 (org-in-commented-heading-p)))
1110 ;; Optional argument.
1112 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1113 (goto-char (point-max))
1114 (org-in-commented-heading-p t
))))
1120 (ert-deftest test-org
/set-regexps-and-options
()
1121 "Test `org-set-regexps-and-options' specifications."
1124 (equal '(("A" . ?a
) ("B") ("C"))
1125 (org-test-with-temp-text "#+TAGS: A(a) B C"
1129 (equal '(("A") (:newline
) ("B"))
1130 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1134 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1135 (org-test-with-temp-text "#+TAGS: { A B } C"
1139 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1140 (org-test-with-temp-text "#+TAGS: { A : B C }"
1144 (equal '(("A" "B" "C"))
1145 (org-test-with-temp-text "#+TAGS: { A : B C }"
1147 org-tag-groups-alist
)))
1148 ;; FILETAGS keyword.
1150 (equal '("A" "B" "C")
1151 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1154 ;; PROPERTY keyword. Property names are case-insensitive.
1157 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1159 (cdr (assoc "var" org-file-properties
)))))
1163 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1165 (cdr (assoc "var" org-file-properties
)))))
1169 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1171 (cdr (assoc "var" org-file-properties
)))))
1175 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1177 org-archive-location
)))
1178 ;; CATEGORY keyword.
1181 (org-test-with-temp-text "#+CATEGORY: test"
1186 (org-test-with-temp-text "#+CATEGORY: test"
1188 (cdr (assoc "CATEGORY" org-file-properties
)))))
1191 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1192 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1194 org-columns-default-format
)))
1195 ;; CONSTANTS keyword. Constants names are case sensitive.
1197 (equal '("299792458." "3.14")
1198 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1201 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1205 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1207 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1210 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1212 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1217 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1219 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1221 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1225 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1227 (list org-highest-priority org-lowest-priority org-default-priority
))))
1231 (org-test-with-temp-text "#+PRIORITIES: X Z"
1233 (list org-highest-priority org-lowest-priority org-default-priority
))))
1237 (org-test-with-temp-text "#+STARTUP: fold odd"
1239 (list org-startup-folded org-odd-levels-only
))))
1242 (equal '(("A" "B") ("C"))
1243 (org-test-with-temp-text "#+TODO: A B | C"
1245 (list org-not-done-keywords org-done-keywords
))))
1247 (equal '(("A" "C") ("B" "D"))
1248 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1250 (list org-not-done-keywords org-done-keywords
))))
1252 (equal '(("A" "B") ("C"))
1253 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1255 (list org-not-done-keywords org-done-keywords
))))
1257 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1258 (org-test-with-temp-text "#+TODO: A(a)"
1260 org-todo-key-alist
)))
1262 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1263 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1265 org-todo-log-states
)))
1266 ;; Enter SETUPFILE keyword.
1269 (org-test-with-temp-text
1270 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1272 (cdr (assoc "a" org-file-properties
))))))
1280 (ert-deftest test-org
/coderef
()
1281 "Test coderef links specifications."
1283 (org-test-with-temp-text "
1284 #+BEGIN_SRC emacs-lisp
1288 (goto-char (point-max))
1290 (looking-at "(ref:sc)"))))
1294 (ert-deftest test-org
/custom-id
()
1295 "Test custom ID links specifications."
1297 (org-test-with-temp-text
1298 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1299 (goto-char (point-max))
1301 (org-looking-at-p "\\* H1"))))
1305 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1306 ;; a named element (#+name: text) and to headlines (* Text).
1308 (ert-deftest test-org
/fuzzy-links
()
1309 "Test fuzzy links specifications."
1310 ;; Fuzzy link goes in priority to a matching target.
1312 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1315 (looking-at "<<Test>>")))
1316 ;; Then fuzzy link points to an element with a given name.
1318 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1321 (looking-at "#\\+NAME: Test")))
1322 ;; A target still lead to a matching headline otherwise.
1324 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1327 (looking-at "\\* Head2")))
1328 ;; With a leading star in link, enforce heading match.
1330 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1333 (looking-at "\\* Test")))
1334 ;; Correctly un-hexify fuzzy links.
1336 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1337 (goto-char (point-max))
1343 (ert-deftest test-org
/org-link-escape-ascii-character
()
1344 "Escape an ascii character."
1348 (org-link-escape "["))))
1350 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1351 "Escape an ascii control character."
1355 (org-link-escape "\t"))))
1357 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1358 "Escape an unicode multibyte character."
1362 (org-link-escape "€"))))
1364 (ert-deftest test-org
/org-link-escape-custom-table
()
1365 "Escape string with custom character table."
1369 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1371 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1372 "Escape string with custom table merged with default table."
1375 "%5BF%6F%6F%3A%42ar%0A%5D"
1376 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1378 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1379 "Unescape an ascii character."
1383 (org-link-unescape "%5B"))))
1385 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1386 "Unescpae an ascii control character."
1390 (org-link-unescape "%0A"))))
1392 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1393 "Unescape unicode multibyte character."
1397 (org-link-unescape "%E2%82%AC"))))
1399 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1400 "Unescape old style percent escaped character."
1403 "à âçèéêîôùû"
1404 (decode-coding-string
1405 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1407 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1408 "Escape and unescape a URL that includes an escaped char.
1409 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1412 "http://some.host.com/form?&id=blah%2Bblah25"
1414 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1416 (ert-deftest test-org
/org-link-escape-chars-browser
()
1417 "Test of the constant `org-link-escape-chars-browser'.
1418 See there why this test is a candidate to be removed once Org
1419 drops support for Emacs 24.1 and 24.2."
1422 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1423 "%22Release%208.2%22&idxname=emacs-orgmode")
1424 (org-link-escape-browser ; Do not replace with `url-encode-url',
1425 ; see docstring above.
1426 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1427 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1431 (ert-deftest test-org
/open-at-point-in-property
()
1432 "Does `org-open-at-point' open link in property drawer?"
1434 (org-test-with-temp-text
1437 :URL: <point>[[info:emacs#Top]]
1439 (org-open-at-point) t
)))
1441 (ert-deftest test-org
/open-at-point-in-comment
()
1442 "Does `org-open-at-point' open link in a commented line?"
1444 (org-test-with-temp-text
1445 "# <point>[[info:emacs#Top]]"
1446 (org-open-at-point) t
)))
1448 (ert-deftest test-org
/open-at-point
/info
()
1449 "Test `org-open-at-point' on info links."
1451 (org-test-with-temp-text
1452 "<point>[[info:emacs#Top]]"
1454 (and (switch-to-buffer "*info*")
1456 (looking-at "\nThe Emacs Editor")
1459 (ert-deftest test-org
/open-at-point
/inline-image
()
1460 "Test `org-open-at-point' on nested links."
1462 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1464 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1465 (kill-buffer "*info*")))))
1470 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1471 "Ensure properties accumulate in subtree drawers."
1472 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1473 (org-babel-next-src-block)
1474 (should (equal '(2 1) (org-babel-execute-src-block)))))
1476 (ert-deftest test-org
/custom-properties
()
1477 "Test custom properties specifications."
1480 (let ((org-custom-properties '("FOO")))
1481 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1482 (org-toggle-custom-properties-visibility)
1483 (org-invisible-p2))))
1484 ;; Properties are case-insensitive.
1486 (let ((org-custom-properties '("FOO")))
1487 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1488 (org-toggle-custom-properties-visibility)
1489 (org-invisible-p2))))
1491 (let ((org-custom-properties '("foo")))
1492 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1493 (org-toggle-custom-properties-visibility)
1494 (org-invisible-p2))))
1495 ;; Multiple custom properties in the same drawer.
1497 (let ((org-custom-properties '("FOO" "BAR")))
1498 (org-test-with-temp-text
1499 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1500 (org-toggle-custom-properties-visibility)
1501 (and (org-invisible-p2)
1502 (not (progn (forward-line) (org-invisible-p2)))
1503 (progn (forward-line) (org-invisible-p2))))))
1504 ;; Hide custom properties with an empty value.
1506 (let ((org-custom-properties '("FOO")))
1507 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1508 (org-toggle-custom-properties-visibility)
1509 (org-invisible-p2))))
1510 ;; Do not hide fake properties.
1512 (let ((org-custom-properties '("FOO")))
1513 (org-test-with-temp-text ":FOO: val\n"
1514 (org-toggle-custom-properties-visibility)
1515 (org-invisible-p2))))
1517 (let ((org-custom-properties '("A")))
1518 (org-test-with-temp-text
1519 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1520 (org-toggle-custom-properties-visibility)
1521 (org-invisible-p2)))))
1527 (ert-deftest test-org
/mark-subtree
()
1528 "Test `org-mark-subtree' specifications."
1529 ;; Error when point is before first headline.
1531 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1532 (progn (transient-mark-mode 1)
1533 (org-mark-subtree))))
1534 ;; Without argument, mark current subtree.
1538 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1539 (progn (transient-mark-mode 1)
1542 (list (region-beginning) (region-end))))))
1543 ;; With an argument, move ARG up.
1547 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1548 (progn (transient-mark-mode 1)
1550 (org-mark-subtree 1)
1551 (list (region-beginning) (region-end))))))
1552 ;; Do not get fooled by inlinetasks.
1553 (when (featurep 'org-inlinetask
)
1556 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1557 (progn (transient-mark-mode 1)
1559 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1560 (region-beginning)))))))
1566 (ert-deftest test-org
/beginning-of-line
()
1567 "Test `org-beginning-of-line' specifications."
1570 (org-test-with-temp-text "Some text\nSome other text"
1571 (progn (org-beginning-of-line) (bolp))))
1572 ;; Standard test with `visual-line-mode'.
1574 (org-test-with-temp-text "A long line of text\nSome other text"
1575 (progn (visual-line-mode)
1577 (dotimes (i 1000) (insert "very "))
1578 (org-beginning-of-line)
1580 ;; At an headline with special movement.
1582 (org-test-with-temp-text "* TODO Headline"
1583 (let ((org-special-ctrl-a/e t
))
1585 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1586 (progn (org-beginning-of-line) (bolp))
1587 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1589 (ert-deftest test-org
/end-of-line
()
1590 "Test `org-end-of-line' specifications."
1593 (org-test-with-temp-text "Some text\nSome other text"
1594 (progn (org-end-of-line) (eolp))))
1595 ;; Standard test with `visual-line-mode'.
1597 (org-test-with-temp-text "A long line of text\nSome other text"
1598 (progn (visual-line-mode)
1600 (dotimes (i 1000) (insert "very "))
1601 (goto-char (point-min))
1604 ;; At an headline with special movement.
1606 (org-test-with-temp-text "* Headline1 :tag:\n"
1607 (let ((org-special-ctrl-a/e t
))
1608 (and (progn (org-end-of-line) (looking-at " :tag:"))
1609 (progn (org-end-of-line) (eolp))
1610 (progn (org-end-of-line) (looking-at " :tag:"))))))
1611 ;; At an headline without special movement.
1613 (org-test-with-temp-text "* Headline2 :tag:\n"
1614 (let ((org-special-ctrl-a/e nil
))
1615 (and (progn (org-end-of-line) (eolp))
1616 (progn (org-end-of-line) (eolp))))))
1617 ;; At an headline, with reversed movement.
1619 (org-test-with-temp-text "* Headline3 :tag:\n"
1620 (let ((org-special-ctrl-a/e
'reversed
)
1621 (this-command last-command
))
1622 (and (progn (org-end-of-line) (eolp))
1623 (progn (org-end-of-line) (looking-at " :tag:"))))))
1624 ;; At a block without hidden contents.
1626 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1627 (progn (org-end-of-line) (eolp))))
1628 ;; At a block with hidden contents.
1630 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1631 (let ((org-special-ctrl-a/e t
))
1632 (org-hide-block-toggle)
1636 (ert-deftest test-org
/forward-paragraph
()
1637 "Test `org-forward-paragraph' specifications."
1638 ;; At end of buffer, return an error.
1640 (org-test-with-temp-text "Paragraph"
1641 (goto-char (point-max))
1642 (org-forward-paragraph)))
1645 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1646 (org-forward-paragraph)
1650 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1651 (org-forward-paragraph)
1653 ;; Do not enter elements with invisible contents.
1655 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1656 (org-hide-block-toggle)
1657 (org-forward-paragraph)
1659 ;; On an affiliated keyword, jump to the beginning of the element.
1661 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1662 (org-forward-paragraph)
1663 (looking-at "Para")))
1664 ;; On an item or a footnote definition, move to the second element
1667 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1668 (org-forward-paragraph)
1669 (looking-at " Paragraph")))
1671 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1672 (org-forward-paragraph)
1673 (looking-at "Paragraph")))
1674 ;; On an item, or a footnote definition, when the first line is
1675 ;; empty, move to the first item.
1677 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1678 (org-forward-paragraph)
1679 (looking-at " Paragraph")))
1681 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1682 (org-forward-paragraph)
1683 (looking-at "Paragraph")))
1684 ;; On a table (resp. a property drawer) do not move through table
1685 ;; rows (resp. node properties).
1687 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1688 (org-forward-paragraph)
1689 (looking-at "Paragraph")))
1691 (org-test-with-temp-text
1692 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1693 (org-forward-paragraph)
1694 (looking-at "Paragraph")))
1695 ;; On a verse or source block, stop after blank lines.
1697 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1698 (org-forward-paragraph)
1701 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1702 (org-forward-paragraph)
1703 (looking-at "L2"))))
1705 (ert-deftest test-org
/backward-paragraph
()
1706 "Test `org-backward-paragraph' specifications."
1707 ;; Error at beginning of buffer.
1709 (org-test-with-temp-text "Paragraph"
1710 (org-backward-paragraph)))
1713 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1714 (goto-char (point-max))
1715 (org-backward-paragraph)
1718 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1719 (goto-char (point-max))
1721 (org-backward-paragraph)
1725 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1726 (goto-char (point-max))
1728 (org-backward-paragraph)
1730 ;; Ignore invisible elements.
1732 (org-test-with-temp-text "* H1\n P1\n* H2"
1734 (goto-char (point-max))
1736 (org-backward-paragraph)
1738 ;; On an affiliated keyword, jump to the first one.
1740 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1741 (search-forward "c2")
1742 (org-backward-paragraph)
1743 (looking-at "#\\+name")))
1744 ;; On the second element in an item or a footnote definition, jump
1745 ;; to item or the definition.
1747 (org-test-with-temp-text "- line1\n\n line2"
1748 (goto-char (point-max))
1750 (org-backward-paragraph)
1751 (looking-at "- line1")))
1753 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1754 (goto-char (point-max))
1756 (org-backward-paragraph)
1757 (looking-at "\\[fn:1\\] line1")))
1758 ;; On a table (resp. a property drawer), ignore table rows
1759 ;; (resp. node properties).
1761 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1762 (goto-char (point-max))
1764 (org-backward-paragraph)
1767 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1768 (org-backward-paragraph)
1769 (looking-at ":PROPERTIES:")))
1770 ;; On a source or verse block, stop before blank lines.
1772 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1773 (search-forward "L3")
1775 (org-backward-paragraph)
1778 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1779 (search-forward "L3")
1781 (org-backward-paragraph)
1782 (looking-at "L2"))))
1784 (ert-deftest test-org
/forward-element
()
1785 "Test `org-forward-element' specifications."
1786 ;; 1. At EOB: should error.
1787 (org-test-with-temp-text "Some text\n"
1788 (goto-char (point-max))
1789 (should-error (org-forward-element)))
1790 ;; 2. Standard move: expected to ignore blank lines.
1791 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1792 (org-forward-element)
1793 (should (looking-at (regexp-quote "Second paragraph."))))
1794 ;; 3. Headline tests.
1795 (org-test-with-temp-text "
1800 ;; 3.1. At an headline beginning: move to next headline at the
1803 (org-forward-element)
1804 (should (looking-at (regexp-quote "** Head 1.2")))
1805 ;; 3.2. At an headline beginning: move to parent headline if no
1806 ;; headline at the same level.
1808 (org-forward-element)
1809 (should (looking-at (regexp-quote "** Head 1.2"))))
1810 ;; 4. Greater element tests.
1811 (org-test-with-temp-text
1812 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1813 ;; 4.1. At a greater element: expected to skip contents.
1814 (org-forward-element)
1815 (should (looking-at (regexp-quote "Outside.")))
1816 ;; 4.2. At the end of greater element contents: expected to skip
1817 ;; to the end of the greater element.
1819 (org-forward-element)
1820 (should (looking-at (regexp-quote "Outside."))))
1822 (org-test-with-temp-text "
1836 ;; 5.1. At list top point: expected to move to the element after
1839 (org-forward-element)
1840 (should (looking-at (regexp-quote "Outside.")))
1841 ;; 5.2. Special case: at the first line of a sub-list, but not at
1842 ;; beginning of line, move to next item.
1845 (org-forward-element)
1846 (should (looking-at "- item2"))
1849 (org-forward-element)
1850 (should (looking-at " - sub2"))
1851 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1853 (org-forward-element)
1854 (should (looking-at (regexp-quote " Inner paragraph.")))
1855 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1857 (org-forward-element)
1858 (should (looking-at (regexp-quote " Inner paragraph.")))
1859 ;; 5.5. At an item: expected to move to next item, if any.
1861 (org-forward-element)
1862 (should (looking-at " - sub3"))))
1864 (ert-deftest test-org
/backward-element
()
1865 "Test `org-backward-element' specifications."
1866 ;; 1. Should error at BOB.
1867 (org-test-with-temp-text " \nParagraph."
1868 (should-error (org-backward-element)))
1869 ;; 2. Should move at BOB when called on the first element in buffer.
1871 (org-test-with-temp-text "\n#+TITLE: test"
1872 (progn (forward-line)
1873 (org-backward-element)
1875 ;; 3. Not at the beginning of an element: move at its beginning.
1876 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1879 (org-backward-element)
1880 (should (looking-at (regexp-quote "Paragraph2."))))
1881 ;; 4. Headline tests.
1882 (org-test-with-temp-text "
1887 ;; 4.1. At an headline beginning: move to previous headline at the
1890 (org-backward-element)
1891 (should (looking-at (regexp-quote "** Head 1.1")))
1892 ;; 4.2. At an headline beginning: move to parent headline if no
1893 ;; headline at the same level.
1895 (org-backward-element)
1896 (should (looking-at (regexp-quote "* Head 1")))
1897 ;; 4.3. At the first top-level headline: should error.
1899 (should-error (org-backward-element)))
1900 ;; 5. At beginning of first element inside a greater element:
1901 ;; expected to move to greater element's beginning.
1902 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1904 (org-backward-element)
1905 (should (looking-at "#\\+BEGIN_CENTER")))
1906 ;; 6. At the beginning of the first element in a section: should
1907 ;; move back to headline, if any.
1909 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1910 (progn (goto-char (point-max))
1912 (org-backward-element)
1913 (org-at-heading-p))))
1915 (org-test-with-temp-text "
1930 ;; 7.1. At beginning of sub-list: expected to move to the
1931 ;; paragraph before it.
1933 (org-backward-element)
1934 (should (looking-at "item1"))
1935 ;; 7.2. At an item in a list: expected to move at previous item.
1937 (org-backward-element)
1938 (should (looking-at " - sub2"))
1940 (org-backward-element)
1941 (should (looking-at "- item1"))
1942 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1945 (org-backward-element)
1946 (should (looking-at " - sub1"))
1948 (org-backward-element)
1949 (should (looking-at "- item1"))
1950 ;; 7.4. At blank-lines before list end: expected to move to top
1953 (org-backward-element)
1954 (should (looking-at "- item1"))))
1956 (ert-deftest test-org
/up-element
()
1957 "Test `org-up-element' specifications."
1958 ;; 1. At BOB or with no surrounding element: should error.
1959 (org-test-with-temp-text "Paragraph."
1960 (should-error (org-up-element)))
1961 (org-test-with-temp-text "* Head1\n* Head2"
1963 (should-error (org-up-element)))
1964 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1966 (should-error (org-up-element)))
1967 ;; 2. At an headline: move to parent headline.
1968 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1971 (should (looking-at "\\* Head1")))
1972 ;; 3. Inside a greater element: move to greater element beginning.
1973 (org-test-with-temp-text
1974 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1977 (should (looking-at "#\\+BEGIN_CENTER")))
1979 (org-test-with-temp-text "* Top
1986 Paragraph within sub2.
1989 ;; 4.1. Within an item: move to the item beginning.
1992 (should (looking-at " - sub2"))
1993 ;; 4.2. At an item in a sub-list: move to parent item.
1996 (should (looking-at "- item1"))
1997 ;; 4.3. At an item in top list: move to beginning of whole list.
2000 (should (looking-at "- item1"))
2001 ;; 4.4. Special case. At very top point: should move to parent of
2005 (should (looking-at "\\* Top"))))
2007 (ert-deftest test-org
/down-element
()
2008 "Test `org-down-element' specifications."
2009 ;; Error when the element hasn't got a recursive type.
2010 (org-test-with-temp-text "Paragraph."
2011 (should-error (org-down-element)))
2012 ;; Error when the element has no contents
2013 (org-test-with-temp-text "* Headline"
2014 (should-error (org-down-element)))
2015 ;; When at a plain-list, move to first item.
2016 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2019 (should (looking-at " - Item 1.1")))
2020 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2022 (should (looking-at " Item 1")))
2023 ;; When at a table, move to first row
2024 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2026 (should (looking-at " a | b |")))
2027 ;; Otherwise, move inside the greater element.
2028 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2030 (should (looking-at "Paragraph"))))
2032 (ert-deftest test-org
/drag-element-backward
()
2033 "Test `org-drag-element-backward' specifications."
2037 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2038 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2039 (org-drag-element-backward)
2043 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2044 (org-test-with-temp-text
2045 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2046 (org-drag-element-backward)
2048 ;; Preserve blank lines.
2050 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2051 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2052 (org-drag-element-backward)
2056 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2057 (org-drag-element-backward)
2058 (org-looking-at-p "2")))
2059 ;; Error when trying to move first element of buffer.
2061 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2062 (org-drag-element-backward)))
2063 ;; Error when trying to swap nested elements.
2065 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2067 (org-drag-element-backward)))
2068 ;; Error when trying to swap an headline element and a non-headline
2071 (org-test-with-temp-text "Test.\n* Head 1"
2073 (org-drag-element-backward)))
2074 ;; Preserve visibility of elements and their contents.
2076 (equal '((63 .
82) (26 .
48))
2077 (org-test-with-temp-text "
2085 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2086 (search-backward "- item 1")
2087 (org-drag-element-backward)
2088 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2089 (overlays-in (point-min) (point-max)))))))
2091 (ert-deftest test-org
/drag-element-forward
()
2092 "Test `org-drag-element-forward' specifications."
2093 ;; 1. Error when trying to move first element of buffer.
2094 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2096 (should-error (org-drag-element-forward)))
2097 ;; 2. Error when trying to swap nested elements.
2098 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2100 (should-error (org-drag-element-forward)))
2101 ;; 3. Error when trying to swap a non-headline element and an
2103 (org-test-with-temp-text "Test.\n* Head 1"
2104 (should-error (org-drag-element-forward)))
2105 ;; 4. Otherwise, swap elements, preserving column and blank lines
2106 ;; between elements.
2107 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2108 (search-forward "graph")
2109 (org-drag-element-forward)
2110 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2111 (should (looking-at " 1")))
2112 ;; 5. Preserve visibility of elements and their contents.
2113 (org-test-with-temp-text "
2121 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2122 (search-backward "#+BEGIN_CENTER")
2123 (org-drag-element-forward)
2126 '((63 .
82) (26 .
48))
2127 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2128 (overlays-in (point-min) (point-max)))))))
2131 ;;; Outline structure
2133 (ert-deftest test-org
/demote
()
2134 "Test `org-demote' specifications."
2135 ;; Add correct number of stars according to `org-odd-levels-only'.
2138 (org-test-with-temp-text "* H"
2139 (let ((org-odd-levels-only nil
)) (org-demote))
2140 (org-current-level))))
2143 (org-test-with-temp-text "* H"
2144 (let ((org-odd-levels-only t
)) (org-demote))
2145 (org-current-level))))
2146 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2148 (org-test-with-temp-text "* H :tag:"
2149 (let ((org-tags-column 10)
2150 (org-auto-align-tags t
)
2151 (org-odd-levels-only nil
))
2153 (org-move-to-column 10)
2154 (org-looking-at-p ":tag:$")))
2156 (org-test-with-temp-text "* H :tag:"
2157 (let ((org-tags-column 10)
2158 (org-auto-align-tags nil
)
2159 (org-odd-levels-only nil
))
2161 (org-move-to-column 10)
2162 (org-looking-at-p ":tag:$")))
2163 ;; When `org-adapt-indentation' is non-nil, always indent planning
2164 ;; info and property drawers accordingly.
2167 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2168 (let ((org-odd-levels-only nil
)
2169 (org-adapt-indentation t
))
2172 (org-get-indentation))))
2175 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2176 (let ((org-odd-levels-only nil
)
2177 (org-adapt-indentation t
))
2180 (org-get-indentation))))
2183 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2184 (let ((org-odd-levels-only nil
)
2185 (org-adapt-indentation nil
))
2188 (org-get-indentation))))
2189 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2190 ;; section accordingly. Ignore, however, footnote definitions and
2191 ;; inlinetasks boundaries.
2194 (org-test-with-temp-text "* H\n Paragraph"
2195 (let ((org-odd-levels-only nil
)
2196 (org-adapt-indentation t
))
2199 (org-get-indentation))))
2202 (org-test-with-temp-text "* H\n Paragraph"
2203 (let ((org-odd-levels-only nil
)
2204 (org-adapt-indentation nil
))
2207 (org-get-indentation))))
2210 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2211 (let ((org-odd-levels-only nil
)
2212 (org-adapt-indentation t
))
2214 (goto-char (point-max))
2215 (org-get-indentation))))
2218 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2219 (let ((org-odd-levels-only nil
)
2220 (org-adapt-indentation t
))
2222 (goto-char (point-max))
2223 (org-get-indentation))))
2224 (when (featurep 'org-inlinetask
)
2227 (let ((org-inlinetask-min-level 5)
2228 (org-adapt-indentation t
))
2229 (org-test-with-temp-text "* H\n***** I\n***** END"
2232 (org-get-indentation))))))
2233 (when (featurep 'org-inlinetask
)
2236 (let ((org-inlinetask-min-level 5)
2237 (org-adapt-indentation t
))
2238 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2241 (org-get-indentation))))))
2242 ;; Ignore contents of source blocks or example blocks when
2243 ;; indentation should be preserved (through
2244 ;; `org-src-preserve-indentation' or "-i" flag).
2247 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2248 (let ((org-adapt-indentation t
)
2249 (org-src-preserve-indentation nil
))
2252 (org-get-indentation))))
2255 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2256 (let ((org-adapt-indentation t
)
2257 (org-src-preserve-indentation t
))
2260 (org-get-indentation))))
2263 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2264 (let ((org-adapt-indentation t
)
2265 (org-src-preserve-indentation t
))
2268 (org-get-indentation))))
2271 (org-test-with-temp-text
2272 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2273 (let ((org-adapt-indentation t
)
2274 (org-src-preserve-indentation nil
))
2277 (org-get-indentation)))))
2279 (ert-deftest test-org
/promote
()
2280 "Test `org-promote' specifications."
2281 ;; Return an error if headline is to be promoted to level 0, unless
2282 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2283 ;; headline becomes a comment.
2285 (org-test-with-temp-text "* H"
2286 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2289 (org-test-with-temp-text "* H"
2290 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2292 ;; Remove correct number of stars according to
2293 ;; `org-odd-levels-only'.
2296 (org-test-with-temp-text "*** H"
2297 (let ((org-odd-levels-only nil
)) (org-promote))
2298 (org-current-level))))
2301 (org-test-with-temp-text "*** H"
2302 (let ((org-odd-levels-only t
)) (org-promote))
2303 (org-current-level))))
2304 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2306 (org-test-with-temp-text "** H :tag:"
2307 (let ((org-tags-column 10)
2308 (org-auto-align-tags t
)
2309 (org-odd-levels-only nil
))
2311 (org-move-to-column 10)
2312 (org-looking-at-p ":tag:$")))
2314 (org-test-with-temp-text "** H :tag:"
2315 (let ((org-tags-column 10)
2316 (org-auto-align-tags nil
)
2317 (org-odd-levels-only nil
))
2319 (org-move-to-column 10)
2320 (org-looking-at-p ":tag:$")))
2321 ;; When `org-adapt-indentation' is non-nil, always indent planning
2322 ;; info and property drawers.
2325 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2326 (let ((org-odd-levels-only nil
)
2327 (org-adapt-indentation t
))
2330 (org-get-indentation))))
2333 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2334 (let ((org-odd-levels-only nil
)
2335 (org-adapt-indentation t
))
2338 (org-get-indentation))))
2341 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2342 (let ((org-odd-levels-only nil
)
2343 (org-adapt-indentation nil
))
2346 (org-get-indentation))))
2347 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2348 ;; section accordingly. Ignore, however, footnote definitions and
2349 ;; inlinetasks boundaries.
2352 (org-test-with-temp-text "** H\n Paragraph"
2353 (let ((org-odd-levels-only nil
)
2354 (org-adapt-indentation t
))
2357 (org-get-indentation))))
2360 (org-test-with-temp-text "** H\n Paragraph"
2361 (let ((org-odd-levels-only nil
)
2362 (org-adapt-indentation nil
))
2365 (org-get-indentation))))
2368 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2369 (let ((org-odd-levels-only nil
)
2370 (org-adapt-indentation t
))
2373 (org-get-indentation))))
2374 (when (featurep 'org-inlinetask
)
2377 (let ((org-inlinetask-min-level 5)
2378 (org-adapt-indentation t
))
2379 (org-test-with-temp-text "** H\n***** I\n***** END"
2382 (org-get-indentation))))))
2383 (when (featurep 'org-inlinetask
)
2386 (let ((org-inlinetask-min-level 5)
2387 (org-adapt-indentation t
))
2388 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2391 (org-get-indentation))))))
2392 ;; Give up shifting if it would break document's structure
2396 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2397 (let ((org-odd-levels-only nil
)
2398 (org-adapt-indentation t
))
2401 (org-get-indentation))))
2404 (org-test-with-temp-text "** H\n Paragraph\n * list."
2405 (let ((org-odd-levels-only nil
)
2406 (org-adapt-indentation t
))
2409 (org-get-indentation))))
2410 ;; Ignore contents of source blocks or example blocks when
2411 ;; indentation should be preserved (through
2412 ;; `org-src-preserve-indentation' or "-i" flag).
2415 (org-test-with-temp-text
2416 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2417 (let ((org-adapt-indentation t
)
2418 (org-src-preserve-indentation nil
)
2419 (org-odd-levels-only nil
))
2422 (org-get-indentation))))
2425 (org-test-with-temp-text
2426 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2427 (let ((org-adapt-indentation t
)
2428 (org-src-preserve-indentation t
)
2429 (org-odd-levels-only nil
))
2432 (org-get-indentation))))
2435 (org-test-with-temp-text
2436 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2437 (let ((org-adapt-indentation t
)
2438 (org-src-preserve-indentation t
)
2439 (org-odd-levels-only nil
))
2442 (org-get-indentation))))
2445 (org-test-with-temp-text
2446 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2447 (let ((org-adapt-indentation t
)
2448 (org-src-preserve-indentation nil
)
2449 (org-odd-levels-only nil
))
2452 (org-get-indentation)))))
2457 (ert-deftest test-org
/at-planning-p
()
2458 "Test `org-at-planning-p' specifications."
2461 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2462 (org-at-planning-p)))
2464 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2465 (org-at-planning-p)))
2466 ;; Correctly find planning attached to inlinetasks.
2467 (when (featurep 'org-inlinetask
)
2469 (org-test-with-temp-text
2470 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2471 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2473 (org-test-with-temp-text
2474 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2475 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2477 (org-test-with-temp-text
2478 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2479 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2481 (org-test-with-temp-text
2482 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2483 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2488 (ert-deftest test-org
/buffer-property-keys
()
2489 "Test `org-buffer-property-keys' specifications."
2490 ;; Retrieve properties accross siblings.
2493 (org-test-with-temp-text "
2502 (org-buffer-property-keys))))
2503 ;; Retrieve properties accross children.
2506 (org-test-with-temp-text "
2515 (org-buffer-property-keys))))
2516 ;; Retrieve muliple properties in the same drawer.
2519 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2520 (org-buffer-property-keys))))
2521 ;; Ignore extension symbol in property name.
2524 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2525 (org-buffer-property-keys))))
2526 ;; With non-nil COLUMNS, extract property names from columns.
2529 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2530 (org-buffer-property-keys nil nil t
))))
2532 (equal '("A" "B" "COLUMNS")
2533 (org-test-with-temp-text
2534 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2535 (org-buffer-property-keys nil nil t
)))))
2537 (ert-deftest test-org
/property-values
()
2538 "Test `org-property-values' specifications."
2542 (org-test-with-temp-text
2543 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2544 (org-property-values "A"))))
2545 ;; Ignore empty values.
2547 (org-test-with-temp-text
2548 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2549 (org-property-values "A")))
2550 ;; Take into consideration extended values.
2553 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2554 (org-property-values "A")))))
2556 (ert-deftest test-org
/entry-delete
()
2557 "Test `org-entry-delete' specifications."
2561 " *:PROPERTIES:\n *:B: +2\n *:END:"
2562 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2563 (org-entry-delete (point) "A")
2565 ;; When last property is removed, remove the property drawer.
2569 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2570 (org-entry-delete (point) "A")
2573 (ert-deftest test-org
/entry-get
()
2574 "Test `org-entry-get' specifications."
2578 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2579 (org-entry-get (point) "A"))))
2583 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2584 (org-entry-get (point) "a"))))
2585 ;; Handle extended values, both before and after base value.
2588 (org-test-with-temp-text
2589 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2590 (org-entry-get (point) "A"))))
2591 ;; Empty values are returned as the empty string.
2594 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2595 (org-entry-get (point) "A"))))
2596 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2597 ;; otherwise, return nil.
2599 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2600 (org-entry-get (point) "A")))
2603 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2604 (org-entry-get (point) "A" nil t
))))
2605 ;; Return nil when no property is found, independently on the
2606 ;; LITERAL-NIL argument.
2608 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2609 (org-entry-get (point) "B")))
2611 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2612 (org-entry-get (point) "B" nil t
)))
2613 ;; Handle inheritance, when allowed.
2617 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2618 (org-entry-get (point) "A" t
))))
2622 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2623 (let ((org-use-property-inheritance t
))
2624 (org-entry-get (point) "A" 'selective
)))))
2626 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2627 (let ((org-use-property-inheritance nil
))
2628 (org-entry-get (point) "A" 'selective
)))))
2630 (ert-deftest test-org
/entry-properties
()
2631 "Test `org-entry-properties' specifications."
2632 ;; Get "ITEM" property.
2635 (org-test-with-temp-text "* TODO H"
2636 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
2639 (org-test-with-temp-text "* TODO H"
2640 (cdr (assoc "ITEM" (org-entry-properties))))))
2641 ;; Get "TODO" property.
2644 (org-test-with-temp-text "* TODO H"
2645 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
2648 (org-test-with-temp-text "* TODO H"
2649 (cdr (assoc "TODO" (org-entry-properties))))))
2651 (org-test-with-temp-text "* H"
2652 (assoc "TODO" (org-entry-properties nil
"TODO"))))
2653 ;; Get "PRIORITY" property.
2656 (org-test-with-temp-text "* [#A] H"
2657 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
2660 (org-test-with-temp-text "* [#A] H"
2661 (cdr (assoc "PRIORITY" (org-entry-properties))))))
2663 (org-test-with-temp-text "* H"
2664 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
2665 ;; Get "FILE" property.
2667 (org-test-with-temp-text-in-file "* H\nParagraph"
2668 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
2669 (buffer-file-name))))
2671 (org-test-with-temp-text-in-file "* H\nParagraph"
2672 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
2673 (buffer-file-name))))
2675 (org-test-with-temp-text "* H\nParagraph"
2676 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
2677 ;; Get "TAGS" property.
2679 (equal ":tag1:tag2:"
2680 (org-test-with-temp-text "* H :tag1:tag2:"
2681 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
2683 (equal ":tag1:tag2:"
2684 (org-test-with-temp-text "* H :tag1:tag2:"
2685 (cdr (assoc "TAGS" (org-entry-properties))))))
2687 (org-test-with-temp-text "* H"
2688 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
2689 ;; Get "ALLTAGS" property.
2691 (equal ":tag1:tag2:"
2692 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2693 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
2695 (equal ":tag1:tag2:"
2696 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2697 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
2699 (org-test-with-temp-text "* H"
2700 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
2701 ;; Get "BLOCKED" property.
2704 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2705 (let ((org-enforce-todo-dependencies t
)
2707 '(org-block-todo-from-children-or-siblings-or-parent)))
2708 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2711 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2712 (let ((org-enforce-todo-dependencies t
)
2714 '(org-block-todo-from-children-or-siblings-or-parent)))
2715 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
2718 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2719 (let ((org-enforce-todo-dependencies t
))
2720 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2721 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2725 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2726 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
2730 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2731 (cdr (assoc "CLOSED" (org-entry-properties))))))
2733 (org-test-with-temp-text "* H"
2734 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
2738 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2739 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
2743 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2744 (cdr (assoc "DEADLINE" (org-entry-properties))))))
2746 (org-test-with-temp-text "* H"
2747 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
2751 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2752 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
2756 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2757 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
2759 (org-test-with-temp-text "* H"
2760 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
2764 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2765 (cdr (assoc "CATEGORY" (org-entry-properties))))))
2768 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2769 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2772 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2773 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2774 ;; Get standard properties.
2777 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2778 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2779 ;; Handle extended properties.
2782 (org-test-with-temp-text
2783 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2784 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2787 (org-test-with-temp-text
2788 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2789 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2790 ;; Ignore forbidden (special) properties.
2792 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2793 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
2795 (ert-deftest test-org
/entry-put
()
2796 "Test `org-entry-put' specifications."
2797 ;; Error when not a string or nil.
2799 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2800 (org-entry-put 1 "test" 2)))
2801 ;; Set "TODO" property.
2803 (string-match (regexp-quote " TODO H")
2804 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2805 (org-entry-put (point) "TODO" "TODO")
2808 (string-match (regexp-quote "* H")
2809 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2810 (org-entry-put (point) "TODO" nil
)
2812 ;; Set "PRIORITY" property.
2815 (org-test-with-temp-text "* [#B] H"
2816 (org-entry-put (point) "PRIORITY" "A")
2820 (org-test-with-temp-text "* [#B] H"
2821 (org-entry-put (point) "PRIORITY" nil
)
2823 ;; Set "SCHEDULED" property.
2825 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2826 (org-test-with-temp-text "* H"
2827 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2831 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2832 (org-entry-put (point) "SCHEDULED" nil
)
2835 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
2836 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2837 (org-entry-put (point) "SCHEDULED" "earlier")
2840 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
2841 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2842 (org-entry-put (point) "SCHEDULED" "later")
2844 ;; Set "DEADLINE" property.
2846 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
2847 (org-test-with-temp-text "* H"
2848 (org-entry-put (point) "DEADLINE" "2014-03-04")
2852 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2853 (org-entry-put (point) "DEADLINE" nil
)
2856 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
2857 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2858 (org-entry-put (point) "DEADLINE" "earlier")
2861 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
2862 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2863 (org-entry-put (point) "DEADLINE" "later")
2865 ;; Regular properties, with or without pre-existing drawer.
2867 (string-match "^ *:A: +2$"
2868 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2869 (org-entry-put (point) "A" "2")
2872 (string-match "^ *:A: +1$"
2873 (org-test-with-temp-text "* H"
2874 (org-entry-put (point) "A" "1")
2876 ;; Special case: two consecutive headlines.
2878 (string-match "\\* A\n *:PROPERTIES:"
2879 (org-test-with-temp-text "* A\n** B"
2880 (org-entry-put (point) "A" "1")
2886 (ert-deftest test-org
/update-radio-target-regexp
()
2887 "Test `org-update-radio-target-regexp' specifications."
2888 ;; Properly update cache with no previous radio target regexp.
2891 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2892 (save-excursion (goto-char (point-max)) (org-element-context))
2894 (search-forward "o")
2896 (org-update-radio-target-regexp)
2897 (goto-char (point-max))
2898 (org-element-type (org-element-context)))))
2899 ;; Properly update cache with previous radio target regexp.
2902 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2903 (save-excursion (goto-char (point-max)) (org-element-context))
2905 (search-forward "o")
2907 (org-update-radio-target-regexp)
2908 (search-backward "r")
2911 (org-update-radio-target-regexp)
2912 (goto-char (point-max))
2913 (delete-region (line-beginning-position) (point))
2915 (org-element-type (org-element-context))))))
2920 (ert-deftest test-org
/match-sparse-tree
()
2921 "Test `org-match-sparse-tree' specifications."
2924 (org-test-with-temp-text "* H\n** H1 :tag:"
2925 (org-match-sparse-tree nil
"tag")
2926 (search-forward "H1")
2927 (org-invisible-p2)))
2929 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
2930 (org-match-sparse-tree nil
"tag")
2931 (search-forward "H2")
2932 (org-invisible-p2)))
2933 ;; "-" operator for tags.
2935 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2936 (org-match-sparse-tree nil
"tag1-tag2")
2937 (search-forward "H1")
2938 (org-invisible-p2)))
2940 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2941 (org-match-sparse-tree nil
"tag1-tag2")
2942 (search-forward "H2")
2943 (org-invisible-p2)))
2944 ;; "&" operator for tags.
2946 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2947 (org-match-sparse-tree nil
"tag1&tag2")
2948 (search-forward "H1")
2949 (org-invisible-p2)))
2951 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2952 (org-match-sparse-tree nil
"tag1&tag2")
2953 (search-forward "H2")
2954 (org-invisible-p2)))
2955 ;; "|" operator for tags.
2957 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2958 (org-match-sparse-tree nil
"tag1|tag2")
2959 (search-forward "H1")
2960 (org-invisible-p2)))
2962 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
2963 (org-match-sparse-tree nil
"tag1|tag2")
2964 (search-forward "H2")
2965 (org-invisible-p2)))
2966 ;; Regexp match on tags.
2968 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
2969 (org-match-sparse-tree nil
"{^tag.*}")
2970 (search-forward "H1")
2971 (org-invisible-p2)))
2973 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
2974 (org-match-sparse-tree nil
"{^tag.*}")
2975 (search-forward "H2")
2976 (org-invisible-p2)))
2977 ;; Match group tags.
2979 (org-test-with-temp-text
2980 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
2981 (org-match-sparse-tree nil
"work")
2982 (search-forward "H1")
2983 (org-invisible-p2)))
2985 (org-test-with-temp-text
2986 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
2987 (org-match-sparse-tree nil
"work")
2988 (search-forward "H2")
2989 (org-invisible-p2)))
2990 ;; Match properties.
2992 (org-test-with-temp-text
2993 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
2994 (org-match-sparse-tree nil
"A=\"1\"")
2995 (search-forward "H2")
2996 (org-invisible-p2)))
2998 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
2999 (org-match-sparse-tree nil
"A=\"1\"")
3000 (search-forward "H2")
3001 (org-invisible-p2)))
3002 ;; Case is not significant when matching properties.
3004 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3005 (org-match-sparse-tree nil
"a=\"1\"")
3006 (search-forward "H2")
3007 (org-invisible-p2)))
3009 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3010 (org-match-sparse-tree nil
"A=\"1\"")
3011 (search-forward "H2")
3012 (org-invisible-p2)))
3013 ;; Match special LEVEL property.
3015 (org-test-with-temp-text "* H\n** H1\n*** H2"
3016 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3017 (search-forward "H1")
3018 (org-invisible-p2)))
3020 (org-test-with-temp-text "* H\n** H1\n*** H2"
3021 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3022 (search-forward "H2")
3023 (org-invisible-p2)))
3024 ;; Comparison operators when matching properties.
3026 (org-test-with-temp-text
3027 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3028 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3029 (search-forward "H1")
3030 (org-invisible-p2)))
3032 (org-test-with-temp-text
3033 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3034 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3035 (search-forward "H2")
3036 (org-invisible-p2)))
3037 ;; Regexp match on properties values.
3039 (org-test-with-temp-text
3040 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3041 (org-match-sparse-tree nil
"A={f.*}")
3042 (search-forward "H1")
3043 (org-invisible-p2)))
3045 (org-test-with-temp-text
3046 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3047 (org-match-sparse-tree nil
"A={f.*}")
3048 (search-forward "H2")
3049 (org-invisible-p2)))
3050 ;; With an optional argument, limit match to TODO entries.
3052 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3053 (org-match-sparse-tree t
"tag")
3054 (search-forward "H1")
3055 (org-invisible-p2)))
3057 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3058 (org-match-sparse-tree t
"tag")
3059 (search-forward "H2")
3060 (org-invisible-p2))))
3065 (ert-deftest test-org
/timestamp-has-time-p
()
3066 "Test `org-timestamp-has-time-p' specifications."
3069 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3070 (org-timestamp-has-time-p (org-element-context))))
3073 (org-test-with-temp-text "<2012-03-29 Thu>"
3074 (org-timestamp-has-time-p (org-element-context)))))
3076 (ert-deftest test-org
/timestamp-format
()
3077 "Test `org-timestamp-format' specifications."
3082 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3083 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3088 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3089 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3091 (ert-deftest test-org
/timestamp-split-range
()
3092 "Test `org-timestamp-split-range' specifications."
3093 ;; Extract range start (active).
3096 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3097 (let ((ts (org-timestamp-split-range (org-element-context))))
3098 (mapcar (lambda (p) (org-element-property p ts
))
3099 '(:year-end
:month-end
:day-end
))))))
3100 ;; Extract range start (inactive)
3103 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3104 (let ((ts (org-timestamp-split-range (org-element-context))))
3105 (mapcar (lambda (p) (org-element-property p ts
))
3106 '(:year-end
:month-end
:day-end
))))))
3107 ;; Extract range end (active).
3110 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3111 (let ((ts (org-timestamp-split-range
3112 (org-element-context) t
)))
3113 (mapcar (lambda (p) (org-element-property p ts
))
3114 '(:year-end
:month-end
:day-end
))))))
3115 ;; Extract range end (inactive)
3118 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3119 (let ((ts (org-timestamp-split-range
3120 (org-element-context) t
)))
3121 (mapcar (lambda (p) (org-element-property p ts
))
3122 '(:year-end
:month-end
:day-end
))))))
3123 ;; Return the timestamp if not a range.
3125 (org-test-with-temp-text "[2012-03-29 Thu]"
3126 (let* ((ts-orig (org-element-context))
3127 (ts-copy (org-timestamp-split-range ts-orig
)))
3128 (eq ts-orig ts-copy
))))
3130 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3131 (let* ((ts-orig (org-element-context))
3132 (ts-copy (org-timestamp-split-range ts-orig
)))
3133 (eq ts-orig ts-copy
))))
3134 ;; Check that parent is the same when a range was split.
3136 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3137 (let* ((ts-orig (org-element-context))
3138 (ts-copy (org-timestamp-split-range ts-orig
)))
3139 (eq (org-element-property :parent ts-orig
)
3140 (org-element-property :parent ts-copy
))))))
3142 (ert-deftest test-org
/timestamp-translate
()
3143 "Test `org-timestamp-translate' specifications."
3144 ;; Translate whole date range.
3147 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3148 (let ((org-display-custom-times t
)
3149 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3150 (org-timestamp-translate (org-element-context))))))
3151 ;; Translate date range start.
3154 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3155 (let ((org-display-custom-times t
)
3156 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3157 (org-timestamp-translate (org-element-context) 'start
)))))
3158 ;; Translate date range end.
3161 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3162 (let ((org-display-custom-times t
)
3163 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3164 (org-timestamp-translate (org-element-context) 'end
)))))
3165 ;; Translate time range.
3168 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3169 (let ((org-display-custom-times t
)
3170 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3171 (org-timestamp-translate (org-element-context))))))
3172 ;; Translate non-range timestamp.
3175 (org-test-with-temp-text "<2012-03-29 Thu>"
3176 (let ((org-display-custom-times t
)
3177 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3178 (org-timestamp-translate (org-element-context))))))
3179 ;; Do not change `diary' timestamps.
3181 (equal "<%%(org-float t 4 2)>"
3182 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3183 (let ((org-display-custom-times t
)
3184 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3185 (org-timestamp-translate (org-element-context)))))))
3191 (ert-deftest test-org
/flag-drawer
()
3192 "Test `org-flag-drawer' specifications."
3195 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3197 (get-char-property (line-end-position) 'invisible
)))
3200 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3202 (org-flag-drawer nil
)
3203 (get-char-property (line-end-position) 'invisible
)))
3204 ;; Test optional argument.
3206 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3207 (let ((drawer (save-excursion (search-forward ":D2")
3208 (org-element-at-point))))
3209 (org-flag-drawer t drawer
)
3210 (get-char-property (progn (search-forward ":D2") (line-end-position))
3213 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3214 (let ((drawer (save-excursion (search-forward ":D2")
3215 (org-element-at-point))))
3216 (org-flag-drawer t drawer
)
3217 (get-char-property (line-end-position) 'invisible
))))
3218 ;; Do not hide fake drawers.
3220 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3223 (get-char-property (line-end-position) 'invisible
)))
3224 ;; Do not hide incomplete drawers.
3226 (org-test-with-temp-text ":D:\nparagraph"
3229 (get-char-property (line-end-position) 'invisible
)))
3230 ;; Do not hide drawers when called from final blank lines.
3232 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3233 (goto-char (point-max))
3235 (goto-char (point-min))
3236 (get-char-property (line-end-position) 'invisible
)))
3237 ;; Don't leave point in an invisible part of the buffer when hiding
3240 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3241 (goto-char (point-max))
3243 (get-char-property (point) 'invisible
))))
3245 (ert-deftest test-org
/hide-block-toggle
()
3246 "Test `org-hide-block-toggle' specifications."
3247 ;; Error when not at a block.
3249 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3250 (org-hide-block-toggle 'off
)
3251 (get-char-property (line-end-position) 'invisible
)))
3254 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3255 (org-hide-block-toggle)
3256 (get-char-property (line-end-position) 'invisible
)))
3258 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3259 (org-hide-block-toggle)
3260 (get-char-property (line-end-position) 'invisible
)))
3261 ;; Show block unconditionally when optional argument is `off'.
3263 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3264 (org-hide-block-toggle)
3265 (org-hide-block-toggle 'off
)
3266 (get-char-property (line-end-position) 'invisible
)))
3268 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3269 (org-hide-block-toggle 'off
)
3270 (get-char-property (line-end-position) 'invisible
)))
3271 ;; Hide block unconditionally when optional argument is non-nil.
3273 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3274 (org-hide-block-toggle t
)
3275 (get-char-property (line-end-position) 'invisible
)))
3277 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3278 (org-hide-block-toggle)
3279 (org-hide-block-toggle t
)
3280 (get-char-property (line-end-position) 'invisible
)))
3281 ;; Do not hide block when called from final blank lines.
3283 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3284 (org-hide-block-toggle)
3285 (goto-char (point-min))
3286 (get-char-property (line-end-position) 'invisible
)))
3287 ;; Don't leave point in an invisible part of the buffer when hiding
3290 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3291 (org-hide-block-toggle)
3292 (get-char-property (point) 'invisible
))))
3294 (ert-deftest test-org
/hide-block-toggle-maybe
()
3295 "Test `org-hide-block-toggle-maybe' specifications."
3297 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3298 (org-hide-block-toggle-maybe)))
3300 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3305 ;;; test-org.el ends here