1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Template test file for Org-mode tests
30 (ert-deftest test-org
/toggle-comment
()
31 "Test `org-toggle-comment' specifications."
35 (org-test-with-temp-text "* COMMENT Test"
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
43 ;; Headline with a regular keyword.
46 (org-test-with-temp-text "* TODO COMMENT Test"
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
57 (org-test-with-temp-text "* COMMENT"
62 (org-test-with-temp-text "* "
65 ;; Headline with a single keyword.
68 (org-test-with-temp-text "* TODO COMMENT"
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
76 ;; Headline with a keyword, a priority cookie and contents.
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
88 (ert-deftest test-org
/comment-dwim
()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim
)
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim
)
104 ;; No region selected, and a comment on this line: indent it.
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t
))
110 (call-interactively 'comment-dwim
))
112 ;; Also recognize single # at column 0 as comments.
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim
)
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
125 (transient-mark-mode 1)
126 (push-mark (point) t t
)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim
)
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
136 (transient-mark-mode 1)
137 (push-mark (point) t t
)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil
))
140 (call-interactively 'comment-dwim
))
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
146 (transient-mark-mode 1)
147 (push-mark (point) t t
)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t
))
150 (call-interactively 'comment-dwim
))
152 ;; In front of a keyword without region, insert a new comment.
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim
)
158 ;; In a source block, use appropriate syntax.
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim
))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
170 (transient-mark-mode 1)
171 (push-mark (point) t t
)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim
))
179 ;;; Date and time analysis
181 (ert-deftest test-org
/org-read-date
()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t
))
186 (org-read-date t nil
"12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t
))
190 (org-read-date t nil
"29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t
))
194 (org-read-date t nil
"29.03. 16:40"))))
195 ;; Relative date applied to current time if there is single
196 ;; plus/minus, or to default date when there are two of them.
200 (flet ((current-time () (apply #'encode-time
201 (org-parse-time-string "2014-03-04"))))
204 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
208 (flet ((current-time () (apply #'encode-time
209 (org-parse-time-string "2014-03-04"))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (flet ((current-time () (apply #'encode-time
220 (org-parse-time-string "2014-03-04"))))
221 (let ((org-read-date-prefer-future t
))
222 (org-read-date t nil
"1")))))
226 (flet ((current-time () (apply #'encode-time
227 (org-parse-time-string "2012-03-29"))))
228 (let ((org-read-date-prefer-future t
))
229 (org-read-date t nil
"3-4")))))
233 (flet ((current-time () (apply #'encode-time
234 (org-parse-time-string "2012-03-29"))))
235 (let ((org-read-date-prefer-future nil
))
236 (org-read-date t nil
"3-4")))))
237 ;; When set to `org-read-date-prefer-future' is set to `time', read
238 ;; day is moved to tomorrow if specified hour is before current
239 ;; time. However, it only happens in no other part of the date is
244 (flet ((current-time () (apply #'encode-time
245 (org-parse-time-string "2012-03-29 16:40"))))
246 (let ((org-read-date-prefer-future 'time
))
247 (org-read-date t nil
"00:40" nil
)))))
251 (flet ((current-time () (apply #'encode-time
252 (org-parse-time-string "2012-03-29 16:40"))))
253 (let ((org-read-date-prefer-future 'time
))
254 (org-read-date t nil
"29 00:40" nil
)))))
255 ;; Caveat: `org-read-date-prefer-future' always refers to current
256 ;; time, not default time, when they differ.
261 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
262 (let ((org-read-date-prefer-future t
))
265 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
270 () (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
271 (let ((org-read-date-prefer-future t
))
274 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
276 (ert-deftest test-org
/org-parse-time-string
()
277 "Test `org-parse-time-string'."
278 (should (equal (org-parse-time-string "2012-03-29 16:40")
279 '(0 40 16 29 3 2012 nil nil nil
)))
280 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
281 '(0 40 16 29 3 2012 nil nil nil
)))
282 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
283 '(0 40 16 29 3 2012 nil nil nil
)))
284 (should (equal (org-parse-time-string "<2012-03-29>")
285 '(0 0 0 29 3 2012 nil nil nil
)))
286 (should (equal (org-parse-time-string "<2012-03-29>" t
)
287 '(0 nil nil
29 3 2012 nil nil nil
))))
292 (ert-deftest test-org
/insert-property-drawer
()
293 "Test `org-insert-property-drawer' specifications."
294 ;; Error before first headline.
295 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
296 ;; Insert drawer right after headline if there is no planning line,
297 ;; or after it otherwise.
299 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
300 (org-test-with-temp-text "* H\nParagraph<point>"
301 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
304 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
305 (org-test-with-temp-text
306 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
307 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
309 ;; Indent inserted drawer.
311 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
312 (org-test-with-temp-text "* H\nParagraph<point>"
313 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
315 ;; Handle insertion at eob.
317 (equal "* H\n:PROPERTIES:\n:END:\n"
318 (org-test-with-temp-text "* H"
319 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
321 ;; Skip inlinetasks before point.
322 (when (featurep 'org-inlinetask
)
324 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
325 (org-test-with-temp-text
326 "* H\n*************** I\n*************** END\nP<point>"
327 (let ((org-adapt-indentation nil
)
328 (org-inlinetask-min-level 15))
329 (org-insert-property-drawer))
331 ;; Correctly set drawer in an inlinetask.
332 (when (featurep 'org-inlinetask
)
334 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
335 (org-test-with-temp-text
336 "* H\n*************** I\nP<point>\n*************** END"
337 (let ((org-adapt-indentation nil
)
338 (org-inlinetask-min-level 15))
339 (org-insert-property-drawer))
345 (ert-deftest test-org
/fill-paragraph
()
346 "Test `org-fill-paragraph' specifications."
347 ;; At an Org table, align it.
350 (org-test-with-temp-text "|a|"
354 (equal "#+name: table\n| a |\n"
355 (org-test-with-temp-text "#+name: table\n| a |"
358 ;; At a paragraph, preserve line breaks.
359 (org-test-with-temp-text "some \\\\\nlong\ntext"
360 (let ((fill-column 20))
362 (should (equal (buffer-string) "some \\\\\nlong text"))))
363 ;; Correctly fill a paragraph when point is at its very end.
366 (org-test-with-temp-text "A\nB"
367 (let ((fill-column 20))
368 (goto-char (point-max))
371 ;; Correctly fill the last paragraph of a greater element.
373 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
374 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
375 (let ((fill-column 8))
380 ;; Correctly fill an element in a narrowed buffer.
383 (org-test-with-temp-text "01234 6789"
384 (let ((fill-column 5))
385 (narrow-to-region 1 8)
388 ;; Handle `adaptive-fill-regexp' in paragraphs.
391 (org-test-with-temp-text "> a\n> b"
392 (let ((fill-column 5)
393 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
396 ;; Special case: Fill first paragraph when point is at an item or
397 ;; a plain-list or a footnote reference.
400 (org-test-with-temp-text "- A\n B"
401 (let ((fill-column 20))
406 (org-test-with-temp-text "[fn:1] A\nB"
407 (let ((fill-column 20))
410 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
411 (let ((fill-column 20))
413 (should (equal (buffer-string)
414 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
415 ;; Fill contents of `comment-block' elements.
418 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
419 (let ((fill-column 20))
423 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
424 ;; Fill `comment' elements.
427 (org-test-with-temp-text " # A\n # B"
428 (let ((fill-column 20))
431 ;; Do not mix consecutive comments when filling one of them.
433 (equal "# A B\n\n# C"
434 (org-test-with-temp-text "# A\n# B\n\n# C"
435 (let ((fill-column 20))
438 ;; Use commented empty lines as separators when filling comments.
440 (equal "# A B\n#\n# C"
441 (org-test-with-temp-text "# A\n# B\n#\n# C"
442 (let ((fill-column 20))
445 ;; Handle `adaptive-fill-regexp' in comments.
448 (org-test-with-temp-text "# > a\n# > b"
449 (let ((fill-column 20)
450 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
453 ;; Do nothing at affiliated keywords.
454 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
455 (let ((fill-column 20))
457 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
458 ;; Do not move point after table when filling a table.
460 (org-test-with-temp-text "| a | b |\n| c | d |\n"
465 (ert-deftest test-org
/auto-fill-function
()
466 "Test auto-filling features."
467 ;; Auto fill paragraph.
470 (org-test-with-temp-text "12345 7890"
471 (let ((fill-column 5))
473 (org-auto-fill-function)
475 ;; Auto fill first paragraph in an item.
477 (equal "- 12345\n 7890"
478 (org-test-with-temp-text "- 12345 7890"
479 (let ((fill-column 7))
481 (org-auto-fill-function)
483 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
485 (equal "> 12345\n 7890"
486 (org-test-with-temp-text "> 12345 7890"
487 (let ((fill-column 10)
488 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
489 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
491 (org-auto-fill-function)
494 (equal "> 12345\n> 12345\n> 7890"
495 (org-test-with-temp-text "> 12345\n> 12345 7890"
496 (let ((fill-column 10)
497 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
498 (goto-char (point-max))
499 (org-auto-fill-function)
502 (equal " 12345\n *12345\n *12345"
503 (org-test-with-temp-text " 12345\n *12345 12345"
504 (let ((fill-column 10)
505 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
506 (goto-char (point-max))
507 (org-auto-fill-function)
509 ;; Auto fill comments.
511 (equal " # 12345\n # 7890"
512 (org-test-with-temp-text " # 12345 7890"
513 (let ((fill-column 10))
515 (org-auto-fill-function)
517 ;; A hash within a line isn't a comment.
519 (equal "12345 # 7890\n# 1"
520 (org-test-with-temp-text "12345 # 7890 1"
521 (let ((fill-column 12))
523 (org-auto-fill-function)
525 ;; Correctly interpret empty prefix.
527 (equal "# a\n# b\nRegular\n# paragraph"
528 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
529 (let ((fill-column 12))
531 (org-auto-fill-function)
533 ;; Comment block: auto fill contents.
535 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
536 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
537 (let ((fill-column 5))
540 (org-auto-fill-function)
543 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
544 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
545 (let ((fill-column 5))
548 (org-auto-fill-function)
550 ;; Do not fill if a new item could be created.
553 (org-test-with-temp-text "12345 - 90"
554 (let ((fill-column 5))
556 (org-auto-fill-function)
558 ;; Do not fill if a line break could be introduced.
560 (equal "123\\\\\n7890"
561 (org-test-with-temp-text "123\\\\ 7890"
562 (let ((fill-column 6))
564 (org-auto-fill-function)
566 ;; Do not fill affiliated keywords.
568 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
569 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
570 (let ((fill-column 20))
572 (org-auto-fill-function)
579 (ert-deftest test-org
/indent-line
()
580 "Test `org-indent-line' specifications."
581 ;; Do not indent diary sexps, footnote definitions or headlines.
584 (org-test-with-temp-text "%%(org-calendar-holiday)"
586 (org-get-indentation))))
589 (org-test-with-temp-text "[fn:1] fn"
590 (let ((org-adapt-indentation t
)) (org-indent-line))
591 (org-get-indentation))))
594 (org-test-with-temp-text "* H"
596 (org-get-indentation))))
597 ;; Do not indent before first headline.
600 (org-test-with-temp-text ""
602 (org-get-indentation))))
603 ;; Indent according to headline level otherwise, unless
604 ;; `org-adapt-indentation' is nil.
607 (org-test-with-temp-text "* H\nA"
609 (let ((org-adapt-indentation t
)) (org-indent-line))
610 (org-get-indentation))))
613 (org-test-with-temp-text "* H\n\nA"
615 (let ((org-adapt-indentation t
)) (org-indent-line))
616 (org-get-indentation))))
619 (org-test-with-temp-text "* H\nA"
621 (let ((org-adapt-indentation nil
)) (org-indent-line))
622 (org-get-indentation))))
623 ;; Indenting preserves point position.
625 (org-test-with-temp-text "* H\nAB"
628 (let ((org-adapt-indentation t
)) (org-indent-line))
630 ;; Do not change indentation at an item.
633 (org-test-with-temp-text "* H\n - A"
635 (let ((org-adapt-indentation t
)) (org-indent-line))
636 (org-get-indentation))))
637 ;; On blank lines at the end of a list, indent like last element
638 ;; within it if the line is still in the list. If the last element
639 ;; is an item, indent like its contents. Otherwise, indent like the
643 (org-test-with-temp-text "* H\n- A\n - AA\n"
644 (goto-char (point-max))
645 (let ((org-adapt-indentation t
)) (org-indent-line))
646 (org-get-indentation))))
649 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
650 (goto-char (point-max))
651 (let ((org-adapt-indentation t
)) (org-indent-line))
652 (org-get-indentation))))
655 (org-test-with-temp-text "* H\n- A\n - \n"
656 (goto-char (point-max))
657 (let ((org-adapt-indentation t
)) (org-indent-line))
658 (org-get-indentation))))
659 ;; Likewise, on a blank line at the end of a footnote definition,
660 ;; indent at column 0 if line belongs to the definition. Otherwise,
661 ;; indent like the definition itself.
664 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
665 (goto-char (point-max))
666 (let ((org-adapt-indentation t
)) (org-indent-line))
667 (org-get-indentation))))
670 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
671 (goto-char (point-max))
672 (let ((org-adapt-indentation t
)) (org-indent-line))
673 (org-get-indentation))))
674 ;; After the end of the contents of a greater element, indent like
675 ;; the beginning of the element.
678 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
681 (org-get-indentation))))
682 ;; On blank lines after a paragraph, indent like its last non-empty
686 (org-test-with-temp-text " Paragraph\n\n<point>"
688 (org-get-indentation))))
689 ;; At the first line of an element, indent like previous element's
690 ;; first line, ignoring footnotes definitions and inline tasks, or
691 ;; according to parent.
694 (org-test-with-temp-text "A\n\n B\n\nC"
695 (goto-char (point-max))
697 (org-get-indentation))))
700 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
701 (goto-char (point-max))
703 (org-get-indentation))))
706 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
709 (org-get-indentation))))
710 ;; Within code part of a source block, use language major mode if
711 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
712 ;; according to line above.
715 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
717 (let ((org-src-tab-acts-natively t
)
718 (org-edit-src-content-indentation 0))
720 (org-get-indentation))))
723 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
725 (let ((org-src-tab-acts-natively nil
)
726 (org-edit-src-content-indentation 0))
728 (org-get-indentation))))
729 ;; Otherwise, indent like the first non-blank line above.
732 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
735 (org-get-indentation))))
736 ;; Align node properties according to `org-property-format'. Handle
737 ;; nicely empty values.
739 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
740 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
741 (let ((org-property-format "%-10s %s")) (org-indent-line))
744 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
745 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
746 (let ((org-property-format "%-10s %s")) (org-indent-line))
749 (ert-deftest test-org
/indent-region
()
750 "Test `org-indent-region' specifications."
754 (org-test-with-temp-text " A\nB\n C"
755 (org-indent-region (point-min) (point-max))
757 ;; Indent greater elements along with their contents.
759 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
760 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
761 (org-indent-region (point-min) (point-max))
763 ;; Ignore contents of verse blocks and example blocks.
765 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
766 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
767 (org-indent-region (point-min) (point-max))
770 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
771 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
772 (org-indent-region (point-min) (point-max))
774 ;; Indent according to mode if `org-src-tab-acts-natively' is
775 ;; non-nil. Otherwise, do not indent code at all.
777 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
778 (org-test-with-temp-text
779 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
780 (let ((org-src-tab-acts-natively t
)
781 (org-edit-src-content-indentation 0))
782 (org-indent-region (point-min) (point-max)))
785 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
786 (org-test-with-temp-text
787 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
788 (let ((org-src-tab-acts-natively nil
)
789 (org-edit-src-content-indentation 0))
790 (org-indent-region (point-min) (point-max)))
792 ;; Align node properties according to `org-property-format'. Handle
793 ;; nicely empty values.
795 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
796 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
797 (let ((org-property-format "%-10s %s")
798 (org-adapt-indentation nil
))
799 (org-indent-region (point) (point-max)))
802 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
803 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
804 (let ((org-property-format "%-10s %s")
805 (org-adapt-indentation nil
))
806 (org-indent-region (point) (point-max)))
808 ;; Indent plain lists.
810 (equal "- A\n B\n - C\n\n D"
811 (org-test-with-temp-text "- A\n B\n - C\n\n D"
812 (org-indent-region (point-min) (point-max))
816 (org-test-with-temp-text " - A\n\n - B"
817 (org-indent-region (point-min) (point-max))
819 ;; Indent footnote definitions.
821 (equal "[fn:1] Definition\n\nDefinition"
822 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
823 (org-indent-region (point-min) (point-max))
825 ;; Special case: Start indenting on a blank line.
828 (org-test-with-temp-text "\n Paragraph"
829 (org-indent-region (point-min) (point-max))
836 (ert-deftest test-org
/delete-indentation
()
837 "Test `org-delete-indentation' specifications."
839 (should (equal "foo bar"
840 (org-test-with-temp-text
842 (org-delete-indentation)
844 ;; With optional argument.
845 (should (equal "foo bar"
846 (org-test-with-temp-text
848 (org-delete-indentation t
)
850 ;; At headline text should be appended to the headline text.
852 (equal"* foo bar :tag:"
853 (let (org-auto-align-tags)
854 (org-test-with-temp-text
855 "* foo :tag:\n bar<point>"
856 (org-delete-indentation)
859 (equal "* foo bar :tag:"
860 (let (org-auto-align-tags)
861 (org-test-with-temp-text
862 "* foo <point>:tag:\n bar"
863 (org-delete-indentation t
)
866 (ert-deftest test-org
/return
()
867 "Test `org-return' specifications."
871 (org-test-with-temp-text "Para<point>graph"
874 ;; With optional argument, indent line.
876 (equal " Para\n graph"
877 (org-test-with-temp-text " Para<point>graph"
880 ;; On a table, call `org-table-next-row'.
882 (org-test-with-temp-text "| <point>a |\n| b |"
884 (org-looking-at-p "b")))
885 ;; Open link or timestamp under point when `org-return-follows-link'
888 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
889 (let ((org-return-follows-link t
)) (org-return))
890 (org-looking-at-p "<<target>>")))
892 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
893 (let ((org-return-follows-link nil
)) (org-return))
894 (org-looking-at-p "<<target>>")))
895 ;; However, do not open link when point is in a table.
897 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
898 (let ((org-return-follows-link t
)) (org-return))
899 (org-looking-at-p "between")))
900 ;; Special case: in a list, when indenting, do not break structure.
903 (org-test-with-temp-text "- A <point>B"
908 (org-test-with-temp-text "- A\n<point>- B"
911 ;; On tags part of a headline, add a newline below it instead of
915 (org-test-with-temp-text "* H :<point>tag:"
918 ;; Before headline text, add a newline below it instead of breaking
921 (equal "* TODO H :tag:\n"
922 (org-test-with-temp-text "* <point>TODO H :tag:"
926 (equal "* TODO [#B] H :tag:\n"
927 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
930 ;; At headline text, break headline text but preserve tags.
932 (equal "* TODO [#B] foo :tag:\nbar"
933 (let (org-auto-align-tags)
934 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
937 ;; At bol of headline insert newline.
940 (org-test-with-temp-text "<point>* h"
944 (ert-deftest test-org
/meta-return
()
945 "Test M-RET (`org-meta-return') specifications."
946 ;; In a table field insert a row above.
948 (org-test-with-temp-text "| a |"
952 (looking-at "| |$")))
953 ;; In a paragraph change current line into a header.
955 (org-test-with-temp-text "a"
958 (looking-at "\* a$")))
959 ;; In an item insert an item, in this case above.
961 (org-test-with-temp-text "- a"
965 ;; In a drawer and item insert an item, in this case above.
967 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
971 (looking-at "- $"))))
973 (ert-deftest test-org
/insert-heading
()
974 "Test `org-insert-heading' specifications."
975 ;; In an empty buffer, insert a new headline.
978 (org-test-with-temp-text ""
981 ;; At the beginning of a line, turn it into a headline
984 (org-test-with-temp-text "<point>P"
987 ;; In the middle of a line, split the line if allowed, otherwise,
988 ;; insert the headline at its end.
990 (equal "Para\n* graph"
991 (org-test-with-temp-text "Para<point>graph"
992 (let ((org-M-RET-may-split-line '((default . t
))))
993 (org-insert-heading))
996 (equal "Paragraph\n* "
997 (org-test-with-temp-text "Para<point>graph"
998 (let ((org-M-RET-may-split-line '((default . nil
))))
999 (org-insert-heading))
1001 ;; When on a list, insert an item instead, unless called with an
1002 ;; universal argument or if list is invisible. In this case, create
1003 ;; a new headline after contents.
1005 (equal "* H\n- item\n- "
1006 (org-test-with-temp-text "* H\n- item<point>"
1007 (let ((org-insert-heading-respect-content nil
))
1008 (org-insert-heading))
1011 (equal "* H\n- item\n- item 2\n* "
1012 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1013 (let ((org-insert-heading-respect-content nil
))
1014 (org-insert-heading '(4)))
1017 (equal "* H\n- item\n* "
1018 (org-test-with-temp-text "* H\n- item"
1020 (goto-char (point-max))
1021 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
1023 ;; When called with two universal arguments, insert a new headline
1024 ;; at the end of the grandparent subtree.
1026 (equal "* H1\n** H3\n- item\n** H2\n** "
1027 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1028 (let ((org-insert-heading-respect-content nil
))
1029 (org-insert-heading '(16)))
1031 ;; When optional TOP-LEVEL argument is non-nil, always insert
1032 ;; a level 1 heading.
1034 (equal "* H1\n** H2\n* "
1035 (org-test-with-temp-text "* H1\n** H2<point>"
1036 (org-insert-heading nil nil t
)
1039 (equal "* H1\n- item\n* "
1040 (org-test-with-temp-text "* H1\n- item<point>"
1041 (org-insert-heading nil nil t
)
1043 ;; Corner case: correctly insert a headline after an empty one.
1046 (org-test-with-temp-text "* <point>"
1047 (org-insert-heading)
1050 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1051 "Test `org-insert-todo-heading-respect-content' specifications."
1052 ;; Create a TODO heading.
1054 (org-test-with-temp-text "* H1\n Body"
1055 (org-insert-todo-heading-respect-content)
1056 (nth 2 (org-heading-components))))
1057 ;; Add headline at the end of the first subtree
1059 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1060 (search-forward "H1Body")
1061 (org-insert-todo-heading-respect-content)
1062 (and (eobp) (org-at-heading-p))))
1063 ;; In a list, do not create a new item.
1065 (org-test-with-temp-text "* H\n- an item\n- another one"
1066 (search-forward "an ")
1067 (org-insert-todo-heading-respect-content)
1068 (and (eobp) (org-at-heading-p)))))
1072 ;;; Fixed-Width Areas
1074 (ert-deftest test-org
/toggle-fixed-width
()
1075 "Test `org-toggle-fixed-width' specifications."
1076 ;; No region: Toggle on fixed-width marker in paragraphs.
1079 (org-test-with-temp-text "A"
1080 (org-toggle-fixed-width)
1082 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1085 (org-test-with-temp-text ": A"
1086 (org-toggle-fixed-width)
1088 ;; No region: Toggle on marker in blank lines after elements or just
1089 ;; after a headline.
1092 (org-test-with-temp-text "* H\n"
1094 (org-toggle-fixed-width)
1097 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1098 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1099 (goto-char (point-max))
1100 (org-toggle-fixed-width)
1102 ;; No region: Toggle on marker in front of one line elements (e.g.,
1103 ;; headlines, clocks)
1105 (equal ": * Headline"
1106 (org-test-with-temp-text "* Headline"
1107 (org-toggle-fixed-width)
1110 (equal ": #+KEYWORD: value"
1111 (org-test-with-temp-text "#+KEYWORD: value"
1112 (org-toggle-fixed-width)
1114 ;; No region: error in other situations.
1116 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1118 (org-toggle-fixed-width)
1120 ;; No region: Indentation is preserved.
1123 (org-test-with-temp-text "- A\n B"
1125 (org-toggle-fixed-width)
1127 ;; Region: If it contains only fixed-width elements and blank lines,
1128 ;; toggle off fixed-width markup.
1131 (org-test-with-temp-text ": A\n\n: B"
1132 (transient-mark-mode 1)
1133 (push-mark (point) t t
)
1134 (goto-char (point-max))
1135 (org-toggle-fixed-width)
1137 ;; Region: If it contains anything else, toggle on fixed-width but
1138 ;; not on fixed-width areas.
1140 (equal ": A\n: \n: B\n: \n: C"
1141 (org-test-with-temp-text "A\n\n: B\n\nC"
1142 (transient-mark-mode 1)
1143 (push-mark (point) t t
)
1144 (goto-char (point-max))
1145 (org-toggle-fixed-width)
1147 ;; Region: Ignore blank lines at its end, unless it contains only
1151 (org-test-with-temp-text "A\n\n"
1152 (transient-mark-mode 1)
1153 (push-mark (point) t t
)
1154 (goto-char (point-max))
1155 (org-toggle-fixed-width)
1159 (org-test-with-temp-text "\n\n"
1160 (transient-mark-mode 1)
1161 (push-mark (point) t t
)
1162 (goto-char (point-max))
1163 (org-toggle-fixed-width)
1170 (ert-deftest test-org
/in-commented-heading-p
()
1171 "Test `org-in-commented-heading-p' specifications."
1172 ;; Commented headline.
1174 (org-test-with-temp-text "* COMMENT Headline\nBody"
1175 (goto-char (point-max))
1176 (org-in-commented-heading-p)))
1177 ;; Commented ancestor.
1179 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1180 (goto-char (point-max))
1181 (org-in-commented-heading-p)))
1182 ;; Comment keyword is case-sensitive.
1184 (org-test-with-temp-text "* Comment Headline\nBody"
1185 (goto-char (point-max))
1186 (org-in-commented-heading-p)))
1187 ;; Keyword is standalone.
1189 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1190 (goto-char (point-max))
1191 (org-in-commented-heading-p)))
1192 ;; Optional argument.
1194 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1195 (goto-char (point-max))
1196 (org-in-commented-heading-p t
))))
1202 (ert-deftest test-org
/set-regexps-and-options
()
1203 "Test `org-set-regexps-and-options' specifications."
1206 (equal '(("A" . ?a
) ("B") ("C"))
1207 (org-test-with-temp-text "#+TAGS: A(a) B C"
1211 (equal '(("A") (:newline
) ("B"))
1212 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1216 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1217 (org-test-with-temp-text "#+TAGS: { A B } C"
1221 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1222 (org-test-with-temp-text "#+TAGS: { A : B C }"
1226 (equal '(("A" "B" "C"))
1227 (org-test-with-temp-text "#+TAGS: { A : B C }"
1229 org-tag-groups-alist
)))
1231 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1232 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1236 (equal '(("A" "B" "C"))
1237 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1239 org-tag-groups-alist
)))
1240 ;; FILETAGS keyword.
1242 (equal '("A" "B" "C")
1243 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1246 ;; PROPERTY keyword. Property names are case-insensitive.
1249 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1251 (cdr (assoc "var" org-file-properties
)))))
1255 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1257 (cdr (assoc "var" org-file-properties
)))))
1261 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1263 (cdr (assoc "var" org-file-properties
)))))
1267 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1269 org-archive-location
)))
1270 ;; CATEGORY keyword.
1273 (org-test-with-temp-text "#+CATEGORY: test"
1278 (org-test-with-temp-text "#+CATEGORY: test"
1280 (cdr (assoc "CATEGORY" org-file-properties
)))))
1283 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1284 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1286 org-columns-default-format
)))
1287 ;; CONSTANTS keyword. Constants names are case sensitive.
1289 (equal '("299792458." "3.14")
1290 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1293 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1297 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1299 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1302 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1304 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1309 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1311 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1313 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1317 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1319 (list org-highest-priority org-lowest-priority org-default-priority
))))
1323 (org-test-with-temp-text "#+PRIORITIES: X Z"
1325 (list org-highest-priority org-lowest-priority org-default-priority
))))
1329 (org-test-with-temp-text "#+STARTUP: fold odd"
1331 (list org-startup-folded org-odd-levels-only
))))
1334 (equal '(("A" "B") ("C"))
1335 (org-test-with-temp-text "#+TODO: A B | C"
1337 (list org-not-done-keywords org-done-keywords
))))
1339 (equal '(("A" "C") ("B" "D"))
1340 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1342 (list org-not-done-keywords org-done-keywords
))))
1344 (equal '(("A" "B") ("C"))
1345 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1347 (list org-not-done-keywords org-done-keywords
))))
1349 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1350 (org-test-with-temp-text "#+TODO: A(a)"
1352 org-todo-key-alist
)))
1354 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1355 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1357 org-todo-log-states
)))
1358 ;; Enter SETUPFILE keyword.
1361 (org-test-with-temp-text
1362 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1364 (cdr (assoc "a" org-file-properties
))))))
1372 (ert-deftest test-org
/coderef
()
1373 "Test coderef links specifications."
1375 (org-test-with-temp-text "
1376 #+BEGIN_SRC emacs-lisp
1380 (goto-char (point-max))
1382 (looking-at "(ref:sc)"))))
1386 (ert-deftest test-org
/custom-id
()
1387 "Test custom ID links specifications."
1389 (org-test-with-temp-text
1390 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1391 (goto-char (point-max))
1393 (org-looking-at-p "\\* H1")))
1394 ;; Ignore false positives.
1396 (org-test-with-temp-text
1397 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1398 (goto-char (point-max))
1399 (let (org-link-search-must-match-exact-headline) (org-open-at-point))
1400 (org-looking-at-p "\\* H1"))))
1404 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1405 ;; a named element (#+name: text) and to headlines (* Text).
1407 (ert-deftest test-org
/fuzzy-links
()
1408 "Test fuzzy links specifications."
1409 ;; Fuzzy link goes in priority to a matching target.
1411 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1414 (looking-at "<<Test>>")))
1415 ;; Then fuzzy link points to an element with a given name.
1417 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1420 (looking-at "#\\+NAME: Test")))
1421 ;; A target still lead to a matching headline otherwise.
1423 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1426 (looking-at "\\* Head2")))
1427 ;; With a leading star in link, enforce heading match.
1429 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1432 (looking-at "\\* Test")))
1433 ;; With a leading star in link, enforce exact heading match, even
1434 ;; with `org-link-search-must-match-exact-headline' set to nil.
1436 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1437 (let ((org-link-search-must-match-exact-headline nil
))
1438 (org-open-at-point))))
1439 ;; Heading match should not care about spaces, cookies, todo
1440 ;; keywords, priorities, and tags.
1443 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1444 (org-test-with-temp-text
1445 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1446 (let ((org-link-search-must-match-exact-headline nil
)
1447 (org-todo-regexp "TODO"))
1448 (org-open-at-point))
1449 (looking-at (regexp-quote first-line
)))))
1450 ;; Heading match should still be exact.
1453 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1454 (org-test-with-temp-text
1455 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1456 (let ((org-link-search-must-match-exact-headline nil
)
1457 (org-todo-regexp "TODO"))
1458 (org-open-at-point)))))
1459 ;; Heading match ignores COMMENT keyword.
1461 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1463 (looking-at "\\* COMMENT Test")))
1464 ;; Correctly un-hexify fuzzy links.
1466 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1467 (goto-char (point-max))
1473 (ert-deftest test-org
/org-link-escape-ascii-character
()
1474 "Escape an ascii character."
1478 (org-link-escape "["))))
1480 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1481 "Escape an ascii control character."
1485 (org-link-escape "\t"))))
1487 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1488 "Escape an unicode multibyte character."
1492 (org-link-escape "€"))))
1494 (ert-deftest test-org
/org-link-escape-custom-table
()
1495 "Escape string with custom character table."
1499 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1501 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1502 "Escape string with custom table merged with default table."
1505 "%5BF%6F%6F%3A%42ar%0A%5D"
1506 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1508 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1509 "Unescape an ascii character."
1513 (org-link-unescape "%5B"))))
1515 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1516 "Unescpae an ascii control character."
1520 (org-link-unescape "%0A"))))
1522 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1523 "Unescape unicode multibyte character."
1527 (org-link-unescape "%E2%82%AC"))))
1529 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1530 "Unescape old style percent escaped character."
1533 "à âçèéêîôùû"
1534 (decode-coding-string
1535 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1537 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1538 "Escape and unescape a URL that includes an escaped char.
1539 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1542 "http://some.host.com/form?&id=blah%2Bblah25"
1544 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1546 (ert-deftest test-org
/org-link-escape-chars-browser
()
1547 "Test of the constant `org-link-escape-chars-browser'.
1548 See there why this test is a candidate to be removed once Org
1549 drops support for Emacs 24.1 and 24.2."
1552 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1553 "%22Release%208.2%22&idxname=emacs-orgmode")
1554 (org-link-escape-browser ; Do not replace with `url-encode-url',
1555 ; see docstring above.
1556 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1557 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1561 (ert-deftest test-org
/open-at-point-in-keyword
()
1562 "Does `org-open-at-point' open link in a keyword line?"
1564 (org-test-with-temp-text
1565 "#+KEYWORD: <point>[[info:emacs#Top]]"
1566 (org-open-at-point) t
)))
1568 (ert-deftest test-org
/open-at-point-in-property
()
1569 "Does `org-open-at-point' open link in property drawer?"
1571 (org-test-with-temp-text
1574 :URL: <point>[[info:emacs#Top]]
1576 (org-open-at-point) t
)))
1578 (ert-deftest test-org
/open-at-point-in-comment
()
1579 "Does `org-open-at-point' open link in a commented line?"
1581 (org-test-with-temp-text
1582 "# <point>[[info:emacs#Top]]"
1583 (org-open-at-point) t
)))
1585 (ert-deftest test-org
/open-at-point
/info
()
1586 "Test `org-open-at-point' on info links."
1588 (org-test-with-temp-text
1589 "<point>[[info:emacs#Top]]"
1591 (and (switch-to-buffer "*info*")
1593 (looking-at "\nThe Emacs Editor")
1596 (ert-deftest test-org
/open-at-point
/inline-image
()
1597 "Test `org-open-at-point' on nested links."
1599 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1601 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1602 (kill-buffer "*info*")))))
1607 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1608 "Ensure properties accumulate in subtree drawers."
1609 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1610 (org-babel-next-src-block)
1611 (should (equal '(2 1) (org-babel-execute-src-block)))))
1613 (ert-deftest test-org
/custom-properties
()
1614 "Test custom properties specifications."
1617 (let ((org-custom-properties '("FOO")))
1618 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1619 (org-toggle-custom-properties-visibility)
1620 (org-invisible-p2))))
1621 ;; Properties are case-insensitive.
1623 (let ((org-custom-properties '("FOO")))
1624 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1625 (org-toggle-custom-properties-visibility)
1626 (org-invisible-p2))))
1628 (let ((org-custom-properties '("foo")))
1629 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1630 (org-toggle-custom-properties-visibility)
1631 (org-invisible-p2))))
1632 ;; Multiple custom properties in the same drawer.
1634 (let ((org-custom-properties '("FOO" "BAR")))
1635 (org-test-with-temp-text
1636 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1637 (org-toggle-custom-properties-visibility)
1638 (and (org-invisible-p2)
1639 (not (progn (forward-line) (org-invisible-p2)))
1640 (progn (forward-line) (org-invisible-p2))))))
1641 ;; Hide custom properties with an empty value.
1643 (let ((org-custom-properties '("FOO")))
1644 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1645 (org-toggle-custom-properties-visibility)
1646 (org-invisible-p2))))
1647 ;; Do not hide fake properties.
1649 (let ((org-custom-properties '("FOO")))
1650 (org-test-with-temp-text ":FOO: val\n"
1651 (org-toggle-custom-properties-visibility)
1652 (org-invisible-p2))))
1654 (let ((org-custom-properties '("A")))
1655 (org-test-with-temp-text
1656 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1657 (org-toggle-custom-properties-visibility)
1658 (org-invisible-p2)))))
1664 (ert-deftest test-org
/mark-subtree
()
1665 "Test `org-mark-subtree' specifications."
1666 ;; Error when point is before first headline.
1668 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1669 (progn (transient-mark-mode 1)
1670 (org-mark-subtree))))
1671 ;; Without argument, mark current subtree.
1675 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1676 (progn (transient-mark-mode 1)
1679 (list (region-beginning) (region-end))))))
1680 ;; With an argument, move ARG up.
1684 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1685 (progn (transient-mark-mode 1)
1687 (org-mark-subtree 1)
1688 (list (region-beginning) (region-end))))))
1689 ;; Do not get fooled by inlinetasks.
1690 (when (featurep 'org-inlinetask
)
1693 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1694 (progn (transient-mark-mode 1)
1696 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1697 (region-beginning)))))))
1703 (ert-deftest test-org
/end-of-meta-data
()
1704 "Test `org-end-of-meta-data' specifications."
1705 ;; Skip planning line.
1707 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1708 (org-end-of-meta-data)
1710 ;; Skip properties drawer.
1712 (org-test-with-temp-text
1713 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1714 (org-end-of-meta-data)
1718 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1719 (org-end-of-meta-data)
1721 ;; Nothing to skip, go to first line.
1723 (org-test-with-temp-text "* Headline\nContents"
1724 (org-end-of-meta-data)
1725 (looking-at "Contents")))
1726 ;; With option argument, skip empty lines, regular drawers and
1729 (org-test-with-temp-text "* Headline\n\nContents"
1730 (org-end-of-meta-data t
)
1731 (looking-at "Contents")))
1733 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1734 (org-end-of-meta-data t
)
1735 (looking-at "Contents")))
1737 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1738 (org-end-of-meta-data t
)
1739 (looking-at "Contents")))
1740 ;; Special case: do not skip incomplete drawers.
1742 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1743 (org-end-of-meta-data t
)
1744 (looking-at ":LOGBOOK:")))
1745 ;; Special case: Be careful about consecutive headlines.
1747 (org-test-with-temp-text "* H1\n*H2\nContents"
1748 (org-end-of-meta-data t
)
1749 (looking-at "Contents"))))
1751 (ert-deftest test-org
/beginning-of-line
()
1752 "Test `org-beginning-of-line' specifications."
1755 (org-test-with-temp-text "Some text\nSome other text"
1756 (progn (org-beginning-of-line) (bolp))))
1757 ;; Standard test with `visual-line-mode'.
1759 (org-test-with-temp-text "A long line of text\nSome other text"
1760 (progn (visual-line-mode)
1762 (dotimes (i 1000) (insert "very "))
1763 (org-beginning-of-line)
1765 ;; At an headline with special movement.
1767 (org-test-with-temp-text "* TODO Headline"
1768 (let ((org-special-ctrl-a/e t
))
1770 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1771 (progn (org-beginning-of-line) (bolp))
1772 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1774 (ert-deftest test-org
/end-of-line
()
1775 "Test `org-end-of-line' specifications."
1778 (org-test-with-temp-text "Some text\nSome other text"
1779 (progn (org-end-of-line) (eolp))))
1780 ;; Standard test with `visual-line-mode'.
1782 (org-test-with-temp-text "A long line of text\nSome other text"
1783 (progn (visual-line-mode)
1785 (dotimes (i 1000) (insert "very "))
1786 (goto-char (point-min))
1789 ;; At an headline with special movement.
1791 (org-test-with-temp-text "* Headline1 :tag:\n"
1792 (let ((org-special-ctrl-a/e t
))
1793 (and (progn (org-end-of-line) (looking-at " :tag:"))
1794 (progn (org-end-of-line) (eolp))
1795 (progn (org-end-of-line) (looking-at " :tag:"))))))
1796 ;; At an headline without special movement.
1798 (org-test-with-temp-text "* Headline2 :tag:\n"
1799 (let ((org-special-ctrl-a/e nil
))
1800 (and (progn (org-end-of-line) (eolp))
1801 (progn (org-end-of-line) (eolp))))))
1802 ;; At an headline, with reversed movement.
1804 (org-test-with-temp-text "* Headline3 :tag:\n"
1805 (let ((org-special-ctrl-a/e
'reversed
)
1806 (this-command last-command
))
1807 (and (progn (org-end-of-line) (eolp))
1808 (progn (org-end-of-line) (looking-at " :tag:"))))))
1809 ;; At a block without hidden contents.
1811 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1812 (progn (org-end-of-line) (eolp))))
1813 ;; At a block with hidden contents.
1815 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1816 (let ((org-special-ctrl-a/e t
))
1817 (org-hide-block-toggle)
1821 (ert-deftest test-org
/forward-sentence
()
1822 "Test `org-forward-sentence' specifications."
1823 ;; At the end of a table cell, move to the end of the next one.
1825 (org-test-with-temp-text "| a<point> | b |"
1826 (org-forward-sentence)
1827 (looking-at " |$")))
1828 ;; Elsewhere in a cell, move to its end.
1830 (org-test-with-temp-text "| a<point>c | b |"
1831 (org-forward-sentence)
1832 (looking-at " | b |$")))
1833 ;; Otherwise, simply call `forward-sentence'.
1835 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1836 (org-forward-sentence)
1837 (looking-at " Sentence 2.")))
1839 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1840 (org-forward-sentence)
1841 (org-forward-sentence)
1843 ;; At the end of an element, jump to the next one, without stopping
1844 ;; on blank lines in-between.
1846 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
1847 (org-forward-sentence)
1850 (ert-deftest test-org
/backward-sentence
()
1851 "Test `org-backward-sentence' specifications."
1852 ;; At the beginning of a table cell, move to the beginning of the
1855 (org-test-with-temp-text "| a | <point>b |"
1856 (org-backward-sentence)
1857 (looking-at "a | b |$")))
1858 ;; Elsewhere in a cell, move to its beginning.
1860 (org-test-with-temp-text "| a | b<point>c |"
1861 (org-backward-sentence)
1862 (looking-at "bc |$")))
1863 ;; Otherwise, simply call `backward-sentence'.
1865 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1866 (org-backward-sentence)
1867 (looking-at "Sentence 2.")))
1869 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1870 (org-backward-sentence)
1871 (org-backward-sentence)
1873 ;; Make sure to hit the beginning of a sentence on the same line as
1876 (org-test-with-temp-text "- Line 1\n line <point>2."
1877 (org-backward-sentence)
1878 (looking-at "Line 1"))))
1880 (ert-deftest test-org
/forward-paragraph
()
1881 "Test `org-forward-paragraph' specifications."
1882 ;; At end of buffer, return an error.
1884 (org-test-with-temp-text "Paragraph"
1885 (goto-char (point-max))
1886 (org-forward-paragraph)))
1889 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1890 (org-forward-paragraph)
1894 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1895 (org-forward-paragraph)
1897 ;; Do not enter elements with invisible contents.
1899 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1900 (org-hide-block-toggle)
1901 (org-forward-paragraph)
1903 ;; On an affiliated keyword, jump to the beginning of the element.
1905 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1906 (org-forward-paragraph)
1907 (looking-at "Para")))
1908 ;; On an item or a footnote definition, move to the second element
1911 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1912 (org-forward-paragraph)
1913 (looking-at " Paragraph")))
1915 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1916 (org-forward-paragraph)
1917 (looking-at "Paragraph")))
1918 ;; On an item, or a footnote definition, when the first line is
1919 ;; empty, move to the first item.
1921 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1922 (org-forward-paragraph)
1923 (looking-at " Paragraph")))
1925 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1926 (org-forward-paragraph)
1927 (looking-at "Paragraph")))
1928 ;; On a table (resp. a property drawer) do not move through table
1929 ;; rows (resp. node properties).
1931 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1932 (org-forward-paragraph)
1933 (looking-at "Paragraph")))
1935 (org-test-with-temp-text
1936 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1937 (org-forward-paragraph)
1938 (looking-at "Paragraph")))
1939 ;; On a verse or source block, stop after blank lines.
1941 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1942 (org-forward-paragraph)
1945 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1946 (org-forward-paragraph)
1947 (looking-at "L2"))))
1949 (ert-deftest test-org
/backward-paragraph
()
1950 "Test `org-backward-paragraph' specifications."
1951 ;; Error at beginning of buffer.
1953 (org-test-with-temp-text "Paragraph"
1954 (org-backward-paragraph)))
1957 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1958 (goto-char (point-max))
1959 (org-backward-paragraph)
1962 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1963 (goto-char (point-max))
1965 (org-backward-paragraph)
1969 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1970 (goto-char (point-max))
1972 (org-backward-paragraph)
1974 ;; Ignore invisible elements.
1976 (org-test-with-temp-text "* H1\n P1\n* H2"
1978 (goto-char (point-max))
1980 (org-backward-paragraph)
1982 ;; On an affiliated keyword, jump to the first one.
1984 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1985 (search-forward "c2")
1986 (org-backward-paragraph)
1987 (looking-at "#\\+name")))
1988 ;; On the second element in an item or a footnote definition, jump
1989 ;; to item or the definition.
1991 (org-test-with-temp-text "- line1\n\n line2"
1992 (goto-char (point-max))
1994 (org-backward-paragraph)
1995 (looking-at "- line1")))
1997 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1998 (goto-char (point-max))
2000 (org-backward-paragraph)
2001 (looking-at "\\[fn:1\\] line1")))
2002 ;; On a table (resp. a property drawer), ignore table rows
2003 ;; (resp. node properties).
2005 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2006 (goto-char (point-max))
2008 (org-backward-paragraph)
2011 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2012 (org-backward-paragraph)
2013 (looking-at ":PROPERTIES:")))
2014 ;; On a source or verse block, stop before blank lines.
2016 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2017 (search-forward "L3")
2019 (org-backward-paragraph)
2022 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2023 (search-forward "L3")
2025 (org-backward-paragraph)
2026 (looking-at "L2"))))
2028 (ert-deftest test-org
/forward-element
()
2029 "Test `org-forward-element' specifications."
2030 ;; 1. At EOB: should error.
2031 (org-test-with-temp-text "Some text\n"
2032 (goto-char (point-max))
2033 (should-error (org-forward-element)))
2034 ;; 2. Standard move: expected to ignore blank lines.
2035 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2036 (org-forward-element)
2037 (should (looking-at (regexp-quote "Second paragraph."))))
2038 ;; 3. Headline tests.
2039 (org-test-with-temp-text "
2044 ;; 3.1. At an headline beginning: move to next headline at the
2047 (org-forward-element)
2048 (should (looking-at (regexp-quote "** Head 1.2")))
2049 ;; 3.2. At an headline beginning: move to parent headline if no
2050 ;; headline at the same level.
2052 (org-forward-element)
2053 (should (looking-at (regexp-quote "** Head 1.2"))))
2054 ;; 4. Greater element tests.
2055 (org-test-with-temp-text
2056 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2057 ;; 4.1. At a greater element: expected to skip contents.
2058 (org-forward-element)
2059 (should (looking-at (regexp-quote "Outside.")))
2060 ;; 4.2. At the end of greater element contents: expected to skip
2061 ;; to the end of the greater element.
2063 (org-forward-element)
2064 (should (looking-at (regexp-quote "Outside."))))
2066 (org-test-with-temp-text "
2080 ;; 5.1. At list top point: expected to move to the element after
2083 (org-forward-element)
2084 (should (looking-at (regexp-quote "Outside.")))
2085 ;; 5.2. Special case: at the first line of a sub-list, but not at
2086 ;; beginning of line, move to next item.
2089 (org-forward-element)
2090 (should (looking-at "- item2"))
2093 (org-forward-element)
2094 (should (looking-at " - sub2"))
2095 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2097 (org-forward-element)
2098 (should (looking-at (regexp-quote " Inner paragraph.")))
2099 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2101 (org-forward-element)
2102 (should (looking-at (regexp-quote " Inner paragraph.")))
2103 ;; 5.5. At an item: expected to move to next item, if any.
2105 (org-forward-element)
2106 (should (looking-at " - sub3"))))
2108 (ert-deftest test-org
/backward-element
()
2109 "Test `org-backward-element' specifications."
2110 ;; 1. Should error at BOB.
2111 (org-test-with-temp-text " \nParagraph."
2112 (should-error (org-backward-element)))
2113 ;; 2. Should move at BOB when called on the first element in buffer.
2115 (org-test-with-temp-text "\n#+TITLE: test"
2116 (progn (forward-line)
2117 (org-backward-element)
2119 ;; 3. Not at the beginning of an element: move at its beginning.
2120 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2123 (org-backward-element)
2124 (should (looking-at (regexp-quote "Paragraph2."))))
2125 ;; 4. Headline tests.
2126 (org-test-with-temp-text "
2131 ;; 4.1. At an headline beginning: move to previous headline at the
2134 (org-backward-element)
2135 (should (looking-at (regexp-quote "** Head 1.1")))
2136 ;; 4.2. At an headline beginning: move to parent headline if no
2137 ;; headline at the same level.
2139 (org-backward-element)
2140 (should (looking-at (regexp-quote "* Head 1")))
2141 ;; 4.3. At the first top-level headline: should error.
2143 (should-error (org-backward-element)))
2144 ;; 5. At beginning of first element inside a greater element:
2145 ;; expected to move to greater element's beginning.
2146 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2148 (org-backward-element)
2149 (should (looking-at "#\\+BEGIN_CENTER")))
2150 ;; 6. At the beginning of the first element in a section: should
2151 ;; move back to headline, if any.
2153 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2154 (progn (goto-char (point-max))
2156 (org-backward-element)
2157 (org-at-heading-p))))
2159 (org-test-with-temp-text "
2174 ;; 7.1. At beginning of sub-list: expected to move to the
2175 ;; paragraph before it.
2177 (org-backward-element)
2178 (should (looking-at "item1"))
2179 ;; 7.2. At an item in a list: expected to move at previous item.
2181 (org-backward-element)
2182 (should (looking-at " - sub2"))
2184 (org-backward-element)
2185 (should (looking-at "- item1"))
2186 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2189 (org-backward-element)
2190 (should (looking-at " - sub1"))
2192 (org-backward-element)
2193 (should (looking-at "- item1"))
2194 ;; 7.4. At blank-lines before list end: expected to move to top
2197 (org-backward-element)
2198 (should (looking-at "- item1"))))
2200 (ert-deftest test-org
/up-element
()
2201 "Test `org-up-element' specifications."
2202 ;; 1. At BOB or with no surrounding element: should error.
2203 (org-test-with-temp-text "Paragraph."
2204 (should-error (org-up-element)))
2205 (org-test-with-temp-text "* Head1\n* Head2"
2207 (should-error (org-up-element)))
2208 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2210 (should-error (org-up-element)))
2211 ;; 2. At an headline: move to parent headline.
2212 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2215 (should (looking-at "\\* Head1")))
2216 ;; 3. Inside a greater element: move to greater element beginning.
2217 (org-test-with-temp-text
2218 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2221 (should (looking-at "#\\+BEGIN_CENTER")))
2223 (org-test-with-temp-text "* Top
2230 Paragraph within sub2.
2233 ;; 4.1. Within an item: move to the item beginning.
2236 (should (looking-at " - sub2"))
2237 ;; 4.2. At an item in a sub-list: move to parent item.
2240 (should (looking-at "- item1"))
2241 ;; 4.3. At an item in top list: move to beginning of whole list.
2244 (should (looking-at "- item1"))
2245 ;; 4.4. Special case. At very top point: should move to parent of
2249 (should (looking-at "\\* Top"))))
2251 (ert-deftest test-org
/down-element
()
2252 "Test `org-down-element' specifications."
2253 ;; Error when the element hasn't got a recursive type.
2254 (org-test-with-temp-text "Paragraph."
2255 (should-error (org-down-element)))
2256 ;; Error when the element has no contents
2257 (org-test-with-temp-text "* Headline"
2258 (should-error (org-down-element)))
2259 ;; When at a plain-list, move to first item.
2260 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2263 (should (looking-at " - Item 1.1")))
2264 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2266 (should (looking-at " Item 1")))
2267 ;; When at a table, move to first row
2268 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2270 (should (looking-at " a | b |")))
2271 ;; Otherwise, move inside the greater element.
2272 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2274 (should (looking-at "Paragraph"))))
2276 (ert-deftest test-org
/drag-element-backward
()
2277 "Test `org-drag-element-backward' specifications."
2281 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2282 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2283 (org-drag-element-backward)
2287 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2288 (org-test-with-temp-text
2289 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2290 (org-drag-element-backward)
2292 ;; Preserve blank lines.
2294 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2295 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2296 (org-drag-element-backward)
2300 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2301 (org-drag-element-backward)
2302 (org-looking-at-p "2")))
2303 ;; Error when trying to move first element of buffer.
2305 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2306 (org-drag-element-backward)))
2307 ;; Error when trying to swap nested elements.
2309 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2311 (org-drag-element-backward)))
2312 ;; Error when trying to swap an headline element and a non-headline
2315 (org-test-with-temp-text "Test.\n* Head 1"
2317 (org-drag-element-backward)))
2318 ;; Preserve visibility of elements and their contents.
2320 (equal '((63 .
82) (26 .
48))
2321 (org-test-with-temp-text "
2329 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2330 (search-backward "- item 1")
2331 (org-drag-element-backward)
2332 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2333 (overlays-in (point-min) (point-max)))))))
2335 (ert-deftest test-org
/drag-element-forward
()
2336 "Test `org-drag-element-forward' specifications."
2337 ;; 1. Error when trying to move first element of buffer.
2338 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2340 (should-error (org-drag-element-forward)))
2341 ;; 2. Error when trying to swap nested elements.
2342 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2344 (should-error (org-drag-element-forward)))
2345 ;; 3. Error when trying to swap a non-headline element and an
2347 (org-test-with-temp-text "Test.\n* Head 1"
2348 (should-error (org-drag-element-forward)))
2349 ;; 4. Otherwise, swap elements, preserving column and blank lines
2350 ;; between elements.
2351 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2352 (search-forward "graph")
2353 (org-drag-element-forward)
2354 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2355 (should (looking-at " 1")))
2356 ;; 5. Preserve visibility of elements and their contents.
2357 (org-test-with-temp-text "
2365 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2366 (search-backward "#+BEGIN_CENTER")
2367 (org-drag-element-forward)
2370 '((63 .
82) (26 .
48))
2371 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2372 (overlays-in (point-min) (point-max)))))))
2374 (ert-deftest test-org
/next-block
()
2375 "Test `org-next-block' specifications."
2378 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2380 (looking-at "#\\+BEGIN_CENTER")))
2383 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2384 (let ((case-fold-search nil
))
2386 (looking-at "#\\+begin_center"))))
2387 ;; Ignore current line.
2389 (org-test-with-temp-text
2390 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2392 (looking-at "#\\+BEGIN_CENTER")))
2393 ;; Throw an error when no block is found.
2395 (org-test-with-temp-text "Paragraph"
2396 (org-next-block 1)))
2397 ;; With an argument, skip many blocks at once.
2399 (org-test-with-temp-text
2400 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2402 (looking-at "#\\+BEGIN_QUOTE")))
2403 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2405 (org-test-with-temp-text
2406 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2407 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2408 (looking-at "#\\+BEGIN_QUOTE")))
2409 ;; Optional argument is also case-insensitive.
2411 (org-test-with-temp-text
2412 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2413 (let ((case-fold-search nil
))
2414 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2415 (looking-at "#\\+begin_quote")))))
2417 (ert-deftest test-org
/previous-block
()
2418 "Test `org-previous-block' specifications."
2421 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2422 (org-previous-block 1)
2423 (looking-at "#\\+BEGIN_CENTER")))
2426 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2427 (let ((case-fold-search nil
))
2428 (org-previous-block 1)
2429 (looking-at "#\\+begin_center"))))
2430 ;; Ignore current line.
2432 (org-test-with-temp-text
2433 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2434 (org-previous-block 1)
2435 (looking-at "#\\+BEGIN_QUOTE")))
2436 ;; Throw an error when no block is found.
2438 (org-test-with-temp-text "Paragraph<point>"
2439 (org-previous-block 1)))
2440 ;; With an argument, skip many blocks at once.
2442 (org-test-with-temp-text
2443 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2444 (org-previous-block 2)
2445 (looking-at "#\\+BEGIN_CENTER")))
2446 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2448 (org-test-with-temp-text
2449 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2450 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2451 (looking-at "#\\+BEGIN_QUOTE")))
2452 ;; Optional argument is also case-insensitive.
2454 (org-test-with-temp-text
2455 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2456 (let ((case-fold-search nil
))
2457 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2458 (looking-at "#\\+begin_quote")))))
2461 ;;; Outline structure
2463 (ert-deftest test-org
/demote
()
2464 "Test `org-demote' specifications."
2465 ;; Add correct number of stars according to `org-odd-levels-only'.
2468 (org-test-with-temp-text "* H"
2469 (let ((org-odd-levels-only nil
)) (org-demote))
2470 (org-current-level))))
2473 (org-test-with-temp-text "* H"
2474 (let ((org-odd-levels-only t
)) (org-demote))
2475 (org-current-level))))
2476 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2478 (org-test-with-temp-text "* H :tag:"
2479 (let ((org-tags-column 10)
2480 (org-auto-align-tags t
)
2481 (org-odd-levels-only nil
))
2483 (org-move-to-column 10)
2484 (org-looking-at-p ":tag:$")))
2486 (org-test-with-temp-text "* H :tag:"
2487 (let ((org-tags-column 10)
2488 (org-auto-align-tags nil
)
2489 (org-odd-levels-only nil
))
2491 (org-move-to-column 10)
2492 (org-looking-at-p ":tag:$")))
2493 ;; When `org-adapt-indentation' is non-nil, always indent planning
2494 ;; info and property drawers accordingly.
2497 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2498 (let ((org-odd-levels-only nil
)
2499 (org-adapt-indentation t
))
2502 (org-get-indentation))))
2505 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2506 (let ((org-odd-levels-only nil
)
2507 (org-adapt-indentation t
))
2510 (org-get-indentation))))
2513 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2514 (let ((org-odd-levels-only nil
)
2515 (org-adapt-indentation nil
))
2518 (org-get-indentation))))
2519 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2520 ;; section accordingly. Ignore, however, footnote definitions and
2521 ;; inlinetasks boundaries.
2524 (org-test-with-temp-text "* H\n Paragraph"
2525 (let ((org-odd-levels-only nil
)
2526 (org-adapt-indentation t
))
2529 (org-get-indentation))))
2532 (org-test-with-temp-text "* H\n Paragraph"
2533 (let ((org-odd-levels-only nil
)
2534 (org-adapt-indentation nil
))
2537 (org-get-indentation))))
2540 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2541 (let ((org-odd-levels-only nil
)
2542 (org-adapt-indentation t
))
2544 (goto-char (point-max))
2545 (org-get-indentation))))
2548 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2549 (let ((org-odd-levels-only nil
)
2550 (org-adapt-indentation t
))
2552 (goto-char (point-max))
2553 (org-get-indentation))))
2554 (when (featurep 'org-inlinetask
)
2557 (let ((org-inlinetask-min-level 5)
2558 (org-adapt-indentation t
))
2559 (org-test-with-temp-text "* H\n***** I\n***** END"
2562 (org-get-indentation))))))
2563 (when (featurep 'org-inlinetask
)
2566 (let ((org-inlinetask-min-level 5)
2567 (org-adapt-indentation t
))
2568 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2571 (org-get-indentation))))))
2572 ;; Ignore contents of source blocks or example blocks when
2573 ;; indentation should be preserved (through
2574 ;; `org-src-preserve-indentation' or "-i" flag).
2577 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2578 (let ((org-adapt-indentation t
)
2579 (org-src-preserve-indentation nil
))
2582 (org-get-indentation))))
2585 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2586 (let ((org-adapt-indentation t
)
2587 (org-src-preserve-indentation t
))
2590 (org-get-indentation))))
2593 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2594 (let ((org-adapt-indentation t
)
2595 (org-src-preserve-indentation t
))
2598 (org-get-indentation))))
2601 (org-test-with-temp-text
2602 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2603 (let ((org-adapt-indentation t
)
2604 (org-src-preserve-indentation nil
))
2607 (org-get-indentation)))))
2609 (ert-deftest test-org
/promote
()
2610 "Test `org-promote' specifications."
2611 ;; Return an error if headline is to be promoted to level 0, unless
2612 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2613 ;; headline becomes a comment.
2615 (org-test-with-temp-text "* H"
2616 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2619 (org-test-with-temp-text "* H"
2620 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2622 ;; Remove correct number of stars according to
2623 ;; `org-odd-levels-only'.
2626 (org-test-with-temp-text "*** H"
2627 (let ((org-odd-levels-only nil
)) (org-promote))
2628 (org-current-level))))
2631 (org-test-with-temp-text "*** H"
2632 (let ((org-odd-levels-only t
)) (org-promote))
2633 (org-current-level))))
2634 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2636 (org-test-with-temp-text "** H :tag:"
2637 (let ((org-tags-column 10)
2638 (org-auto-align-tags t
)
2639 (org-odd-levels-only nil
))
2641 (org-move-to-column 10)
2642 (org-looking-at-p ":tag:$")))
2644 (org-test-with-temp-text "** H :tag:"
2645 (let ((org-tags-column 10)
2646 (org-auto-align-tags nil
)
2647 (org-odd-levels-only nil
))
2649 (org-move-to-column 10)
2650 (org-looking-at-p ":tag:$")))
2651 ;; When `org-adapt-indentation' is non-nil, always indent planning
2652 ;; info and property drawers.
2655 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2656 (let ((org-odd-levels-only nil
)
2657 (org-adapt-indentation t
))
2660 (org-get-indentation))))
2663 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2664 (let ((org-odd-levels-only nil
)
2665 (org-adapt-indentation t
))
2668 (org-get-indentation))))
2671 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2672 (let ((org-odd-levels-only nil
)
2673 (org-adapt-indentation nil
))
2676 (org-get-indentation))))
2677 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2678 ;; section accordingly. Ignore, however, footnote definitions and
2679 ;; inlinetasks boundaries.
2682 (org-test-with-temp-text "** H\n Paragraph"
2683 (let ((org-odd-levels-only nil
)
2684 (org-adapt-indentation t
))
2687 (org-get-indentation))))
2690 (org-test-with-temp-text "** H\n Paragraph"
2691 (let ((org-odd-levels-only nil
)
2692 (org-adapt-indentation nil
))
2695 (org-get-indentation))))
2698 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2699 (let ((org-odd-levels-only nil
)
2700 (org-adapt-indentation t
))
2703 (org-get-indentation))))
2704 (when (featurep 'org-inlinetask
)
2707 (let ((org-inlinetask-min-level 5)
2708 (org-adapt-indentation t
))
2709 (org-test-with-temp-text "** H\n***** I\n***** END"
2712 (org-get-indentation))))))
2713 (when (featurep 'org-inlinetask
)
2716 (let ((org-inlinetask-min-level 5)
2717 (org-adapt-indentation t
))
2718 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2721 (org-get-indentation))))))
2722 ;; Give up shifting if it would break document's structure
2726 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2727 (let ((org-odd-levels-only nil
)
2728 (org-adapt-indentation t
))
2731 (org-get-indentation))))
2734 (org-test-with-temp-text "** H\n Paragraph\n * list."
2735 (let ((org-odd-levels-only nil
)
2736 (org-adapt-indentation t
))
2739 (org-get-indentation))))
2740 ;; Ignore contents of source blocks or example blocks when
2741 ;; indentation should be preserved (through
2742 ;; `org-src-preserve-indentation' or "-i" flag).
2745 (org-test-with-temp-text
2746 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2747 (let ((org-adapt-indentation t
)
2748 (org-src-preserve-indentation nil
)
2749 (org-odd-levels-only nil
))
2752 (org-get-indentation))))
2755 (org-test-with-temp-text
2756 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2757 (let ((org-adapt-indentation t
)
2758 (org-src-preserve-indentation t
)
2759 (org-odd-levels-only nil
))
2762 (org-get-indentation))))
2765 (org-test-with-temp-text
2766 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2767 (let ((org-adapt-indentation t
)
2768 (org-src-preserve-indentation t
)
2769 (org-odd-levels-only nil
))
2772 (org-get-indentation))))
2775 (org-test-with-temp-text
2776 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2777 (let ((org-adapt-indentation t
)
2778 (org-src-preserve-indentation nil
)
2779 (org-odd-levels-only nil
))
2782 (org-get-indentation)))))
2787 (ert-deftest test-org
/at-planning-p
()
2788 "Test `org-at-planning-p' specifications."
2791 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2792 (org-at-planning-p)))
2794 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2795 (org-at-planning-p)))
2796 ;; Correctly find planning attached to inlinetasks.
2797 (when (featurep 'org-inlinetask
)
2799 (org-test-with-temp-text
2800 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2801 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2803 (org-test-with-temp-text
2804 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2805 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2807 (org-test-with-temp-text
2808 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2809 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2811 (org-test-with-temp-text
2812 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2813 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2818 (ert-deftest test-org
/buffer-property-keys
()
2819 "Test `org-buffer-property-keys' specifications."
2820 ;; Retrieve properties accross siblings.
2823 (org-test-with-temp-text "
2832 (org-buffer-property-keys))))
2833 ;; Retrieve properties accross children.
2836 (org-test-with-temp-text "
2845 (org-buffer-property-keys))))
2846 ;; Retrieve muliple properties in the same drawer.
2849 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2850 (org-buffer-property-keys))))
2851 ;; Ignore extension symbol in property name.
2854 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2855 (org-buffer-property-keys))))
2856 ;; With non-nil COLUMNS, extract property names from columns.
2859 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2860 (org-buffer-property-keys nil nil t
))))
2862 (equal '("A" "B" "COLUMNS")
2863 (org-test-with-temp-text
2864 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2865 (org-buffer-property-keys nil nil t
)))))
2867 (ert-deftest test-org
/property-values
()
2868 "Test `org-property-values' specifications."
2872 (org-test-with-temp-text
2873 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2874 (org-property-values "A"))))
2875 ;; Ignore empty values.
2877 (org-test-with-temp-text
2878 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2879 (org-property-values "A")))
2880 ;; Take into consideration extended values.
2883 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2884 (org-property-values "A")))))
2886 (ert-deftest test-org
/find-property
()
2887 "Test `org-find-property' specifications."
2891 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
2892 (org-find-property "prop"))))
2893 ;; Ignore false positives.
2896 (org-test-with-temp-text
2897 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
2898 (org-find-property "A"))))
2899 ;; Return first entry found in buffer.
2902 (org-test-with-temp-text
2903 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2904 (org-find-property "A"))))
2905 ;; Only search visible part of the buffer.
2908 (org-test-with-temp-text
2909 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2910 (org-narrow-to-subtree)
2911 (org-find-property "A"))))
2912 ;; With optional argument, only find entries with a specific value.
2914 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2915 (org-find-property "A" "2")))
2918 (org-test-with-temp-text
2919 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
2920 (org-find-property "A" "2"))))
2921 ;; Use "nil" for explicit nil values.
2924 (org-test-with-temp-text
2925 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
2926 (org-find-property "A" "nil")))))
2928 (ert-deftest test-org
/entry-delete
()
2929 "Test `org-entry-delete' specifications."
2933 " *:PROPERTIES:\n *:B: +2\n *:END:"
2934 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2935 (org-entry-delete (point) "A")
2937 ;; Also remove accumulated properties.
2941 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
2942 (org-entry-delete (point) "A")
2944 ;; When last property is removed, remove the property drawer.
2948 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2949 (org-entry-delete (point) "A")
2951 ;; Return a non-nil value when some property was removed.
2953 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2954 (org-entry-delete (point) "A")))
2956 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2957 (org-entry-delete (point) "C"))))
2959 (ert-deftest test-org
/entry-get
()
2960 "Test `org-entry-get' specifications."
2964 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2965 (org-entry-get (point) "A"))))
2969 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2970 (org-entry-get (point) "a"))))
2971 ;; Handle extended values, both before and after base value.
2974 (org-test-with-temp-text
2975 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2976 (org-entry-get (point) "A"))))
2977 ;; Empty values are returned as the empty string.
2980 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2981 (org-entry-get (point) "A"))))
2982 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2983 ;; otherwise, return nil.
2985 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2986 (org-entry-get (point) "A")))
2989 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2990 (org-entry-get (point) "A" nil t
))))
2991 ;; Return nil when no property is found, independently on the
2992 ;; LITERAL-NIL argument.
2994 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2995 (org-entry-get (point) "B")))
2997 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2998 (org-entry-get (point) "B" nil t
)))
2999 ;; Handle inheritance, when allowed.
3003 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3004 (org-entry-get (point) "A" t
))))
3008 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3009 (let ((org-use-property-inheritance t
))
3010 (org-entry-get (point) "A" 'selective
)))))
3012 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
3013 (let ((org-use-property-inheritance nil
))
3014 (org-entry-get (point) "A" 'selective
)))))
3016 (ert-deftest test-org
/entry-properties
()
3017 "Test `org-entry-properties' specifications."
3018 ;; Get "ITEM" property.
3021 (org-test-with-temp-text "* TODO H"
3022 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
3025 (org-test-with-temp-text "* TODO H"
3026 (cdr (assoc "ITEM" (org-entry-properties))))))
3027 ;; Get "TODO" property.
3030 (org-test-with-temp-text "* TODO H"
3031 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
3034 (org-test-with-temp-text "* TODO H"
3035 (cdr (assoc "TODO" (org-entry-properties))))))
3037 (org-test-with-temp-text "* H"
3038 (assoc "TODO" (org-entry-properties nil
"TODO"))))
3039 ;; Get "PRIORITY" property.
3042 (org-test-with-temp-text "* [#A] H"
3043 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
3046 (org-test-with-temp-text "* [#A] H"
3047 (cdr (assoc "PRIORITY" (org-entry-properties))))))
3049 (org-test-with-temp-text "* H"
3050 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
3051 ;; Get "FILE" property.
3053 (org-test-with-temp-text-in-file "* H\nParagraph"
3054 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3055 (buffer-file-name))))
3057 (org-test-with-temp-text-in-file "* H\nParagraph"
3058 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3059 (buffer-file-name))))
3061 (org-test-with-temp-text "* H\nParagraph"
3062 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3063 ;; Get "TAGS" property.
3065 (equal ":tag1:tag2:"
3066 (org-test-with-temp-text "* H :tag1:tag2:"
3067 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3069 (equal ":tag1:tag2:"
3070 (org-test-with-temp-text "* H :tag1:tag2:"
3071 (cdr (assoc "TAGS" (org-entry-properties))))))
3073 (org-test-with-temp-text "* H"
3074 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3075 ;; Get "ALLTAGS" property.
3077 (equal ":tag1:tag2:"
3078 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3079 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3081 (equal ":tag1:tag2:"
3082 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3083 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3085 (org-test-with-temp-text "* H"
3086 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3087 ;; Get "BLOCKED" property.
3090 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
3091 (let ((org-enforce-todo-dependencies t
)
3093 '(org-block-todo-from-children-or-siblings-or-parent)))
3094 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3097 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
3098 (let ((org-enforce-todo-dependencies t
)
3100 '(org-block-todo-from-children-or-siblings-or-parent)))
3101 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
3104 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
3105 (let ((org-enforce-todo-dependencies t
))
3106 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3107 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3111 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3112 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3116 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3117 (cdr (assoc "CLOSED" (org-entry-properties))))))
3119 (org-test-with-temp-text "* H"
3120 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3124 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3125 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3129 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3130 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3132 (org-test-with-temp-text "* H"
3133 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3137 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3138 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3142 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3143 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3145 (org-test-with-temp-text "* H"
3146 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3150 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3151 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3154 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3155 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3158 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3159 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3162 (org-test-with-temp-text
3163 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3165 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3166 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3167 ;; Get standard properties.
3170 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3171 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3172 ;; Handle extended properties.
3175 (org-test-with-temp-text
3176 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3177 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3180 (org-test-with-temp-text
3181 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3182 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3183 ;; Ignore forbidden (special) properties.
3185 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3186 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3188 (ert-deftest test-org
/entry-put
()
3189 "Test `org-entry-put' specifications."
3190 ;; Error when not a string or nil.
3192 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3193 (org-entry-put 1 "test" 2)))
3194 ;; Set "TODO" property.
3196 (string-match (regexp-quote " TODO H")
3197 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3198 (org-entry-put (point) "TODO" "TODO")
3201 (string-match (regexp-quote "* H")
3202 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3203 (org-entry-put (point) "TODO" nil
)
3205 ;; Set "PRIORITY" property.
3208 (org-test-with-temp-text "* [#B] H"
3209 (org-entry-put (point) "PRIORITY" "A")
3213 (org-test-with-temp-text "* [#B] H"
3214 (org-entry-put (point) "PRIORITY" nil
)
3216 ;; Set "SCHEDULED" property.
3218 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3219 (org-test-with-temp-text "* H"
3220 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3224 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3225 (org-entry-put (point) "SCHEDULED" nil
)
3228 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3229 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3230 (org-entry-put (point) "SCHEDULED" "earlier")
3233 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3234 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3235 (org-entry-put (point) "SCHEDULED" "later")
3237 ;; Set "DEADLINE" property.
3239 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3240 (org-test-with-temp-text "* H"
3241 (org-entry-put (point) "DEADLINE" "2014-03-04")
3245 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3246 (org-entry-put (point) "DEADLINE" nil
)
3249 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3250 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3251 (org-entry-put (point) "DEADLINE" "earlier")
3254 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3255 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3256 (org-entry-put (point) "DEADLINE" "later")
3258 ;; Set "CATEGORY" property
3260 (string-match "^ *:CATEGORY: cat"
3261 (org-test-with-temp-text "* H"
3262 (org-entry-put (point) "CATEGORY" "cat")
3264 ;; Regular properties, with or without pre-existing drawer.
3266 (string-match "^ *:A: +2$"
3267 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3268 (org-entry-put (point) "A" "2")
3271 (string-match "^ *:A: +1$"
3272 (org-test-with-temp-text "* H"
3273 (org-entry-put (point) "A" "1")
3275 ;; Special case: two consecutive headlines.
3277 (string-match "\\* A\n *:PROPERTIES:"
3278 (org-test-with-temp-text "* A\n** B"
3279 (org-entry-put (point) "A" "1")
3285 (ert-deftest test-org
/update-radio-target-regexp
()
3286 "Test `org-update-radio-target-regexp' specifications."
3287 ;; Properly update cache with no previous radio target regexp.
3290 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3291 (save-excursion (goto-char (point-max)) (org-element-context))
3293 (search-forward "o")
3295 (org-update-radio-target-regexp)
3296 (goto-char (point-max))
3297 (org-element-type (org-element-context)))))
3298 ;; Properly update cache with previous radio target regexp.
3301 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3302 (save-excursion (goto-char (point-max)) (org-element-context))
3304 (search-forward "o")
3306 (org-update-radio-target-regexp)
3307 (search-backward "r")
3310 (org-update-radio-target-regexp)
3311 (goto-char (point-max))
3312 (delete-region (line-beginning-position) (point))
3314 (org-element-type (org-element-context))))))
3319 (ert-deftest test-org
/match-sparse-tree
()
3320 "Test `org-match-sparse-tree' specifications."
3323 (org-test-with-temp-text "* H\n** H1 :tag:"
3324 (org-match-sparse-tree nil
"tag")
3325 (search-forward "H1")
3326 (org-invisible-p2)))
3328 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3329 (org-match-sparse-tree nil
"tag")
3330 (search-forward "H2")
3331 (org-invisible-p2)))
3332 ;; "-" operator for tags.
3334 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3335 (org-match-sparse-tree nil
"tag1-tag2")
3336 (search-forward "H1")
3337 (org-invisible-p2)))
3339 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3340 (org-match-sparse-tree nil
"tag1-tag2")
3341 (search-forward "H2")
3342 (org-invisible-p2)))
3343 ;; "&" operator for tags.
3345 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3346 (org-match-sparse-tree nil
"tag1&tag2")
3347 (search-forward "H1")
3348 (org-invisible-p2)))
3350 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3351 (org-match-sparse-tree nil
"tag1&tag2")
3352 (search-forward "H2")
3353 (org-invisible-p2)))
3354 ;; "|" operator for tags.
3356 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3357 (org-match-sparse-tree nil
"tag1|tag2")
3358 (search-forward "H1")
3359 (org-invisible-p2)))
3361 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3362 (org-match-sparse-tree nil
"tag1|tag2")
3363 (search-forward "H2")
3364 (org-invisible-p2)))
3365 ;; Regexp match on tags.
3367 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3368 (org-match-sparse-tree nil
"{^tag.*}")
3369 (search-forward "H1")
3370 (org-invisible-p2)))
3372 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3373 (org-match-sparse-tree nil
"{^tag.*}")
3374 (search-forward "H2")
3375 (org-invisible-p2)))
3376 ;; Match group tags.
3378 (org-test-with-temp-text
3379 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3380 (org-match-sparse-tree nil
"work")
3381 (search-forward "H1")
3382 (org-invisible-p2)))
3384 (org-test-with-temp-text
3385 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3386 (org-match-sparse-tree nil
"work")
3387 (search-forward "H2")
3388 (org-invisible-p2)))
3389 ;; Match group tags with hard brackets.
3391 (org-test-with-temp-text
3392 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3393 (org-match-sparse-tree nil
"work")
3394 (search-forward "H1")
3395 (org-invisible-p2)))
3397 (org-test-with-temp-text
3398 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3399 (org-match-sparse-tree nil
"work")
3400 (search-forward "H2")
3401 (org-invisible-p2)))
3402 ;; Match tags in hierarchies
3404 (org-test-with-temp-text
3405 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3406 #+TAGS: [ Lev_2 : Lev_3 ]\n
3407 #+TAGS: { Lev_3 : Lev_4 }\n
3408 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3409 (org-match-sparse-tree nil
"Lev_1")
3410 (search-forward "H4")
3411 (org-invisible-p2)))
3412 ;; Match regular expressions in tags
3414 (org-test-with-temp-text
3415 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3416 (org-match-sparse-tree nil
"Lev")
3417 (search-forward "H1")
3418 (org-invisible-p2)))
3420 (org-test-with-temp-text
3421 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3422 (org-match-sparse-tree nil
"Lev")
3423 (search-forward "H1")
3424 (org-invisible-p2)))
3425 ;; Match properties.
3427 (org-test-with-temp-text
3428 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3429 (org-match-sparse-tree nil
"A=\"1\"")
3430 (search-forward "H2")
3431 (org-invisible-p2)))
3433 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3434 (org-match-sparse-tree nil
"A=\"1\"")
3435 (search-forward "H2")
3436 (org-invisible-p2)))
3437 ;; Case is not significant when matching properties.
3439 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3440 (org-match-sparse-tree nil
"a=\"1\"")
3441 (search-forward "H2")
3442 (org-invisible-p2)))
3444 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3445 (org-match-sparse-tree nil
"A=\"1\"")
3446 (search-forward "H2")
3447 (org-invisible-p2)))
3448 ;; Match special LEVEL property.
3450 (org-test-with-temp-text "* H\n** H1\n*** H2"
3451 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3452 (search-forward "H1")
3453 (org-invisible-p2)))
3455 (org-test-with-temp-text "* H\n** H1\n*** H2"
3456 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3457 (search-forward "H2")
3458 (org-invisible-p2)))
3459 ;; Comparison operators when matching properties.
3461 (org-test-with-temp-text
3462 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3463 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3464 (search-forward "H1")
3465 (org-invisible-p2)))
3467 (org-test-with-temp-text
3468 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3469 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3470 (search-forward "H2")
3471 (org-invisible-p2)))
3472 ;; Regexp match on properties values.
3474 (org-test-with-temp-text
3475 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3476 (org-match-sparse-tree nil
"A={f.*}")
3477 (search-forward "H1")
3478 (org-invisible-p2)))
3480 (org-test-with-temp-text
3481 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3482 (org-match-sparse-tree nil
"A={f.*}")
3483 (search-forward "H2")
3484 (org-invisible-p2)))
3485 ;; With an optional argument, limit match to TODO entries.
3487 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3488 (org-match-sparse-tree t
"tag")
3489 (search-forward "H1")
3490 (org-invisible-p2)))
3492 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3493 (org-match-sparse-tree t
"tag")
3494 (search-forward "H2")
3495 (org-invisible-p2))))
3500 (ert-deftest test-org
/time-stamp
()
3501 "Test `org-time-stamp' specifications."
3502 ;; Insert chosen time stamp at point.
3505 "Te<2014-03-04 .*?>xt"
3506 (org-test-with-temp-text "Te<point>xt"
3507 (flet ((org-read-date
3509 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3510 (org-time-stamp nil
)
3512 ;; With a prefix argument, also insert time.
3515 "Te<2014-03-04 .*? 00:41>xt"
3516 (org-test-with-temp-text "Te<point>xt"
3517 (flet ((org-read-date
3519 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3520 (org-time-stamp '(4))
3522 ;; With two universal prefix arguments, insert an active timestamp
3523 ;; with the current time without prompting the user.
3526 "Te<2014-03-04 .*? 00:41>xt"
3527 (org-test-with-temp-text "Te<point>xt"
3528 (flet ((current-time
3530 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3531 (org-time-stamp '(16))
3533 ;; When optional argument is non-nil, insert an inactive timestamp.
3536 "Te\\[2014-03-04 .*?\\]xt"
3537 (org-test-with-temp-text "Te<point>xt"
3538 (flet ((org-read-date
3540 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3541 (org-time-stamp nil t
)
3543 ;; When called from a timestamp, replace existing one.
3547 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3548 (flet ((org-read-date
3550 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3551 (org-time-stamp nil
)
3555 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3556 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3557 (flet ((org-read-date
3559 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3560 (org-time-stamp nil
)
3562 ;; When replacing a timestamp, preserve repeater, if any.
3565 "<2014-03-04 .*? \\+2y>"
3566 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3567 (flet ((org-read-date
3569 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3570 (org-time-stamp nil
)
3572 ;; When called twice in a raw, build a date range.
3575 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3576 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3577 (flet ((org-read-date
3579 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3580 (let ((last-command 'org-time-stamp
)
3581 (this-command 'org-time-stamp
))
3582 (org-time-stamp nil
))
3583 (buffer-string))))))
3585 (ert-deftest test-org
/timestamp-has-time-p
()
3586 "Test `org-timestamp-has-time-p' specifications."
3589 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3590 (org-timestamp-has-time-p (org-element-context))))
3593 (org-test-with-temp-text "<2012-03-29 Thu>"
3594 (org-timestamp-has-time-p (org-element-context)))))
3596 (ert-deftest test-org
/timestamp-format
()
3597 "Test `org-timestamp-format' specifications."
3602 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3603 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3608 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3609 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3611 (ert-deftest test-org
/timestamp-split-range
()
3612 "Test `org-timestamp-split-range' specifications."
3613 ;; Extract range start (active).
3616 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3617 (let ((ts (org-timestamp-split-range (org-element-context))))
3618 (mapcar (lambda (p) (org-element-property p ts
))
3619 '(:year-end
:month-end
:day-end
))))))
3620 ;; Extract range start (inactive)
3623 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3624 (let ((ts (org-timestamp-split-range (org-element-context))))
3625 (mapcar (lambda (p) (org-element-property p ts
))
3626 '(:year-end
:month-end
:day-end
))))))
3627 ;; Extract range end (active).
3630 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3631 (let ((ts (org-timestamp-split-range
3632 (org-element-context) t
)))
3633 (mapcar (lambda (p) (org-element-property p ts
))
3634 '(:year-end
:month-end
:day-end
))))))
3635 ;; Extract range end (inactive)
3638 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3639 (let ((ts (org-timestamp-split-range
3640 (org-element-context) t
)))
3641 (mapcar (lambda (p) (org-element-property p ts
))
3642 '(:year-end
:month-end
:day-end
))))))
3643 ;; Return the timestamp if not a range.
3645 (org-test-with-temp-text "[2012-03-29 Thu]"
3646 (let* ((ts-orig (org-element-context))
3647 (ts-copy (org-timestamp-split-range ts-orig
)))
3648 (eq ts-orig ts-copy
))))
3650 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3651 (let* ((ts-orig (org-element-context))
3652 (ts-copy (org-timestamp-split-range ts-orig
)))
3653 (eq ts-orig ts-copy
)))))
3655 (ert-deftest test-org
/timestamp-translate
()
3656 "Test `org-timestamp-translate' specifications."
3657 ;; Translate whole date range.
3660 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3661 (let ((org-display-custom-times t
)
3662 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3663 (org-timestamp-translate (org-element-context))))))
3664 ;; Translate date range start.
3667 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3668 (let ((org-display-custom-times t
)
3669 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3670 (org-timestamp-translate (org-element-context) 'start
)))))
3671 ;; Translate date range end.
3674 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3675 (let ((org-display-custom-times t
)
3676 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3677 (org-timestamp-translate (org-element-context) 'end
)))))
3678 ;; Translate time range.
3681 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3682 (let ((org-display-custom-times t
)
3683 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3684 (org-timestamp-translate (org-element-context))))))
3685 ;; Translate non-range timestamp.
3688 (org-test-with-temp-text "<2012-03-29 Thu>"
3689 (let ((org-display-custom-times t
)
3690 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3691 (org-timestamp-translate (org-element-context))))))
3692 ;; Do not change `diary' timestamps.
3694 (equal "<%%(org-float t 4 2)>"
3695 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3696 (let ((org-display-custom-times t
)
3697 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3698 (org-timestamp-translate (org-element-context)))))))
3704 (ert-deftest test-org
/flag-drawer
()
3705 "Test `org-flag-drawer' specifications."
3708 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3710 (get-char-property (line-end-position) 'invisible
)))
3713 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3715 (org-flag-drawer nil
)
3716 (get-char-property (line-end-position) 'invisible
)))
3717 ;; Test optional argument.
3719 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3720 (let ((drawer (save-excursion (search-forward ":D2")
3721 (org-element-at-point))))
3722 (org-flag-drawer t drawer
)
3723 (get-char-property (progn (search-forward ":D2") (line-end-position))
3726 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3727 (let ((drawer (save-excursion (search-forward ":D2")
3728 (org-element-at-point))))
3729 (org-flag-drawer t drawer
)
3730 (get-char-property (line-end-position) 'invisible
))))
3731 ;; Do not hide fake drawers.
3733 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3736 (get-char-property (line-end-position) 'invisible
)))
3737 ;; Do not hide incomplete drawers.
3739 (org-test-with-temp-text ":D:\nparagraph"
3742 (get-char-property (line-end-position) 'invisible
)))
3743 ;; Do not hide drawers when called from final blank lines.
3745 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3746 (goto-char (point-max))
3748 (goto-char (point-min))
3749 (get-char-property (line-end-position) 'invisible
)))
3750 ;; Don't leave point in an invisible part of the buffer when hiding
3753 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3754 (goto-char (point-max))
3756 (get-char-property (point) 'invisible
))))
3758 (ert-deftest test-org
/hide-block-toggle
()
3759 "Test `org-hide-block-toggle' specifications."
3760 ;; Error when not at a block.
3762 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3763 (org-hide-block-toggle 'off
)
3764 (get-char-property (line-end-position) 'invisible
)))
3767 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3768 (org-hide-block-toggle)
3769 (get-char-property (line-end-position) 'invisible
)))
3771 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3772 (org-hide-block-toggle)
3773 (get-char-property (line-end-position) 'invisible
)))
3774 ;; Show block unconditionally when optional argument is `off'.
3776 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3777 (org-hide-block-toggle)
3778 (org-hide-block-toggle 'off
)
3779 (get-char-property (line-end-position) 'invisible
)))
3781 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3782 (org-hide-block-toggle 'off
)
3783 (get-char-property (line-end-position) 'invisible
)))
3784 ;; Hide block unconditionally when optional argument is non-nil.
3786 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3787 (org-hide-block-toggle t
)
3788 (get-char-property (line-end-position) 'invisible
)))
3790 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3791 (org-hide-block-toggle)
3792 (org-hide-block-toggle t
)
3793 (get-char-property (line-end-position) 'invisible
)))
3794 ;; Do not hide block when called from final blank lines.
3796 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3797 (org-hide-block-toggle)
3798 (goto-char (point-min))
3799 (get-char-property (line-end-position) 'invisible
)))
3800 ;; Don't leave point in an invisible part of the buffer when hiding
3803 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3804 (org-hide-block-toggle)
3805 (get-char-property (point) 'invisible
))))
3807 (ert-deftest test-org
/hide-block-toggle-maybe
()
3808 "Test `org-hide-block-toggle-maybe' specifications."
3810 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3811 (org-hide-block-toggle-maybe)))
3813 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3815 (ert-deftest test-org
/show-set-visibility
()
3816 "Test `org-show-set-visibility' specifications."
3817 ;; Do not throw an error before first heading.
3819 (org-test-with-temp-text "Preamble\n* Headline"
3820 (org-show-set-visibility 'tree
)
3822 ;; Test all visibility spans, both on headline and in entry.
3823 (let ((list-visible-lines
3824 (lambda (state headerp
)
3825 (org-test-with-temp-text "* Grandmother (0)
3836 **** The other child (11)
3841 (search-forward (if headerp
"Self" "Match"))
3842 (org-show-set-visibility state
)
3843 (goto-char (point-min))
3844 (let (result (line 0))
3846 (unless (org-invisible-p2) (push line result
))
3849 (nreverse result
))))))
3850 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
3851 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
3852 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
3853 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
3854 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
3855 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
3856 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
3857 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
3858 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
3859 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3860 (funcall list-visible-lines
'tree nil
)))
3861 (should (equal '(0 1 3 4 5 7 12 13)
3862 (funcall list-visible-lines
'canonical t
)))
3863 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3864 (funcall list-visible-lines
'canonical nil
)))))
3869 ;;; test-org.el ends here