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>>")))
918 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
919 (let ((org-return-follows-link t
)
920 (org-link-search-must-match-exact-headline nil
))
922 (org-looking-at-p "<<target>>")))
923 ;; When `org-return-follows-link' is non-nil, tolerate links and
924 ;; timestamps in comments, node properties, etc.
926 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
927 (let ((org-return-follows-link t
)
928 (org-link-search-must-match-exact-headline nil
))
930 (org-looking-at-p "<<target>>")))
932 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
933 (let ((org-return-follows-link nil
)) (org-return))
934 (org-looking-at-p "<<target>>")))
936 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
937 (let ((org-return-follows-link t
)
938 (org-link-search-must-match-exact-headline nil
))
940 (org-looking-at-p "<<target>>")))
941 ;; However, do not open link when point is in a table.
943 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
944 (let ((org-return-follows-link t
)) (org-return))
945 (org-looking-at-p "between")))
946 ;; Special case: in a list, when indenting, do not break structure.
949 (org-test-with-temp-text "- A <point>B"
954 (org-test-with-temp-text "- A\n<point>- B"
957 ;; On tags part of a headline, add a newline below it instead of
961 (org-test-with-temp-text "* H :<point>tag:"
964 ;; Before headline text, add a newline below it instead of breaking
967 (equal "* TODO H :tag:\n"
968 (org-test-with-temp-text "* <point>TODO H :tag:"
972 (equal "* TODO [#B] H :tag:\n"
973 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
976 ;; At headline text, break headline text but preserve tags.
978 (equal "* TODO [#B] foo :tag:\nbar"
979 (let (org-auto-align-tags)
980 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
983 ;; At bol of headline insert newline.
986 (org-test-with-temp-text "<point>* h"
989 ;; Refuse to leave invalid headline in buffer.
992 (org-test-with-temp-text "*<point> h"
996 (ert-deftest test-org
/meta-return
()
997 "Test M-RET (`org-meta-return') specifications."
998 ;; In a table field insert a row above.
1000 (org-test-with-temp-text "| a |"
1004 (looking-at "| |$")))
1005 ;; In a paragraph change current line into a header.
1007 (org-test-with-temp-text "a"
1010 (looking-at "\* a$")))
1011 ;; In an item insert an item, in this case above.
1013 (org-test-with-temp-text "- a"
1016 (looking-at "- $")))
1017 ;; In a drawer and item insert an item, in this case above.
1019 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1023 (looking-at "- $"))))
1025 (ert-deftest test-org
/insert-heading
()
1026 "Test `org-insert-heading' specifications."
1027 ;; In an empty buffer, insert a new headline.
1030 (org-test-with-temp-text ""
1031 (org-insert-heading)
1033 ;; At the beginning of a line, turn it into a headline
1036 (org-test-with-temp-text "<point>P"
1037 (org-insert-heading)
1039 ;; In the middle of a line, split the line if allowed, otherwise,
1040 ;; insert the headline at its end.
1042 (equal "Para\n* graph"
1043 (org-test-with-temp-text "Para<point>graph"
1044 (let ((org-M-RET-may-split-line '((default . t
))))
1045 (org-insert-heading))
1048 (equal "Paragraph\n* "
1049 (org-test-with-temp-text "Para<point>graph"
1050 (let ((org-M-RET-may-split-line '((default . nil
))))
1051 (org-insert-heading))
1053 ;; When on a list, insert an item instead, unless called with an
1054 ;; universal argument or if list is invisible. In this case, create
1055 ;; a new headline after contents.
1057 (equal "* H\n- item\n- "
1058 (org-test-with-temp-text "* H\n- item<point>"
1059 (let ((org-insert-heading-respect-content nil
))
1060 (org-insert-heading))
1063 (equal "* H\n- item\n- item 2\n* "
1064 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1065 (let ((org-insert-heading-respect-content nil
))
1066 (org-insert-heading '(4)))
1069 (equal "* H\n- item\n* "
1070 (org-test-with-temp-text "* H\n- item"
1072 (goto-char (point-max))
1073 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1075 ;; When called with two universal arguments, insert a new headline
1076 ;; at the end of the grandparent subtree.
1078 (equal "* H1\n** H3\n- item\n** H2\n** "
1079 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1080 (let ((org-insert-heading-respect-content nil
))
1081 (org-insert-heading '(16)))
1083 ;; When optional TOP-LEVEL argument is non-nil, always insert
1084 ;; a level 1 heading.
1086 (equal "* H1\n** H2\n* "
1087 (org-test-with-temp-text "* H1\n** H2<point>"
1088 (org-insert-heading nil nil t
)
1091 (equal "* H1\n- item\n* "
1092 (org-test-with-temp-text "* H1\n- item<point>"
1093 (org-insert-heading nil nil t
)
1095 ;; Corner case: correctly insert a headline after an empty one.
1098 (org-test-with-temp-text "* <point>"
1099 (org-insert-heading)
1102 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1103 "Test `org-insert-todo-heading-respect-content' specifications."
1104 ;; Create a TODO heading.
1106 (org-test-with-temp-text "* H1\n Body"
1107 (org-insert-todo-heading-respect-content)
1108 (nth 2 (org-heading-components))))
1109 ;; Add headline at the end of the first subtree
1111 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1112 (search-forward "H1Body")
1113 (org-insert-todo-heading-respect-content)
1114 (and (eobp) (org-at-heading-p))))
1115 ;; In a list, do not create a new item.
1117 (org-test-with-temp-text "* H\n- an item\n- another one"
1118 (search-forward "an ")
1119 (org-insert-todo-heading-respect-content)
1120 (and (eobp) (org-at-heading-p)))))
1122 (ert-deftest test-org
/clone-with-time-shift
()
1123 "Test `org-clone-subtree-with-time-shift'."
1124 ;; Clone non-repeating once.
1130 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1131 (org-clone-subtree-with-time-shift 1 "+2d")
1132 (replace-regexp-in-string
1133 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1135 ;; Clone repeating once.
1140 * H1\n<2015-06-25 +1w>
1142 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1143 (org-clone-subtree-with-time-shift 1 "+2d")
1144 (replace-regexp-in-string
1145 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1147 ;; Clone non-repeating zero times.
1152 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1153 (org-clone-subtree-with-time-shift 0 "+2d")
1154 (replace-regexp-in-string
1155 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1157 ;; Clone repeating "zero" times.
1161 * H1\n<2015-06-23 +1w>
1163 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1164 (org-clone-subtree-with-time-shift 0 "+2d")
1165 (replace-regexp-in-string
1166 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1170 ;;; Fixed-Width Areas
1172 (ert-deftest test-org
/toggle-fixed-width
()
1173 "Test `org-toggle-fixed-width' specifications."
1174 ;; No region: Toggle on fixed-width marker in paragraphs.
1177 (org-test-with-temp-text "A"
1178 (org-toggle-fixed-width)
1180 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1183 (org-test-with-temp-text ": A"
1184 (org-toggle-fixed-width)
1186 ;; No region: Toggle on marker in blank lines after elements or just
1187 ;; after a headline.
1190 (org-test-with-temp-text "* H\n"
1192 (org-toggle-fixed-width)
1195 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1196 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1197 (goto-char (point-max))
1198 (org-toggle-fixed-width)
1200 ;; No region: Toggle on marker in front of one line elements (e.g.,
1201 ;; headlines, clocks)
1203 (equal ": * Headline"
1204 (org-test-with-temp-text "* Headline"
1205 (org-toggle-fixed-width)
1208 (equal ": #+KEYWORD: value"
1209 (org-test-with-temp-text "#+KEYWORD: value"
1210 (org-toggle-fixed-width)
1212 ;; No region: error in other situations.
1214 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1216 (org-toggle-fixed-width)
1218 ;; No region: Indentation is preserved.
1221 (org-test-with-temp-text "- A\n B"
1223 (org-toggle-fixed-width)
1225 ;; Region: If it contains only fixed-width elements and blank lines,
1226 ;; toggle off fixed-width markup.
1229 (org-test-with-temp-text ": A\n\n: B"
1230 (transient-mark-mode 1)
1231 (push-mark (point) t t
)
1232 (goto-char (point-max))
1233 (org-toggle-fixed-width)
1235 ;; Region: If it contains anything else, toggle on fixed-width but
1236 ;; not on fixed-width areas.
1238 (equal ": A\n: \n: B\n: \n: C"
1239 (org-test-with-temp-text "A\n\n: B\n\nC"
1240 (transient-mark-mode 1)
1241 (push-mark (point) t t
)
1242 (goto-char (point-max))
1243 (org-toggle-fixed-width)
1245 ;; Region: Ignore blank lines at its end, unless it contains only
1249 (org-test-with-temp-text "A\n\n"
1250 (transient-mark-mode 1)
1251 (push-mark (point) t t
)
1252 (goto-char (point-max))
1253 (org-toggle-fixed-width)
1257 (org-test-with-temp-text "\n\n"
1258 (transient-mark-mode 1)
1259 (push-mark (point) t t
)
1260 (goto-char (point-max))
1261 (org-toggle-fixed-width)
1268 (ert-deftest test-org
/get-heading
()
1269 "Test `org-get-heading' specifications."
1270 ;; Return current heading, even if point is not on it.
1273 (org-test-with-temp-text "* H"
1274 (org-get-heading))))
1277 (org-test-with-temp-text "* H\nText<point>"
1278 (org-get-heading))))
1279 ;; Without any optional argument, return TODO keywords and tags.
1282 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1283 (org-get-heading))))
1286 (org-test-with-temp-text "* H :tag:"
1287 (org-get-heading))))
1288 ;; With NO-TAGS argument, ignore tags.
1291 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1292 (org-get-heading t
))))
1295 (org-test-with-temp-text "* H :tag:"
1296 (org-get-heading t
))))
1297 ;; With NO-TODO, ignore TODO keyword.
1300 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1301 (org-get-heading nil t
))))
1304 (org-test-with-temp-text "* H :tag:"
1305 (org-get-heading nil t
))))
1306 ;; TODO keywords are case-sensitive.
1309 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1310 (org-get-heading nil t
)))))
1312 (ert-deftest test-org
/in-commented-heading-p
()
1313 "Test `org-in-commented-heading-p' specifications."
1314 ;; Commented headline.
1316 (org-test-with-temp-text "* COMMENT Headline\nBody"
1317 (goto-char (point-max))
1318 (org-in-commented-heading-p)))
1319 ;; Commented ancestor.
1321 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1322 (goto-char (point-max))
1323 (org-in-commented-heading-p)))
1324 ;; Comment keyword is case-sensitive.
1326 (org-test-with-temp-text "* Comment Headline\nBody"
1327 (goto-char (point-max))
1328 (org-in-commented-heading-p)))
1329 ;; Keyword is standalone.
1331 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1332 (goto-char (point-max))
1333 (org-in-commented-heading-p)))
1334 ;; Optional argument.
1336 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1337 (goto-char (point-max))
1338 (org-in-commented-heading-p t
))))
1340 (ert-deftest test-org
/entry-blocked-p
()
1341 ;; Check other dependencies.
1343 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1344 (let ((org-enforce-todo-dependencies t
)
1346 '(org-block-todo-from-children-or-siblings-or-parent)))
1347 (org-entry-blocked-p))))
1349 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1350 (let ((org-enforce-todo-dependencies t
)
1352 '(org-block-todo-from-children-or-siblings-or-parent)))
1353 (org-entry-blocked-p))))
1354 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1357 (org-test-with-temp-text "* Blocked\n** TODO one"
1358 (let ((org-enforce-todo-dependencies t
)
1360 '(org-block-todo-from-children-or-siblings-or-parent)))
1361 (org-entry-blocked-p))))
1363 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1364 (let ((org-enforce-todo-dependencies t
)
1366 '(org-block-todo-from-children-or-siblings-or-parent)))
1367 (org-entry-blocked-p))))
1368 ;; Follow :ORDERED: specifications.
1370 (org-test-with-temp-text
1371 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1372 (let ((org-enforce-todo-dependencies t
)
1374 '(org-block-todo-from-children-or-siblings-or-parent)))
1375 (org-entry-blocked-p))))
1377 (org-test-with-temp-text
1378 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1379 (let ((org-enforce-todo-dependencies t
)
1381 '(org-block-todo-from-children-or-siblings-or-parent)))
1382 (org-entry-blocked-p)))))
1384 (ert-deftest test-org
/get-outline-path
()
1385 "Test `org-get-outline-path' specifications."
1386 ;; Top-level headlines have no outline path.
1388 (org-test-with-temp-text "* H"
1389 (org-get-outline-path)))
1390 ;; Otherwise, outline path is the path leading to the headline.
1393 (org-test-with-temp-text "* H\n** S<point>"
1394 (org-get-outline-path))))
1395 ;; Find path even when point is not on a headline.
1398 (org-test-with-temp-text "* H\n** S\nText<point>"
1399 (org-get-outline-path))))
1400 ;; TODO keywords, tags and statistics cookies are ignored.
1403 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1404 (org-get-outline-path))))
1405 ;; Links are replaced with their description or their path.
1408 (org-test-with-temp-text
1409 "* [[http://orgmode.org][Org]]\n** S<point>"
1410 (org-get-outline-path))))
1412 (equal '("http://orgmode.org")
1413 (org-test-with-temp-text
1414 "* [[http://orgmode.org]]\n** S<point>"
1415 (org-get-outline-path))))
1416 ;; When WITH-SELF is non-nil, include current heading.
1419 (org-test-with-temp-text "* H"
1420 (org-get-outline-path t
))))
1423 (org-test-with-temp-text "* H\n** S\nText<point>"
1424 (org-get-outline-path t
))))
1425 ;; Using cache is transparent to the user.
1428 (org-test-with-temp-text "* H\n** S<point>"
1429 (setq org-outline-path-cache nil
)
1430 (org-get-outline-path nil t
))))
1431 ;; Do not corrupt cache when finding outline path in distant part of
1435 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1436 (setq org-outline-path-cache nil
)
1437 (org-get-outline-path nil t
)
1438 (search-forward "S2")
1439 (org-get-outline-path nil t
))))
1440 ;; Do not choke on empty headlines.
1442 (org-test-with-temp-text "* H\n** <point>"
1443 (org-get-outline-path)))
1445 (org-test-with-temp-text "* \n** H<point>"
1446 (org-get-outline-path))))
1448 (ert-deftest test-org
/format-outline-path
()
1449 "Test `org-format-outline-path' specifications."
1451 (string= (org-format-outline-path (list "one" "two" "three"))
1455 (string= (org-format-outline-path '())
1458 (string= (org-format-outline-path '(nil))
1460 ;; Empty path and prefix.
1462 (string= (org-format-outline-path '() nil
">>")
1464 ;; Trailing whitespace in headings.
1466 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1468 ;; Non-default prefix and separators.
1470 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1471 ">>|one|two|three"))
1474 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1476 ;; Give a very narrow width.
1478 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1480 ;; Give a prefix that extends beyond the width.
1482 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1489 (ert-deftest test-org
/set-regexps-and-options
()
1490 "Test `org-set-regexps-and-options' specifications."
1493 (equal '(("A" . ?a
) ("B") ("C"))
1494 (org-test-with-temp-text "#+TAGS: A(a) B C"
1498 (equal '(("A") (:newline
) ("B"))
1499 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1503 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1504 (org-test-with-temp-text "#+TAGS: { A B } C"
1508 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1509 (org-test-with-temp-text "#+TAGS: { A : B C }"
1513 (equal '(("A" "B" "C"))
1514 (org-test-with-temp-text "#+TAGS: { A : B C }"
1516 org-tag-groups-alist
)))
1518 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1519 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1523 (equal '(("A" "B" "C"))
1524 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1526 org-tag-groups-alist
)))
1527 ;; FILETAGS keyword.
1529 (equal '("A" "B" "C")
1530 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1533 ;; PROPERTY keyword. Property names are case-insensitive.
1536 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1538 (cdr (assoc "var" org-file-properties
)))))
1542 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1544 (cdr (assoc "var" org-file-properties
)))))
1548 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1550 (cdr (assoc "var" org-file-properties
)))))
1554 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1556 org-archive-location
)))
1557 ;; CATEGORY keyword.
1560 (org-test-with-temp-text "#+CATEGORY: test"
1565 (org-test-with-temp-text "#+CATEGORY: test"
1567 (cdr (assoc "CATEGORY" org-file-properties
)))))
1570 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1571 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1573 org-columns-default-format
)))
1574 ;; CONSTANTS keyword. Constants names are case sensitive.
1576 (equal '("299792458." "3.14")
1577 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1580 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1584 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1586 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1589 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1591 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1596 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1598 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1600 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1604 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1606 (list org-highest-priority org-lowest-priority org-default-priority
))))
1610 (org-test-with-temp-text "#+PRIORITIES: X Z"
1612 (list org-highest-priority org-lowest-priority org-default-priority
))))
1616 (org-test-with-temp-text "#+STARTUP: fold odd"
1618 (list org-startup-folded org-odd-levels-only
))))
1621 (equal '(("A" "B") ("C"))
1622 (org-test-with-temp-text "#+TODO: A B | C"
1624 (list org-not-done-keywords org-done-keywords
))))
1626 (equal '(("A" "C") ("B" "D"))
1627 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1629 (list org-not-done-keywords org-done-keywords
))))
1631 (equal '(("A" "B") ("C"))
1632 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1634 (list org-not-done-keywords org-done-keywords
))))
1636 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1637 (org-test-with-temp-text "#+TODO: A(a)"
1639 org-todo-key-alist
)))
1641 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1642 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1644 org-todo-log-states
)))
1645 ;; Enter SETUPFILE keyword.
1648 (org-test-with-temp-text
1649 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1651 (cdr (assoc "a" org-file-properties
))))))
1659 (ert-deftest test-org
/coderef
()
1660 "Test coderef links specifications."
1662 (org-test-with-temp-text "
1663 #+BEGIN_SRC emacs-lisp
1668 (looking-at "(ref:sc)")))
1669 ;; Find coderef even with alternate label format.
1671 (org-test-with-temp-text "
1672 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
1677 (looking-at "{ref:sc}"))))
1681 (ert-deftest test-org
/custom-id
()
1682 "Test custom ID links specifications."
1684 (org-test-with-temp-text
1685 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1687 (org-looking-at-p "\\* H1")))
1688 ;; Throw an error on false positives.
1690 (org-test-with-temp-text
1691 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
1693 (org-looking-at-p "\\* H1"))))
1697 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1698 ;; a named element (#+name: text) and to headlines (* Text).
1700 (ert-deftest test-org
/fuzzy-links
()
1701 "Test fuzzy links specifications."
1702 ;; Fuzzy link goes in priority to a matching target.
1704 (org-test-with-temp-text
1705 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
1706 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1707 (looking-at "<<Test>>")))
1708 ;; Then fuzzy link points to an element with a given name.
1710 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
1711 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1712 (looking-at "#\\+NAME: Test")))
1713 ;; A target still lead to a matching headline otherwise.
1715 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
1716 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1717 (looking-at "\\* Head2")))
1718 ;; With a leading star in link, enforce heading match.
1720 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
1721 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
1722 (looking-at "\\* Test")))
1723 ;; With a leading star in link, enforce exact heading match, even
1724 ;; with `org-link-search-must-match-exact-headline' set to nil.
1726 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1727 (let ((org-link-search-must-match-exact-headline nil
))
1728 (org-open-at-point))))
1729 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
1731 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
1732 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1733 (looking-at "\\* Test")))
1735 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
1736 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
1737 (looking-at "\\* Test")))
1738 ;; Heading match should not care about spaces, cookies, TODO
1739 ;; keywords, priorities, and tags.
1742 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1743 (org-test-with-temp-text
1744 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1745 (let ((org-link-search-must-match-exact-headline nil
)
1746 (org-todo-regexp "TODO"))
1747 (org-open-at-point))
1748 (looking-at (regexp-quote first-line
)))))
1749 ;; Heading match should still be exact.
1752 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1753 (org-test-with-temp-text
1754 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1755 (let ((org-link-search-must-match-exact-headline nil
)
1756 (org-todo-regexp "TODO"))
1757 (org-open-at-point)))))
1758 ;; Heading match ignores COMMENT keyword.
1760 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1762 (looking-at "\\* COMMENT Test")))
1763 ;; Correctly un-hexify fuzzy links.
1765 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
1771 (ert-deftest test-org
/org-link-escape-ascii-character
()
1772 "Escape an ascii character."
1776 (org-link-escape "["))))
1778 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1779 "Escape an ascii control character."
1783 (org-link-escape "\t"))))
1785 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1786 "Escape an unicode multibyte character."
1790 (org-link-escape "€"))))
1792 (ert-deftest test-org
/org-link-escape-custom-table
()
1793 "Escape string with custom character table."
1797 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1799 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1800 "Escape string with custom table merged with default table."
1803 "%5BF%6F%6F%3A%42ar%0A%5D"
1804 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1806 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1807 "Unescape an ascii character."
1811 (org-link-unescape "%5B"))))
1813 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1814 "Unescpae an ascii control character."
1818 (org-link-unescape "%0A"))))
1820 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1821 "Unescape unicode multibyte character."
1825 (org-link-unescape "%E2%82%AC"))))
1827 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1828 "Unescape old style percent escaped character."
1831 "à âçèéêîôùû"
1832 (decode-coding-string
1833 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1835 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1836 "Escape and unescape a URL that includes an escaped char.
1837 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1840 "http://some.host.com/form?&id=blah%2Bblah25"
1842 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1844 (ert-deftest test-org
/org-link-escape-chars-browser
()
1845 "Test of the constant `org-link-escape-chars-browser'.
1846 See there why this test is a candidate to be removed once Org
1847 drops support for Emacs 24.1 and 24.2."
1850 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1851 "%22Release%208.2%22&idxname=emacs-orgmode")
1852 (org-link-escape-browser ; Do not replace with `url-encode-url',
1853 ; see docstring above.
1854 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1855 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1859 (ert-deftest test-org
/open-at-point-in-keyword
()
1860 "Does `org-open-at-point' open link in a keyword line?"
1862 (org-test-with-temp-text
1863 "#+KEYWORD: <point>[[info:emacs#Top]]"
1864 (org-open-at-point) t
)))
1866 (ert-deftest test-org
/open-at-point-in-property
()
1867 "Does `org-open-at-point' open link in property drawer?"
1869 (org-test-with-temp-text
1872 :URL: <point>[[info:emacs#Top]]
1874 (org-open-at-point) t
)))
1876 (ert-deftest test-org
/open-at-point-in-comment
()
1877 "Does `org-open-at-point' open link in a commented line?"
1879 (org-test-with-temp-text
1880 "# <point>[[info:emacs#Top]]"
1881 (org-open-at-point) t
)))
1883 (ert-deftest test-org
/open-at-point
/info
()
1884 "Test `org-open-at-point' on info links."
1886 (org-test-with-temp-text
1887 "<point>[[info:emacs#Top]]"
1889 (and (switch-to-buffer "*info*")
1891 (looking-at "\nThe Emacs Editor")
1894 (ert-deftest test-org
/open-at-point
/inline-image
()
1895 "Test `org-open-at-point' on nested links."
1897 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1899 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1900 (kill-buffer "*info*")))))
1902 (ert-deftest test-org
/open-at-point
/radio-target
()
1903 "Test `org-open-at-point' on radio targets."
1905 (org-test-with-temp-text "<<<target>>> <point>target"
1906 (org-update-radio-target-regexp)
1908 (eq (org-element-type (org-element-context)) 'radio-target
))))
1912 (ert-deftest test-org
/store-link
()
1913 "Test `org-store-link' specifications."
1914 ;; On a headline, link to that headline. Use heading as the
1915 ;; description of the link.
1917 (let (org-store-link-props org-stored-links
)
1918 (org-test-with-temp-text-in-file "* H1"
1919 (let ((file (buffer-file-name)))
1920 (equal (format "[[file:%s::*H1][H1]]" file
)
1921 (org-store-link nil
))))))
1922 ;; On a headline, remove any link from description.
1924 (let (org-store-link-props org-stored-links
)
1925 (org-test-with-temp-text-in-file "* [[#l][d]]"
1926 (let ((file (buffer-file-name)))
1927 (equal (format "[[file:%s::*%s][d]]"
1929 (org-link-escape "[[#l][d]]"))
1930 (org-store-link nil
))))))
1932 (let (org-store-link-props org-stored-links
)
1933 (org-test-with-temp-text-in-file "* [[l]]"
1934 (let ((file (buffer-file-name)))
1935 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
1936 (org-store-link nil
))))))
1938 (let (org-store-link-props org-stored-links
)
1939 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
1940 (let ((file (buffer-file-name)))
1941 (equal (format "[[file:%s::*%s][d1 d2]]"
1943 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
1944 (org-store-link nil
))))))
1945 ;; On a named element, link to that element.
1947 (let (org-store-link-props org-stored-links
)
1948 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
1949 (let ((file (buffer-file-name)))
1950 (equal (format "[[file:%s::foo][foo]]" file
)
1951 (org-store-link nil
)))))))
1956 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1957 "Ensure properties accumulate in subtree drawers."
1958 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1959 (org-babel-next-src-block)
1960 (should (equal '(2 1) (org-babel-execute-src-block)))))
1962 (ert-deftest test-org
/custom-properties
()
1963 "Test custom properties specifications."
1966 (let ((org-custom-properties '("FOO")))
1967 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1968 (org-toggle-custom-properties-visibility)
1969 (org-invisible-p2))))
1970 ;; Properties are case-insensitive.
1972 (let ((org-custom-properties '("FOO")))
1973 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1974 (org-toggle-custom-properties-visibility)
1975 (org-invisible-p2))))
1977 (let ((org-custom-properties '("foo")))
1978 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1979 (org-toggle-custom-properties-visibility)
1980 (org-invisible-p2))))
1981 ;; Multiple custom properties in the same drawer.
1983 (let ((org-custom-properties '("FOO" "BAR")))
1984 (org-test-with-temp-text
1985 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1986 (org-toggle-custom-properties-visibility)
1987 (and (org-invisible-p2)
1988 (not (progn (forward-line) (org-invisible-p2)))
1989 (progn (forward-line) (org-invisible-p2))))))
1990 ;; Hide custom properties with an empty value.
1992 (let ((org-custom-properties '("FOO")))
1993 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1994 (org-toggle-custom-properties-visibility)
1995 (org-invisible-p2))))
1996 ;; Do not hide fake properties.
1998 (let ((org-custom-properties '("FOO")))
1999 (org-test-with-temp-text ":FOO: val\n"
2000 (org-toggle-custom-properties-visibility)
2001 (org-invisible-p2))))
2003 (let ((org-custom-properties '("A")))
2004 (org-test-with-temp-text
2005 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2006 (org-toggle-custom-properties-visibility)
2007 (org-invisible-p2)))))
2013 (ert-deftest test-org
/mark-subtree
()
2014 "Test `org-mark-subtree' specifications."
2015 ;; Error when point is before first headline.
2017 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2018 (progn (transient-mark-mode 1)
2019 (org-mark-subtree))))
2020 ;; Without argument, mark current subtree.
2024 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2025 (progn (transient-mark-mode 1)
2028 (list (region-beginning) (region-end))))))
2029 ;; With an argument, move ARG up.
2033 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2034 (progn (transient-mark-mode 1)
2036 (org-mark-subtree 1)
2037 (list (region-beginning) (region-end))))))
2038 ;; Do not get fooled by inlinetasks.
2039 (when (featurep 'org-inlinetask
)
2042 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2043 (progn (transient-mark-mode 1)
2045 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2046 (region-beginning)))))))
2052 (ert-deftest test-org
/in-regexp
()
2053 "Test `org-in-regexp' specifications."
2056 (org-test-with-temp-text "xx ab<point>c xx"
2057 (org-in-regexp "abc")))
2059 (org-test-with-temp-text "xx abc <point>xx"
2060 (org-in-regexp "abc")))
2061 ;; Return non-nil even with multiple matching regexps in the same
2064 (org-test-with-temp-text "abc xx ab<point>c xx"
2065 (org-in-regexp "abc")))
2066 ;; With optional argument NLINES, check extra lines around point.
2068 (org-test-with-temp-text "A\nB<point>\nC"
2069 (org-in-regexp "A\nB\nC")))
2071 (org-test-with-temp-text "A\nB<point>\nC"
2072 (org-in-regexp "A\nB\nC" 1)))
2074 (org-test-with-temp-text "A\nB\nC<point>"
2075 (org-in-regexp "A\nB\nC" 1)))
2076 ;; When optional argument VISUALLY is non-nil, return nil if at
2077 ;; regexp boundaries.
2079 (org-test-with-temp-text "xx abc<point> xx"
2080 (org-in-regexp "abc")))
2082 (org-test-with-temp-text "xx abc<point> xx"
2083 (org-in-regexp "abc" nil t
))))
2088 (ert-deftest test-org
/end-of-meta-data
()
2089 "Test `org-end-of-meta-data' specifications."
2090 ;; Skip planning line.
2092 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2093 (org-end-of-meta-data)
2095 ;; Skip properties drawer.
2097 (org-test-with-temp-text
2098 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2099 (org-end-of-meta-data)
2103 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2104 (org-end-of-meta-data)
2106 ;; Nothing to skip, go to first line.
2108 (org-test-with-temp-text "* Headline\nContents"
2109 (org-end-of-meta-data)
2110 (looking-at "Contents")))
2111 ;; With option argument, skip empty lines, regular drawers and
2114 (org-test-with-temp-text "* Headline\n\nContents"
2115 (org-end-of-meta-data t
)
2116 (looking-at "Contents")))
2118 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2119 (org-end-of-meta-data t
)
2120 (looking-at "Contents")))
2122 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2123 (org-end-of-meta-data t
)
2124 (looking-at "Contents")))
2125 ;; Special case: do not skip incomplete drawers.
2127 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2128 (org-end-of-meta-data t
)
2129 (looking-at ":LOGBOOK:")))
2130 ;; Special case: Be careful about consecutive headlines.
2132 (org-test-with-temp-text "* H1\n*H2\nContents"
2133 (org-end-of-meta-data t
)
2134 (looking-at "Contents"))))
2136 (ert-deftest test-org
/beginning-of-line
()
2137 "Test `org-beginning-of-line' specifications."
2140 (org-test-with-temp-text "Some text\nSome other text"
2141 (progn (org-beginning-of-line) (bolp))))
2142 ;; Standard test with `visual-line-mode'.
2144 (org-test-with-temp-text "A long line of text\nSome other text"
2145 (progn (visual-line-mode)
2147 (dotimes (i 1000) (insert "very "))
2148 (org-beginning-of-line)
2150 ;; At an headline with special movement.
2152 (org-test-with-temp-text "* TODO Headline"
2153 (let ((org-special-ctrl-a/e t
))
2155 (and (progn (org-beginning-of-line) (looking-at "Headline"))
2156 (progn (org-beginning-of-line) (bolp))
2157 (progn (org-beginning-of-line) (looking-at "Headline"))))))
2158 ;; Special case: Do not error when the buffer contains only a single
2161 (org-test-with-temp-text "*<point>"
2162 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))))
2164 (org-test-with-temp-text "*<point>"
2165 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line)))))
2167 (ert-deftest test-org
/end-of-line
()
2168 "Test `org-end-of-line' specifications."
2171 (org-test-with-temp-text "Some text\nSome other text"
2172 (progn (org-end-of-line) (eolp))))
2173 ;; Standard test with `visual-line-mode'.
2175 (org-test-with-temp-text "A long line of text\nSome other text"
2176 (progn (visual-line-mode)
2178 (dotimes (i 1000) (insert "very "))
2179 (goto-char (point-min))
2182 ;; At an headline with special movement.
2184 (org-test-with-temp-text "* Headline1 :tag:\n"
2185 (let ((org-special-ctrl-a/e t
))
2186 (and (progn (org-end-of-line) (looking-at " :tag:"))
2187 (progn (org-end-of-line) (eolp))
2188 (progn (org-end-of-line) (looking-at " :tag:"))))))
2189 ;; At an headline without special movement.
2191 (org-test-with-temp-text "* Headline2 :tag:\n"
2192 (let ((org-special-ctrl-a/e nil
))
2193 (and (progn (org-end-of-line) (eolp))
2194 (progn (org-end-of-line) (eolp))))))
2195 ;; At an headline, with reversed movement.
2197 (org-test-with-temp-text "* Headline3 :tag:\n"
2198 (let ((org-special-ctrl-a/e
'reversed
)
2199 (this-command last-command
))
2200 (and (progn (org-end-of-line) (eolp))
2201 (progn (org-end-of-line) (looking-at " :tag:"))))))
2202 ;; At a block without hidden contents.
2204 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2205 (progn (org-end-of-line) (eolp))))
2206 ;; At a block with hidden contents.
2208 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2209 (let ((org-special-ctrl-a/e t
))
2210 (org-hide-block-toggle)
2214 (ert-deftest test-org
/forward-sentence
()
2215 "Test `org-forward-sentence' specifications."
2216 ;; At the end of a table cell, move to the end of the next one.
2218 (org-test-with-temp-text "| a<point> | b |"
2219 (org-forward-sentence)
2220 (looking-at " |$")))
2221 ;; Elsewhere in a cell, move to its end.
2223 (org-test-with-temp-text "| a<point>c | b |"
2224 (org-forward-sentence)
2225 (looking-at " | b |$")))
2226 ;; Otherwise, simply call `forward-sentence'.
2228 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2229 (org-forward-sentence)
2230 (looking-at " Sentence 2.")))
2232 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2233 (org-forward-sentence)
2234 (org-forward-sentence)
2236 ;; At the end of an element, jump to the next one, without stopping
2237 ;; on blank lines in-between.
2239 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2240 (org-forward-sentence)
2243 (ert-deftest test-org
/backward-sentence
()
2244 "Test `org-backward-sentence' specifications."
2245 ;; At the beginning of a table cell, move to the beginning of the
2248 (org-test-with-temp-text "| a | <point>b |"
2249 (org-backward-sentence)
2250 (looking-at "a | b |$")))
2251 ;; Elsewhere in a cell, move to its beginning.
2253 (org-test-with-temp-text "| a | b<point>c |"
2254 (org-backward-sentence)
2255 (looking-at "bc |$")))
2256 ;; Otherwise, simply call `backward-sentence'.
2258 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2259 (org-backward-sentence)
2260 (looking-at "Sentence 2.")))
2262 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2263 (org-backward-sentence)
2264 (org-backward-sentence)
2266 ;; Make sure to hit the beginning of a sentence on the same line as
2269 (org-test-with-temp-text "- Line 1\n line <point>2."
2270 (org-backward-sentence)
2271 (looking-at "Line 1"))))
2273 (ert-deftest test-org
/forward-paragraph
()
2274 "Test `org-forward-paragraph' specifications."
2275 ;; At end of buffer, return an error.
2277 (org-test-with-temp-text "Paragraph"
2278 (goto-char (point-max))
2279 (org-forward-paragraph)))
2282 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2283 (org-forward-paragraph)
2287 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2288 (org-forward-paragraph)
2290 ;; Do not enter elements with invisible contents.
2292 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2293 (org-hide-block-toggle)
2294 (org-forward-paragraph)
2296 ;; On an affiliated keyword, jump to the beginning of the element.
2298 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2299 (org-forward-paragraph)
2300 (looking-at "Para")))
2301 ;; On an item or a footnote definition, move to the second element
2304 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2305 (org-forward-paragraph)
2306 (looking-at " Paragraph")))
2308 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2309 (org-forward-paragraph)
2310 (looking-at "Paragraph")))
2311 ;; On an item, or a footnote definition, when the first line is
2312 ;; empty, move to the first item.
2314 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2315 (org-forward-paragraph)
2316 (looking-at " Paragraph")))
2318 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2319 (org-forward-paragraph)
2320 (looking-at "Paragraph")))
2321 ;; On a table (resp. a property drawer) do not move through table
2322 ;; rows (resp. node properties).
2324 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2325 (org-forward-paragraph)
2326 (looking-at "Paragraph")))
2328 (org-test-with-temp-text
2329 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2330 (org-forward-paragraph)
2331 (looking-at "Paragraph")))
2332 ;; On a verse or source block, stop after blank lines.
2334 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2335 (org-forward-paragraph)
2338 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2339 (org-forward-paragraph)
2340 (looking-at "L2"))))
2342 (ert-deftest test-org
/backward-paragraph
()
2343 "Test `org-backward-paragraph' specifications."
2344 ;; Error at beginning of buffer.
2346 (org-test-with-temp-text "Paragraph"
2347 (org-backward-paragraph)))
2350 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2351 (goto-char (point-max))
2352 (org-backward-paragraph)
2355 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2356 (goto-char (point-max))
2358 (org-backward-paragraph)
2362 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2363 (goto-char (point-max))
2365 (org-backward-paragraph)
2367 ;; Ignore invisible elements.
2369 (org-test-with-temp-text "* H1\n P1\n* H2"
2371 (goto-char (point-max))
2373 (org-backward-paragraph)
2375 ;; On an affiliated keyword, jump to the first one.
2377 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2378 (search-forward "c2")
2379 (org-backward-paragraph)
2380 (looking-at "#\\+name")))
2381 ;; On the second element in an item or a footnote definition, jump
2382 ;; to item or the definition.
2384 (org-test-with-temp-text "- line1\n\n line2"
2385 (goto-char (point-max))
2387 (org-backward-paragraph)
2388 (looking-at "- line1")))
2390 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2391 (goto-char (point-max))
2393 (org-backward-paragraph)
2394 (looking-at "\\[fn:1\\] line1")))
2395 ;; On a table (resp. a property drawer), ignore table rows
2396 ;; (resp. node properties).
2398 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2399 (goto-char (point-max))
2401 (org-backward-paragraph)
2404 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2405 (org-backward-paragraph)
2406 (looking-at ":PROPERTIES:")))
2407 ;; On a source or verse block, stop before blank lines.
2409 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2410 (search-forward "L3")
2412 (org-backward-paragraph)
2415 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2416 (search-forward "L3")
2418 (org-backward-paragraph)
2419 (looking-at "L2"))))
2421 (ert-deftest test-org
/forward-element
()
2422 "Test `org-forward-element' specifications."
2423 ;; 1. At EOB: should error.
2424 (org-test-with-temp-text "Some text\n"
2425 (goto-char (point-max))
2426 (should-error (org-forward-element)))
2427 ;; 2. Standard move: expected to ignore blank lines.
2428 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2429 (org-forward-element)
2430 (should (looking-at (regexp-quote "Second paragraph."))))
2431 ;; 3. Headline tests.
2432 (org-test-with-temp-text "
2437 ;; 3.1. At an headline beginning: move to next headline at the
2440 (org-forward-element)
2441 (should (looking-at (regexp-quote "** Head 1.2")))
2442 ;; 3.2. At an headline beginning: move to parent headline if no
2443 ;; headline at the same level.
2445 (org-forward-element)
2446 (should (looking-at (regexp-quote "** Head 1.2"))))
2447 ;; 4. Greater element tests.
2448 (org-test-with-temp-text
2449 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2450 ;; 4.1. At a greater element: expected to skip contents.
2451 (org-forward-element)
2452 (should (looking-at (regexp-quote "Outside.")))
2453 ;; 4.2. At the end of greater element contents: expected to skip
2454 ;; to the end of the greater element.
2456 (org-forward-element)
2457 (should (looking-at (regexp-quote "Outside."))))
2459 (org-test-with-temp-text "
2473 ;; 5.1. At list top point: expected to move to the element after
2476 (org-forward-element)
2477 (should (looking-at (regexp-quote "Outside.")))
2478 ;; 5.2. Special case: at the first line of a sub-list, but not at
2479 ;; beginning of line, move to next item.
2482 (org-forward-element)
2483 (should (looking-at "- item2"))
2486 (org-forward-element)
2487 (should (looking-at " - sub2"))
2488 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2490 (org-forward-element)
2491 (should (looking-at (regexp-quote " Inner paragraph.")))
2492 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2494 (org-forward-element)
2495 (should (looking-at (regexp-quote " Inner paragraph.")))
2496 ;; 5.5. At an item: expected to move to next item, if any.
2498 (org-forward-element)
2499 (should (looking-at " - sub3"))))
2501 (ert-deftest test-org
/backward-element
()
2502 "Test `org-backward-element' specifications."
2503 ;; 1. Should error at BOB.
2504 (org-test-with-temp-text " \nParagraph."
2505 (should-error (org-backward-element)))
2506 ;; 2. Should move at BOB when called on the first element in buffer.
2508 (org-test-with-temp-text "\n#+TITLE: test"
2509 (progn (forward-line)
2510 (org-backward-element)
2512 ;; 3. Not at the beginning of an element: move at its beginning.
2513 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2516 (org-backward-element)
2517 (should (looking-at (regexp-quote "Paragraph2."))))
2518 ;; 4. Headline tests.
2519 (org-test-with-temp-text "
2524 ;; 4.1. At an headline beginning: move to previous headline at the
2527 (org-backward-element)
2528 (should (looking-at (regexp-quote "** Head 1.1")))
2529 ;; 4.2. At an headline beginning: move to parent headline if no
2530 ;; headline at the same level.
2532 (org-backward-element)
2533 (should (looking-at (regexp-quote "* Head 1")))
2534 ;; 4.3. At the first top-level headline: should error.
2536 (should-error (org-backward-element)))
2537 ;; 5. At beginning of first element inside a greater element:
2538 ;; expected to move to greater element's beginning.
2539 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2541 (org-backward-element)
2542 (should (looking-at "#\\+BEGIN_CENTER")))
2543 ;; 6. At the beginning of the first element in a section: should
2544 ;; move back to headline, if any.
2546 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2547 (progn (goto-char (point-max))
2549 (org-backward-element)
2550 (org-at-heading-p))))
2552 (org-test-with-temp-text "
2567 ;; 7.1. At beginning of sub-list: expected to move to the
2568 ;; paragraph before it.
2570 (org-backward-element)
2571 (should (looking-at "item1"))
2572 ;; 7.2. At an item in a list: expected to move at previous item.
2574 (org-backward-element)
2575 (should (looking-at " - sub2"))
2577 (org-backward-element)
2578 (should (looking-at "- item1"))
2579 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2582 (org-backward-element)
2583 (should (looking-at " - sub1"))
2585 (org-backward-element)
2586 (should (looking-at "- item1"))
2587 ;; 7.4. At blank-lines before list end: expected to move to top
2590 (org-backward-element)
2591 (should (looking-at "- item1"))))
2593 (ert-deftest test-org
/up-element
()
2594 "Test `org-up-element' specifications."
2595 ;; 1. At BOB or with no surrounding element: should error.
2596 (org-test-with-temp-text "Paragraph."
2597 (should-error (org-up-element)))
2598 (org-test-with-temp-text "* Head1\n* Head2"
2600 (should-error (org-up-element)))
2601 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2603 (should-error (org-up-element)))
2604 ;; 2. At an headline: move to parent headline.
2605 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2608 (should (looking-at "\\* Head1")))
2609 ;; 3. Inside a greater element: move to greater element beginning.
2610 (org-test-with-temp-text
2611 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2614 (should (looking-at "#\\+BEGIN_CENTER")))
2616 (org-test-with-temp-text "* Top
2623 Paragraph within sub2.
2626 ;; 4.1. Within an item: move to the item beginning.
2629 (should (looking-at " - sub2"))
2630 ;; 4.2. At an item in a sub-list: move to parent item.
2633 (should (looking-at "- item1"))
2634 ;; 4.3. At an item in top list: move to beginning of whole list.
2637 (should (looking-at "- item1"))
2638 ;; 4.4. Special case. At very top point: should move to parent of
2642 (should (looking-at "\\* Top"))))
2644 (ert-deftest test-org
/down-element
()
2645 "Test `org-down-element' specifications."
2646 ;; Error when the element hasn't got a recursive type.
2647 (org-test-with-temp-text "Paragraph."
2648 (should-error (org-down-element)))
2649 ;; Error when the element has no contents
2650 (org-test-with-temp-text "* Headline"
2651 (should-error (org-down-element)))
2652 ;; When at a plain-list, move to first item.
2653 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2656 (should (looking-at " - Item 1.1")))
2657 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2659 (should (looking-at " Item 1")))
2660 ;; When at a table, move to first row
2661 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2663 (should (looking-at " a | b |")))
2664 ;; Otherwise, move inside the greater element.
2665 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2667 (should (looking-at "Paragraph"))))
2669 (ert-deftest test-org
/drag-element-backward
()
2670 "Test `org-drag-element-backward' specifications."
2674 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2675 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2676 (org-drag-element-backward)
2680 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2681 (org-test-with-temp-text
2682 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2683 (org-drag-element-backward)
2685 ;; Preserve blank lines.
2687 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2688 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2689 (org-drag-element-backward)
2693 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2694 (org-drag-element-backward)
2695 (org-looking-at-p "2")))
2696 ;; Error when trying to move first element of buffer.
2698 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2699 (org-drag-element-backward)))
2700 ;; Error when trying to swap nested elements.
2702 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2704 (org-drag-element-backward)))
2705 ;; Error when trying to swap an headline element and a non-headline
2708 (org-test-with-temp-text "Test.\n* Head 1"
2710 (org-drag-element-backward)))
2711 ;; Preserve visibility of elements and their contents.
2713 (equal '((63 .
82) (26 .
48))
2714 (org-test-with-temp-text "
2722 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2723 (search-backward "- item 1")
2724 (org-drag-element-backward)
2725 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2726 (overlays-in (point-min) (point-max)))))))
2728 (ert-deftest test-org
/drag-element-forward
()
2729 "Test `org-drag-element-forward' specifications."
2730 ;; 1. Error when trying to move first element of buffer.
2731 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2733 (should-error (org-drag-element-forward)))
2734 ;; 2. Error when trying to swap nested elements.
2735 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2737 (should-error (org-drag-element-forward)))
2738 ;; 3. Error when trying to swap a non-headline element and an
2740 (org-test-with-temp-text "Test.\n* Head 1"
2741 (should-error (org-drag-element-forward)))
2742 ;; 4. Otherwise, swap elements, preserving column and blank lines
2743 ;; between elements.
2744 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2745 (search-forward "graph")
2746 (org-drag-element-forward)
2747 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2748 (should (looking-at " 1")))
2749 ;; 5. Preserve visibility of elements and their contents.
2750 (org-test-with-temp-text "
2758 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2759 (search-backward "#+BEGIN_CENTER")
2760 (org-drag-element-forward)
2763 '((63 .
82) (26 .
48))
2764 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2765 (overlays-in (point-min) (point-max)))))))
2767 (ert-deftest test-org
/next-block
()
2768 "Test `org-next-block' specifications."
2771 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2773 (looking-at "#\\+BEGIN_CENTER")))
2776 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2777 (let ((case-fold-search nil
))
2779 (looking-at "#\\+begin_center"))))
2780 ;; Ignore current line.
2782 (org-test-with-temp-text
2783 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2785 (looking-at "#\\+BEGIN_CENTER")))
2786 ;; Throw an error when no block is found.
2788 (org-test-with-temp-text "Paragraph"
2789 (org-next-block 1)))
2790 ;; With an argument, skip many blocks at once.
2792 (org-test-with-temp-text
2793 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2795 (looking-at "#\\+BEGIN_QUOTE")))
2796 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2798 (org-test-with-temp-text
2799 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2800 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2801 (looking-at "#\\+BEGIN_QUOTE")))
2802 ;; Optional argument is also case-insensitive.
2804 (org-test-with-temp-text
2805 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2806 (let ((case-fold-search nil
))
2807 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2808 (looking-at "#\\+begin_quote")))))
2810 (ert-deftest test-org
/previous-block
()
2811 "Test `org-previous-block' specifications."
2814 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2815 (org-previous-block 1)
2816 (looking-at "#\\+BEGIN_CENTER")))
2819 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2820 (let ((case-fold-search nil
))
2821 (org-previous-block 1)
2822 (looking-at "#\\+begin_center"))))
2823 ;; Ignore current line.
2825 (org-test-with-temp-text
2826 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2827 (org-previous-block 1)
2828 (looking-at "#\\+BEGIN_QUOTE")))
2829 ;; Throw an error when no block is found.
2831 (org-test-with-temp-text "Paragraph<point>"
2832 (org-previous-block 1)))
2833 ;; With an argument, skip many blocks at once.
2835 (org-test-with-temp-text
2836 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2837 (org-previous-block 2)
2838 (looking-at "#\\+BEGIN_CENTER")))
2839 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2841 (org-test-with-temp-text
2842 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2843 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2844 (looking-at "#\\+BEGIN_QUOTE")))
2845 ;; Optional argument is also case-insensitive.
2847 (org-test-with-temp-text
2848 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2849 (let ((case-fold-search nil
))
2850 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2851 (looking-at "#\\+begin_quote")))))
2854 ;;; Outline structure
2856 (ert-deftest test-org
/demote
()
2857 "Test `org-demote' specifications."
2858 ;; Add correct number of stars according to `org-odd-levels-only'.
2861 (org-test-with-temp-text "* H"
2862 (let ((org-odd-levels-only nil
)) (org-demote))
2863 (org-current-level))))
2866 (org-test-with-temp-text "* H"
2867 (let ((org-odd-levels-only t
)) (org-demote))
2868 (org-current-level))))
2869 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2871 (org-test-with-temp-text "* H :tag:"
2872 (let ((org-tags-column 10)
2873 (org-auto-align-tags t
)
2874 (org-odd-levels-only nil
))
2876 (org-move-to-column 10)
2877 (org-looking-at-p ":tag:$")))
2879 (org-test-with-temp-text "* H :tag:"
2880 (let ((org-tags-column 10)
2881 (org-auto-align-tags nil
)
2882 (org-odd-levels-only nil
))
2884 (org-move-to-column 10)
2885 (org-looking-at-p ":tag:$")))
2886 ;; When `org-adapt-indentation' is non-nil, always indent planning
2887 ;; info and property drawers accordingly.
2890 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2891 (let ((org-odd-levels-only nil
)
2892 (org-adapt-indentation t
))
2895 (org-get-indentation))))
2898 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2899 (let ((org-odd-levels-only nil
)
2900 (org-adapt-indentation t
))
2903 (org-get-indentation))))
2906 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2907 (let ((org-odd-levels-only nil
)
2908 (org-adapt-indentation nil
))
2911 (org-get-indentation))))
2912 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2913 ;; section accordingly. Ignore, however, footnote definitions and
2914 ;; inlinetasks boundaries.
2917 (org-test-with-temp-text "* H\n Paragraph"
2918 (let ((org-odd-levels-only nil
)
2919 (org-adapt-indentation t
))
2922 (org-get-indentation))))
2925 (org-test-with-temp-text "* H\n Paragraph"
2926 (let ((org-odd-levels-only nil
)
2927 (org-adapt-indentation nil
))
2930 (org-get-indentation))))
2933 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2934 (let ((org-odd-levels-only nil
)
2935 (org-adapt-indentation t
))
2937 (goto-char (point-max))
2938 (org-get-indentation))))
2941 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2942 (let ((org-odd-levels-only nil
)
2943 (org-adapt-indentation t
))
2945 (goto-char (point-max))
2946 (org-get-indentation))))
2947 (when (featurep 'org-inlinetask
)
2950 (let ((org-inlinetask-min-level 5)
2951 (org-adapt-indentation t
))
2952 (org-test-with-temp-text "* H\n***** I\n***** END"
2955 (org-get-indentation))))))
2956 (when (featurep 'org-inlinetask
)
2959 (let ((org-inlinetask-min-level 5)
2960 (org-adapt-indentation t
))
2961 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2964 (org-get-indentation))))))
2965 ;; Ignore contents of source blocks or example blocks when
2966 ;; indentation should be preserved (through
2967 ;; `org-src-preserve-indentation' or "-i" flag).
2970 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2971 (let ((org-adapt-indentation t
)
2972 (org-src-preserve-indentation nil
))
2975 (org-get-indentation))))
2978 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2979 (let ((org-adapt-indentation t
)
2980 (org-src-preserve-indentation t
))
2983 (org-get-indentation))))
2986 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2987 (let ((org-adapt-indentation t
)
2988 (org-src-preserve-indentation t
))
2991 (org-get-indentation))))
2994 (org-test-with-temp-text
2995 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2996 (let ((org-adapt-indentation t
)
2997 (org-src-preserve-indentation nil
))
3000 (org-get-indentation)))))
3002 (ert-deftest test-org
/promote
()
3003 "Test `org-promote' specifications."
3004 ;; Return an error if headline is to be promoted to level 0, unless
3005 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3006 ;; headline becomes a comment.
3008 (org-test-with-temp-text "* H"
3009 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3012 (org-test-with-temp-text "* H"
3013 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3015 ;; Remove correct number of stars according to
3016 ;; `org-odd-levels-only'.
3019 (org-test-with-temp-text "*** H"
3020 (let ((org-odd-levels-only nil
)) (org-promote))
3021 (org-current-level))))
3024 (org-test-with-temp-text "*** H"
3025 (let ((org-odd-levels-only t
)) (org-promote))
3026 (org-current-level))))
3027 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3029 (org-test-with-temp-text "** H :tag:"
3030 (let ((org-tags-column 10)
3031 (org-auto-align-tags t
)
3032 (org-odd-levels-only nil
))
3034 (org-move-to-column 10)
3035 (org-looking-at-p ":tag:$")))
3037 (org-test-with-temp-text "** H :tag:"
3038 (let ((org-tags-column 10)
3039 (org-auto-align-tags nil
)
3040 (org-odd-levels-only nil
))
3042 (org-move-to-column 10)
3043 (org-looking-at-p ":tag:$")))
3044 ;; When `org-adapt-indentation' is non-nil, always indent planning
3045 ;; info and property drawers.
3048 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3049 (let ((org-odd-levels-only nil
)
3050 (org-adapt-indentation t
))
3053 (org-get-indentation))))
3056 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3057 (let ((org-odd-levels-only nil
)
3058 (org-adapt-indentation t
))
3061 (org-get-indentation))))
3064 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3065 (let ((org-odd-levels-only nil
)
3066 (org-adapt-indentation nil
))
3069 (org-get-indentation))))
3070 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3071 ;; section accordingly. Ignore, however, footnote definitions and
3072 ;; inlinetasks boundaries.
3075 (org-test-with-temp-text "** H\n Paragraph"
3076 (let ((org-odd-levels-only nil
)
3077 (org-adapt-indentation t
))
3080 (org-get-indentation))))
3083 (org-test-with-temp-text "** H\n Paragraph"
3084 (let ((org-odd-levels-only nil
)
3085 (org-adapt-indentation nil
))
3088 (org-get-indentation))))
3091 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3092 (let ((org-odd-levels-only nil
)
3093 (org-adapt-indentation t
))
3096 (org-get-indentation))))
3097 (when (featurep 'org-inlinetask
)
3100 (let ((org-inlinetask-min-level 5)
3101 (org-adapt-indentation t
))
3102 (org-test-with-temp-text "** H\n***** I\n***** END"
3105 (org-get-indentation))))))
3106 (when (featurep 'org-inlinetask
)
3109 (let ((org-inlinetask-min-level 5)
3110 (org-adapt-indentation t
))
3111 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3114 (org-get-indentation))))))
3115 ;; Give up shifting if it would break document's structure
3119 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3120 (let ((org-odd-levels-only nil
)
3121 (org-adapt-indentation t
))
3124 (org-get-indentation))))
3127 (org-test-with-temp-text "** H\n Paragraph\n * list."
3128 (let ((org-odd-levels-only nil
)
3129 (org-adapt-indentation t
))
3132 (org-get-indentation))))
3133 ;; Ignore contents of source blocks or example blocks when
3134 ;; indentation should be preserved (through
3135 ;; `org-src-preserve-indentation' or "-i" flag).
3138 (org-test-with-temp-text
3139 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3140 (let ((org-adapt-indentation t
)
3141 (org-src-preserve-indentation nil
)
3142 (org-odd-levels-only nil
))
3145 (org-get-indentation))))
3148 (org-test-with-temp-text
3149 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3150 (let ((org-adapt-indentation t
)
3151 (org-src-preserve-indentation t
)
3152 (org-odd-levels-only nil
))
3155 (org-get-indentation))))
3158 (org-test-with-temp-text
3159 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3160 (let ((org-adapt-indentation t
)
3161 (org-src-preserve-indentation t
)
3162 (org-odd-levels-only nil
))
3165 (org-get-indentation))))
3168 (org-test-with-temp-text
3169 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3170 (let ((org-adapt-indentation t
)
3171 (org-src-preserve-indentation nil
)
3172 (org-odd-levels-only nil
))
3175 (org-get-indentation)))))
3180 (ert-deftest test-org
/at-planning-p
()
3181 "Test `org-at-planning-p' specifications."
3184 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3185 (org-at-planning-p)))
3187 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3188 (org-at-planning-p)))
3189 ;; Correctly find planning attached to inlinetasks.
3190 (when (featurep 'org-inlinetask
)
3192 (org-test-with-temp-text
3193 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3194 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3196 (org-test-with-temp-text
3197 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3198 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3200 (org-test-with-temp-text
3201 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3202 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3204 (org-test-with-temp-text
3205 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3206 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3208 (ert-deftest test-org
/add-planning-info
()
3209 "Test `org-add-planning-info'."
3210 ;; Create deadline when `org-adapt-indentation' is non-nil.
3212 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3213 (org-test-with-temp-text "* H\nParagraph<point>"
3214 (let ((org-adapt-indentation t
))
3215 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3216 (replace-regexp-in-string
3217 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3219 ;; Create deadline when `org-adapt-indentation' is nil.
3221 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3222 (org-test-with-temp-text "* H\nParagraph<point>"
3223 (let ((org-adapt-indentation nil
))
3224 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3225 (replace-regexp-in-string
3226 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3228 ;; Update deadline when `org-adapt-indentation' is non-nil.
3230 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3231 (org-test-with-temp-text "\
3233 DEADLINE: <2015-06-24 Wed>
3235 (let ((org-adapt-indentation t
))
3236 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3237 (replace-regexp-in-string
3238 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3240 ;; Update deadline when `org-adapt-indentation' is nil.
3242 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3243 (org-test-with-temp-text "\
3245 DEADLINE: <2015-06-24 Wed>
3247 (let ((org-adapt-indentation nil
))
3248 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3249 (replace-regexp-in-string
3250 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3252 ;; Schedule when `org-adapt-indentation' is non-nil.
3254 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3255 (org-test-with-temp-text "* H\nParagraph<point>"
3256 (let ((org-adapt-indentation t
))
3257 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3258 (replace-regexp-in-string
3259 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3261 ;; Schedule when `org-adapt-indentation' is nil.
3263 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3264 (org-test-with-temp-text "* H\nParagraph<point>"
3265 (let ((org-adapt-indentation nil
))
3266 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3267 (replace-regexp-in-string
3268 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3270 ;; Add deadline when scheduled.
3274 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3276 (org-test-with-temp-text "\
3278 SCHEDULED: <2015-06-24 Wed>
3280 (let ((org-adapt-indentation t
))
3281 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3282 (replace-regexp-in-string
3283 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3285 ;; Remove middle entry.
3289 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3291 (org-test-with-temp-text "\
3293 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3295 (let ((org-adapt-indentation t
))
3296 (org-add-planning-info nil nil
'deadline
))
3297 (replace-regexp-in-string
3298 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3300 ;; Remove last entry and then middle entry (order should not
3305 CLOSED: [2015-06-24]
3307 (org-test-with-temp-text "\
3309 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3311 (let ((org-adapt-indentation t
))
3312 (org-add-planning-info nil nil
'scheduled
'deadline
))
3313 (replace-regexp-in-string
3314 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3316 ;; Remove closed when `org-adapt-indentation' is non-nil.
3318 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3319 (org-test-with-temp-text "\
3321 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3323 (let ((org-adapt-indentation t
))
3324 (org-add-planning-info nil nil
'closed
))
3325 (replace-regexp-in-string
3326 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3329 (equal "* H\n Paragraph"
3330 (org-test-with-temp-text "\
3332 CLOSED: [2015-06-25 Thu]
3334 (let ((org-adapt-indentation t
))
3335 (org-add-planning-info nil nil
'closed
))
3336 (replace-regexp-in-string
3337 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3339 ;; Remove closed when `org-adapt-indentation' is nil.
3341 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3342 (org-test-with-temp-text "\
3344 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3346 (let ((org-adapt-indentation nil
))
3347 (org-add-planning-info nil nil
'closed
))
3348 (replace-regexp-in-string
3349 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3352 (equal "* H\nParagraph"
3353 (org-test-with-temp-text "\
3355 CLOSED: [2015-06-25 Thu]
3357 (let ((org-adapt-indentation nil
))
3358 (org-add-planning-info nil nil
'closed
))
3359 (replace-regexp-in-string
3360 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3362 ;; Remove closed entry and delete empty line.
3367 (org-test-with-temp-text "\
3369 CLOSED: [2015-06-24 Wed]
3371 (let ((org-adapt-indentation t
))
3372 (org-add-planning-info nil nil
'closed
))
3373 (replace-regexp-in-string
3374 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3376 ;; Remove one entry and update another.
3378 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3379 (org-test-with-temp-text "\
3381 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3383 (let ((org-adapt-indentation t
))
3384 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3385 (replace-regexp-in-string
3386 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3392 (ert-deftest test-org
/buffer-property-keys
()
3393 "Test `org-buffer-property-keys' specifications."
3394 ;; Retrieve properties accross siblings.
3397 (org-test-with-temp-text "
3406 (org-buffer-property-keys))))
3407 ;; Retrieve properties accross children.
3410 (org-test-with-temp-text "
3419 (org-buffer-property-keys))))
3420 ;; Retrieve muliple properties in the same drawer.
3423 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3424 (org-buffer-property-keys))))
3425 ;; Ignore extension symbol in property name.
3428 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3429 (org-buffer-property-keys))))
3430 ;; With non-nil COLUMNS, extract property names from columns.
3433 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
3434 (org-buffer-property-keys nil nil t
))))
3436 (equal '("A" "B" "COLUMNS")
3437 (org-test-with-temp-text
3438 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
3439 (org-buffer-property-keys nil nil t
)))))
3441 (ert-deftest test-org
/property-values
()
3442 "Test `org-property-values' specifications."
3446 (org-test-with-temp-text
3447 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
3448 (org-property-values "A"))))
3449 ;; Ignore empty values.
3451 (org-test-with-temp-text
3452 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
3453 (org-property-values "A")))
3454 ;; Take into consideration extended values.
3457 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
3458 (org-property-values "A")))))
3460 (ert-deftest test-org
/find-property
()
3461 "Test `org-find-property' specifications."
3465 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
3466 (org-find-property "prop"))))
3467 ;; Ignore false positives.
3470 (org-test-with-temp-text
3471 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
3472 (org-find-property "A"))))
3473 ;; Return first entry found in buffer.
3476 (org-test-with-temp-text
3477 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3478 (org-find-property "A"))))
3479 ;; Only search visible part of the buffer.
3482 (org-test-with-temp-text
3483 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
3484 (org-narrow-to-subtree)
3485 (org-find-property "A"))))
3486 ;; With optional argument, only find entries with a specific value.
3488 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3489 (org-find-property "A" "2")))
3492 (org-test-with-temp-text
3493 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
3494 (org-find-property "A" "2"))))
3495 ;; Use "nil" for explicit nil values.
3498 (org-test-with-temp-text
3499 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
3500 (org-find-property "A" "nil")))))
3502 (ert-deftest test-org
/entry-delete
()
3503 "Test `org-entry-delete' specifications."
3507 " *:PROPERTIES:\n *:B: +2\n *:END:"
3508 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3509 (org-entry-delete (point) "A")
3511 ;; Also remove accumulated properties.
3515 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
3516 (org-entry-delete (point) "A")
3518 ;; When last property is removed, remove the property drawer.
3522 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
3523 (org-entry-delete (point) "A")
3525 ;; Return a non-nil value when some property was removed.
3527 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3528 (org-entry-delete (point) "A")))
3530 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
3531 (org-entry-delete (point) "C"))))
3533 (ert-deftest test-org
/entry-get
()
3534 "Test `org-entry-get' specifications."
3538 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3539 (org-entry-get (point) "A"))))
3543 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3544 (org-entry-get (point) "a"))))
3545 ;; Handle extended values, both before and after base value.
3548 (org-test-with-temp-text
3549 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3550 (org-entry-get (point) "A"))))
3551 ;; Empty values are returned as the empty string.
3554 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
3555 (org-entry-get (point) "A"))))
3556 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
3557 ;; otherwise, return nil.
3559 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3560 (org-entry-get (point) "A")))
3563 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
3564 (org-entry-get (point) "A" nil t
))))
3565 ;; Return nil when no property is found, independently on the
3566 ;; LITERAL-NIL argument.
3568 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3569 (org-entry-get (point) "B")))
3571 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3572 (org-entry-get (point) "B" nil t
)))
3573 ;; Handle inheritance, when allowed. Include extended values and
3574 ;; possibly global values.
3578 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3579 (org-entry-get (point) "A" t
))))
3583 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3584 (let ((org-use-property-inheritance t
))
3585 (org-entry-get (point) "A" 'selective
)))))
3587 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3588 (let ((org-use-property-inheritance nil
))
3589 (org-entry-get (point) "A" 'selective
))))
3593 (org-test-with-temp-text
3594 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
3595 (org-entry-get (point-max) "A" t
))))
3598 (org-test-with-temp-text
3599 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
3601 (org-entry-get (point-max) "A" t
))))
3604 (org-test-with-temp-text
3605 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
3607 (org-entry-get (point-max) "A" t
)))))
3609 (ert-deftest test-org
/entry-properties
()
3610 "Test `org-entry-properties' specifications."
3611 ;; Get "ITEM" property.
3614 (org-test-with-temp-text "* TODO H"
3615 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3618 (org-test-with-temp-text "* TODO H"
3619 (cdr (assoc "ITEM" (org-entry-properties))))))
3620 ;; Get "TODO" property. TODO keywords are case sensitive.
3623 (org-test-with-temp-text "* TODO H"
3624 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3627 (org-test-with-temp-text "* TODO H"
3628 (cdr (assoc "TODO" (org-entry-properties))))))
3630 (org-test-with-temp-text "* H"
3631 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3633 (org-test-with-temp-text "* todo H"
3634 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3635 ;; Get "PRIORITY" property.
3638 (org-test-with-temp-text "* [#A] H"
3639 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3642 (org-test-with-temp-text "* [#A] H"
3643 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3645 (equal (char-to-string org-default-priority
)
3646 (org-test-with-temp-text "* H"
3647 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3648 ;; Get "FILE" property.
3650 (org-test-with-temp-text-in-file "* H\nParagraph"
3651 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3652 (buffer-file-name))))
3654 (org-test-with-temp-text-in-file "* H\nParagraph"
3655 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3656 (buffer-file-name))))
3658 (org-test-with-temp-text "* H\nParagraph"
3659 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3660 ;; Get "TAGS" property.
3662 (equal ":tag1:tag2:"
3663 (org-test-with-temp-text "* H :tag1:tag2:"
3664 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3666 (equal ":tag1:tag2:"
3667 (org-test-with-temp-text "* H :tag1:tag2:"
3668 (cdr (assoc "TAGS" (org-entry-properties))))))
3670 (org-test-with-temp-text "* H"
3671 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3672 ;; Get "ALLTAGS" property.
3674 (equal ":tag1:tag2:"
3675 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3676 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3678 (equal ":tag1:tag2:"
3679 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3680 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3682 (org-test-with-temp-text "* H"
3683 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3684 ;; Get "BLOCKED" property.
3687 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
3688 (let ((org-enforce-todo-dependencies t
)
3690 '(org-block-todo-from-children-or-siblings-or-parent)))
3691 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3694 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
3695 (let ((org-enforce-todo-dependencies t
)
3697 '(org-block-todo-from-children-or-siblings-or-parent)))
3698 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3699 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3703 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3704 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3708 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3709 (cdr (assoc "CLOSED" (org-entry-properties))))))
3711 (org-test-with-temp-text "* H"
3712 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3716 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3717 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3721 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3722 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3724 (org-test-with-temp-text "* H"
3725 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3729 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3730 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3734 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3735 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3737 (org-test-with-temp-text "* H"
3738 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3742 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3743 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3746 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3747 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3750 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3751 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3754 (org-test-with-temp-text
3755 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3757 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3758 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3759 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
3761 (equal "<2012-03-29 thu.>"
3762 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
3763 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
3765 (equal "[2012-03-29 thu.]"
3766 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
3767 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
3769 (equal "<2012-03-29 thu.>"
3770 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
3771 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
3773 (equal "[2014-03-04 tue.]"
3774 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
3775 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
3776 ;; Get standard properties.
3779 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3780 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3781 ;; Handle extended properties.
3784 (org-test-with-temp-text
3785 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3786 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3789 (org-test-with-temp-text
3790 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3791 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3792 ;; Ignore forbidden (special) properties.
3794 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3795 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3797 (ert-deftest test-org
/entry-put
()
3798 "Test `org-entry-put' specifications."
3799 ;; Error when not a string or nil.
3801 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3802 (org-entry-put 1 "test" 2)))
3803 ;; Error when property name is invalid.
3805 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3806 (org-entry-put 1 "no space" "value")))
3808 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3809 (org-entry-put 1 "" "value")))
3810 ;; Set "TODO" property.
3812 (string-match (regexp-quote " TODO H")
3813 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3814 (org-entry-put (point) "TODO" "TODO")
3817 (string-match (regexp-quote "* H")
3818 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3819 (org-entry-put (point) "TODO" nil
)
3821 ;; Set "PRIORITY" property.
3824 (org-test-with-temp-text "* [#B] H"
3825 (org-entry-put (point) "PRIORITY" "A")
3829 (org-test-with-temp-text "* [#B] H"
3830 (org-entry-put (point) "PRIORITY" nil
)
3832 ;; Set "SCHEDULED" property.
3834 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3835 (org-test-with-temp-text "* H"
3836 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3840 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3841 (org-entry-put (point) "SCHEDULED" nil
)
3844 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3845 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3846 (org-entry-put (point) "SCHEDULED" "earlier")
3849 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3850 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3851 (org-entry-put (point) "SCHEDULED" "later")
3853 ;; Set "DEADLINE" property.
3855 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3856 (org-test-with-temp-text "* H"
3857 (org-entry-put (point) "DEADLINE" "2014-03-04")
3861 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3862 (org-entry-put (point) "DEADLINE" nil
)
3865 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3866 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3867 (org-entry-put (point) "DEADLINE" "earlier")
3870 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3871 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3872 (org-entry-put (point) "DEADLINE" "later")
3874 ;; Set "CATEGORY" property
3876 (string-match "^ *:CATEGORY: cat"
3877 (org-test-with-temp-text "* H"
3878 (org-entry-put (point) "CATEGORY" "cat")
3880 ;; Regular properties, with or without pre-existing drawer.
3882 (string-match "^ *:A: +2$"
3883 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3884 (org-entry-put (point) "A" "2")
3887 (string-match "^ *:A: +1$"
3888 (org-test-with-temp-text "* H"
3889 (org-entry-put (point) "A" "1")
3891 ;; Special case: two consecutive headlines.
3893 (string-match "\\* A\n *:PROPERTIES:"
3894 (org-test-with-temp-text "* A\n** B"
3895 (org-entry-put (point) "A" "1")
3901 (ert-deftest test-org
/update-radio-target-regexp
()
3902 "Test `org-update-radio-target-regexp' specifications."
3903 ;; Properly update cache with no previous radio target regexp.
3906 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3907 (save-excursion (goto-char (point-max)) (org-element-context))
3909 (search-forward "o")
3911 (org-update-radio-target-regexp)
3912 (goto-char (point-max))
3913 (org-element-type (org-element-context)))))
3914 ;; Properly update cache with previous radio target regexp.
3917 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3918 (save-excursion (goto-char (point-max)) (org-element-context))
3920 (search-forward "o")
3922 (org-update-radio-target-regexp)
3923 (search-backward "r")
3926 (org-update-radio-target-regexp)
3927 (goto-char (point-max))
3928 (delete-region (line-beginning-position) (point))
3930 (org-element-type (org-element-context))))))
3935 (ert-deftest test-org
/match-sparse-tree
()
3936 "Test `org-match-sparse-tree' specifications."
3939 (org-test-with-temp-text "* H\n** H1 :tag:"
3940 (org-match-sparse-tree nil
"tag")
3941 (search-forward "H1")
3942 (org-invisible-p2)))
3944 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3945 (org-match-sparse-tree nil
"tag")
3946 (search-forward "H2")
3947 (org-invisible-p2)))
3948 ;; "-" operator for tags.
3950 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3951 (org-match-sparse-tree nil
"tag1-tag2")
3952 (search-forward "H1")
3953 (org-invisible-p2)))
3955 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3956 (org-match-sparse-tree nil
"tag1-tag2")
3957 (search-forward "H2")
3958 (org-invisible-p2)))
3959 ;; "&" operator for tags.
3961 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3962 (org-match-sparse-tree nil
"tag1&tag2")
3963 (search-forward "H1")
3964 (org-invisible-p2)))
3966 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3967 (org-match-sparse-tree nil
"tag1&tag2")
3968 (search-forward "H2")
3969 (org-invisible-p2)))
3970 ;; "|" operator for tags.
3972 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3973 (org-match-sparse-tree nil
"tag1|tag2")
3974 (search-forward "H1")
3975 (org-invisible-p2)))
3977 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3978 (org-match-sparse-tree nil
"tag1|tag2")
3979 (search-forward "H2")
3980 (org-invisible-p2)))
3981 ;; Regexp match on tags.
3983 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3984 (org-match-sparse-tree nil
"{^tag.*}")
3985 (search-forward "H1")
3986 (org-invisible-p2)))
3988 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3989 (org-match-sparse-tree nil
"{^tag.*}")
3990 (search-forward "H2")
3991 (org-invisible-p2)))
3992 ;; Match group tags.
3994 (org-test-with-temp-text
3995 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3996 (org-match-sparse-tree nil
"work")
3997 (search-forward "H1")
3998 (org-invisible-p2)))
4000 (org-test-with-temp-text
4001 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4002 (org-match-sparse-tree nil
"work")
4003 (search-forward "H2")
4004 (org-invisible-p2)))
4005 ;; Match group tags with hard brackets.
4007 (org-test-with-temp-text
4008 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4009 (org-match-sparse-tree nil
"work")
4010 (search-forward "H1")
4011 (org-invisible-p2)))
4013 (org-test-with-temp-text
4014 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4015 (org-match-sparse-tree nil
"work")
4016 (search-forward "H2")
4017 (org-invisible-p2)))
4018 ;; Match tags in hierarchies
4020 (org-test-with-temp-text
4021 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4022 #+TAGS: [ Lev_2 : Lev_3 ]\n
4023 #+TAGS: { Lev_3 : Lev_4 }\n
4024 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4025 (org-match-sparse-tree nil
"Lev_1")
4026 (search-forward "H4")
4027 (org-invisible-p2)))
4028 ;; Match regular expressions in tags
4030 (org-test-with-temp-text
4031 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4032 (org-match-sparse-tree nil
"Lev")
4033 (search-forward "H1")
4034 (org-invisible-p2)))
4036 (org-test-with-temp-text
4037 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4038 (org-match-sparse-tree nil
"Lev")
4039 (search-forward "H1")
4040 (org-invisible-p2)))
4041 ;; Match properties.
4043 (org-test-with-temp-text
4044 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4045 (org-match-sparse-tree nil
"A=\"1\"")
4046 (search-forward "H2")
4047 (org-invisible-p2)))
4049 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4050 (org-match-sparse-tree nil
"A=\"1\"")
4051 (search-forward "H2")
4052 (org-invisible-p2)))
4053 ;; Case is not significant when matching properties.
4055 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4056 (org-match-sparse-tree nil
"a=\"1\"")
4057 (search-forward "H2")
4058 (org-invisible-p2)))
4060 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4061 (org-match-sparse-tree nil
"A=\"1\"")
4062 (search-forward "H2")
4063 (org-invisible-p2)))
4064 ;; Match special LEVEL property.
4066 (org-test-with-temp-text "* H\n** H1\n*** H2"
4067 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4068 (search-forward "H1")
4069 (org-invisible-p2)))
4071 (org-test-with-temp-text "* H\n** H1\n*** H2"
4072 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4073 (search-forward "H2")
4074 (org-invisible-p2)))
4075 ;; Comparison operators when matching properties.
4077 (org-test-with-temp-text
4078 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4079 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4080 (search-forward "H1")
4081 (org-invisible-p2)))
4083 (org-test-with-temp-text
4084 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4085 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4086 (search-forward "H2")
4087 (org-invisible-p2)))
4088 ;; Regexp match on properties values.
4090 (org-test-with-temp-text
4091 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4092 (org-match-sparse-tree nil
"A={f.*}")
4093 (search-forward "H1")
4094 (org-invisible-p2)))
4096 (org-test-with-temp-text
4097 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4098 (org-match-sparse-tree nil
"A={f.*}")
4099 (search-forward "H2")
4100 (org-invisible-p2)))
4101 ;; With an optional argument, limit match to TODO entries.
4103 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4104 (org-match-sparse-tree t
"tag")
4105 (search-forward "H1")
4106 (org-invisible-p2)))
4108 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4109 (org-match-sparse-tree t
"tag")
4110 (search-forward "H2")
4111 (org-invisible-p2))))
4113 (ert-deftest test-org
/occur
()
4114 "Test `org-occur' specifications."
4115 ;; Count number of matches.
4118 (org-test-with-temp-text "* H\nA\n* H2"
4122 (org-test-with-temp-text "* H\nA\n* H2\nA"
4124 ;; Test CALLBACK optional argument.
4127 (org-test-with-temp-text "* H\nA\n* H2"
4128 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4131 (org-test-with-temp-text "* H\nA\n* H2\nA"
4132 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2")))))))
4137 (ert-deftest test-org
/tag-align
()
4138 "Test `org-align-tags-here' with different display width."
4140 ;; 12345678901234567890
4141 (equal "* Test :abc:"
4142 (org-test-with-temp-text "* Test :abc:"
4143 (let ((org-tags-column -
20)
4144 (indent-tabs-mode nil
))
4145 (org-fix-tags-on-the-fly))
4148 ;; 12345678901234567890
4149 (equal "* Test :日本語:"
4150 (org-test-with-temp-text "* Test :日本語:"
4151 (let ((org-tags-column -
20)
4152 (indent-tabs-mode nil
))
4153 (org-fix-tags-on-the-fly))
4159 (ert-deftest test-org
/time-stamp
()
4160 "Test `org-time-stamp' specifications."
4161 ;; Insert chosen time stamp at point.
4164 "Te<2014-03-04 .*?>xt"
4165 (org-test-with-temp-text "Te<point>xt"
4166 (flet ((org-read-date
4168 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4169 (org-time-stamp nil
)
4171 ;; With a prefix argument, also insert time.
4174 "Te<2014-03-04 .*? 00:41>xt"
4175 (org-test-with-temp-text "Te<point>xt"
4176 (flet ((org-read-date
4178 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
4179 (org-time-stamp '(4))
4181 ;; With two universal prefix arguments, insert an active timestamp
4182 ;; with the current time without prompting the user.
4185 "Te<2014-03-04 .*? 00:41>xt"
4186 (org-test-with-temp-text "Te<point>xt"
4187 (flet ((current-time
4189 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
4190 (org-time-stamp '(16))
4192 ;; When optional argument is non-nil, insert an inactive timestamp.
4195 "Te\\[2014-03-04 .*?\\]xt"
4196 (org-test-with-temp-text "Te<point>xt"
4197 (flet ((org-read-date
4199 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4200 (org-time-stamp nil t
)
4202 ;; When called from a timestamp, replace existing one.
4206 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4207 (flet ((org-read-date
4209 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4210 (org-time-stamp nil
)
4214 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4215 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4216 (flet ((org-read-date
4218 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4219 (org-time-stamp nil
)
4221 ;; When replacing a timestamp, preserve repeater, if any.
4224 "<2014-03-04 .*? \\+2y>"
4225 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4226 (flet ((org-read-date
4228 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4229 (org-time-stamp nil
)
4231 ;; When called twice in a raw, build a date range.
4234 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4235 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4236 (flet ((org-read-date
4238 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
4239 (let ((last-command 'org-time-stamp
)
4240 (this-command 'org-time-stamp
))
4241 (org-time-stamp nil
))
4242 (buffer-string))))))
4244 (ert-deftest test-org
/timestamp-has-time-p
()
4245 "Test `org-timestamp-has-time-p' specifications."
4248 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4249 (org-timestamp-has-time-p (org-element-context))))
4252 (org-test-with-temp-text "<2012-03-29 Thu>"
4253 (org-timestamp-has-time-p (org-element-context)))))
4255 (ert-deftest test-org
/timestamp-format
()
4256 "Test `org-timestamp-format' specifications."
4261 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4262 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4267 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4268 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4270 (ert-deftest test-org
/timestamp-split-range
()
4271 "Test `org-timestamp-split-range' specifications."
4272 ;; Extract range start (active).
4275 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4276 (let ((ts (org-timestamp-split-range (org-element-context))))
4277 (mapcar (lambda (p) (org-element-property p ts
))
4278 '(:year-end
:month-end
:day-end
))))))
4279 ;; Extract range start (inactive)
4282 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4283 (let ((ts (org-timestamp-split-range (org-element-context))))
4284 (mapcar (lambda (p) (org-element-property p ts
))
4285 '(:year-end
:month-end
:day-end
))))))
4286 ;; Extract range end (active).
4289 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4290 (let ((ts (org-timestamp-split-range
4291 (org-element-context) t
)))
4292 (mapcar (lambda (p) (org-element-property p ts
))
4293 '(:year-end
:month-end
:day-end
))))))
4294 ;; Extract range end (inactive)
4297 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4298 (let ((ts (org-timestamp-split-range
4299 (org-element-context) t
)))
4300 (mapcar (lambda (p) (org-element-property p ts
))
4301 '(:year-end
:month-end
:day-end
))))))
4302 ;; Return the timestamp if not a range.
4304 (org-test-with-temp-text "[2012-03-29 Thu]"
4305 (let* ((ts-orig (org-element-context))
4306 (ts-copy (org-timestamp-split-range ts-orig
)))
4307 (eq ts-orig ts-copy
))))
4309 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4310 (let* ((ts-orig (org-element-context))
4311 (ts-copy (org-timestamp-split-range ts-orig
)))
4312 (eq ts-orig ts-copy
)))))
4314 (ert-deftest test-org
/timestamp-translate
()
4315 "Test `org-timestamp-translate' specifications."
4316 ;; Translate whole date range.
4319 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4320 (let ((org-display-custom-times t
)
4321 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4322 (org-timestamp-translate (org-element-context))))))
4323 ;; Translate date range start.
4326 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4327 (let ((org-display-custom-times t
)
4328 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4329 (org-timestamp-translate (org-element-context) 'start
)))))
4330 ;; Translate date range end.
4333 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4334 (let ((org-display-custom-times t
)
4335 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4336 (org-timestamp-translate (org-element-context) 'end
)))))
4337 ;; Translate time range.
4340 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
4341 (let ((org-display-custom-times t
)
4342 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
4343 (org-timestamp-translate (org-element-context))))))
4344 ;; Translate non-range timestamp.
4347 (org-test-with-temp-text "<2012-03-29 Thu>"
4348 (let ((org-display-custom-times t
)
4349 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4350 (org-timestamp-translate (org-element-context))))))
4351 ;; Do not change `diary' timestamps.
4353 (equal "<%%(org-float t 4 2)>"
4354 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4355 (let ((org-display-custom-times t
)
4356 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
4357 (org-timestamp-translate (org-element-context)))))))
4363 (ert-deftest test-org
/flag-drawer
()
4364 "Test `org-flag-drawer' specifications."
4367 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4369 (get-char-property (line-end-position) 'invisible
)))
4372 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4374 (org-flag-drawer nil
)
4375 (get-char-property (line-end-position) 'invisible
)))
4376 ;; Test optional argument.
4378 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4379 (let ((drawer (save-excursion (search-forward ":D2")
4380 (org-element-at-point))))
4381 (org-flag-drawer t drawer
)
4382 (get-char-property (progn (search-forward ":D2") (line-end-position))
4385 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
4386 (let ((drawer (save-excursion (search-forward ":D2")
4387 (org-element-at-point))))
4388 (org-flag-drawer t drawer
)
4389 (get-char-property (line-end-position) 'invisible
))))
4390 ;; Do not hide fake drawers.
4392 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
4395 (get-char-property (line-end-position) 'invisible
)))
4396 ;; Do not hide incomplete drawers.
4398 (org-test-with-temp-text ":D:\nparagraph"
4401 (get-char-property (line-end-position) 'invisible
)))
4402 ;; Do not hide drawers when called from final blank lines.
4404 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
4405 (goto-char (point-max))
4407 (goto-char (point-min))
4408 (get-char-property (line-end-position) 'invisible
)))
4409 ;; Don't leave point in an invisible part of the buffer when hiding
4412 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
4413 (goto-char (point-max))
4415 (get-char-property (point) 'invisible
))))
4417 (ert-deftest test-org
/hide-block-toggle
()
4418 "Test `org-hide-block-toggle' specifications."
4419 ;; Error when not at a block.
4421 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
4422 (org-hide-block-toggle 'off
)
4423 (get-char-property (line-end-position) 'invisible
)))
4426 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
4427 (org-hide-block-toggle)
4428 (get-char-property (line-end-position) 'invisible
)))
4430 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
4431 (org-hide-block-toggle)
4432 (get-char-property (line-end-position) 'invisible
)))
4433 ;; Show block unconditionally when optional argument is `off'.
4435 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4436 (org-hide-block-toggle)
4437 (org-hide-block-toggle 'off
)
4438 (get-char-property (line-end-position) 'invisible
)))
4440 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4441 (org-hide-block-toggle 'off
)
4442 (get-char-property (line-end-position) 'invisible
)))
4443 ;; Hide block unconditionally when optional argument is non-nil.
4445 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4446 (org-hide-block-toggle t
)
4447 (get-char-property (line-end-position) 'invisible
)))
4449 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
4450 (org-hide-block-toggle)
4451 (org-hide-block-toggle t
)
4452 (get-char-property (line-end-position) 'invisible
)))
4453 ;; Do not hide block when called from final blank lines.
4455 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
4456 (org-hide-block-toggle)
4457 (goto-char (point-min))
4458 (get-char-property (line-end-position) 'invisible
)))
4459 ;; Don't leave point in an invisible part of the buffer when hiding
4462 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
4463 (org-hide-block-toggle)
4464 (get-char-property (point) 'invisible
))))
4466 (ert-deftest test-org
/hide-block-toggle-maybe
()
4467 "Test `org-hide-block-toggle-maybe' specifications."
4469 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
4470 (org-hide-block-toggle-maybe)))
4472 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
4474 (ert-deftest test-org
/show-set-visibility
()
4475 "Test `org-show-set-visibility' specifications."
4476 ;; Do not throw an error before first heading.
4478 (org-test-with-temp-text "Preamble\n* Headline"
4479 (org-show-set-visibility 'tree
)
4481 ;; Test all visibility spans, both on headline and in entry.
4482 (let ((list-visible-lines
4483 (lambda (state headerp
)
4484 (org-test-with-temp-text "* Grandmother (0)
4495 **** The other child (11)
4500 (search-forward (if headerp
"Self" "Match"))
4501 (org-show-set-visibility state
)
4502 (goto-char (point-min))
4503 (let (result (line 0))
4505 (unless (org-invisible-p2) (push line result
))
4508 (nreverse result
))))))
4509 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
4510 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
4511 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
4512 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
4513 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
4514 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
4515 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
4516 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
4517 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
4518 (should (equal '(0 1 3 5 7 8 9 11 12 13)
4519 (funcall list-visible-lines
'tree nil
)))
4520 (should (equal '(0 1 3 4 5 7 12 13)
4521 (funcall list-visible-lines
'canonical t
)))
4522 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
4523 (funcall list-visible-lines
'canonical nil
)))))
4528 ;;; test-org.el ends here