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
/return
()
837 "Test RET (`org-return') specifications."
841 (org-test-with-temp-text "Para<point>graph"
844 ;; With optional argument, indent line.
846 (equal " Para\n graph"
847 (org-test-with-temp-text " Para<point>graph"
850 ;; On a table, call `org-table-next-row'.
852 (org-test-with-temp-text "| <point>a |\n| b |"
854 (org-looking-at-p "b")))
855 ;; Open link or timestamp under point when `org-return-follows-link'
858 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
859 (let ((org-return-follows-link t
)) (org-return))
860 (org-looking-at-p "<<target>>")))
862 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
863 (let ((org-return-follows-link nil
)) (org-return))
864 (org-looking-at-p "<<target>>")))
865 ;; However, do not open link when point is in a table.
867 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
868 (let ((org-return-follows-link t
)) (org-return))
869 (org-looking-at-p "between")))
870 ;; Special case: in a list, when indenting, do not break structure.
873 (org-test-with-temp-text "- A <point>B"
878 (org-test-with-temp-text "- A\n<point>- B"
881 ;; Special case: on tags part of a headline, add a newline below it
882 ;; instead of breaking it.
885 (org-test-with-temp-text "* H :<point>tag:"
889 (ert-deftest test-org
/meta-return
()
890 "Test M-RET (`org-meta-return') specifications."
891 ;; In a table field insert a row above.
893 (org-test-with-temp-text "| a |"
897 (looking-at "| |$")))
898 ;; In a paragraph change current line into a header.
900 (org-test-with-temp-text "a"
903 (looking-at "\* a$")))
904 ;; In an item insert an item, in this case above.
906 (org-test-with-temp-text "- a"
910 ;; In a drawer and item insert an item, in this case above.
912 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
916 (looking-at "- $"))))
918 (ert-deftest test-org
/insert-heading
()
919 "Test `org-insert-heading' specifications."
920 ;; In an empty buffer, insert a new headline.
923 (org-test-with-temp-text ""
926 ;; At the beginning of a line, turn it into a headline
929 (org-test-with-temp-text "<point>P"
932 ;; In the middle of a line, split the line if allowed, otherwise,
933 ;; insert the headline at its end.
935 (equal "Para\n* graph"
936 (org-test-with-temp-text "Para<point>graph"
937 (let ((org-M-RET-may-split-line '((default . t
))))
938 (org-insert-heading))
941 (equal "Paragraph\n* "
942 (org-test-with-temp-text "Para<point>graph"
943 (let ((org-M-RET-may-split-line '((default . nil
))))
944 (org-insert-heading))
946 ;; When on a list, insert an item instead, unless called with an
947 ;; universal argument or if list is invisible. In this case, create
948 ;; a new headline after contents.
950 (equal "* H\n- item\n- "
951 (org-test-with-temp-text "* H\n- item<point>"
952 (let ((org-insert-heading-respect-content nil
))
953 (org-insert-heading))
956 (equal "* H\n- item\n- item 2\n* "
957 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
958 (let ((org-insert-heading-respect-content nil
))
959 (org-insert-heading '(4)))
962 (equal "* H\n- item\n* "
963 (org-test-with-temp-text "* H\n- item"
965 (goto-char (point-max))
966 (let ((org-insert-heading-respect-content nil
)) (org-insert-heading))
968 ;; When called with two universal arguments, insert a new headline
969 ;; at the end of the grandparent subtree.
971 (equal "* H1\n** H3\n- item\n** H2\n** "
972 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
973 (let ((org-insert-heading-respect-content nil
))
974 (org-insert-heading '(16)))
976 ;; When optional TOP-LEVEL argument is non-nil, always insert
977 ;; a level 1 heading.
979 (equal "* H1\n** H2\n* "
980 (org-test-with-temp-text "* H1\n** H2<point>"
981 (org-insert-heading nil nil t
)
984 (equal "* H1\n- item\n* "
985 (org-test-with-temp-text "* H1\n- item<point>"
986 (org-insert-heading nil nil t
)
988 ;; Corner case: correctly insert a headline after an empty one.
991 (org-test-with-temp-text "* <point>"
995 (ert-deftest test-org
/insert-todo-heading-respect-content
()
996 "Test `org-insert-todo-heading-respect-content' specifications."
997 ;; Create a TODO heading.
999 (org-test-with-temp-text "* H1\n Body"
1000 (org-insert-todo-heading-respect-content)
1001 (nth 2 (org-heading-components))))
1002 ;; Add headline at the end of the first subtree
1004 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1005 (search-forward "H1Body")
1006 (org-insert-todo-heading-respect-content)
1007 (and (eobp) (org-at-heading-p))))
1008 ;; In a list, do not create a new item.
1010 (org-test-with-temp-text "* H\n- an item\n- another one"
1011 (search-forward "an ")
1012 (org-insert-todo-heading-respect-content)
1013 (and (eobp) (org-at-heading-p)))))
1017 ;;; Fixed-Width Areas
1019 (ert-deftest test-org
/toggle-fixed-width
()
1020 "Test `org-toggle-fixed-width' specifications."
1021 ;; No region: Toggle on fixed-width marker in paragraphs.
1024 (org-test-with-temp-text "A"
1025 (org-toggle-fixed-width)
1027 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1030 (org-test-with-temp-text ": A"
1031 (org-toggle-fixed-width)
1033 ;; No region: Toggle on marker in blank lines after elements or just
1034 ;; after a headline.
1037 (org-test-with-temp-text "* H\n"
1039 (org-toggle-fixed-width)
1042 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1043 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1044 (goto-char (point-max))
1045 (org-toggle-fixed-width)
1047 ;; No region: Toggle on marker in front of one line elements (e.g.,
1048 ;; headlines, clocks)
1050 (equal ": * Headline"
1051 (org-test-with-temp-text "* Headline"
1052 (org-toggle-fixed-width)
1055 (equal ": #+KEYWORD: value"
1056 (org-test-with-temp-text "#+KEYWORD: value"
1057 (org-toggle-fixed-width)
1059 ;; No region: error in other situations.
1061 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1063 (org-toggle-fixed-width)
1065 ;; No region: Indentation is preserved.
1068 (org-test-with-temp-text "- A\n B"
1070 (org-toggle-fixed-width)
1072 ;; Region: If it contains only fixed-width elements and blank lines,
1073 ;; toggle off fixed-width markup.
1076 (org-test-with-temp-text ": A\n\n: B"
1077 (transient-mark-mode 1)
1078 (push-mark (point) t t
)
1079 (goto-char (point-max))
1080 (org-toggle-fixed-width)
1082 ;; Region: If it contains anything else, toggle on fixed-width but
1083 ;; not on fixed-width areas.
1085 (equal ": A\n: \n: B\n: \n: C"
1086 (org-test-with-temp-text "A\n\n: B\n\nC"
1087 (transient-mark-mode 1)
1088 (push-mark (point) t t
)
1089 (goto-char (point-max))
1090 (org-toggle-fixed-width)
1092 ;; Region: Ignore blank lines at its end, unless it contains only
1096 (org-test-with-temp-text "A\n\n"
1097 (transient-mark-mode 1)
1098 (push-mark (point) t t
)
1099 (goto-char (point-max))
1100 (org-toggle-fixed-width)
1104 (org-test-with-temp-text "\n\n"
1105 (transient-mark-mode 1)
1106 (push-mark (point) t t
)
1107 (goto-char (point-max))
1108 (org-toggle-fixed-width)
1115 (ert-deftest test-org
/in-commented-heading-p
()
1116 "Test `org-in-commented-heading-p' specifications."
1117 ;; Commented headline.
1119 (org-test-with-temp-text "* COMMENT Headline\nBody"
1120 (goto-char (point-max))
1121 (org-in-commented-heading-p)))
1122 ;; Commented ancestor.
1124 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1125 (goto-char (point-max))
1126 (org-in-commented-heading-p)))
1127 ;; Comment keyword is case-sensitive.
1129 (org-test-with-temp-text "* Comment Headline\nBody"
1130 (goto-char (point-max))
1131 (org-in-commented-heading-p)))
1132 ;; Keyword is standalone.
1134 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1135 (goto-char (point-max))
1136 (org-in-commented-heading-p)))
1137 ;; Optional argument.
1139 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1140 (goto-char (point-max))
1141 (org-in-commented-heading-p t
))))
1147 (ert-deftest test-org
/set-regexps-and-options
()
1148 "Test `org-set-regexps-and-options' specifications."
1151 (equal '(("A" . ?a
) ("B") ("C"))
1152 (org-test-with-temp-text "#+TAGS: A(a) B C"
1156 (equal '(("A") (:newline
) ("B"))
1157 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1161 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1162 (org-test-with-temp-text "#+TAGS: { A B } C"
1166 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1167 (org-test-with-temp-text "#+TAGS: { A : B C }"
1171 (equal '(("A" "B" "C"))
1172 (org-test-with-temp-text "#+TAGS: { A : B C }"
1174 org-tag-groups-alist
)))
1176 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1177 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1181 (equal '(("A" "B" "C"))
1182 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1184 org-tag-groups-alist
)))
1185 ;; FILETAGS keyword.
1187 (equal '("A" "B" "C")
1188 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1191 ;; PROPERTY keyword. Property names are case-insensitive.
1194 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1196 (cdr (assoc "var" org-file-properties
)))))
1200 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1202 (cdr (assoc "var" org-file-properties
)))))
1206 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1208 (cdr (assoc "var" org-file-properties
)))))
1212 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1214 org-archive-location
)))
1215 ;; CATEGORY keyword.
1218 (org-test-with-temp-text "#+CATEGORY: test"
1223 (org-test-with-temp-text "#+CATEGORY: test"
1225 (cdr (assoc "CATEGORY" org-file-properties
)))))
1228 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1229 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1231 org-columns-default-format
)))
1232 ;; CONSTANTS keyword. Constants names are case sensitive.
1234 (equal '("299792458." "3.14")
1235 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1238 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1242 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1244 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1247 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1249 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1254 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1256 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1258 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1262 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1264 (list org-highest-priority org-lowest-priority org-default-priority
))))
1268 (org-test-with-temp-text "#+PRIORITIES: X Z"
1270 (list org-highest-priority org-lowest-priority org-default-priority
))))
1274 (org-test-with-temp-text "#+STARTUP: fold odd"
1276 (list org-startup-folded org-odd-levels-only
))))
1279 (equal '(("A" "B") ("C"))
1280 (org-test-with-temp-text "#+TODO: A B | C"
1282 (list org-not-done-keywords org-done-keywords
))))
1284 (equal '(("A" "C") ("B" "D"))
1285 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1287 (list org-not-done-keywords org-done-keywords
))))
1289 (equal '(("A" "B") ("C"))
1290 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1292 (list org-not-done-keywords org-done-keywords
))))
1294 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1295 (org-test-with-temp-text "#+TODO: A(a)"
1297 org-todo-key-alist
)))
1299 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1300 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1302 org-todo-log-states
)))
1303 ;; Enter SETUPFILE keyword.
1306 (org-test-with-temp-text
1307 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1309 (cdr (assoc "a" org-file-properties
))))))
1317 (ert-deftest test-org
/coderef
()
1318 "Test coderef links specifications."
1320 (org-test-with-temp-text "
1321 #+BEGIN_SRC emacs-lisp
1325 (goto-char (point-max))
1327 (looking-at "(ref:sc)"))))
1331 (ert-deftest test-org
/custom-id
()
1332 "Test custom ID links specifications."
1334 (org-test-with-temp-text
1335 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1336 (goto-char (point-max))
1338 (org-looking-at-p "\\* H1")))
1339 ;; Ignore false positives.
1341 (org-test-with-temp-text
1342 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>"
1343 (goto-char (point-max))
1344 (let (org-link-search-must-match-exact-headline) (org-open-at-point))
1345 (org-looking-at-p "\\* H1"))))
1349 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1350 ;; a named element (#+name: text) and to headlines (* Text).
1352 (ert-deftest test-org
/fuzzy-links
()
1353 "Test fuzzy links specifications."
1354 ;; Fuzzy link goes in priority to a matching target.
1356 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1359 (looking-at "<<Test>>")))
1360 ;; Then fuzzy link points to an element with a given name.
1362 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1365 (looking-at "#\\+NAME: Test")))
1366 ;; A target still lead to a matching headline otherwise.
1368 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1371 (looking-at "\\* Head2")))
1372 ;; With a leading star in link, enforce heading match.
1374 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1377 (looking-at "\\* Test")))
1378 ;; With a leading star in link, enforce exact heading match, even
1379 ;; with `org-link-search-must-match-exact-headline' set to nil.
1381 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1382 (let ((org-link-search-must-match-exact-headline nil
))
1383 (org-open-at-point))))
1384 ;; Heading match should not care about spaces, cookies, todo
1385 ;; keywords, priorities, and tags.
1388 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1389 (org-test-with-temp-text
1390 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
1391 (let ((org-link-search-must-match-exact-headline nil
)
1392 (org-todo-regexp "TODO"))
1393 (org-open-at-point))
1394 (looking-at (regexp-quote first-line
)))))
1395 ;; Heading match should still be exact.
1398 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1399 (org-test-with-temp-text
1400 (concat first-line
"\nFoo Bar\n<point>[[*Test 1]]")
1401 (let ((org-link-search-must-match-exact-headline nil
)
1402 (org-todo-regexp "TODO"))
1403 (org-open-at-point)))))
1404 ;; Heading match ignores COMMENT keyword.
1406 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
1408 (looking-at "\\* COMMENT Test")))
1409 ;; Correctly un-hexify fuzzy links.
1411 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1412 (goto-char (point-max))
1418 (ert-deftest test-org
/org-link-escape-ascii-character
()
1419 "Escape an ascii character."
1423 (org-link-escape "["))))
1425 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1426 "Escape an ascii control character."
1430 (org-link-escape "\t"))))
1432 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1433 "Escape an unicode multibyte character."
1437 (org-link-escape "€"))))
1439 (ert-deftest test-org
/org-link-escape-custom-table
()
1440 "Escape string with custom character table."
1444 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1446 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1447 "Escape string with custom table merged with default table."
1450 "%5BF%6F%6F%3A%42ar%0A%5D"
1451 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1453 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1454 "Unescape an ascii character."
1458 (org-link-unescape "%5B"))))
1460 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1461 "Unescpae an ascii control character."
1465 (org-link-unescape "%0A"))))
1467 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1468 "Unescape unicode multibyte character."
1472 (org-link-unescape "%E2%82%AC"))))
1474 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1475 "Unescape old style percent escaped character."
1478 "à âçèéêîôùû"
1479 (decode-coding-string
1480 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1482 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1483 "Escape and unescape a URL that includes an escaped char.
1484 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1487 "http://some.host.com/form?&id=blah%2Bblah25"
1489 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1491 (ert-deftest test-org
/org-link-escape-chars-browser
()
1492 "Test of the constant `org-link-escape-chars-browser'.
1493 See there why this test is a candidate to be removed once Org
1494 drops support for Emacs 24.1 and 24.2."
1497 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1498 "%22Release%208.2%22&idxname=emacs-orgmode")
1499 (org-link-escape-browser ; Do not replace with `url-encode-url',
1500 ; see docstring above.
1501 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1502 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1506 (ert-deftest test-org
/open-at-point-in-keyword
()
1507 "Does `org-open-at-point' open link in a keyword line?"
1509 (org-test-with-temp-text
1510 "#+KEYWORD: <point>[[info:emacs#Top]]"
1511 (org-open-at-point) t
)))
1513 (ert-deftest test-org
/open-at-point-in-property
()
1514 "Does `org-open-at-point' open link in property drawer?"
1516 (org-test-with-temp-text
1519 :URL: <point>[[info:emacs#Top]]
1521 (org-open-at-point) t
)))
1523 (ert-deftest test-org
/open-at-point-in-comment
()
1524 "Does `org-open-at-point' open link in a commented line?"
1526 (org-test-with-temp-text
1527 "# <point>[[info:emacs#Top]]"
1528 (org-open-at-point) t
)))
1530 (ert-deftest test-org
/open-at-point
/info
()
1531 "Test `org-open-at-point' on info links."
1533 (org-test-with-temp-text
1534 "<point>[[info:emacs#Top]]"
1536 (and (switch-to-buffer "*info*")
1538 (looking-at "\nThe Emacs Editor")
1541 (ert-deftest test-org
/open-at-point
/inline-image
()
1542 "Test `org-open-at-point' on nested links."
1544 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1546 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1547 (kill-buffer "*info*")))))
1552 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1553 "Ensure properties accumulate in subtree drawers."
1554 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1555 (org-babel-next-src-block)
1556 (should (equal '(2 1) (org-babel-execute-src-block)))))
1558 (ert-deftest test-org
/custom-properties
()
1559 "Test custom properties specifications."
1562 (let ((org-custom-properties '("FOO")))
1563 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1564 (org-toggle-custom-properties-visibility)
1565 (org-invisible-p2))))
1566 ;; Properties are case-insensitive.
1568 (let ((org-custom-properties '("FOO")))
1569 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1570 (org-toggle-custom-properties-visibility)
1571 (org-invisible-p2))))
1573 (let ((org-custom-properties '("foo")))
1574 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1575 (org-toggle-custom-properties-visibility)
1576 (org-invisible-p2))))
1577 ;; Multiple custom properties in the same drawer.
1579 (let ((org-custom-properties '("FOO" "BAR")))
1580 (org-test-with-temp-text
1581 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1582 (org-toggle-custom-properties-visibility)
1583 (and (org-invisible-p2)
1584 (not (progn (forward-line) (org-invisible-p2)))
1585 (progn (forward-line) (org-invisible-p2))))))
1586 ;; Hide custom properties with an empty value.
1588 (let ((org-custom-properties '("FOO")))
1589 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1590 (org-toggle-custom-properties-visibility)
1591 (org-invisible-p2))))
1592 ;; Do not hide fake properties.
1594 (let ((org-custom-properties '("FOO")))
1595 (org-test-with-temp-text ":FOO: val\n"
1596 (org-toggle-custom-properties-visibility)
1597 (org-invisible-p2))))
1599 (let ((org-custom-properties '("A")))
1600 (org-test-with-temp-text
1601 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1602 (org-toggle-custom-properties-visibility)
1603 (org-invisible-p2)))))
1609 (ert-deftest test-org
/mark-subtree
()
1610 "Test `org-mark-subtree' specifications."
1611 ;; Error when point is before first headline.
1613 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1614 (progn (transient-mark-mode 1)
1615 (org-mark-subtree))))
1616 ;; Without argument, mark current subtree.
1620 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1621 (progn (transient-mark-mode 1)
1624 (list (region-beginning) (region-end))))))
1625 ;; With an argument, move ARG up.
1629 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1630 (progn (transient-mark-mode 1)
1632 (org-mark-subtree 1)
1633 (list (region-beginning) (region-end))))))
1634 ;; Do not get fooled by inlinetasks.
1635 (when (featurep 'org-inlinetask
)
1638 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1639 (progn (transient-mark-mode 1)
1641 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1642 (region-beginning)))))))
1648 (ert-deftest test-org
/end-of-meta-data
()
1649 "Test `org-end-of-meta-data' specifications."
1650 ;; Skip planning line.
1652 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1653 (org-end-of-meta-data)
1655 ;; Skip properties drawer.
1657 (org-test-with-temp-text
1658 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1659 (org-end-of-meta-data)
1663 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1664 (org-end-of-meta-data)
1666 ;; Nothing to skip, go to first line.
1668 (org-test-with-temp-text "* Headline\nContents"
1669 (org-end-of-meta-data)
1670 (looking-at "Contents")))
1671 ;; With option argument, skip empty lines, regular drawers and
1674 (org-test-with-temp-text "* Headline\n\nContents"
1675 (org-end-of-meta-data t
)
1676 (looking-at "Contents")))
1678 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1679 (org-end-of-meta-data t
)
1680 (looking-at "Contents")))
1682 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1683 (org-end-of-meta-data t
)
1684 (looking-at "Contents")))
1685 ;; Special case: do not skip incomplete drawers.
1687 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1688 (org-end-of-meta-data t
)
1689 (looking-at ":LOGBOOK:")))
1690 ;; Special case: Be careful about consecutive headlines.
1692 (org-test-with-temp-text "* H1\n*H2\nContents"
1693 (org-end-of-meta-data t
)
1694 (looking-at "Contents"))))
1696 (ert-deftest test-org
/beginning-of-line
()
1697 "Test `org-beginning-of-line' specifications."
1700 (org-test-with-temp-text "Some text\nSome other text"
1701 (progn (org-beginning-of-line) (bolp))))
1702 ;; Standard test with `visual-line-mode'.
1704 (org-test-with-temp-text "A long line of text\nSome other text"
1705 (progn (visual-line-mode)
1707 (dotimes (i 1000) (insert "very "))
1708 (org-beginning-of-line)
1710 ;; At an headline with special movement.
1712 (org-test-with-temp-text "* TODO Headline"
1713 (let ((org-special-ctrl-a/e t
))
1715 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1716 (progn (org-beginning-of-line) (bolp))
1717 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1719 (ert-deftest test-org
/end-of-line
()
1720 "Test `org-end-of-line' specifications."
1723 (org-test-with-temp-text "Some text\nSome other text"
1724 (progn (org-end-of-line) (eolp))))
1725 ;; Standard test with `visual-line-mode'.
1727 (org-test-with-temp-text "A long line of text\nSome other text"
1728 (progn (visual-line-mode)
1730 (dotimes (i 1000) (insert "very "))
1731 (goto-char (point-min))
1734 ;; At an headline with special movement.
1736 (org-test-with-temp-text "* Headline1 :tag:\n"
1737 (let ((org-special-ctrl-a/e t
))
1738 (and (progn (org-end-of-line) (looking-at " :tag:"))
1739 (progn (org-end-of-line) (eolp))
1740 (progn (org-end-of-line) (looking-at " :tag:"))))))
1741 ;; At an headline without special movement.
1743 (org-test-with-temp-text "* Headline2 :tag:\n"
1744 (let ((org-special-ctrl-a/e nil
))
1745 (and (progn (org-end-of-line) (eolp))
1746 (progn (org-end-of-line) (eolp))))))
1747 ;; At an headline, with reversed movement.
1749 (org-test-with-temp-text "* Headline3 :tag:\n"
1750 (let ((org-special-ctrl-a/e
'reversed
)
1751 (this-command last-command
))
1752 (and (progn (org-end-of-line) (eolp))
1753 (progn (org-end-of-line) (looking-at " :tag:"))))))
1754 ;; At a block without hidden contents.
1756 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1757 (progn (org-end-of-line) (eolp))))
1758 ;; At a block with hidden contents.
1760 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1761 (let ((org-special-ctrl-a/e t
))
1762 (org-hide-block-toggle)
1766 (ert-deftest test-org
/forward-sentence
()
1767 "Test `org-forward-sentence' specifications."
1768 ;; At the end of a table cell, move to the end of the next one.
1770 (org-test-with-temp-text "| a<point> | b |"
1771 (org-forward-sentence)
1772 (looking-at " |$")))
1773 ;; Elsewhere in a cell, move to its end.
1775 (org-test-with-temp-text "| a<point>c | b |"
1776 (org-forward-sentence)
1777 (looking-at " | b |$")))
1778 ;; Otherwise, simply call `forward-sentence'.
1780 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1781 (org-forward-sentence)
1782 (looking-at " Sentence 2.")))
1784 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
1785 (org-forward-sentence)
1786 (org-forward-sentence)
1788 ;; At the end of an element, jump to the next one, without stopping
1789 ;; on blank lines in-between.
1791 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
1792 (org-forward-sentence)
1795 (ert-deftest test-org
/backward-sentence
()
1796 "Test `org-backward-sentence' specifications."
1797 ;; At the beginning of a table cell, move to the beginning of the
1800 (org-test-with-temp-text "| a | <point>b |"
1801 (org-backward-sentence)
1802 (looking-at "a | b |$")))
1803 ;; Elsewhere in a cell, move to its beginning.
1805 (org-test-with-temp-text "| a | b<point>c |"
1806 (org-backward-sentence)
1807 (looking-at "bc |$")))
1808 ;; Otherwise, simply call `backward-sentence'.
1810 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1811 (org-backward-sentence)
1812 (looking-at "Sentence 2.")))
1814 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
1815 (org-backward-sentence)
1816 (org-backward-sentence)
1818 ;; Make sure to hit the beginning of a sentence on the same line as
1821 (org-test-with-temp-text "- Line 1\n line <point>2."
1822 (org-backward-sentence)
1823 (looking-at "Line 1"))))
1825 (ert-deftest test-org
/forward-paragraph
()
1826 "Test `org-forward-paragraph' specifications."
1827 ;; At end of buffer, return an error.
1829 (org-test-with-temp-text "Paragraph"
1830 (goto-char (point-max))
1831 (org-forward-paragraph)))
1834 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1835 (org-forward-paragraph)
1839 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1840 (org-forward-paragraph)
1842 ;; Do not enter elements with invisible contents.
1844 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1845 (org-hide-block-toggle)
1846 (org-forward-paragraph)
1848 ;; On an affiliated keyword, jump to the beginning of the element.
1850 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1851 (org-forward-paragraph)
1852 (looking-at "Para")))
1853 ;; On an item or a footnote definition, move to the second element
1856 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1857 (org-forward-paragraph)
1858 (looking-at " Paragraph")))
1860 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1861 (org-forward-paragraph)
1862 (looking-at "Paragraph")))
1863 ;; On an item, or a footnote definition, when the first line is
1864 ;; empty, move to the first item.
1866 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1867 (org-forward-paragraph)
1868 (looking-at " Paragraph")))
1870 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1871 (org-forward-paragraph)
1872 (looking-at "Paragraph")))
1873 ;; On a table (resp. a property drawer) do not move through table
1874 ;; rows (resp. node properties).
1876 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1877 (org-forward-paragraph)
1878 (looking-at "Paragraph")))
1880 (org-test-with-temp-text
1881 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1882 (org-forward-paragraph)
1883 (looking-at "Paragraph")))
1884 ;; On a verse or source block, stop after blank lines.
1886 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1887 (org-forward-paragraph)
1890 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1891 (org-forward-paragraph)
1892 (looking-at "L2"))))
1894 (ert-deftest test-org
/backward-paragraph
()
1895 "Test `org-backward-paragraph' specifications."
1896 ;; Error at beginning of buffer.
1898 (org-test-with-temp-text "Paragraph"
1899 (org-backward-paragraph)))
1902 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1903 (goto-char (point-max))
1904 (org-backward-paragraph)
1907 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1908 (goto-char (point-max))
1910 (org-backward-paragraph)
1914 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1915 (goto-char (point-max))
1917 (org-backward-paragraph)
1919 ;; Ignore invisible elements.
1921 (org-test-with-temp-text "* H1\n P1\n* H2"
1923 (goto-char (point-max))
1925 (org-backward-paragraph)
1927 ;; On an affiliated keyword, jump to the first one.
1929 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1930 (search-forward "c2")
1931 (org-backward-paragraph)
1932 (looking-at "#\\+name")))
1933 ;; On the second element in an item or a footnote definition, jump
1934 ;; to item or the definition.
1936 (org-test-with-temp-text "- line1\n\n line2"
1937 (goto-char (point-max))
1939 (org-backward-paragraph)
1940 (looking-at "- line1")))
1942 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1943 (goto-char (point-max))
1945 (org-backward-paragraph)
1946 (looking-at "\\[fn:1\\] line1")))
1947 ;; On a table (resp. a property drawer), ignore table rows
1948 ;; (resp. node properties).
1950 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1951 (goto-char (point-max))
1953 (org-backward-paragraph)
1956 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1957 (org-backward-paragraph)
1958 (looking-at ":PROPERTIES:")))
1959 ;; On a source or verse block, stop before blank lines.
1961 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1962 (search-forward "L3")
1964 (org-backward-paragraph)
1967 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1968 (search-forward "L3")
1970 (org-backward-paragraph)
1971 (looking-at "L2"))))
1973 (ert-deftest test-org
/forward-element
()
1974 "Test `org-forward-element' specifications."
1975 ;; 1. At EOB: should error.
1976 (org-test-with-temp-text "Some text\n"
1977 (goto-char (point-max))
1978 (should-error (org-forward-element)))
1979 ;; 2. Standard move: expected to ignore blank lines.
1980 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1981 (org-forward-element)
1982 (should (looking-at (regexp-quote "Second paragraph."))))
1983 ;; 3. Headline tests.
1984 (org-test-with-temp-text "
1989 ;; 3.1. At an headline beginning: move to next headline at the
1992 (org-forward-element)
1993 (should (looking-at (regexp-quote "** Head 1.2")))
1994 ;; 3.2. At an headline beginning: move to parent headline if no
1995 ;; headline at the same level.
1997 (org-forward-element)
1998 (should (looking-at (regexp-quote "** Head 1.2"))))
1999 ;; 4. Greater element tests.
2000 (org-test-with-temp-text
2001 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
2002 ;; 4.1. At a greater element: expected to skip contents.
2003 (org-forward-element)
2004 (should (looking-at (regexp-quote "Outside.")))
2005 ;; 4.2. At the end of greater element contents: expected to skip
2006 ;; to the end of the greater element.
2008 (org-forward-element)
2009 (should (looking-at (regexp-quote "Outside."))))
2011 (org-test-with-temp-text "
2025 ;; 5.1. At list top point: expected to move to the element after
2028 (org-forward-element)
2029 (should (looking-at (regexp-quote "Outside.")))
2030 ;; 5.2. Special case: at the first line of a sub-list, but not at
2031 ;; beginning of line, move to next item.
2034 (org-forward-element)
2035 (should (looking-at "- item2"))
2038 (org-forward-element)
2039 (should (looking-at " - sub2"))
2040 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
2042 (org-forward-element)
2043 (should (looking-at (regexp-quote " Inner paragraph.")))
2044 ;; 5.4. At sub-list end: expected to move outside the sub-list.
2046 (org-forward-element)
2047 (should (looking-at (regexp-quote " Inner paragraph.")))
2048 ;; 5.5. At an item: expected to move to next item, if any.
2050 (org-forward-element)
2051 (should (looking-at " - sub3"))))
2053 (ert-deftest test-org
/backward-element
()
2054 "Test `org-backward-element' specifications."
2055 ;; 1. Should error at BOB.
2056 (org-test-with-temp-text " \nParagraph."
2057 (should-error (org-backward-element)))
2058 ;; 2. Should move at BOB when called on the first element in buffer.
2060 (org-test-with-temp-text "\n#+TITLE: test"
2061 (progn (forward-line)
2062 (org-backward-element)
2064 ;; 3. Not at the beginning of an element: move at its beginning.
2065 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2068 (org-backward-element)
2069 (should (looking-at (regexp-quote "Paragraph2."))))
2070 ;; 4. Headline tests.
2071 (org-test-with-temp-text "
2076 ;; 4.1. At an headline beginning: move to previous headline at the
2079 (org-backward-element)
2080 (should (looking-at (regexp-quote "** Head 1.1")))
2081 ;; 4.2. At an headline beginning: move to parent headline if no
2082 ;; headline at the same level.
2084 (org-backward-element)
2085 (should (looking-at (regexp-quote "* Head 1")))
2086 ;; 4.3. At the first top-level headline: should error.
2088 (should-error (org-backward-element)))
2089 ;; 5. At beginning of first element inside a greater element:
2090 ;; expected to move to greater element's beginning.
2091 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
2093 (org-backward-element)
2094 (should (looking-at "#\\+BEGIN_CENTER")))
2095 ;; 6. At the beginning of the first element in a section: should
2096 ;; move back to headline, if any.
2098 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
2099 (progn (goto-char (point-max))
2101 (org-backward-element)
2102 (org-at-heading-p))))
2104 (org-test-with-temp-text "
2119 ;; 7.1. At beginning of sub-list: expected to move to the
2120 ;; paragraph before it.
2122 (org-backward-element)
2123 (should (looking-at "item1"))
2124 ;; 7.2. At an item in a list: expected to move at previous item.
2126 (org-backward-element)
2127 (should (looking-at " - sub2"))
2129 (org-backward-element)
2130 (should (looking-at "- item1"))
2131 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2134 (org-backward-element)
2135 (should (looking-at " - sub1"))
2137 (org-backward-element)
2138 (should (looking-at "- item1"))
2139 ;; 7.4. At blank-lines before list end: expected to move to top
2142 (org-backward-element)
2143 (should (looking-at "- item1"))))
2145 (ert-deftest test-org
/up-element
()
2146 "Test `org-up-element' specifications."
2147 ;; 1. At BOB or with no surrounding element: should error.
2148 (org-test-with-temp-text "Paragraph."
2149 (should-error (org-up-element)))
2150 (org-test-with-temp-text "* Head1\n* Head2"
2152 (should-error (org-up-element)))
2153 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2155 (should-error (org-up-element)))
2156 ;; 2. At an headline: move to parent headline.
2157 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2160 (should (looking-at "\\* Head1")))
2161 ;; 3. Inside a greater element: move to greater element beginning.
2162 (org-test-with-temp-text
2163 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2166 (should (looking-at "#\\+BEGIN_CENTER")))
2168 (org-test-with-temp-text "* Top
2175 Paragraph within sub2.
2178 ;; 4.1. Within an item: move to the item beginning.
2181 (should (looking-at " - sub2"))
2182 ;; 4.2. At an item in a sub-list: move to parent item.
2185 (should (looking-at "- item1"))
2186 ;; 4.3. At an item in top list: move to beginning of whole list.
2189 (should (looking-at "- item1"))
2190 ;; 4.4. Special case. At very top point: should move to parent of
2194 (should (looking-at "\\* Top"))))
2196 (ert-deftest test-org
/down-element
()
2197 "Test `org-down-element' specifications."
2198 ;; Error when the element hasn't got a recursive type.
2199 (org-test-with-temp-text "Paragraph."
2200 (should-error (org-down-element)))
2201 ;; Error when the element has no contents
2202 (org-test-with-temp-text "* Headline"
2203 (should-error (org-down-element)))
2204 ;; When at a plain-list, move to first item.
2205 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2208 (should (looking-at " - Item 1.1")))
2209 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2211 (should (looking-at " Item 1")))
2212 ;; When at a table, move to first row
2213 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2215 (should (looking-at " a | b |")))
2216 ;; Otherwise, move inside the greater element.
2217 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2219 (should (looking-at "Paragraph"))))
2221 (ert-deftest test-org
/drag-element-backward
()
2222 "Test `org-drag-element-backward' specifications."
2226 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2227 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2228 (org-drag-element-backward)
2232 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2233 (org-test-with-temp-text
2234 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2235 (org-drag-element-backward)
2237 ;; Preserve blank lines.
2239 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2240 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2241 (org-drag-element-backward)
2245 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2246 (org-drag-element-backward)
2247 (org-looking-at-p "2")))
2248 ;; Error when trying to move first element of buffer.
2250 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2251 (org-drag-element-backward)))
2252 ;; Error when trying to swap nested elements.
2254 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2256 (org-drag-element-backward)))
2257 ;; Error when trying to swap an headline element and a non-headline
2260 (org-test-with-temp-text "Test.\n* Head 1"
2262 (org-drag-element-backward)))
2263 ;; Preserve visibility of elements and their contents.
2265 (equal '((63 .
82) (26 .
48))
2266 (org-test-with-temp-text "
2274 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2275 (search-backward "- item 1")
2276 (org-drag-element-backward)
2277 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2278 (overlays-in (point-min) (point-max)))))))
2280 (ert-deftest test-org
/drag-element-forward
()
2281 "Test `org-drag-element-forward' specifications."
2282 ;; 1. Error when trying to move first element of buffer.
2283 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2285 (should-error (org-drag-element-forward)))
2286 ;; 2. Error when trying to swap nested elements.
2287 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2289 (should-error (org-drag-element-forward)))
2290 ;; 3. Error when trying to swap a non-headline element and an
2292 (org-test-with-temp-text "Test.\n* Head 1"
2293 (should-error (org-drag-element-forward)))
2294 ;; 4. Otherwise, swap elements, preserving column and blank lines
2295 ;; between elements.
2296 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2297 (search-forward "graph")
2298 (org-drag-element-forward)
2299 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2300 (should (looking-at " 1")))
2301 ;; 5. Preserve visibility of elements and their contents.
2302 (org-test-with-temp-text "
2310 (while (search-forward "BEGIN_" nil t
) (org-cycle))
2311 (search-backward "#+BEGIN_CENTER")
2312 (org-drag-element-forward)
2315 '((63 .
82) (26 .
48))
2316 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
2317 (overlays-in (point-min) (point-max)))))))
2319 (ert-deftest test-org
/next-block
()
2320 "Test `org-next-block' specifications."
2323 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2325 (looking-at "#\\+BEGIN_CENTER")))
2328 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
2329 (let ((case-fold-search nil
))
2331 (looking-at "#\\+begin_center"))))
2332 ;; Ignore current line.
2334 (org-test-with-temp-text
2335 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
2337 (looking-at "#\\+BEGIN_CENTER")))
2338 ;; Throw an error when no block is found.
2340 (org-test-with-temp-text "Paragraph"
2341 (org-next-block 1)))
2342 ;; With an argument, skip many blocks at once.
2344 (org-test-with-temp-text
2345 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2347 (looking-at "#\\+BEGIN_QUOTE")))
2348 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2350 (org-test-with-temp-text
2351 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
2352 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2353 (looking-at "#\\+BEGIN_QUOTE")))
2354 ;; Optional argument is also case-insensitive.
2356 (org-test-with-temp-text
2357 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
2358 (let ((case-fold-search nil
))
2359 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
2360 (looking-at "#\\+begin_quote")))))
2362 (ert-deftest test-org
/previous-block
()
2363 "Test `org-previous-block' specifications."
2366 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
2367 (org-previous-block 1)
2368 (looking-at "#\\+BEGIN_CENTER")))
2371 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
2372 (let ((case-fold-search nil
))
2373 (org-previous-block 1)
2374 (looking-at "#\\+begin_center"))))
2375 ;; Ignore current line.
2377 (org-test-with-temp-text
2378 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
2379 (org-previous-block 1)
2380 (looking-at "#\\+BEGIN_QUOTE")))
2381 ;; Throw an error when no block is found.
2383 (org-test-with-temp-text "Paragraph<point>"
2384 (org-previous-block 1)))
2385 ;; With an argument, skip many blocks at once.
2387 (org-test-with-temp-text
2388 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2389 (org-previous-block 2)
2390 (looking-at "#\\+BEGIN_CENTER")))
2391 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
2393 (org-test-with-temp-text
2394 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
2395 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2396 (looking-at "#\\+BEGIN_QUOTE")))
2397 ;; Optional argument is also case-insensitive.
2399 (org-test-with-temp-text
2400 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
2401 (let ((case-fold-search nil
))
2402 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
2403 (looking-at "#\\+begin_quote")))))
2406 ;;; Outline structure
2408 (ert-deftest test-org
/demote
()
2409 "Test `org-demote' specifications."
2410 ;; Add correct number of stars according to `org-odd-levels-only'.
2413 (org-test-with-temp-text "* H"
2414 (let ((org-odd-levels-only nil
)) (org-demote))
2415 (org-current-level))))
2418 (org-test-with-temp-text "* H"
2419 (let ((org-odd-levels-only t
)) (org-demote))
2420 (org-current-level))))
2421 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2423 (org-test-with-temp-text "* H :tag:"
2424 (let ((org-tags-column 10)
2425 (org-auto-align-tags t
)
2426 (org-odd-levels-only nil
))
2428 (org-move-to-column 10)
2429 (org-looking-at-p ":tag:$")))
2431 (org-test-with-temp-text "* H :tag:"
2432 (let ((org-tags-column 10)
2433 (org-auto-align-tags nil
)
2434 (org-odd-levels-only nil
))
2436 (org-move-to-column 10)
2437 (org-looking-at-p ":tag:$")))
2438 ;; When `org-adapt-indentation' is non-nil, always indent planning
2439 ;; info and property drawers accordingly.
2442 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2443 (let ((org-odd-levels-only nil
)
2444 (org-adapt-indentation t
))
2447 (org-get-indentation))))
2450 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2451 (let ((org-odd-levels-only nil
)
2452 (org-adapt-indentation t
))
2455 (org-get-indentation))))
2458 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2459 (let ((org-odd-levels-only nil
)
2460 (org-adapt-indentation nil
))
2463 (org-get-indentation))))
2464 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2465 ;; section accordingly. Ignore, however, footnote definitions and
2466 ;; inlinetasks boundaries.
2469 (org-test-with-temp-text "* H\n Paragraph"
2470 (let ((org-odd-levels-only nil
)
2471 (org-adapt-indentation t
))
2474 (org-get-indentation))))
2477 (org-test-with-temp-text "* H\n Paragraph"
2478 (let ((org-odd-levels-only nil
)
2479 (org-adapt-indentation nil
))
2482 (org-get-indentation))))
2485 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2486 (let ((org-odd-levels-only nil
)
2487 (org-adapt-indentation t
))
2489 (goto-char (point-max))
2490 (org-get-indentation))))
2493 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2494 (let ((org-odd-levels-only nil
)
2495 (org-adapt-indentation t
))
2497 (goto-char (point-max))
2498 (org-get-indentation))))
2499 (when (featurep 'org-inlinetask
)
2502 (let ((org-inlinetask-min-level 5)
2503 (org-adapt-indentation t
))
2504 (org-test-with-temp-text "* H\n***** I\n***** END"
2507 (org-get-indentation))))))
2508 (when (featurep 'org-inlinetask
)
2511 (let ((org-inlinetask-min-level 5)
2512 (org-adapt-indentation t
))
2513 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2516 (org-get-indentation))))))
2517 ;; Ignore contents of source blocks or example blocks when
2518 ;; indentation should be preserved (through
2519 ;; `org-src-preserve-indentation' or "-i" flag).
2522 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2523 (let ((org-adapt-indentation t
)
2524 (org-src-preserve-indentation nil
))
2527 (org-get-indentation))))
2530 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2531 (let ((org-adapt-indentation t
)
2532 (org-src-preserve-indentation t
))
2535 (org-get-indentation))))
2538 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2539 (let ((org-adapt-indentation t
)
2540 (org-src-preserve-indentation t
))
2543 (org-get-indentation))))
2546 (org-test-with-temp-text
2547 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2548 (let ((org-adapt-indentation t
)
2549 (org-src-preserve-indentation nil
))
2552 (org-get-indentation)))))
2554 (ert-deftest test-org
/promote
()
2555 "Test `org-promote' specifications."
2556 ;; Return an error if headline is to be promoted to level 0, unless
2557 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2558 ;; headline becomes a comment.
2560 (org-test-with-temp-text "* H"
2561 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
2564 (org-test-with-temp-text "* H"
2565 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
2567 ;; Remove correct number of stars according to
2568 ;; `org-odd-levels-only'.
2571 (org-test-with-temp-text "*** H"
2572 (let ((org-odd-levels-only nil
)) (org-promote))
2573 (org-current-level))))
2576 (org-test-with-temp-text "*** H"
2577 (let ((org-odd-levels-only t
)) (org-promote))
2578 (org-current-level))))
2579 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2581 (org-test-with-temp-text "** H :tag:"
2582 (let ((org-tags-column 10)
2583 (org-auto-align-tags t
)
2584 (org-odd-levels-only nil
))
2586 (org-move-to-column 10)
2587 (org-looking-at-p ":tag:$")))
2589 (org-test-with-temp-text "** H :tag:"
2590 (let ((org-tags-column 10)
2591 (org-auto-align-tags nil
)
2592 (org-odd-levels-only nil
))
2594 (org-move-to-column 10)
2595 (org-looking-at-p ":tag:$")))
2596 ;; When `org-adapt-indentation' is non-nil, always indent planning
2597 ;; info and property drawers.
2600 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2601 (let ((org-odd-levels-only nil
)
2602 (org-adapt-indentation t
))
2605 (org-get-indentation))))
2608 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2609 (let ((org-odd-levels-only nil
)
2610 (org-adapt-indentation t
))
2613 (org-get-indentation))))
2616 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2617 (let ((org-odd-levels-only nil
)
2618 (org-adapt-indentation nil
))
2621 (org-get-indentation))))
2622 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2623 ;; section accordingly. Ignore, however, footnote definitions and
2624 ;; inlinetasks boundaries.
2627 (org-test-with-temp-text "** H\n Paragraph"
2628 (let ((org-odd-levels-only nil
)
2629 (org-adapt-indentation t
))
2632 (org-get-indentation))))
2635 (org-test-with-temp-text "** H\n Paragraph"
2636 (let ((org-odd-levels-only nil
)
2637 (org-adapt-indentation nil
))
2640 (org-get-indentation))))
2643 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2644 (let ((org-odd-levels-only nil
)
2645 (org-adapt-indentation t
))
2648 (org-get-indentation))))
2649 (when (featurep 'org-inlinetask
)
2652 (let ((org-inlinetask-min-level 5)
2653 (org-adapt-indentation t
))
2654 (org-test-with-temp-text "** H\n***** I\n***** END"
2657 (org-get-indentation))))))
2658 (when (featurep 'org-inlinetask
)
2661 (let ((org-inlinetask-min-level 5)
2662 (org-adapt-indentation t
))
2663 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2666 (org-get-indentation))))))
2667 ;; Give up shifting if it would break document's structure
2671 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2672 (let ((org-odd-levels-only nil
)
2673 (org-adapt-indentation t
))
2676 (org-get-indentation))))
2679 (org-test-with-temp-text "** H\n Paragraph\n * list."
2680 (let ((org-odd-levels-only nil
)
2681 (org-adapt-indentation t
))
2684 (org-get-indentation))))
2685 ;; Ignore contents of source blocks or example blocks when
2686 ;; indentation should be preserved (through
2687 ;; `org-src-preserve-indentation' or "-i" flag).
2690 (org-test-with-temp-text
2691 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2692 (let ((org-adapt-indentation t
)
2693 (org-src-preserve-indentation nil
)
2694 (org-odd-levels-only nil
))
2697 (org-get-indentation))))
2700 (org-test-with-temp-text
2701 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2702 (let ((org-adapt-indentation t
)
2703 (org-src-preserve-indentation t
)
2704 (org-odd-levels-only nil
))
2707 (org-get-indentation))))
2710 (org-test-with-temp-text
2711 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2712 (let ((org-adapt-indentation t
)
2713 (org-src-preserve-indentation t
)
2714 (org-odd-levels-only nil
))
2717 (org-get-indentation))))
2720 (org-test-with-temp-text
2721 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2722 (let ((org-adapt-indentation t
)
2723 (org-src-preserve-indentation nil
)
2724 (org-odd-levels-only nil
))
2727 (org-get-indentation)))))
2732 (ert-deftest test-org
/at-planning-p
()
2733 "Test `org-at-planning-p' specifications."
2736 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2737 (org-at-planning-p)))
2739 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2740 (org-at-planning-p)))
2741 ;; Correctly find planning attached to inlinetasks.
2742 (when (featurep 'org-inlinetask
)
2744 (org-test-with-temp-text
2745 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2746 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2748 (org-test-with-temp-text
2749 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2750 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2752 (org-test-with-temp-text
2753 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2754 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2756 (org-test-with-temp-text
2757 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2758 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2763 (ert-deftest test-org
/buffer-property-keys
()
2764 "Test `org-buffer-property-keys' specifications."
2765 ;; Retrieve properties accross siblings.
2768 (org-test-with-temp-text "
2777 (org-buffer-property-keys))))
2778 ;; Retrieve properties accross children.
2781 (org-test-with-temp-text "
2790 (org-buffer-property-keys))))
2791 ;; Retrieve muliple properties in the same drawer.
2794 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2795 (org-buffer-property-keys))))
2796 ;; Ignore extension symbol in property name.
2799 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2800 (org-buffer-property-keys))))
2801 ;; With non-nil COLUMNS, extract property names from columns.
2804 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2805 (org-buffer-property-keys nil nil t
))))
2807 (equal '("A" "B" "COLUMNS")
2808 (org-test-with-temp-text
2809 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2810 (org-buffer-property-keys nil nil t
)))))
2812 (ert-deftest test-org
/property-values
()
2813 "Test `org-property-values' specifications."
2817 (org-test-with-temp-text
2818 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2819 (org-property-values "A"))))
2820 ;; Ignore empty values.
2822 (org-test-with-temp-text
2823 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2824 (org-property-values "A")))
2825 ;; Take into consideration extended values.
2828 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2829 (org-property-values "A")))))
2831 (ert-deftest test-org
/find-property
()
2832 "Test `org-find-property' specifications."
2836 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
2837 (org-find-property "prop"))))
2838 ;; Ignore false positives.
2841 (org-test-with-temp-text
2842 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
2843 (org-find-property "A"))))
2844 ;; Return first entry found in buffer.
2847 (org-test-with-temp-text
2848 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2849 (org-find-property "A"))))
2850 ;; Only search visible part of the buffer.
2853 (org-test-with-temp-text
2854 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
2855 (org-narrow-to-subtree)
2856 (org-find-property "A"))))
2857 ;; With optional argument, only find entries with a specific value.
2859 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2860 (org-find-property "A" "2")))
2863 (org-test-with-temp-text
2864 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
2865 (org-find-property "A" "2"))))
2866 ;; Use "nil" for explicit nil values.
2869 (org-test-with-temp-text
2870 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
2871 (org-find-property "A" "nil")))))
2873 (ert-deftest test-org
/entry-delete
()
2874 "Test `org-entry-delete' specifications."
2878 " *:PROPERTIES:\n *:B: +2\n *:END:"
2879 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2880 (org-entry-delete (point) "A")
2882 ;; Also remove accumulated properties.
2886 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
2887 (org-entry-delete (point) "A")
2889 ;; When last property is removed, remove the property drawer.
2893 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2894 (org-entry-delete (point) "A")
2896 ;; Return a non-nil value when some property was removed.
2898 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2899 (org-entry-delete (point) "A")))
2901 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2902 (org-entry-delete (point) "C"))))
2904 (ert-deftest test-org
/entry-get
()
2905 "Test `org-entry-get' specifications."
2909 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2910 (org-entry-get (point) "A"))))
2914 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2915 (org-entry-get (point) "a"))))
2916 ;; Handle extended values, both before and after base value.
2919 (org-test-with-temp-text
2920 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2921 (org-entry-get (point) "A"))))
2922 ;; Empty values are returned as the empty string.
2925 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2926 (org-entry-get (point) "A"))))
2927 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2928 ;; otherwise, return nil.
2930 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2931 (org-entry-get (point) "A")))
2934 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2935 (org-entry-get (point) "A" nil t
))))
2936 ;; Return nil when no property is found, independently on the
2937 ;; LITERAL-NIL argument.
2939 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2940 (org-entry-get (point) "B")))
2942 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2943 (org-entry-get (point) "B" nil t
)))
2944 ;; Handle inheritance, when allowed.
2948 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2949 (org-entry-get (point) "A" t
))))
2953 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2954 (let ((org-use-property-inheritance t
))
2955 (org-entry-get (point) "A" 'selective
)))))
2957 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2958 (let ((org-use-property-inheritance nil
))
2959 (org-entry-get (point) "A" 'selective
)))))
2961 (ert-deftest test-org
/entry-properties
()
2962 "Test `org-entry-properties' specifications."
2963 ;; Get "ITEM" property.
2966 (org-test-with-temp-text "* TODO H"
2967 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
2970 (org-test-with-temp-text "* TODO H"
2971 (cdr (assoc "ITEM" (org-entry-properties))))))
2972 ;; Get "TODO" property.
2975 (org-test-with-temp-text "* TODO H"
2976 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
2979 (org-test-with-temp-text "* TODO H"
2980 (cdr (assoc "TODO" (org-entry-properties))))))
2982 (org-test-with-temp-text "* H"
2983 (assoc "TODO" (org-entry-properties nil
"TODO"))))
2984 ;; Get "PRIORITY" property.
2987 (org-test-with-temp-text "* [#A] H"
2988 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
2991 (org-test-with-temp-text "* [#A] H"
2992 (cdr (assoc "PRIORITY" (org-entry-properties))))))
2994 (org-test-with-temp-text "* H"
2995 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
2996 ;; Get "FILE" property.
2998 (org-test-with-temp-text-in-file "* H\nParagraph"
2999 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
3000 (buffer-file-name))))
3002 (org-test-with-temp-text-in-file "* H\nParagraph"
3003 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
3004 (buffer-file-name))))
3006 (org-test-with-temp-text "* H\nParagraph"
3007 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
3008 ;; Get "TAGS" property.
3010 (equal ":tag1:tag2:"
3011 (org-test-with-temp-text "* H :tag1:tag2:"
3012 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
3014 (equal ":tag1:tag2:"
3015 (org-test-with-temp-text "* H :tag1:tag2:"
3016 (cdr (assoc "TAGS" (org-entry-properties))))))
3018 (org-test-with-temp-text "* H"
3019 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
3020 ;; Get "ALLTAGS" property.
3022 (equal ":tag1:tag2:"
3023 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3024 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
3026 (equal ":tag1:tag2:"
3027 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
3028 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
3030 (org-test-with-temp-text "* H"
3031 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
3032 ;; Get "BLOCKED" property.
3035 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
3036 (let ((org-enforce-todo-dependencies t
)
3038 '(org-block-todo-from-children-or-siblings-or-parent)))
3039 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3042 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
3043 (let ((org-enforce-todo-dependencies t
)
3045 '(org-block-todo-from-children-or-siblings-or-parent)))
3046 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
3049 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
3050 (let ((org-enforce-todo-dependencies t
))
3051 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
3052 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
3056 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3057 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
3061 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
3062 (cdr (assoc "CLOSED" (org-entry-properties))))))
3064 (org-test-with-temp-text "* H"
3065 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
3069 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3070 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
3074 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3075 (cdr (assoc "DEADLINE" (org-entry-properties))))))
3077 (org-test-with-temp-text "* H"
3078 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
3082 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3083 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
3087 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3088 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
3090 (org-test-with-temp-text "* H"
3091 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
3095 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3096 (cdr (assoc "CATEGORY" (org-entry-properties))))))
3099 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
3100 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3103 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
3104 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3107 (org-test-with-temp-text
3108 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
3110 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
3111 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
3112 ;; Get standard properties.
3115 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3116 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3117 ;; Handle extended properties.
3120 (org-test-with-temp-text
3121 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
3122 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3125 (org-test-with-temp-text
3126 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
3127 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
3128 ;; Ignore forbidden (special) properties.
3130 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
3131 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
3133 (ert-deftest test-org
/entry-put
()
3134 "Test `org-entry-put' specifications."
3135 ;; Error when not a string or nil.
3137 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
3138 (org-entry-put 1 "test" 2)))
3139 ;; Set "TODO" property.
3141 (string-match (regexp-quote " TODO H")
3142 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3143 (org-entry-put (point) "TODO" "TODO")
3146 (string-match (regexp-quote "* H")
3147 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
3148 (org-entry-put (point) "TODO" nil
)
3150 ;; Set "PRIORITY" property.
3153 (org-test-with-temp-text "* [#B] H"
3154 (org-entry-put (point) "PRIORITY" "A")
3158 (org-test-with-temp-text "* [#B] H"
3159 (org-entry-put (point) "PRIORITY" nil
)
3161 ;; Set "SCHEDULED" property.
3163 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
3164 (org-test-with-temp-text "* H"
3165 (org-entry-put (point) "SCHEDULED" "2014-03-04")
3169 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3170 (org-entry-put (point) "SCHEDULED" nil
)
3173 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
3174 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3175 (org-entry-put (point) "SCHEDULED" "earlier")
3178 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
3179 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
3180 (org-entry-put (point) "SCHEDULED" "later")
3182 ;; Set "DEADLINE" property.
3184 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
3185 (org-test-with-temp-text "* H"
3186 (org-entry-put (point) "DEADLINE" "2014-03-04")
3190 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3191 (org-entry-put (point) "DEADLINE" nil
)
3194 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
3195 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3196 (org-entry-put (point) "DEADLINE" "earlier")
3199 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
3200 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
3201 (org-entry-put (point) "DEADLINE" "later")
3203 ;; Set "CATEGORY" property
3205 (string-match "^ *:CATEGORY: cat"
3206 (org-test-with-temp-text "* H"
3207 (org-entry-put (point) "CATEGORY" "cat")
3209 ;; Regular properties, with or without pre-existing drawer.
3211 (string-match "^ *:A: +2$"
3212 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
3213 (org-entry-put (point) "A" "2")
3216 (string-match "^ *:A: +1$"
3217 (org-test-with-temp-text "* H"
3218 (org-entry-put (point) "A" "1")
3220 ;; Special case: two consecutive headlines.
3222 (string-match "\\* A\n *:PROPERTIES:"
3223 (org-test-with-temp-text "* A\n** B"
3224 (org-entry-put (point) "A" "1")
3230 (ert-deftest test-org
/update-radio-target-regexp
()
3231 "Test `org-update-radio-target-regexp' specifications."
3232 ;; Properly update cache with no previous radio target regexp.
3235 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3236 (save-excursion (goto-char (point-max)) (org-element-context))
3238 (search-forward "o")
3240 (org-update-radio-target-regexp)
3241 (goto-char (point-max))
3242 (org-element-type (org-element-context)))))
3243 ;; Properly update cache with previous radio target regexp.
3246 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
3247 (save-excursion (goto-char (point-max)) (org-element-context))
3249 (search-forward "o")
3251 (org-update-radio-target-regexp)
3252 (search-backward "r")
3255 (org-update-radio-target-regexp)
3256 (goto-char (point-max))
3257 (delete-region (line-beginning-position) (point))
3259 (org-element-type (org-element-context))))))
3264 (ert-deftest test-org
/match-sparse-tree
()
3265 "Test `org-match-sparse-tree' specifications."
3268 (org-test-with-temp-text "* H\n** H1 :tag:"
3269 (org-match-sparse-tree nil
"tag")
3270 (search-forward "H1")
3271 (org-invisible-p2)))
3273 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3274 (org-match-sparse-tree nil
"tag")
3275 (search-forward "H2")
3276 (org-invisible-p2)))
3277 ;; "-" operator for tags.
3279 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3280 (org-match-sparse-tree nil
"tag1-tag2")
3281 (search-forward "H1")
3282 (org-invisible-p2)))
3284 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3285 (org-match-sparse-tree nil
"tag1-tag2")
3286 (search-forward "H2")
3287 (org-invisible-p2)))
3288 ;; "&" operator for tags.
3290 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3291 (org-match-sparse-tree nil
"tag1&tag2")
3292 (search-forward "H1")
3293 (org-invisible-p2)))
3295 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3296 (org-match-sparse-tree nil
"tag1&tag2")
3297 (search-forward "H2")
3298 (org-invisible-p2)))
3299 ;; "|" operator for tags.
3301 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3302 (org-match-sparse-tree nil
"tag1|tag2")
3303 (search-forward "H1")
3304 (org-invisible-p2)))
3306 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3307 (org-match-sparse-tree nil
"tag1|tag2")
3308 (search-forward "H2")
3309 (org-invisible-p2)))
3310 ;; Regexp match on tags.
3312 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3313 (org-match-sparse-tree nil
"{^tag.*}")
3314 (search-forward "H1")
3315 (org-invisible-p2)))
3317 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3318 (org-match-sparse-tree nil
"{^tag.*}")
3319 (search-forward "H2")
3320 (org-invisible-p2)))
3321 ;; Match group tags.
3323 (org-test-with-temp-text
3324 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3325 (org-match-sparse-tree nil
"work")
3326 (search-forward "H1")
3327 (org-invisible-p2)))
3329 (org-test-with-temp-text
3330 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3331 (org-match-sparse-tree nil
"work")
3332 (search-forward "H2")
3333 (org-invisible-p2)))
3334 ;; Match group tags with hard brackets.
3336 (org-test-with-temp-text
3337 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3338 (org-match-sparse-tree nil
"work")
3339 (search-forward "H1")
3340 (org-invisible-p2)))
3342 (org-test-with-temp-text
3343 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
3344 (org-match-sparse-tree nil
"work")
3345 (search-forward "H2")
3346 (org-invisible-p2)))
3347 ;; Match tags in hierarchies
3349 (org-test-with-temp-text
3350 "#+TAGS: [ Lev_1 : Lev_2 ]\n
3351 #+TAGS: [ Lev_2 : Lev_3 ]\n
3352 #+TAGS: { Lev_3 : Lev_4 }\n
3353 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
3354 (org-match-sparse-tree nil
"Lev_1")
3355 (search-forward "H4")
3356 (org-invisible-p2)))
3357 ;; Match regular expressions in tags
3359 (org-test-with-temp-text
3360 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
3361 (org-match-sparse-tree nil
"Lev")
3362 (search-forward "H1")
3363 (org-invisible-p2)))
3365 (org-test-with-temp-text
3366 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
3367 (org-match-sparse-tree nil
"Lev")
3368 (search-forward "H1")
3369 (org-invisible-p2)))
3370 ;; Match properties.
3372 (org-test-with-temp-text
3373 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3374 (org-match-sparse-tree nil
"A=\"1\"")
3375 (search-forward "H2")
3376 (org-invisible-p2)))
3378 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3379 (org-match-sparse-tree nil
"A=\"1\"")
3380 (search-forward "H2")
3381 (org-invisible-p2)))
3382 ;; Case is not significant when matching properties.
3384 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3385 (org-match-sparse-tree nil
"a=\"1\"")
3386 (search-forward "H2")
3387 (org-invisible-p2)))
3389 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3390 (org-match-sparse-tree nil
"A=\"1\"")
3391 (search-forward "H2")
3392 (org-invisible-p2)))
3393 ;; Match special LEVEL property.
3395 (org-test-with-temp-text "* H\n** H1\n*** H2"
3396 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3397 (search-forward "H1")
3398 (org-invisible-p2)))
3400 (org-test-with-temp-text "* H\n** H1\n*** H2"
3401 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
3402 (search-forward "H2")
3403 (org-invisible-p2)))
3404 ;; Comparison operators when matching properties.
3406 (org-test-with-temp-text
3407 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3408 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3409 (search-forward "H1")
3410 (org-invisible-p2)))
3412 (org-test-with-temp-text
3413 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3414 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
3415 (search-forward "H2")
3416 (org-invisible-p2)))
3417 ;; Regexp match on properties values.
3419 (org-test-with-temp-text
3420 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3421 (org-match-sparse-tree nil
"A={f.*}")
3422 (search-forward "H1")
3423 (org-invisible-p2)))
3425 (org-test-with-temp-text
3426 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3427 (org-match-sparse-tree nil
"A={f.*}")
3428 (search-forward "H2")
3429 (org-invisible-p2)))
3430 ;; With an optional argument, limit match to TODO entries.
3432 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3433 (org-match-sparse-tree t
"tag")
3434 (search-forward "H1")
3435 (org-invisible-p2)))
3437 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3438 (org-match-sparse-tree t
"tag")
3439 (search-forward "H2")
3440 (org-invisible-p2))))
3445 (ert-deftest test-org
/time-stamp
()
3446 "Test `org-time-stamp' specifications."
3447 ;; Insert chosen time stamp at point.
3450 "Te<2014-03-04 .*?>xt"
3451 (org-test-with-temp-text "Te<point>xt"
3452 (flet ((org-read-date
3454 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3455 (org-time-stamp nil
)
3457 ;; With a prefix argument, also insert time.
3460 "Te<2014-03-04 .*? 00:41>xt"
3461 (org-test-with-temp-text "Te<point>xt"
3462 (flet ((org-read-date
3464 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3465 (org-time-stamp '(4))
3467 ;; With two universal prefix arguments, insert an active timestamp
3468 ;; with the current time without prompting the user.
3471 "Te<2014-03-04 .*? 00:41>xt"
3472 (org-test-with-temp-text "Te<point>xt"
3473 (flet ((current-time
3475 (apply #'encode-time
(org-parse-time-string "2014-03-04 00:41"))))
3476 (org-time-stamp '(16))
3478 ;; When optional argument is non-nil, insert an inactive timestamp.
3481 "Te\\[2014-03-04 .*?\\]xt"
3482 (org-test-with-temp-text "Te<point>xt"
3483 (flet ((org-read-date
3485 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3486 (org-time-stamp nil t
)
3488 ;; When called from a timestamp, replace existing one.
3492 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3493 (flet ((org-read-date
3495 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3496 (org-time-stamp nil
)
3500 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3501 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3502 (flet ((org-read-date
3504 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3505 (org-time-stamp nil
)
3507 ;; When replacing a timestamp, preserve repeater, if any.
3510 "<2014-03-04 .*? \\+2y>"
3511 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3512 (flet ((org-read-date
3514 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3515 (org-time-stamp nil
)
3517 ;; When called twice in a raw, build a date range.
3520 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3521 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3522 (flet ((org-read-date
3524 (apply #'encode-time
(org-parse-time-string "2014-03-04"))))
3525 (let ((last-command 'org-time-stamp
)
3526 (this-command 'org-time-stamp
))
3527 (org-time-stamp nil
))
3528 (buffer-string))))))
3530 (ert-deftest test-org
/timestamp-has-time-p
()
3531 "Test `org-timestamp-has-time-p' specifications."
3534 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3535 (org-timestamp-has-time-p (org-element-context))))
3538 (org-test-with-temp-text "<2012-03-29 Thu>"
3539 (org-timestamp-has-time-p (org-element-context)))))
3541 (ert-deftest test-org
/timestamp-format
()
3542 "Test `org-timestamp-format' specifications."
3547 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3548 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3553 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3554 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
3556 (ert-deftest test-org
/timestamp-split-range
()
3557 "Test `org-timestamp-split-range' specifications."
3558 ;; Extract range start (active).
3561 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3562 (let ((ts (org-timestamp-split-range (org-element-context))))
3563 (mapcar (lambda (p) (org-element-property p ts
))
3564 '(:year-end
:month-end
:day-end
))))))
3565 ;; Extract range start (inactive)
3568 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3569 (let ((ts (org-timestamp-split-range (org-element-context))))
3570 (mapcar (lambda (p) (org-element-property p ts
))
3571 '(:year-end
:month-end
:day-end
))))))
3572 ;; Extract range end (active).
3575 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3576 (let ((ts (org-timestamp-split-range
3577 (org-element-context) t
)))
3578 (mapcar (lambda (p) (org-element-property p ts
))
3579 '(:year-end
:month-end
:day-end
))))))
3580 ;; Extract range end (inactive)
3583 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3584 (let ((ts (org-timestamp-split-range
3585 (org-element-context) t
)))
3586 (mapcar (lambda (p) (org-element-property p ts
))
3587 '(:year-end
:month-end
:day-end
))))))
3588 ;; Return the timestamp if not a range.
3590 (org-test-with-temp-text "[2012-03-29 Thu]"
3591 (let* ((ts-orig (org-element-context))
3592 (ts-copy (org-timestamp-split-range ts-orig
)))
3593 (eq ts-orig ts-copy
))))
3595 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3596 (let* ((ts-orig (org-element-context))
3597 (ts-copy (org-timestamp-split-range ts-orig
)))
3598 (eq ts-orig ts-copy
)))))
3600 (ert-deftest test-org
/timestamp-translate
()
3601 "Test `org-timestamp-translate' specifications."
3602 ;; Translate whole date range.
3605 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3606 (let ((org-display-custom-times t
)
3607 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3608 (org-timestamp-translate (org-element-context))))))
3609 ;; Translate date range start.
3612 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3613 (let ((org-display-custom-times t
)
3614 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3615 (org-timestamp-translate (org-element-context) 'start
)))))
3616 ;; Translate date range end.
3619 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3620 (let ((org-display-custom-times t
)
3621 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3622 (org-timestamp-translate (org-element-context) 'end
)))))
3623 ;; Translate time range.
3626 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3627 (let ((org-display-custom-times t
)
3628 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
3629 (org-timestamp-translate (org-element-context))))))
3630 ;; Translate non-range timestamp.
3633 (org-test-with-temp-text "<2012-03-29 Thu>"
3634 (let ((org-display-custom-times t
)
3635 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3636 (org-timestamp-translate (org-element-context))))))
3637 ;; Do not change `diary' timestamps.
3639 (equal "<%%(org-float t 4 2)>"
3640 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3641 (let ((org-display-custom-times t
)
3642 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
3643 (org-timestamp-translate (org-element-context)))))))
3649 (ert-deftest test-org
/flag-drawer
()
3650 "Test `org-flag-drawer' specifications."
3653 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3655 (get-char-property (line-end-position) 'invisible
)))
3658 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3660 (org-flag-drawer nil
)
3661 (get-char-property (line-end-position) 'invisible
)))
3662 ;; Test optional argument.
3664 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3665 (let ((drawer (save-excursion (search-forward ":D2")
3666 (org-element-at-point))))
3667 (org-flag-drawer t drawer
)
3668 (get-char-property (progn (search-forward ":D2") (line-end-position))
3671 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3672 (let ((drawer (save-excursion (search-forward ":D2")
3673 (org-element-at-point))))
3674 (org-flag-drawer t drawer
)
3675 (get-char-property (line-end-position) 'invisible
))))
3676 ;; Do not hide fake drawers.
3678 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3681 (get-char-property (line-end-position) 'invisible
)))
3682 ;; Do not hide incomplete drawers.
3684 (org-test-with-temp-text ":D:\nparagraph"
3687 (get-char-property (line-end-position) 'invisible
)))
3688 ;; Do not hide drawers when called from final blank lines.
3690 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3691 (goto-char (point-max))
3693 (goto-char (point-min))
3694 (get-char-property (line-end-position) 'invisible
)))
3695 ;; Don't leave point in an invisible part of the buffer when hiding
3698 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3699 (goto-char (point-max))
3701 (get-char-property (point) 'invisible
))))
3703 (ert-deftest test-org
/hide-block-toggle
()
3704 "Test `org-hide-block-toggle' specifications."
3705 ;; Error when not at a block.
3707 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3708 (org-hide-block-toggle 'off
)
3709 (get-char-property (line-end-position) 'invisible
)))
3712 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3713 (org-hide-block-toggle)
3714 (get-char-property (line-end-position) 'invisible
)))
3716 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3717 (org-hide-block-toggle)
3718 (get-char-property (line-end-position) 'invisible
)))
3719 ;; Show block unconditionally when optional argument is `off'.
3721 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3722 (org-hide-block-toggle)
3723 (org-hide-block-toggle 'off
)
3724 (get-char-property (line-end-position) 'invisible
)))
3726 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3727 (org-hide-block-toggle 'off
)
3728 (get-char-property (line-end-position) 'invisible
)))
3729 ;; Hide block unconditionally when optional argument is non-nil.
3731 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3732 (org-hide-block-toggle t
)
3733 (get-char-property (line-end-position) 'invisible
)))
3735 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3736 (org-hide-block-toggle)
3737 (org-hide-block-toggle t
)
3738 (get-char-property (line-end-position) 'invisible
)))
3739 ;; Do not hide block when called from final blank lines.
3741 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3742 (org-hide-block-toggle)
3743 (goto-char (point-min))
3744 (get-char-property (line-end-position) 'invisible
)))
3745 ;; Don't leave point in an invisible part of the buffer when hiding
3748 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3749 (org-hide-block-toggle)
3750 (get-char-property (point) 'invisible
))))
3752 (ert-deftest test-org
/hide-block-toggle-maybe
()
3753 "Test `org-hide-block-toggle-maybe' specifications."
3755 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3756 (org-hide-block-toggle-maybe)))
3758 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3760 (ert-deftest test-org
/show-set-visibility
()
3761 "Test `org-show-set-visibility' specifications."
3762 ;; Do not throw an error before first heading.
3764 (org-test-with-temp-text "Preamble\n* Headline"
3765 (org-show-set-visibility 'tree
)
3767 ;; Test all visibility spans, both on headline and in entry.
3768 (let ((list-visible-lines
3769 (lambda (state headerp
)
3770 (org-test-with-temp-text "* Grandmother (0)
3781 **** The other child (11)
3786 (search-forward (if headerp
"Self" "Match"))
3787 (org-show-set-visibility state
)
3788 (goto-char (point-min))
3789 (let (result (line 0))
3791 (unless (org-invisible-p2) (push line result
))
3794 (nreverse result
))))))
3795 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
3796 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
3797 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
3798 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
3799 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
3800 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
3801 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
3802 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
3803 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
3804 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3805 (funcall list-visible-lines
'tree nil
)))
3806 (should (equal '(0 1 3 4 5 7 12 13)
3807 (funcall list-visible-lines
'canonical t
)))
3808 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3809 (funcall list-visible-lines
'canonical nil
)))))
3814 ;;; test-org.el ends here