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 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 (cl-letf (((symbol-function 'current-time
)
202 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
205 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
209 (cl-letf (((symbol-function 'current-time
)
211 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
214 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
215 ;; When `org-read-date-prefer-future' is non-nil, prefer future
216 ;; dates (relatively to now) when incomplete. Otherwise, use
221 (cl-letf (((symbol-function 'current-time
)
223 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
224 (let ((org-read-date-prefer-future t
))
225 (org-read-date t nil
"1")))))
229 (cl-letf (((symbol-function 'current-time
)
231 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
232 (let ((org-read-date-prefer-future t
))
233 (org-read-date t nil
"3-4")))))
237 (cl-letf (((symbol-function 'current-time
)
239 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
240 (let ((org-read-date-prefer-future nil
))
241 (org-read-date t nil
"3-4")))))
242 ;; When set to `org-read-date-prefer-future' is set to `time', read
243 ;; day is moved to tomorrow if specified hour is before current
244 ;; time. However, it only happens in no other part of the date is
249 (cl-letf (((symbol-function 'current-time
)
251 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
252 (let ((org-read-date-prefer-future 'time
))
253 (org-read-date t nil
"00:40" nil
)))))
257 (cl-letf (((symbol-function 'current-time
)
259 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
260 (let ((org-read-date-prefer-future 'time
))
261 (org-read-date t nil
"29 00:40" nil
)))))
262 ;; Caveat: `org-read-date-prefer-future' always refers to current
263 ;; time, not default time, when they differ.
267 (cl-letf (((symbol-function 'current-time
)
269 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
270 (let ((org-read-date-prefer-future t
))
273 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
277 (cl-letf (((symbol-function 'current-time
)
279 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
280 (let ((org-read-date-prefer-future t
))
283 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
285 (ert-deftest test-org
/org-parse-time-string
()
286 "Test `org-parse-time-string'."
287 (should (equal (org-parse-time-string "2012-03-29 16:40")
288 '(0 40 16 29 3 2012 nil nil nil
)))
289 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
290 '(0 40 16 29 3 2012 nil nil nil
)))
291 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
292 '(0 40 16 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>")
294 '(0 0 0 29 3 2012 nil nil nil
)))
295 (should (equal (org-parse-time-string "<2012-03-29>" t
)
296 '(0 nil nil
29 3 2012 nil nil nil
))))
298 (ert-deftest test-org
/closest-date
()
299 "Test `org-closest-date' specifications."
301 ;; Time stamps without a repeater are returned unchanged.
305 (calendar-gregorian-from-absolute
306 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
307 ;; Time stamps with a null repeater are returned unchanged.
311 (calendar-gregorian-from-absolute
312 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
313 ;; if PREFER is set to `past' always return a date before, or equal
318 (calendar-gregorian-from-absolute
319 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
323 (calendar-gregorian-from-absolute
324 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
325 ;; if PREFER is set to `future' always return a date before, or equal
330 (calendar-gregorian-from-absolute
331 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
335 (calendar-gregorian-from-absolute
336 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
337 ;; If PREFER is neither `past' nor `future', select closest date.
341 (calendar-gregorian-from-absolute
342 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
346 (calendar-gregorian-from-absolute
347 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
348 ;; Test "day" repeater.
351 (calendar-gregorian-from-absolute
352 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
355 (calendar-gregorian-from-absolute
356 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
357 ;; Test "month" repeater.
360 (calendar-gregorian-from-absolute
361 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
364 (calendar-gregorian-from-absolute
365 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
366 ;; Test "year" repeater.
369 (calendar-gregorian-from-absolute
370 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
373 (calendar-gregorian-from-absolute
374 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
376 (ert-deftest test-org
/deadline-close-p
()
377 "Test `org-deadline-close-p' specifications."
378 ;; Pretend that the current time is 2016-06-03 Fri 01:43
379 (cl-letf (((symbol-function 'current-time
)
380 (lambda () '(22353 6425 905205 644000))))
381 ;; Timestamps are close if they are within `ndays' of lead time.
382 (org-test-with-temp-text "* Heading"
383 (should (org-deadline-close-p "2016-06-03 Fri" 0))
384 (should (org-deadline-close-p "2016-06-02 Thu" 0))
385 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
386 (should (org-deadline-close-p "2016-06-04 Sat" 1))
387 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
388 ;; Read `ndays' from timestamp if argument not given.
389 (org-test-with-temp-text "* H"
390 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
391 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
392 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
393 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
394 ;; Prefer `ndays' argument over lead time in timestamp.
395 (org-test-with-temp-text "* H"
396 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
397 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
398 ;; Completed tasks are never close.
399 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
400 (org-test-with-temp-text "* TODO Heading"
401 (should (org-deadline-close-p "2016-06-03")))
402 (org-test-with-temp-text "* DONE Heading"
403 (should-not (org-deadline-close-p "2016-06-03"))))))
408 (ert-deftest test-org
/insert-property-drawer
()
409 "Test `org-insert-property-drawer' specifications."
410 ;; Error before first headline.
411 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
412 ;; Insert drawer right after headline if there is no planning line,
413 ;; or after it otherwise.
415 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text "* H\nParagraph<point>"
417 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
420 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
421 (org-test-with-temp-text
422 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
423 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
425 ;; Indent inserted drawer.
427 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
428 (org-test-with-temp-text "* H\nParagraph<point>"
429 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
431 ;; Handle insertion at eob.
433 (equal "* H\n:PROPERTIES:\n:END:\n"
434 (org-test-with-temp-text "* H"
435 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
437 ;; Skip inlinetasks before point.
438 (when (featurep 'org-inlinetask
)
440 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
441 (org-test-with-temp-text
442 "* H\n*************** I\n*************** END\nP<point>"
443 (let ((org-adapt-indentation nil
)
444 (org-inlinetask-min-level 15))
445 (org-insert-property-drawer))
447 ;; Correctly set drawer in an inlinetask.
448 (when (featurep 'org-inlinetask
)
450 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
451 (org-test-with-temp-text
452 "* H\n*************** I\nP<point>\n*************** END"
453 (let ((org-adapt-indentation nil
)
454 (org-inlinetask-min-level 15))
455 (org-insert-property-drawer))
461 (ert-deftest test-org
/fill-paragraph
()
462 "Test `org-fill-paragraph' specifications."
463 ;; At an Org table, align it.
466 (org-test-with-temp-text "|a|"
470 (equal "#+name: table\n| a |\n"
471 (org-test-with-temp-text "#+name: table\n| a |\n"
474 ;; At a paragraph, preserve line breaks.
475 (org-test-with-temp-text "some \\\\\nlong\ntext"
476 (let ((fill-column 20))
478 (should (equal (buffer-string) "some \\\\\nlong text"))))
479 ;; Correctly fill a paragraph when point is at its very end.
482 (org-test-with-temp-text "A\nB"
483 (let ((fill-column 20))
484 (goto-char (point-max))
487 ;; Correctly fill the last paragraph of a greater element.
489 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
490 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
491 (let ((fill-column 8))
496 ;; Correctly fill an element in a narrowed buffer.
499 (org-test-with-temp-text "01234 6789"
500 (let ((fill-column 5))
501 (narrow-to-region 1 8)
504 ;; Handle `adaptive-fill-regexp' in paragraphs.
507 (org-test-with-temp-text "> a\n> b"
508 (let ((fill-column 5)
509 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
512 ;; Special case: Fill first paragraph when point is at an item or
513 ;; a plain-list or a footnote reference.
516 (org-test-with-temp-text "- A\n B"
517 (let ((fill-column 20))
522 (org-test-with-temp-text "[fn:1] A\nB"
523 (let ((fill-column 20))
526 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
527 (let ((fill-column 20))
529 (should (equal (buffer-string)
530 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
531 ;; Fill contents of `comment-block' elements.
534 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
535 (let ((fill-column 20))
539 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
540 ;; Fill `comment' elements.
543 (org-test-with-temp-text " # A\n # B"
544 (let ((fill-column 20))
547 ;; Do not mix consecutive comments when filling one of them.
549 (equal "# A B\n\n# C"
550 (org-test-with-temp-text "# A\n# B\n\n# C"
551 (let ((fill-column 20))
554 ;; Use commented empty lines as separators when filling comments.
556 (equal "# A B\n#\n# C"
557 (org-test-with-temp-text "# A\n# B\n#\n# C"
558 (let ((fill-column 20))
561 ;; Handle `adaptive-fill-regexp' in comments.
564 (org-test-with-temp-text "# > a\n# > b"
565 (let ((fill-column 20)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
569 ;; Do nothing at affiliated keywords.
570 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
571 (let ((fill-column 20))
573 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
574 ;; Do not move point after table when filling a table.
576 (org-test-with-temp-text "| a | b |\n| c | d |\n"
581 (ert-deftest test-org
/auto-fill-function
()
582 "Test auto-filling features."
583 ;; Auto fill paragraph.
586 (org-test-with-temp-text "12345 7890"
587 (let ((fill-column 5))
589 (org-auto-fill-function)
591 ;; Auto fill first paragraph in an item.
593 (equal "- 12345\n 7890"
594 (org-test-with-temp-text "- 12345 7890"
595 (let ((fill-column 7))
597 (org-auto-fill-function)
599 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
601 (equal "> 12345\n 7890"
602 (org-test-with-temp-text "> 12345 7890"
603 (let ((fill-column 10)
604 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
605 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
607 (org-auto-fill-function)
610 (equal "> 12345\n> 12345\n> 7890"
611 (org-test-with-temp-text "> 12345\n> 12345 7890"
612 (let ((fill-column 10)
613 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
614 (goto-char (point-max))
615 (org-auto-fill-function)
618 (equal " 12345\n *12345\n *12345"
619 (org-test-with-temp-text " 12345\n *12345 12345"
620 (let ((fill-column 10)
621 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
622 (goto-char (point-max))
623 (org-auto-fill-function)
625 ;; Auto fill comments.
627 (equal " # 12345\n # 7890"
628 (org-test-with-temp-text " # 12345 7890"
629 (let ((fill-column 10))
631 (org-auto-fill-function)
633 ;; A hash within a line isn't a comment.
635 (equal "12345 # 7890\n# 1"
636 (org-test-with-temp-text "12345 # 7890 1"
637 (let ((fill-column 12))
639 (org-auto-fill-function)
641 ;; Correctly interpret empty prefix.
643 (equal "# a\n# b\nRegular\n# paragraph"
644 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
645 (let ((fill-column 12))
647 (org-auto-fill-function)
649 ;; Comment block: auto fill contents.
651 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
652 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
653 (let ((fill-column 5))
656 (org-auto-fill-function)
659 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
660 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
661 (let ((fill-column 5))
664 (org-auto-fill-function)
666 ;; Do not fill if a new item could be created.
669 (org-test-with-temp-text "12345 - 90"
670 (let ((fill-column 5))
672 (org-auto-fill-function)
674 ;; Do not fill if a line break could be introduced.
676 (equal "123\\\\\n7890"
677 (org-test-with-temp-text "123\\\\ 7890"
678 (let ((fill-column 6))
680 (org-auto-fill-function)
682 ;; Do not fill affiliated keywords.
684 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
685 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
686 (let ((fill-column 20))
688 (org-auto-fill-function)
695 (ert-deftest test-org
/indent-line
()
696 "Test `org-indent-line' specifications."
697 ;; Do not indent diary sexps, footnote definitions or headlines.
700 (org-test-with-temp-text "%%(org-calendar-holiday)"
702 (org-get-indentation))))
705 (org-test-with-temp-text "[fn:1] fn"
706 (let ((org-adapt-indentation t
)) (org-indent-line))
707 (org-get-indentation))))
710 (org-test-with-temp-text "* H"
712 (org-get-indentation))))
713 ;; Do not indent before first headline.
716 (org-test-with-temp-text ""
718 (org-get-indentation))))
719 ;; Indent according to headline level otherwise, unless
720 ;; `org-adapt-indentation' is nil.
723 (org-test-with-temp-text "* H\nA"
725 (let ((org-adapt-indentation t
)) (org-indent-line))
726 (org-get-indentation))))
729 (org-test-with-temp-text "* H\n\nA"
731 (let ((org-adapt-indentation t
)) (org-indent-line))
732 (org-get-indentation))))
735 (org-test-with-temp-text "* H\nA"
737 (let ((org-adapt-indentation nil
)) (org-indent-line))
738 (org-get-indentation))))
739 ;; Indenting preserves point position.
741 (org-test-with-temp-text "* H\nAB"
744 (let ((org-adapt-indentation t
)) (org-indent-line))
746 ;; Do not change indentation at an item.
749 (org-test-with-temp-text "* H\n - A"
751 (let ((org-adapt-indentation t
)) (org-indent-line))
752 (org-get-indentation))))
753 ;; On blank lines at the end of a list, indent like last element
754 ;; within it if the line is still in the list. If the last element
755 ;; is an item, indent like its contents. Otherwise, indent like the
759 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
760 (let ((org-adapt-indentation t
)) (org-indent-line))
761 (org-get-indentation))))
764 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
765 (let ((org-adapt-indentation t
)) (org-indent-line))
766 (org-get-indentation))))
769 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
770 (let ((org-adapt-indentation t
)) (org-indent-line))
771 (org-get-indentation))))
774 (org-test-with-temp-text "* H\n- A\n - \n<point>"
775 (let ((org-adapt-indentation t
)) (org-indent-line))
776 (org-get-indentation))))
779 (org-test-with-temp-text
780 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
781 (let ((org-adapt-indentation t
)) (org-indent-line))
782 (org-get-indentation))))
785 (org-test-with-temp-text "- A\n B\n\n<point>"
786 (let ((org-adapt-indentation nil
)) (org-indent-line))
787 (org-get-indentation))))
788 ;; Likewise, on a blank line at the end of a footnote definition,
789 ;; indent at column 0 if line belongs to the definition. Otherwise,
790 ;; indent like the definition itself.
793 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
794 (goto-char (point-max))
795 (let ((org-adapt-indentation t
)) (org-indent-line))
796 (org-get-indentation))))
799 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
800 (goto-char (point-max))
801 (let ((org-adapt-indentation t
)) (org-indent-line))
802 (org-get-indentation))))
803 ;; After the end of the contents of a greater element, indent like
804 ;; the beginning of the element.
807 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
810 (org-get-indentation))))
811 ;; On blank lines after a paragraph, indent like its last non-empty
815 (org-test-with-temp-text " Paragraph\n\n<point>"
817 (org-get-indentation))))
818 ;; At the first line of an element, indent like previous element's
819 ;; first line, ignoring footnotes definitions and inline tasks, or
820 ;; according to parent.
823 (org-test-with-temp-text "A\n\n B\n\nC"
824 (goto-char (point-max))
826 (org-get-indentation))))
829 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
830 (goto-char (point-max))
832 (org-get-indentation))))
835 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
838 (org-get-indentation))))
839 ;; Within code part of a source block, use language major mode if
840 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
841 ;; according to line above.
844 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
846 (let ((org-src-tab-acts-natively t
)
847 (org-edit-src-content-indentation 0))
849 (org-get-indentation))))
852 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
854 (let ((org-src-tab-acts-natively nil
)
855 (org-edit-src-content-indentation 0))
857 (org-get-indentation))))
858 ;; Otherwise, indent like the first non-blank line above.
861 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
864 (org-get-indentation))))
865 ;; Align node properties according to `org-property-format'. Handle
866 ;; nicely empty values.
868 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
869 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
870 (let ((org-property-format "%-10s %s")) (org-indent-line))
873 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
874 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
875 (let ((org-property-format "%-10s %s")) (org-indent-line))
878 (ert-deftest test-org
/indent-region
()
879 "Test `org-indent-region' specifications."
883 (org-test-with-temp-text " A\nB\n C"
884 (org-indent-region (point-min) (point-max))
886 ;; Indent greater elements along with their contents.
888 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
889 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
890 (org-indent-region (point-min) (point-max))
892 ;; Ignore contents of verse blocks and example blocks.
894 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
895 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
896 (org-indent-region (point-min) (point-max))
899 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
900 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
901 (org-indent-region (point-min) (point-max))
903 ;; Indent according to mode if `org-src-tab-acts-natively' is
904 ;; non-nil. Otherwise, do not indent code at all.
906 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
907 (org-test-with-temp-text
908 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
909 (let ((org-src-tab-acts-natively t
)
910 (org-edit-src-content-indentation 0))
911 (org-indent-region (point-min) (point-max)))
914 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
915 (org-test-with-temp-text
916 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
917 (let ((org-src-tab-acts-natively nil
)
918 (org-edit-src-content-indentation 0))
919 (org-indent-region (point-min) (point-max)))
921 ;; Align node properties according to `org-property-format'. Handle
922 ;; nicely empty values.
924 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
925 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
926 (let ((org-property-format "%-10s %s")
927 (org-adapt-indentation nil
))
928 (org-indent-region (point) (point-max)))
931 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
932 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
933 (let ((org-property-format "%-10s %s")
934 (org-adapt-indentation nil
))
935 (org-indent-region (point) (point-max)))
937 ;; Indent plain lists.
939 (equal "- A\n B\n - C\n\n D"
940 (org-test-with-temp-text "- A\n B\n - C\n\n D"
941 (org-indent-region (point-min) (point-max))
945 (org-test-with-temp-text " - A\n\n - B"
946 (org-indent-region (point-min) (point-max))
948 ;; Indent footnote definitions.
950 (equal "[fn:1] Definition\n\nDefinition"
951 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
952 (org-indent-region (point-min) (point-max))
954 ;; Special case: Start indenting on a blank line.
957 (org-test-with-temp-text "\n Paragraph"
958 (org-indent-region (point-min) (point-max))
965 (ert-deftest test-org
/delete-indentation
()
966 "Test `org-delete-indentation' specifications."
968 (should (equal "foo bar"
969 (org-test-with-temp-text
971 (org-delete-indentation)
973 ;; With optional argument.
974 (should (equal "foo bar"
975 (org-test-with-temp-text
977 (org-delete-indentation t
)
979 ;; At headline text should be appended to the headline text.
981 (equal"* foo bar :tag:"
982 (let (org-auto-align-tags)
983 (org-test-with-temp-text
984 "* foo :tag:\n bar<point>"
985 (org-delete-indentation)
988 (equal "* foo bar :tag:"
989 (let (org-auto-align-tags)
990 (org-test-with-temp-text
991 "* foo <point>:tag:\n bar"
992 (org-delete-indentation t
)
995 (ert-deftest test-org
/return
()
996 "Test `org-return' specifications."
1000 (org-test-with-temp-text "Para<point>graph"
1003 ;; With optional argument, indent line.
1005 (equal " Para\n graph"
1006 (org-test-with-temp-text " Para<point>graph"
1009 ;; On a table, call `org-table-next-row'.
1011 (org-test-with-temp-text "| <point>a |\n| b |"
1013 (looking-at-p "b")))
1014 ;; Open link or timestamp under point when `org-return-follows-link'
1017 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1018 (let ((org-return-follows-link t
)
1019 (org-link-search-must-match-exact-headline nil
))
1021 (looking-at-p "<<target>>")))
1023 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1024 (let ((org-return-follows-link nil
)) (org-return))
1025 (looking-at-p "<<target>>")))
1027 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1028 (let ((org-return-follows-link t
)) (org-return))
1029 (looking-at-p "* b")))
1031 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1032 (let ((org-return-follows-link t
)
1033 (org-link-search-must-match-exact-headline nil
))
1035 (looking-at-p "<<target>>")))
1037 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1038 (let ((org-return-follows-link t
)
1039 (org-link-search-must-match-exact-headline nil
))
1041 (looking-at-p "<<target>>")))
1042 ;; When `org-return-follows-link' is non-nil, tolerate links and
1043 ;; timestamps in comments, node properties, etc.
1045 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1046 (let ((org-return-follows-link t
)
1047 (org-link-search-must-match-exact-headline nil
))
1049 (looking-at-p "<<target>>")))
1051 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1052 (let ((org-return-follows-link nil
)) (org-return))
1053 (looking-at-p "<<target>>")))
1055 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1056 (let ((org-return-follows-link t
)
1057 (org-link-search-must-match-exact-headline nil
))
1059 (looking-at-p "<<target>>")))
1060 ;; However, do not open link when point is in a table.
1062 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1063 (let ((org-return-follows-link t
)) (org-return))
1064 (looking-at-p "between")))
1065 ;; Special case: in a list, when indenting, do not break structure.
1068 (org-test-with-temp-text "- A <point>B"
1073 (org-test-with-temp-text "- A\n<point>- B"
1076 ;; On tags part of a headline, add a newline below it instead of
1079 (equal "* H :tag:\n"
1080 (org-test-with-temp-text "* H :<point>tag:"
1083 ;; Before headline text, add a newline below it instead of breaking
1086 (equal "* TODO H :tag:\n"
1087 (org-test-with-temp-text "* <point>TODO H :tag:"
1091 (equal "* TODO [#B] H :tag:\n"
1092 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1095 (should ;TODO are case-sensitive
1097 (org-test-with-temp-text "* <point>Todo"
1100 ;; At headline text, break headline text but preserve tags.
1102 (equal "* TODO [#B] foo :tag:\nbar"
1103 (let (org-auto-align-tags)
1104 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1107 ;; At bol of headline insert newline.
1110 (org-test-with-temp-text "<point>* h"
1113 ;; Refuse to leave invalid headline in buffer.
1116 (org-test-with-temp-text "*<point> h"
1120 (ert-deftest test-org
/meta-return
()
1121 "Test M-RET (`org-meta-return') specifications."
1122 ;; In a table field insert a row above.
1124 (org-test-with-temp-text "| a |"
1128 (looking-at "| |$")))
1129 ;; In a paragraph change current line into a header.
1131 (org-test-with-temp-text "a"
1134 (looking-at "\* a$")))
1135 ;; In an item insert an item, in this case above.
1137 (org-test-with-temp-text "- a"
1140 (looking-at "- $")))
1141 ;; In a drawer and item insert an item, in this case above.
1143 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1147 (looking-at "- $"))))
1149 (ert-deftest test-org
/insert-heading
()
1150 "Test `org-insert-heading' specifications."
1151 ;; In an empty buffer, insert a new headline.
1154 (org-test-with-temp-text ""
1155 (org-insert-heading)
1157 ;; At the beginning of a line, turn it into a headline.
1160 (org-test-with-temp-text "<point>P"
1161 (org-insert-heading)
1163 ;; In the middle of a line, split the line if allowed, otherwise,
1164 ;; insert the headline at its end.
1166 (equal "Para\n* graph"
1167 (org-test-with-temp-text "Para<point>graph"
1168 (let ((org-M-RET-may-split-line '((default . t
))))
1169 (org-insert-heading))
1172 (equal "Paragraph\n* "
1173 (org-test-with-temp-text "Para<point>graph"
1174 (let ((org-M-RET-may-split-line '((default . nil
))))
1175 (org-insert-heading))
1177 ;; At the beginning of a headline, create one above.
1180 (org-test-with-temp-text "* H"
1181 (org-insert-heading)
1183 ;; In the middle of a headline, split it if allowed.
1186 (org-test-with-temp-text "* H<point>1"
1187 (let ((org-M-RET-may-split-line '((headline . t
))))
1188 (org-insert-heading))
1192 (org-test-with-temp-text "* H<point>1"
1193 (let ((org-M-RET-may-split-line '((headline . nil
))))
1194 (org-insert-heading))
1196 ;; However, splitting cannot happen on TODO keywords, priorities or
1199 (equal "* TODO H1\n* \n"
1200 (org-test-with-temp-text "* TO<point>DO H1"
1201 (let ((org-M-RET-may-split-line '((headline . t
))))
1202 (org-insert-heading))
1205 (equal "* [#A] H1\n* \n"
1206 (org-test-with-temp-text "* [#<point>A] H1"
1207 (let ((org-M-RET-may-split-line '((headline . t
))))
1208 (org-insert-heading))
1211 (equal "* H1 :tag:\n* \n"
1212 (org-test-with-temp-text "* H1 :ta<point>g:"
1213 (let ((org-M-RET-may-split-line '((headline . t
))))
1214 (org-insert-heading))
1216 ;; New headline level depends on the level of the headline above.
1219 (org-test-with-temp-text "** H\n<point>P"
1220 (org-insert-heading)
1223 (equal "** H\nPara\n** graph"
1224 (org-test-with-temp-text "** H\nPara<point>graph"
1225 (let ((org-M-RET-may-split-line '((default . t
))))
1226 (org-insert-heading))
1230 (org-test-with-temp-text "** H"
1231 (org-insert-heading)
1233 ;; When called with one universal argument, insert a new headline at
1234 ;; the end of the current subtree, independently on the position of
1239 (org-test-with-temp-text "* H1\n** H2"
1240 (let ((org-insert-heading-respect-content nil
))
1241 (org-insert-heading '(4)))
1246 (org-test-with-temp-text "* H<point>1\n** H2"
1247 (let ((org-insert-heading-respect-content nil
))
1248 (org-insert-heading '(4)))
1250 ;; When called with two universal arguments, insert a new headline
1251 ;; at the end of the grandparent subtree.
1253 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1254 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1255 (let ((org-insert-heading-respect-content nil
))
1256 (org-insert-heading '(16)))
1258 ;; When optional TOP-LEVEL argument is non-nil, always insert
1259 ;; a level 1 heading.
1261 (equal "* H1\n** H2\n* \n"
1262 (org-test-with-temp-text "* H1\n** H2<point>"
1263 (org-insert-heading nil nil t
)
1266 (equal "* H1\n- item\n* "
1267 (org-test-with-temp-text "* H1\n- item<point>"
1268 (org-insert-heading nil nil t
)
1270 ;; Obey `org-blank-before-new-entry'.
1272 (equal "* H1\n\n* \n"
1273 (org-test-with-temp-text "* H1<point>"
1274 (let ((org-blank-before-new-entry '((heading . t
))))
1275 (org-insert-heading))
1279 (org-test-with-temp-text "* H1<point>"
1280 (let ((org-blank-before-new-entry '((heading . nil
))))
1281 (org-insert-heading))
1284 (equal "* H1\n* H2\n* \n"
1285 (org-test-with-temp-text "* H1\n* H2<point>"
1286 (let ((org-blank-before-new-entry '((heading . auto
))))
1287 (org-insert-heading))
1290 (equal "* H1\n\n* H2\n\n* \n"
1291 (org-test-with-temp-text "* H1\n\n* H2<point>"
1292 (let ((org-blank-before-new-entry '((heading . auto
))))
1293 (org-insert-heading))
1295 ;; Corner case: correctly insert a headline after an empty one.
1298 (org-test-with-temp-text "* <point>"
1299 (org-insert-heading)
1302 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1303 "Test `org-insert-todo-heading-respect-content' specifications."
1304 ;; Create a TODO heading.
1306 (org-test-with-temp-text "* H1\n Body"
1307 (org-insert-todo-heading-respect-content)
1308 (nth 2 (org-heading-components))))
1309 ;; Add headline at the end of the first subtree
1313 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1314 (org-insert-todo-heading-respect-content)
1315 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1316 ;; In a list, do not create a new item.
1320 (org-test-with-temp-text "* H\n- an item\n- another one"
1321 (search-forward "an ")
1322 (org-insert-todo-heading-respect-content)
1323 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1325 (ert-deftest test-org
/clone-with-time-shift
()
1326 "Test `org-clone-subtree-with-time-shift'."
1327 ;; Clone non-repeating once.
1333 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1334 (org-clone-subtree-with-time-shift 1 "+2d")
1335 (replace-regexp-in-string
1336 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1338 ;; Clone repeating once.
1343 * H1\n<2015-06-25 +1w>
1345 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1346 (org-clone-subtree-with-time-shift 1 "+2d")
1347 (replace-regexp-in-string
1348 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1350 ;; Clone non-repeating zero times.
1355 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1356 (org-clone-subtree-with-time-shift 0 "+2d")
1357 (replace-regexp-in-string
1358 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1360 ;; Clone repeating "zero" times.
1364 * H1\n<2015-06-23 +1w>
1366 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1367 (org-clone-subtree-with-time-shift 0 "+2d")
1368 (replace-regexp-in-string
1369 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1373 ;;; Fixed-Width Areas
1375 (ert-deftest test-org
/toggle-fixed-width
()
1376 "Test `org-toggle-fixed-width' specifications."
1377 ;; No region: Toggle on fixed-width marker in paragraphs.
1380 (org-test-with-temp-text "A"
1381 (org-toggle-fixed-width)
1383 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1386 (org-test-with-temp-text ": A"
1387 (org-toggle-fixed-width)
1389 ;; No region: Toggle on marker in blank lines after elements or just
1390 ;; after a headline.
1393 (org-test-with-temp-text "* H\n"
1395 (org-toggle-fixed-width)
1398 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1399 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1400 (goto-char (point-max))
1401 (org-toggle-fixed-width)
1403 ;; No region: Toggle on marker in front of one line elements (e.g.,
1404 ;; headlines, clocks)
1406 (equal ": * Headline"
1407 (org-test-with-temp-text "* Headline"
1408 (org-toggle-fixed-width)
1411 (equal ": #+KEYWORD: value"
1412 (org-test-with-temp-text "#+KEYWORD: value"
1413 (org-toggle-fixed-width)
1415 ;; No region: error in other situations.
1417 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1419 (org-toggle-fixed-width)
1421 ;; No region: Indentation is preserved.
1424 (org-test-with-temp-text "- A\n B"
1426 (org-toggle-fixed-width)
1428 ;; Region: If it contains only fixed-width elements and blank lines,
1429 ;; toggle off fixed-width markup.
1432 (org-test-with-temp-text ": A\n\n: B"
1433 (transient-mark-mode 1)
1434 (push-mark (point) t t
)
1435 (goto-char (point-max))
1436 (org-toggle-fixed-width)
1438 ;; Region: If it contains anything else, toggle on fixed-width but
1439 ;; not on fixed-width areas.
1441 (equal ": A\n: \n: B\n: \n: C"
1442 (org-test-with-temp-text "A\n\n: B\n\nC"
1443 (transient-mark-mode 1)
1444 (push-mark (point) t t
)
1445 (goto-char (point-max))
1446 (org-toggle-fixed-width)
1448 ;; Region: Ignore blank lines at its end, unless it contains only
1452 (org-test-with-temp-text "A\n\n"
1453 (transient-mark-mode 1)
1454 (push-mark (point) t t
)
1455 (goto-char (point-max))
1456 (org-toggle-fixed-width)
1460 (org-test-with-temp-text "\n\n"
1461 (transient-mark-mode 1)
1462 (push-mark (point) t t
)
1463 (goto-char (point-max))
1464 (org-toggle-fixed-width)
1471 (ert-deftest test-org
/get-heading
()
1472 "Test `org-get-heading' specifications."
1473 ;; Return current heading, even if point is not on it.
1476 (org-test-with-temp-text "* H"
1477 (org-get-heading))))
1480 (org-test-with-temp-text "* H\nText<point>"
1481 (org-get-heading))))
1482 ;; Without any optional argument, return TODO keywords and tags.
1485 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1486 (org-get-heading))))
1489 (org-test-with-temp-text "* H :tag:"
1490 (org-get-heading))))
1491 ;; With NO-TAGS argument, ignore tags.
1494 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1495 (org-get-heading t
))))
1498 (org-test-with-temp-text "* H :tag:"
1499 (org-get-heading t
))))
1500 ;; With NO-TODO, ignore TODO keyword.
1503 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1504 (org-get-heading nil t
))))
1507 (org-test-with-temp-text "* H :tag:"
1508 (org-get-heading nil t
))))
1509 ;; TODO keywords are case-sensitive.
1512 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1513 (org-get-heading nil t
))))
1514 ;; On an empty headline, return value is consistent.
1515 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1516 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1517 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1518 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t
)))))
1520 (ert-deftest test-org
/in-commented-heading-p
()
1521 "Test `org-in-commented-heading-p' specifications."
1522 ;; Commented headline.
1524 (org-test-with-temp-text "* COMMENT Headline\nBody"
1525 (goto-char (point-max))
1526 (org-in-commented-heading-p)))
1527 ;; Commented ancestor.
1529 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1530 (goto-char (point-max))
1531 (org-in-commented-heading-p)))
1532 ;; Comment keyword is case-sensitive.
1534 (org-test-with-temp-text "* Comment Headline\nBody"
1535 (goto-char (point-max))
1536 (org-in-commented-heading-p)))
1537 ;; Keyword is standalone.
1539 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1540 (goto-char (point-max))
1541 (org-in-commented-heading-p)))
1542 ;; Optional argument.
1544 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1545 (goto-char (point-max))
1546 (org-in-commented-heading-p t
))))
1548 (ert-deftest test-org
/entry-blocked-p
()
1549 ;; Check other dependencies.
1551 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1552 (let ((org-enforce-todo-dependencies t
)
1554 '(org-block-todo-from-children-or-siblings-or-parent)))
1555 (org-entry-blocked-p))))
1557 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1558 (let ((org-enforce-todo-dependencies t
)
1560 '(org-block-todo-from-children-or-siblings-or-parent)))
1561 (org-entry-blocked-p))))
1562 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1565 (org-test-with-temp-text "* Blocked\n** TODO one"
1566 (let ((org-enforce-todo-dependencies t
)
1568 '(org-block-todo-from-children-or-siblings-or-parent)))
1569 (org-entry-blocked-p))))
1571 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1572 (let ((org-enforce-todo-dependencies t
)
1574 '(org-block-todo-from-children-or-siblings-or-parent)))
1575 (org-entry-blocked-p))))
1576 ;; Follow :ORDERED: specifications.
1578 (org-test-with-temp-text
1579 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1580 (let ((org-enforce-todo-dependencies t
)
1582 '(org-block-todo-from-children-or-siblings-or-parent)))
1583 (org-entry-blocked-p))))
1585 (org-test-with-temp-text
1586 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1587 (let ((org-enforce-todo-dependencies t
)
1589 '(org-block-todo-from-children-or-siblings-or-parent)))
1590 (org-entry-blocked-p)))))
1592 (ert-deftest test-org
/get-outline-path
()
1593 "Test `org-get-outline-path' specifications."
1594 ;; Top-level headlines have no outline path.
1596 (org-test-with-temp-text "* H"
1597 (org-get-outline-path)))
1598 ;; Otherwise, outline path is the path leading to the headline.
1601 (org-test-with-temp-text "* H\n** S<point>"
1602 (org-get-outline-path))))
1603 ;; Find path even when point is not on a headline.
1606 (org-test-with-temp-text "* H\n** S\nText<point>"
1607 (org-get-outline-path))))
1608 ;; TODO keywords, tags and statistics cookies are ignored.
1611 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1612 (org-get-outline-path))))
1613 ;; Links are replaced with their description or their path.
1616 (org-test-with-temp-text
1617 "* [[http://orgmode.org][Org]]\n** S<point>"
1618 (org-get-outline-path))))
1620 (equal '("http://orgmode.org")
1621 (org-test-with-temp-text
1622 "* [[http://orgmode.org]]\n** S<point>"
1623 (org-get-outline-path))))
1624 ;; When WITH-SELF is non-nil, include current heading.
1627 (org-test-with-temp-text "* H"
1628 (org-get-outline-path t
))))
1631 (org-test-with-temp-text "* H\n** S\nText<point>"
1632 (org-get-outline-path t
))))
1633 ;; Using cache is transparent to the user.
1636 (org-test-with-temp-text "* H\n** S<point>"
1637 (setq org-outline-path-cache nil
)
1638 (org-get-outline-path nil t
))))
1639 ;; Do not corrupt cache when finding outline path in distant part of
1643 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1644 (setq org-outline-path-cache nil
)
1645 (org-get-outline-path nil t
)
1646 (search-forward "S2")
1647 (org-get-outline-path nil t
))))
1648 ;; Do not choke on empty headlines.
1650 (org-test-with-temp-text "* H\n** <point>"
1651 (org-get-outline-path)))
1653 (org-test-with-temp-text "* \n** H<point>"
1654 (org-get-outline-path))))
1656 (ert-deftest test-org
/format-outline-path
()
1657 "Test `org-format-outline-path' specifications."
1659 (string= (org-format-outline-path (list "one" "two" "three"))
1663 (string= (org-format-outline-path '())
1666 (string= (org-format-outline-path '(nil))
1668 ;; Empty path and prefix.
1670 (string= (org-format-outline-path '() nil
">>")
1672 ;; Trailing whitespace in headings.
1674 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1676 ;; Non-default prefix and separators.
1678 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1679 ">>|one|two|three"))
1682 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1684 ;; Give a very narrow width.
1686 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1688 ;; Give a prefix that extends beyond the width.
1690 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1694 (ert-deftest test-org
/map-entries
()
1695 "Test `org-map-entries' specifications."
1699 (org-test-with-temp-text "* Level 1\n** Level 2"
1700 (org-map-entries #'point
))))
1704 (org-test-with-temp-text "* Level 1\n** Level 2"
1705 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1708 (org-test-with-temp-text "* Level 1\n** Level 2"
1709 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1713 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1714 (org-map-entries #'point
"yes"))))
1717 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1718 (org-map-entries #'point
"+yes-a"))))
1721 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1722 (org-map-entries #'point
"{yes?}"))))
1726 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1727 (org-map-entries #'point
"PRIORITY=\"A\""))))
1731 (org-test-with-temp-text "
1733 SCHEDULED: <2012-03-29 thu.>
1735 SCHEDULED: <2014-03-04 tue.>"
1736 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1739 (org-test-with-temp-text "
1741 SCHEDULED: <2012-03-29 thu.>
1743 SCHEDULED: <2014-03-04 tue.>"
1744 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1745 ;; Regular property match.
1748 (org-test-with-temp-text "
1757 (org-map-entries #'point
"TEST=1"))))
1758 ;; Multiple criteria.
1761 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1762 (let (org-odd-levels-only
1763 (org-use-tag-inheritance nil
))
1764 (org-map-entries #'point
"yes+LEVEL=1")))))
1768 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1769 (let (org-odd-levels-only)
1770 (org-map-entries #'point
"LEVEL=2|no")))))
1773 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1774 (let (org-odd-levels-only)
1775 (org-map-entries #'point
"yes|no")))))
1779 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1780 (let (org-odd-levels-only)
1781 (org-map-entries #'point
"yes&no"))))))
1783 (ert-deftest test-org
/edit-headline
()
1784 "Test `org-edit-headline' specifications."
1787 (org-test-with-temp-text "* A"
1788 (org-edit-headline "B")
1790 ;; Handle empty headings.
1793 (org-test-with-temp-text "* A"
1794 (org-edit-headline "")
1798 (org-test-with-temp-text "* "
1799 (org-edit-headline "A")
1801 ;; Handle TODO keywords and priority cookies.
1804 (org-test-with-temp-text "* TODO A"
1805 (org-edit-headline "B")
1809 (org-test-with-temp-text "* [#A] A"
1810 (org-edit-headline "B")
1813 (equal "* TODO [#A] B"
1814 (org-test-with-temp-text "* TODO [#A] A"
1815 (org-edit-headline "B")
1819 (org-test-with-temp-text "* A :tag:"
1820 (let ((org-tags-column 4)) (org-edit-headline "B"))
1827 (ert-deftest test-org
/set-regexps-and-options
()
1828 "Test `org-set-regexps-and-options' specifications."
1832 (let ((org-tag-alist '(("A")))
1833 (org-tag-persistent-alist nil
))
1834 (org-test-with-temp-text ""
1836 org-current-tag-alist
))))
1839 (let ((org-tag-alist '(("A")))
1840 (org-tag-persistent-alist nil
))
1841 (org-test-with-temp-text "#+TAGS: B"
1843 org-current-tag-alist
))))
1845 (equal '(("C") ("B"))
1846 (let ((org-tag-alist '(("A")))
1847 (org-tag-persistent-alist '(("C"))))
1848 (org-test-with-temp-text "#+TAGS: B"
1850 org-current-tag-alist
))))
1853 (let ((org-tag-alist '(("A")))
1854 (org-tag-persistent-alist '(("C"))))
1855 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1857 org-current-tag-alist
))))
1859 (equal '(("A" . ?a
) ("B") ("C"))
1860 (let ((org-tag-persistant-alist nil
))
1861 (org-test-with-temp-text "#+TAGS: A(a) B C"
1863 org-current-tag-alist
))))
1865 (equal '(("A") (:newline
) ("B"))
1866 (let ((org-tag-persistent-alist nil
))
1867 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1869 org-current-tag-alist
))))
1871 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
1872 (let ((org-tag-persistent-alist nil
))
1873 (org-test-with-temp-text "#+TAGS: { A B } C"
1875 org-current-tag-alist
))))
1877 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
1878 (let ((org-tag-persistent-alist nil
))
1879 (org-test-with-temp-text "#+TAGS: { A : B C }"
1881 org-current-tag-alist
))))
1883 (equal '(("A" "B" "C"))
1884 (let ((org-tag-persistent-alist nil
))
1885 (org-test-with-temp-text "#+TAGS: { A : B C }"
1887 org-tag-groups-alist
))))
1889 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
1890 (let ((org-tag-persistent-alist nil
))
1891 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1893 org-current-tag-alist
))))
1895 (equal '(("A" "B" "C"))
1896 (let ((org-tag-persistent-alist nil
))
1897 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1899 org-tag-groups-alist
))))
1900 ;; FILETAGS keyword.
1902 (equal '("A" "B" "C")
1903 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1906 ;; PROPERTY keyword. Property names are case-insensitive.
1909 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1911 (cdr (assoc "var" org-file-properties
)))))
1915 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1917 (cdr (assoc "var" org-file-properties
)))))
1921 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1923 (cdr (assoc "var" org-file-properties
)))))
1927 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1929 org-archive-location
)))
1930 ;; CATEGORY keyword.
1933 (org-test-with-temp-text "#+CATEGORY: test"
1938 (org-test-with-temp-text "#+CATEGORY: test"
1940 (cdr (assoc "CATEGORY" org-file-properties
)))))
1943 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1944 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1946 org-columns-default-format
)))
1947 ;; CONSTANTS keyword. Constants names are case sensitive.
1949 (equal '("299792458." "3.14")
1950 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1953 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
1957 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1959 (cdr (assoc "pi" org-table-formula-constants-local
)))))
1962 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1964 (cdr (assoc "PI" org-table-formula-constants-local
)))))
1969 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1971 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
1973 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1977 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1979 (list org-highest-priority org-lowest-priority org-default-priority
))))
1983 (org-test-with-temp-text "#+PRIORITIES: X Z"
1985 (list org-highest-priority org-lowest-priority org-default-priority
))))
1989 (org-test-with-temp-text "#+STARTUP: fold odd"
1991 (list org-startup-folded org-odd-levels-only
))))
1994 (equal '(("A" "B") ("C"))
1995 (org-test-with-temp-text "#+TODO: A B | C"
1997 (list org-not-done-keywords org-done-keywords
))))
1999 (equal '(("A" "C") ("B" "D"))
2000 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2002 (list org-not-done-keywords org-done-keywords
))))
2004 (equal '(("A" "B") ("C"))
2005 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2007 (list org-not-done-keywords org-done-keywords
))))
2009 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2010 (org-test-with-temp-text "#+TODO: A(a)"
2012 org-todo-key-alist
)))
2014 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2015 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2017 org-todo-log-states
)))
2018 ;; Enter SETUPFILE keyword.
2021 (org-test-with-temp-text
2022 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2024 (cdr (assoc "a" org-file-properties
))))))
2032 (ert-deftest test-org
/coderef
()
2033 "Test coderef links specifications."
2035 (org-test-with-temp-text "
2036 #+BEGIN_SRC emacs-lisp
2041 (looking-at "(ref:sc)")))
2042 ;; Find coderef even with alternate label format.
2044 (org-test-with-temp-text "
2045 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2050 (looking-at "{ref:sc}"))))
2054 (ert-deftest test-org
/custom-id
()
2055 "Test custom ID links specifications."
2057 (org-test-with-temp-text
2058 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2060 (looking-at-p "\\* H1")))
2061 ;; Throw an error on false positives.
2063 (org-test-with-temp-text
2064 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2066 (looking-at-p "\\* H1"))))
2070 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2071 ;; a named element (#+name: text) and to headlines (* Text).
2073 (ert-deftest test-org
/fuzzy-links
()
2074 "Test fuzzy links specifications."
2075 ;; Fuzzy link goes in priority to a matching target.
2077 (org-test-with-temp-text
2078 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2079 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2080 (looking-at "<<Test>>")))
2081 ;; Then fuzzy link points to an element with a given name.
2083 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2084 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2085 (looking-at "#\\+NAME: Test")))
2086 ;; A target still lead to a matching headline otherwise.
2088 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2089 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2090 (looking-at "\\* Head2")))
2091 ;; With a leading star in link, enforce heading match.
2093 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2094 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2095 (looking-at "\\* Test")))
2096 ;; With a leading star in link, enforce exact heading match, even
2097 ;; with `org-link-search-must-match-exact-headline' set to nil.
2099 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2100 (let ((org-link-search-must-match-exact-headline nil
))
2101 (org-open-at-point))))
2102 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2104 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2105 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2106 (looking-at "\\* Test")))
2108 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2109 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2110 (looking-at "\\* Test")))
2111 ;; Heading match should not care about spaces, cookies, TODO
2112 ;; keywords, priorities, and tags. However, TODO keywords are
2116 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2117 (org-test-with-temp-text
2118 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2119 (let ((org-link-search-must-match-exact-headline nil
)
2120 (org-todo-regexp "TODO"))
2121 (org-open-at-point))
2122 (looking-at (regexp-quote first-line
)))))
2124 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2125 (let ((org-link-search-must-match-exact-headline nil
)
2126 (org-todo-regexp "TODO"))
2127 (org-open-at-point))))
2128 ;; Heading match should still be exact.
2130 (org-test-with-temp-text "
2131 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2134 (let ((org-link-search-must-match-exact-headline nil
)
2135 (org-todo-regexp "TODO"))
2136 (org-open-at-point))))
2138 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2139 (let ((org-link-search-must-match-exact-headline nil
)
2140 (org-todo-regexp "TODO"))
2141 (org-open-at-point))
2142 (looking-at-p (regexp-quote "** Test 1 2"))))
2143 ;; Heading match ignores COMMENT keyword.
2145 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2147 (looking-at "\\* COMMENT Test")))
2149 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2151 (looking-at "\\* TODO COMMENT Test")))
2152 ;; Correctly un-hexify fuzzy links.
2154 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2158 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2164 (ert-deftest test-org
/org-link-escape-ascii-character
()
2165 "Escape an ascii character."
2169 (org-link-escape "["))))
2171 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2172 "Escape an ascii control character."
2176 (org-link-escape "\t"))))
2178 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2179 "Escape an unicode multibyte character."
2183 (org-link-escape "€"))))
2185 (ert-deftest test-org
/org-link-escape-custom-table
()
2186 "Escape string with custom character table."
2190 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2192 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2193 "Escape string with custom table merged with default table."
2196 "%5BF%6F%6F%3A%42ar%0A%5D"
2197 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2199 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2200 "Unescape an ascii character."
2204 (org-link-unescape "%5B"))))
2206 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2207 "Unescpae an ascii control character."
2211 (org-link-unescape "%0A"))))
2213 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2214 "Unescape unicode multibyte character."
2218 (org-link-unescape "%E2%82%AC"))))
2220 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2221 "Unescape old style percent escaped character."
2224 "à âçèéêîôùû"
2225 (decode-coding-string
2226 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2228 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2229 "Escape and unescape a URL that includes an escaped char.
2230 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2233 "http://some.host.com/form?&id=blah%2Bblah25"
2235 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2239 (ert-deftest test-org
/open-at-point-in-keyword
()
2240 "Does `org-open-at-point' open link in a keyword line?"
2242 (org-test-with-temp-text
2243 "<<top>>\n#+KEYWORD: <point>[[top]]"
2244 (org-open-at-point) t
)))
2246 (ert-deftest test-org
/open-at-point-in-property
()
2247 "Does `org-open-at-point' open link in property drawer?"
2249 (org-test-with-temp-text
2252 :URL: <point>[[*Headline]]
2254 (org-open-at-point) t
)))
2256 (ert-deftest test-org
/open-at-point-in-comment
()
2257 "Does `org-open-at-point' open link in a commented line?"
2259 (org-test-with-temp-text
2260 "<<top>>\n# <point>[[top]]"
2261 (org-open-at-point) t
)))
2263 (ert-deftest test-org
/open-at-point
/inline-image
()
2264 "Test `org-open-at-point' on nested links."
2266 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2270 (ert-deftest test-org
/open-at-point
/radio-target
()
2271 "Test `org-open-at-point' on radio targets."
2273 (org-test-with-temp-text "<<<target>>> <point>target"
2274 (org-update-radio-target-regexp)
2276 (eq (org-element-type (org-element-context)) 'radio-target
))))
2280 (ert-deftest test-org
/store-link
()
2281 "Test `org-store-link' specifications."
2282 ;; On a headline, link to that headline. Use heading as the
2283 ;; description of the link.
2285 (let (org-store-link-props org-stored-links
)
2286 (org-test-with-temp-text-in-file "* H1"
2287 (let ((file (buffer-file-name)))
2288 (equal (format "[[file:%s::*H1][H1]]" file
)
2289 (org-store-link nil
))))))
2290 ;; On a headline, remove any link from description.
2292 (let (org-store-link-props org-stored-links
)
2293 (org-test-with-temp-text-in-file "* [[#l][d]]"
2294 (let ((file (buffer-file-name)))
2295 (equal (format "[[file:%s::*%s][d]]"
2297 (org-link-escape "[[#l][d]]"))
2298 (org-store-link nil
))))))
2300 (let (org-store-link-props org-stored-links
)
2301 (org-test-with-temp-text-in-file "* [[l]]"
2302 (let ((file (buffer-file-name)))
2303 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2304 (org-store-link nil
))))))
2306 (let (org-store-link-props org-stored-links
)
2307 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2308 (let ((file (buffer-file-name)))
2309 (equal (format "[[file:%s::*%s][d1 d2]]"
2311 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2312 (org-store-link nil
))))))
2313 ;; On a named element, link to that element.
2315 (let (org-store-link-props org-stored-links
)
2316 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2317 (let ((file (buffer-file-name)))
2318 (equal (format "[[file:%s::foo][foo]]" file
)
2319 (org-store-link nil
)))))))
2324 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2325 "Ensure properties accumulate in subtree drawers."
2326 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2327 (org-babel-next-src-block)
2328 (should (equal '(2 1) (org-babel-execute-src-block)))))
2330 (ert-deftest test-org
/custom-properties
()
2331 "Test custom properties specifications."
2334 (let ((org-custom-properties '("FOO")))
2335 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2336 (org-toggle-custom-properties-visibility)
2337 (org-invisible-p2))))
2338 ;; Properties are case-insensitive.
2340 (let ((org-custom-properties '("FOO")))
2341 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2342 (org-toggle-custom-properties-visibility)
2343 (org-invisible-p2))))
2345 (let ((org-custom-properties '("foo")))
2346 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2347 (org-toggle-custom-properties-visibility)
2348 (org-invisible-p2))))
2349 ;; Multiple custom properties in the same drawer.
2351 (let ((org-custom-properties '("FOO" "BAR")))
2352 (org-test-with-temp-text
2353 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2354 (org-toggle-custom-properties-visibility)
2355 (and (org-invisible-p2)
2356 (not (progn (forward-line) (org-invisible-p2)))
2357 (progn (forward-line) (org-invisible-p2))))))
2358 ;; Hide custom properties with an empty value.
2360 (let ((org-custom-properties '("FOO")))
2361 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2362 (org-toggle-custom-properties-visibility)
2363 (org-invisible-p2))))
2364 ;; Do not hide fake properties.
2366 (let ((org-custom-properties '("FOO")))
2367 (org-test-with-temp-text ":FOO: val\n"
2368 (org-toggle-custom-properties-visibility)
2369 (org-invisible-p2))))
2371 (let ((org-custom-properties '("A")))
2372 (org-test-with-temp-text
2373 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2374 (org-toggle-custom-properties-visibility)
2375 (org-invisible-p2)))))
2381 (ert-deftest test-org
/mark-subtree
()
2382 "Test `org-mark-subtree' specifications."
2383 ;; Error when point is before first headline.
2385 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2386 (progn (transient-mark-mode 1)
2387 (org-mark-subtree))))
2388 ;; Without argument, mark current subtree.
2392 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2393 (progn (transient-mark-mode 1)
2396 (list (region-beginning) (region-end))))))
2397 ;; With an argument, move ARG up.
2401 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2402 (progn (transient-mark-mode 1)
2404 (org-mark-subtree 1)
2405 (list (region-beginning) (region-end))))))
2406 ;; Do not get fooled by inlinetasks.
2407 (when (featurep 'org-inlinetask
)
2410 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2411 (progn (transient-mark-mode 1)
2413 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2414 (region-beginning)))))))
2420 (ert-deftest test-org
/in-regexp
()
2421 "Test `org-in-regexp' specifications."
2424 (org-test-with-temp-text "xx ab<point>c xx"
2425 (org-in-regexp "abc")))
2427 (org-test-with-temp-text "xx abc <point>xx"
2428 (org-in-regexp "abc")))
2429 ;; Return non-nil even with multiple matching regexps in the same
2432 (org-test-with-temp-text "abc xx ab<point>c xx"
2433 (org-in-regexp "abc")))
2434 ;; With optional argument NLINES, check extra lines around point.
2436 (org-test-with-temp-text "A\nB<point>\nC"
2437 (org-in-regexp "A\nB\nC")))
2439 (org-test-with-temp-text "A\nB<point>\nC"
2440 (org-in-regexp "A\nB\nC" 1)))
2442 (org-test-with-temp-text "A\nB\nC<point>"
2443 (org-in-regexp "A\nB\nC" 1)))
2444 ;; When optional argument VISUALLY is non-nil, return nil if at
2445 ;; regexp boundaries.
2447 (org-test-with-temp-text "xx abc<point> xx"
2448 (org-in-regexp "abc")))
2450 (org-test-with-temp-text "xx abc<point> xx"
2451 (org-in-regexp "abc" nil t
))))
2456 (ert-deftest test-org
/end-of-meta-data
()
2457 "Test `org-end-of-meta-data' specifications."
2458 ;; Skip planning line.
2460 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2461 (org-end-of-meta-data)
2463 ;; Skip properties drawer.
2465 (org-test-with-temp-text
2466 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2467 (org-end-of-meta-data)
2471 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2472 (org-end-of-meta-data)
2474 ;; Nothing to skip, go to first line.
2476 (org-test-with-temp-text "* Headline\nContents"
2477 (org-end-of-meta-data)
2478 (looking-at "Contents")))
2479 ;; With option argument, skip empty lines, regular drawers and
2482 (org-test-with-temp-text "* Headline\n\nContents"
2483 (org-end-of-meta-data t
)
2484 (looking-at "Contents")))
2486 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2487 (org-end-of-meta-data t
)
2488 (looking-at "Contents")))
2490 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2491 (org-end-of-meta-data t
)
2492 (looking-at "Contents")))
2493 ;; Special case: do not skip incomplete drawers.
2495 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2496 (org-end-of-meta-data t
)
2497 (looking-at ":LOGBOOK:")))
2498 ;; Special case: Be careful about consecutive headlines.
2500 (org-test-with-temp-text "* H1\n*H2\nContents"
2501 (org-end-of-meta-data t
)
2502 (looking-at "Contents"))))
2504 (ert-deftest test-org
/beginning-of-line
()
2505 "Test `org-beginning-of-line' specifications."
2506 ;; Move to beginning of line. If current line in invisible, move to
2507 ;; beginning of visible line instead.
2509 (org-test-with-temp-text "Some text\nSome other text<point>"
2510 (org-beginning-of-line)
2513 (org-test-with-temp-text "* H1\n** H2<point>"
2515 (org-beginning-of-line)
2516 (= (line-beginning-position) 1)))
2517 ;; With `visual-line-mode' active, move to beginning of visual line.
2519 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2521 (dotimes (i 1000) (insert "very "))
2522 (org-beginning-of-line)
2524 ;; In a wide headline, with `visual-line-mode', prefer going to the
2525 ;; beginning of a visual line than to the logical beginning of line,
2526 ;; even if special movement is active.
2528 (org-test-with-temp-text "* A <point>long headline"
2530 (dotimes (i 1000) (insert "very "))
2531 (goto-char (point-max))
2532 (org-beginning-of-line)
2535 (org-test-with-temp-text "* A <point>long headline"
2537 (dotimes (i 1000) (insert "very "))
2538 (goto-char (point-max))
2539 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2541 ;; At an headline with special movement, first move at beginning of
2542 ;; title, then at the beginning of line, rinse, repeat.
2544 (org-test-with-temp-text "* TODO Headline<point>"
2545 (let ((org-special-ctrl-a/e t
))
2546 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2547 (progn (org-beginning-of-line) (bolp))
2548 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2550 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2551 (let ((org-special-ctrl-a/e t
))
2552 (org-beginning-of-line)
2553 (looking-at "Headline"))))
2555 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2556 (let ((org-special-ctrl-a/e
'(t . nil
)))
2557 (org-beginning-of-line)
2558 (looking-at "Headline"))))
2560 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2561 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2562 (org-beginning-of-line)
2563 (looking-at "Headline"))))
2564 ;; At an headline with reversed movement, first move to beginning of
2565 ;; line, then to the beginning of title.
2567 (org-test-with-temp-text "* TODO Headline<point>"
2568 (let ((org-special-ctrl-a/e
'reversed
)
2569 (this-command last-command
))
2570 (and (progn (org-beginning-of-line) (bolp))
2571 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2573 (org-test-with-temp-text "* TODO Headline<point>"
2574 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2575 (this-command last-command
))
2576 (and (progn (org-beginning-of-line) (bolp))
2577 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2579 (org-test-with-temp-text "* TODO Headline<point>"
2580 (let ((org-special-ctrl-a/e
'(t . nil
))
2581 (this-command last-command
))
2582 (and (progn (org-beginning-of-line) (bolp))
2583 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2584 ;; At an item with special movement, first move after to beginning
2585 ;; of title, then to the beginning of line, rinse, repeat.
2587 (org-test-with-temp-text "- [ ] Item<point>"
2588 (let ((org-special-ctrl-a/e t
))
2589 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2590 (progn (org-beginning-of-line) (bolp))
2591 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2592 ;; At an item with reversed movement, first move to beginning of
2593 ;; line, then to the beginning of title.
2595 (org-test-with-temp-text "- [X] Item<point>"
2596 (let ((org-special-ctrl-a/e
'reversed
)
2597 (this-command last-command
))
2598 (and (progn (org-beginning-of-line) (bolp))
2599 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2600 ;; Leave point before invisible characters at column 0.
2602 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2603 (let ((org-special-ctrl-a/e nil
))
2604 (org-beginning-of-line)
2607 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2608 (let ((org-special-ctrl-a/e t
))
2609 (org-beginning-of-line)
2612 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2614 (org-beginning-of-line)
2616 ;; Special case: Do not error when the buffer contains only a single
2619 (org-test-with-temp-text "*<point>"
2620 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
2622 (org-test-with-temp-text "*<point>"
2623 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
2625 (ert-deftest test-org
/end-of-line
()
2626 "Test `org-end-of-line' specifications."
2629 (org-test-with-temp-text "Some text\nSome other text"
2632 ;; With `visual-line-mode' active, move to end of visible line.
2633 ;; However, never go past ellipsis.
2635 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2637 (dotimes (i 1000) (insert "very "))
2638 (goto-char (point-min))
2642 (org-test-with-temp-text "* A short headline\nSome contents"
2647 ;; In a wide headline, with `visual-line-mode', prefer going to end
2648 ;; of visible line if tags, or end of line, are farther.
2650 (org-test-with-temp-text "* A <point>long headline"
2652 (dotimes (i 1000) (insert "very "))
2653 (goto-char (point-min))
2657 (org-test-with-temp-text "* A <point>long headline :tag:"
2659 (dotimes (i 1000) (insert "very "))
2660 (goto-char (point-min))
2663 ;; At an headline without special movement, go to end of line.
2664 ;; However, never go past ellipsis.
2666 (org-test-with-temp-text "* Headline2b :tag:\n"
2667 (let ((org-special-ctrl-a/e nil
))
2668 (and (progn (org-end-of-line) (eolp))
2669 (progn (org-end-of-line) (eolp))))))
2671 (org-test-with-temp-text "* Headline2b :tag:\n"
2672 (let ((org-special-ctrl-a/e
'(t . nil
)))
2673 (and (progn (org-end-of-line) (eolp))
2674 (progn (org-end-of-line) (eolp))))))
2676 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2678 (let ((org-special-ctrl-a/e nil
))
2680 (= 1 (line-beginning-position)))))
2681 ;; At an headline with special movement, first move before tags,
2682 ;; then at the end of line, rinse, repeat. However, never go past
2685 (org-test-with-temp-text "* Headline1 :tag:\n"
2686 (let ((org-special-ctrl-a/e t
))
2687 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2688 (progn (org-end-of-line) (eolp))
2689 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2691 (org-test-with-temp-text "* Headline1 :tag:\n"
2692 (let ((org-special-ctrl-a/e
'(nil . t
)))
2693 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2694 (progn (org-end-of-line) (eolp))
2695 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2697 (org-test-with-temp-text "* Headline1 :tag:\n"
2698 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2699 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2700 (progn (org-end-of-line) (eolp))
2701 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2703 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2705 (let ((org-special-ctrl-a/e t
))
2708 (= 1 (line-beginning-position)))))
2709 ;; At an headline, with reversed movement, first go to end of line,
2710 ;; then before tags. However, never go past ellipsis.
2712 (org-test-with-temp-text "* Headline3 :tag:\n"
2713 (let ((org-special-ctrl-a/e
'reversed
)
2714 (this-command last-command
))
2715 (and (progn (org-end-of-line) (eolp))
2716 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2718 (org-test-with-temp-text "* Headline3 :tag:\n"
2719 (let ((org-special-ctrl-a/e
'(nil . reversed
))
2720 (this-command last-command
))
2721 (and (progn (org-end-of-line) (eolp))
2722 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2724 (org-test-with-temp-text "* Headline3 :tag:\n"
2725 (let ((org-special-ctrl-a/e
'(nil . t
))
2726 (this-command last-command
))
2727 (and (progn (org-end-of-line) (eolp))
2728 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2730 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2732 (let ((org-special-ctrl-a/e
'reversed
))
2734 (= 1 (line-beginning-position)))))
2735 ;; At a block without hidden contents.
2737 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2738 (progn (org-end-of-line) (eolp))))
2739 ;; At a block with hidden contents.
2741 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2742 (let ((org-special-ctrl-a/e t
))
2743 (org-hide-block-toggle)
2746 ;; Get past invisible characters at the end of line.
2748 (org-test-with-temp-text "[[http://orgmode.org]]"
2752 (ert-deftest test-org
/open-line
()
2753 "Test `org-open-line' specifications."
2754 ;; Call `open-line' outside of tables.
2757 (org-test-with-temp-text "Text"
2760 ;; At a table, create a row above.
2762 (equal "\n| |\n| a |"
2763 (org-test-with-temp-text "\n<point>| a |"
2766 ;; At the very first character of the buffer, also call `open-line'.
2769 (org-test-with-temp-text "| a |"
2772 ;; Narrowing does not count.
2774 (equal "Text\n| |\n| a |"
2775 (org-test-with-temp-text "Text\n<point>| a |"
2776 (narrow-to-region (point) (point-max))
2781 (ert-deftest test-org
/forward-sentence
()
2782 "Test `org-forward-sentence' specifications."
2783 ;; At the end of a table cell, move to the end of the next one.
2785 (org-test-with-temp-text "| a<point> | b |"
2786 (org-forward-sentence)
2787 (looking-at " |$")))
2788 ;; Elsewhere in a cell, move to its end.
2790 (org-test-with-temp-text "| a<point>c | b |"
2791 (org-forward-sentence)
2792 (looking-at " | b |$")))
2793 ;; Otherwise, simply call `forward-sentence'.
2795 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2796 (org-forward-sentence)
2797 (looking-at " Sentence 2.")))
2799 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2800 (org-forward-sentence)
2801 (org-forward-sentence)
2803 ;; At the end of an element, jump to the next one, without stopping
2804 ;; on blank lines in-between.
2806 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2807 (org-forward-sentence)
2810 (ert-deftest test-org
/backward-sentence
()
2811 "Test `org-backward-sentence' specifications."
2812 ;; At the beginning of a table cell, move to the beginning of the
2815 (org-test-with-temp-text "| a | <point>b |"
2816 (org-backward-sentence)
2817 (looking-at "a | b |$")))
2818 ;; Elsewhere in a cell, move to its beginning.
2820 (org-test-with-temp-text "| a | b<point>c |"
2821 (org-backward-sentence)
2822 (looking-at "bc |$")))
2823 ;; Otherwise, simply call `backward-sentence'.
2825 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2826 (org-backward-sentence)
2827 (looking-at "Sentence 2.")))
2829 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2830 (org-backward-sentence)
2831 (org-backward-sentence)
2833 ;; Make sure to hit the beginning of a sentence on the same line as
2836 (org-test-with-temp-text "- Line 1\n line <point>2."
2837 (org-backward-sentence)
2838 (looking-at "Line 1"))))
2840 (ert-deftest test-org
/forward-paragraph
()
2841 "Test `org-forward-paragraph' specifications."
2842 ;; At end of buffer, return an error.
2844 (org-test-with-temp-text "Paragraph"
2845 (goto-char (point-max))
2846 (org-forward-paragraph)))
2849 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2850 (org-forward-paragraph)
2854 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2855 (org-forward-paragraph)
2857 ;; Do not enter elements with invisible contents.
2859 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2860 (org-hide-block-toggle)
2861 (org-forward-paragraph)
2863 ;; On an affiliated keyword, jump to the beginning of the element.
2865 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2866 (org-forward-paragraph)
2867 (looking-at "Para")))
2868 ;; On an item or a footnote definition, move to the second element
2871 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2872 (org-forward-paragraph)
2873 (looking-at " Paragraph")))
2875 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2876 (org-forward-paragraph)
2877 (looking-at "Paragraph")))
2878 ;; On an item, or a footnote definition, when the first line is
2879 ;; empty, move to the first item.
2881 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2882 (org-forward-paragraph)
2883 (looking-at " Paragraph")))
2885 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2886 (org-forward-paragraph)
2887 (looking-at "Paragraph")))
2888 ;; On a table (resp. a property drawer) do not move through table
2889 ;; rows (resp. node properties).
2891 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2892 (org-forward-paragraph)
2893 (looking-at "Paragraph")))
2895 (org-test-with-temp-text
2896 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2897 (org-forward-paragraph)
2898 (looking-at "Paragraph")))
2899 ;; On a verse or source block, stop after blank lines.
2901 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2902 (org-forward-paragraph)
2905 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2906 (org-forward-paragraph)
2907 (looking-at "L2"))))
2909 (ert-deftest test-org
/backward-paragraph
()
2910 "Test `org-backward-paragraph' specifications."
2911 ;; Error at beginning of buffer.
2913 (org-test-with-temp-text "Paragraph"
2914 (org-backward-paragraph)))
2917 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2918 (goto-char (point-max))
2919 (org-backward-paragraph)
2922 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2923 (goto-char (point-max))
2925 (org-backward-paragraph)
2929 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
2930 (goto-char (point-max))
2932 (org-backward-paragraph)
2934 ;; Ignore invisible elements.
2936 (org-test-with-temp-text "* H1\n P1\n* H2"
2938 (goto-char (point-max))
2940 (org-backward-paragraph)
2942 ;; On an affiliated keyword, jump to the first one.
2944 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
2945 (search-forward "c2")
2946 (org-backward-paragraph)
2947 (looking-at "#\\+name")))
2948 ;; On the second element in an item or a footnote definition, jump
2949 ;; to item or the definition.
2951 (org-test-with-temp-text "- line1\n\n line2"
2952 (goto-char (point-max))
2954 (org-backward-paragraph)
2955 (looking-at "- line1")))
2957 (org-test-with-temp-text "[fn:1] line1\n\n line2"
2958 (goto-char (point-max))
2960 (org-backward-paragraph)
2961 (looking-at "\\[fn:1\\] line1")))
2962 ;; On a table (resp. a property drawer), ignore table rows
2963 ;; (resp. node properties).
2965 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
2966 (goto-char (point-max))
2968 (org-backward-paragraph)
2971 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
2972 (org-backward-paragraph)
2973 (looking-at ":PROPERTIES:")))
2974 ;; On a source or verse block, stop before blank lines.
2976 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
2977 (search-forward "L3")
2979 (org-backward-paragraph)
2982 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
2983 (search-forward "L3")
2985 (org-backward-paragraph)
2986 (looking-at "L2"))))
2988 (ert-deftest test-org
/forward-element
()
2989 "Test `org-forward-element' specifications."
2990 ;; 1. At EOB: should error.
2991 (org-test-with-temp-text "Some text\n"
2992 (goto-char (point-max))
2993 (should-error (org-forward-element)))
2994 ;; 2. Standard move: expected to ignore blank lines.
2995 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
2996 (org-forward-element)
2997 (should (looking-at (regexp-quote "Second paragraph."))))
2998 ;; 3. Headline tests.
2999 (org-test-with-temp-text "
3004 ;; 3.1. At an headline beginning: move to next headline at the
3007 (org-forward-element)
3008 (should (looking-at (regexp-quote "** Head 1.2")))
3009 ;; 3.2. At an headline beginning: move to parent headline if no
3010 ;; headline at the same level.
3012 (org-forward-element)
3013 (should (looking-at (regexp-quote "** Head 1.2"))))
3014 ;; 4. Greater element tests.
3015 (org-test-with-temp-text
3016 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3017 ;; 4.1. At a greater element: expected to skip contents.
3018 (org-forward-element)
3019 (should (looking-at (regexp-quote "Outside.")))
3020 ;; 4.2. At the end of greater element contents: expected to skip
3021 ;; to the end of the greater element.
3023 (org-forward-element)
3024 (should (looking-at (regexp-quote "Outside."))))
3026 (org-test-with-temp-text "
3040 ;; 5.1. At list top point: expected to move to the element after
3043 (org-forward-element)
3044 (should (looking-at (regexp-quote "Outside.")))
3045 ;; 5.2. Special case: at the first line of a sub-list, but not at
3046 ;; beginning of line, move to next item.
3049 (org-forward-element)
3050 (should (looking-at "- item2"))
3053 (org-forward-element)
3054 (should (looking-at " - sub2"))
3055 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3057 (org-forward-element)
3058 (should (looking-at (regexp-quote " Inner paragraph.")))
3059 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3061 (org-forward-element)
3062 (should (looking-at (regexp-quote " Inner paragraph.")))
3063 ;; 5.5. At an item: expected to move to next item, if any.
3065 (org-forward-element)
3066 (should (looking-at " - sub3"))))
3068 (ert-deftest test-org
/backward-element
()
3069 "Test `org-backward-element' specifications."
3070 ;; 1. Should error at BOB.
3071 (org-test-with-temp-text " \nParagraph."
3072 (should-error (org-backward-element)))
3073 ;; 2. Should move at BOB when called on the first element in buffer.
3075 (org-test-with-temp-text "\n#+TITLE: test"
3076 (progn (forward-line)
3077 (org-backward-element)
3079 ;; 3. Not at the beginning of an element: move at its beginning.
3080 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3083 (org-backward-element)
3084 (should (looking-at (regexp-quote "Paragraph2."))))
3085 ;; 4. Headline tests.
3086 (org-test-with-temp-text "
3091 ;; 4.1. At an headline beginning: move to previous headline at the
3094 (org-backward-element)
3095 (should (looking-at (regexp-quote "** Head 1.1")))
3096 ;; 4.2. At an headline beginning: move to parent headline if no
3097 ;; headline at the same level.
3099 (org-backward-element)
3100 (should (looking-at (regexp-quote "* Head 1")))
3101 ;; 4.3. At the first top-level headline: should error.
3103 (should-error (org-backward-element)))
3104 ;; 5. At beginning of first element inside a greater element:
3105 ;; expected to move to greater element's beginning.
3106 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3108 (org-backward-element)
3109 (should (looking-at "#\\+BEGIN_CENTER")))
3110 ;; 6. At the beginning of the first element in a section: should
3111 ;; move back to headline, if any.
3113 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3114 (progn (goto-char (point-max))
3116 (org-backward-element)
3117 (org-at-heading-p))))
3119 (org-test-with-temp-text "
3134 ;; 7.1. At beginning of sub-list: expected to move to the
3135 ;; paragraph before it.
3137 (org-backward-element)
3138 (should (looking-at "item1"))
3139 ;; 7.2. At an item in a list: expected to move at previous item.
3141 (org-backward-element)
3142 (should (looking-at " - sub2"))
3144 (org-backward-element)
3145 (should (looking-at "- item1"))
3146 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3149 (org-backward-element)
3150 (should (looking-at " - sub1"))
3152 (org-backward-element)
3153 (should (looking-at "- item1"))
3154 ;; 7.4. At blank-lines before list end: expected to move to top
3157 (org-backward-element)
3158 (should (looking-at "- item1"))))
3160 (ert-deftest test-org
/up-element
()
3161 "Test `org-up-element' specifications."
3162 ;; 1. At BOB or with no surrounding element: should error.
3163 (org-test-with-temp-text "Paragraph."
3164 (should-error (org-up-element)))
3165 (org-test-with-temp-text "* Head1\n* Head2"
3167 (should-error (org-up-element)))
3168 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3170 (should-error (org-up-element)))
3171 ;; 2. At an headline: move to parent headline.
3172 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3175 (should (looking-at "\\* Head1")))
3176 ;; 3. Inside a greater element: move to greater element beginning.
3177 (org-test-with-temp-text
3178 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3181 (should (looking-at "#\\+BEGIN_CENTER")))
3183 (org-test-with-temp-text "* Top
3190 Paragraph within sub2.
3193 ;; 4.1. Within an item: move to the item beginning.
3196 (should (looking-at " - sub2"))
3197 ;; 4.2. At an item in a sub-list: move to parent item.
3200 (should (looking-at "- item1"))
3201 ;; 4.3. At an item in top list: move to beginning of whole list.
3204 (should (looking-at "- item1"))
3205 ;; 4.4. Special case. At very top point: should move to parent of
3209 (should (looking-at "\\* Top"))))
3211 (ert-deftest test-org
/down-element
()
3212 "Test `org-down-element' specifications."
3213 ;; Error when the element hasn't got a recursive type.
3214 (org-test-with-temp-text "Paragraph."
3215 (should-error (org-down-element)))
3216 ;; Error when the element has no contents
3217 (org-test-with-temp-text "* Headline"
3218 (should-error (org-down-element)))
3219 ;; When at a plain-list, move to first item.
3220 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3223 (should (looking-at " - Item 1.1")))
3224 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3226 (should (looking-at " Item 1")))
3227 ;; When at a table, move to first row
3228 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3230 (should (looking-at " a | b |")))
3231 ;; Otherwise, move inside the greater element.
3232 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3234 (should (looking-at "Paragraph"))))
3236 (ert-deftest test-org
/drag-element-backward
()
3237 "Test `org-drag-element-backward' specifications."
3241 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3242 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3243 (org-drag-element-backward)
3247 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3248 (org-test-with-temp-text
3249 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3250 (org-drag-element-backward)
3252 ;; Preserve blank lines.
3254 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3255 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3256 (org-drag-element-backward)
3260 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3261 (org-drag-element-backward)
3262 (looking-at-p "2")))
3263 ;; Error when trying to move first element of buffer.
3265 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3266 (org-drag-element-backward))
3268 ;; Error when trying to swap nested elements.
3270 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3271 (org-drag-element-backward))
3273 ;; Error when trying to swap an headline element and a non-headline
3276 (org-test-with-temp-text "Test.\n<point>* Head 1"
3277 (org-drag-element-backward))
3279 ;; Error when called before first element.
3281 (org-test-with-temp-text "\n<point>"
3282 (org-drag-element-backward))
3284 ;; Preserve visibility of elements and their contents.
3286 (equal '((63 .
82) (26 .
48))
3287 (org-test-with-temp-text "
3295 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3296 (search-backward "- item 1")
3297 (org-drag-element-backward)
3298 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3299 (overlays-in (point-min) (point-max))))))
3300 ;; Pathological case: handle call with point in blank lines right
3301 ;; after a headline.
3303 (equal "* H2\n* H1\nText\n\n"
3304 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3305 (org-drag-element-backward)
3308 (ert-deftest test-org
/drag-element-forward
()
3309 "Test `org-drag-element-forward' specifications."
3310 ;; 1. Error when trying to move first element of buffer.
3311 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3313 (should-error (org-drag-element-forward)))
3314 ;; 2. Error when trying to swap nested elements.
3315 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3317 (should-error (org-drag-element-forward)))
3318 ;; 3. Error when trying to swap a non-headline element and an
3320 (org-test-with-temp-text "Test.\n* Head 1"
3321 (should-error (org-drag-element-forward)))
3322 ;; 4. Error when called before first element.
3324 (org-test-with-temp-text "\n"
3326 (org-drag-element-backward))
3328 ;; 5. Otherwise, swap elements, preserving column and blank lines
3329 ;; between elements.
3330 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3331 (search-forward "graph")
3332 (org-drag-element-forward)
3333 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3334 (should (looking-at " 1")))
3335 ;; 5. Preserve visibility of elements and their contents.
3336 (org-test-with-temp-text "
3344 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3345 (search-backward "#+BEGIN_CENTER")
3346 (org-drag-element-forward)
3349 '((63 .
82) (26 .
48))
3350 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3351 (overlays-in (point-min) (point-max)))))))
3353 (ert-deftest test-org
/next-block
()
3354 "Test `org-next-block' specifications."
3357 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3359 (looking-at "#\\+BEGIN_CENTER")))
3362 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3363 (let ((case-fold-search nil
))
3365 (looking-at "#\\+begin_center"))))
3366 ;; Ignore current line.
3368 (org-test-with-temp-text
3369 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3371 (looking-at "#\\+BEGIN_CENTER")))
3372 ;; Throw an error when no block is found.
3374 (org-test-with-temp-text "Paragraph"
3375 (org-next-block 1)))
3376 ;; With an argument, skip many blocks at once.
3378 (org-test-with-temp-text
3379 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3381 (looking-at "#\\+BEGIN_QUOTE")))
3382 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3384 (org-test-with-temp-text
3385 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3386 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3387 (looking-at "#\\+BEGIN_QUOTE")))
3388 ;; Optional argument is also case-insensitive.
3390 (org-test-with-temp-text
3391 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3392 (let ((case-fold-search nil
))
3393 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3394 (looking-at "#\\+begin_quote")))))
3396 (ert-deftest test-org
/previous-block
()
3397 "Test `org-previous-block' specifications."
3400 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3401 (org-previous-block 1)
3402 (looking-at "#\\+BEGIN_CENTER")))
3405 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3406 (let ((case-fold-search nil
))
3407 (org-previous-block 1)
3408 (looking-at "#\\+begin_center"))))
3409 ;; Ignore current line.
3411 (org-test-with-temp-text
3412 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3413 (org-previous-block 1)
3414 (looking-at "#\\+BEGIN_QUOTE")))
3415 ;; Throw an error when no block is found.
3417 (org-test-with-temp-text "Paragraph<point>"
3418 (org-previous-block 1)))
3419 ;; With an argument, skip many blocks at once.
3421 (org-test-with-temp-text
3422 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3423 (org-previous-block 2)
3424 (looking-at "#\\+BEGIN_CENTER")))
3425 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3427 (org-test-with-temp-text
3428 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3429 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3430 (looking-at "#\\+BEGIN_QUOTE")))
3431 ;; Optional argument is also case-insensitive.
3433 (org-test-with-temp-text
3434 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3435 (let ((case-fold-search nil
))
3436 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3437 (looking-at "#\\+begin_quote")))))
3440 ;;; Outline structure
3442 (ert-deftest test-org
/demote
()
3443 "Test `org-demote' specifications."
3444 ;; Add correct number of stars according to `org-odd-levels-only'.
3447 (org-test-with-temp-text "* H"
3448 (let ((org-odd-levels-only nil
)) (org-demote))
3449 (org-current-level))))
3452 (org-test-with-temp-text "* H"
3453 (let ((org-odd-levels-only t
)) (org-demote))
3454 (org-current-level))))
3455 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3457 (org-test-with-temp-text "* H :tag:"
3458 (let ((org-tags-column 10)
3459 (org-auto-align-tags t
)
3460 (org-odd-levels-only nil
))
3462 (org-move-to-column 10)
3463 (looking-at-p ":tag:$")))
3465 (org-test-with-temp-text "* H :tag:"
3466 (let ((org-tags-column 10)
3467 (org-auto-align-tags nil
)
3468 (org-odd-levels-only nil
))
3470 (org-move-to-column 10)
3471 (looking-at-p ":tag:$")))
3472 ;; When `org-adapt-indentation' is non-nil, always indent planning
3473 ;; info and property drawers accordingly.
3476 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3477 (let ((org-odd-levels-only nil
)
3478 (org-adapt-indentation t
))
3481 (org-get-indentation))))
3484 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3485 (let ((org-odd-levels-only nil
)
3486 (org-adapt-indentation t
))
3489 (org-get-indentation))))
3492 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3493 (let ((org-odd-levels-only nil
)
3494 (org-adapt-indentation nil
))
3497 (org-get-indentation))))
3498 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3499 ;; section accordingly. Ignore, however, footnote definitions and
3500 ;; inlinetasks boundaries.
3503 (org-test-with-temp-text "* H\n Paragraph"
3504 (let ((org-odd-levels-only nil
)
3505 (org-adapt-indentation t
))
3508 (org-get-indentation))))
3511 (org-test-with-temp-text "* H\n Paragraph"
3512 (let ((org-odd-levels-only nil
)
3513 (org-adapt-indentation nil
))
3516 (org-get-indentation))))
3519 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3520 (let ((org-odd-levels-only nil
)
3521 (org-adapt-indentation t
))
3523 (goto-char (point-max))
3524 (org-get-indentation))))
3527 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3528 (let ((org-odd-levels-only nil
)
3529 (org-adapt-indentation t
))
3531 (goto-char (point-max))
3532 (org-get-indentation))))
3533 (when (featurep 'org-inlinetask
)
3536 (let ((org-inlinetask-min-level 5)
3537 (org-adapt-indentation t
))
3538 (org-test-with-temp-text "* H\n***** I\n***** END"
3541 (org-get-indentation))))))
3542 (when (featurep 'org-inlinetask
)
3545 (let ((org-inlinetask-min-level 5)
3546 (org-adapt-indentation t
))
3547 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3550 (org-get-indentation))))))
3551 ;; Ignore contents of source blocks or example blocks when
3552 ;; indentation should be preserved (through
3553 ;; `org-src-preserve-indentation' or "-i" flag).
3556 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3557 (let ((org-adapt-indentation t
)
3558 (org-src-preserve-indentation nil
))
3561 (org-get-indentation))))
3564 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3565 (let ((org-adapt-indentation t
)
3566 (org-src-preserve-indentation t
))
3569 (org-get-indentation))))
3572 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3573 (let ((org-adapt-indentation t
)
3574 (org-src-preserve-indentation t
))
3577 (org-get-indentation))))
3580 (org-test-with-temp-text
3581 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3582 (let ((org-adapt-indentation t
)
3583 (org-src-preserve-indentation nil
))
3586 (org-get-indentation)))))
3588 (ert-deftest test-org
/promote
()
3589 "Test `org-promote' specifications."
3590 ;; Return an error if headline is to be promoted to level 0, unless
3591 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3592 ;; headline becomes a comment.
3594 (org-test-with-temp-text "* H"
3595 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
3598 (org-test-with-temp-text "* H"
3599 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
3601 ;; Remove correct number of stars according to
3602 ;; `org-odd-levels-only'.
3605 (org-test-with-temp-text "*** H"
3606 (let ((org-odd-levels-only nil
)) (org-promote))
3607 (org-current-level))))
3610 (org-test-with-temp-text "*** H"
3611 (let ((org-odd-levels-only t
)) (org-promote))
3612 (org-current-level))))
3613 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3615 (org-test-with-temp-text "** H :tag:"
3616 (let ((org-tags-column 10)
3617 (org-auto-align-tags t
)
3618 (org-odd-levels-only nil
))
3620 (org-move-to-column 10)
3621 (looking-at-p ":tag:$")))
3623 (org-test-with-temp-text "** H :tag:"
3624 (let ((org-tags-column 10)
3625 (org-auto-align-tags nil
)
3626 (org-odd-levels-only nil
))
3628 (org-move-to-column 10)
3629 (looking-at-p ":tag:$")))
3630 ;; When `org-adapt-indentation' is non-nil, always indent planning
3631 ;; info and property drawers.
3634 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3635 (let ((org-odd-levels-only nil
)
3636 (org-adapt-indentation t
))
3639 (org-get-indentation))))
3642 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3643 (let ((org-odd-levels-only nil
)
3644 (org-adapt-indentation t
))
3647 (org-get-indentation))))
3650 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3651 (let ((org-odd-levels-only nil
)
3652 (org-adapt-indentation nil
))
3655 (org-get-indentation))))
3656 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3657 ;; section accordingly. Ignore, however, footnote definitions and
3658 ;; inlinetasks boundaries.
3661 (org-test-with-temp-text "** H\n Paragraph"
3662 (let ((org-odd-levels-only nil
)
3663 (org-adapt-indentation t
))
3666 (org-get-indentation))))
3669 (org-test-with-temp-text "** H\n Paragraph"
3670 (let ((org-odd-levels-only nil
)
3671 (org-adapt-indentation nil
))
3674 (org-get-indentation))))
3677 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3678 (let ((org-odd-levels-only nil
)
3679 (org-adapt-indentation t
))
3682 (org-get-indentation))))
3683 (when (featurep 'org-inlinetask
)
3686 (let ((org-inlinetask-min-level 5)
3687 (org-adapt-indentation t
))
3688 (org-test-with-temp-text "** H\n***** I\n***** END"
3691 (org-get-indentation))))))
3692 (when (featurep 'org-inlinetask
)
3695 (let ((org-inlinetask-min-level 5)
3696 (org-adapt-indentation t
))
3697 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3700 (org-get-indentation))))))
3701 ;; Give up shifting if it would break document's structure
3705 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3706 (let ((org-odd-levels-only nil
)
3707 (org-adapt-indentation t
))
3710 (org-get-indentation))))
3713 (org-test-with-temp-text "** H\n Paragraph\n * list."
3714 (let ((org-odd-levels-only nil
)
3715 (org-adapt-indentation t
))
3718 (org-get-indentation))))
3719 ;; Ignore contents of source blocks or example blocks when
3720 ;; indentation should be preserved (through
3721 ;; `org-src-preserve-indentation' or "-i" flag).
3724 (org-test-with-temp-text
3725 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3726 (let ((org-adapt-indentation t
)
3727 (org-src-preserve-indentation nil
)
3728 (org-odd-levels-only nil
))
3731 (org-get-indentation))))
3734 (org-test-with-temp-text
3735 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3736 (let ((org-adapt-indentation t
)
3737 (org-src-preserve-indentation t
)
3738 (org-odd-levels-only nil
))
3741 (org-get-indentation))))
3744 (org-test-with-temp-text
3745 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3746 (let ((org-adapt-indentation t
)
3747 (org-src-preserve-indentation t
)
3748 (org-odd-levels-only nil
))
3751 (org-get-indentation))))
3754 (org-test-with-temp-text
3755 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3756 (let ((org-adapt-indentation t
)
3757 (org-src-preserve-indentation nil
)
3758 (org-odd-levels-only nil
))
3761 (org-get-indentation)))))
3766 (ert-deftest test-org
/at-planning-p
()
3767 "Test `org-at-planning-p' specifications."
3770 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3771 (org-at-planning-p)))
3773 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3774 (org-at-planning-p)))
3775 ;; Correctly find planning attached to inlinetasks.
3776 (when (featurep 'org-inlinetask
)
3778 (org-test-with-temp-text
3779 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3780 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3782 (org-test-with-temp-text
3783 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3784 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3786 (org-test-with-temp-text
3787 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3788 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3790 (org-test-with-temp-text
3791 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3792 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3794 (ert-deftest test-org
/add-planning-info
()
3795 "Test `org-add-planning-info'."
3796 ;; Create deadline when `org-adapt-indentation' is non-nil.
3798 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3799 (org-test-with-temp-text "* H\nParagraph<point>"
3800 (let ((org-adapt-indentation t
))
3801 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3802 (replace-regexp-in-string
3803 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3805 ;; Create deadline when `org-adapt-indentation' is nil.
3807 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3808 (org-test-with-temp-text "* H\nParagraph<point>"
3809 (let ((org-adapt-indentation nil
))
3810 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3811 (replace-regexp-in-string
3812 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3814 ;; Update deadline when `org-adapt-indentation' is non-nil.
3816 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3817 (org-test-with-temp-text "\
3819 DEADLINE: <2015-06-24 Wed>
3821 (let ((org-adapt-indentation t
))
3822 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3823 (replace-regexp-in-string
3824 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3826 ;; Update deadline when `org-adapt-indentation' is nil.
3828 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3829 (org-test-with-temp-text "\
3831 DEADLINE: <2015-06-24 Wed>
3833 (let ((org-adapt-indentation nil
))
3834 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3835 (replace-regexp-in-string
3836 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3838 ;; Schedule when `org-adapt-indentation' is non-nil.
3840 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3841 (org-test-with-temp-text "* H\nParagraph<point>"
3842 (let ((org-adapt-indentation t
))
3843 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3844 (replace-regexp-in-string
3845 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3847 ;; Schedule when `org-adapt-indentation' is nil.
3849 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3850 (org-test-with-temp-text "* H\nParagraph<point>"
3851 (let ((org-adapt-indentation nil
))
3852 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
3853 (replace-regexp-in-string
3854 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3856 ;; Add deadline when scheduled.
3860 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3862 (org-test-with-temp-text "\
3864 SCHEDULED: <2015-06-24 Wed>
3866 (let ((org-adapt-indentation t
))
3867 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
3868 (replace-regexp-in-string
3869 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3871 ;; Remove middle entry.
3875 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3877 (org-test-with-temp-text "\
3879 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3881 (let ((org-adapt-indentation t
))
3882 (org-add-planning-info nil nil
'deadline
))
3883 (replace-regexp-in-string
3884 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3886 ;; Remove last entry and then middle entry (order should not
3891 CLOSED: [2015-06-24]
3893 (org-test-with-temp-text "\
3895 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3897 (let ((org-adapt-indentation t
))
3898 (org-add-planning-info nil nil
'scheduled
'deadline
))
3899 (replace-regexp-in-string
3900 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3902 ;; Remove closed when `org-adapt-indentation' is non-nil.
3904 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3905 (org-test-with-temp-text "\
3907 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3909 (let ((org-adapt-indentation t
))
3910 (org-add-planning-info nil nil
'closed
))
3911 (replace-regexp-in-string
3912 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3915 (equal "* H\n Paragraph"
3916 (org-test-with-temp-text "\
3918 CLOSED: [2015-06-25 Thu]
3920 (let ((org-adapt-indentation t
))
3921 (org-add-planning-info nil nil
'closed
))
3922 (replace-regexp-in-string
3923 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3925 ;; Remove closed when `org-adapt-indentation' is nil.
3927 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3928 (org-test-with-temp-text "\
3930 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3932 (let ((org-adapt-indentation nil
))
3933 (org-add-planning-info nil nil
'closed
))
3934 (replace-regexp-in-string
3935 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3938 (equal "* H\nParagraph"
3939 (org-test-with-temp-text "\
3941 CLOSED: [2015-06-25 Thu]
3943 (let ((org-adapt-indentation nil
))
3944 (org-add-planning-info nil nil
'closed
))
3945 (replace-regexp-in-string
3946 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3948 ;; Remove closed entry and delete empty line.
3953 (org-test-with-temp-text "\
3955 CLOSED: [2015-06-24 Wed]
3957 (let ((org-adapt-indentation t
))
3958 (org-add-planning-info nil nil
'closed
))
3959 (replace-regexp-in-string
3960 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3962 ;; Remove one entry and update another.
3964 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3965 (org-test-with-temp-text "\
3967 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
3969 (let ((org-adapt-indentation t
))
3970 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
3971 (replace-regexp-in-string
3972 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3978 (ert-deftest test-org
/buffer-property-keys
()
3979 "Test `org-buffer-property-keys' specifications."
3980 ;; Retrieve properties accross siblings.
3983 (org-test-with-temp-text "
3992 (org-buffer-property-keys))))
3993 ;; Retrieve properties accross children.
3996 (org-test-with-temp-text "
4005 (org-buffer-property-keys))))
4006 ;; Retrieve muliple properties in the same drawer.
4009 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4010 (org-buffer-property-keys))))
4011 ;; Ignore extension symbol in property name.
4014 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4015 (org-buffer-property-keys))))
4016 ;; With non-nil COLUMNS, extract property names from columns.
4019 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4020 (org-buffer-property-keys nil nil t
))))
4022 (equal '("A" "B" "COLUMNS")
4023 (org-test-with-temp-text
4024 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4025 (org-buffer-property-keys nil nil t
))))
4026 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4029 (org-test-with-temp-text
4030 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4031 (org-buffer-property-keys nil nil nil t
)))))
4033 (ert-deftest test-org
/property-values
()
4034 "Test `org-property-values' specifications."
4038 (org-test-with-temp-text
4039 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4040 (org-property-values "A"))))
4041 ;; Ignore empty values.
4043 (org-test-with-temp-text
4044 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4045 (org-property-values "A")))
4046 ;; Take into consideration extended values.
4049 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4050 (org-property-values "A")))))
4052 (ert-deftest test-org
/find-property
()
4053 "Test `org-find-property' specifications."
4057 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4058 (org-find-property "prop"))))
4059 ;; Ignore false positives.
4062 (org-test-with-temp-text
4063 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4064 (org-find-property "A"))))
4065 ;; Return first entry found in buffer.
4068 (org-test-with-temp-text
4069 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4070 (org-find-property "A"))))
4071 ;; Only search visible part of the buffer.
4074 (org-test-with-temp-text
4075 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4076 (org-narrow-to-subtree)
4077 (org-find-property "A"))))
4078 ;; With optional argument, only find entries with a specific value.
4080 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4081 (org-find-property "A" "2")))
4084 (org-test-with-temp-text
4085 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4086 (org-find-property "A" "2"))))
4087 ;; Use "nil" for explicit nil values.
4090 (org-test-with-temp-text
4091 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4092 (org-find-property "A" "nil")))))
4094 (ert-deftest test-org
/entry-delete
()
4095 "Test `org-entry-delete' specifications."
4099 " *:PROPERTIES:\n *:B: +2\n *:END:"
4100 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4101 (org-entry-delete (point) "A")
4103 ;; Also remove accumulated properties.
4107 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4108 (org-entry-delete (point) "A")
4110 ;; When last property is removed, remove the property drawer.
4114 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4115 (org-entry-delete (point) "A")
4117 ;; Return a non-nil value when some property was removed.
4119 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4120 (org-entry-delete (point) "A")))
4122 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4123 (org-entry-delete (point) "C"))))
4125 (ert-deftest test-org
/entry-get
()
4126 "Test `org-entry-get' specifications."
4130 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4131 (org-entry-get (point) "A"))))
4135 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4136 (org-entry-get (point) "a"))))
4137 ;; Handle extended values, both before and after base value.
4140 (org-test-with-temp-text
4141 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4142 (org-entry-get (point) "A"))))
4143 ;; Empty values are returned as the empty string.
4146 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4147 (org-entry-get (point) "A"))))
4148 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4149 ;; otherwise, return nil.
4151 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4152 (org-entry-get (point) "A")))
4155 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4156 (org-entry-get (point) "A" nil t
))))
4157 ;; Return nil when no property is found, independently on the
4158 ;; LITERAL-NIL argument.
4160 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4161 (org-entry-get (point) "B")))
4163 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4164 (org-entry-get (point) "B" nil t
)))
4165 ;; Handle inheritance, when allowed. Include extended values and
4166 ;; possibly global values.
4170 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4171 (org-entry-get (point) "A" t
))))
4175 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4176 (let ((org-use-property-inheritance t
))
4177 (org-entry-get (point) "A" 'selective
)))))
4179 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4180 (let ((org-use-property-inheritance nil
))
4181 (org-entry-get (point) "A" 'selective
))))
4185 (org-test-with-temp-text
4186 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4187 (org-entry-get (point-max) "A" t
))))
4190 (org-test-with-temp-text
4191 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4193 (org-entry-get (point-max) "A" t
))))
4196 (org-test-with-temp-text
4197 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4199 (org-entry-get (point-max) "A" t
)))))
4201 (ert-deftest test-org
/entry-properties
()
4202 "Test `org-entry-properties' specifications."
4203 ;; Get "ITEM" property.
4206 (org-test-with-temp-text "* TODO H"
4207 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4210 (org-test-with-temp-text "* TODO H"
4211 (cdr (assoc "ITEM" (org-entry-properties))))))
4212 ;; Get "TODO" property. TODO keywords are case sensitive.
4215 (org-test-with-temp-text "* TODO H"
4216 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4219 (org-test-with-temp-text "* TODO H"
4220 (cdr (assoc "TODO" (org-entry-properties))))))
4222 (org-test-with-temp-text "* H"
4223 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4225 (org-test-with-temp-text "* todo H"
4226 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4227 ;; Get "PRIORITY" property.
4230 (org-test-with-temp-text "* [#A] H"
4231 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4234 (org-test-with-temp-text "* [#A] H"
4235 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4237 (equal (char-to-string org-default-priority
)
4238 (org-test-with-temp-text "* H"
4239 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4240 ;; Get "FILE" property.
4242 (org-test-with-temp-text-in-file "* H\nParagraph"
4243 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4244 (buffer-file-name))))
4246 (org-test-with-temp-text-in-file "* H\nParagraph"
4247 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4248 (buffer-file-name))))
4250 (org-test-with-temp-text "* H\nParagraph"
4251 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4252 ;; Get "TAGS" property.
4254 (equal ":tag1:tag2:"
4255 (org-test-with-temp-text "* H :tag1:tag2:"
4256 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4258 (equal ":tag1:tag2:"
4259 (org-test-with-temp-text "* H :tag1:tag2:"
4260 (cdr (assoc "TAGS" (org-entry-properties))))))
4262 (org-test-with-temp-text "* H"
4263 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4264 ;; Get "ALLTAGS" property.
4266 (equal ":tag1:tag2:"
4267 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4268 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4270 (equal ":tag1:tag2:"
4271 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4272 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4274 (org-test-with-temp-text "* H"
4275 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4276 ;; Get "BLOCKED" property.
4279 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4280 (let ((org-enforce-todo-dependencies t
)
4282 '(org-block-todo-from-children-or-siblings-or-parent)))
4283 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4286 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4287 (let ((org-enforce-todo-dependencies t
)
4289 '(org-block-todo-from-children-or-siblings-or-parent)))
4290 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4291 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4295 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4296 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4300 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4301 (cdr (assoc "CLOSED" (org-entry-properties))))))
4303 (org-test-with-temp-text "* H"
4304 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4308 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4309 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
4313 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4314 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4316 (org-test-with-temp-text "* H"
4317 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
4321 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4322 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
4326 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4327 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4329 (org-test-with-temp-text "* H"
4330 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
4334 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4335 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4338 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4339 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4342 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4343 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4346 (org-test-with-temp-text
4347 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4349 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4350 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
4351 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4353 (equal "<2012-03-29 thu.>"
4354 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4355 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4357 (equal "[2012-03-29 thu.]"
4358 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4359 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4361 (equal "<2012-03-29 thu.>"
4362 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4363 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
4365 (equal "[2014-03-04 tue.]"
4366 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4367 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil
"TIMESTAMP_IA"))))))
4368 ;; Get standard properties.
4371 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4372 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4373 ;; Handle extended properties.
4376 (org-test-with-temp-text
4377 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4378 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4381 (org-test-with-temp-text
4382 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4383 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
4384 ;; Ignore forbidden (special) properties.
4386 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4387 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
4389 (ert-deftest test-org
/entry-put
()
4390 "Test `org-entry-put' specifications."
4391 ;; Error when not a string or nil.
4393 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4394 (org-entry-put 1 "test" 2)))
4395 ;; Error when property name is invalid.
4397 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4398 (org-entry-put 1 "no space" "value")))
4400 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4401 (org-entry-put 1 "" "value")))
4402 ;; Set "TODO" property.
4404 (string-match (regexp-quote " TODO H")
4405 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4406 (org-entry-put (point) "TODO" "TODO")
4409 (string-match (regexp-quote "* H")
4410 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4411 (org-entry-put (point) "TODO" nil
)
4413 ;; Set "PRIORITY" property.
4416 (org-test-with-temp-text "* [#B] H"
4417 (org-entry-put (point) "PRIORITY" "A")
4421 (org-test-with-temp-text "* [#B] H"
4422 (org-entry-put (point) "PRIORITY" nil
)
4424 ;; Set "SCHEDULED" property.
4426 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4427 (org-test-with-temp-text "* H"
4428 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4432 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4433 (org-entry-put (point) "SCHEDULED" nil
)
4436 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4437 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4438 (org-entry-put (point) "SCHEDULED" "earlier")
4441 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4442 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4443 (org-entry-put (point) "SCHEDULED" "later")
4445 ;; Set "DEADLINE" property.
4447 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4448 (org-test-with-temp-text "* H"
4449 (org-entry-put (point) "DEADLINE" "2014-03-04")
4453 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4454 (org-entry-put (point) "DEADLINE" nil
)
4457 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4458 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4459 (org-entry-put (point) "DEADLINE" "earlier")
4462 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4463 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4464 (org-entry-put (point) "DEADLINE" "later")
4466 ;; Set "CATEGORY" property
4468 (string-match "^ *:CATEGORY: cat"
4469 (org-test-with-temp-text "* H"
4470 (org-entry-put (point) "CATEGORY" "cat")
4472 ;; Regular properties, with or without pre-existing drawer.
4474 (string-match "^ *:A: +2$"
4475 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4476 (org-entry-put (point) "A" "2")
4479 (string-match "^ *:A: +1$"
4480 (org-test-with-temp-text "* H"
4481 (org-entry-put (point) "A" "1")
4483 ;; Special case: two consecutive headlines.
4485 (string-match "\\* A\n *:PROPERTIES:"
4486 (org-test-with-temp-text "* A\n** B"
4487 (org-entry-put (point) "A" "1")
4493 (ert-deftest test-org
/update-radio-target-regexp
()
4494 "Test `org-update-radio-target-regexp' specifications."
4495 ;; Properly update cache with no previous radio target regexp.
4498 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4499 (save-excursion (goto-char (point-max)) (org-element-context))
4501 (search-forward "o")
4503 (org-update-radio-target-regexp)
4504 (goto-char (point-max))
4505 (org-element-type (org-element-context)))))
4506 ;; Properly update cache with previous radio target regexp.
4509 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4510 (save-excursion (goto-char (point-max)) (org-element-context))
4512 (search-forward "o")
4514 (org-update-radio-target-regexp)
4515 (search-backward "r")
4518 (org-update-radio-target-regexp)
4519 (goto-char (point-max))
4520 (delete-region (line-beginning-position) (point))
4522 (org-element-type (org-element-context))))))
4527 (ert-deftest test-org
/match-sparse-tree
()
4528 "Test `org-match-sparse-tree' specifications."
4531 (org-test-with-temp-text "* H\n** H1 :tag:"
4532 (org-match-sparse-tree nil
"tag")
4533 (search-forward "H1")
4534 (org-invisible-p2)))
4536 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4537 (org-match-sparse-tree nil
"tag")
4538 (search-forward "H2")
4539 (org-invisible-p2)))
4540 ;; "-" operator for tags.
4542 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4543 (org-match-sparse-tree nil
"tag1-tag2")
4544 (search-forward "H1")
4545 (org-invisible-p2)))
4547 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4548 (org-match-sparse-tree nil
"tag1-tag2")
4549 (search-forward "H2")
4550 (org-invisible-p2)))
4551 ;; "&" operator for tags.
4553 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4554 (org-match-sparse-tree nil
"tag1&tag2")
4555 (search-forward "H1")
4556 (org-invisible-p2)))
4558 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4559 (org-match-sparse-tree nil
"tag1&tag2")
4560 (search-forward "H2")
4561 (org-invisible-p2)))
4562 ;; "|" operator for tags.
4564 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4565 (org-match-sparse-tree nil
"tag1|tag2")
4566 (search-forward "H1")
4567 (org-invisible-p2)))
4569 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4570 (org-match-sparse-tree nil
"tag1|tag2")
4571 (search-forward "H2")
4572 (org-invisible-p2)))
4573 ;; Regexp match on tags.
4575 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4576 (org-match-sparse-tree nil
"{^tag.*}")
4577 (search-forward "H1")
4578 (org-invisible-p2)))
4580 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4581 (org-match-sparse-tree nil
"{^tag.*}")
4582 (search-forward "H2")
4583 (org-invisible-p2)))
4584 ;; Match group tags.
4586 (org-test-with-temp-text
4587 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4588 (org-match-sparse-tree nil
"work")
4589 (search-forward "H1")
4590 (org-invisible-p2)))
4592 (org-test-with-temp-text
4593 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4594 (org-match-sparse-tree nil
"work")
4595 (search-forward "H2")
4596 (org-invisible-p2)))
4597 ;; Match group tags with hard brackets.
4599 (org-test-with-temp-text
4600 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4601 (org-match-sparse-tree nil
"work")
4602 (search-forward "H1")
4603 (org-invisible-p2)))
4605 (org-test-with-temp-text
4606 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4607 (org-match-sparse-tree nil
"work")
4608 (search-forward "H2")
4609 (org-invisible-p2)))
4610 ;; Match tags in hierarchies
4612 (org-test-with-temp-text
4613 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4614 #+TAGS: [ Lev_2 : Lev_3 ]\n
4615 #+TAGS: { Lev_3 : Lev_4 }\n
4616 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
4617 (org-match-sparse-tree nil
"Lev_1")
4618 (search-forward "H4")
4619 (org-invisible-p2)))
4620 ;; Match regular expressions in tags
4622 (org-test-with-temp-text
4623 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
4624 (org-match-sparse-tree nil
"Lev")
4625 (search-forward "H1")
4626 (org-invisible-p2)))
4628 (org-test-with-temp-text
4629 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
4630 (org-match-sparse-tree nil
"Lev")
4631 (search-forward "H1")
4632 (org-invisible-p2)))
4633 ;; Match properties.
4635 (org-test-with-temp-text
4636 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
4637 (org-match-sparse-tree nil
"A=\"1\"")
4638 (search-forward "H2")
4639 (org-invisible-p2)))
4641 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4642 (org-match-sparse-tree nil
"A=\"1\"")
4643 (search-forward "H2")
4644 (org-invisible-p2)))
4645 ;; Case is not significant when matching properties.
4647 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
4648 (org-match-sparse-tree nil
"a=\"1\"")
4649 (search-forward "H2")
4650 (org-invisible-p2)))
4652 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
4653 (org-match-sparse-tree nil
"A=\"1\"")
4654 (search-forward "H2")
4655 (org-invisible-p2)))
4656 ;; Match special LEVEL property.
4658 (org-test-with-temp-text "* H\n** H1\n*** H2"
4659 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4660 (search-forward "H1")
4661 (org-invisible-p2)))
4663 (org-test-with-temp-text "* H\n** H1\n*** H2"
4664 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
4665 (search-forward "H2")
4666 (org-invisible-p2)))
4667 ;; Comparison operators when matching properties.
4669 (org-test-with-temp-text
4670 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4671 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4672 (search-forward "H1")
4673 (org-invisible-p2)))
4675 (org-test-with-temp-text
4676 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
4677 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
4678 (search-forward "H2")
4679 (org-invisible-p2)))
4680 ;; Regexp match on properties values.
4682 (org-test-with-temp-text
4683 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4684 (org-match-sparse-tree nil
"A={f.*}")
4685 (search-forward "H1")
4686 (org-invisible-p2)))
4688 (org-test-with-temp-text
4689 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
4690 (org-match-sparse-tree nil
"A={f.*}")
4691 (search-forward "H2")
4692 (org-invisible-p2)))
4693 ;; With an optional argument, limit match to TODO entries.
4695 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4696 (org-match-sparse-tree t
"tag")
4697 (search-forward "H1")
4698 (org-invisible-p2)))
4700 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
4701 (org-match-sparse-tree t
"tag")
4702 (search-forward "H2")
4703 (org-invisible-p2))))
4705 (ert-deftest test-org
/occur
()
4706 "Test `org-occur' specifications."
4707 ;; Count number of matches.
4710 (org-test-with-temp-text "* H\nA\n* H2"
4714 (org-test-with-temp-text "* H\nA\n* H2\nA"
4716 ;; Test CALLBACK optional argument.
4719 (org-test-with-temp-text "* H\nA\n* H2"
4720 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4723 (org-test-with-temp-text "* H\nA\n* H2\nA"
4724 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
4725 ;; Case-fold searches according to `org-occur-case-fold-search'.
4728 (org-test-with-temp-text "Aa"
4729 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
4732 (org-test-with-temp-text "Aa"
4733 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
4736 (org-test-with-temp-text "Aa"
4737 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
4740 (org-test-with-temp-text "Aa"
4741 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
4744 (org-test-with-temp-text "Aa"
4745 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
4748 (org-test-with-temp-text "Aa"
4749 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
4754 (ert-deftest test-org
/tag-string-to-alist
()
4755 "Test `org-tag-string-to-alist' specifications."
4756 ;; Tag without selection key.
4757 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
4758 ;; Tag with selection key.
4759 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
4763 (org-tag-string-to-alist "[ group : t1 t2 ]")
4764 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
4765 ;; Mutually exclusive tags.
4766 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
4767 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
4770 (org-tag-string-to-alist "{ group : tag1 tag2 }")
4771 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
4773 (ert-deftest test-org
/tag-alist-to-string
()
4774 "Test `org-tag-alist-to-string' specifications."
4775 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
4776 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
4779 (org-tag-alist-to-string
4780 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4781 "[ group : t1 t2 ]"))
4783 (equal (org-tag-alist-to-string
4784 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
4788 (org-tag-alist-to-string
4789 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
4790 "{ group : tag1 tag2 }")))
4792 (ert-deftest test-org
/tag-alist-to-groups
()
4793 "Test `org-tag-alist-to-groups' specifications."
4795 (equal (org-tag-alist-to-groups
4796 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
4797 '(("group" "t1" "t2"))))
4800 (org-tag-alist-to-groups
4801 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
4802 '(("group" "t1" "t2"))))
4804 (org-tag-alist-to-groups
4805 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
4807 (ert-deftest test-org
/tag-align
()
4808 "Test tags alignment."
4809 ;; Test aligning tags with different display width.
4811 ;; 12345678901234567890
4812 (equal "* Test :abc:"
4813 (org-test-with-temp-text "* Test :abc:"
4814 (let ((org-tags-column -
20)
4815 (indent-tabs-mode nil
))
4816 (org-fix-tags-on-the-fly))
4819 ;; 12345678901234567890
4820 (equal "* Test :日本語:"
4821 (org-test-with-temp-text "* Test :日本語:"
4822 (let ((org-tags-column -
20)
4823 (indent-tabs-mode nil
))
4824 (org-fix-tags-on-the-fly))
4826 ;; Make sure aligning tags do not skip invisible text.
4828 (equal "* [[linkx]] :tag:"
4829 (org-test-with-temp-text "* [[link<point>]] :tag:"
4830 (let ((org-tags-column 0))
4831 (org-fix-tags-on-the-fly)
4833 (buffer-string))))))
4835 (ert-deftest test-org
/tags-at
()
4837 (equal '("foo" "bar")
4838 (org-test-with-temp-text
4839 "* T<point>est :foo:bar:"
4840 (org-get-tags-at)))))
4845 (ert-deftest test-org
/time-stamp
()
4846 "Test `org-time-stamp' specifications."
4847 ;; Insert chosen time stamp at point.
4850 "Te<2014-03-04 .*?>xt"
4851 (org-test-with-temp-text "Te<point>xt"
4852 (cl-letf (((symbol-function 'org-read-date
)
4853 (lambda (&rest args
)
4854 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4855 (org-time-stamp nil
)
4857 ;; With a prefix argument, also insert time.
4860 "Te<2014-03-04 .*? 00:41>xt"
4861 (org-test-with-temp-text "Te<point>xt"
4862 (cl-letf (((symbol-function 'org-read-date
)
4863 (lambda (&rest args
)
4864 (apply #'encode-time
4865 (org-parse-time-string "2014-03-04 00:41")))))
4866 (org-time-stamp '(4))
4868 ;; With two universal prefix arguments, insert an active timestamp
4869 ;; with the current time without prompting the user.
4872 "Te<2014-03-04 .*? 00:41>xt"
4873 (org-test-with-temp-text "Te<point>xt"
4874 (cl-letf (((symbol-function 'current-time
)
4876 (apply #'encode-time
4877 (org-parse-time-string "2014-03-04 00:41")))))
4878 (org-time-stamp '(16))
4880 ;; When optional argument is non-nil, insert an inactive timestamp.
4883 "Te\\[2014-03-04 .*?\\]xt"
4884 (org-test-with-temp-text "Te<point>xt"
4885 (cl-letf (((symbol-function 'org-read-date
)
4886 (lambda (&rest args
)
4887 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4888 (org-time-stamp nil t
)
4890 ;; When called from a timestamp, replace existing one.
4894 (org-test-with-temp-text "<2012-03-29<point> thu.>"
4895 (cl-letf (((symbol-function 'org-read-date
)
4896 (lambda (&rest args
)
4897 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4898 (org-time-stamp nil
)
4902 "<2014-03-04 .*?>--<2014-03-04 .*?>"
4903 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
4904 (cl-letf (((symbol-function 'org-read-date
)
4905 (lambda (&rest args
)
4906 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4907 (org-time-stamp nil
)
4909 ;; When replacing a timestamp, preserve repeater, if any.
4912 "<2014-03-04 .*? \\+2y>"
4913 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
4914 (cl-letf (((symbol-function 'org-read-date
)
4915 (lambda (&rest args
)
4916 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4917 (org-time-stamp nil
)
4919 ;; When called twice in a raw, build a date range.
4922 "<2012-03-29 .*?>--<2014-03-04 .*?>"
4923 (org-test-with-temp-text "<2012-03-29 thu.><point>"
4924 (cl-letf (((symbol-function 'org-read-date
)
4925 (lambda (&rest args
)
4926 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
4927 (let ((last-command 'org-time-stamp
)
4928 (this-command 'org-time-stamp
))
4929 (org-time-stamp nil
))
4930 (buffer-string))))))
4932 (ert-deftest test-org
/timestamp-has-time-p
()
4933 "Test `org-timestamp-has-time-p' specifications."
4936 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4937 (org-timestamp-has-time-p (org-element-context))))
4940 (org-test-with-temp-text "<2012-03-29 Thu>"
4941 (org-timestamp-has-time-p (org-element-context)))))
4943 (ert-deftest test-org
/timestamp-format
()
4944 "Test `org-timestamp-format' specifications."
4949 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
4950 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
4955 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
4956 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
4958 (ert-deftest test-org
/timestamp-split-range
()
4959 "Test `org-timestamp-split-range' specifications."
4960 ;; Extract range start (active).
4963 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4964 (let ((ts (org-timestamp-split-range (org-element-context))))
4965 (mapcar (lambda (p) (org-element-property p ts
))
4966 '(:year-end
:month-end
:day-end
))))))
4967 ;; Extract range start (inactive)
4970 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4971 (let ((ts (org-timestamp-split-range (org-element-context))))
4972 (mapcar (lambda (p) (org-element-property p ts
))
4973 '(:year-end
:month-end
:day-end
))))))
4974 ;; Extract range end (active).
4977 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
4978 (let ((ts (org-timestamp-split-range
4979 (org-element-context) t
)))
4980 (mapcar (lambda (p) (org-element-property p ts
))
4981 '(:year-end
:month-end
:day-end
))))))
4982 ;; Extract range end (inactive)
4985 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
4986 (let ((ts (org-timestamp-split-range
4987 (org-element-context) t
)))
4988 (mapcar (lambda (p) (org-element-property p ts
))
4989 '(:year-end
:month-end
:day-end
))))))
4990 ;; Return the timestamp if not a range.
4992 (org-test-with-temp-text "[2012-03-29 Thu]"
4993 (let* ((ts-orig (org-element-context))
4994 (ts-copy (org-timestamp-split-range ts-orig
)))
4995 (eq ts-orig ts-copy
))))
4997 (org-test-with-temp-text "<%%(org-float t 4 2)>"
4998 (let* ((ts-orig (org-element-context))
4999 (ts-copy (org-timestamp-split-range ts-orig
)))
5000 (eq ts-orig ts-copy
)))))
5002 (ert-deftest test-org
/timestamp-translate
()
5003 "Test `org-timestamp-translate' specifications."
5004 ;; Translate whole date range.
5007 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5008 (let ((org-display-custom-times t
)
5009 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5010 (org-timestamp-translate (org-element-context))))))
5011 ;; Translate date range start.
5014 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5015 (let ((org-display-custom-times t
)
5016 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5017 (org-timestamp-translate (org-element-context) 'start
)))))
5018 ;; Translate date range end.
5021 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5022 (let ((org-display-custom-times t
)
5023 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5024 (org-timestamp-translate (org-element-context) 'end
)))))
5025 ;; Translate time range.
5028 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5029 (let ((org-display-custom-times t
)
5030 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
5031 (org-timestamp-translate (org-element-context))))))
5032 ;; Translate non-range timestamp.
5035 (org-test-with-temp-text "<2012-03-29 Thu>"
5036 (let ((org-display-custom-times t
)
5037 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5038 (org-timestamp-translate (org-element-context))))))
5039 ;; Do not change `diary' timestamps.
5041 (equal "<%%(org-float t 4 2)>"
5042 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5043 (let ((org-display-custom-times t
)
5044 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
5045 (org-timestamp-translate (org-element-context)))))))
5051 (ert-deftest test-org
/flag-drawer
()
5052 "Test `org-flag-drawer' specifications."
5055 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5057 (get-char-property (line-end-position) 'invisible
)))
5060 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5062 (org-flag-drawer nil
)
5063 (get-char-property (line-end-position) 'invisible
)))
5064 ;; Test optional argument.
5066 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5067 (let ((drawer (save-excursion (search-forward ":D2")
5068 (org-element-at-point))))
5069 (org-flag-drawer t drawer
)
5070 (get-char-property (progn (search-forward ":D2") (line-end-position))
5073 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5074 (let ((drawer (save-excursion (search-forward ":D2")
5075 (org-element-at-point))))
5076 (org-flag-drawer t drawer
)
5077 (get-char-property (line-end-position) 'invisible
))))
5078 ;; Do not hide fake drawers.
5080 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5083 (get-char-property (line-end-position) 'invisible
)))
5084 ;; Do not hide incomplete drawers.
5086 (org-test-with-temp-text ":D:\nparagraph"
5089 (get-char-property (line-end-position) 'invisible
)))
5090 ;; Do not hide drawers when called from final blank lines.
5092 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5093 (goto-char (point-max))
5095 (goto-char (point-min))
5096 (get-char-property (line-end-position) 'invisible
)))
5097 ;; Don't leave point in an invisible part of the buffer when hiding
5100 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5101 (goto-char (point-max))
5103 (get-char-property (point) 'invisible
))))
5105 (ert-deftest test-org
/hide-block-toggle
()
5106 "Test `org-hide-block-toggle' specifications."
5107 ;; Error when not at a block.
5109 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5110 (org-hide-block-toggle 'off
)
5111 (get-char-property (line-end-position) 'invisible
)))
5114 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5115 (org-hide-block-toggle)
5116 (get-char-property (line-end-position) 'invisible
)))
5118 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5119 (org-hide-block-toggle)
5120 (get-char-property (line-end-position) 'invisible
)))
5121 ;; Show block unconditionally when optional argument is `off'.
5123 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5124 (org-hide-block-toggle)
5125 (org-hide-block-toggle 'off
)
5126 (get-char-property (line-end-position) 'invisible
)))
5128 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5129 (org-hide-block-toggle 'off
)
5130 (get-char-property (line-end-position) 'invisible
)))
5131 ;; Hide block unconditionally when optional argument is non-nil.
5133 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5134 (org-hide-block-toggle t
)
5135 (get-char-property (line-end-position) 'invisible
)))
5137 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5138 (org-hide-block-toggle)
5139 (org-hide-block-toggle t
)
5140 (get-char-property (line-end-position) 'invisible
)))
5141 ;; Do not hide block when called from final blank lines.
5143 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5144 (org-hide-block-toggle)
5145 (goto-char (point-min))
5146 (get-char-property (line-end-position) 'invisible
)))
5147 ;; Don't leave point in an invisible part of the buffer when hiding
5150 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5151 (org-hide-block-toggle)
5152 (get-char-property (point) 'invisible
))))
5154 (ert-deftest test-org
/hide-block-toggle-maybe
()
5155 "Test `org-hide-block-toggle-maybe' specifications."
5157 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5158 (org-hide-block-toggle-maybe)))
5160 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5162 (ert-deftest test-org
/set-tags
()
5163 "Test `org-set-tags' specifications."
5164 ;; Tags set via fast-tag-selection should be visible afterwards
5166 (let ((org-tag-alist '(("NEXT" . ?n
)))
5167 (org-fast-tag-selection-single-key t
))
5168 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
5169 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
5170 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5171 ;; Show only headlines
5173 ;; Set NEXT tag on current entry
5174 (org-set-tags nil nil
)
5175 ;; Move point to that NEXT tag
5176 (search-forward "NEXT") (backward-word)
5177 ;; And it should be visible (i.e. no overlays)
5178 (not (overlays-at (point))))))))
5180 (ert-deftest test-org
/show-set-visibility
()
5181 "Test `org-show-set-visibility' specifications."
5182 ;; Do not throw an error before first heading.
5184 (org-test-with-temp-text "Preamble\n* Headline"
5185 (org-show-set-visibility 'tree
)
5187 ;; Test all visibility spans, both on headline and in entry.
5188 (let ((list-visible-lines
5189 (lambda (state headerp
)
5190 (org-test-with-temp-text "* Grandmother (0)
5201 **** The other child (11)
5206 (search-forward (if headerp
"Self" "Match"))
5207 (org-show-set-visibility state
)
5208 (goto-char (point-min))
5209 (let (result (line 0))
5211 (unless (org-invisible-p2) (push line result
))
5214 (nreverse result
))))))
5215 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
5216 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
5217 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
5218 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
5219 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
5220 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
5221 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
5222 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
5223 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
5224 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5225 (funcall list-visible-lines
'tree nil
)))
5226 (should (equal '(0 1 3 4 5 7 12 13)
5227 (funcall list-visible-lines
'canonical t
)))
5228 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5229 (funcall list-visible-lines
'canonical nil
))))
5230 ;; When point is hidden in a drawer or a block, make sure to make it
5233 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5234 (org-hide-block-toggle)
5235 (search-forward "Text")
5236 (org-show-set-visibility 'minimal
)
5237 (org-invisible-p2)))
5239 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5241 (search-forward "Text")
5242 (org-show-set-visibility 'minimal
)
5243 (org-invisible-p2)))
5245 (org-test-with-temp-text
5246 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5249 (org-hide-block-toggle)
5250 (search-forward "Text")
5251 (org-show-set-visibility 'minimal
)
5252 (org-invisible-p2))))
5257 ;;; test-org.el ends here