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/>.
21 ;; Template test file for Org tests
28 (ert-deftest test-org
/toggle-comment
()
29 "Test `org-toggle-comment' specifications."
33 (org-test-with-temp-text "* COMMENT Test"
37 (equal "* COMMENT Test"
38 (org-test-with-temp-text "* Test"
41 ;; Headline with a regular keyword.
44 (org-test-with-temp-text "* TODO COMMENT Test"
48 (equal "* TODO COMMENT Test"
49 (org-test-with-temp-text "* TODO Test"
55 (org-test-with-temp-text "* COMMENT"
60 (org-test-with-temp-text "* "
63 ;; Headline with a single keyword.
66 (org-test-with-temp-text "* TODO COMMENT"
70 (equal "* TODO COMMENT"
71 (org-test-with-temp-text "* TODO"
74 ;; Headline with a keyword, a priority cookie and contents.
76 (equal "* TODO [#A] Headline"
77 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
81 (equal "* TODO [#A] COMMENT Headline"
82 (org-test-with-temp-text "* TODO [#A] Headline"
86 (ert-deftest test-org
/comment-dwim
()
87 "Test `comment-dwim' behaviour in an Org buffer."
88 ;; No region selected, no comment on current line and line not
89 ;; empty: insert comment on line above.
92 (org-test-with-temp-text "Comment"
93 (progn (call-interactively 'comment-dwim
)
95 ;; No region selected, no comment on current line and line empty:
96 ;; insert comment on this line.
98 (equal "# \nParagraph"
99 (org-test-with-temp-text "\nParagraph"
100 (progn (call-interactively 'comment-dwim
)
102 ;; No region selected, and a comment on this line: indent it.
104 (equal "* Headline\n # Comment"
105 (org-test-with-temp-text "* Headline\n# Comment"
106 (progn (forward-line)
107 (let ((org-adapt-indentation t
))
108 (call-interactively 'comment-dwim
))
110 ;; Also recognize single # at column 0 as comments.
113 (org-test-with-temp-text "# Comment"
114 (progn (forward-line)
115 (call-interactively 'comment-dwim
)
117 ;; Region selected and only comments and blank lines within it:
118 ;; un-comment all commented lines.
120 (equal "Comment 1\n\nComment 2"
121 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
123 (transient-mark-mode 1)
124 (push-mark (point) t t
)
125 (goto-char (point-max))
126 (call-interactively 'comment-dwim
)
128 ;; Region selected without comments: comment all lines if
129 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
131 (equal "# Comment 1\n\n# Comment 2"
132 (org-test-with-temp-text "Comment 1\n\nComment 2"
134 (transient-mark-mode 1)
135 (push-mark (point) t t
)
136 (goto-char (point-max))
137 (let ((comment-empty-lines nil
))
138 (call-interactively 'comment-dwim
))
141 (equal "# Comment 1\n# \n# Comment 2"
142 (org-test-with-temp-text "Comment 1\n\nComment 2"
144 (transient-mark-mode 1)
145 (push-mark (point) t t
)
146 (goto-char (point-max))
147 (let ((comment-empty-lines t
))
148 (call-interactively 'comment-dwim
))
150 ;; In front of a keyword without region, insert a new comment.
152 (equal "# \n#+KEYWORD: value"
153 (org-test-with-temp-text "#+KEYWORD: value"
154 (progn (call-interactively 'comment-dwim
)
156 ;; In a source block, use appropriate syntax.
159 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
161 (let ((org-edit-src-content-indentation 2))
162 (call-interactively 'comment-dwim
))
163 (buffer-substring-no-properties (line-beginning-position) (point)))))
165 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
166 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
168 (transient-mark-mode 1)
169 (push-mark (point) t t
)
171 (let ((org-edit-src-content-indentation 2))
172 (call-interactively 'comment-dwim
))
177 ;;; Date and time analysis
179 (ert-deftest test-org
/org-read-date
()
180 "Test `org-read-date' specifications."
181 ;; Parse ISO date with abbreviated year and month.
182 (should (equal "2012-03-29 16:40"
183 (let ((org-time-was-given t
))
184 (org-read-date t nil
"12-3-29 16:40"))))
185 ;; Parse Europeans dates.
186 (should (equal "2012-03-29 16:40"
187 (let ((org-time-was-given t
))
188 (org-read-date t nil
"29.03.2012 16:40"))))
189 ;; Parse Europeans dates without year.
190 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
191 (let ((org-time-was-given t
))
192 (org-read-date t nil
"29.03. 16:40"))))
193 ;; Relative date applied to current time if there is single
194 ;; plus/minus, or to default date when there are two of them.
198 (cl-letf (((symbol-function 'current-time
)
200 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
203 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
207 (cl-letf (((symbol-function 'current-time
)
209 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
212 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
219 (cl-letf (((symbol-function 'current-time
)
221 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
222 (let ((org-read-date-prefer-future t
))
223 (org-read-date t nil
"1")))))
227 (cl-letf (((symbol-function 'current-time
)
229 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
230 (let ((org-read-date-prefer-future t
))
231 (org-read-date t nil
"3-4")))))
235 (cl-letf (((symbol-function 'current-time
)
237 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))
238 (let ((org-read-date-prefer-future nil
))
239 (org-read-date t nil
"3-4")))))
240 ;; When set to `org-read-date-prefer-future' is set to `time', read
241 ;; day is moved to tomorrow if specified hour is before current
242 ;; time. However, it only happens in no other part of the date is
247 (cl-letf (((symbol-function 'current-time
)
249 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
250 (let ((org-read-date-prefer-future 'time
))
251 (org-read-date t nil
"00:40" nil
)))))
255 (cl-letf (((symbol-function 'current-time
)
257 (apply #'encode-time
(org-parse-time-string "2012-03-29 16:40")))))
258 (let ((org-read-date-prefer-future 'time
))
259 (org-read-date t nil
"29 00:40" nil
)))))
260 ;; Caveat: `org-read-date-prefer-future' always refers to current
261 ;; time, not default time, when they differ.
265 (cl-letf (((symbol-function 'current-time
)
267 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
268 (let ((org-read-date-prefer-future t
))
271 (apply #'encode-time
(org-parse-time-string "2012-03-29")))))))
275 (cl-letf (((symbol-function 'current-time
)
277 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
278 (let ((org-read-date-prefer-future t
))
281 (apply #'encode-time
(org-parse-time-string "2012-03-29"))))))))
283 (ert-deftest test-org
/org-parse-time-string
()
284 "Test `org-parse-time-string'."
285 (should (equal (org-parse-time-string "2012-03-29 16:40")
286 '(0 40 16 29 3 2012 nil nil nil
)))
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>")
292 '(0 0 0 29 3 2012 nil nil nil
)))
293 (should (equal (org-parse-time-string "<2012-03-29>" t
)
294 '(0 nil nil
29 3 2012 nil nil nil
))))
296 (ert-deftest test-org
/closest-date
()
297 "Test `org-closest-date' specifications."
299 ;; Time stamps without a repeater are returned unchanged.
303 (calendar-gregorian-from-absolute
304 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil
))))
305 ;; Time stamps with a null repeater are returned unchanged.
309 (calendar-gregorian-from-absolute
310 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil
))))
311 ;; if PREFER is set to `past' always return a date before, or equal
316 (calendar-gregorian-from-absolute
317 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past
))))
321 (calendar-gregorian-from-absolute
322 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past
))))
323 ;; if PREFER is set to `future' always return a date before, or equal
328 (calendar-gregorian-from-absolute
329 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future
))))
333 (calendar-gregorian-from-absolute
334 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future
))))
335 ;; If PREFER is neither `past' nor `future', select closest date.
339 (calendar-gregorian-from-absolute
340 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil
))))
344 (calendar-gregorian-from-absolute
345 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil
))))
346 ;; Test "day" repeater.
349 (calendar-gregorian-from-absolute
350 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past
))))
353 (calendar-gregorian-from-absolute
354 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future
))))
355 ;; Test "month" repeater.
358 (calendar-gregorian-from-absolute
359 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past
))))
362 (calendar-gregorian-from-absolute
363 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future
))))
364 ;; Test "year" repeater.
367 (calendar-gregorian-from-absolute
368 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past
))))
371 (calendar-gregorian-from-absolute
372 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future
)))))
374 (ert-deftest test-org
/deadline-close-p
()
375 "Test `org-deadline-close-p' specifications."
376 ;; Pretend that the current time is 2016-06-03 Fri 01:43
377 (cl-letf (((symbol-function 'current-time
)
378 (lambda () '(22353 6425 905205 644000))))
379 ;; Timestamps are close if they are within `ndays' of lead time.
380 (org-test-with-temp-text "* Heading"
381 (should (org-deadline-close-p "2016-06-03 Fri" 0))
382 (should (org-deadline-close-p "2016-06-02 Thu" 0))
383 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
384 (should (org-deadline-close-p "2016-06-04 Sat" 1))
385 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
386 ;; Read `ndays' from timestamp if argument not given.
387 (org-test-with-temp-text "* H"
388 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
389 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
390 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
391 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
392 ;; Prefer `ndays' argument over lead time in timestamp.
393 (org-test-with-temp-text "* H"
394 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
395 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
396 ;; Completed tasks are never close.
397 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
398 (org-test-with-temp-text "* TODO Heading"
399 (should (org-deadline-close-p "2016-06-03")))
400 (org-test-with-temp-text "* DONE Heading"
401 (should-not (org-deadline-close-p "2016-06-03"))))))
406 (ert-deftest test-org
/insert-property-drawer
()
407 "Test `org-insert-property-drawer' specifications."
408 ;; Error before first headline.
409 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
410 ;; Insert drawer right after headline if there is no planning line,
411 ;; or after it otherwise.
413 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
414 (org-test-with-temp-text "* H\nParagraph<point>"
415 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
418 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
419 (org-test-with-temp-text
420 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
421 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
423 ;; Indent inserted drawer.
425 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
426 (org-test-with-temp-text "* H\nParagraph<point>"
427 (let ((org-adapt-indentation t
)) (org-insert-property-drawer))
429 ;; Handle insertion at eob.
431 (equal "* H\n:PROPERTIES:\n:END:\n"
432 (org-test-with-temp-text "* H"
433 (let ((org-adapt-indentation nil
)) (org-insert-property-drawer))
435 ;; Skip inlinetasks before point.
436 (when (featurep 'org-inlinetask
)
438 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
439 (org-test-with-temp-text
440 "* H\n*************** I\n*************** END\nP<point>"
441 (let ((org-adapt-indentation nil
)
442 (org-inlinetask-min-level 15))
443 (org-insert-property-drawer))
445 ;; Correctly set drawer in an inlinetask.
446 (when (featurep 'org-inlinetask
)
448 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
449 (org-test-with-temp-text
450 "* H\n*************** I\nP<point>\n*************** END"
451 (let ((org-adapt-indentation nil
)
452 (org-inlinetask-min-level 15))
453 (org-insert-property-drawer))
459 (ert-deftest test-org
/fill-paragraph
()
460 "Test `org-fill-paragraph' specifications."
461 ;; At an Org table, align it.
464 (org-test-with-temp-text "|a|"
468 (equal "#+name: table\n| a |\n"
469 (org-test-with-temp-text "#+name: table\n| a |\n"
472 ;; At a paragraph, preserve line breaks.
473 (org-test-with-temp-text "some \\\\\nlong\ntext"
474 (let ((fill-column 20))
476 (should (equal (buffer-string) "some \\\\\nlong text"))))
477 ;; Correctly fill a paragraph when point is at its very end.
480 (org-test-with-temp-text "A\nB"
481 (let ((fill-column 20))
482 (goto-char (point-max))
485 ;; Correctly fill the last paragraph of a greater element.
487 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
488 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
489 (let ((fill-column 8))
494 ;; Correctly fill an element in a narrowed buffer.
497 (org-test-with-temp-text "01234 6789"
498 (let ((fill-column 5))
499 (narrow-to-region 1 8)
502 ;; Handle `adaptive-fill-regexp' in paragraphs.
505 (org-test-with-temp-text "> a\n> b"
506 (let ((fill-column 5)
507 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
510 ;; Special case: Fill first paragraph when point is at an item or
511 ;; a plain-list or a footnote reference.
514 (org-test-with-temp-text "- A\n B"
515 (let ((fill-column 20))
520 (org-test-with-temp-text "[fn:1] A\nB"
521 (let ((fill-column 20))
524 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
525 (let ((fill-column 20))
527 (should (equal (buffer-string)
528 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
529 ;; Fill contents of `comment-block' elements.
532 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
533 (let ((fill-column 20))
537 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
538 ;; Fill `comment' elements.
541 (org-test-with-temp-text " # A\n # B"
542 (let ((fill-column 20))
545 ;; Do not mix consecutive comments when filling one of them.
547 (equal "# A B\n\n# C"
548 (org-test-with-temp-text "# A\n# B\n\n# C"
549 (let ((fill-column 20))
552 ;; Use commented empty lines as separators when filling comments.
554 (equal "# A B\n#\n# C"
555 (org-test-with-temp-text "# A\n# B\n#\n# C"
556 (let ((fill-column 20))
559 ;; Handle `adaptive-fill-regexp' in comments.
562 (org-test-with-temp-text "# > a\n# > b"
563 (let ((fill-column 20)
564 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
567 ;; Do nothing at affiliated keywords.
568 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
569 (let ((fill-column 20))
571 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
572 ;; Do not move point after table when filling a table.
574 (org-test-with-temp-text "| a | b |\n| c | d |\n"
579 (ert-deftest test-org
/auto-fill-function
()
580 "Test auto-filling features."
581 ;; Auto fill paragraph.
584 (org-test-with-temp-text "12345 7890"
585 (let ((fill-column 5))
587 (org-auto-fill-function)
589 ;; Auto fill first paragraph in an item.
591 (equal "- 12345\n 7890"
592 (org-test-with-temp-text "- 12345 7890"
593 (let ((fill-column 7))
595 (org-auto-fill-function)
597 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
599 (equal "> 12345\n 7890"
600 (org-test-with-temp-text "> 12345 7890"
601 (let ((fill-column 10)
602 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
603 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
605 (org-auto-fill-function)
608 (equal "> 12345\n> 12345\n> 7890"
609 (org-test-with-temp-text "> 12345\n> 12345 7890"
610 (let ((fill-column 10)
611 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
612 (goto-char (point-max))
613 (org-auto-fill-function)
616 (equal " 12345\n *12345\n *12345"
617 (org-test-with-temp-text " 12345\n *12345 12345"
618 (let ((fill-column 10)
619 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
620 (goto-char (point-max))
621 (org-auto-fill-function)
623 ;; Auto fill comments.
625 (equal " # 12345\n # 7890"
626 (org-test-with-temp-text " # 12345 7890"
627 (let ((fill-column 10))
629 (org-auto-fill-function)
631 ;; A hash within a line isn't a comment.
633 (equal "12345 # 7890\n# 1"
634 (org-test-with-temp-text "12345 # 7890 1"
635 (let ((fill-column 12))
637 (org-auto-fill-function)
639 ;; Correctly interpret empty prefix.
641 (equal "# a\n# b\nRegular\n# paragraph"
642 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
643 (let ((fill-column 12))
645 (org-auto-fill-function)
647 ;; Comment block: auto fill contents.
649 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
650 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
651 (let ((fill-column 5))
654 (org-auto-fill-function)
657 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
658 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
659 (let ((fill-column 5))
662 (org-auto-fill-function)
664 ;; Do not fill if a new item could be created.
667 (org-test-with-temp-text "12345 - 90"
668 (let ((fill-column 5))
670 (org-auto-fill-function)
672 ;; Do not fill if a line break could be introduced.
674 (equal "123\\\\\n7890"
675 (org-test-with-temp-text "123\\\\ 7890"
676 (let ((fill-column 6))
678 (org-auto-fill-function)
680 ;; Do not fill affiliated keywords.
682 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
683 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
684 (let ((fill-column 20))
686 (org-auto-fill-function)
693 (ert-deftest test-org
/indent-line
()
694 "Test `org-indent-line' specifications."
695 ;; Do not indent diary sexps, footnote definitions or headlines.
698 (org-test-with-temp-text "%%(org-calendar-holiday)"
700 (org-get-indentation))))
703 (org-test-with-temp-text "[fn:1] fn"
704 (let ((org-adapt-indentation t
)) (org-indent-line))
705 (org-get-indentation))))
708 (org-test-with-temp-text "* H"
710 (org-get-indentation))))
711 ;; Do not indent before first headline.
714 (org-test-with-temp-text ""
716 (org-get-indentation))))
717 ;; Indent according to headline level otherwise, unless
718 ;; `org-adapt-indentation' is nil.
721 (org-test-with-temp-text "* H\n<point>A"
722 (let ((org-adapt-indentation t
)) (org-indent-line))
723 (org-get-indentation))))
726 (org-test-with-temp-text "* H\n<point>\nA"
727 (let ((org-adapt-indentation t
)) (org-indent-line))
728 (org-get-indentation))))
731 (org-test-with-temp-text "* H\n<point>A"
732 (let ((org-adapt-indentation nil
)) (org-indent-line))
733 (org-get-indentation))))
734 ;; Indenting preserves point position.
736 (org-test-with-temp-text "* H\nA<point>B"
737 (let ((org-adapt-indentation t
)) (org-indent-line))
739 ;; Do not change indentation at an item or a LaTeX environment.
742 (org-test-with-temp-text "* H\n<point> - A"
743 (let ((org-adapt-indentation t
)) (org-indent-line))
744 (org-get-indentation))))
747 (org-test-with-temp-text
748 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
750 (org-get-indentation))))
751 ;; On blank lines at the end of a list, indent like last element
752 ;; within it if the line is still in the list. If the last element
753 ;; is an item, indent like its contents. Otherwise, indent like the
757 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
758 (let ((org-adapt-indentation t
)) (org-indent-line))
759 (org-get-indentation))))
762 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
763 (let ((org-adapt-indentation t
)) (org-indent-line))
764 (org-get-indentation))))
767 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
768 (let ((org-adapt-indentation t
)) (org-indent-line))
769 (org-get-indentation))))
772 (org-test-with-temp-text "* H\n- A\n - \n<point>"
773 (let ((org-adapt-indentation t
)) (org-indent-line))
774 (org-get-indentation))))
777 (org-test-with-temp-text
778 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
779 (let ((org-adapt-indentation t
)) (org-indent-line))
780 (org-get-indentation))))
783 (org-test-with-temp-text "- A\n B\n\n<point>"
784 (let ((org-adapt-indentation nil
)) (org-indent-line))
785 (org-get-indentation))))
788 (org-test-with-temp-text
789 "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
790 (let ((org-adapt-indentation nil
)) (org-indent-line))
791 (org-get-indentation))))
792 ;; Likewise, on a blank line at the end of a footnote definition,
793 ;; indent at column 0 if line belongs to the definition. Otherwise,
794 ;; indent like the definition itself.
797 (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
798 (let ((org-adapt-indentation t
)) (org-indent-line))
799 (org-get-indentation))))
802 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
803 (let ((org-adapt-indentation t
)) (org-indent-line))
804 (org-get-indentation))))
805 ;; After the end of the contents of a greater element, indent like
806 ;; the beginning of the element.
809 (org-test-with-temp-text
810 " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
812 (org-get-indentation))))
813 ;; On blank lines after a paragraph, indent like its last non-empty
817 (org-test-with-temp-text " Paragraph\n\n<point>"
819 (org-get-indentation))))
820 ;; At the first line of an element, indent like previous element's
821 ;; first line, ignoring footnotes definitions and inline tasks, or
822 ;; according to parent.
825 (org-test-with-temp-text "A\n\n B\n\nC<point>"
827 (org-get-indentation))))
830 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
832 (org-get-indentation))))
835 (org-test-with-temp-text
836 " #+BEGIN_CENTER\n<point> 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
845 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\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
853 "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\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
862 "#+BEGIN_CENTER\nline1\n\n<point> 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
870 "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
871 (let ((org-property-format "%-10s %s")) (org-indent-line))
874 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
875 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
876 (let ((org-property-format "%-10s %s")) (org-indent-line))
879 (ert-deftest test-org
/indent-region
()
880 "Test `org-indent-region' specifications."
884 (org-test-with-temp-text " A\nB\n C"
885 (org-indent-region (point-min) (point-max))
887 ;; Indent greater elements along with their contents.
889 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
890 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
891 (org-indent-region (point-min) (point-max))
893 ;; Ignore contents of verse blocks. Only indent block delimiters.
895 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
896 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
897 (org-indent-region (point-min) (point-max))
900 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
901 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
902 (org-indent-region (point-min) (point-max))
904 ;; Indent example blocks as a single block, unless indentation
905 ;; should be preserved. In this case only indent the block markers.
907 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
908 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
909 (org-indent-region (point-min) (point-max))
912 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
913 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
914 (org-indent-region (point-min) (point-max))
917 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
918 (org-test-with-temp-text
919 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
920 (org-indent-region (point-min) (point-max))
923 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
924 (org-test-with-temp-text
925 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
926 (let ((org-src-preserve-indentation t
))
927 (org-indent-region (point-min) (point-max)))
929 ;; Treat export blocks as a whole.
931 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
932 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
933 (org-indent-region (point-min) (point-max))
936 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
937 (org-test-with-temp-text
938 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
939 (org-indent-region (point-min) (point-max))
941 ;; Indent according to mode if `org-src-tab-acts-natively' is
942 ;; non-nil. Otherwise, do not indent code at all.
944 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
945 (org-test-with-temp-text
946 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
947 (let ((org-src-tab-acts-natively t
)
948 (org-edit-src-content-indentation 0))
949 (org-indent-region (point-min) (point-max)))
952 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
953 (org-test-with-temp-text
954 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
955 (let ((org-src-tab-acts-natively nil
)
956 (org-edit-src-content-indentation 0))
957 (org-indent-region (point-min) (point-max)))
959 ;; Align node properties according to `org-property-format'. Handle
960 ;; nicely empty values.
962 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
963 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
964 (let ((org-property-format "%-10s %s")
965 (org-adapt-indentation nil
))
966 (org-indent-region (point) (point-max)))
969 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
970 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
971 (let ((org-property-format "%-10s %s")
972 (org-adapt-indentation nil
))
973 (org-indent-region (point) (point-max)))
975 ;; Indent plain lists.
977 (equal "- A\n B\n - C\n\n D"
978 (org-test-with-temp-text "- A\n B\n - C\n\n D"
979 (org-indent-region (point-min) (point-max))
983 (org-test-with-temp-text " - A\n\n - B"
984 (org-indent-region (point-min) (point-max))
986 ;; Indent footnote definitions.
988 (equal "[fn:1] Definition\n\nDefinition"
989 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
990 (org-indent-region (point-min) (point-max))
992 ;; Special case: Start indenting on a blank line.
995 (org-test-with-temp-text "\n Paragraph"
996 (org-indent-region (point-min) (point-max))
1003 (ert-deftest test-org
/delete-indentation
()
1004 "Test `org-delete-indentation' specifications."
1006 (should (equal "foo bar"
1007 (org-test-with-temp-text
1009 (org-delete-indentation)
1011 ;; With optional argument.
1012 (should (equal "foo bar"
1013 (org-test-with-temp-text
1015 (org-delete-indentation t
)
1017 ;; At headline text should be appended to the headline text.
1019 (equal"* foo bar :tag:"
1020 (let (org-auto-align-tags)
1021 (org-test-with-temp-text
1022 "* foo :tag:\n bar<point>"
1023 (org-delete-indentation)
1026 (equal "* foo bar :tag:"
1027 (let (org-auto-align-tags)
1028 (org-test-with-temp-text
1029 "* foo <point>:tag:\n bar"
1030 (org-delete-indentation t
)
1031 (buffer-string))))))
1033 (ert-deftest test-org
/return
()
1034 "Test `org-return' specifications."
1037 (equal "Para\ngraph"
1038 (org-test-with-temp-text "Para<point>graph"
1041 ;; With optional argument, indent line.
1043 (equal " Para\n graph"
1044 (org-test-with-temp-text " Para<point>graph"
1047 ;; On a table, call `org-table-next-row'.
1049 (org-test-with-temp-text "| <point>a |\n| b |"
1051 (looking-at-p "b")))
1052 ;; Open link or timestamp under point when `org-return-follows-link'
1055 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1056 (let ((org-return-follows-link t
)
1057 (org-link-search-must-match-exact-headline nil
))
1059 (looking-at-p "<<target>>")))
1061 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1062 (let ((org-return-follows-link nil
)) (org-return))
1063 (looking-at-p "<<target>>")))
1065 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1066 (let ((org-return-follows-link t
)) (org-return))
1067 (looking-at-p "* b")))
1069 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1070 (let ((org-return-follows-link t
)
1071 (org-link-search-must-match-exact-headline nil
))
1073 (looking-at-p "<<target>>")))
1075 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1076 (let ((org-return-follows-link t
)
1077 (org-link-search-must-match-exact-headline nil
))
1079 (looking-at-p "<<target>>")))
1080 ;; When `org-return-follows-link' is non-nil, tolerate links and
1081 ;; timestamps in comments, node properties, etc.
1083 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1084 (let ((org-return-follows-link t
)
1085 (org-link-search-must-match-exact-headline nil
))
1087 (looking-at-p "<<target>>")))
1089 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1090 (let ((org-return-follows-link nil
)) (org-return))
1091 (looking-at-p "<<target>>")))
1093 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1094 (let ((org-return-follows-link t
)
1095 (org-link-search-must-match-exact-headline nil
))
1097 (looking-at-p "<<target>>")))
1098 ;; However, do not open link when point is in a table.
1100 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1101 (let ((org-return-follows-link t
)) (org-return))
1102 (looking-at-p "between")))
1103 ;; Special case: in a list, when indenting, do not break structure.
1106 (org-test-with-temp-text "- A <point>B"
1111 (org-test-with-temp-text "- A\n<point>- B"
1114 ;; On tags part of a headline, add a newline below it instead of
1117 (equal "* H :tag:\n"
1118 (org-test-with-temp-text "* H :<point>tag:"
1121 ;; Before headline text, add a newline below it instead of breaking
1124 (equal "* TODO H :tag:\n"
1125 (org-test-with-temp-text "* <point>TODO H :tag:"
1129 (equal "* TODO [#B] H :tag:\n"
1130 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1133 (should ;TODO are case-sensitive
1135 (org-test-with-temp-text "* <point>Todo"
1138 ;; At headline text, break headline text but preserve tags.
1140 (equal "* TODO [#B] foo :tag:\nbar"
1141 (let (org-auto-align-tags)
1142 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1145 ;; At bol of headline insert newline.
1148 (org-test-with-temp-text "<point>* h"
1151 ;; Refuse to leave invalid headline in buffer.
1154 (org-test-with-temp-text "*<point> h"
1158 (ert-deftest test-org
/meta-return
()
1159 "Test M-RET (`org-meta-return') specifications."
1160 ;; In a table field insert a row above.
1162 (org-test-with-temp-text "| a |"
1166 (looking-at "| |$")))
1167 ;; In a paragraph change current line into a header.
1169 (org-test-with-temp-text "a"
1172 (looking-at "\* a$")))
1173 ;; In an item insert an item, in this case above.
1175 (org-test-with-temp-text "- a"
1178 (looking-at "- $")))
1179 ;; In a drawer and item insert an item, in this case above.
1181 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1185 (looking-at "- $"))))
1187 (ert-deftest test-org
/insert-heading
()
1188 "Test `org-insert-heading' specifications."
1189 ;; In an empty buffer, insert a new headline.
1192 (org-test-with-temp-text ""
1193 (org-insert-heading)
1195 ;; At the beginning of a line, turn it into a headline.
1198 (org-test-with-temp-text "<point>P"
1199 (org-insert-heading)
1201 ;; In the middle of a line, split the line if allowed, otherwise,
1202 ;; insert the headline at its end.
1204 (equal "Para\n* graph"
1205 (org-test-with-temp-text "Para<point>graph"
1206 (let ((org-M-RET-may-split-line '((default . t
))))
1207 (org-insert-heading))
1210 (equal "Paragraph\n* "
1211 (org-test-with-temp-text "Para<point>graph"
1212 (let ((org-M-RET-may-split-line '((default . nil
))))
1213 (org-insert-heading))
1215 ;; At the beginning of a headline, create one above.
1218 (org-test-with-temp-text "* H"
1219 (org-insert-heading)
1221 ;; In the middle of a headline, split it if allowed.
1224 (org-test-with-temp-text "* H<point>1"
1225 (let ((org-M-RET-may-split-line '((headline . t
))))
1226 (org-insert-heading))
1230 (org-test-with-temp-text "* H<point>1"
1231 (let ((org-M-RET-may-split-line '((headline . nil
))))
1232 (org-insert-heading))
1234 ;; However, splitting cannot happen on TODO keywords, priorities or
1237 (equal "* TODO H1\n* \n"
1238 (org-test-with-temp-text "* TO<point>DO H1"
1239 (let ((org-M-RET-may-split-line '((headline . t
))))
1240 (org-insert-heading))
1243 (equal "* [#A] H1\n* \n"
1244 (org-test-with-temp-text "* [#<point>A] H1"
1245 (let ((org-M-RET-may-split-line '((headline . t
))))
1246 (org-insert-heading))
1249 (equal "* H1 :tag:\n* \n"
1250 (org-test-with-temp-text "* H1 :ta<point>g:"
1251 (let ((org-M-RET-may-split-line '((headline . t
))))
1252 (org-insert-heading))
1254 ;; New headline level depends on the level of the headline above.
1257 (org-test-with-temp-text "** H\n<point>P"
1258 (org-insert-heading)
1261 (equal "** H\nPara\n** graph"
1262 (org-test-with-temp-text "** H\nPara<point>graph"
1263 (let ((org-M-RET-may-split-line '((default . t
))))
1264 (org-insert-heading))
1268 (org-test-with-temp-text "** H"
1269 (org-insert-heading)
1271 ;; When called with one universal argument, insert a new headline at
1272 ;; the end of the current subtree, independently on the position of
1277 (org-test-with-temp-text "* H1\n** H2"
1278 (let ((org-insert-heading-respect-content nil
))
1279 (org-insert-heading '(4)))
1284 (org-test-with-temp-text "* H<point>1\n** H2"
1285 (let ((org-insert-heading-respect-content nil
))
1286 (org-insert-heading '(4)))
1288 ;; When called with two universal arguments, insert a new headline
1289 ;; at the end of the grandparent subtree.
1291 (equal "* H1\n** H3\n- item\n** H2\n** \n"
1292 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1293 (let ((org-insert-heading-respect-content nil
))
1294 (org-insert-heading '(16)))
1296 ;; When optional TOP-LEVEL argument is non-nil, always insert
1297 ;; a level 1 heading.
1299 (equal "* H1\n** H2\n* \n"
1300 (org-test-with-temp-text "* H1\n** H2<point>"
1301 (org-insert-heading nil nil t
)
1304 (equal "* H1\n- item\n* "
1305 (org-test-with-temp-text "* H1\n- item<point>"
1306 (org-insert-heading nil nil t
)
1308 ;; Obey `org-blank-before-new-entry'.
1310 (equal "* H1\n\n* \n"
1311 (org-test-with-temp-text "* H1<point>"
1312 (let ((org-blank-before-new-entry '((heading . t
))))
1313 (org-insert-heading))
1317 (org-test-with-temp-text "* H1<point>"
1318 (let ((org-blank-before-new-entry '((heading . nil
))))
1319 (org-insert-heading))
1322 (equal "* H1\n* H2\n* \n"
1323 (org-test-with-temp-text "* H1\n* H2<point>"
1324 (let ((org-blank-before-new-entry '((heading . auto
))))
1325 (org-insert-heading))
1328 (equal "* H1\n\n* H2\n\n* \n"
1329 (org-test-with-temp-text "* H1\n\n* H2<point>"
1330 (let ((org-blank-before-new-entry '((heading . auto
))))
1331 (org-insert-heading))
1333 ;; Corner case: correctly insert a headline after an empty one.
1336 (org-test-with-temp-text "* <point>"
1337 (org-insert-heading)
1340 (org-test-with-temp-text "* <point>\n"
1341 (org-insert-heading)
1342 (looking-at-p "\n\\'")))
1343 ;; Do not insert spurious headlines when inserting a new headline.
1345 (equal "* H1\n* H2\n* \n"
1346 (org-test-with-temp-text "* H1\n* H2<point>\n"
1347 (org-insert-heading)
1349 ;; Preserve visibility at beginning of line. In particular, when
1350 ;; removing spurious blank lines, do not visually merge heading with
1351 ;; the line visible above.
1353 (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
1355 (let ((org-blank-before-new-entry '((heading . nil
))))
1356 (org-insert-heading '(4)))
1357 (invisible-p (line-end-position 0))))
1358 ;; Properly handle empty lines when forcing a headline below current
1361 (equal "* H1\n\n* H\n\n* \n"
1362 (org-test-with-temp-text "* H1\n\n* H<point>"
1363 (let ((org-blank-before-new-entry '((heading . t
))))
1364 (org-insert-heading '(4))
1365 (buffer-string))))))
1367 (ert-deftest test-org
/insert-todo-heading-respect-content
()
1368 "Test `org-insert-todo-heading-respect-content' specifications."
1369 ;; Create a TODO heading.
1371 (org-test-with-temp-text "* H1\n Body"
1372 (org-insert-todo-heading-respect-content)
1373 (nth 2 (org-heading-components))))
1374 ;; Add headline at the end of the first subtree
1378 (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
1379 (org-insert-todo-heading-respect-content)
1380 (buffer-substring-no-properties (line-beginning-position) (point-max)))))
1381 ;; In a list, do not create a new item.
1385 (org-test-with-temp-text "* H\n- an item\n- another one"
1386 (search-forward "an ")
1387 (org-insert-todo-heading-respect-content)
1388 (buffer-substring-no-properties (line-beginning-position) (point-max))))))
1390 (ert-deftest test-org
/clone-with-time-shift
()
1391 "Test `org-clone-subtree-with-time-shift'."
1392 ;; Raise an error before first heading.
1394 (org-test-with-temp-text ""
1395 (org-clone-subtree-with-time-shift 1)))
1396 ;; Raise an error on invalid number of clones.
1398 (org-test-with-temp-text "* Clone me"
1399 (org-clone-subtree-with-time-shift -
1)))
1400 ;; Clone non-repeating once.
1406 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1407 (org-clone-subtree-with-time-shift 1 "+2d")
1408 (replace-regexp-in-string
1409 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1411 ;; Clone repeating once.
1416 * H1\n<2015-06-25 +1w>
1418 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1419 (org-clone-subtree-with-time-shift 1 "+2d")
1420 (replace-regexp-in-string
1421 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1423 ;; Clone non-repeating zero times.
1428 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1429 (org-clone-subtree-with-time-shift 0 "+2d")
1430 (replace-regexp-in-string
1431 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1433 ;; Clone repeating "zero" times.
1437 * H1\n<2015-06-23 +1w>
1439 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1440 (org-clone-subtree-with-time-shift 0 "+2d")
1441 (replace-regexp-in-string
1442 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1444 ;; Clone with blank SHIFT argument.
1448 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1449 (org-clone-subtree-with-time-shift 1 "")
1450 (buffer-substring-no-properties (line-beginning-position 2)
1451 (line-end-position 2)))))
1452 ;; Find time stamps before point. If SHIFT is not specified, ask
1453 ;; for a time shift.
1457 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1458 (org-clone-subtree-with-time-shift 1 "+1d")
1459 (buffer-substring-no-properties (line-beginning-position 2)
1460 (line-end-position 2)))))
1464 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1465 (cl-letf (((symbol-function 'read-from-minibuffer
)
1466 (lambda (&rest args
) "+1d")))
1467 (org-clone-subtree-with-time-shift 1))
1468 (buffer-substring-no-properties (line-beginning-position 2)
1469 (line-end-position 2))))))
1472 ;;; Fixed-Width Areas
1474 (ert-deftest test-org
/toggle-fixed-width
()
1475 "Test `org-toggle-fixed-width' specifications."
1476 ;; No region: Toggle on fixed-width marker in paragraphs.
1479 (org-test-with-temp-text "A"
1480 (org-toggle-fixed-width)
1482 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1485 (org-test-with-temp-text ": A"
1486 (org-toggle-fixed-width)
1488 ;; No region: Toggle on marker in blank lines after elements or just
1489 ;; after a headline.
1492 (org-test-with-temp-text "* H\n"
1494 (org-toggle-fixed-width)
1497 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1498 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1499 (goto-char (point-max))
1500 (org-toggle-fixed-width)
1502 ;; No region: Toggle on marker in front of one line elements (e.g.,
1503 ;; headlines, clocks)
1505 (equal ": * Headline"
1506 (org-test-with-temp-text "* Headline"
1507 (org-toggle-fixed-width)
1510 (equal ": #+KEYWORD: value"
1511 (org-test-with-temp-text "#+KEYWORD: value"
1512 (org-toggle-fixed-width)
1514 ;; No region: error in other situations.
1516 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1518 (org-toggle-fixed-width)
1520 ;; No region: Indentation is preserved.
1523 (org-test-with-temp-text "- A\n B"
1525 (org-toggle-fixed-width)
1527 ;; Region: If it contains only fixed-width elements and blank lines,
1528 ;; toggle off fixed-width markup.
1531 (org-test-with-temp-text ": A\n\n: B"
1532 (transient-mark-mode 1)
1533 (push-mark (point) t t
)
1534 (goto-char (point-max))
1535 (org-toggle-fixed-width)
1537 ;; Region: If it contains anything else, toggle on fixed-width but
1538 ;; not on fixed-width areas.
1540 (equal ": A\n: \n: B\n: \n: C"
1541 (org-test-with-temp-text "A\n\n: B\n\nC"
1542 (transient-mark-mode 1)
1543 (push-mark (point) t t
)
1544 (goto-char (point-max))
1545 (org-toggle-fixed-width)
1547 ;; Region: Ignore blank lines at its end, unless it contains only
1551 (org-test-with-temp-text "A\n\n"
1552 (transient-mark-mode 1)
1553 (push-mark (point) t t
)
1554 (goto-char (point-max))
1555 (org-toggle-fixed-width)
1559 (org-test-with-temp-text "\n\n"
1560 (transient-mark-mode 1)
1561 (push-mark (point) t t
)
1562 (goto-char (point-max))
1563 (org-toggle-fixed-width)
1570 (ert-deftest test-org
/get-heading
()
1571 "Test `org-get-heading' specifications."
1572 ;; Return current heading, even if point is not on it.
1575 (org-test-with-temp-text "* H"
1576 (org-get-heading))))
1579 (org-test-with-temp-text "* H\nText<point>"
1580 (org-get-heading))))
1581 ;; Without any optional argument, return TODO keyword, priority
1582 ;; cookie, COMMENT keyword and tags.
1585 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1586 (org-get-heading))))
1589 (org-test-with-temp-text "* [#A] H"
1590 (org-get-heading))))
1593 (org-test-with-temp-text "* COMMENT H"
1594 (org-get-heading))))
1597 (org-test-with-temp-text "* H :tag:"
1598 (org-get-heading))))
1599 ;; With NO-TAGS argument, ignore tags.
1602 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1603 (org-get-heading t
))))
1606 (org-test-with-temp-text "* H :tag:"
1607 (org-get-heading t
))))
1608 ;; With NO-TODO, ignore TODO keyword.
1611 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1612 (org-get-heading nil t
))))
1615 (org-test-with-temp-text "* H :tag:"
1616 (org-get-heading nil t
))))
1617 ;; TODO keywords are case-sensitive.
1620 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1621 (org-get-heading nil t
))))
1622 ;; With NO-PRIORITY, ignore priority.
1625 (org-test-with-temp-text "* [#A] H"
1626 (org-get-heading nil nil t
))))
1629 (org-test-with-temp-text "* H"
1630 (org-get-heading nil nil t
))))
1633 (org-test-with-temp-text "* TODO [#A] H"
1634 (org-get-heading nil nil t
))))
1635 ;; With NO-COMMENT, ignore COMMENT keyword.
1638 (org-test-with-temp-text "* COMMENT H"
1639 (org-get-heading nil nil nil t
))))
1642 (org-test-with-temp-text "* H"
1643 (org-get-heading nil nil nil t
))))
1645 (equal "TODO [#A] H"
1646 (org-test-with-temp-text "* TODO [#A] COMMENT H"
1647 (org-get-heading nil nil nil t
))))
1648 ;; On an empty headline, return value is consistent.
1649 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1650 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
))))
1651 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t
))))
1652 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t
))))
1654 (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t
)))))
1656 (ert-deftest test-org
/in-commented-heading-p
()
1657 "Test `org-in-commented-heading-p' specifications."
1658 ;; Commented headline.
1660 (org-test-with-temp-text "* COMMENT Headline\nBody"
1661 (goto-char (point-max))
1662 (org-in-commented-heading-p)))
1663 ;; Commented ancestor.
1665 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1666 (goto-char (point-max))
1667 (org-in-commented-heading-p)))
1668 ;; Comment keyword is case-sensitive.
1670 (org-test-with-temp-text "* Comment Headline\nBody"
1671 (goto-char (point-max))
1672 (org-in-commented-heading-p)))
1673 ;; Keyword is standalone.
1675 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1676 (goto-char (point-max))
1677 (org-in-commented-heading-p)))
1678 ;; Optional argument.
1680 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1681 (goto-char (point-max))
1682 (org-in-commented-heading-p t
))))
1684 (ert-deftest test-org
/entry-blocked-p
()
1685 ;; Check other dependencies.
1687 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1688 (let ((org-enforce-todo-dependencies t
)
1690 '(org-block-todo-from-children-or-siblings-or-parent)))
1691 (org-entry-blocked-p))))
1693 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1694 (let ((org-enforce-todo-dependencies t
)
1696 '(org-block-todo-from-children-or-siblings-or-parent)))
1697 (org-entry-blocked-p))))
1698 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1701 (org-test-with-temp-text "* Blocked\n** TODO one"
1702 (let ((org-enforce-todo-dependencies t
)
1704 '(org-block-todo-from-children-or-siblings-or-parent)))
1705 (org-entry-blocked-p))))
1707 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1708 (let ((org-enforce-todo-dependencies t
)
1710 '(org-block-todo-from-children-or-siblings-or-parent)))
1711 (org-entry-blocked-p))))
1712 ;; Follow :ORDERED: specifications.
1714 (org-test-with-temp-text
1715 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1716 (let ((org-enforce-todo-dependencies t
)
1718 '(org-block-todo-from-children-or-siblings-or-parent)))
1719 (org-entry-blocked-p))))
1721 (org-test-with-temp-text
1722 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1723 (let ((org-enforce-todo-dependencies t
)
1725 '(org-block-todo-from-children-or-siblings-or-parent)))
1726 (org-entry-blocked-p)))))
1728 (ert-deftest test-org
/get-outline-path
()
1729 "Test `org-get-outline-path' specifications."
1730 ;; Top-level headlines have no outline path.
1732 (org-test-with-temp-text "* H"
1733 (org-get-outline-path)))
1734 ;; Otherwise, outline path is the path leading to the headline.
1737 (org-test-with-temp-text "* H\n** S<point>"
1738 (org-get-outline-path))))
1739 ;; Find path even when point is not on a headline.
1742 (org-test-with-temp-text "* H\n** S\nText<point>"
1743 (org-get-outline-path))))
1744 ;; TODO keywords, tags and statistics cookies are ignored.
1747 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1748 (org-get-outline-path))))
1749 ;; Links are replaced with their description or their path.
1752 (org-test-with-temp-text
1753 "* [[http://orgmode.org][Org]]\n** S<point>"
1754 (org-get-outline-path))))
1756 (equal '("http://orgmode.org")
1757 (org-test-with-temp-text
1758 "* [[http://orgmode.org]]\n** S<point>"
1759 (org-get-outline-path))))
1760 ;; When WITH-SELF is non-nil, include current heading.
1763 (org-test-with-temp-text "* H"
1764 (org-get-outline-path t
))))
1767 (org-test-with-temp-text "* H\n** S\nText<point>"
1768 (org-get-outline-path t
))))
1769 ;; Using cache is transparent to the user.
1772 (org-test-with-temp-text "* H\n** S<point>"
1773 (setq org-outline-path-cache nil
)
1774 (org-get-outline-path nil t
))))
1775 ;; Do not corrupt cache when finding outline path in distant part of
1779 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1780 (setq org-outline-path-cache nil
)
1781 (org-get-outline-path nil t
)
1782 (search-forward "S2")
1783 (org-get-outline-path nil t
))))
1784 ;; Do not choke on empty headlines.
1786 (org-test-with-temp-text "* H\n** <point>"
1787 (org-get-outline-path)))
1789 (org-test-with-temp-text "* \n** H<point>"
1790 (org-get-outline-path))))
1792 (ert-deftest test-org
/format-outline-path
()
1793 "Test `org-format-outline-path' specifications."
1795 (string= (org-format-outline-path (list "one" "two" "three"))
1799 (string= (org-format-outline-path '())
1802 (string= (org-format-outline-path '(nil))
1804 ;; Empty path and prefix.
1806 (string= (org-format-outline-path '() nil
">>")
1808 ;; Trailing whitespace in headings.
1810 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1812 ;; Non-default prefix and separators.
1814 (string= (org-format-outline-path (list "one" "two" "three") nil
">>" "|")
1815 ">>|one|two|three"))
1818 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1820 ;; Give a very narrow width.
1822 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1824 ;; Give a prefix that extends beyond the width.
1826 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1830 (ert-deftest test-org
/map-entries
()
1831 "Test `org-map-entries' specifications."
1835 (org-test-with-temp-text "* Level 1\n** Level 2"
1836 (org-map-entries #'point
))))
1840 (org-test-with-temp-text "* Level 1\n** Level 2"
1841 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL=1")))))
1844 (org-test-with-temp-text "* Level 1\n** Level 2"
1845 (let (org-odd-levels-only) (org-map-entries #'point
"LEVEL>1")))))
1849 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1850 (org-map-entries #'point
"yes"))))
1853 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1854 (org-map-entries #'point
"+yes-a"))))
1857 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1858 (org-map-entries #'point
"{yes?}"))))
1862 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1863 (org-map-entries #'point
"PRIORITY=\"A\""))))
1867 (org-test-with-temp-text "
1869 SCHEDULED: <2012-03-29 thu.>
1871 SCHEDULED: <2014-03-04 tue.>"
1872 (org-map-entries #'point
"SCHEDULED=\"<2014-03-04 tue.>\""))))
1875 (org-test-with-temp-text "
1877 SCHEDULED: <2012-03-29 thu.>
1879 SCHEDULED: <2014-03-04 tue.>"
1880 (org-map-entries #'point
"SCHEDULED<\"<2013-01-01>\""))))
1881 ;; Regular property match.
1884 (org-test-with-temp-text "
1893 (org-map-entries #'point
"TEST=1"))))
1894 ;; Multiple criteria.
1897 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1898 (let (org-odd-levels-only
1899 (org-use-tag-inheritance nil
))
1900 (org-map-entries #'point
"yes+LEVEL=1")))))
1904 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1905 (let (org-odd-levels-only)
1906 (org-map-entries #'point
"LEVEL=2|no")))))
1909 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1910 (let (org-odd-levels-only)
1911 (org-map-entries #'point
"yes|no")))))
1915 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1916 (let (org-odd-levels-only)
1917 (org-map-entries #'point
"yes&no"))))))
1919 (ert-deftest test-org
/edit-headline
()
1920 "Test `org-edit-headline' specifications."
1923 (org-test-with-temp-text "* A"
1924 (org-edit-headline "B")
1926 ;; Handle empty headings.
1929 (org-test-with-temp-text "* A"
1930 (org-edit-headline "")
1934 (org-test-with-temp-text "* "
1935 (org-edit-headline "A")
1937 ;; Handle TODO keywords and priority cookies.
1940 (org-test-with-temp-text "* TODO A"
1941 (org-edit-headline "B")
1945 (org-test-with-temp-text "* [#A] A"
1946 (org-edit-headline "B")
1949 (equal "* TODO [#A] B"
1950 (org-test-with-temp-text "* TODO [#A] A"
1951 (org-edit-headline "B")
1955 (org-test-with-temp-text "* A :tag:"
1956 (let ((org-tags-column 4)) (org-edit-headline "B"))
1963 (ert-deftest test-org
/set-regexps-and-options
()
1964 "Test `org-set-regexps-and-options' specifications."
1968 (let ((org-tag-alist '(("A")))
1969 (org-tag-persistent-alist nil
))
1970 (org-test-with-temp-text ""
1972 org-current-tag-alist
))))
1975 (let ((org-tag-alist '(("A")))
1976 (org-tag-persistent-alist nil
))
1977 (org-test-with-temp-text "#+TAGS: B"
1979 org-current-tag-alist
))))
1981 (equal '(("C") ("B"))
1982 (let ((org-tag-alist '(("A")))
1983 (org-tag-persistent-alist '(("C"))))
1984 (org-test-with-temp-text "#+TAGS: B"
1986 org-current-tag-alist
))))
1989 (let ((org-tag-alist '(("A")))
1990 (org-tag-persistent-alist '(("C"))))
1991 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1993 org-current-tag-alist
))))
1995 (equal '(("A" . ?a
) ("B") ("C"))
1996 (let ((org-tag-persistant-alist nil
))
1997 (org-test-with-temp-text "#+TAGS: A(a) B C"
1999 org-current-tag-alist
))))
2001 (equal '(("A") (:newline
) ("B"))
2002 (let ((org-tag-persistent-alist nil
))
2003 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
2005 org-current-tag-alist
))))
2007 (equal '((:startgroup
) ("A") ("B") (:endgroup
) ("C"))
2008 (let ((org-tag-persistent-alist nil
))
2009 (org-test-with-temp-text "#+TAGS: { A B } C"
2011 org-current-tag-alist
))))
2013 (equal '((:startgroup
) ("A") (:grouptags
) ("B") ("C") (:endgroup
))
2014 (let ((org-tag-persistent-alist nil
))
2015 (org-test-with-temp-text "#+TAGS: { A : B C }"
2017 org-current-tag-alist
))))
2019 (equal '(("A" "B" "C"))
2020 (let ((org-tag-persistent-alist nil
))
2021 (org-test-with-temp-text "#+TAGS: { A : B C }"
2023 org-tag-groups-alist
))))
2025 (equal '((:startgrouptag
) ("A") (:grouptags
) ("B") ("C") (:endgrouptag
))
2026 (let ((org-tag-persistent-alist nil
))
2027 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2029 org-current-tag-alist
))))
2031 (equal '(("A" "B" "C"))
2032 (let ((org-tag-persistent-alist nil
))
2033 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
2035 org-tag-groups-alist
))))
2036 ;; FILETAGS keyword.
2038 (equal '("A" "B" "C")
2039 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
2042 ;; PROPERTY keyword. Property names are case-insensitive.
2045 (org-test-with-temp-text "#+PROPERTY: var foo=1"
2047 (cdr (assoc "var" org-file-properties
)))))
2051 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
2053 (cdr (assoc "var" org-file-properties
)))))
2057 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
2059 (cdr (assoc "var" org-file-properties
)))))
2063 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
2065 org-archive-location
)))
2066 ;; CATEGORY keyword.
2069 (org-test-with-temp-text "#+CATEGORY: test"
2074 (org-test-with-temp-text "#+CATEGORY: test"
2076 (cdr (assoc "CATEGORY" org-file-properties
)))))
2079 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2080 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2082 org-columns-default-format
)))
2083 ;; CONSTANTS keyword. Constants names are case sensitive.
2085 (equal '("299792458." "3.14")
2086 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2089 (lambda (n) (cdr (assoc n org-table-formula-constants-local
)))
2093 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2095 (cdr (assoc "pi" org-table-formula-constants-local
)))))
2098 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2100 (cdr (assoc "PI" org-table-formula-constants-local
)))))
2105 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2107 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local
)))
2109 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2113 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2115 (list org-highest-priority org-lowest-priority org-default-priority
))))
2119 (org-test-with-temp-text "#+PRIORITIES: X Z"
2121 (list org-highest-priority org-lowest-priority org-default-priority
))))
2125 (org-test-with-temp-text "#+STARTUP: fold odd"
2127 (list org-startup-folded org-odd-levels-only
))))
2130 (equal '(("A" "B") ("C"))
2131 (org-test-with-temp-text "#+TODO: A B | C"
2133 (list org-not-done-keywords org-done-keywords
))))
2135 (equal '(("A" "C") ("B" "D"))
2136 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2138 (list org-not-done-keywords org-done-keywords
))))
2140 (equal '(("A" "B") ("C"))
2141 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2143 (list org-not-done-keywords org-done-keywords
))))
2145 (equal '((:startgroup
) ("A" . ?a
) (:endgroup
))
2146 (org-test-with-temp-text "#+TODO: A(a)"
2148 org-todo-key-alist
)))
2150 (equal '(("D" note nil
) ("C" time nil
) ("B" note time
))
2151 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2153 org-todo-log-states
)))
2154 ;; Enter SETUPFILE keyword.
2157 (org-test-with-temp-text
2158 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
2160 (cdr (assoc "a" org-file-properties
))))))
2168 (ert-deftest test-org
/coderef
()
2169 "Test coderef links specifications."
2171 (org-test-with-temp-text "
2172 #+BEGIN_SRC emacs-lisp
2177 (looking-at "(ref:sc)")))
2178 ;; Find coderef even with alternate label format.
2180 (org-test-with-temp-text "
2181 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2186 (looking-at "{ref:sc}"))))
2190 (ert-deftest test-org
/custom-id
()
2191 "Test custom ID links specifications."
2193 (org-test-with-temp-text
2194 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2196 (looking-at-p "\\* H1")))
2197 ;; Throw an error on false positives.
2199 (org-test-with-temp-text
2200 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2202 (looking-at-p "\\* H1"))))
2206 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2207 ;; a named element (#+name: text) and to headlines (* Text).
2209 (ert-deftest test-org
/fuzzy-links
()
2210 "Test fuzzy links specifications."
2211 ;; Fuzzy link goes in priority to a matching target.
2213 (org-test-with-temp-text
2214 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2215 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2216 (looking-at "<<Test>>")))
2217 ;; Then fuzzy link points to an element with a given name.
2219 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2220 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2221 (looking-at "#\\+NAME: Test")))
2222 ;; A target still lead to a matching headline otherwise.
2224 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2225 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2226 (looking-at "\\* Head2")))
2227 ;; With a leading star in link, enforce heading match.
2229 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2230 (let ((org-link-search-must-match-exact-headline nil
)) (org-open-at-point))
2231 (looking-at "\\* Test")))
2232 ;; With a leading star in link, enforce exact heading match, even
2233 ;; with `org-link-search-must-match-exact-headline' set to nil.
2235 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2236 (let ((org-link-search-must-match-exact-headline nil
))
2237 (org-open-at-point))))
2238 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2240 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2241 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2242 (looking-at "\\* Test")))
2244 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2245 (let ((org-link-search-must-match-exact-headline t
)) (org-open-at-point))
2246 (looking-at "\\* Test")))
2247 ;; Heading match should not care about spaces, cookies, TODO
2248 ;; keywords, priorities, and tags. However, TODO keywords are
2252 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2253 (org-test-with-temp-text
2254 (concat first-line
"\nFoo Bar\n<point>[[*Test 1 2]]")
2255 (let ((org-link-search-must-match-exact-headline nil
)
2256 (org-todo-regexp "TODO"))
2257 (org-open-at-point))
2258 (looking-at (regexp-quote first-line
)))))
2260 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2261 (let ((org-link-search-must-match-exact-headline nil
)
2262 (org-todo-regexp "TODO"))
2263 (org-open-at-point))))
2264 ;; Heading match should still be exact.
2266 (org-test-with-temp-text "
2267 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2270 (let ((org-link-search-must-match-exact-headline nil
)
2271 (org-todo-regexp "TODO"))
2272 (org-open-at-point))))
2274 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2275 (let ((org-link-search-must-match-exact-headline nil
)
2276 (org-todo-regexp "TODO"))
2277 (org-open-at-point))
2278 (looking-at-p (regexp-quote "** Test 1 2"))))
2279 ;; Heading match ignores COMMENT keyword.
2281 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2283 (looking-at "\\* COMMENT Test")))
2285 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2287 (looking-at "\\* TODO COMMENT Test")))
2288 ;; Correctly un-hexify fuzzy links.
2290 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2294 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2297 ;; Match search strings containing newline characters, including
2300 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2301 (let ((file (buffer-file-name)))
2302 (goto-char (point-max))
2303 (insert (format "[[file:%s::line1 line2]]" file
))
2305 (let ((org-link-search-must-match-exact-headline nil
))
2306 (org-open-at-point 0))
2307 (looking-at-p "line1"))))
2309 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2310 (let ((file (buffer-file-name)))
2311 (goto-char (point-max))
2312 (insert (format "[[file:%s::line1 line2]]" file
))
2314 (let ((org-link-search-must-match-exact-headline nil
))
2315 (org-open-at-point 0))
2316 (looking-at-p "line1")))))
2320 (ert-deftest test-org
/org-link-escape-ascii-character
()
2321 "Escape an ascii character."
2325 (org-link-escape "["))))
2327 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
2328 "Escape an ascii control character."
2332 (org-link-escape "\t"))))
2334 (ert-deftest test-org
/org-link-escape-multibyte-character
()
2335 "Escape an unicode multibyte character."
2339 (org-link-escape "€"))))
2341 (ert-deftest test-org
/org-link-escape-custom-table
()
2342 "Escape string with custom character table."
2346 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
2348 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
2349 "Escape string with custom table merged with default table."
2352 "%5BF%6F%6F%3A%42ar%0A%5D"
2353 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
2355 (ert-deftest test-org
/org-link-unescape-ascii-character
()
2356 "Unescape an ascii character."
2360 (org-link-unescape "%5B"))))
2362 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
2363 "Unescpae an ascii control character."
2367 (org-link-unescape "%0A"))))
2369 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
2370 "Unescape unicode multibyte character."
2374 (org-link-unescape "%E2%82%AC"))))
2376 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
2377 "Unescape old style percent escaped character."
2380 "à âçèéêîôùû"
2381 (decode-coding-string
2382 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
2384 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
2385 "Escape and unescape a URL that includes an escaped char.
2386 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2389 "http://some.host.com/form?&id=blah%2Bblah25"
2391 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2395 (ert-deftest test-org
/open-at-point-in-keyword
()
2396 "Does `org-open-at-point' open link in a keyword line?"
2398 (org-test-with-temp-text
2399 "<<top>>\n#+KEYWORD: <point>[[top]]"
2400 (org-open-at-point) t
)))
2402 (ert-deftest test-org
/open-at-point-in-property
()
2403 "Does `org-open-at-point' open link in property drawer?"
2405 (org-test-with-temp-text
2408 :URL: <point>[[*Headline]]
2410 (org-open-at-point) t
)))
2412 (ert-deftest test-org
/open-at-point-in-comment
()
2413 "Does `org-open-at-point' open link in a commented line?"
2415 (org-test-with-temp-text
2416 "<<top>>\n# <point>[[top]]"
2417 (org-open-at-point) t
)))
2419 (ert-deftest test-org
/open-at-point
/inline-image
()
2420 "Test `org-open-at-point' on nested links."
2422 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2426 (ert-deftest test-org
/open-at-point
/radio-target
()
2427 "Test `org-open-at-point' on radio targets."
2429 (org-test-with-temp-text "<<<target>>> <point>target"
2430 (org-update-radio-target-regexp)
2432 (eq (org-element-type (org-element-context)) 'radio-target
))))
2436 (ert-deftest test-org
/store-link
()
2437 "Test `org-store-link' specifications."
2438 ;; On a headline, link to that headline. Use heading as the
2439 ;; description of the link.
2441 (let (org-store-link-props org-stored-links
)
2442 (org-test-with-temp-text-in-file "* H1"
2443 (let ((file (buffer-file-name)))
2444 (equal (format "[[file:%s::*H1][H1]]" file
)
2445 (org-store-link nil
))))))
2446 ;; On a headline, remove any link from description.
2448 (let (org-store-link-props org-stored-links
)
2449 (org-test-with-temp-text-in-file "* [[#l][d]]"
2450 (let ((file (buffer-file-name)))
2451 (equal (format "[[file:%s::*%s][d]]"
2453 (org-link-escape "[[#l][d]]"))
2454 (org-store-link nil
))))))
2456 (let (org-store-link-props org-stored-links
)
2457 (org-test-with-temp-text-in-file "* [[l]]"
2458 (let ((file (buffer-file-name)))
2459 (equal (format "[[file:%s::*%s][l]]" file
(org-link-escape "[[l]]"))
2460 (org-store-link nil
))))))
2462 (let (org-store-link-props org-stored-links
)
2463 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2464 (let ((file (buffer-file-name)))
2465 (equal (format "[[file:%s::*%s][d1 d2]]"
2467 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2468 (org-store-link nil
))))))
2469 ;; On a named element, link to that element.
2471 (let (org-store-link-props org-stored-links
)
2472 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2473 (let ((file (buffer-file-name)))
2474 (equal (format "[[file:%s::foo][foo]]" file
)
2475 (org-store-link nil
)))))))
2480 (ert-deftest test-org
/accumulated-properties-in-drawers
()
2481 "Ensure properties accumulate in subtree drawers."
2482 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2483 (org-babel-next-src-block)
2484 (should (equal '(2 1) (org-babel-execute-src-block)))))
2486 (ert-deftest test-org
/custom-properties
()
2487 "Test custom properties specifications."
2490 (let ((org-custom-properties '("FOO")))
2491 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2492 (org-toggle-custom-properties-visibility)
2493 (org-invisible-p2))))
2494 ;; Properties are case-insensitive.
2496 (let ((org-custom-properties '("FOO")))
2497 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2498 (org-toggle-custom-properties-visibility)
2499 (org-invisible-p2))))
2501 (let ((org-custom-properties '("foo")))
2502 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2503 (org-toggle-custom-properties-visibility)
2504 (org-invisible-p2))))
2505 ;; Multiple custom properties in the same drawer.
2507 (let ((org-custom-properties '("FOO" "BAR")))
2508 (org-test-with-temp-text
2509 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2510 (org-toggle-custom-properties-visibility)
2511 (and (org-invisible-p2)
2512 (not (progn (forward-line) (org-invisible-p2)))
2513 (progn (forward-line) (org-invisible-p2))))))
2514 ;; Hide custom properties with an empty value.
2516 (let ((org-custom-properties '("FOO")))
2517 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2518 (org-toggle-custom-properties-visibility)
2519 (org-invisible-p2))))
2520 ;; Do not hide fake properties.
2522 (let ((org-custom-properties '("FOO")))
2523 (org-test-with-temp-text ":FOO: val\n"
2524 (org-toggle-custom-properties-visibility)
2525 (org-invisible-p2))))
2527 (let ((org-custom-properties '("A")))
2528 (org-test-with-temp-text
2529 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2530 (org-toggle-custom-properties-visibility)
2531 (org-invisible-p2)))))
2537 (ert-deftest test-org
/mark-subtree
()
2538 "Test `org-mark-subtree' specifications."
2539 ;; Error when point is before first headline.
2541 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2542 (progn (transient-mark-mode 1)
2543 (org-mark-subtree))))
2544 ;; Without argument, mark current subtree.
2548 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2549 (progn (transient-mark-mode 1)
2552 (list (region-beginning) (region-end))))))
2553 ;; With an argument, move ARG up.
2557 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2558 (progn (transient-mark-mode 1)
2560 (org-mark-subtree 1)
2561 (list (region-beginning) (region-end))))))
2562 ;; Do not get fooled by inlinetasks.
2563 (when (featurep 'org-inlinetask
)
2566 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2567 (progn (transient-mark-mode 1)
2569 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2570 (region-beginning)))))))
2576 (ert-deftest test-org
/in-regexp
()
2577 "Test `org-in-regexp' specifications."
2580 (org-test-with-temp-text "xx ab<point>c xx"
2581 (org-in-regexp "abc")))
2583 (org-test-with-temp-text "xx abc <point>xx"
2584 (org-in-regexp "abc")))
2585 ;; Return non-nil even with multiple matching regexps in the same
2588 (org-test-with-temp-text "abc xx ab<point>c xx"
2589 (org-in-regexp "abc")))
2590 ;; With optional argument NLINES, check extra lines around point.
2592 (org-test-with-temp-text "A\nB<point>\nC"
2593 (org-in-regexp "A\nB\nC")))
2595 (org-test-with-temp-text "A\nB<point>\nC"
2596 (org-in-regexp "A\nB\nC" 1)))
2598 (org-test-with-temp-text "A\nB\nC<point>"
2599 (org-in-regexp "A\nB\nC" 1)))
2600 ;; When optional argument VISUALLY is non-nil, return nil if at
2601 ;; regexp boundaries.
2603 (org-test-with-temp-text "xx abc<point> xx"
2604 (org-in-regexp "abc")))
2606 (org-test-with-temp-text "xx abc<point> xx"
2607 (org-in-regexp "abc" nil t
))))
2609 (ert-deftest test-org
/sort-entries
()
2610 "Test `org-sort-entries'."
2611 ;; Sort alphabetically.
2613 (equal "\n* abc\n* def\n* xyz\n"
2614 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2615 (org-sort-entries nil ?a
)
2618 (equal "\n* xyz\n* def\n* abc\n"
2619 (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
2620 (org-sort-entries nil ?A
)
2622 ;; Sort numerically.
2624 (equal "\n* 1\n* 2\n* 10\n"
2625 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2626 (org-sort-entries nil ?n
)
2629 (equal "\n* 10\n* 2\n* 1\n"
2630 (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
2631 (org-sort-entries nil ?N
)
2633 ;; Sort by custom function.
2635 (equal "\n* b\n* aa\n* ccc\n"
2636 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2637 (org-sort-entries nil ?f
2639 (length (buffer-substring (point-at-bol)
2644 (equal "\n* ccc\n* aa\n* b\n"
2645 (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
2646 (org-sort-entries nil ?F
2648 (length (buffer-substring (point-at-bol)
2652 ;; Sort by TODO keyword.
2654 (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
2655 (org-test-with-temp-text
2656 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2657 (org-sort-entries nil ?o
)
2660 (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
2661 (org-test-with-temp-text
2662 "\n* TODO h1\n* DONE h2\n* TODO h3\n"
2663 (org-sort-entries nil ?O
)
2665 ;; Sort by priority.
2667 (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
2668 (org-test-with-temp-text
2669 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2670 (org-sort-entries nil ?p
)
2673 (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
2674 (org-test-with-temp-text
2675 "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
2676 (org-sort-entries nil ?P
)
2678 ;; Sort by creation time.
2688 (org-test-with-temp-text
2697 (org-sort-entries nil ?c
)
2700 ;; Sort by scheduled date.
2704 SCHEDULED: <2017-05-06 Sat>
2706 SCHEDULED: <2017-05-08 Mon>
2708 DEADLINE: <2017-05-09 Tue>
2710 DEADLINE: <2017-05-07 Sun>
2712 (org-test-with-temp-text
2715 DEADLINE: <2017-05-09 Tue>
2717 DEADLINE: <2017-05-07 Sun>
2719 SCHEDULED: <2017-05-08 Mon>
2721 SCHEDULED: <2017-05-06 Sat>
2723 (org-sort-entries nil ?s
)
2725 ;; Sort by deadline date.
2729 DEADLINE: <2017-05-07 Sun>
2731 DEADLINE: <2017-05-09 Tue>
2733 SCHEDULED: <2017-05-08 Mon>
2735 SCHEDULED: <2017-05-06 Sat>
2737 (org-test-with-temp-text
2740 DEADLINE: <2017-05-09 Tue>
2742 DEADLINE: <2017-05-07 Sun>
2744 SCHEDULED: <2017-05-08 Mon>
2746 SCHEDULED: <2017-05-06 Sat>
2748 (org-sort-entries nil ?d
)
2750 ;; Sort by any date/time
2754 SCHEDULED: <2017-05-06 Sat>
2756 DEADLINE: <2017-05-07 Sun>
2758 SCHEDULED: <2017-05-08 Mon>
2760 DEADLINE: <2017-05-09 Tue>
2762 (org-test-with-temp-text
2765 DEADLINE: <2017-05-09 Tue>
2767 DEADLINE: <2017-05-07 Sun>
2769 SCHEDULED: <2017-05-08 Mon>
2771 SCHEDULED: <2017-05-06 Sat>
2773 (org-sort-entries nil ?t
)
2775 ;; Sort by clocking time.
2780 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2781 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2785 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2786 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2789 (org-test-with-temp-text
2793 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2794 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
2798 CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
2799 CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
2802 (org-sort-entries nil ?k
)
2808 (ert-deftest test-org
/forward-heading-same-level
()
2809 "Test `org-forward-heading-same-level' specifications."
2810 ;; Test navigation at top level, forward and backward.
2813 (org-test-with-temp-text "* H1\n* H2"
2814 (org-forward-heading-same-level 1)
2815 (buffer-substring-no-properties (point) (line-end-position)))))
2818 (org-test-with-temp-text "* H1\n<point>* H2"
2819 (org-forward-heading-same-level -
1)
2820 (buffer-substring-no-properties (point) (line-end-position)))))
2821 ;; Test navigation in a sub-tree, forward and backward.
2824 (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
2825 (org-forward-heading-same-level 1)
2826 (buffer-substring-no-properties (point) (line-end-position)))))
2829 (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
2830 (org-forward-heading-same-level -
1)
2831 (buffer-substring-no-properties (point) (line-end-position)))))
2832 ;; Stop at first or last sub-heading.
2835 (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
2836 (org-forward-heading-same-level 1)
2837 (buffer-substring-no-properties (point) (line-end-position)))))
2840 (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
2841 (org-forward-heading-same-level -
1)
2842 (buffer-substring-no-properties (point) (line-end-position)))))
2843 ;; Allow multiple moves.
2846 (org-test-with-temp-text "* H1\n* H2\n* H3"
2847 (org-forward-heading-same-level 2)
2848 (buffer-substring-no-properties (point) (line-end-position)))))
2851 (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
2852 (org-forward-heading-same-level -
2)
2853 (buffer-substring-no-properties (point) (line-end-position)))))
2854 ;; Ignore spurious moves when first (or last) sibling is reached.
2857 (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
2858 (org-forward-heading-same-level 100)
2859 (buffer-substring-no-properties (point) (line-end-position)))))
2862 (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
2863 (org-forward-heading-same-level -
100)
2864 (buffer-substring-no-properties (point) (line-end-position))))))
2866 (ert-deftest test-org
/end-of-meta-data
()
2867 "Test `org-end-of-meta-data' specifications."
2868 ;; Skip planning line.
2870 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2871 (org-end-of-meta-data)
2873 ;; Skip properties drawer.
2875 (org-test-with-temp-text
2876 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2877 (org-end-of-meta-data)
2881 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2882 (org-end-of-meta-data)
2884 ;; Nothing to skip, go to first line.
2886 (org-test-with-temp-text "* Headline\nContents"
2887 (org-end-of-meta-data)
2888 (looking-at "Contents")))
2889 ;; With option argument, skip empty lines, regular drawers and
2892 (org-test-with-temp-text "* Headline\n\nContents"
2893 (org-end-of-meta-data t
)
2894 (looking-at "Contents")))
2896 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2897 (org-end-of-meta-data t
)
2898 (looking-at "Contents")))
2900 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2901 (org-end-of-meta-data t
)
2902 (looking-at "Contents")))
2903 ;; Special case: do not skip incomplete drawers.
2905 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2906 (org-end-of-meta-data t
)
2907 (looking-at ":LOGBOOK:")))
2908 ;; Special case: Be careful about consecutive headlines.
2910 (org-test-with-temp-text "* H1\n*H2\nContents"
2911 (org-end-of-meta-data t
)
2912 (looking-at "Contents"))))
2914 (ert-deftest test-org
/beginning-of-line
()
2915 "Test `org-beginning-of-line' specifications."
2916 ;; Move to beginning of line. If current line in invisible, move to
2917 ;; beginning of visible line instead.
2919 (org-test-with-temp-text "Some text\nSome other text<point>"
2920 (org-beginning-of-line)
2923 (org-test-with-temp-text "* H1\n** H2<point>"
2925 (org-beginning-of-line)
2926 (= (line-beginning-position) 1)))
2927 ;; With `visual-line-mode' active, move to beginning of visual line.
2929 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2931 (dotimes (i 1000) (insert "very "))
2932 (org-beginning-of-line)
2934 ;; In a wide headline, with `visual-line-mode', prefer going to the
2935 ;; beginning of a visual line than to the logical beginning of line,
2936 ;; even if special movement is active.
2938 (org-test-with-temp-text "* A <point>long headline"
2940 (dotimes (i 1000) (insert "very "))
2941 (goto-char (point-max))
2942 (org-beginning-of-line)
2945 (org-test-with-temp-text "* A <point>long headline"
2947 (dotimes (i 1000) (insert "very "))
2948 (goto-char (point-max))
2949 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line))
2951 ;; At an headline with special movement, first move at beginning of
2952 ;; title, then at the beginning of line, rinse, repeat.
2954 (org-test-with-temp-text "* TODO Headline<point>"
2955 (let ((org-special-ctrl-a/e t
))
2956 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2957 (progn (org-beginning-of-line) (bolp))
2958 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2960 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2961 (let ((org-special-ctrl-a/e t
))
2962 (org-beginning-of-line)
2963 (looking-at "Headline"))))
2965 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2966 (let ((org-special-ctrl-a/e
'(t . nil
)))
2967 (org-beginning-of-line)
2968 (looking-at "Headline"))))
2970 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2971 (let ((org-special-ctrl-a/e
'(nil . nil
)))
2972 (org-beginning-of-line)
2973 (looking-at "Headline"))))
2974 ;; At an headline with reversed movement, first move to beginning of
2975 ;; line, then to the beginning of title.
2977 (org-test-with-temp-text "* TODO Headline<point>"
2978 (let ((org-special-ctrl-a/e
'reversed
)
2979 (this-command last-command
))
2980 (and (progn (org-beginning-of-line) (bolp))
2981 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2983 (org-test-with-temp-text "* TODO Headline<point>"
2984 (let ((org-special-ctrl-a/e
'(reversed . nil
))
2985 (this-command last-command
))
2986 (and (progn (org-beginning-of-line) (bolp))
2987 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2989 (org-test-with-temp-text "* TODO Headline<point>"
2990 (let ((org-special-ctrl-a/e
'(t . nil
))
2991 (this-command last-command
))
2992 (and (progn (org-beginning-of-line) (bolp))
2993 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2994 ;; At an item with special movement, first move after to beginning
2995 ;; of title, then to the beginning of line, rinse, repeat.
2997 (org-test-with-temp-text "- [ ] Item<point>"
2998 (let ((org-special-ctrl-a/e t
))
2999 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
3000 (progn (org-beginning-of-line) (bolp))
3001 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3002 ;; At an item with reversed movement, first move to beginning of
3003 ;; line, then to the beginning of title.
3005 (org-test-with-temp-text "- [X] Item<point>"
3006 (let ((org-special-ctrl-a/e
'reversed
)
3007 (this-command last-command
))
3008 (and (progn (org-beginning-of-line) (bolp))
3009 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
3010 ;; Leave point before invisible characters at column 0.
3012 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3013 (let ((org-special-ctrl-a/e nil
))
3014 (org-beginning-of-line)
3017 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
3018 (let ((org-special-ctrl-a/e t
))
3019 (org-beginning-of-line)
3022 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
3024 (org-beginning-of-line)
3026 ;; Special case: Do not error when the buffer contains only a single
3029 (org-test-with-temp-text "*<point>"
3030 (let ((org-special-ctrl-a/e t
)) (org-beginning-of-line) t
)))
3032 (org-test-with-temp-text "*<point>"
3033 (let ((org-special-ctrl-a/e nil
)) (org-beginning-of-line) t
))))
3035 (ert-deftest test-org
/end-of-line
()
3036 "Test `org-end-of-line' specifications."
3039 (org-test-with-temp-text "Some text\nSome other text"
3042 ;; With `visual-line-mode' active, move to end of visible line.
3043 ;; However, never go past ellipsis.
3045 (org-test-with-temp-text "A <point>long line of text\nSome other text"
3047 (dotimes (i 1000) (insert "very "))
3048 (goto-char (point-min))
3052 (org-test-with-temp-text "* A short headline\nSome contents"
3057 ;; In a wide headline, with `visual-line-mode', prefer going to end
3058 ;; of visible line if tags, or end of line, are farther.
3060 (org-test-with-temp-text "* A <point>long headline"
3062 (dotimes (i 1000) (insert "very "))
3063 (goto-char (point-min))
3067 (org-test-with-temp-text "* A <point>long headline :tag:"
3069 (dotimes (i 1000) (insert "very "))
3070 (goto-char (point-min))
3073 ;; At an headline without special movement, go to end of line.
3074 ;; However, never go past ellipsis.
3076 (org-test-with-temp-text "* Headline2b :tag:\n"
3077 (let ((org-special-ctrl-a/e nil
))
3078 (and (progn (org-end-of-line) (eolp))
3079 (progn (org-end-of-line) (eolp))))))
3081 (org-test-with-temp-text "* Headline2b :tag:\n"
3082 (let ((org-special-ctrl-a/e
'(t . nil
)))
3083 (and (progn (org-end-of-line) (eolp))
3084 (progn (org-end-of-line) (eolp))))))
3086 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3088 (let ((org-special-ctrl-a/e nil
))
3090 (= 1 (line-beginning-position)))))
3091 ;; At an headline with special movement, first move before tags,
3092 ;; then at the end of line, rinse, repeat. However, never go past
3095 (org-test-with-temp-text "* Headline1 :tag:\n"
3096 (let ((org-special-ctrl-a/e t
))
3097 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3098 (progn (org-end-of-line) (eolp))
3099 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3101 (org-test-with-temp-text "* Headline1 :tag:\n"
3102 (let ((org-special-ctrl-a/e
'(nil . t
)))
3103 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3104 (progn (org-end-of-line) (eolp))
3105 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3107 (org-test-with-temp-text "* Headline1 :tag:\n"
3108 (let ((org-special-ctrl-a/e
'(nil . nil
)))
3109 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
3110 (progn (org-end-of-line) (eolp))
3111 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3113 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3115 (let ((org-special-ctrl-a/e t
))
3118 (= 1 (line-beginning-position)))))
3119 ;; At an headline, with reversed movement, first go to end of line,
3120 ;; then before tags. However, never go past ellipsis.
3122 (org-test-with-temp-text "* Headline3 :tag:\n"
3123 (let ((org-special-ctrl-a/e
'reversed
)
3124 (this-command last-command
))
3125 (and (progn (org-end-of-line) (eolp))
3126 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3128 (org-test-with-temp-text "* Headline3 :tag:\n"
3129 (let ((org-special-ctrl-a/e
'(nil . reversed
))
3130 (this-command last-command
))
3131 (and (progn (org-end-of-line) (eolp))
3132 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3134 (org-test-with-temp-text "* Headline3 :tag:\n"
3135 (let ((org-special-ctrl-a/e
'(nil . t
))
3136 (this-command last-command
))
3137 (and (progn (org-end-of-line) (eolp))
3138 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
3140 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
3142 (let ((org-special-ctrl-a/e
'reversed
))
3144 (= 1 (line-beginning-position)))))
3145 ;; At a block without hidden contents.
3147 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3148 (progn (org-end-of-line) (eolp))))
3149 ;; At a block with hidden contents.
3151 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
3152 (let ((org-special-ctrl-a/e t
))
3153 (org-hide-block-toggle)
3156 ;; Get past invisible characters at the end of line.
3158 (org-test-with-temp-text "[[http://orgmode.org]]"
3162 (ert-deftest test-org
/open-line
()
3163 "Test `org-open-line' specifications."
3164 ;; Call `open-line' outside of tables.
3167 (org-test-with-temp-text "Text"
3170 ;; At a table, create a row above.
3172 (equal "\n| |\n| a |"
3173 (org-test-with-temp-text "\n<point>| a |"
3176 ;; At the very first character of the buffer, also call `open-line'.
3179 (org-test-with-temp-text "| a |"
3182 ;; Narrowing does not count.
3184 (equal "Text\n| |\n| a |"
3185 (org-test-with-temp-text "Text\n<point>| a |"
3186 (narrow-to-region (point) (point-max))
3191 (ert-deftest test-org
/forward-sentence
()
3192 "Test `org-forward-sentence' specifications."
3193 ;; At the end of a table cell, move to the end of the next one.
3195 (org-test-with-temp-text "| a<point> | b |"
3196 (org-forward-sentence)
3197 (looking-at " |$")))
3198 ;; Elsewhere in a cell, move to its end.
3200 (org-test-with-temp-text "| a<point>c | b |"
3201 (org-forward-sentence)
3202 (looking-at " | b |$")))
3203 ;; Otherwise, simply call `forward-sentence'.
3205 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3206 (org-forward-sentence)
3207 (looking-at " Sentence 2.")))
3209 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
3210 (org-forward-sentence)
3211 (org-forward-sentence)
3213 ;; At the end of an element, jump to the next one, without stopping
3214 ;; on blank lines in-between.
3216 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
3217 (org-forward-sentence)
3220 (ert-deftest test-org
/backward-sentence
()
3221 "Test `org-backward-sentence' specifications."
3222 ;; At the beginning of a table cell, move to the beginning of the
3225 (org-test-with-temp-text "| a | <point>b |"
3226 (org-backward-sentence)
3227 (looking-at "a | b |$")))
3228 ;; Elsewhere in a cell, move to its beginning.
3230 (org-test-with-temp-text "| a | b<point>c |"
3231 (org-backward-sentence)
3232 (looking-at "bc |$")))
3233 ;; Otherwise, simply call `backward-sentence'.
3235 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3236 (org-backward-sentence)
3237 (looking-at "Sentence 2.")))
3239 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
3240 (org-backward-sentence)
3241 (org-backward-sentence)
3243 ;; Make sure to hit the beginning of a sentence on the same line as
3246 (org-test-with-temp-text "- Line 1\n line <point>2."
3247 (org-backward-sentence)
3248 (looking-at "Line 1"))))
3250 (ert-deftest test-org
/forward-paragraph
()
3251 "Test `org-forward-paragraph' specifications."
3252 ;; At end of buffer, return an error.
3254 (org-test-with-temp-text "Paragraph"
3255 (goto-char (point-max))
3256 (org-forward-paragraph)))
3259 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3260 (org-forward-paragraph)
3264 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
3265 (org-forward-paragraph)
3267 ;; Do not enter elements with invisible contents.
3269 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
3270 (org-hide-block-toggle)
3271 (org-forward-paragraph)
3273 ;; On an affiliated keyword, jump to the beginning of the element.
3275 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
3276 (org-forward-paragraph)
3277 (looking-at "Para")))
3278 ;; On an item or a footnote definition, move to the second element
3281 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
3282 (org-forward-paragraph)
3283 (looking-at " Paragraph")))
3285 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
3286 (org-forward-paragraph)
3287 (looking-at "Paragraph")))
3288 ;; On an item, or a footnote definition, when the first line is
3289 ;; empty, move to the first item.
3291 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
3292 (org-forward-paragraph)
3293 (looking-at " Paragraph")))
3295 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
3296 (org-forward-paragraph)
3297 (looking-at "Paragraph")))
3298 ;; On a table (resp. a property drawer) do not move through table
3299 ;; rows (resp. node properties).
3301 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
3302 (org-forward-paragraph)
3303 (looking-at "Paragraph")))
3305 (org-test-with-temp-text
3306 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
3307 (org-forward-paragraph)
3308 (looking-at "Paragraph")))
3309 ;; On a verse or source block, stop after blank lines.
3311 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
3312 (org-forward-paragraph)
3315 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
3316 (org-forward-paragraph)
3317 (looking-at "L2"))))
3319 (ert-deftest test-org
/backward-paragraph
()
3320 "Test `org-backward-paragraph' specifications."
3321 ;; Error at beginning of buffer.
3323 (org-test-with-temp-text "Paragraph"
3324 (org-backward-paragraph)))
3327 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3328 (goto-char (point-max))
3329 (org-backward-paragraph)
3332 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3333 (goto-char (point-max))
3335 (org-backward-paragraph)
3339 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3340 (goto-char (point-max))
3342 (org-backward-paragraph)
3344 ;; Ignore invisible elements.
3346 (org-test-with-temp-text "* H1\n P1\n* H2"
3348 (goto-char (point-max))
3350 (org-backward-paragraph)
3352 ;; On an affiliated keyword, jump to the first one.
3354 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3355 (search-forward "c2")
3356 (org-backward-paragraph)
3357 (looking-at "#\\+name")))
3358 ;; On the second element in an item or a footnote definition, jump
3359 ;; to item or the definition.
3361 (org-test-with-temp-text "- line1\n\n line2"
3362 (goto-char (point-max))
3364 (org-backward-paragraph)
3365 (looking-at "- line1")))
3367 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3368 (goto-char (point-max))
3370 (org-backward-paragraph)
3371 (looking-at "\\[fn:1\\] line1")))
3372 ;; On a table (resp. a property drawer), ignore table rows
3373 ;; (resp. node properties).
3375 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3376 (goto-char (point-max))
3378 (org-backward-paragraph)
3381 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3382 (org-backward-paragraph)
3383 (looking-at ":PROPERTIES:")))
3384 ;; On a source or verse block, stop before blank lines.
3386 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3387 (search-forward "L3")
3389 (org-backward-paragraph)
3392 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3393 (search-forward "L3")
3395 (org-backward-paragraph)
3396 (looking-at "L2"))))
3398 (ert-deftest test-org
/forward-element
()
3399 "Test `org-forward-element' specifications."
3400 ;; 1. At EOB: should error.
3401 (org-test-with-temp-text "Some text\n"
3402 (goto-char (point-max))
3403 (should-error (org-forward-element)))
3404 ;; 2. Standard move: expected to ignore blank lines.
3405 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3406 (org-forward-element)
3407 (should (looking-at (regexp-quote "Second paragraph."))))
3408 ;; 3. Headline tests.
3409 (org-test-with-temp-text "
3414 ;; 3.1. At an headline beginning: move to next headline at the
3417 (org-forward-element)
3418 (should (looking-at (regexp-quote "** Head 1.2")))
3419 ;; 3.2. At an headline beginning: move to parent headline if no
3420 ;; headline at the same level.
3422 (org-forward-element)
3423 (should (looking-at (regexp-quote "** Head 1.2"))))
3424 ;; 4. Greater element tests.
3425 (org-test-with-temp-text
3426 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3427 ;; 4.1. At a greater element: expected to skip contents.
3428 (org-forward-element)
3429 (should (looking-at (regexp-quote "Outside.")))
3430 ;; 4.2. At the end of greater element contents: expected to skip
3431 ;; to the end of the greater element.
3433 (org-forward-element)
3434 (should (looking-at (regexp-quote "Outside."))))
3436 (org-test-with-temp-text "
3450 ;; 5.1. At list top point: expected to move to the element after
3453 (org-forward-element)
3454 (should (looking-at (regexp-quote "Outside.")))
3455 ;; 5.2. Special case: at the first line of a sub-list, but not at
3456 ;; beginning of line, move to next item.
3459 (org-forward-element)
3460 (should (looking-at "- item2"))
3463 (org-forward-element)
3464 (should (looking-at " - sub2"))
3465 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3467 (org-forward-element)
3468 (should (looking-at (regexp-quote " Inner paragraph.")))
3469 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3471 (org-forward-element)
3472 (should (looking-at (regexp-quote " Inner paragraph.")))
3473 ;; 5.5. At an item: expected to move to next item, if any.
3475 (org-forward-element)
3476 (should (looking-at " - sub3"))))
3478 (ert-deftest test-org
/backward-element
()
3479 "Test `org-backward-element' specifications."
3480 ;; 1. Should error at BOB.
3481 (org-test-with-temp-text " \nParagraph."
3482 (should-error (org-backward-element)))
3483 ;; 2. Should move at BOB when called on the first element in buffer.
3485 (org-test-with-temp-text "\n#+TITLE: test"
3486 (progn (forward-line)
3487 (org-backward-element)
3489 ;; 3. Not at the beginning of an element: move at its beginning.
3490 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3493 (org-backward-element)
3494 (should (looking-at (regexp-quote "Paragraph2."))))
3495 ;; 4. Headline tests.
3496 (org-test-with-temp-text "
3501 ;; 4.1. At an headline beginning: move to previous headline at the
3504 (org-backward-element)
3505 (should (looking-at (regexp-quote "** Head 1.1")))
3506 ;; 4.2. At an headline beginning: move to parent headline if no
3507 ;; headline at the same level.
3509 (org-backward-element)
3510 (should (looking-at (regexp-quote "* Head 1")))
3511 ;; 4.3. At the first top-level headline: should error.
3513 (should-error (org-backward-element)))
3514 ;; 5. At beginning of first element inside a greater element:
3515 ;; expected to move to greater element's beginning.
3516 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3518 (org-backward-element)
3519 (should (looking-at "#\\+BEGIN_CENTER")))
3520 ;; 6. At the beginning of the first element in a section: should
3521 ;; move back to headline, if any.
3523 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3524 (progn (goto-char (point-max))
3526 (org-backward-element)
3527 (org-at-heading-p))))
3529 (org-test-with-temp-text "
3544 ;; 7.1. At beginning of sub-list: expected to move to the
3545 ;; paragraph before it.
3547 (org-backward-element)
3548 (should (looking-at "item1"))
3549 ;; 7.2. At an item in a list: expected to move at previous item.
3551 (org-backward-element)
3552 (should (looking-at " - sub2"))
3554 (org-backward-element)
3555 (should (looking-at "- item1"))
3556 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3559 (org-backward-element)
3560 (should (looking-at " - sub1"))
3562 (org-backward-element)
3563 (should (looking-at "- item1"))
3564 ;; 7.4. At blank-lines before list end: expected to move to top
3567 (org-backward-element)
3568 (should (looking-at "- item1"))))
3570 (ert-deftest test-org
/up-element
()
3571 "Test `org-up-element' specifications."
3572 ;; 1. At BOB or with no surrounding element: should error.
3573 (org-test-with-temp-text "Paragraph."
3574 (should-error (org-up-element)))
3575 (org-test-with-temp-text "* Head1\n* Head2"
3577 (should-error (org-up-element)))
3578 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3580 (should-error (org-up-element)))
3581 ;; 2. At an headline: move to parent headline.
3582 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3585 (should (looking-at "\\* Head1")))
3586 ;; 3. Inside a greater element: move to greater element beginning.
3587 (org-test-with-temp-text
3588 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3591 (should (looking-at "#\\+BEGIN_CENTER")))
3593 (org-test-with-temp-text "* Top
3600 Paragraph within sub2.
3603 ;; 4.1. Within an item: move to the item beginning.
3606 (should (looking-at " - sub2"))
3607 ;; 4.2. At an item in a sub-list: move to parent item.
3610 (should (looking-at "- item1"))
3611 ;; 4.3. At an item in top list: move to beginning of whole list.
3614 (should (looking-at "- item1"))
3615 ;; 4.4. Special case. At very top point: should move to parent of
3619 (should (looking-at "\\* Top"))))
3621 (ert-deftest test-org
/down-element
()
3622 "Test `org-down-element' specifications."
3623 ;; Error when the element hasn't got a recursive type.
3624 (org-test-with-temp-text "Paragraph."
3625 (should-error (org-down-element)))
3626 ;; Error when the element has no contents
3627 (org-test-with-temp-text "* Headline"
3628 (should-error (org-down-element)))
3629 ;; When at a plain-list, move to first item.
3630 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3633 (should (looking-at " - Item 1.1")))
3634 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3636 (should (looking-at " Item 1")))
3637 ;; When at a table, move to first row
3638 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3640 (should (looking-at " a | b |")))
3641 ;; Otherwise, move inside the greater element.
3642 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3644 (should (looking-at "Paragraph"))))
3646 (ert-deftest test-org
/drag-element-backward
()
3647 "Test `org-drag-element-backward' specifications."
3651 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3652 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3653 (org-drag-element-backward)
3657 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3658 (org-test-with-temp-text
3659 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3660 (org-drag-element-backward)
3662 ;; Preserve blank lines.
3664 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3665 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3666 (org-drag-element-backward)
3670 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3671 (org-drag-element-backward)
3672 (looking-at-p "2")))
3673 ;; Error when trying to move first element of buffer.
3675 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3676 (org-drag-element-backward))
3678 ;; Error when trying to swap nested elements.
3680 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3681 (org-drag-element-backward))
3683 ;; Error when trying to swap an headline element and a non-headline
3686 (org-test-with-temp-text "Test.\n<point>* Head 1"
3687 (org-drag-element-backward))
3689 ;; Error when called before first element.
3691 (org-test-with-temp-text "\n<point>"
3692 (org-drag-element-backward))
3694 ;; Preserve visibility of elements and their contents.
3696 (equal '((63 .
82) (26 .
48))
3697 (org-test-with-temp-text "
3705 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3706 (search-backward "- item 1")
3707 (org-drag-element-backward)
3708 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3709 (overlays-in (point-min) (point-max))))))
3710 ;; Pathological case: handle call with point in blank lines right
3711 ;; after a headline.
3713 (equal "* H2\n* H1\nText\n\n"
3714 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3715 (org-drag-element-backward)
3718 (ert-deftest test-org
/drag-element-forward
()
3719 "Test `org-drag-element-forward' specifications."
3720 ;; 1. Error when trying to move first element of buffer.
3721 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3723 (should-error (org-drag-element-forward)))
3724 ;; 2. Error when trying to swap nested elements.
3725 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3727 (should-error (org-drag-element-forward)))
3728 ;; 3. Error when trying to swap a non-headline element and an
3730 (org-test-with-temp-text "Test.\n* Head 1"
3731 (should-error (org-drag-element-forward)))
3732 ;; 4. Error when called before first element.
3734 (org-test-with-temp-text "\n"
3736 (org-drag-element-backward))
3738 ;; 5. Otherwise, swap elements, preserving column and blank lines
3739 ;; between elements.
3740 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3741 (search-forward "graph")
3742 (org-drag-element-forward)
3743 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3744 (should (looking-at " 1")))
3745 ;; 5. Preserve visibility of elements and their contents.
3746 (org-test-with-temp-text "
3754 (while (search-forward "BEGIN_" nil t
) (org-cycle))
3755 (search-backward "#+BEGIN_CENTER")
3756 (org-drag-element-forward)
3759 '((63 .
82) (26 .
48))
3760 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
3761 (overlays-in (point-min) (point-max)))))))
3763 (ert-deftest test-org
/next-block
()
3764 "Test `org-next-block' specifications."
3767 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3769 (looking-at "#\\+BEGIN_CENTER")))
3772 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3773 (let ((case-fold-search nil
))
3775 (looking-at "#\\+begin_center"))))
3776 ;; Ignore current line.
3778 (org-test-with-temp-text
3779 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3781 (looking-at "#\\+BEGIN_CENTER")))
3782 ;; Throw an error when no block is found.
3784 (org-test-with-temp-text "Paragraph"
3785 (org-next-block 1)))
3786 ;; With an argument, skip many blocks at once.
3788 (org-test-with-temp-text
3789 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3791 (looking-at "#\\+BEGIN_QUOTE")))
3792 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3794 (org-test-with-temp-text
3795 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3796 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3797 (looking-at "#\\+BEGIN_QUOTE")))
3798 ;; Optional argument is also case-insensitive.
3800 (org-test-with-temp-text
3801 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3802 (let ((case-fold-search nil
))
3803 (org-next-block 1 nil
"^[ \t]*#\\+BEGIN_QUOTE")
3804 (looking-at "#\\+begin_quote")))))
3806 (ert-deftest test-org
/previous-block
()
3807 "Test `org-previous-block' specifications."
3810 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3811 (org-previous-block 1)
3812 (looking-at "#\\+BEGIN_CENTER")))
3815 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3816 (let ((case-fold-search nil
))
3817 (org-previous-block 1)
3818 (looking-at "#\\+begin_center"))))
3819 ;; Ignore current line.
3821 (org-test-with-temp-text
3822 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3823 (org-previous-block 1)
3824 (looking-at "#\\+BEGIN_QUOTE")))
3825 ;; Throw an error when no block is found.
3827 (org-test-with-temp-text "Paragraph<point>"
3828 (org-previous-block 1)))
3829 ;; With an argument, skip many blocks at once.
3831 (org-test-with-temp-text
3832 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3833 (org-previous-block 2)
3834 (looking-at "#\\+BEGIN_CENTER")))
3835 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3837 (org-test-with-temp-text
3838 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3839 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3840 (looking-at "#\\+BEGIN_QUOTE")))
3841 ;; Optional argument is also case-insensitive.
3843 (org-test-with-temp-text
3844 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3845 (let ((case-fold-search nil
))
3846 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3847 (looking-at "#\\+begin_quote")))))
3850 ;;; Outline structure
3852 (ert-deftest test-org
/demote
()
3853 "Test `org-demote' specifications."
3854 ;; Add correct number of stars according to `org-odd-levels-only'.
3857 (org-test-with-temp-text "* H"
3858 (let ((org-odd-levels-only nil
)) (org-demote))
3859 (org-current-level))))
3862 (org-test-with-temp-text "* H"
3863 (let ((org-odd-levels-only t
)) (org-demote))
3864 (org-current-level))))
3865 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3867 (org-test-with-temp-text "* H :tag:"
3868 (let ((org-tags-column 10)
3869 (org-auto-align-tags t
)
3870 (org-odd-levels-only nil
))
3872 (org-move-to-column 10)
3873 (looking-at-p ":tag:$")))
3875 (org-test-with-temp-text "* H :tag:"
3876 (let ((org-tags-column 10)
3877 (org-auto-align-tags nil
)
3878 (org-odd-levels-only nil
))
3880 (org-move-to-column 10)
3881 (looking-at-p ":tag:$")))
3882 ;; When `org-adapt-indentation' is non-nil, always indent planning
3883 ;; info and property drawers accordingly.
3886 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3887 (let ((org-odd-levels-only nil
)
3888 (org-adapt-indentation t
))
3891 (org-get-indentation))))
3894 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3895 (let ((org-odd-levels-only nil
)
3896 (org-adapt-indentation t
))
3899 (org-get-indentation))))
3902 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3903 (let ((org-odd-levels-only nil
)
3904 (org-adapt-indentation nil
))
3907 (org-get-indentation))))
3908 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3909 ;; section accordingly. Ignore, however, footnote definitions and
3910 ;; inlinetasks boundaries.
3913 (org-test-with-temp-text "* H\n Paragraph"
3914 (let ((org-odd-levels-only nil
)
3915 (org-adapt-indentation t
))
3918 (org-get-indentation))))
3921 (org-test-with-temp-text "* H\n Paragraph"
3922 (let ((org-odd-levels-only nil
)
3923 (org-adapt-indentation nil
))
3926 (org-get-indentation))))
3929 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3930 (let ((org-odd-levels-only nil
)
3931 (org-adapt-indentation t
))
3933 (goto-char (point-max))
3934 (org-get-indentation))))
3937 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3938 (let ((org-odd-levels-only nil
)
3939 (org-adapt-indentation t
))
3941 (goto-char (point-max))
3942 (org-get-indentation))))
3943 (when (featurep 'org-inlinetask
)
3946 (let ((org-inlinetask-min-level 5)
3947 (org-adapt-indentation t
))
3948 (org-test-with-temp-text "* H\n***** I\n***** END"
3951 (org-get-indentation))))))
3952 (when (featurep 'org-inlinetask
)
3955 (let ((org-inlinetask-min-level 5)
3956 (org-adapt-indentation t
))
3957 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3960 (org-get-indentation))))))
3961 ;; Ignore contents of source blocks or example blocks when
3962 ;; indentation should be preserved (through
3963 ;; `org-src-preserve-indentation' or "-i" flag).
3966 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3967 (let ((org-adapt-indentation t
)
3968 (org-src-preserve-indentation nil
))
3971 (org-get-indentation))))
3974 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3975 (let ((org-adapt-indentation t
)
3976 (org-src-preserve-indentation t
))
3979 (org-get-indentation))))
3982 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3983 (let ((org-adapt-indentation t
)
3984 (org-src-preserve-indentation t
))
3987 (org-get-indentation))))
3990 (org-test-with-temp-text
3991 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3992 (let ((org-adapt-indentation t
)
3993 (org-src-preserve-indentation nil
))
3996 (org-get-indentation)))))
3998 (ert-deftest test-org
/promote
()
3999 "Test `org-promote' specifications."
4000 ;; Return an error if headline is to be promoted to level 0, unless
4001 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
4002 ;; headline becomes a comment.
4004 (org-test-with-temp-text "* H"
4005 (let ((org-allow-promoting-top-level-subtree nil
)) (org-promote))))
4008 (org-test-with-temp-text "* H"
4009 (let ((org-allow-promoting-top-level-subtree t
)) (org-promote))
4011 ;; Remove correct number of stars according to
4012 ;; `org-odd-levels-only'.
4015 (org-test-with-temp-text "*** H"
4016 (let ((org-odd-levels-only nil
)) (org-promote))
4017 (org-current-level))))
4020 (org-test-with-temp-text "*** H"
4021 (let ((org-odd-levels-only t
)) (org-promote))
4022 (org-current-level))))
4023 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
4025 (org-test-with-temp-text "** H :tag:"
4026 (let ((org-tags-column 10)
4027 (org-auto-align-tags t
)
4028 (org-odd-levels-only nil
))
4030 (org-move-to-column 10)
4031 (looking-at-p ":tag:$")))
4033 (org-test-with-temp-text "** H :tag:"
4034 (let ((org-tags-column 10)
4035 (org-auto-align-tags nil
)
4036 (org-odd-levels-only nil
))
4038 (org-move-to-column 10)
4039 (looking-at-p ":tag:$")))
4040 ;; When `org-adapt-indentation' is non-nil, always indent planning
4041 ;; info and property drawers.
4044 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4045 (let ((org-odd-levels-only nil
)
4046 (org-adapt-indentation t
))
4049 (org-get-indentation))))
4052 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
4053 (let ((org-odd-levels-only nil
)
4054 (org-adapt-indentation t
))
4057 (org-get-indentation))))
4060 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
4061 (let ((org-odd-levels-only nil
)
4062 (org-adapt-indentation nil
))
4065 (org-get-indentation))))
4066 ;; When `org-adapt-indentation' is non-nil, shift all lines in
4067 ;; section accordingly. Ignore, however, footnote definitions and
4068 ;; inlinetasks boundaries.
4071 (org-test-with-temp-text "** H\n Paragraph"
4072 (let ((org-odd-levels-only nil
)
4073 (org-adapt-indentation t
))
4076 (org-get-indentation))))
4079 (org-test-with-temp-text "** H\n Paragraph"
4080 (let ((org-odd-levels-only nil
)
4081 (org-adapt-indentation nil
))
4084 (org-get-indentation))))
4087 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
4088 (let ((org-odd-levels-only nil
)
4089 (org-adapt-indentation t
))
4092 (org-get-indentation))))
4093 (when (featurep 'org-inlinetask
)
4096 (let ((org-inlinetask-min-level 5)
4097 (org-adapt-indentation t
))
4098 (org-test-with-temp-text "** H\n***** I\n***** END"
4101 (org-get-indentation))))))
4102 (when (featurep 'org-inlinetask
)
4105 (let ((org-inlinetask-min-level 5)
4106 (org-adapt-indentation t
))
4107 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
4110 (org-get-indentation))))))
4111 ;; Give up shifting if it would break document's structure
4115 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
4116 (let ((org-odd-levels-only nil
)
4117 (org-adapt-indentation t
))
4120 (org-get-indentation))))
4123 (org-test-with-temp-text "** H\n Paragraph\n * list."
4124 (let ((org-odd-levels-only nil
)
4125 (org-adapt-indentation t
))
4128 (org-get-indentation))))
4129 ;; Ignore contents of source blocks or example blocks when
4130 ;; indentation should be preserved (through
4131 ;; `org-src-preserve-indentation' or "-i" flag).
4134 (org-test-with-temp-text
4135 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4136 (let ((org-adapt-indentation t
)
4137 (org-src-preserve-indentation nil
)
4138 (org-odd-levels-only nil
))
4141 (org-get-indentation))))
4144 (org-test-with-temp-text
4145 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
4146 (let ((org-adapt-indentation t
)
4147 (org-src-preserve-indentation t
)
4148 (org-odd-levels-only nil
))
4151 (org-get-indentation))))
4154 (org-test-with-temp-text
4155 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
4156 (let ((org-adapt-indentation t
)
4157 (org-src-preserve-indentation t
)
4158 (org-odd-levels-only nil
))
4161 (org-get-indentation))))
4164 (org-test-with-temp-text
4165 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
4166 (let ((org-adapt-indentation t
)
4167 (org-src-preserve-indentation nil
)
4168 (org-odd-levels-only nil
))
4171 (org-get-indentation)))))
4173 (ert-deftest test-org
/org-get-valid-level
()
4174 "Test function `org-get-valid-level' specifications."
4175 (let ((org-odd-levels-only nil
))
4176 (should (equal 1 (org-get-valid-level 0 0)))
4177 (should (equal 1 (org-get-valid-level 0 1)))
4178 (should (equal 2 (org-get-valid-level 0 2)))
4179 (should (equal 3 (org-get-valid-level 0 3)))
4180 (should (equal 1 (org-get-valid-level 1 0)))
4181 (should (equal 2 (org-get-valid-level 1 1)))
4182 (should (equal 23 (org-get-valid-level 1 22)))
4183 (should (equal 1 (org-get-valid-level 1 -
1)))
4184 (should (equal 1 (org-get-valid-level 2 -
1))))
4185 (let ((org-odd-levels-only t
))
4186 (should (equal 1 (org-get-valid-level 0 0)))
4187 (should (equal 1 (org-get-valid-level 0 1)))
4188 (should (equal 3 (org-get-valid-level 0 2)))
4189 (should (equal 5 (org-get-valid-level 0 3)))
4190 (should (equal 1 (org-get-valid-level 1 0)))
4191 (should (equal 3 (org-get-valid-level 1 1)))
4192 (should (equal 3 (org-get-valid-level 2 1)))
4193 (should (equal 5 (org-get-valid-level 3 1)))
4194 (should (equal 5 (org-get-valid-level 4 1)))
4195 (should (equal 43 (org-get-valid-level 1 21)))
4196 (should (equal 1 (org-get-valid-level 1 -
1)))
4197 (should (equal 1 (org-get-valid-level 2 -
1)))
4198 (should (equal 1 (org-get-valid-level 3 -
1)))
4199 (should (equal 3 (org-get-valid-level 4 -
1)))
4200 (should (equal 3 (org-get-valid-level 5 -
1)))))
4205 (ert-deftest test-org
/at-planning-p
()
4206 "Test `org-at-planning-p' specifications."
4209 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
4210 (org-at-planning-p)))
4212 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
4213 (org-at-planning-p)))
4214 ;; Correctly find planning attached to inlinetasks.
4215 (when (featurep 'org-inlinetask
)
4217 (org-test-with-temp-text
4218 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
4219 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4221 (org-test-with-temp-text
4222 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4223 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4225 (org-test-with-temp-text
4226 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
4227 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
4229 (org-test-with-temp-text
4230 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
4231 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
4233 (ert-deftest test-org
/add-planning-info
()
4234 "Test `org-add-planning-info'."
4235 ;; Create deadline when `org-adapt-indentation' is non-nil.
4237 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4238 (org-test-with-temp-text "* H\nParagraph<point>"
4239 (let ((org-adapt-indentation t
))
4240 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4241 (replace-regexp-in-string
4242 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4244 ;; Create deadline when `org-adapt-indentation' is nil.
4246 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4247 (org-test-with-temp-text "* H\nParagraph<point>"
4248 (let ((org-adapt-indentation nil
))
4249 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4250 (replace-regexp-in-string
4251 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4253 ;; Update deadline when `org-adapt-indentation' is non-nil.
4255 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4256 (org-test-with-temp-text "\
4258 DEADLINE: <2015-06-24 Wed>
4260 (let ((org-adapt-indentation t
))
4261 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4262 (replace-regexp-in-string
4263 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4265 ;; Update deadline when `org-adapt-indentation' is nil.
4267 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4268 (org-test-with-temp-text "\
4270 DEADLINE: <2015-06-24 Wed>
4272 (let ((org-adapt-indentation nil
))
4273 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4274 (replace-regexp-in-string
4275 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4277 ;; Schedule when `org-adapt-indentation' is non-nil.
4279 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
4280 (org-test-with-temp-text "* H\nParagraph<point>"
4281 (let ((org-adapt-indentation t
))
4282 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4283 (replace-regexp-in-string
4284 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4286 ;; Schedule when `org-adapt-indentation' is nil.
4288 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
4289 (org-test-with-temp-text "* H\nParagraph<point>"
4290 (let ((org-adapt-indentation nil
))
4291 (org-add-planning-info 'scheduled
"<2015-06-25 Thu>"))
4292 (replace-regexp-in-string
4293 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4295 ;; Add deadline when scheduled.
4299 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
4301 (org-test-with-temp-text "\
4303 SCHEDULED: <2015-06-24 Wed>
4305 (let ((org-adapt-indentation t
))
4306 (org-add-planning-info 'deadline
"<2015-06-25 Thu>"))
4307 (replace-regexp-in-string
4308 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4310 ;; Remove middle entry.
4314 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
4316 (org-test-with-temp-text "\
4318 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4320 (let ((org-adapt-indentation t
))
4321 (org-add-planning-info nil nil
'deadline
))
4322 (replace-regexp-in-string
4323 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4325 ;; Remove last entry and then middle entry (order should not
4330 CLOSED: [2015-06-24]
4332 (org-test-with-temp-text "\
4334 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
4336 (let ((org-adapt-indentation t
))
4337 (org-add-planning-info nil nil
'scheduled
'deadline
))
4338 (replace-regexp-in-string
4339 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
4341 ;; Remove closed when `org-adapt-indentation' is non-nil.
4343 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4344 (org-test-with-temp-text "\
4346 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4348 (let ((org-adapt-indentation t
))
4349 (org-add-planning-info nil nil
'closed
))
4350 (replace-regexp-in-string
4351 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4354 (equal "* H\n Paragraph"
4355 (org-test-with-temp-text "\
4357 CLOSED: [2015-06-25 Thu]
4359 (let ((org-adapt-indentation t
))
4360 (org-add-planning-info nil nil
'closed
))
4361 (replace-regexp-in-string
4362 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4364 ;; Remove closed when `org-adapt-indentation' is nil.
4366 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4367 (org-test-with-temp-text "\
4369 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4371 (let ((org-adapt-indentation nil
))
4372 (org-add-planning-info nil nil
'closed
))
4373 (replace-regexp-in-string
4374 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4377 (equal "* H\nParagraph"
4378 (org-test-with-temp-text "\
4380 CLOSED: [2015-06-25 Thu]
4382 (let ((org-adapt-indentation nil
))
4383 (org-add-planning-info nil nil
'closed
))
4384 (replace-regexp-in-string
4385 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4387 ;; Remove closed entry and delete empty line.
4392 (org-test-with-temp-text "\
4394 CLOSED: [2015-06-24 Wed]
4396 (let ((org-adapt-indentation t
))
4397 (org-add-planning-info nil nil
'closed
))
4398 (replace-regexp-in-string
4399 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4401 ;; Remove one entry and update another.
4403 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4404 (org-test-with-temp-text "\
4406 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4408 (let ((org-adapt-indentation t
))
4409 (org-add-planning-info 'deadline
"<2015-06-25 Thu>" 'scheduled
))
4410 (replace-regexp-in-string
4411 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4414 (ert-deftest test-org
/deadline
()
4415 "Test `org-deadline' specifications."
4416 ;; Insert a new value or replace existing one.
4418 (equal "* H\nDEADLINE: <2012-03-29>\n"
4419 (org-test-with-temp-text "* H"
4420 (let ((org-adapt-indentation nil
)
4421 (org-last-inserted-timestamp nil
))
4422 (org-deadline nil
"<2012-03-29 Tue>"))
4423 (replace-regexp-in-string
4424 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4427 (equal "* H\nDEADLINE: <2014-03-04>"
4428 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4429 (let ((org-adapt-indentation nil
)
4430 (org-last-inserted-timestamp nil
))
4431 (org-deadline nil
"<2014-03-04 Thu>"))
4432 (replace-regexp-in-string
4433 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4435 ;; Accept delta time, e.g., "+2d".
4437 (equal "* H\nDEADLINE: <2015-03-04>\n"
4438 (cl-letf (((symbol-function 'current-time
)
4439 (lambda (&rest args
)
4440 (apply #'encode-time
4441 (org-parse-time-string "2014-03-04")))))
4442 (org-test-with-temp-text "* H"
4443 (let ((org-adapt-indentation nil
)
4444 (org-last-inserted-timestamp nil
))
4445 (org-deadline nil
"+1y"))
4446 (replace-regexp-in-string
4447 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4448 ;; Preserve repeater.
4450 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4451 (org-test-with-temp-text "* H"
4452 (let ((org-adapt-indentation nil
)
4453 (org-last-inserted-timestamp nil
))
4454 (org-deadline nil
"<2012-03-29 Tue +2y>"))
4455 (replace-regexp-in-string
4456 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4457 ;; Remove CLOSED keyword, if any.
4459 (equal "* H\nDEADLINE: <2012-03-29>"
4460 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4461 (let ((org-adapt-indentation nil
)
4462 (org-last-inserted-timestamp nil
))
4463 (org-deadline nil
"<2012-03-29 Tue>"))
4464 (replace-regexp-in-string
4465 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4466 ;; With C-u argument, remove DEADLINE keyword.
4469 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4470 (let ((org-adapt-indentation nil
)
4471 (org-last-inserted-timestamp nil
))
4472 (org-deadline '(4)))
4476 (org-test-with-temp-text "* H"
4477 (let ((org-adapt-indentation nil
)
4478 (org-last-inserted-timestamp nil
))
4479 (org-deadline '(4)))
4481 ;; With C-u C-u argument, prompt for a delay cookie.
4483 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4484 (cl-letf (((symbol-function 'org-read-date
)
4485 (lambda (&rest args
)
4486 (apply #'encode-time
4487 (org-parse-time-string "2014-03-04")))))
4488 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4489 (let ((org-adapt-indentation nil
)
4490 (org-last-inserted-timestamp nil
))
4491 (org-deadline '(16)))
4494 (cl-letf (((symbol-function 'org-read-date
)
4495 (lambda (&rest args
)
4496 (apply #'encode-time
4497 (org-parse-time-string "2014-03-04")))))
4498 (org-test-with-temp-text "* H"
4499 (let ((org-adapt-indentation nil
)
4500 (org-last-inserted-timestamp nil
))
4501 (org-deadline '(16)))
4503 ;; When a region is active and
4504 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4505 ;; same value in all headlines in region.
4507 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4508 (org-test-with-temp-text "* H1\n* H2"
4509 (let ((org-adapt-indentation nil
)
4510 (org-last-inserted-timestamp nil
)
4511 (org-loop-over-headlines-in-active-region t
))
4512 (transient-mark-mode 1)
4513 (push-mark (point) t t
)
4514 (goto-char (point-max))
4515 (org-deadline nil
"2012-03-29"))
4516 (replace-regexp-in-string
4517 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4519 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4520 (org-test-with-temp-text "* H1\n* H2"
4521 (let ((org-adapt-indentation nil
)
4522 (org-last-inserted-timestamp nil
)
4523 (org-loop-over-headlines-in-active-region nil
))
4524 (transient-mark-mode 1)
4525 (push-mark (point) t t
)
4526 (goto-char (point-max))
4527 (org-deadline nil
"2012-03-29"))
4528 (replace-regexp-in-string
4529 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4531 (ert-deftest test-org
/schedule
()
4532 "Test `org-schedule' specifications."
4533 ;; Insert a new value or replace existing one.
4535 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4536 (org-test-with-temp-text "* H"
4537 (let ((org-adapt-indentation nil
)
4538 (org-last-inserted-timestamp nil
))
4539 (org-schedule nil
"<2012-03-29 Tue>"))
4540 (replace-regexp-in-string
4541 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4544 (equal "* H\nSCHEDULED: <2014-03-04>"
4545 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4546 (let ((org-adapt-indentation nil
)
4547 (org-last-inserted-timestamp nil
))
4548 (org-schedule nil
"<2014-03-04 Thu>"))
4549 (replace-regexp-in-string
4550 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4552 ;; Accept delta time, e.g., "+2d".
4554 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4555 (cl-letf (((symbol-function 'current-time
)
4556 (lambda (&rest args
)
4557 (apply #'encode-time
4558 (org-parse-time-string "2014-03-04")))))
4559 (org-test-with-temp-text "* H"
4560 (let ((org-adapt-indentation nil
)
4561 (org-last-inserted-timestamp nil
))
4562 (org-schedule nil
"+1y"))
4563 (replace-regexp-in-string
4564 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1)))))
4565 ;; Preserve repeater.
4567 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4568 (org-test-with-temp-text "* H"
4569 (let ((org-adapt-indentation nil
)
4570 (org-last-inserted-timestamp nil
))
4571 (org-schedule nil
"<2012-03-29 Tue +2y>"))
4572 (replace-regexp-in-string
4573 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil
1))))
4574 ;; Remove CLOSED keyword, if any.
4576 (equal "* H\nSCHEDULED: <2012-03-29>"
4577 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4578 (let ((org-adapt-indentation nil
)
4579 (org-last-inserted-timestamp nil
))
4580 (org-schedule nil
"<2012-03-29 Tue>"))
4581 (replace-regexp-in-string
4582 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4583 ;; With C-u argument, remove SCHEDULED keyword.
4586 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4587 (let ((org-adapt-indentation nil
)
4588 (org-last-inserted-timestamp nil
))
4589 (org-schedule '(4)))
4593 (org-test-with-temp-text "* H"
4594 (let ((org-adapt-indentation nil
)
4595 (org-last-inserted-timestamp nil
))
4596 (org-schedule '(4)))
4598 ;; With C-u C-u argument, prompt for a delay cookie.
4600 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4601 (cl-letf (((symbol-function 'org-read-date
)
4602 (lambda (&rest args
)
4603 (apply #'encode-time
4604 (org-parse-time-string "2014-03-04")))))
4605 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4606 (let ((org-adapt-indentation nil
)
4607 (org-last-inserted-timestamp nil
))
4608 (org-schedule '(16)))
4611 (cl-letf (((symbol-function 'org-read-date
)
4612 (lambda (&rest args
)
4613 (apply #'encode-time
4614 (org-parse-time-string "2014-03-04")))))
4615 (org-test-with-temp-text "* H"
4616 (let ((org-adapt-indentation nil
)
4617 (org-last-inserted-timestamp nil
))
4618 (org-schedule '(16)))
4620 ;; When a region is active and
4621 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4622 ;; same value in all headlines in region.
4624 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4625 (org-test-with-temp-text "* H1\n* H2"
4626 (let ((org-adapt-indentation nil
)
4627 (org-last-inserted-timestamp nil
)
4628 (org-loop-over-headlines-in-active-region t
))
4629 (transient-mark-mode 1)
4630 (push-mark (point) t t
)
4631 (goto-char (point-max))
4632 (org-schedule nil
"2012-03-29"))
4633 (replace-regexp-in-string
4634 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4636 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4637 (org-test-with-temp-text "* H1\n* H2"
4638 (let ((org-adapt-indentation nil
)
4639 (org-last-inserted-timestamp nil
)
4640 (org-loop-over-headlines-in-active-region nil
))
4641 (transient-mark-mode 1)
4642 (push-mark (point) t t
)
4643 (goto-char (point-max))
4644 (org-schedule nil
"2012-03-29"))
4645 (replace-regexp-in-string
4646 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil
1))))
4648 ;; check if a repeater survives re-scheduling.
4650 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4651 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4652 (let ((org-adapt-indentation nil
)
4653 (org-last-inserted-timestamp nil
))
4654 (org-schedule nil
"2017-02-01"))
4660 (ert-deftest test-org
/buffer-property-keys
()
4661 "Test `org-buffer-property-keys' specifications."
4662 ;; Retrieve properties accross siblings.
4665 (org-test-with-temp-text "
4674 (org-buffer-property-keys))))
4675 ;; Retrieve properties accross children.
4678 (org-test-with-temp-text "
4687 (org-buffer-property-keys))))
4688 ;; Retrieve muliple properties in the same drawer.
4691 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4692 (org-buffer-property-keys))))
4693 ;; Ignore extension symbol in property name.
4696 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4697 (org-buffer-property-keys))))
4698 ;; With non-nil COLUMNS, extract property names from columns.
4701 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4702 (org-buffer-property-keys nil nil t
))))
4704 (equal '("A" "B" "COLUMNS")
4705 (org-test-with-temp-text
4706 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4707 (org-buffer-property-keys nil nil t
))))
4708 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4711 (org-test-with-temp-text
4712 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4713 (org-buffer-property-keys nil nil nil t
)))))
4715 (ert-deftest test-org
/property-values
()
4716 "Test `org-property-values' specifications."
4720 (org-test-with-temp-text
4721 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4722 (org-property-values "A"))))
4723 ;; Ignore empty values.
4725 (org-test-with-temp-text
4726 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4727 (org-property-values "A")))
4728 ;; Take into consideration extended values.
4731 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4732 (org-property-values "A")))))
4734 (ert-deftest test-org
/find-property
()
4735 "Test `org-find-property' specifications."
4739 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4740 (org-find-property "prop"))))
4741 ;; Ignore false positives.
4744 (org-test-with-temp-text
4745 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4746 (org-find-property "A"))))
4747 ;; Return first entry found in buffer.
4750 (org-test-with-temp-text
4751 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4752 (org-find-property "A"))))
4753 ;; Only search visible part of the buffer.
4756 (org-test-with-temp-text
4757 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4758 (org-narrow-to-subtree)
4759 (org-find-property "A"))))
4760 ;; With optional argument, only find entries with a specific value.
4762 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4763 (org-find-property "A" "2")))
4766 (org-test-with-temp-text
4767 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4768 (org-find-property "A" "2"))))
4769 ;; Use "nil" for explicit nil values.
4772 (org-test-with-temp-text
4773 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4774 (org-find-property "A" "nil")))))
4776 (ert-deftest test-org
/entry-delete
()
4777 "Test `org-entry-delete' specifications."
4781 " *:PROPERTIES:\n *:B: +2\n *:END:"
4782 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4783 (org-entry-delete (point) "A")
4785 ;; Also remove accumulated properties.
4789 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4790 (org-entry-delete (point) "A")
4792 ;; When last property is removed, remove the property drawer.
4796 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4797 (org-entry-delete (point) "A")
4799 ;; Return a non-nil value when some property was removed.
4801 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4802 (org-entry-delete (point) "A")))
4804 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4805 (org-entry-delete (point) "C")))
4806 ;; Special properties cannot be located in a drawer. Allow to
4807 ;; remove them anyway, in case of user error.
4809 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4810 (org-entry-delete (point) "SCHEDULED"))))
4812 (ert-deftest test-org
/entry-get
()
4813 "Test `org-entry-get' specifications."
4817 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4818 (org-entry-get (point) "A"))))
4822 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4823 (org-entry-get (point) "a"))))
4824 ;; Handle extended values, both before and after base value.
4827 (org-test-with-temp-text
4828 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4829 (org-entry-get (point) "A"))))
4830 ;; Empty values are returned as the empty string.
4833 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4834 (org-entry-get (point) "A"))))
4835 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4836 ;; otherwise, return nil.
4838 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4839 (org-entry-get (point) "A")))
4842 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4843 (org-entry-get (point) "A" nil t
))))
4844 ;; Return nil when no property is found, independently on the
4845 ;; LITERAL-NIL argument.
4847 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4848 (org-entry-get (point) "B")))
4850 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4851 (org-entry-get (point) "B" nil t
)))
4852 ;; Handle inheritance, when allowed. Include extended values and
4853 ;; possibly global values.
4857 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4858 (org-entry-get (point) "A" t
))))
4862 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4863 (let ((org-use-property-inheritance t
))
4864 (org-entry-get (point) "A" 'selective
)))))
4866 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4867 (let ((org-use-property-inheritance nil
))
4868 (org-entry-get (point) "A" 'selective
))))
4872 (org-test-with-temp-text
4873 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4874 (org-entry-get (point-max) "A" t
))))
4877 (org-test-with-temp-text
4878 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4880 (org-entry-get (point-max) "A" t
))))
4883 (org-test-with-temp-text
4884 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4886 (org-entry-get (point-max) "A" t
)))))
4888 (ert-deftest test-org
/entry-properties
()
4889 "Test `org-entry-properties' specifications."
4890 ;; Get "ITEM" property.
4893 (org-test-with-temp-text "* TODO H"
4894 (cdr (assoc "ITEM" (org-entry-properties nil
"ITEM"))))))
4897 (org-test-with-temp-text "* TODO H"
4898 (cdr (assoc "ITEM" (org-entry-properties))))))
4899 ;; Get "TODO" property. TODO keywords are case sensitive.
4902 (org-test-with-temp-text "* TODO H"
4903 (cdr (assoc "TODO" (org-entry-properties nil
"TODO"))))))
4906 (org-test-with-temp-text "* TODO H"
4907 (cdr (assoc "TODO" (org-entry-properties))))))
4909 (org-test-with-temp-text "* H"
4910 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4912 (org-test-with-temp-text "* todo H"
4913 (assoc "TODO" (org-entry-properties nil
"TODO"))))
4914 ;; Get "PRIORITY" property.
4917 (org-test-with-temp-text "* [#A] H"
4918 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4921 (org-test-with-temp-text "* [#A] H"
4922 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4924 (equal (char-to-string org-default-priority
)
4925 (org-test-with-temp-text "* H"
4926 (cdr (assoc "PRIORITY" (org-entry-properties nil
"PRIORITY"))))))
4927 ;; Get "FILE" property.
4929 (org-test-with-temp-text-in-file "* H\nParagraph"
4930 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))
4931 (buffer-file-name))))
4933 (org-test-with-temp-text-in-file "* H\nParagraph"
4934 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4935 (buffer-file-name))))
4937 (org-test-with-temp-text "* H\nParagraph"
4938 (cdr (assoc "FILE" (org-entry-properties nil
"FILE")))))
4939 ;; Get "TAGS" property.
4941 (equal ":tag1:tag2:"
4942 (org-test-with-temp-text "* H :tag1:tag2:"
4943 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS"))))))
4945 (equal ":tag1:tag2:"
4946 (org-test-with-temp-text "* H :tag1:tag2:"
4947 (cdr (assoc "TAGS" (org-entry-properties))))))
4949 (org-test-with-temp-text "* H"
4950 (cdr (assoc "TAGS" (org-entry-properties nil
"TAGS")))))
4951 ;; Get "ALLTAGS" property.
4953 (equal ":tag1:tag2:"
4954 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4955 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS"))))))
4957 (equal ":tag1:tag2:"
4958 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4959 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4961 (org-test-with-temp-text "* H"
4962 (cdr (assoc "ALLTAGS" (org-entry-properties nil
"ALLTAGS")))))
4963 ;; Get "BLOCKED" property.
4966 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4967 (let ((org-enforce-todo-dependencies t
)
4969 '(org-block-todo-from-children-or-siblings-or-parent)))
4970 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4973 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4974 (let ((org-enforce-todo-dependencies t
)
4976 '(org-block-todo-from-children-or-siblings-or-parent)))
4977 (cdr (assoc "BLOCKED" (org-entry-properties nil
"BLOCKED")))))))
4978 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4982 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4983 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED"))))))
4987 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4988 (cdr (assoc "CLOSED" (org-entry-properties))))))
4990 (org-test-with-temp-text "* H"
4991 (cdr (assoc "CLOSED" (org-entry-properties nil
"CLOSED")))))
4995 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4996 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE"))))))
5000 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5001 (cdr (assoc "DEADLINE" (org-entry-properties))))))
5003 (org-test-with-temp-text "* H"
5004 (cdr (assoc "DEADLINE" (org-entry-properties nil
"DEADLINE")))))
5008 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5009 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED"))))))
5013 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5014 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
5016 (org-test-with-temp-text "* H"
5017 (cdr (assoc "SCHEDULED" (org-entry-properties nil
"SCHEDULED")))))
5021 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5022 (cdr (assoc "CATEGORY" (org-entry-properties))))))
5025 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
5026 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5029 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
5030 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5033 (org-test-with-temp-text
5034 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
5036 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
5037 (cdr (assoc "CATEGORY" (org-entry-properties nil
"CATEGORY"))))))
5038 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
5040 (equal "<2012-03-29 thu.>"
5041 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
5042 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5044 (equal "[2012-03-29 thu.]"
5045 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
5046 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
5048 (equal "<2012-03-29 thu.>"
5049 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
5050 (cdr (assoc "TIMESTAMP" (org-entry-properties nil
"TIMESTAMP"))))))
5052 (equal "[2014-03-04 tue.]"
5053 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
5054 (cdr (assoc "TIMESTAMP_IA"
5055 (org-entry-properties nil
"TIMESTAMP_IA"))))))
5057 (equal "<2012-03-29 thu.>"
5058 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
5059 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
5060 ;; Get standard properties.
5063 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5064 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5065 ;; Handle extended properties.
5068 (org-test-with-temp-text
5069 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
5070 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5073 (org-test-with-temp-text
5074 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
5075 (cdr (assoc "A" (org-entry-properties nil
'standard
))))))
5076 ;; Ignore forbidden (special) properties.
5078 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
5079 (cdr (assoc "TODO" (org-entry-properties nil
'standard
))))))
5081 (ert-deftest test-org
/entry-put
()
5082 "Test `org-entry-put' specifications."
5083 ;; Error when not a string or nil.
5085 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5086 (org-entry-put 1 "test" 2)))
5087 ;; Error when property name is invalid.
5089 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5090 (org-entry-put 1 "no space" "value")))
5092 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
5093 (org-entry-put 1 "" "value")))
5094 ;; Set "TODO" property.
5096 (string-match (regexp-quote " TODO H")
5097 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5098 (org-entry-put (point) "TODO" "TODO")
5101 (string-match (regexp-quote "* H")
5102 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
5103 (org-entry-put (point) "TODO" nil
)
5105 ;; Set "PRIORITY" property.
5108 (org-test-with-temp-text "* [#B] H"
5109 (org-entry-put (point) "PRIORITY" "A")
5113 (org-test-with-temp-text "* [#B] H"
5114 (org-entry-put (point) "PRIORITY" nil
)
5116 ;; Set "SCHEDULED" property.
5118 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
5119 (org-test-with-temp-text "* H"
5120 (org-entry-put (point) "SCHEDULED" "2014-03-04")
5124 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5125 (org-entry-put (point) "SCHEDULED" nil
)
5128 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
5129 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5130 (org-entry-put (point) "SCHEDULED" "earlier")
5133 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
5134 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
5135 (org-entry-put (point) "SCHEDULED" "later")
5137 ;; Set "DEADLINE" property.
5139 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
5140 (org-test-with-temp-text "* H"
5141 (org-entry-put (point) "DEADLINE" "2014-03-04")
5145 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5146 (org-entry-put (point) "DEADLINE" nil
)
5149 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
5150 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5151 (org-entry-put (point) "DEADLINE" "earlier")
5154 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
5155 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
5156 (org-entry-put (point) "DEADLINE" "later")
5158 ;; Set "CATEGORY" property
5160 (string-match "^ *:CATEGORY: cat"
5161 (org-test-with-temp-text "* H"
5162 (org-entry-put (point) "CATEGORY" "cat")
5164 ;; Regular properties, with or without pre-existing drawer.
5166 (string-match "^ *:A: +2$"
5167 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5168 (org-entry-put (point) "A" "2")
5171 (string-match "^ *:A: +1$"
5172 (org-test-with-temp-text "* H"
5173 (org-entry-put (point) "A" "1")
5175 ;; Special case: two consecutive headlines.
5177 (string-match "\\* A\n *:PROPERTIES:"
5178 (org-test-with-temp-text "* A\n** B"
5179 (org-entry-put (point) "A" "1")
5182 (ert-deftest test-org
/refresh-properties
()
5183 "Test `org-refresh-properties' specifications."
5186 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5187 (org-refresh-properties "A" 'org-test
)
5188 (get-text-property (point) 'org-test
))))
5190 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
5191 (org-refresh-properties "B" 'org-test
)
5192 (get-text-property (point) 'org-test
)))
5193 ;; Handle properties only defined with extension syntax, i.e.,
5197 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
5198 (org-refresh-properties "A" 'org-test
)
5199 (get-text-property (point) 'org-test
))))
5200 ;; When property is inherited, add text property to the whole
5204 (org-test-with-temp-text
5205 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
5206 (let ((org-use-property-inheritance t
))
5207 (org-refresh-properties "A" 'org-test
))
5208 (get-text-property (point) 'org-test
))))
5209 ;; When property is inherited, use global value across the whole
5210 ;; buffer. However local values have precedence.
5213 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5215 (let ((org-use-property-inheritance nil
))
5216 (org-refresh-properties "A" 'org-test
))
5217 (get-text-property (point) 'org-test
))))
5220 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
5222 (let ((org-use-property-inheritance t
))
5223 (org-refresh-properties "A" 'org-test
))
5224 (get-text-property (point) 'org-test
))))
5227 (org-test-with-temp-text
5228 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
5230 (let ((org-use-property-inheritance t
))
5231 (org-refresh-properties "A" 'org-test
))
5232 (get-text-property (point) 'org-test
)))))
5237 (ert-deftest test-org
/update-radio-target-regexp
()
5238 "Test `org-update-radio-target-regexp' specifications."
5239 ;; Properly update cache with no previous radio target regexp.
5242 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5243 (save-excursion (goto-char (point-max)) (org-element-context))
5245 (search-forward "o")
5247 (org-update-radio-target-regexp)
5248 (goto-char (point-max))
5249 (org-element-type (org-element-context)))))
5250 ;; Properly update cache with previous radio target regexp.
5253 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
5254 (save-excursion (goto-char (point-max)) (org-element-context))
5256 (search-forward "o")
5258 (org-update-radio-target-regexp)
5259 (search-backward "r")
5262 (org-update-radio-target-regexp)
5263 (goto-char (point-max))
5264 (delete-region (line-beginning-position) (point))
5266 (org-element-type (org-element-context))))))
5271 (ert-deftest test-org
/match-sparse-tree
()
5272 "Test `org-match-sparse-tree' specifications."
5275 (org-test-with-temp-text "* H\n** H1 :tag:"
5276 (org-match-sparse-tree nil
"tag")
5277 (search-forward "H1")
5278 (org-invisible-p2)))
5280 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
5281 (org-match-sparse-tree nil
"tag")
5282 (search-forward "H2")
5283 (org-invisible-p2)))
5284 ;; "-" operator for tags.
5286 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5287 (org-match-sparse-tree nil
"tag1-tag2")
5288 (search-forward "H1")
5289 (org-invisible-p2)))
5291 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5292 (org-match-sparse-tree nil
"tag1-tag2")
5293 (search-forward "H2")
5294 (org-invisible-p2)))
5295 ;; "&" operator for tags.
5297 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5298 (org-match-sparse-tree nil
"tag1&tag2")
5299 (search-forward "H1")
5300 (org-invisible-p2)))
5302 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5303 (org-match-sparse-tree nil
"tag1&tag2")
5304 (search-forward "H2")
5305 (org-invisible-p2)))
5306 ;; "|" operator for tags.
5308 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5309 (org-match-sparse-tree nil
"tag1|tag2")
5310 (search-forward "H1")
5311 (org-invisible-p2)))
5313 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
5314 (org-match-sparse-tree nil
"tag1|tag2")
5315 (search-forward "H2")
5316 (org-invisible-p2)))
5317 ;; Regexp match on tags.
5319 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5320 (org-match-sparse-tree nil
"{^tag.*}")
5321 (search-forward "H1")
5322 (org-invisible-p2)))
5324 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
5325 (org-match-sparse-tree nil
"{^tag.*}")
5326 (search-forward "H2")
5327 (org-invisible-p2)))
5328 ;; Match group tags.
5330 (org-test-with-temp-text
5331 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5332 (org-match-sparse-tree nil
"work")
5333 (search-forward "H1")
5334 (org-invisible-p2)))
5336 (org-test-with-temp-text
5337 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
5338 (org-match-sparse-tree nil
"work")
5339 (search-forward "H2")
5340 (org-invisible-p2)))
5341 ;; Match group tags with hard brackets.
5343 (org-test-with-temp-text
5344 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5345 (org-match-sparse-tree nil
"work")
5346 (search-forward "H1")
5347 (org-invisible-p2)))
5349 (org-test-with-temp-text
5350 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
5351 (org-match-sparse-tree nil
"work")
5352 (search-forward "H2")
5353 (org-invisible-p2)))
5354 ;; Match tags in hierarchies
5356 (org-test-with-temp-text
5357 "#+TAGS: [ Lev_1 : Lev_2 ]\n
5358 #+TAGS: [ Lev_2 : Lev_3 ]\n
5359 #+TAGS: { Lev_3 : Lev_4 }\n
5360 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5361 (org-match-sparse-tree nil
"Lev_1")
5362 (search-forward "H4")
5363 (org-invisible-p2)))
5364 ;; Match regular expressions in tags
5366 (org-test-with-temp-text
5367 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5368 (org-match-sparse-tree nil
"Lev")
5369 (search-forward "H1")
5370 (org-invisible-p2)))
5372 (org-test-with-temp-text
5373 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5374 (org-match-sparse-tree nil
"Lev")
5375 (search-forward "H1")
5376 (org-invisible-p2)))
5377 ;; Match properties.
5379 (org-test-with-temp-text
5380 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5381 (org-match-sparse-tree nil
"A=\"1\"")
5382 (search-forward "H2")
5383 (org-invisible-p2)))
5385 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5386 (org-match-sparse-tree nil
"A=\"1\"")
5387 (search-forward "H2")
5388 (org-invisible-p2)))
5389 ;; Case is not significant when matching properties.
5391 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5392 (org-match-sparse-tree nil
"a=\"1\"")
5393 (search-forward "H2")
5394 (org-invisible-p2)))
5396 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5397 (org-match-sparse-tree nil
"A=\"1\"")
5398 (search-forward "H2")
5399 (org-invisible-p2)))
5400 ;; Match special LEVEL property.
5402 (org-test-with-temp-text "* H\n** H1\n*** H2"
5403 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5404 (search-forward "H1")
5405 (org-invisible-p2)))
5407 (org-test-with-temp-text "* H\n** H1\n*** H2"
5408 (let ((org-odd-levels-only nil
)) (org-match-sparse-tree nil
"LEVEL=2"))
5409 (search-forward "H2")
5410 (org-invisible-p2)))
5411 ;; Comparison operators when matching properties.
5413 (org-test-with-temp-text
5414 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5415 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5416 (search-forward "H1")
5417 (org-invisible-p2)))
5419 (org-test-with-temp-text
5420 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5421 (org-match-sparse-tree nil
"SCHEDULED<=\"<2013-01-01>\"")
5422 (search-forward "H2")
5423 (org-invisible-p2)))
5424 ;; Regexp match on properties values.
5426 (org-test-with-temp-text
5427 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5428 (org-match-sparse-tree nil
"A={f.*}")
5429 (search-forward "H1")
5430 (org-invisible-p2)))
5432 (org-test-with-temp-text
5433 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5434 (org-match-sparse-tree nil
"A={f.*}")
5435 (search-forward "H2")
5436 (org-invisible-p2)))
5437 ;; With an optional argument, limit match to TODO entries.
5439 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5440 (org-match-sparse-tree t
"tag")
5441 (search-forward "H1")
5442 (org-invisible-p2)))
5444 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5445 (org-match-sparse-tree t
"tag")
5446 (search-forward "H2")
5447 (org-invisible-p2))))
5449 (ert-deftest test-org
/occur
()
5450 "Test `org-occur' specifications."
5451 ;; Count number of matches.
5454 (org-test-with-temp-text "* H\nA\n* H2"
5458 (org-test-with-temp-text "* H\nA\n* H2\nA"
5460 ;; Test CALLBACK optional argument.
5463 (org-test-with-temp-text "* H\nA\n* H2"
5464 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5467 (org-test-with-temp-text "* H\nA\n* H2\nA"
5468 (org-occur "A" nil
(lambda () (equal (org-get-heading) "H2"))))))
5469 ;; Case-fold searches according to `org-occur-case-fold-search'.
5472 (org-test-with-temp-text "Aa"
5473 (let ((org-occur-case-fold-search t
)) (org-occur "A")))))
5476 (org-test-with-temp-text "Aa"
5477 (let ((org-occur-case-fold-search t
)) (org-occur "a")))))
5480 (org-test-with-temp-text "Aa"
5481 (let ((org-occur-case-fold-search nil
)) (org-occur "A")))))
5484 (org-test-with-temp-text "Aa"
5485 (let ((org-occur-case-fold-search nil
)) (org-occur "a")))))
5488 (org-test-with-temp-text "Aa"
5489 (let ((org-occur-case-fold-search 'smart
)) (org-occur "A")))))
5492 (org-test-with-temp-text "Aa"
5493 (let ((org-occur-case-fold-search 'smart
)) (org-occur "a"))))))
5498 (ert-deftest test-org
/tag-string-to-alist
()
5499 "Test `org-tag-string-to-alist' specifications."
5500 ;; Tag without selection key.
5501 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5502 ;; Tag with selection key.
5503 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t
))))
5507 (org-tag-string-to-alist "[ group : t1 t2 ]")
5508 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
))))
5509 ;; Mutually exclusive tags.
5510 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5511 '((:startgroup
) ("tag1") ("tag2") (:endgroup
))))
5514 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5515 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))))
5517 (ert-deftest test-org
/tag-alist-to-string
()
5518 "Test `org-tag-alist-to-string' specifications."
5519 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5520 (should (equal (org-tag-alist-to-string '(("tag1" . ?t
))) "tag1(t)"))
5523 (org-tag-alist-to-string
5524 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5525 "[ group : t1 t2 ]"))
5527 (equal (org-tag-alist-to-string
5528 '((:startgroup
) ("tag1") ("tag2") (:endgroup
)))
5532 (org-tag-alist-to-string
5533 '((:startgroup
) ("group") (:grouptags
) ("tag1") ("tag2") (:endgroup
)))
5534 "{ group : tag1 tag2 }")))
5536 (ert-deftest test-org
/tag-alist-to-groups
()
5537 "Test `org-tag-alist-to-groups' specifications."
5539 (equal (org-tag-alist-to-groups
5540 '((:startgroup
) ("group") (:grouptags
) ("t1") ("t2") (:endgroup
)))
5541 '(("group" "t1" "t2"))))
5544 (org-tag-alist-to-groups
5545 '((:startgrouptag
) ("group") (:grouptags
) ("t1") ("t2") (:endgrouptag
)))
5546 '(("group" "t1" "t2"))))
5548 (org-tag-alist-to-groups
5549 '((:startgroup
) ("group") ("t1") ("t2") (:endgroup
)))))
5551 (ert-deftest test-org
/tag-align
()
5552 "Test tags alignment."
5553 ;; Test aligning tags with different display width.
5555 ;; 12345678901234567890
5556 (equal "* Test :abc:"
5557 (org-test-with-temp-text "* Test :abc:"
5558 (let ((org-tags-column -
20)
5559 (indent-tabs-mode nil
))
5560 (org-fix-tags-on-the-fly))
5563 ;; 12345678901234567890
5564 (equal "* Test :日本語:"
5565 (org-test-with-temp-text "* Test :日本語:"
5566 (let ((org-tags-column -
20)
5567 (indent-tabs-mode nil
))
5568 (org-fix-tags-on-the-fly))
5570 ;; Make sure aligning tags do not skip invisible text.
5572 (equal "* [[linkx]] :tag:"
5573 (org-test-with-temp-text "* [[link<point>]] :tag:"
5574 (let ((org-tags-column 0))
5575 (org-fix-tags-on-the-fly)
5577 (buffer-string))))))
5579 (ert-deftest test-org
/tags-at
()
5581 (equal '("foo" "bar")
5582 (org-test-with-temp-text
5583 "* T<point>est :foo:bar:"
5584 (org-get-tags-at)))))
5589 (ert-deftest test-org
/auto-repeat-maybe
()
5590 "Test `org-auto-repeat-maybe' specifications."
5591 ;; Do not auto repeat when there is no valid time stamp with
5592 ;; a repeater in the entry.
5596 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5597 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
5603 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5604 (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
5607 ;; When switching to DONE state, switch back to first TODO keyword
5608 ;; in sequence, or the same keyword if they have different types.
5612 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5613 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5619 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5620 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5626 (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
5627 (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
5630 ;; If there was no TODO keyword in the first place, do not insert
5635 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5636 (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
5639 ;; Revert to REPEAT_TO_STATE, if set.
5643 (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
5644 (org-test-with-temp-text
5647 :REPEAT_TO_STATE: KWD2
5649 <2012-03-29 Thu +2y>"
5652 ;; When switching to DONE state, update base date. If there are
5653 ;; multiple repeated time stamps, update them all.
5656 "<2014-03-29 .* \\+2y>"
5657 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5658 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
5663 "<2015-03-04 .* \\+1y>"
5664 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5665 (org-test-with-temp-text
5666 "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
5669 ;; Throw an error if repeater unit is the hour and no time is
5670 ;; provided in the time-stamp.
5672 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5673 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
5676 ;; Do not repeat commented time stamps.
5679 "<2015-03-04 .* \\+1y>"
5680 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5681 (org-test-with-temp-text
5682 "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
5687 "<2015-03-04 .* \\+1y>"
5688 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5689 (org-test-with-temp-text
5691 <2012-03-29 Thu. +2y>
5693 <2014-03-04 Tue +1y>
5697 ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
5698 ;; entry, record time of last repeat.
5702 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5703 (org-log-repeat nil
))
5704 (cl-letf (((symbol-function 'org-add-log-setup
)
5705 (lambda (&rest args
) nil
)))
5706 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5708 (buffer-string))))))
5712 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
5714 (cl-letf (((symbol-function 'org-add-log-setup
)
5715 (lambda (&rest args
) nil
)))
5716 (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
5718 (buffer-string))))))
5722 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5723 (cl-letf (((symbol-function 'org-add-log-setup
)
5724 (lambda (&rest args
) nil
)))
5725 (org-test-with-temp-text
5726 "* TODO H\n<2012-03-29 Thu. +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
5728 (buffer-string))))))
5729 ;; When a SCHEDULED entry has no repeater, remove it upon repeating
5730 ;; the entry as it is no longer relevant.
5734 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
5735 (org-test-with-temp-text
5736 "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
5738 (buffer-string))))))
5743 (ert-deftest test-org
/at-timestamp-p
()
5744 "Test `org-at-timestamp-p' specifications."
5746 (org-test-with-temp-text "<2012-03-29 Thu>"
5747 (org-at-timestamp-p)))
5749 (org-test-with-temp-text "2012-03-29 Thu"
5750 (org-at-timestamp-p)))
5751 ;; Test return values.
5754 (org-test-with-temp-text "<2012-03-29 Thu>"
5755 (org-at-timestamp-p))))
5758 (org-test-with-temp-text "<<point>2012-03-29 Thu>"
5759 (org-at-timestamp-p))))
5762 (org-test-with-temp-text "<2012-<point>03-29 Thu>"
5763 (org-at-timestamp-p))))
5766 (org-test-with-temp-text "<2012-03-<point>29 Thu>"
5767 (org-at-timestamp-p))))
5770 (org-test-with-temp-text "<2012-03-29 T<point>hu>"
5771 (org-at-timestamp-p))))
5774 (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
5775 (org-at-timestamp-p))))
5778 (org-test-with-temp-text "<2012-03-29 Thu<point>>"
5779 (org-at-timestamp-p))))
5782 (org-test-with-temp-text "<2012-03-29 Thu><point>»"
5783 (org-at-timestamp-p))))
5784 ;; Test `inactive' optional argument.
5786 (org-test-with-temp-text "[2012-03-29 Thu]"
5787 (org-at-timestamp-p 'inactive
)))
5789 (org-test-with-temp-text "[2012-03-29 Thu]"
5790 (org-at-timestamp-p)))
5791 ;; When optional argument is `agenda', recognize time-stamps in
5792 ;; planning info line, property drawers and clocks.
5794 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5795 (org-at-timestamp-p 'agenda
)))
5797 (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
5798 (org-at-timestamp-p)))
5800 (org-test-with-temp-text
5801 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5802 (org-at-timestamp-p 'agenda
)))
5804 (org-test-with-temp-text
5805 "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
5806 (org-at-timestamp-p)))
5808 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5809 (let ((org-agenda-include-inactive-timestamps t
))
5810 (org-at-timestamp-p 'agenda
))))
5812 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5813 (let ((org-agenda-include-inactive-timestamps t
))
5814 (org-at-timestamp-p))))
5816 (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
5817 (let ((org-agenda-include-inactive-timestamps t
))
5818 (org-at-timestamp-p 'inactive
))))
5819 ;; When optional argument is `lax', match any part of the document
5820 ;; with Org timestamp syntax.
5822 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
5823 (org-at-timestamp-p 'lax
)))
5825 (org-test-with-temp-text "# <2012-03-29 Thu><point>"
5826 (org-at-timestamp-p)))
5828 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
5829 (org-at-timestamp-p 'lax
)))
5831 (org-test-with-temp-text ": <2012-03-29 Thu><point>"
5832 (org-at-timestamp-p)))
5834 (org-test-with-temp-text
5835 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
5836 (org-at-timestamp-p 'lax
)))
5838 (org-test-with-temp-text
5839 "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
5840 (org-at-timestamp-p)))
5841 ;; Optional argument `lax' also matches inactive timestamps.
5843 (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
5844 (org-at-timestamp-p 'lax
))))
5846 (ert-deftest test-org
/time-stamp
()
5847 "Test `org-time-stamp' specifications."
5848 ;; Insert chosen time stamp at point.
5851 "Te<2014-03-04 .*?>xt"
5852 (org-test-with-temp-text "Te<point>xt"
5853 (cl-letf (((symbol-function 'org-read-date
)
5854 (lambda (&rest args
)
5855 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5856 (org-time-stamp nil
)
5858 ;; With a prefix argument, also insert time.
5861 "Te<2014-03-04 .*? 00:41>xt"
5862 (org-test-with-temp-text "Te<point>xt"
5863 (cl-letf (((symbol-function 'org-read-date
)
5864 (lambda (&rest args
)
5865 (apply #'encode-time
5866 (org-parse-time-string "2014-03-04 00:41")))))
5867 (org-time-stamp '(4))
5869 ;; With two universal prefix arguments, insert an active timestamp
5870 ;; with the current time without prompting the user.
5873 "Te<2014-03-04 .*? 00:41>xt"
5874 (org-test-with-temp-text "Te<point>xt"
5875 (cl-letf (((symbol-function 'current-time
)
5877 (apply #'encode-time
5878 (org-parse-time-string "2014-03-04 00:41")))))
5879 (org-time-stamp '(16))
5881 ;; When optional argument is non-nil, insert an inactive timestamp.
5884 "Te\\[2014-03-04 .*?\\]xt"
5885 (org-test-with-temp-text "Te<point>xt"
5886 (cl-letf (((symbol-function 'org-read-date
)
5887 (lambda (&rest args
)
5888 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5889 (org-time-stamp nil t
)
5891 ;; When called from a timestamp, replace existing one.
5895 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5896 (cl-letf (((symbol-function 'org-read-date
)
5897 (lambda (&rest args
)
5898 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5899 (org-time-stamp nil
)
5903 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5904 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5905 (cl-letf (((symbol-function 'org-read-date
)
5906 (lambda (&rest args
)
5907 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5908 (org-time-stamp nil
)
5910 ;; When replacing a timestamp, preserve repeater, if any.
5913 "<2014-03-04 .*? \\+2y>"
5914 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5915 (cl-letf (((symbol-function 'org-read-date
)
5916 (lambda (&rest args
)
5917 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5918 (org-time-stamp nil
)
5920 ;; When called twice in a raw, build a date range.
5923 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5924 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5925 (cl-letf (((symbol-function 'org-read-date
)
5926 (lambda (&rest args
)
5927 (apply #'encode-time
(org-parse-time-string "2014-03-04")))))
5928 (let ((last-command 'org-time-stamp
)
5929 (this-command 'org-time-stamp
))
5930 (org-time-stamp nil
))
5931 (buffer-string))))))
5933 (ert-deftest test-org
/timestamp-has-time-p
()
5934 "Test `org-timestamp-has-time-p' specifications."
5937 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5938 (org-timestamp-has-time-p (org-element-context))))
5941 (org-test-with-temp-text "<2012-03-29 Thu>"
5942 (org-timestamp-has-time-p (org-element-context)))))
5944 (ert-deftest test-org
/get-repeat
()
5945 "Test `org-get-repeat' specifications."
5947 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
5950 (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
5952 ;; Return proper repeat string.
5955 (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
5957 ;; Prevent false positive (commented or verbatim time stamps)
5959 (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
5962 (org-test-with-temp-text
5963 "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
5965 ;; Return nil when called before first heading.
5967 (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
5969 ;; When called with an optional argument, extract repeater from that
5971 (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
5972 (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
5974 (ert-deftest test-org
/timestamp-format
()
5975 "Test `org-timestamp-format' specifications."
5980 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5981 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5986 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5987 (org-timestamp-format (org-element-context) "%Y-%m-%d" t
)))))
5989 (ert-deftest test-org
/timestamp-split-range
()
5990 "Test `org-timestamp-split-range' specifications."
5991 ;; Extract range start (active).
5994 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5995 (let ((ts (org-timestamp-split-range (org-element-context))))
5996 (mapcar (lambda (p) (org-element-property p ts
))
5997 '(:year-end
:month-end
:day-end
))))))
5998 ;; Extract range start (inactive)
6001 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6002 (let ((ts (org-timestamp-split-range (org-element-context))))
6003 (mapcar (lambda (p) (org-element-property p ts
))
6004 '(:year-end
:month-end
:day-end
))))))
6005 ;; Extract range end (active).
6008 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6009 (let ((ts (org-timestamp-split-range
6010 (org-element-context) t
)))
6011 (mapcar (lambda (p) (org-element-property p ts
))
6012 '(:year-end
:month-end
:day-end
))))))
6013 ;; Extract range end (inactive)
6016 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
6017 (let ((ts (org-timestamp-split-range
6018 (org-element-context) t
)))
6019 (mapcar (lambda (p) (org-element-property p ts
))
6020 '(:year-end
:month-end
:day-end
))))))
6021 ;; Return the timestamp if not a range.
6023 (org-test-with-temp-text "[2012-03-29 Thu]"
6024 (let* ((ts-orig (org-element-context))
6025 (ts-copy (org-timestamp-split-range ts-orig
)))
6026 (eq ts-orig ts-copy
))))
6028 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6029 (let* ((ts-orig (org-element-context))
6030 (ts-copy (org-timestamp-split-range ts-orig
)))
6031 (eq ts-orig ts-copy
)))))
6033 (ert-deftest test-org
/timestamp-translate
()
6034 "Test `org-timestamp-translate' specifications."
6035 ;; Translate whole date range.
6038 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6039 (let ((org-display-custom-times t
)
6040 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6041 (org-timestamp-translate (org-element-context))))))
6042 ;; Translate date range start.
6045 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6046 (let ((org-display-custom-times t
)
6047 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6048 (org-timestamp-translate (org-element-context) 'start
)))))
6049 ;; Translate date range end.
6052 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
6053 (let ((org-display-custom-times t
)
6054 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6055 (org-timestamp-translate (org-element-context) 'end
)))))
6056 ;; Translate time range.
6059 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
6060 (let ((org-display-custom-times t
)
6061 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
6062 (org-timestamp-translate (org-element-context))))))
6063 ;; Translate non-range timestamp.
6066 (org-test-with-temp-text "<2012-03-29 Thu>"
6067 (let ((org-display-custom-times t
)
6068 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6069 (org-timestamp-translate (org-element-context))))))
6070 ;; Do not change `diary' timestamps.
6072 (equal "<%%(org-float t 4 2)>"
6073 (org-test-with-temp-text "<%%(org-float t 4 2)>"
6074 (let ((org-display-custom-times t
)
6075 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
6076 (org-timestamp-translate (org-element-context)))))))
6082 (ert-deftest test-org
/flag-drawer
()
6083 "Test `org-flag-drawer' specifications."
6086 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6088 (get-char-property (line-end-position) 'invisible
)))
6091 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6093 (org-flag-drawer nil
)
6094 (get-char-property (line-end-position) 'invisible
)))
6095 ;; Test optional argument.
6097 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6098 (let ((drawer (save-excursion (search-forward ":D2")
6099 (org-element-at-point))))
6100 (org-flag-drawer t drawer
)
6101 (get-char-property (progn (search-forward ":D2") (line-end-position))
6104 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
6105 (let ((drawer (save-excursion (search-forward ":D2")
6106 (org-element-at-point))))
6107 (org-flag-drawer t drawer
)
6108 (get-char-property (line-end-position) 'invisible
))))
6109 ;; Do not hide fake drawers.
6111 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
6114 (get-char-property (line-end-position) 'invisible
)))
6115 ;; Do not hide incomplete drawers.
6117 (org-test-with-temp-text ":D:\nparagraph"
6120 (get-char-property (line-end-position) 'invisible
)))
6121 ;; Do not hide drawers when called from final blank lines.
6123 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
6124 (goto-char (point-max))
6126 (goto-char (point-min))
6127 (get-char-property (line-end-position) 'invisible
)))
6128 ;; Don't leave point in an invisible part of the buffer when hiding
6131 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
6132 (goto-char (point-max))
6134 (get-char-property (point) 'invisible
))))
6136 (ert-deftest test-org
/hide-block-toggle
()
6137 "Test `org-hide-block-toggle' specifications."
6138 ;; Error when not at a block.
6140 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
6141 (org-hide-block-toggle 'off
)
6142 (get-char-property (line-end-position) 'invisible
)))
6145 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
6146 (org-hide-block-toggle)
6147 (get-char-property (line-end-position) 'invisible
)))
6149 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
6150 (org-hide-block-toggle)
6151 (get-char-property (line-end-position) 'invisible
)))
6152 ;; Show block unconditionally when optional argument is `off'.
6154 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6155 (org-hide-block-toggle)
6156 (org-hide-block-toggle 'off
)
6157 (get-char-property (line-end-position) 'invisible
)))
6159 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6160 (org-hide-block-toggle 'off
)
6161 (get-char-property (line-end-position) 'invisible
)))
6162 ;; Hide block unconditionally when optional argument is non-nil.
6164 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6165 (org-hide-block-toggle t
)
6166 (get-char-property (line-end-position) 'invisible
)))
6168 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
6169 (org-hide-block-toggle)
6170 (org-hide-block-toggle t
)
6171 (get-char-property (line-end-position) 'invisible
)))
6172 ;; Do not hide block when called from final blank lines.
6174 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
6175 (org-hide-block-toggle)
6176 (goto-char (point-min))
6177 (get-char-property (line-end-position) 'invisible
)))
6178 ;; Don't leave point in an invisible part of the buffer when hiding
6181 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
6182 (org-hide-block-toggle)
6183 (get-char-property (point) 'invisible
))))
6185 (ert-deftest test-org
/hide-block-toggle-maybe
()
6186 "Test `org-hide-block-toggle-maybe' specifications."
6188 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
6189 (org-hide-block-toggle-maybe)))
6191 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
6193 (ert-deftest test-org
/set-tags
()
6194 "Test `org-set-tags' specifications."
6195 ;; Tags set via fast-tag-selection should be visible afterwards
6197 (let ((org-tag-alist '(("NEXT" . ?n
)))
6198 (org-fast-tag-selection-single-key t
))
6199 (cl-letf (((symbol-function 'read-char-exclusive
) (lambda () ?n
))
6200 ((symbol-function 'window-width
) (lambda (&rest args
) 100)))
6201 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
6202 ;; Show only headlines
6204 ;; Set NEXT tag on current entry
6205 (org-set-tags nil nil
)
6206 ;; Move point to that NEXT tag
6207 (search-forward "NEXT") (backward-word)
6208 ;; And it should be visible (i.e. no overlays)
6209 (not (overlays-at (point))))))))
6211 (ert-deftest test-org
/show-set-visibility
()
6212 "Test `org-show-set-visibility' specifications."
6213 ;; Do not throw an error before first heading.
6215 (org-test-with-temp-text "Preamble\n* Headline"
6216 (org-show-set-visibility 'tree
)
6218 ;; Test all visibility spans, both on headline and in entry.
6219 (let ((list-visible-lines
6220 (lambda (state headerp
)
6221 (org-test-with-temp-text "* Grandmother (0)
6232 **** The other child (11)
6237 (search-forward (if headerp
"Self" "Match"))
6238 (org-show-set-visibility state
)
6239 (goto-char (point-min))
6240 (let (result (line 0))
6242 (unless (org-invisible-p2) (push line result
))
6245 (nreverse result
))))))
6246 (should (equal '(0 7) (funcall list-visible-lines
'minimal t
)))
6247 (should (equal '(0 7 8) (funcall list-visible-lines
'minimal nil
)))
6248 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local t
)))
6249 (should (equal '(0 7 8 9) (funcall list-visible-lines
'local nil
)))
6250 (should (equal '(0 3 7) (funcall list-visible-lines
'ancestors t
)))
6251 (should (equal '(0 3 7 8) (funcall list-visible-lines
'ancestors nil
)))
6252 (should (equal '(0 3 5 7 12) (funcall list-visible-lines
'lineage t
)))
6253 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines
'lineage nil
)))
6254 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines
'tree t
)))
6255 (should (equal '(0 1 3 5 7 8 9 11 12 13)
6256 (funcall list-visible-lines
'tree nil
)))
6257 (should (equal '(0 1 3 4 5 7 12 13)
6258 (funcall list-visible-lines
'canonical t
)))
6259 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
6260 (funcall list-visible-lines
'canonical nil
))))
6261 ;; When point is hidden in a drawer or a block, make sure to make it
6264 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
6265 (org-hide-block-toggle)
6266 (search-forward "Text")
6267 (org-show-set-visibility 'minimal
)
6268 (org-invisible-p2)))
6270 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
6272 (search-forward "Text")
6273 (org-show-set-visibility 'minimal
)
6274 (org-invisible-p2)))
6276 (org-test-with-temp-text
6277 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
6280 (org-hide-block-toggle)
6281 (search-forward "Text")
6282 (org-show-set-visibility 'minimal
)
6283 (org-invisible-p2))))
6288 ;;; test-org.el ends here