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")))))
196 (ert-deftest test-org
/org-parse-time-string
()
197 "Test `org-parse-time-string'."
198 (should (equal (org-parse-time-string "2012-03-29 16:40")
199 '(0 40 16 29 3 2012 nil nil nil
)))
200 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
201 '(0 40 16 29 3 2012 nil nil nil
)))
202 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
203 '(0 40 16 29 3 2012 nil nil nil
)))
204 (should (equal (org-parse-time-string "<2012-03-29>")
205 '(0 0 0 29 3 2012 nil nil nil
)))
206 (should (equal (org-parse-time-string "<2012-03-29>" t
)
207 '(0 nil nil
29 3 2012 nil nil nil
))))
212 (ert-deftest test-org
/insert-property-drawer
()
213 "Test `org-insert-property-drawer' specifications."
214 ;; Error before first headline.
215 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
216 ;; Insert drawer right after headline if there is no planning line,
217 ;; or after it otherwise.
219 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
220 (org-test-with-temp-text "* H\nParagraph<point>"
221 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
224 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
225 (org-test-with-temp-text
226 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
227 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
229 ;; Indent inserted drawer.
231 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
232 (org-test-with-temp-text "* H\nParagraph<point>"
233 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
235 ;; Handle insertion at eob.
237 (equal "* H\n:PROPERTIES:\n:END:\n"
238 (org-test-with-temp-text "* H"
239 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
241 ;; Skip inlinetasks before point.
242 (when (featurep 'org-inlinetask
)
244 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
245 (org-test-with-temp-text
246 "* H\n*************** I\n*************** END\nP<point>"
247 (let ((org-adapt-indentation nil
)
248 (org-inlinetask-min-level 15))
249 (org-insert-property-drawer))
251 ;; Correctly set drawer in an inlinetask.
252 (when (featurep 'org-inlinetask
)
254 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
255 (org-test-with-temp-text
256 "* H\n*************** I\nP<point>\n*************** END"
257 (let ((org-adapt-indentation nil
)
258 (org-inlinetask-min-level 15))
259 (org-insert-property-drawer))
265 (ert-deftest test-org
/fill-paragraph
()
266 "Test `org-fill-paragraph' specifications."
267 ;; At an Org table, align it.
270 (org-test-with-temp-text "|a|"
274 (equal "#+name: table\n| a |\n"
275 (org-test-with-temp-text "#+name: table\n| a |"
278 ;; At a paragraph, preserve line breaks.
279 (org-test-with-temp-text "some \\\\\nlong\ntext"
280 (let ((fill-column 20))
282 (should (equal (buffer-string) "some \\\\\nlong text"))))
283 ;; Correctly fill a paragraph when point is at its very end.
286 (org-test-with-temp-text "A\nB"
287 (let ((fill-column 20))
288 (goto-char (point-max))
291 ;; Correctly fill the last paragraph of a greater element.
293 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
294 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
295 (let ((fill-column 8))
300 ;; Correctly fill an element in a narrowed buffer.
303 (org-test-with-temp-text "01234 6789"
304 (let ((fill-column 5))
305 (narrow-to-region 1 8)
308 ;; Handle `adaptive-fill-regexp' in paragraphs.
311 (org-test-with-temp-text "> a\n> b"
312 (let ((fill-column 5)
313 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
316 ;; Special case: Fill first paragraph when point is at an item or
317 ;; a plain-list or a footnote reference.
320 (org-test-with-temp-text "- A\n B"
321 (let ((fill-column 20))
326 (org-test-with-temp-text "[fn:1] A\nB"
327 (let ((fill-column 20))
330 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
331 (let ((fill-column 20))
333 (should (equal (buffer-string)
334 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
335 ;; Fill contents of `comment-block' elements.
338 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
339 (let ((fill-column 20))
343 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
344 ;; Fill `comment' elements.
347 (org-test-with-temp-text " # A\n # B"
348 (let ((fill-column 20))
351 ;; Do not mix consecutive comments when filling one of them.
353 (equal "# A B\n\n# C"
354 (org-test-with-temp-text "# A\n# B\n\n# C"
355 (let ((fill-column 20))
358 ;; Use commented empty lines as separators when filling comments.
360 (equal "# A B\n#\n# C"
361 (org-test-with-temp-text "# A\n# B\n#\n# C"
362 (let ((fill-column 20))
365 ;; Handle `adaptive-fill-regexp' in comments.
368 (org-test-with-temp-text "# > a\n# > b"
369 (let ((fill-column 20)
370 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
373 ;; Do nothing at affiliated keywords.
374 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
375 (let ((fill-column 20))
377 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
378 ;; Do not move point after table when filling a table.
380 (org-test-with-temp-text "| a | b |\n| c | d |\n"
385 (ert-deftest test-org
/auto-fill-function
()
386 "Test auto-filling features."
387 ;; Auto fill paragraph.
390 (org-test-with-temp-text "12345 7890"
391 (let ((fill-column 5))
393 (org-auto-fill-function)
395 ;; Auto fill first paragraph in an item.
397 (equal "- 12345\n 7890"
398 (org-test-with-temp-text "- 12345 7890"
399 (let ((fill-column 7))
401 (org-auto-fill-function)
403 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
405 (equal "> 12345\n 7890"
406 (org-test-with-temp-text "> 12345 7890"
407 (let ((fill-column 10)
408 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
409 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
411 (org-auto-fill-function)
414 (equal "> 12345\n> 12345\n> 7890"
415 (org-test-with-temp-text "> 12345\n> 12345 7890"
416 (let ((fill-column 10)
417 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
418 (goto-char (point-max))
419 (org-auto-fill-function)
422 (equal " 12345\n *12345\n *12345"
423 (org-test-with-temp-text " 12345\n *12345 12345"
424 (let ((fill-column 10)
425 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
426 (goto-char (point-max))
427 (org-auto-fill-function)
429 ;; Auto fill comments.
431 (equal " # 12345\n # 7890"
432 (org-test-with-temp-text " # 12345 7890"
433 (let ((fill-column 10))
435 (org-auto-fill-function)
437 ;; A hash within a line isn't a comment.
439 (equal "12345 # 7890\n# 1"
440 (org-test-with-temp-text "12345 # 7890 1"
441 (let ((fill-column 12))
443 (org-auto-fill-function)
445 ;; Correctly interpret empty prefix.
447 (equal "# a\n# b\nRegular\n# paragraph"
448 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
449 (let ((fill-column 12))
451 (org-auto-fill-function)
453 ;; Comment block: auto fill contents.
455 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
456 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
457 (let ((fill-column 5))
460 (org-auto-fill-function)
463 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
464 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
465 (let ((fill-column 5))
468 (org-auto-fill-function)
470 ;; Do not fill if a new item could be created.
473 (org-test-with-temp-text "12345 - 90"
474 (let ((fill-column 5))
476 (org-auto-fill-function)
478 ;; Do not fill if a line break could be introduced.
480 (equal "123\\\\\n7890"
481 (org-test-with-temp-text "123\\\\ 7890"
482 (let ((fill-column 6))
484 (org-auto-fill-function)
486 ;; Do not fill affiliated keywords.
488 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
489 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
490 (let ((fill-column 20))
492 (org-auto-fill-function)
499 (ert-deftest test-org
/indent-line
()
500 "Test `org-indent-line' specifications."
501 ;; Do not indent footnote definitions or headlines.
504 (org-test-with-temp-text "* H"
506 (org-get-indentation))))
509 (org-test-with-temp-text "[fn:1] fn"
510 (let ((org-adapt-indentation t
)) (org-indent-line))
511 (org-get-indentation))))
512 ;; Do not indent before first headline.
515 (org-test-with-temp-text ""
517 (org-get-indentation))))
518 ;; Indent according to headline level otherwise, unless
519 ;; `org-adapt-indentation' is nil.
522 (org-test-with-temp-text "* H\nA"
524 (let ((org-adapt-indentation t
)) (org-indent-line))
525 (org-get-indentation))))
528 (org-test-with-temp-text "* H\n\nA"
530 (let ((org-adapt-indentation t
)) (org-indent-line))
531 (org-get-indentation))))
534 (org-test-with-temp-text "* H\nA"
536 (let ((org-adapt-indentation nil
)) (org-indent-line))
537 (org-get-indentation))))
538 ;; Indenting preserves point position.
540 (org-test-with-temp-text "* H\nAB"
543 (let ((org-adapt-indentation t
)) (org-indent-line))
545 ;; Do not change indentation at an item.
548 (org-test-with-temp-text "* H\n - A"
550 (let ((org-adapt-indentation t
)) (org-indent-line))
551 (org-get-indentation))))
552 ;; On blank lines at the end of a list, indent like last element
553 ;; within it if the line is still in the list. Otherwise, indent
554 ;; like the whole list.
557 (org-test-with-temp-text "* H\n- A\n - AA\n"
558 (goto-char (point-max))
559 (let ((org-adapt-indentation t
)) (org-indent-line))
560 (org-get-indentation))))
563 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
564 (goto-char (point-max))
565 (let ((org-adapt-indentation t
)) (org-indent-line))
566 (org-get-indentation))))
567 ;; Likewise, on a blank line at the end of a footnote definition,
568 ;; indent at column 0 if line belongs to the definition. Otherwise,
569 ;; indent like the definition itself.
572 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
573 (goto-char (point-max))
574 (let ((org-adapt-indentation t
)) (org-indent-line))
575 (org-get-indentation))))
578 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
579 (goto-char (point-max))
580 (let ((org-adapt-indentation t
)) (org-indent-line))
581 (org-get-indentation))))
582 ;; After the end of the contents of a greater element, indent like
583 ;; the beginning of the element.
586 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
589 (org-get-indentation))))
590 ;; At the first line of an element, indent like previous element's
591 ;; first line, ignoring footnotes definitions and inline tasks, or
592 ;; according to parent.
595 (org-test-with-temp-text "A\n\n B\n\nC"
596 (goto-char (point-max))
598 (org-get-indentation))))
601 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
602 (goto-char (point-max))
604 (org-get-indentation))))
607 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
610 (org-get-indentation))))
611 ;; Within code part of a source block, use language major mode if
612 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
613 ;; according to line above.
616 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
618 (let ((org-src-tab-acts-natively t
)
619 (org-edit-src-content-indentation 0))
621 (org-get-indentation))))
624 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
626 (let ((org-src-tab-acts-natively nil
)
627 (org-edit-src-content-indentation 0))
629 (org-get-indentation))))
630 ;; Otherwise, indent like the first non-blank line above.
633 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
636 (org-get-indentation))))
637 ;; Align node properties according to `org-property-format'. Handle
638 ;; nicely empty values.
640 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
641 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
642 (let ((org-property-format "%-10s %s")) (org-indent-line))
645 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
646 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
647 (let ((org-property-format "%-10s %s")) (org-indent-line))
650 (ert-deftest test-org
/indent-region
()
651 "Test `org-indent-region' specifications."
655 (org-test-with-temp-text " A\nB\n C"
656 (org-indent-region (point-min) (point-max))
658 ;; Indent greater elements along with their contents.
660 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
661 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
662 (org-indent-region (point-min) (point-max))
664 ;; Ignore contents of verse blocks and example blocks.
666 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
667 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
668 (org-indent-region (point-min) (point-max))
671 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
672 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
673 (org-indent-region (point-min) (point-max))
675 ;; Indent according to mode if `org-src-tab-acts-natively' is
676 ;; non-nil. Otherwise, do not indent code at all.
678 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
679 (org-test-with-temp-text
680 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
681 (let ((org-src-tab-acts-natively t
)
682 (org-edit-src-content-indentation 0))
683 (org-indent-region (point-min) (point-max)))
686 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
687 (org-test-with-temp-text
688 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
689 (let ((org-src-tab-acts-natively nil
)
690 (org-edit-src-content-indentation 0))
691 (org-indent-region (point-min) (point-max)))
693 ;; Align node properties according to `org-property-format'. Handle
694 ;; nicely empty values.
696 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
697 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
698 (let ((org-property-format "%-10s %s")
699 (org-adapt-indentation nil
))
700 (org-indent-region (point) (point-max)))
703 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
704 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
705 (let ((org-property-format "%-10s %s")
706 (org-adapt-indentation nil
))
707 (org-indent-region (point) (point-max)))
709 ;; Indent plain lists.
711 (equal "- A\n B\n - C\n\n D"
712 (org-test-with-temp-text "- A\n B\n - C\n\n D"
713 (org-indent-region (point-min) (point-max))
717 (org-test-with-temp-text " - A\n\n - B"
718 (org-indent-region (point-min) (point-max))
720 ;; Indent footnote definitions.
722 (equal "[fn:1] Definition\n\nDefinition"
723 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
724 (org-indent-region (point-min) (point-max))
726 ;; Special case: Start indenting on a blank line.
729 (org-test-with-temp-text "\n Paragraph"
730 (org-indent-region (point-min) (point-max))
739 (ert-deftest test-org
/meta-return
()
740 "Test M-RET (`org-meta-return')."
741 ;; In a table field insert a row above.
743 (org-test-with-temp-text "| a |"
747 (looking-at "| |$")))
748 ;; In a paragraph change current line into a header.
750 (org-test-with-temp-text "a"
753 (looking-at "\* a$")))
754 ;; In an item insert an item, in this case above.
756 (org-test-with-temp-text "- a"
760 ;; In a drawer and item insert an item, in this case above.
762 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
766 (looking-at "- $"))))
768 (ert-deftest test-org
/insert-heading
()
769 "Test `org-insert-heading' specifications."
770 ;; FIXME: Test coverage is incomplete yet.
772 ;; In an empty buffer, insert a new headline.
775 (org-test-with-temp-text ""
778 ;; At the beginning of a line, turn it into a headline
781 (org-test-with-temp-text "<point>P"
784 ;; In the middle of a line, split the line if allowed, otherwise,
785 ;; insert the headline at its end.
787 (equal "Para\n* graph"
788 (org-test-with-temp-text "Para<point>graph"
789 (let ((org-M-RET-may-split-line '((default . t
))))
790 (org-insert-heading))
793 (equal "Paragraph\n* "
794 (org-test-with-temp-text "Para<point>graph"
795 (let ((org-M-RET-may-split-line '((default . nil
))))
796 (org-insert-heading))
798 ;; Corner case: correctly insert a headline after an empty one.
801 (org-test-with-temp-text "* <point>"
805 (ert-deftest test-org
/insert-todo-heading-respect-content
()
806 "Test `org-insert-todo-heading-respect-content' specifications."
807 ;; Create a TODO heading.
809 (org-test-with-temp-text "* H1\n Body"
810 (org-insert-todo-heading-respect-content)
811 (nth 2 (org-heading-components))))
812 ;; Add headline at the end of the first subtree
814 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
815 (search-forward "H1Body")
816 (org-insert-todo-heading-respect-content)
817 (and (eobp) (org-at-heading-p))))
818 ;; In a list, do not create a new item.
820 (org-test-with-temp-text "* H\n- an item\n- another one"
821 (search-forward "an ")
822 (org-insert-todo-heading-respect-content)
823 (and (eobp) (org-at-heading-p)))))
827 ;;; Fixed-Width Areas
829 (ert-deftest test-org
/toggle-fixed-width
()
830 "Test `org-toggle-fixed-width' specifications."
831 ;; No region: Toggle on fixed-width marker in paragraphs.
834 (org-test-with-temp-text "A"
835 (org-toggle-fixed-width)
837 ;; No region: Toggle off fixed-width markers in fixed-width areas.
840 (org-test-with-temp-text ": A"
841 (org-toggle-fixed-width)
843 ;; No region: Toggle on marker in blank lines after elements or just
847 (org-test-with-temp-text "* H\n"
849 (org-toggle-fixed-width)
852 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
853 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
854 (goto-char (point-max))
855 (org-toggle-fixed-width)
857 ;; No region: Toggle on marker in front of one line elements (e.g.,
858 ;; headlines, clocks)
860 (equal ": * Headline"
861 (org-test-with-temp-text "* Headline"
862 (org-toggle-fixed-width)
865 (equal ": #+KEYWORD: value"
866 (org-test-with-temp-text "#+KEYWORD: value"
867 (org-toggle-fixed-width)
869 ;; No region: error in other situations.
871 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
873 (org-toggle-fixed-width)
875 ;; No region: Indentation is preserved.
878 (org-test-with-temp-text "- A\n B"
880 (org-toggle-fixed-width)
882 ;; Region: If it contains only fixed-width elements and blank lines,
883 ;; toggle off fixed-width markup.
886 (org-test-with-temp-text ": A\n\n: B"
887 (transient-mark-mode 1)
888 (push-mark (point) t t
)
889 (goto-char (point-max))
890 (org-toggle-fixed-width)
892 ;; Region: If it contains anything else, toggle on fixed-width but
893 ;; not on fixed-width areas.
895 (equal ": A\n: \n: B\n: \n: C"
896 (org-test-with-temp-text "A\n\n: B\n\nC"
897 (transient-mark-mode 1)
898 (push-mark (point) t t
)
899 (goto-char (point-max))
900 (org-toggle-fixed-width)
902 ;; Region: Ignore blank lines at its end, unless it contains only
906 (org-test-with-temp-text "A\n\n"
907 (transient-mark-mode 1)
908 (push-mark (point) t t
)
909 (goto-char (point-max))
910 (org-toggle-fixed-width)
914 (org-test-with-temp-text "\n\n"
915 (transient-mark-mode 1)
916 (push-mark (point) t t
)
917 (goto-char (point-max))
918 (org-toggle-fixed-width)
925 (ert-deftest test-org
/in-commented-heading-p
()
926 "Test `org-in-commented-heading-p' specifications."
927 ;; Commented headline.
929 (org-test-with-temp-text "* COMMENT Headline\nBody"
930 (goto-char (point-max))
931 (org-in-commented-heading-p)))
932 ;; Commented ancestor.
934 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
935 (goto-char (point-max))
936 (org-in-commented-heading-p)))
937 ;; Comment keyword is case-sensitive.
939 (org-test-with-temp-text "* Comment Headline\nBody"
940 (goto-char (point-max))
941 (org-in-commented-heading-p)))
942 ;; Keyword is standalone.
944 (org-test-with-temp-text "* COMMENTHeadline\nBody"
945 (goto-char (point-max))
946 (org-in-commented-heading-p)))
947 ;; Optional argument.
949 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
950 (goto-char (point-max))
951 (org-in-commented-heading-p t
))))
957 (ert-deftest test-org
/set-regexps-and-options
()
958 "Test `org-set-regexps-and-options' specifications."
961 (equal '(("A" . ?a
) ("B") ("C"))
962 (org-test-with-temp-text "#+TAGS: A(a) B C"
966 (equal '(("A") (:newline
) ("B"))
967 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
971 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
972 (org-test-with-temp-text "#+TAGS: { A B } C"
976 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
977 (org-test-with-temp-text "#+TAGS: { A : B C }"
981 (equal '(("A" "B" "C"))
982 (org-test-with-temp-text "#+TAGS: { A : B C }"
984 org-tag-groups-alist
)))
987 (equal '("A" "B" "C")
988 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
991 ;; PROPERTY keyword. Property names are case-insensitive.
994 (org-test-with-temp-text "#+PROPERTY: var foo=1"
996 (cdr (assoc "var" org-file-properties
)))))
1000 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1002 (cdr (assoc "var" org-file-properties
)))))
1006 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1008 (cdr (assoc "var" org-file-properties
)))))
1012 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1014 org-archive-location
)))
1015 ;; CATEGORY keyword.
1018 (org-test-with-temp-text "#+CATEGORY: test"
1023 (org-test-with-temp-text "#+CATEGORY: test"
1025 (cdr (assoc "CATEGORY" org-file-properties
)))))
1028 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1029 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1031 org-columns-default-format
)))
1032 ;; CONSTANTS keyword. Constants names are case sensitive.
1034 (equal '("299792458." "3.14")
1035 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1038 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1042 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1044 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1047 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1049 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1054 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1056 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1058 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1062 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1064 (list org-highest-priority org-lowest-priority org-default-priority
))))
1068 (org-test-with-temp-text "#+PRIORITIES: X Z"
1070 (list org-highest-priority org-lowest-priority org-default-priority
))))
1074 (org-test-with-temp-text "#+STARTUP: fold odd"
1076 (list org-startup-folded org-odd-levels-only
))))
1079 (equal '(("A" "B") ("C"))
1080 (org-test-with-temp-text "#+TODO: A B | C"
1082 (list org-not-done-keywords org-done-keywords
))))
1084 (equal '(("A" "C") ("B" "D"))
1085 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1087 (list org-not-done-keywords org-done-keywords
))))
1089 (equal '(("A" "B") ("C"))
1090 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1092 (list org-not-done-keywords org-done-keywords
))))
1094 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
1095 (org-test-with-temp-text "#+TODO: A(a)"
1097 org-todo-key-alist
)))
1099 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
1100 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1102 org-todo-log-states
)))
1103 ;; Enter SETUPFILE keyword.
1106 (org-test-with-temp-text
1107 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
1109 (cdr (assoc "a" org-file-properties
))))))
1117 (ert-deftest test-org
/coderef
()
1118 "Test coderef links specifications."
1120 (org-test-with-temp-text "
1121 #+BEGIN_SRC emacs-lisp
1125 (goto-char (point-max))
1127 (looking-at "(ref:sc)"))))
1131 (ert-deftest test-org
/custom-id
()
1132 "Test custom ID links specifications."
1134 (org-test-with-temp-text
1135 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1136 (goto-char (point-max))
1138 (org-looking-at-p "\\* H1"))))
1142 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1143 ;; a named element (#+name: text) and to headlines (* Text).
1145 (ert-deftest test-org
/fuzzy-links
()
1146 "Test fuzzy links specifications."
1147 ;; Fuzzy link goes in priority to a matching target.
1149 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1152 (looking-at "<<Test>>")))
1153 ;; Then fuzzy link points to an element with a given name.
1155 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1158 (looking-at "#\\+NAME: Test")))
1159 ;; A target still lead to a matching headline otherwise.
1161 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1164 (looking-at "\\* Head2")))
1165 ;; With a leading star in link, enforce heading match.
1167 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1170 (looking-at "\\* Test")))
1171 ;; Correctly un-hexify fuzzy links.
1173 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1174 (goto-char (point-max))
1180 (ert-deftest test-org
/org-link-escape-ascii-character
()
1181 "Escape an ascii character."
1185 (org-link-escape "["))))
1187 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
1188 "Escape an ascii control character."
1192 (org-link-escape "\t"))))
1194 (ert-deftest test-org
/org-link-escape-multibyte-character
()
1195 "Escape an unicode multibyte character."
1199 (org-link-escape "€"))))
1201 (ert-deftest test-org
/org-link-escape-custom-table
()
1202 "Escape string with custom character table."
1206 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
1208 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
1209 "Escape string with custom table merged with default table."
1212 "%5BF%6F%6F%3A%42ar%0A%5D"
1213 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
1215 (ert-deftest test-org
/org-link-unescape-ascii-character
()
1216 "Unescape an ascii character."
1220 (org-link-unescape "%5B"))))
1222 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
1223 "Unescpae an ascii control character."
1227 (org-link-unescape "%0A"))))
1229 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
1230 "Unescape unicode multibyte character."
1234 (org-link-unescape "%E2%82%AC"))))
1236 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
1237 "Unescape old style percent escaped character."
1240 "à âçèéêîôùû"
1241 (decode-coding-string
1242 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
1244 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
1245 "Escape and unescape a URL that includes an escaped char.
1246 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1249 "http://some.host.com/form?&id=blah%2Bblah25"
1251 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1253 (ert-deftest test-org
/org-link-escape-chars-browser
()
1254 "Test of the constant `org-link-escape-chars-browser'.
1255 See there why this test is a candidate to be removed once Org
1256 drops support for Emacs 24.1 and 24.2."
1259 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1260 "%22Release%208.2%22&idxname=emacs-orgmode")
1261 (org-link-escape-browser ; Do not replace with `url-encode-url',
1262 ; see docstring above.
1263 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1264 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1268 (ert-deftest test-org
/open-at-point-in-property
()
1269 "Does `org-open-at-point' open link in property drawer?"
1271 (org-test-with-temp-text
1274 :URL: <point>[[info:emacs#Top]]
1276 (org-open-at-point) t
)))
1278 (ert-deftest test-org
/open-at-point-in-comment
()
1279 "Does `org-open-at-point' open link in a commented line?"
1281 (org-test-with-temp-text
1282 "# <point>[[info:emacs#Top]]"
1283 (org-open-at-point) t
)))
1285 (ert-deftest test-org
/open-at-point
/info
()
1286 "Test `org-open-at-point' on info links."
1288 (org-test-with-temp-text
1289 "<point>[[info:emacs#Top]]"
1291 (and (switch-to-buffer "*info*")
1293 (looking-at "\nThe Emacs Editor")
1299 (ert-deftest test-org
/accumulated-properties-in-drawers
()
1300 "Ensure properties accumulate in subtree drawers."
1301 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1302 (org-babel-next-src-block)
1303 (should (equal '(2 1) (org-babel-execute-src-block)))))
1309 (ert-deftest test-org
/mark-subtree
()
1310 "Test `org-mark-subtree' specifications."
1311 ;; Error when point is before first headline.
1313 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1314 (progn (transient-mark-mode 1)
1315 (org-mark-subtree))))
1316 ;; Without argument, mark current subtree.
1320 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1321 (progn (transient-mark-mode 1)
1324 (list (region-beginning) (region-end))))))
1325 ;; With an argument, move ARG up.
1329 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1330 (progn (transient-mark-mode 1)
1332 (org-mark-subtree 1)
1333 (list (region-beginning) (region-end))))))
1334 ;; Do not get fooled by inlinetasks.
1335 (when (featurep 'org-inlinetask
)
1338 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1339 (progn (transient-mark-mode 1)
1341 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1342 (region-beginning)))))))
1348 (ert-deftest test-org
/beginning-of-line
()
1349 "Test `org-beginning-of-line' specifications."
1352 (org-test-with-temp-text "Some text\nSome other text"
1353 (progn (org-beginning-of-line) (bolp))))
1354 ;; Standard test with `visual-line-mode'.
1356 (org-test-with-temp-text "A long line of text\nSome other text"
1357 (progn (visual-line-mode)
1359 (dotimes (i 1000) (insert "very "))
1360 (org-beginning-of-line)
1362 ;; At an headline with special movement.
1364 (org-test-with-temp-text "* TODO Headline"
1365 (let ((org-special-ctrl-a/e t
))
1367 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1368 (progn (org-beginning-of-line) (bolp))
1369 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1371 (ert-deftest test-org
/end-of-line
()
1372 "Test `org-end-of-line' specifications."
1375 (org-test-with-temp-text "Some text\nSome other text"
1376 (progn (org-end-of-line) (eolp))))
1377 ;; Standard test with `visual-line-mode'.
1379 (org-test-with-temp-text "A long line of text\nSome other text"
1380 (progn (visual-line-mode)
1382 (dotimes (i 1000) (insert "very "))
1383 (goto-char (point-min))
1386 ;; At an headline with special movement.
1388 (org-test-with-temp-text "* Headline1 :tag:\n"
1389 (let ((org-special-ctrl-a/e t
))
1390 (and (progn (org-end-of-line) (looking-at " :tag:"))
1391 (progn (org-end-of-line) (eolp))
1392 (progn (org-end-of-line) (looking-at " :tag:"))))))
1393 ;; At an headline without special movement.
1395 (org-test-with-temp-text "* Headline2 :tag:\n"
1396 (let ((org-special-ctrl-a/e nil
))
1397 (and (progn (org-end-of-line) (eolp))
1398 (progn (org-end-of-line) (eolp))))))
1399 ;; At an headline, with reversed movement.
1401 (org-test-with-temp-text "* Headline3 :tag:\n"
1402 (let ((org-special-ctrl-a/e
'reversed
)
1403 (this-command last-command
))
1404 (and (progn (org-end-of-line) (eolp))
1405 (progn (org-end-of-line) (looking-at " :tag:"))))))
1406 ;; At a block without hidden contents.
1408 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1409 (progn (org-end-of-line) (eolp))))
1410 ;; At a block with hidden contents.
1412 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1413 (let ((org-special-ctrl-a/e t
))
1414 (org-hide-block-toggle)
1418 (ert-deftest test-org
/forward-paragraph
()
1419 "Test `org-forward-paragraph' specifications."
1420 ;; At end of buffer, return an error.
1422 (org-test-with-temp-text "Paragraph"
1423 (goto-char (point-max))
1424 (org-forward-paragraph)))
1427 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1428 (org-forward-paragraph)
1432 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1433 (org-forward-paragraph)
1435 ;; Do not enter elements with invisible contents.
1437 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1438 (org-hide-block-toggle)
1439 (org-forward-paragraph)
1441 ;; On an affiliated keyword, jump to the beginning of the element.
1443 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1444 (org-forward-paragraph)
1445 (looking-at "Para")))
1446 ;; On an item or a footnote definition, move to the second element
1449 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1450 (org-forward-paragraph)
1451 (looking-at " Paragraph")))
1453 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1454 (org-forward-paragraph)
1455 (looking-at "Paragraph")))
1456 ;; On an item, or a footnote definition, when the first line is
1457 ;; empty, move to the first item.
1459 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1460 (org-forward-paragraph)
1461 (looking-at " Paragraph")))
1463 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1464 (org-forward-paragraph)
1465 (looking-at "Paragraph")))
1466 ;; On a table (resp. a property drawer) do not move through table
1467 ;; rows (resp. node properties).
1469 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1470 (org-forward-paragraph)
1471 (looking-at "Paragraph")))
1473 (org-test-with-temp-text
1474 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1475 (org-forward-paragraph)
1476 (looking-at "Paragraph")))
1477 ;; On a verse or source block, stop after blank lines.
1479 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1480 (org-forward-paragraph)
1483 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1484 (org-forward-paragraph)
1485 (looking-at "L2"))))
1487 (ert-deftest test-org
/backward-paragraph
()
1488 "Test `org-backward-paragraph' specifications."
1489 ;; Error at beginning of buffer.
1491 (org-test-with-temp-text "Paragraph"
1492 (org-backward-paragraph)))
1495 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1496 (goto-char (point-max))
1497 (org-backward-paragraph)
1500 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1501 (goto-char (point-max))
1503 (org-backward-paragraph)
1507 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1508 (goto-char (point-max))
1510 (org-backward-paragraph)
1512 ;; Ignore invisible elements.
1514 (org-test-with-temp-text "* H1\n P1\n* H2"
1516 (goto-char (point-max))
1518 (org-backward-paragraph)
1520 ;; On an affiliated keyword, jump to the first one.
1522 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1523 (search-forward "c2")
1524 (org-backward-paragraph)
1525 (looking-at "#\\+name")))
1526 ;; On the second element in an item or a footnote definition, jump
1527 ;; to item or the definition.
1529 (org-test-with-temp-text "- line1\n\n line2"
1530 (goto-char (point-max))
1532 (org-backward-paragraph)
1533 (looking-at "- line1")))
1535 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1536 (goto-char (point-max))
1538 (org-backward-paragraph)
1539 (looking-at "\\[fn:1\\] line1")))
1540 ;; On a table (resp. a property drawer), ignore table rows
1541 ;; (resp. node properties).
1543 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1544 (goto-char (point-max))
1546 (org-backward-paragraph)
1549 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1550 (org-backward-paragraph)
1551 (looking-at ":PROPERTIES:")))
1552 ;; On a source or verse block, stop before blank lines.
1554 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1555 (search-forward "L3")
1557 (org-backward-paragraph)
1560 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1561 (search-forward "L3")
1563 (org-backward-paragraph)
1564 (looking-at "L2"))))
1566 (ert-deftest test-org
/forward-element
()
1567 "Test `org-forward-element' specifications."
1568 ;; 1. At EOB: should error.
1569 (org-test-with-temp-text "Some text\n"
1570 (goto-char (point-max))
1571 (should-error (org-forward-element)))
1572 ;; 2. Standard move: expected to ignore blank lines.
1573 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1574 (org-forward-element)
1575 (should (looking-at (regexp-quote "Second paragraph."))))
1576 ;; 3. Headline tests.
1577 (org-test-with-temp-text "
1582 ;; 3.1. At an headline beginning: move to next headline at the
1585 (org-forward-element)
1586 (should (looking-at (regexp-quote "** Head 1.2")))
1587 ;; 3.2. At an headline beginning: move to parent headline if no
1588 ;; headline at the same level.
1590 (org-forward-element)
1591 (should (looking-at (regexp-quote "** Head 1.2"))))
1592 ;; 4. Greater element tests.
1593 (org-test-with-temp-text
1594 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1595 ;; 4.1. At a greater element: expected to skip contents.
1596 (org-forward-element)
1597 (should (looking-at (regexp-quote "Outside.")))
1598 ;; 4.2. At the end of greater element contents: expected to skip
1599 ;; to the end of the greater element.
1601 (org-forward-element)
1602 (should (looking-at (regexp-quote "Outside."))))
1604 (org-test-with-temp-text "
1618 ;; 5.1. At list top point: expected to move to the element after
1621 (org-forward-element)
1622 (should (looking-at (regexp-quote "Outside.")))
1623 ;; 5.2. Special case: at the first line of a sub-list, but not at
1624 ;; beginning of line, move to next item.
1627 (org-forward-element)
1628 (should (looking-at "- item2"))
1631 (org-forward-element)
1632 (should (looking-at " - sub2"))
1633 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1635 (org-forward-element)
1636 (should (looking-at (regexp-quote " Inner paragraph.")))
1637 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1639 (org-forward-element)
1640 (should (looking-at (regexp-quote " Inner paragraph.")))
1641 ;; 5.5. At an item: expected to move to next item, if any.
1643 (org-forward-element)
1644 (should (looking-at " - sub3"))))
1646 (ert-deftest test-org
/backward-element
()
1647 "Test `org-backward-element' specifications."
1648 ;; 1. Should error at BOB.
1649 (org-test-with-temp-text " \nParagraph."
1650 (should-error (org-backward-element)))
1651 ;; 2. Should move at BOB when called on the first element in buffer.
1653 (org-test-with-temp-text "\n#+TITLE: test"
1654 (progn (forward-line)
1655 (org-backward-element)
1657 ;; 3. Not at the beginning of an element: move at its beginning.
1658 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1661 (org-backward-element)
1662 (should (looking-at (regexp-quote "Paragraph2."))))
1663 ;; 4. Headline tests.
1664 (org-test-with-temp-text "
1669 ;; 4.1. At an headline beginning: move to previous headline at the
1672 (org-backward-element)
1673 (should (looking-at (regexp-quote "** Head 1.1")))
1674 ;; 4.2. At an headline beginning: move to parent headline if no
1675 ;; headline at the same level.
1677 (org-backward-element)
1678 (should (looking-at (regexp-quote "* Head 1")))
1679 ;; 4.3. At the first top-level headline: should error.
1681 (should-error (org-backward-element)))
1682 ;; 5. At beginning of first element inside a greater element:
1683 ;; expected to move to greater element's beginning.
1684 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1686 (org-backward-element)
1687 (should (looking-at "#\\+BEGIN_CENTER")))
1688 ;; 6. At the beginning of the first element in a section: should
1689 ;; move back to headline, if any.
1691 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1692 (progn (goto-char (point-max))
1694 (org-backward-element)
1695 (org-at-heading-p))))
1697 (org-test-with-temp-text "
1712 ;; 7.1. At beginning of sub-list: expected to move to the
1713 ;; paragraph before it.
1715 (org-backward-element)
1716 (should (looking-at "item1"))
1717 ;; 7.2. At an item in a list: expected to move at previous item.
1719 (org-backward-element)
1720 (should (looking-at " - sub2"))
1722 (org-backward-element)
1723 (should (looking-at "- item1"))
1724 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1727 (org-backward-element)
1728 (should (looking-at " - sub1"))
1730 (org-backward-element)
1731 (should (looking-at "- item1"))
1732 ;; 7.4. At blank-lines before list end: expected to move to top
1735 (org-backward-element)
1736 (should (looking-at "- item1"))))
1738 (ert-deftest test-org
/up-element
()
1739 "Test `org-up-element' specifications."
1740 ;; 1. At BOB or with no surrounding element: should error.
1741 (org-test-with-temp-text "Paragraph."
1742 (should-error (org-up-element)))
1743 (org-test-with-temp-text "* Head1\n* Head2"
1745 (should-error (org-up-element)))
1746 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1748 (should-error (org-up-element)))
1749 ;; 2. At an headline: move to parent headline.
1750 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1753 (should (looking-at "\\* Head1")))
1754 ;; 3. Inside a greater element: move to greater element beginning.
1755 (org-test-with-temp-text
1756 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1759 (should (looking-at "#\\+BEGIN_CENTER")))
1761 (org-test-with-temp-text "* Top
1768 Paragraph within sub2.
1771 ;; 4.1. Within an item: move to the item beginning.
1774 (should (looking-at " - sub2"))
1775 ;; 4.2. At an item in a sub-list: move to parent item.
1778 (should (looking-at "- item1"))
1779 ;; 4.3. At an item in top list: move to beginning of whole list.
1782 (should (looking-at "- item1"))
1783 ;; 4.4. Special case. At very top point: should move to parent of
1787 (should (looking-at "\\* Top"))))
1789 (ert-deftest test-org
/down-element
()
1790 "Test `org-down-element' specifications."
1791 ;; Error when the element hasn't got a recursive type.
1792 (org-test-with-temp-text "Paragraph."
1793 (should-error (org-down-element)))
1794 ;; Error when the element has no contents
1795 (org-test-with-temp-text "* Headline"
1796 (should-error (org-down-element)))
1797 ;; When at a plain-list, move to first item.
1798 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1801 (should (looking-at " - Item 1.1")))
1802 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1804 (should (looking-at " Item 1")))
1805 ;; When at a table, move to first row
1806 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1808 (should (looking-at " a | b |")))
1809 ;; Otherwise, move inside the greater element.
1810 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1812 (should (looking-at "Paragraph"))))
1814 (ert-deftest test-org
/drag-element-backward
()
1815 "Test `org-drag-element-backward' specifications."
1819 "#+key2: val2\n#+key1: val1\n#+key3: val3"
1820 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
1821 (org-drag-element-backward)
1825 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
1826 (org-test-with-temp-text
1827 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
1828 (org-drag-element-backward)
1830 ;; Preserve blank lines.
1832 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
1833 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
1834 (org-drag-element-backward)
1838 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
1839 (org-drag-element-backward)
1840 (org-looking-at-p "2")))
1841 ;; Error when trying to move first element of buffer.
1843 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1844 (org-drag-element-backward)))
1845 ;; Error when trying to swap nested elements.
1847 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1849 (org-drag-element-backward)))
1850 ;; Error when trying to swap an headline element and a non-headline
1853 (org-test-with-temp-text "Test.\n* Head 1"
1855 (org-drag-element-backward)))
1856 ;; Preserve visibility of elements and their contents.
1858 (equal '((63 .
82) (26 .
48))
1859 (org-test-with-temp-text "
1867 (while (search-forward "BEGIN_" nil t
) (org-cycle))
1868 (search-backward "- item 1")
1869 (org-drag-element-backward)
1870 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
1871 (overlays-in (point-min) (point-max)))))))
1873 (ert-deftest test-org
/drag-element-forward
()
1874 "Test `org-drag-element-forward' specifications."
1875 ;; 1. Error when trying to move first element of buffer.
1876 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1878 (should-error (org-drag-element-forward)))
1879 ;; 2. Error when trying to swap nested elements.
1880 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1882 (should-error (org-drag-element-forward)))
1883 ;; 3. Error when trying to swap a non-headline element and an
1885 (org-test-with-temp-text "Test.\n* Head 1"
1886 (should-error (org-drag-element-forward)))
1887 ;; 4. Otherwise, swap elements, preserving column and blank lines
1888 ;; between elements.
1889 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
1890 (search-forward "graph")
1891 (org-drag-element-forward)
1892 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
1893 (should (looking-at " 1")))
1894 ;; 5. Preserve visibility of elements and their contents.
1895 (org-test-with-temp-text "
1903 (while (search-forward "BEGIN_" nil t
) (org-cycle))
1904 (search-backward "#+BEGIN_CENTER")
1905 (org-drag-element-forward)
1908 '((63 .
82) (26 .
48))
1909 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
1910 (overlays-in (point-min) (point-max)))))))
1916 (ert-deftest test-org
/timestamp-has-time-p
()
1917 "Test `org-timestamp-has-time-p' specifications."
1920 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1921 (org-timestamp-has-time-p (org-element-context))))
1924 (org-test-with-temp-text "<2012-03-29 Thu>"
1925 (org-timestamp-has-time-p (org-element-context)))))
1927 (ert-deftest test-org
/timestamp-format
()
1928 "Test `org-timestamp-format' specifications."
1933 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1934 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
1939 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1940 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
1942 (ert-deftest test-org
/timestamp-split-range
()
1943 "Test `org-timestamp-split-range' specifications."
1944 ;; Extract range start (active).
1947 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1948 (let ((ts (org-timestamp-split-range (org-element-context))))
1949 (mapcar (lambda (p) (org-element-property p ts
))
1950 '(:year-end
:month-end
:day-end
))))))
1951 ;; Extract range start (inactive)
1954 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1955 (let ((ts (org-timestamp-split-range (org-element-context))))
1956 (mapcar (lambda (p) (org-element-property p ts
))
1957 '(:year-end
:month-end
:day-end
))))))
1958 ;; Extract range end (active).
1961 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1962 (let ((ts (org-timestamp-split-range
1963 (org-element-context) t
)))
1964 (mapcar (lambda (p) (org-element-property p ts
))
1965 '(:year-end
:month-end
:day-end
))))))
1966 ;; Extract range end (inactive)
1969 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1970 (let ((ts (org-timestamp-split-range
1971 (org-element-context) t
)))
1972 (mapcar (lambda (p) (org-element-property p ts
))
1973 '(:year-end
:month-end
:day-end
))))))
1974 ;; Return the timestamp if not a range.
1976 (org-test-with-temp-text "[2012-03-29 Thu]"
1977 (let* ((ts-orig (org-element-context))
1978 (ts-copy (org-timestamp-split-range ts-orig
)))
1979 (eq ts-orig ts-copy
))))
1981 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1982 (let* ((ts-orig (org-element-context))
1983 (ts-copy (org-timestamp-split-range ts-orig
)))
1984 (eq ts-orig ts-copy
))))
1985 ;; Check that parent is the same when a range was split.
1987 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1988 (let* ((ts-orig (org-element-context))
1989 (ts-copy (org-timestamp-split-range ts-orig
)))
1990 (eq (org-element-property :parent ts-orig
)
1991 (org-element-property :parent ts-copy
))))))
1993 (ert-deftest test-org
/timestamp-translate
()
1994 "Test `org-timestamp-translate' specifications."
1995 ;; Translate whole date range.
1998 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1999 (let ((org-display-custom-times t
)
2000 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2001 (org-timestamp-translate (org-element-context))))))
2002 ;; Translate date range start.
2005 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2006 (let ((org-display-custom-times t
)
2007 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2008 (org-timestamp-translate (org-element-context) 'start
)))))
2009 ;; Translate date range end.
2012 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2013 (let ((org-display-custom-times t
)
2014 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2015 (org-timestamp-translate (org-element-context) 'end
)))))
2016 ;; Translate time range.
2019 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
2020 (let ((org-display-custom-times t
)
2021 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
2022 (org-timestamp-translate (org-element-context))))))
2023 ;; Translate non-range timestamp.
2026 (org-test-with-temp-text "<2012-03-29 Thu>"
2027 (let ((org-display-custom-times t
)
2028 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2029 (org-timestamp-translate (org-element-context))))))
2030 ;; Do not change `diary' timestamps.
2032 (equal "<%%(org-float t 4 2)>"
2033 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2034 (let ((org-display-custom-times t
)
2035 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2036 (org-timestamp-translate (org-element-context)))))))
2042 (ert-deftest test-org
/buffer-property-keys
()
2043 "Test `org-buffer-property-keys' specifications."
2044 ;; Retrieve properties accross siblings.
2047 (org-test-with-temp-text "
2056 (org-buffer-property-keys))))
2057 ;; Retrieve properties accross children.
2060 (org-test-with-temp-text "
2069 (org-buffer-property-keys))))
2070 ;; Retrieve muliple properties in the same drawer.
2073 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2074 (org-buffer-property-keys))))
2075 ;; Ignore extension symbol in property name.
2078 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2079 (org-buffer-property-keys))))
2080 ;; With non-nil COLUMNS, extract property names from columns.
2083 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2084 (org-buffer-property-keys nil nil t
))))
2086 (equal '("A" "B" "COLUMNS")
2087 (org-test-with-temp-text
2088 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2089 (org-buffer-property-keys nil nil t
)))))
2091 (ert-deftest test-org
/property-values
()
2092 "Test `org-property-values' specifications."
2096 (org-test-with-temp-text
2097 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2098 (org-property-values "A"))))
2099 ;; Ignore empty values.
2101 (org-test-with-temp-text
2102 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2103 (org-property-values "A")))
2104 ;; Take into consideration extended values.
2107 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2108 (org-property-values "A")))))
2110 (ert-deftest test-org
/entry-delete
()
2111 "Test `org-entry-delete' specifications."
2115 " *:PROPERTIES:\n *:B: +2\n *:END:"
2116 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2117 (org-entry-delete (point) "A")
2119 ;; When last property is removed, remove the property drawer.
2123 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2124 (org-entry-delete (point) "A")
2127 (ert-deftest test-org
/entry-get
()
2128 "Test `org-entry-get' specifications."
2132 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2133 (org-entry-get (point) "A"))))
2137 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2138 (org-entry-get (point) "a"))))
2139 ;; Handle extended values, both before and after base value.
2142 (org-test-with-temp-text
2143 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2144 (org-entry-get (point) "A"))))
2145 ;; Empty values are returned as the empty string.
2148 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2149 (org-entry-get (point) "A"))))
2150 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2151 ;; otherwise, return nil.
2153 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2154 (org-entry-get (point) "A")))
2157 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2158 (org-entry-get (point) "A" nil t
))))
2159 ;; Return nil when no property is found, independently on the
2160 ;; LITERAL-NIL argument.
2162 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2163 (org-entry-get (point) "B")))
2165 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2166 (org-entry-get (point) "B" nil t
)))
2167 ;; Handle inheritance, when allowed.
2171 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2172 (org-entry-get (point) "A" t
))))
2176 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2177 (let ((org-use-property-inheritance t
))
2178 (org-entry-get (point) "A" 'selective
)))))
2180 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2181 (let ((org-use-property-inheritance nil
))
2182 (org-entry-get (point) "A" 'selective
)))))
2184 (ert-deftest test-org
/entry-properties
()
2185 "Test `org-entry-properties' specifications."
2186 ;; Get "TODO" property.
2189 (org-test-with-temp-text "* TODO H"
2190 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
2192 (org-test-with-temp-text "* H"
2193 (assoc "TODO" (org-entry-properties nil
"TODO"))))
2194 ;; Get "PRIORITY" property.
2197 (org-test-with-temp-text "* [#A] H"
2198 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
2200 (org-test-with-temp-text "* H"
2201 (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))
2202 ;; Get "FILE" property.
2204 (org-test-with-temp-text-in-file "* H\nParagraph"
2205 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
2206 (buffer-file-name))))
2208 (org-test-with-temp-text "* H\nParagraph"
2209 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
2210 ;; Get "TAGS" property.
2212 (equal ":tag1:tag2:"
2213 (org-test-with-temp-text "* H :tag1:tag2:"
2214 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
2216 (org-test-with-temp-text "* H"
2217 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
2218 ;; Get "ALLTAGS" property.
2220 (equal ":tag1:tag2:"
2221 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2222 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
2224 (org-test-with-temp-text "* H"
2225 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
2226 ;; Get "BLOCKED" property.
2229 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2230 (let ((org-enforce-todo-dependencies t
)
2232 '(org-block-todo-from-children-or-siblings-or-parent)))
2233 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2236 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2237 (let ((org-enforce-todo-dependencies t
))
2238 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
2239 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2243 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2244 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
2246 (org-test-with-temp-text "* H"
2247 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
2251 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2252 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
2254 (org-test-with-temp-text "* H"
2255 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
2259 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2260 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
2262 (org-test-with-temp-text "* H"
2263 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
2267 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2268 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2271 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2272 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
2273 ;; Get standard properties.
2276 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2277 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2278 ;; Handle extended properties.
2281 (org-test-with-temp-text
2282 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2283 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2286 (org-test-with-temp-text
2287 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2288 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
2289 ;; Ignore forbidden (special) properties.
2291 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2292 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
2294 (ert-deftest test-org
/entry-put
()
2295 "Test `org-entry-put' specifications."
2296 ;; Error when not a string or nil.
2298 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2299 (org-entry-put 1 "test" 2)))
2300 ;; Set "TODO" property.
2302 (string-match (regexp-quote " TODO H")
2303 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2304 (org-entry-put (point) "TODO" "TODO")
2307 (string-match (regexp-quote "* H")
2308 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2309 (org-entry-put (point) "TODO" nil
)
2311 ;; Set "PRIORITY" property.
2314 (org-test-with-temp-text "* [#B] H"
2315 (org-entry-put (point) "PRIORITY" "A")
2319 (org-test-with-temp-text "* [#B] H"
2320 (org-entry-put (point) "PRIORITY" nil
)
2322 ;; Set "SCHEDULED" property.
2324 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2325 (org-test-with-temp-text "* H"
2326 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2330 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2331 (org-entry-put (point) "SCHEDULED" nil
)
2334 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
2335 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2336 (org-entry-put (point) "SCHEDULED" "earlier")
2339 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
2340 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2341 (org-entry-put (point) "SCHEDULED" "later")
2343 ;; Set "DEADLINE" property.
2345 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
2346 (org-test-with-temp-text "* H"
2347 (org-entry-put (point) "DEADLINE" "2014-03-04")
2351 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2352 (org-entry-put (point) "DEADLINE" nil
)
2355 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
2356 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2357 (org-entry-put (point) "DEADLINE" "earlier")
2360 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
2361 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2362 (org-entry-put (point) "DEADLINE" "later")
2364 ;; Regular properties, with or without pre-existing drawer.
2366 (string-match "^ *:A: +2$"
2367 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2368 (org-entry-put (point) "A" "2")
2371 (string-match "^ *:A: +1$"
2372 (org-test-with-temp-text "* H"
2373 (org-entry-put (point) "A" "1")
2375 ;; Special case: two consecutive headlines.
2377 (string-match "\\* A\n *:PROPERTIES:"
2378 (org-test-with-temp-text "* A\n** B"
2379 (org-entry-put (point) "A" "1")
2385 (ert-deftest test-org
/update-radio-target-regexp
()
2386 "Test `org-update-radio-target-regexp' specifications."
2387 ;; Properly update cache with no previous radio target regexp.
2390 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2391 (save-excursion (goto-char (point-max)) (org-element-context))
2393 (search-forward "o")
2395 (org-update-radio-target-regexp)
2396 (goto-char (point-max))
2397 (org-element-type (org-element-context)))))
2398 ;; Properly update cache with previous radio target regexp.
2401 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2402 (save-excursion (goto-char (point-max)) (org-element-context))
2404 (search-forward "o")
2406 (org-update-radio-target-regexp)
2407 (search-backward "r")
2410 (org-update-radio-target-regexp)
2411 (goto-char (point-max))
2412 (delete-region (line-beginning-position) (point))
2414 (org-element-type (org-element-context))))))
2420 (ert-deftest test-org
/flag-drawer
()
2421 "Test `org-flag-drawer' specifications."
2424 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2426 (get-char-property (line-end-position) 'invisible
)))
2429 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2431 (org-flag-drawer nil
)
2432 (get-char-property (line-end-position) 'invisible
)))
2433 ;; Test optional argument.
2435 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2436 (let ((drawer (save-excursion (search-forward ":D2")
2437 (org-element-at-point))))
2438 (org-flag-drawer t drawer
)
2439 (get-char-property (progn (search-forward ":D2") (line-end-position))
2442 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2443 (let ((drawer (save-excursion (search-forward ":D2")
2444 (org-element-at-point))))
2445 (org-flag-drawer t drawer
)
2446 (get-char-property (line-end-position) 'invisible
))))
2447 ;; Do not hide fake drawers.
2449 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
2452 (get-char-property (line-end-position) 'invisible
)))
2453 ;; Do not hide incomplete drawers.
2455 (org-test-with-temp-text ":D:\nparagraph"
2458 (get-char-property (line-end-position) 'invisible
)))
2459 ;; Do not hide drawers when called from final blank lines.
2461 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
2462 (goto-char (point-max))
2464 (goto-char (point-min))
2465 (get-char-property (line-end-position) 'invisible
)))
2466 ;; Don't leave point in an invisible part of the buffer when hiding
2469 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2470 (goto-char (point-max))
2472 (get-char-property (point) 'invisible
))))
2474 (ert-deftest test-org
/hide-block-toggle
()
2475 "Test `org-hide-block-toggle' specifications."
2476 ;; Error when not at a block.
2478 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
2479 (org-hide-block-toggle 'off
)
2480 (get-char-property (line-end-position) 'invisible
)))
2483 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2484 (org-hide-block-toggle)
2485 (get-char-property (line-end-position) 'invisible
)))
2487 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
2488 (org-hide-block-toggle)
2489 (get-char-property (line-end-position) 'invisible
)))
2490 ;; Show block unconditionally when optional argument is `off'.
2492 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2493 (org-hide-block-toggle)
2494 (org-hide-block-toggle 'off
)
2495 (get-char-property (line-end-position) 'invisible
)))
2497 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2498 (org-hide-block-toggle 'off
)
2499 (get-char-property (line-end-position) 'invisible
)))
2500 ;; Hide block unconditionally when optional argument is non-nil.
2502 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2503 (org-hide-block-toggle t
)
2504 (get-char-property (line-end-position) 'invisible
)))
2506 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2507 (org-hide-block-toggle)
2508 (org-hide-block-toggle t
)
2509 (get-char-property (line-end-position) 'invisible
)))
2510 ;; Do not hide block when called from final blank lines.
2512 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
2513 (org-hide-block-toggle)
2514 (goto-char (point-min))
2515 (get-char-property (line-end-position) 'invisible
)))
2516 ;; Don't leave point in an invisible part of the buffer when hiding
2519 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
2520 (org-hide-block-toggle)
2521 (get-char-property (point) 'invisible
))))
2523 (ert-deftest test-org
/hide-block-toggle-maybe
()
2524 "Test `org-hide-block-toggle-maybe' specifications."
2526 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
2527 (org-hide-block-toggle-maybe)))
2529 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
2534 ;;; test-org.el ends here