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 "TIMESTAMP" and "TIMESTAMP_IA" properties.
3169 (equal "<2012-03-29 thu.>"
3170 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
3171 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
3173 (equal "[2012-03-29 thu.]"
3174 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
3175 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
3177 (equal "<2012-03-29 thu.>"
3178 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
3179 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
3181 (equal "[2014-03-04 tue.]"
3182 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
3183 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
3184 ;; Get standard properties.
3187 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3188 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3189 ;; Handle extended properties.
3192 (org-test-with-temp-text
3193 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3194 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3197 (org-test-with-temp-text
3198 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3199 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3200 ;; Ignore forbidden (special) properties.
3202 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3203 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3205 (ert-deftest test-org
/entry-put
()
3206 "Test `org-entry-put' specifications."
3207 ;; Error when not a string or nil.
3209 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3210 (org-entry-put 1 "test" 2)))
3211 ;; Set "TODO" property.
3213 (string-match (regexp-quote " TODO H")
3214 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3215 (org-entry-put (point) "TODO" "TODO")
3218 (string-match (regexp-quote "* H")
3219 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3220 (org-entry-put (point) "TODO" nil
)
3222 ;; Set "PRIORITY" property.
3225 (org-test-with-temp-text "* [#B] H"
3226 (org-entry-put (point) "PRIORITY" "A")
3230 (org-test-with-temp-text "* [#B] H"
3231 (org-entry-put (point) "PRIORITY" nil
)
3233 ;; Set "SCHEDULED" property.
3235 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3236 (org-test-with-temp-text "* H"
3237 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3241 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3242 (org-entry-put (point) "SCHEDULED" nil
)
3245 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3246 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3247 (org-entry-put (point) "SCHEDULED" "earlier")
3250 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3251 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3252 (org-entry-put (point) "SCHEDULED" "later")
3254 ;; Set "DEADLINE" property.
3256 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3257 (org-test-with-temp-text "* H"
3258 (org-entry-put (point) "DEADLINE" "2014-03-04")
3262 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3263 (org-entry-put (point) "DEADLINE" nil
)
3266 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3267 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3268 (org-entry-put (point) "DEADLINE" "earlier")
3271 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3272 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3273 (org-entry-put (point) "DEADLINE" "later")
3275 ;; Set "CATEGORY" property
3277 (string-match "^ *:CATEGORY: cat"
3278 (org-test-with-temp-text "* H"
3279 (org-entry-put (point) "CATEGORY" "cat")
3281 ;; Regular properties, with or without pre-existing drawer.
3283 (string-match "^ *:A: +2$"
3284 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3285 (org-entry-put (point) "A" "2")
3288 (string-match "^ *:A: +1$"
3289 (org-test-with-temp-text "* H"
3290 (org-entry-put (point) "A" "1")
3292 ;; Special case: two consecutive headlines.
3294 (string-match "\\* A\n *:PROPERTIES:"
3295 (org-test-with-temp-text "* A\n** B"
3296 (org-entry-put (point) "A" "1")
3302 (ert-deftest test-org
/update-radio-target-regexp
()
3303 "Test `org-update-radio-target-regexp' specifications."
3304 ;; Properly update cache with no previous radio target regexp.
3307 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3308 (save-excursion (goto-char (point-max)) (org-element-context))
3310 (search-forward "o")
3312 (org-update-radio-target-regexp)
3313 (goto-char (point-max))
3314 (org-element-type (org-element-context)))))
3315 ;; Properly update cache with previous radio target regexp.
3318 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3319 (save-excursion (goto-char (point-max)) (org-element-context))
3321 (search-forward "o")
3323 (org-update-radio-target-regexp)
3324 (search-backward "r")
3327 (org-update-radio-target-regexp)
3328 (goto-char (point-max))
3329 (delete-region (line-beginning-position) (point))
3331 (org-element-type (org-element-context))))))
3336 (ert-deftest test-org
/match-sparse-tree
()
3337 "Test `org-match-sparse-tree' specifications."
3340 (org-test-with-temp-text "* H\n** H1 :tag:"
3341 (org-match-sparse-tree nil
"tag")
3342 (search-forward "H1")
3343 (org-invisible-p2)))
3345 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3346 (org-match-sparse-tree nil
"tag")
3347 (search-forward "H2")
3348 (org-invisible-p2)))
3349 ;; "-" operator for tags.
3351 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3352 (org-match-sparse-tree nil
"tag1-tag2")
3353 (search-forward "H1")
3354 (org-invisible-p2)))
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 "H2")
3359 (org-invisible-p2)))
3360 ;; "&" operator for tags.
3362 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3363 (org-match-sparse-tree nil
"tag1&tag2")
3364 (search-forward "H1")
3365 (org-invisible-p2)))
3367 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3368 (org-match-sparse-tree nil
"tag1&tag2")
3369 (search-forward "H2")
3370 (org-invisible-p2)))
3371 ;; "|" operator for tags.
3373 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3374 (org-match-sparse-tree nil
"tag1|tag2")
3375 (search-forward "H1")
3376 (org-invisible-p2)))
3378 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3379 (org-match-sparse-tree nil
"tag1|tag2")
3380 (search-forward "H2")
3381 (org-invisible-p2)))
3382 ;; Regexp match on tags.
3384 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3385 (org-match-sparse-tree nil
"{^tag.*}")
3386 (search-forward "H1")
3387 (org-invisible-p2)))
3389 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3390 (org-match-sparse-tree nil
"{^tag.*}")
3391 (search-forward "H2")
3392 (org-invisible-p2)))
3393 ;; Match group tags.
3395 (org-test-with-temp-text
3396 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3397 (org-match-sparse-tree nil
"work")
3398 (search-forward "H1")
3399 (org-invisible-p2)))
3401 (org-test-with-temp-text
3402 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3403 (org-match-sparse-tree nil
"work")
3404 (search-forward "H2")
3405 (org-invisible-p2)))
3406 ;; Match group tags with hard brackets.
3408 (org-test-with-temp-text
3409 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3410 (org-match-sparse-tree nil
"work")
3411 (search-forward "H1")
3412 (org-invisible-p2)))
3414 (org-test-with-temp-text
3415 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3416 (org-match-sparse-tree nil
"work")
3417 (search-forward "H2")
3418 (org-invisible-p2)))
3419 ;; Match tags in hierarchies
3421 (org-test-with-temp-text
3422 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3423 #+TAGS: [ Lev_2 : Lev_3 ]\n
3424 #+TAGS: { Lev_3 : Lev_4 }\n
3425 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3426 (org-match-sparse-tree nil
"Lev_1")
3427 (search-forward "H4")
3428 (org-invisible-p2)))
3429 ;; Match regular expressions in tags
3431 (org-test-with-temp-text
3432 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3433 (org-match-sparse-tree nil
"Lev")
3434 (search-forward "H1")
3435 (org-invisible-p2)))
3437 (org-test-with-temp-text
3438 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3439 (org-match-sparse-tree nil
"Lev")
3440 (search-forward "H1")
3441 (org-invisible-p2)))
3442 ;; Match properties.
3444 (org-test-with-temp-text
3445 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3446 (org-match-sparse-tree nil
"A=\"1\"")
3447 (search-forward "H2")
3448 (org-invisible-p2)))
3450 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3451 (org-match-sparse-tree nil
"A=\"1\"")
3452 (search-forward "H2")
3453 (org-invisible-p2)))
3454 ;; Case is not significant when matching properties.
3456 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3457 (org-match-sparse-tree nil
"a=\"1\"")
3458 (search-forward "H2")
3459 (org-invisible-p2)))
3461 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3462 (org-match-sparse-tree nil
"A=\"1\"")
3463 (search-forward "H2")
3464 (org-invisible-p2)))
3465 ;; Match special LEVEL property.
3467 (org-test-with-temp-text "* H\n** H1\n*** H2"
3468 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3469 (search-forward "H1")
3470 (org-invisible-p2)))
3472 (org-test-with-temp-text "* H\n** H1\n*** H2"
3473 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3474 (search-forward "H2")
3475 (org-invisible-p2)))
3476 ;; Comparison operators when matching properties.
3478 (org-test-with-temp-text
3479 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3480 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3481 (search-forward "H1")
3482 (org-invisible-p2)))
3484 (org-test-with-temp-text
3485 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3486 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3487 (search-forward "H2")
3488 (org-invisible-p2)))
3489 ;; Regexp match on properties values.
3491 (org-test-with-temp-text
3492 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3493 (org-match-sparse-tree nil
"A={f.*}")
3494 (search-forward "H1")
3495 (org-invisible-p2)))
3497 (org-test-with-temp-text
3498 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3499 (org-match-sparse-tree nil
"A={f.*}")
3500 (search-forward "H2")
3501 (org-invisible-p2)))
3502 ;; With an optional argument, limit match to TODO entries.
3504 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3505 (org-match-sparse-tree t
"tag")
3506 (search-forward "H1")
3507 (org-invisible-p2)))
3509 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3510 (org-match-sparse-tree t
"tag")
3511 (search-forward "H2")
3512 (org-invisible-p2))))
3517 (ert-deftest test-org
/time-stamp
()
3518 "Test `org-time-stamp' specifications."
3519 ;; Insert chosen time stamp at point.
3522 "Te<2014-03-04 .*?>xt"
3523 (org-test-with-temp-text "Te<point>xt"
3524 (flet ((org-read-date
3526 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3527 (org-time-stamp nil
)
3529 ;; With a prefix argument, also insert time.
3532 "Te<2014-03-04 .*? 00:41>xt"
3533 (org-test-with-temp-text "Te<point>xt"
3534 (flet ((org-read-date
3536 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3537 (org-time-stamp '(4))
3539 ;; With two universal prefix arguments, insert an active timestamp
3540 ;; with the current time without prompting the user.
3543 "Te<2014-03-04 .*? 00:41>xt"
3544 (org-test-with-temp-text "Te<point>xt"
3545 (flet ((current-time
3547 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3548 (org-time-stamp '(16))
3550 ;; When optional argument is non-nil, insert an inactive timestamp.
3553 "Te\\[2014-03-04 .*?\\]xt"
3554 (org-test-with-temp-text "Te<point>xt"
3555 (flet ((org-read-date
3557 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3558 (org-time-stamp nil t
)
3560 ;; When called from a timestamp, replace existing one.
3564 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3565 (flet ((org-read-date
3567 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3568 (org-time-stamp nil
)
3572 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3573 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3574 (flet ((org-read-date
3576 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3577 (org-time-stamp nil
)
3579 ;; When replacing a timestamp, preserve repeater, if any.
3582 "<2014-03-04 .*? \\+2y>"
3583 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3584 (flet ((org-read-date
3586 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3587 (org-time-stamp nil
)
3589 ;; When called twice in a raw, build a date range.
3592 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3593 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3594 (flet ((org-read-date
3596 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3597 (let ((last-command 'org-time-stamp
)
3598 (this-command 'org-time-stamp
))
3599 (org-time-stamp nil
))
3600 (buffer-string))))))
3602 (ert-deftest test-org
/timestamp-has-time-p
()
3603 "Test `org-timestamp-has-time-p' specifications."
3606 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3607 (org-timestamp-has-time-p (org-element-context))))
3610 (org-test-with-temp-text "<2012-03-29 Thu>"
3611 (org-timestamp-has-time-p (org-element-context)))))
3613 (ert-deftest test-org
/timestamp-format
()
3614 "Test `org-timestamp-format' specifications."
3619 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3620 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3625 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3626 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3628 (ert-deftest test-org
/timestamp-split-range
()
3629 "Test `org-timestamp-split-range' specifications."
3630 ;; Extract range start (active).
3633 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3634 (let ((ts (org-timestamp-split-range (org-element-context))))
3635 (mapcar (lambda (p) (org-element-property p ts
))
3636 '(:year-end
:month-end
:day-end
))))))
3637 ;; Extract range start (inactive)
3640 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3641 (let ((ts (org-timestamp-split-range (org-element-context))))
3642 (mapcar (lambda (p) (org-element-property p ts
))
3643 '(:year-end
:month-end
:day-end
))))))
3644 ;; Extract range end (active).
3647 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3648 (let ((ts (org-timestamp-split-range
3649 (org-element-context) t
)))
3650 (mapcar (lambda (p) (org-element-property p ts
))
3651 '(:year-end
:month-end
:day-end
))))))
3652 ;; Extract range end (inactive)
3655 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3656 (let ((ts (org-timestamp-split-range
3657 (org-element-context) t
)))
3658 (mapcar (lambda (p) (org-element-property p ts
))
3659 '(:year-end
:month-end
:day-end
))))))
3660 ;; Return the timestamp if not a range.
3662 (org-test-with-temp-text "[2012-03-29 Thu]"
3663 (let* ((ts-orig (org-element-context))
3664 (ts-copy (org-timestamp-split-range ts-orig
)))
3665 (eq ts-orig ts-copy
))))
3667 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3668 (let* ((ts-orig (org-element-context))
3669 (ts-copy (org-timestamp-split-range ts-orig
)))
3670 (eq ts-orig ts-copy
)))))
3672 (ert-deftest test-org
/timestamp-translate
()
3673 "Test `org-timestamp-translate' specifications."
3674 ;; Translate whole date range.
3677 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3678 (let ((org-display-custom-times t
)
3679 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3680 (org-timestamp-translate (org-element-context))))))
3681 ;; Translate date range start.
3684 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3685 (let ((org-display-custom-times t
)
3686 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3687 (org-timestamp-translate (org-element-context) 'start
)))))
3688 ;; Translate date range end.
3691 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3692 (let ((org-display-custom-times t
)
3693 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3694 (org-timestamp-translate (org-element-context) 'end
)))))
3695 ;; Translate time range.
3698 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3699 (let ((org-display-custom-times t
)
3700 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3701 (org-timestamp-translate (org-element-context))))))
3702 ;; Translate non-range timestamp.
3705 (org-test-with-temp-text "<2012-03-29 Thu>"
3706 (let ((org-display-custom-times t
)
3707 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3708 (org-timestamp-translate (org-element-context))))))
3709 ;; Do not change `diary' timestamps.
3711 (equal "<%%(org-float t 4 2)>"
3712 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3713 (let ((org-display-custom-times t
)
3714 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3715 (org-timestamp-translate (org-element-context)))))))
3721 (ert-deftest test-org
/flag-drawer
()
3722 "Test `org-flag-drawer' specifications."
3725 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3727 (get-char-property (line-end-position) 'invisible
)))
3730 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3732 (org-flag-drawer nil
)
3733 (get-char-property (line-end-position) 'invisible
)))
3734 ;; Test optional argument.
3736 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3737 (let ((drawer (save-excursion (search-forward ":D2")
3738 (org-element-at-point))))
3739 (org-flag-drawer t drawer
)
3740 (get-char-property (progn (search-forward ":D2") (line-end-position))
3743 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3744 (let ((drawer (save-excursion (search-forward ":D2")
3745 (org-element-at-point))))
3746 (org-flag-drawer t drawer
)
3747 (get-char-property (line-end-position) 'invisible
))))
3748 ;; Do not hide fake drawers.
3750 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3753 (get-char-property (line-end-position) 'invisible
)))
3754 ;; Do not hide incomplete drawers.
3756 (org-test-with-temp-text ":D:\nparagraph"
3759 (get-char-property (line-end-position) 'invisible
)))
3760 ;; Do not hide drawers when called from final blank lines.
3762 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3763 (goto-char (point-max))
3765 (goto-char (point-min))
3766 (get-char-property (line-end-position) 'invisible
)))
3767 ;; Don't leave point in an invisible part of the buffer when hiding
3770 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3771 (goto-char (point-max))
3773 (get-char-property (point) 'invisible
))))
3775 (ert-deftest test-org
/hide-block-toggle
()
3776 "Test `org-hide-block-toggle' specifications."
3777 ;; Error when not at a block.
3779 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3780 (org-hide-block-toggle 'off
)
3781 (get-char-property (line-end-position) 'invisible
)))
3784 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3785 (org-hide-block-toggle)
3786 (get-char-property (line-end-position) 'invisible
)))
3788 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3789 (org-hide-block-toggle)
3790 (get-char-property (line-end-position) 'invisible
)))
3791 ;; Show block unconditionally when optional argument is `off'.
3793 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3794 (org-hide-block-toggle)
3795 (org-hide-block-toggle 'off
)
3796 (get-char-property (line-end-position) 'invisible
)))
3798 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3799 (org-hide-block-toggle 'off
)
3800 (get-char-property (line-end-position) 'invisible
)))
3801 ;; Hide block unconditionally when optional argument is non-nil.
3803 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3804 (org-hide-block-toggle t
)
3805 (get-char-property (line-end-position) 'invisible
)))
3807 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3808 (org-hide-block-toggle)
3809 (org-hide-block-toggle t
)
3810 (get-char-property (line-end-position) 'invisible
)))
3811 ;; Do not hide block when called from final blank lines.
3813 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3814 (org-hide-block-toggle)
3815 (goto-char (point-min))
3816 (get-char-property (line-end-position) 'invisible
)))
3817 ;; Don't leave point in an invisible part of the buffer when hiding
3820 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3821 (org-hide-block-toggle)
3822 (get-char-property (point) 'invisible
))))
3824 (ert-deftest test-org
/hide-block-toggle-maybe
()
3825 "Test `org-hide-block-toggle-maybe' specifications."
3827 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3828 (org-hide-block-toggle-maybe)))
3830 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3832 (ert-deftest test-org
/show-set-visibility
()
3833 "Test `org-show-set-visibility' specifications."
3834 ;; Do not throw an error before first heading.
3836 (org-test-with-temp-text "Preamble\n* Headline"
3837 (org-show-set-visibility 'tree
)
3839 ;; Test all visibility spans, both on headline and in entry.
3840 (let ((list-visible-lines
3841 (lambda (state headerp
)
3842 (org-test-with-temp-text "* Grandmother (0)
3853 **** The other child (11)
3858 (search-forward (if headerp
"Self" "Match"))
3859 (org-show-set-visibility state
)
3860 (goto-char (point-min))
3861 (let (result (line 0))
3863 (unless (org-invisible-p2) (push line result
))
3866 (nreverse result
))))))
3867 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
3868 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
3869 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
3870 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
3871 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
3872 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
3873 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
3874 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
3875 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
3876 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3877 (funcall list-visible-lines
'tree nil
)))
3878 (should (equal '(0 1 3 4 5 7 12 13)
3879 (funcall list-visible-lines
'canonical t
)))
3880 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3881 (funcall list-visible-lines
'canonical nil
)))))
3886 ;;; test-org.el ends here