Ensure test files are opened in Emacs in test-org/fuzzy-links
[org-mode.git] / testing / lisp / test-org.el
blob79d768f8521e085f1ac55a43b8e6e7c0cac624fd
1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
4 ;; Authors: 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 ;;; Comments:
23 ;; Template test file for Org tests
25 ;;; Code:
28 ;;; Comments
30 (ert-deftest test-org/toggle-comment ()
31 "Test `org-toggle-comment' specifications."
32 ;; Simple headline.
33 (should
34 (equal "* Test"
35 (org-test-with-temp-text "* COMMENT Test"
36 (org-toggle-comment)
37 (buffer-string))))
38 (should
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
41 (org-toggle-comment)
42 (buffer-string))))
43 ;; Headline with a regular keyword.
44 (should
45 (equal "* TODO Test"
46 (org-test-with-temp-text "* TODO COMMENT Test"
47 (org-toggle-comment)
48 (buffer-string))))
49 (should
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
52 (org-toggle-comment)
53 (buffer-string))))
54 ;; Empty headline.
55 (should
56 (equal "* "
57 (org-test-with-temp-text "* COMMENT"
58 (org-toggle-comment)
59 (buffer-string))))
60 (should
61 (equal "* COMMENT"
62 (org-test-with-temp-text "* "
63 (org-toggle-comment)
64 (buffer-string))))
65 ;; Headline with a single keyword.
66 (should
67 (equal "* TODO "
68 (org-test-with-temp-text "* TODO COMMENT"
69 (org-toggle-comment)
70 (buffer-string))))
71 (should
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
74 (org-toggle-comment)
75 (buffer-string))))
76 ;; Headline with a keyword, a priority cookie and contents.
77 (should
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
80 (org-toggle-comment)
81 (buffer-string))))
82 (should
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
85 (org-toggle-comment)
86 (buffer-string)))))
88 (ert-deftest test-org/comment-dwim ()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
92 (should
93 (equal "# \nComment"
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim)
96 (buffer-string)))))
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
99 (should
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim)
103 (buffer-string)))))
104 ;; No region selected, and a comment on this line: indent it.
105 (should
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t))
110 (call-interactively 'comment-dwim))
111 (buffer-string)))))
112 ;; Also recognize single # at column 0 as comments.
113 (should
114 (equal "# Comment"
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim)
118 (buffer-string)))))
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
121 (should
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
124 (progn
125 (transient-mark-mode 1)
126 (push-mark (point) t t)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim)
129 (buffer-string)))))
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
132 (should
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
135 (progn
136 (transient-mark-mode 1)
137 (push-mark (point) t t)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil))
140 (call-interactively 'comment-dwim))
141 (buffer-string)))))
142 (should
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
145 (progn
146 (transient-mark-mode 1)
147 (push-mark (point) t t)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t))
150 (call-interactively 'comment-dwim))
151 (buffer-string)))))
152 ;; In front of a keyword without region, insert a new comment.
153 (should
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim)
157 (buffer-string)))))
158 ;; In a source block, use appropriate syntax.
159 (should
160 (equal " ;; "
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
162 (forward-line)
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
166 (should
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
169 (forward-line)
170 (transient-mark-mode 1)
171 (push-mark (point) t t)
172 (forward-line 2)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim))
175 (buffer-string)))))
179 ;;; Date and time analysis
181 (ert-deftest test-org/org-read-date ()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t))
186 (org-read-date t nil "12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t))
190 (org-read-date t nil "29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t))
194 (org-read-date t nil "29.03. 16:40"))))
195 ;; Relative date applied to current time if there is single
196 ;; plus/minus, or to default date when there are two of them.
197 (should
198 (equal
199 "2015-03-04"
200 (cl-letf (((symbol-function 'current-time)
201 (lambda ()
202 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
203 (org-read-date
204 t nil "+1y" nil
205 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
206 (should
207 (equal
208 "2013-03-29"
209 (cl-letf (((symbol-function 'current-time)
210 (lambda ()
211 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
212 (org-read-date
213 t nil "++1y" nil
214 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
215 ;; When `org-read-date-prefer-future' is non-nil, prefer future
216 ;; dates (relatively to now) when incomplete. Otherwise, use
217 ;; default date.
218 (should
219 (equal
220 "2014-04-01"
221 (cl-letf (((symbol-function 'current-time)
222 (lambda ()
223 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
224 (let ((org-read-date-prefer-future t))
225 (org-read-date t nil "1")))))
226 (should
227 (equal
228 "2013-03-04"
229 (cl-letf (((symbol-function 'current-time)
230 (lambda ()
231 (apply #'encode-time (org-parse-time-string "2012-03-29")))))
232 (let ((org-read-date-prefer-future t))
233 (org-read-date t nil "3-4")))))
234 (should
235 (equal
236 "2012-03-04"
237 (cl-letf (((symbol-function 'current-time)
238 (lambda ()
239 (apply #'encode-time (org-parse-time-string "2012-03-29")))))
240 (let ((org-read-date-prefer-future nil))
241 (org-read-date t nil "3-4")))))
242 ;; When set to `org-read-date-prefer-future' is set to `time', read
243 ;; day is moved to tomorrow if specified hour is before current
244 ;; time. However, it only happens in no other part of the date is
245 ;; specified.
246 (should
247 (equal
248 "2012-03-30"
249 (cl-letf (((symbol-function 'current-time)
250 (lambda ()
251 (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
252 (let ((org-read-date-prefer-future 'time))
253 (org-read-date t nil "00:40" nil)))))
254 (should-not
255 (equal
256 "2012-03-30"
257 (cl-letf (((symbol-function 'current-time)
258 (lambda ()
259 (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
260 (let ((org-read-date-prefer-future 'time))
261 (org-read-date t nil "29 00:40" nil)))))
262 ;; Caveat: `org-read-date-prefer-future' always refers to current
263 ;; time, not default time, when they differ.
264 (should
265 (equal
266 "2014-04-01"
267 (cl-letf (((symbol-function 'current-time)
268 (lambda ()
269 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
270 (let ((org-read-date-prefer-future t))
271 (org-read-date
272 t nil "1" nil
273 (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
274 (should
275 (equal
276 "2014-03-25"
277 (cl-letf (((symbol-function 'current-time)
278 (lambda ()
279 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
280 (let ((org-read-date-prefer-future t))
281 (org-read-date
282 t nil "25" nil
283 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
285 (ert-deftest test-org/org-parse-time-string ()
286 "Test `org-parse-time-string'."
287 (should (equal (org-parse-time-string "2012-03-29 16:40")
288 '(0 40 16 29 3 2012 nil nil nil)))
289 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
290 '(0 40 16 29 3 2012 nil nil nil)))
291 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
292 '(0 40 16 29 3 2012 nil nil nil)))
293 (should (equal (org-parse-time-string "<2012-03-29>")
294 '(0 0 0 29 3 2012 nil nil nil)))
295 (should (equal (org-parse-time-string "<2012-03-29>" t)
296 '(0 nil nil 29 3 2012 nil nil nil))))
298 (ert-deftest test-org/closest-date ()
299 "Test `org-closest-date' specifications."
300 (require 'calendar)
301 ;; Time stamps without a repeater are returned unchanged.
302 (should
303 (equal
304 '(3 29 2012)
305 (calendar-gregorian-from-absolute
306 (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
307 ;; Time stamps with a null repeater are returned unchanged.
308 (should
309 (equal
310 '(3 29 2012)
311 (calendar-gregorian-from-absolute
312 (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
313 ;; if PREFER is set to `past' always return a date before, or equal
314 ;; to CURRENT.
315 (should
316 (equal
317 '(3 1 2014)
318 (calendar-gregorian-from-absolute
319 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
320 (should
321 (equal
322 '(3 4 2014)
323 (calendar-gregorian-from-absolute
324 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
325 ;; if PREFER is set to `future' always return a date before, or equal
326 ;; to CURRENT.
327 (should
328 (equal
329 '(3 29 2014)
330 (calendar-gregorian-from-absolute
331 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
332 (should
333 (equal
334 '(3 4 2014)
335 (calendar-gregorian-from-absolute
336 (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
337 ;; If PREFER is neither `past' nor `future', select closest date.
338 (should
339 (equal
340 '(3 1 2014)
341 (calendar-gregorian-from-absolute
342 (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
343 (should
344 (equal
345 '(5 4 2014)
346 (calendar-gregorian-from-absolute
347 (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
348 ;; Test "day" repeater.
349 (should
350 (equal '(3 8 2014)
351 (calendar-gregorian-from-absolute
352 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
353 (should
354 (equal '(3 10 2014)
355 (calendar-gregorian-from-absolute
356 (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
357 ;; Test "month" repeater.
358 (should
359 (equal '(1 5 2015)
360 (calendar-gregorian-from-absolute
361 (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
362 (should
363 (equal '(3 29 2014)
364 (calendar-gregorian-from-absolute
365 (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
366 ;; Test "year" repeater.
367 (should
368 (equal '(3 5 2014)
369 (calendar-gregorian-from-absolute
370 (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
371 (should
372 (equal '(3 29 2014)
373 (calendar-gregorian-from-absolute
374 (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
376 (ert-deftest test-org/deadline-close-p ()
377 "Test `org-deadline-close-p' specifications."
378 ;; Pretend that the current time is 2016-06-03 Fri 01:43
379 (cl-letf (((symbol-function 'current-time)
380 (lambda () '(22353 6425 905205 644000))))
381 ;; Timestamps are close if they are within `ndays' of lead time.
382 (org-test-with-temp-text "* Heading"
383 (should (org-deadline-close-p "2016-06-03 Fri" 0))
384 (should (org-deadline-close-p "2016-06-02 Thu" 0))
385 (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
386 (should (org-deadline-close-p "2016-06-04 Sat" 1))
387 (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
388 ;; Read `ndays' from timestamp if argument not given.
389 (org-test-with-temp-text "* H"
390 (should (org-deadline-close-p "2016-06-04 Sat -1d"))
391 (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
392 (should (org-deadline-close-p "2016-06-10 Fri -1w"))
393 (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
394 ;; Prefer `ndays' argument over lead time in timestamp.
395 (org-test-with-temp-text "* H"
396 (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
397 (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
398 ;; Completed tasks are never close.
399 (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
400 (org-test-with-temp-text "* TODO Heading"
401 (should (org-deadline-close-p "2016-06-03")))
402 (org-test-with-temp-text "* DONE Heading"
403 (should-not (org-deadline-close-p "2016-06-03"))))))
406 ;;; Drawers
408 (ert-deftest test-org/insert-property-drawer ()
409 "Test `org-insert-property-drawer' specifications."
410 ;; Error before first headline.
411 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
412 ;; Insert drawer right after headline if there is no planning line,
413 ;; or after it otherwise.
414 (should
415 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
416 (org-test-with-temp-text "* H\nParagraph<point>"
417 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
418 (buffer-string))))
419 (should
420 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
421 (org-test-with-temp-text
422 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
423 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
424 (buffer-string))))
425 ;; Indent inserted drawer.
426 (should
427 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
428 (org-test-with-temp-text "* H\nParagraph<point>"
429 (let ((org-adapt-indentation t)) (org-insert-property-drawer))
430 (buffer-string))))
431 ;; Handle insertion at eob.
432 (should
433 (equal "* H\n:PROPERTIES:\n:END:\n"
434 (org-test-with-temp-text "* H"
435 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
436 (buffer-string))))
437 ;; Skip inlinetasks before point.
438 (when (featurep 'org-inlinetask)
439 (should
440 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
441 (org-test-with-temp-text
442 "* H\n*************** I\n*************** END\nP<point>"
443 (let ((org-adapt-indentation nil)
444 (org-inlinetask-min-level 15))
445 (org-insert-property-drawer))
446 (buffer-string)))))
447 ;; Correctly set drawer in an inlinetask.
448 (when (featurep 'org-inlinetask)
449 (should
450 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
451 (org-test-with-temp-text
452 "* H\n*************** I\nP<point>\n*************** END"
453 (let ((org-adapt-indentation nil)
454 (org-inlinetask-min-level 15))
455 (org-insert-property-drawer))
456 (buffer-string))))))
459 ;;; Filling
461 (ert-deftest test-org/fill-paragraph ()
462 "Test `org-fill-paragraph' specifications."
463 ;; At an Org table, align it.
464 (should
465 (equal "| a |\n"
466 (org-test-with-temp-text "|a|"
467 (org-fill-paragraph)
468 (buffer-string))))
469 (should
470 (equal "#+name: table\n| a |\n"
471 (org-test-with-temp-text "#+name: table\n| a |\n"
472 (org-fill-paragraph)
473 (buffer-string))))
474 ;; At a paragraph, preserve line breaks.
475 (org-test-with-temp-text "some \\\\\nlong\ntext"
476 (let ((fill-column 20))
477 (org-fill-paragraph)
478 (should (equal (buffer-string) "some \\\\\nlong text"))))
479 ;; Correctly fill a paragraph when point is at its very end.
480 (should
481 (equal "A B"
482 (org-test-with-temp-text "A\nB"
483 (let ((fill-column 20))
484 (goto-char (point-max))
485 (org-fill-paragraph)
486 (buffer-string)))))
487 ;; Correctly fill the last paragraph of a greater element.
488 (should
489 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
490 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
491 (let ((fill-column 8))
492 (forward-line)
493 (end-of-line)
494 (org-fill-paragraph)
495 (buffer-string)))))
496 ;; Correctly fill an element in a narrowed buffer.
497 (should
498 (equal "01234\n6"
499 (org-test-with-temp-text "01234 6789"
500 (let ((fill-column 5))
501 (narrow-to-region 1 8)
502 (org-fill-paragraph)
503 (buffer-string)))))
504 ;; Handle `adaptive-fill-regexp' in paragraphs.
505 (should
506 (equal "> a b"
507 (org-test-with-temp-text "> a\n> b"
508 (let ((fill-column 5)
509 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
510 (org-fill-paragraph)
511 (buffer-string)))))
512 ;; Special case: Fill first paragraph when point is at an item or
513 ;; a plain-list or a footnote reference.
514 (should
515 (equal "- A B"
516 (org-test-with-temp-text "- A\n B"
517 (let ((fill-column 20))
518 (org-fill-paragraph)
519 (buffer-string)))))
520 (should
521 (equal "[fn:1] A B"
522 (org-test-with-temp-text "[fn:1] A\nB"
523 (let ((fill-column 20))
524 (org-fill-paragraph)
525 (buffer-string)))))
526 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
527 (let ((fill-column 20))
528 (org-fill-paragraph)
529 (should (equal (buffer-string)
530 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
531 ;; Fill contents of `comment-block' elements.
532 (should
533 (equal
534 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
535 (let ((fill-column 20))
536 (forward-line)
537 (org-fill-paragraph)
538 (buffer-string)))
539 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
540 ;; Fill `comment' elements.
541 (should
542 (equal " # A B"
543 (org-test-with-temp-text " # A\n # B"
544 (let ((fill-column 20))
545 (org-fill-paragraph)
546 (buffer-string)))))
547 ;; Do not mix consecutive comments when filling one of them.
548 (should
549 (equal "# A B\n\n# C"
550 (org-test-with-temp-text "# A\n# B\n\n# C"
551 (let ((fill-column 20))
552 (org-fill-paragraph)
553 (buffer-string)))))
554 ;; Use commented empty lines as separators when filling comments.
555 (should
556 (equal "# A B\n#\n# C"
557 (org-test-with-temp-text "# A\n# B\n#\n# C"
558 (let ((fill-column 20))
559 (org-fill-paragraph)
560 (buffer-string)))))
561 ;; Handle `adaptive-fill-regexp' in comments.
562 (should
563 (equal "# > a b"
564 (org-test-with-temp-text "# > a\n# > b"
565 (let ((fill-column 20)
566 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
567 (org-fill-paragraph)
568 (buffer-string)))))
569 ;; Do nothing at affiliated keywords.
570 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
571 (let ((fill-column 20))
572 (org-fill-paragraph)
573 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
574 ;; Do not move point after table when filling a table.
575 (should-not
576 (org-test-with-temp-text "| a | b |\n| c | d |\n"
577 (forward-char)
578 (org-fill-paragraph)
579 (eobp))))
581 (ert-deftest test-org/auto-fill-function ()
582 "Test auto-filling features."
583 ;; Auto fill paragraph.
584 (should
585 (equal "12345\n7890"
586 (org-test-with-temp-text "12345 7890"
587 (let ((fill-column 5))
588 (end-of-line)
589 (org-auto-fill-function)
590 (buffer-string)))))
591 ;; Auto fill first paragraph in an item.
592 (should
593 (equal "- 12345\n 7890"
594 (org-test-with-temp-text "- 12345 7890"
595 (let ((fill-column 7))
596 (end-of-line)
597 (org-auto-fill-function)
598 (buffer-string)))))
599 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
600 (should
601 (equal "> 12345\n 7890"
602 (org-test-with-temp-text "> 12345 7890"
603 (let ((fill-column 10)
604 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
605 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
606 (end-of-line)
607 (org-auto-fill-function)
608 (buffer-string)))))
609 (should
610 (equal "> 12345\n> 12345\n> 7890"
611 (org-test-with-temp-text "> 12345\n> 12345 7890"
612 (let ((fill-column 10)
613 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
614 (goto-char (point-max))
615 (org-auto-fill-function)
616 (buffer-string)))))
617 (should-not
618 (equal " 12345\n *12345\n *12345"
619 (org-test-with-temp-text " 12345\n *12345 12345"
620 (let ((fill-column 10)
621 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
622 (goto-char (point-max))
623 (org-auto-fill-function)
624 (buffer-string)))))
625 ;; Auto fill comments.
626 (should
627 (equal " # 12345\n # 7890"
628 (org-test-with-temp-text " # 12345 7890"
629 (let ((fill-column 10))
630 (end-of-line)
631 (org-auto-fill-function)
632 (buffer-string)))))
633 ;; A hash within a line isn't a comment.
634 (should-not
635 (equal "12345 # 7890\n# 1"
636 (org-test-with-temp-text "12345 # 7890 1"
637 (let ((fill-column 12))
638 (end-of-line)
639 (org-auto-fill-function)
640 (buffer-string)))))
641 ;; Correctly interpret empty prefix.
642 (should-not
643 (equal "# a\n# b\nRegular\n# paragraph"
644 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
645 (let ((fill-column 12))
646 (end-of-line 3)
647 (org-auto-fill-function)
648 (buffer-string)))))
649 ;; Comment block: auto fill contents.
650 (should
651 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
652 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
653 (let ((fill-column 5))
654 (forward-line)
655 (end-of-line)
656 (org-auto-fill-function)
657 (buffer-string)))))
658 (should
659 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
660 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
661 (let ((fill-column 5))
662 (forward-line)
663 (end-of-line)
664 (org-auto-fill-function)
665 (buffer-string)))))
666 ;; Do not fill if a new item could be created.
667 (should-not
668 (equal "12345\n- 90"
669 (org-test-with-temp-text "12345 - 90"
670 (let ((fill-column 5))
671 (end-of-line)
672 (org-auto-fill-function)
673 (buffer-string)))))
674 ;; Do not fill if a line break could be introduced.
675 (should-not
676 (equal "123\\\\\n7890"
677 (org-test-with-temp-text "123\\\\ 7890"
678 (let ((fill-column 6))
679 (end-of-line)
680 (org-auto-fill-function)
681 (buffer-string)))))
682 ;; Do not fill affiliated keywords.
683 (should-not
684 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
685 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
686 (let ((fill-column 20))
687 (end-of-line)
688 (org-auto-fill-function)
689 (buffer-string))))))
693 ;;; Indentation
695 (ert-deftest test-org/indent-line ()
696 "Test `org-indent-line' specifications."
697 ;; Do not indent diary sexps, footnote definitions or headlines.
698 (should
699 (zerop
700 (org-test-with-temp-text "%%(org-calendar-holiday)"
701 (org-indent-line)
702 (org-get-indentation))))
703 (should
704 (zerop
705 (org-test-with-temp-text "[fn:1] fn"
706 (let ((org-adapt-indentation t)) (org-indent-line))
707 (org-get-indentation))))
708 (should
709 (zerop
710 (org-test-with-temp-text "* H"
711 (org-indent-line)
712 (org-get-indentation))))
713 ;; Do not indent before first headline.
714 (should
715 (zerop
716 (org-test-with-temp-text ""
717 (org-indent-line)
718 (org-get-indentation))))
719 ;; Indent according to headline level otherwise, unless
720 ;; `org-adapt-indentation' is nil.
721 (should
722 (= 2
723 (org-test-with-temp-text "* H\n<point>A"
724 (let ((org-adapt-indentation t)) (org-indent-line))
725 (org-get-indentation))))
726 (should
727 (= 2
728 (org-test-with-temp-text "* H\n<point>\nA"
729 (let ((org-adapt-indentation t)) (org-indent-line))
730 (org-get-indentation))))
731 (should
732 (zerop
733 (org-test-with-temp-text "* H\n<point>A"
734 (let ((org-adapt-indentation nil)) (org-indent-line))
735 (org-get-indentation))))
736 ;; Indenting preserves point position.
737 (should
738 (org-test-with-temp-text "* H\nA<point>B"
739 (let ((org-adapt-indentation t)) (org-indent-line))
740 (looking-at "B")))
741 ;; Do not change indentation at an item or a LaTeX environment.
742 (should
743 (= 1
744 (org-test-with-temp-text "* H\n<point> - A"
745 (let ((org-adapt-indentation t)) (org-indent-line))
746 (org-get-indentation))))
747 (should
748 (= 1
749 (org-test-with-temp-text
750 "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
751 (org-indent-line)
752 (org-get-indentation))))
753 ;; On blank lines at the end of a list, indent like last element
754 ;; within it if the line is still in the list. If the last element
755 ;; is an item, indent like its contents. Otherwise, indent like the
756 ;; whole list.
757 (should
758 (= 4
759 (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
760 (let ((org-adapt-indentation t)) (org-indent-line))
761 (org-get-indentation))))
762 (should
763 (= 4
764 (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
765 (let ((org-adapt-indentation t)) (org-indent-line))
766 (org-get-indentation))))
767 (should
768 (zerop
769 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
770 (let ((org-adapt-indentation t)) (org-indent-line))
771 (org-get-indentation))))
772 (should
773 (= 4
774 (org-test-with-temp-text "* H\n- A\n - \n<point>"
775 (let ((org-adapt-indentation t)) (org-indent-line))
776 (org-get-indentation))))
777 (should
778 (= 4
779 (org-test-with-temp-text
780 "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
781 (let ((org-adapt-indentation t)) (org-indent-line))
782 (org-get-indentation))))
783 (should
784 (= 2
785 (org-test-with-temp-text "- A\n B\n\n<point>"
786 (let ((org-adapt-indentation nil)) (org-indent-line))
787 (org-get-indentation))))
788 ;; Likewise, on a blank line at the end of a footnote definition,
789 ;; indent at column 0 if line belongs to the definition. Otherwise,
790 ;; indent like the definition itself.
791 (should
792 (zerop
793 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
794 (goto-char (point-max))
795 (let ((org-adapt-indentation t)) (org-indent-line))
796 (org-get-indentation))))
797 (should
798 (zerop
799 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
800 (goto-char (point-max))
801 (let ((org-adapt-indentation t)) (org-indent-line))
802 (org-get-indentation))))
803 ;; After the end of the contents of a greater element, indent like
804 ;; the beginning of the element.
805 (should
806 (= 1
807 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
808 (forward-line 2)
809 (org-indent-line)
810 (org-get-indentation))))
811 ;; On blank lines after a paragraph, indent like its last non-empty
812 ;; line.
813 (should
814 (= 1
815 (org-test-with-temp-text " Paragraph\n\n<point>"
816 (org-indent-line)
817 (org-get-indentation))))
818 ;; At the first line of an element, indent like previous element's
819 ;; first line, ignoring footnotes definitions and inline tasks, or
820 ;; according to parent.
821 (should
822 (= 2
823 (org-test-with-temp-text "A\n\n B\n\nC"
824 (goto-char (point-max))
825 (org-indent-line)
826 (org-get-indentation))))
827 (should
828 (= 1
829 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
830 (goto-char (point-max))
831 (org-indent-line)
832 (org-get-indentation))))
833 (should
834 (= 1
835 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
836 (forward-line 1)
837 (org-indent-line)
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.
842 (should
843 (= 6
844 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
845 (forward-line 2)
846 (let ((org-src-tab-acts-natively t)
847 (org-edit-src-content-indentation 0))
848 (org-indent-line))
849 (org-get-indentation))))
850 (should
851 (= 1
852 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
853 (forward-line 2)
854 (let ((org-src-tab-acts-natively nil)
855 (org-edit-src-content-indentation 0))
856 (org-indent-line))
857 (org-get-indentation))))
858 ;; Otherwise, indent like the first non-blank line above.
859 (should
860 (zerop
861 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
862 (forward-line 3)
863 (org-indent-line)
864 (org-get-indentation))))
865 ;; Align node properties according to `org-property-format'. Handle
866 ;; nicely empty values.
867 (should
868 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
869 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
870 (let ((org-property-format "%-10s %s")) (org-indent-line))
871 (buffer-string))))
872 (should
873 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
874 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
875 (let ((org-property-format "%-10s %s")) (org-indent-line))
876 (buffer-string)))))
878 (ert-deftest test-org/indent-region ()
879 "Test `org-indent-region' specifications."
880 ;; Indent paragraph.
881 (should
882 (equal "A\nB\nC"
883 (org-test-with-temp-text " A\nB\n C"
884 (org-indent-region (point-min) (point-max))
885 (buffer-string))))
886 ;; Indent greater elements along with their contents.
887 (should
888 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
889 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
890 (org-indent-region (point-min) (point-max))
891 (buffer-string))))
892 ;; Ignore contents of verse blocks. Only indent block delimiters.
893 (should
894 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
895 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
896 (org-indent-region (point-min) (point-max))
897 (buffer-string))))
898 (should
899 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
900 (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
901 (org-indent-region (point-min) (point-max))
902 (buffer-string))))
903 ;; Indent example blocks as a single block, unless indentation
904 ;; should be preserved. In this case only indent the block markers.
905 (should
906 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
907 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
908 (org-indent-region (point-min) (point-max))
909 (buffer-string))))
910 (should
911 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
912 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
913 (org-indent-region (point-min) (point-max))
914 (buffer-string))))
915 (should
916 (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
917 (org-test-with-temp-text
918 " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
919 (org-indent-region (point-min) (point-max))
920 (buffer-string))))
921 (should
922 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
923 (org-test-with-temp-text
924 " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
925 (let ((org-src-preserve-indentation t))
926 (org-indent-region (point-min) (point-max)))
927 (buffer-string))))
928 ;; Treat export blocks as a whole.
929 (should
930 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
931 (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
932 (org-indent-region (point-min) (point-max))
933 (buffer-string))))
934 (should
935 (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
936 (org-test-with-temp-text
937 " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
938 (org-indent-region (point-min) (point-max))
939 (buffer-string))))
940 ;; Indent according to mode if `org-src-tab-acts-natively' is
941 ;; non-nil. Otherwise, do not indent code at all.
942 (should
943 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
944 (org-test-with-temp-text
945 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
946 (let ((org-src-tab-acts-natively t)
947 (org-edit-src-content-indentation 0))
948 (org-indent-region (point-min) (point-max)))
949 (buffer-string))))
950 (should
951 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
952 (org-test-with-temp-text
953 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
954 (let ((org-src-tab-acts-natively nil)
955 (org-edit-src-content-indentation 0))
956 (org-indent-region (point-min) (point-max)))
957 (buffer-string))))
958 ;; Align node properties according to `org-property-format'. Handle
959 ;; nicely empty values.
960 (should
961 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
962 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
963 (let ((org-property-format "%-10s %s")
964 (org-adapt-indentation nil))
965 (org-indent-region (point) (point-max)))
966 (buffer-string))))
967 (should
968 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
969 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
970 (let ((org-property-format "%-10s %s")
971 (org-adapt-indentation nil))
972 (org-indent-region (point) (point-max)))
973 (buffer-string))))
974 ;; Indent plain lists.
975 (should
976 (equal "- A\n B\n - C\n\n D"
977 (org-test-with-temp-text "- A\n B\n - C\n\n D"
978 (org-indent-region (point-min) (point-max))
979 (buffer-string))))
980 (should
981 (equal "- A\n\n- B"
982 (org-test-with-temp-text " - A\n\n - B"
983 (org-indent-region (point-min) (point-max))
984 (buffer-string))))
985 ;; Indent footnote definitions.
986 (should
987 (equal "[fn:1] Definition\n\nDefinition"
988 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
989 (org-indent-region (point-min) (point-max))
990 (buffer-string))))
991 ;; Special case: Start indenting on a blank line.
992 (should
993 (equal "\nParagraph"
994 (org-test-with-temp-text "\n Paragraph"
995 (org-indent-region (point-min) (point-max))
996 (buffer-string)))))
1000 ;;; Editing
1002 (ert-deftest test-org/delete-indentation ()
1003 "Test `org-delete-indentation' specifications."
1004 ;; Regular test.
1005 (should (equal "foo bar"
1006 (org-test-with-temp-text
1007 "foo \n bar<point>"
1008 (org-delete-indentation)
1009 (buffer-string))))
1010 ;; With optional argument.
1011 (should (equal "foo bar"
1012 (org-test-with-temp-text
1013 "foo<point> \n bar"
1014 (org-delete-indentation t)
1015 (buffer-string))))
1016 ;; At headline text should be appended to the headline text.
1017 (should
1018 (equal"* foo bar :tag:"
1019 (let (org-auto-align-tags)
1020 (org-test-with-temp-text
1021 "* foo :tag:\n bar<point>"
1022 (org-delete-indentation)
1023 (buffer-string)))))
1024 (should
1025 (equal "* foo bar :tag:"
1026 (let (org-auto-align-tags)
1027 (org-test-with-temp-text
1028 "* foo <point>:tag:\n bar"
1029 (org-delete-indentation t)
1030 (buffer-string))))))
1032 (ert-deftest test-org/return ()
1033 "Test `org-return' specifications."
1034 ;; Regular test.
1035 (should
1036 (equal "Para\ngraph"
1037 (org-test-with-temp-text "Para<point>graph"
1038 (org-return)
1039 (buffer-string))))
1040 ;; With optional argument, indent line.
1041 (should
1042 (equal " Para\n graph"
1043 (org-test-with-temp-text " Para<point>graph"
1044 (org-return t)
1045 (buffer-string))))
1046 ;; On a table, call `org-table-next-row'.
1047 (should
1048 (org-test-with-temp-text "| <point>a |\n| b |"
1049 (org-return)
1050 (looking-at-p "b")))
1051 ;; Open link or timestamp under point when `org-return-follows-link'
1052 ;; is non-nil.
1053 (should
1054 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1055 (let ((org-return-follows-link t)
1056 (org-link-search-must-match-exact-headline nil))
1057 (org-return))
1058 (looking-at-p "<<target>>")))
1059 (should-not
1060 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
1061 (let ((org-return-follows-link nil)) (org-return))
1062 (looking-at-p "<<target>>")))
1063 (should
1064 (org-test-with-temp-text "* [[b][a<point>]]\n* b"
1065 (let ((org-return-follows-link t)) (org-return))
1066 (looking-at-p "* b")))
1067 (should
1068 (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
1069 (let ((org-return-follows-link t)
1070 (org-link-search-must-match-exact-headline nil))
1071 (org-return))
1072 (looking-at-p "<<target>>")))
1073 (should-not
1074 (org-test-with-temp-text "Link [[target]]<point> <<target>>"
1075 (let ((org-return-follows-link t)
1076 (org-link-search-must-match-exact-headline nil))
1077 (org-return))
1078 (looking-at-p "<<target>>")))
1079 ;; When `org-return-follows-link' is non-nil, tolerate links and
1080 ;; timestamps in comments, node properties, etc.
1081 (should
1082 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1083 (let ((org-return-follows-link t)
1084 (org-link-search-must-match-exact-headline nil))
1085 (org-return))
1086 (looking-at-p "<<target>>")))
1087 (should-not
1088 (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
1089 (let ((org-return-follows-link nil)) (org-return))
1090 (looking-at-p "<<target>>")))
1091 (should-not
1092 (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
1093 (let ((org-return-follows-link t)
1094 (org-link-search-must-match-exact-headline nil))
1095 (org-return))
1096 (looking-at-p "<<target>>")))
1097 ;; However, do not open link when point is in a table.
1098 (should
1099 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
1100 (let ((org-return-follows-link t)) (org-return))
1101 (looking-at-p "between")))
1102 ;; Special case: in a list, when indenting, do not break structure.
1103 (should
1104 (equal "- A\n B"
1105 (org-test-with-temp-text "- A <point>B"
1106 (org-return t)
1107 (buffer-string))))
1108 (should
1109 (equal "- A\n\n- B"
1110 (org-test-with-temp-text "- A\n<point>- B"
1111 (org-return t)
1112 (buffer-string))))
1113 ;; On tags part of a headline, add a newline below it instead of
1114 ;; breaking it.
1115 (should
1116 (equal "* H :tag:\n"
1117 (org-test-with-temp-text "* H :<point>tag:"
1118 (org-return)
1119 (buffer-string))))
1120 ;; Before headline text, add a newline below it instead of breaking
1121 ;; it.
1122 (should
1123 (equal "* TODO H :tag:\n"
1124 (org-test-with-temp-text "* <point>TODO H :tag:"
1125 (org-return)
1126 (buffer-string))))
1127 (should
1128 (equal "* TODO [#B] H :tag:\n"
1129 (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
1130 (org-return)
1131 (buffer-string))))
1132 (should ;TODO are case-sensitive
1133 (equal "* \nTodo"
1134 (org-test-with-temp-text "* <point>Todo"
1135 (org-return)
1136 (buffer-string))))
1137 ;; At headline text, break headline text but preserve tags.
1138 (should
1139 (equal "* TODO [#B] foo :tag:\nbar"
1140 (let (org-auto-align-tags)
1141 (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
1142 (org-return)
1143 (buffer-string)))))
1144 ;; At bol of headline insert newline.
1145 (should
1146 (equal "\n* h"
1147 (org-test-with-temp-text "<point>* h"
1148 (org-return)
1149 (buffer-string))))
1150 ;; Refuse to leave invalid headline in buffer.
1151 (should
1152 (equal "* h\n"
1153 (org-test-with-temp-text "*<point> h"
1154 (org-return)
1155 (buffer-string)))))
1157 (ert-deftest test-org/meta-return ()
1158 "Test M-RET (`org-meta-return') specifications."
1159 ;; In a table field insert a row above.
1160 (should
1161 (org-test-with-temp-text "| a |"
1162 (forward-char)
1163 (org-meta-return)
1164 (forward-line -1)
1165 (looking-at "| |$")))
1166 ;; In a paragraph change current line into a header.
1167 (should
1168 (org-test-with-temp-text "a"
1169 (org-meta-return)
1170 (beginning-of-line)
1171 (looking-at "\* a$")))
1172 ;; In an item insert an item, in this case above.
1173 (should
1174 (org-test-with-temp-text "- a"
1175 (org-meta-return)
1176 (beginning-of-line)
1177 (looking-at "- $")))
1178 ;; In a drawer and item insert an item, in this case above.
1179 (should
1180 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
1181 (forward-line)
1182 (org-meta-return)
1183 (beginning-of-line)
1184 (looking-at "- $"))))
1186 (ert-deftest test-org/insert-heading ()
1187 "Test `org-insert-heading' specifications."
1188 ;; In an empty buffer, insert a new headline.
1189 (should
1190 (equal "* "
1191 (org-test-with-temp-text ""
1192 (org-insert-heading)
1193 (buffer-string))))
1194 ;; At the beginning of a line, turn it into a headline
1195 (should
1196 (equal "* P"
1197 (org-test-with-temp-text "<point>P"
1198 (org-insert-heading)
1199 (buffer-string))))
1200 ;; In the middle of a line, split the line if allowed, otherwise,
1201 ;; insert the headline at its end.
1202 (should
1203 (equal "Para\n* graph"
1204 (org-test-with-temp-text "Para<point>graph"
1205 (let ((org-M-RET-may-split-line '((default . t))))
1206 (org-insert-heading))
1207 (buffer-string))))
1208 (should
1209 (equal "Paragraph\n* "
1210 (org-test-with-temp-text "Para<point>graph"
1211 (let ((org-M-RET-may-split-line '((default . nil))))
1212 (org-insert-heading))
1213 (buffer-string))))
1214 ;; At the beginning of a headline, create one above.
1215 (should
1216 (equal "* \n* H"
1217 (org-test-with-temp-text "* H"
1218 (org-insert-heading)
1219 (buffer-string))))
1220 ;; In the middle of a headline, split it if allowed.
1221 (should
1222 (equal "* H\n* 1"
1223 (org-test-with-temp-text "* H<point>1"
1224 (let ((org-M-RET-may-split-line '((headline . t))))
1225 (org-insert-heading))
1226 (buffer-string))))
1227 (should
1228 (equal "* H1\n* "
1229 (org-test-with-temp-text "* H<point>1"
1230 (let ((org-M-RET-may-split-line '((headline . nil))))
1231 (org-insert-heading))
1232 (buffer-string))))
1233 ;; However, splitting cannot happen on TODO keywords, priorities or
1234 ;; tags.
1235 (should
1236 (equal "* TODO H1\n* "
1237 (org-test-with-temp-text "* TO<point>DO H1"
1238 (let ((org-M-RET-may-split-line '((headline . t))))
1239 (org-insert-heading))
1240 (buffer-string))))
1241 (should
1242 (equal "* [#A] H1\n* "
1243 (org-test-with-temp-text "* [#<point>A] H1"
1244 (let ((org-M-RET-may-split-line '((headline . t))))
1245 (org-insert-heading))
1246 (buffer-string))))
1247 (should
1248 (equal "* H1 :tag:\n* "
1249 (org-test-with-temp-text "* H1 :ta<point>g:"
1250 (let ((org-M-RET-may-split-line '((headline . t))))
1251 (org-insert-heading))
1252 (buffer-string))))
1253 ;; When on a list, insert an item instead, unless called with an
1254 ;; universal argument or if list is invisible. In this case, create
1255 ;; a new headline after contents.
1256 (should
1257 (equal "* H\n- item\n- "
1258 (org-test-with-temp-text "* H\n- item<point>"
1259 (let ((org-insert-heading-respect-content nil))
1260 (org-insert-heading))
1261 (buffer-string))))
1262 (should
1263 (equal "* H\n- item\n- item 2\n* "
1264 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
1265 (let ((org-insert-heading-respect-content nil))
1266 (org-insert-heading '(4)))
1267 (buffer-string))))
1268 (should
1269 (equal "* H\n- item\n* "
1270 (org-test-with-temp-text "* H\n- item"
1271 (org-cycle)
1272 (goto-char (point-max))
1273 (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
1274 (buffer-string))))
1275 ;; Preserve list visibility when inserting an item.
1276 (should
1277 (equal
1278 '(outline outline)
1279 (org-test-with-temp-text "- A\n - B\n- C\n - D"
1280 (let ((org-cycle-include-plain-lists t))
1281 (org-cycle)
1282 (forward-line 2)
1283 (org-cycle)
1284 (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
1285 (list (get-char-property (line-beginning-position 0) 'invisible)
1286 (get-char-property (line-end-position 2) 'invisible))))))
1287 ;; When called with one universal argument, insert a new headline at
1288 ;; the end of the current subtree, independently on the position of
1289 ;; point.
1290 (should
1291 (equal
1292 "* H1\n** H2\n* "
1293 (org-test-with-temp-text "* H1\n** H2"
1294 (let ((org-insert-heading-respect-content nil))
1295 (org-insert-heading '(4)))
1296 (buffer-string))))
1297 (should
1298 (equal
1299 "* H1\n** H2\n* "
1300 (org-test-with-temp-text "* H<point>1\n** H2"
1301 (let ((org-insert-heading-respect-content nil))
1302 (org-insert-heading '(4)))
1303 (buffer-string))))
1304 ;; When called with two universal arguments, insert a new headline
1305 ;; at the end of the grandparent subtree.
1306 (should
1307 (equal "* H1\n** H3\n- item\n** H2\n** "
1308 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
1309 (let ((org-insert-heading-respect-content nil))
1310 (org-insert-heading '(16)))
1311 (buffer-string))))
1312 ;; When optional TOP-LEVEL argument is non-nil, always insert
1313 ;; a level 1 heading.
1314 (should
1315 (equal "* H1\n** H2\n* "
1316 (org-test-with-temp-text "* H1\n** H2<point>"
1317 (org-insert-heading nil nil t)
1318 (buffer-string))))
1319 (should
1320 (equal "* H1\n- item\n* "
1321 (org-test-with-temp-text "* H1\n- item<point>"
1322 (org-insert-heading nil nil t)
1323 (buffer-string))))
1324 ;; Corner case: correctly insert a headline after an empty one.
1325 (should
1326 (equal "* \n* "
1327 (org-test-with-temp-text "* <point>"
1328 (org-insert-heading)
1329 (buffer-string)))))
1331 (ert-deftest test-org/insert-todo-heading-respect-content ()
1332 "Test `org-insert-todo-heading-respect-content' specifications."
1333 ;; Create a TODO heading.
1334 (should
1335 (org-test-with-temp-text "* H1\n Body"
1336 (org-insert-todo-heading-respect-content)
1337 (nth 2 (org-heading-components))))
1338 ;; Add headline at the end of the first subtree
1339 (should
1340 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
1341 (search-forward "H1Body")
1342 (org-insert-todo-heading-respect-content)
1343 (and (eobp) (org-at-heading-p))))
1344 ;; In a list, do not create a new item.
1345 (should
1346 (org-test-with-temp-text "* H\n- an item\n- another one"
1347 (search-forward "an ")
1348 (org-insert-todo-heading-respect-content)
1349 (and (eobp) (org-at-heading-p)))))
1351 (ert-deftest test-org/clone-with-time-shift ()
1352 "Test `org-clone-subtree-with-time-shift'."
1353 ;; Raise an error before first heading.
1354 (should-error
1355 (org-test-with-temp-text ""
1356 (org-clone-subtree-with-time-shift 1)))
1357 ;; Raise an error on invalid number of clones.
1358 (should-error
1359 (org-test-with-temp-text "* Clone me"
1360 (org-clone-subtree-with-time-shift -1)))
1361 ;; Clone non-repeating once.
1362 (should
1363 (equal "\
1364 * H1\n<2015-06-21>
1365 * H1\n<2015-06-23>
1367 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1368 (org-clone-subtree-with-time-shift 1 "+2d")
1369 (replace-regexp-in-string
1370 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1371 nil nil 1))))
1372 ;; Clone repeating once.
1373 (should
1374 (equal "\
1375 * H1\n<2015-06-21>
1376 * H1\n<2015-06-23>
1377 * H1\n<2015-06-25 +1w>
1379 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1380 (org-clone-subtree-with-time-shift 1 "+2d")
1381 (replace-regexp-in-string
1382 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1383 nil nil 1))))
1384 ;; Clone non-repeating zero times.
1385 (should
1386 (equal "\
1387 * H1\n<2015-06-21>
1389 (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
1390 (org-clone-subtree-with-time-shift 0 "+2d")
1391 (replace-regexp-in-string
1392 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1393 nil nil 1))))
1394 ;; Clone repeating "zero" times.
1395 (should
1396 (equal "\
1397 * H1\n<2015-06-21>
1398 * H1\n<2015-06-23 +1w>
1400 (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
1401 (org-clone-subtree-with-time-shift 0 "+2d")
1402 (replace-regexp-in-string
1403 "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
1404 nil nil 1))))
1405 ;; Clone with blank SHIFT argument.
1406 (should
1407 (string-prefix-p
1408 "* H <2012-03-29"
1409 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1410 (org-clone-subtree-with-time-shift 1 "")
1411 (buffer-substring-no-properties (line-beginning-position 2)
1412 (line-end-position 2)))))
1413 ;; Find time stamps before point. If SHIFT is not specified, ask
1414 ;; for a time shift.
1415 (should
1416 (string-prefix-p
1417 "* H <2012-03-30"
1418 (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
1419 (org-clone-subtree-with-time-shift 1 "+1d")
1420 (buffer-substring-no-properties (line-beginning-position 2)
1421 (line-end-position 2)))))
1422 (should
1423 (string-prefix-p
1424 "* H <2014-03-05"
1425 (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
1426 (cl-letf (((symbol-function 'read-from-minibuffer)
1427 (lambda (&rest args) "+1d")))
1428 (org-clone-subtree-with-time-shift 1))
1429 (buffer-substring-no-properties (line-beginning-position 2)
1430 (line-end-position 2))))))
1433 ;;; Fixed-Width Areas
1435 (ert-deftest test-org/toggle-fixed-width ()
1436 "Test `org-toggle-fixed-width' specifications."
1437 ;; No region: Toggle on fixed-width marker in paragraphs.
1438 (should
1439 (equal ": A"
1440 (org-test-with-temp-text "A"
1441 (org-toggle-fixed-width)
1442 (buffer-string))))
1443 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1444 (should
1445 (equal "A"
1446 (org-test-with-temp-text ": A"
1447 (org-toggle-fixed-width)
1448 (buffer-string))))
1449 ;; No region: Toggle on marker in blank lines after elements or just
1450 ;; after a headline.
1451 (should
1452 (equal "* H\n: "
1453 (org-test-with-temp-text "* H\n"
1454 (forward-line)
1455 (org-toggle-fixed-width)
1456 (buffer-string))))
1457 (should
1458 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1459 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1460 (goto-char (point-max))
1461 (org-toggle-fixed-width)
1462 (buffer-string))))
1463 ;; No region: Toggle on marker in front of one line elements (e.g.,
1464 ;; headlines, clocks)
1465 (should
1466 (equal ": * Headline"
1467 (org-test-with-temp-text "* Headline"
1468 (org-toggle-fixed-width)
1469 (buffer-string))))
1470 (should
1471 (equal ": #+KEYWORD: value"
1472 (org-test-with-temp-text "#+KEYWORD: value"
1473 (org-toggle-fixed-width)
1474 (buffer-string))))
1475 ;; No region: error in other situations.
1476 (should-error
1477 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1478 (forward-line)
1479 (org-toggle-fixed-width)
1480 (buffer-string)))
1481 ;; No region: Indentation is preserved.
1482 (should
1483 (equal "- A\n : B"
1484 (org-test-with-temp-text "- A\n B"
1485 (forward-line)
1486 (org-toggle-fixed-width)
1487 (buffer-string))))
1488 ;; Region: If it contains only fixed-width elements and blank lines,
1489 ;; toggle off fixed-width markup.
1490 (should
1491 (equal "A\n\nB"
1492 (org-test-with-temp-text ": A\n\n: B"
1493 (transient-mark-mode 1)
1494 (push-mark (point) t t)
1495 (goto-char (point-max))
1496 (org-toggle-fixed-width)
1497 (buffer-string))))
1498 ;; Region: If it contains anything else, toggle on fixed-width but
1499 ;; not on fixed-width areas.
1500 (should
1501 (equal ": A\n: \n: B\n: \n: C"
1502 (org-test-with-temp-text "A\n\n: B\n\nC"
1503 (transient-mark-mode 1)
1504 (push-mark (point) t t)
1505 (goto-char (point-max))
1506 (org-toggle-fixed-width)
1507 (buffer-string))))
1508 ;; Region: Ignore blank lines at its end, unless it contains only
1509 ;; such lines.
1510 (should
1511 (equal ": A\n\n"
1512 (org-test-with-temp-text "A\n\n"
1513 (transient-mark-mode 1)
1514 (push-mark (point) t t)
1515 (goto-char (point-max))
1516 (org-toggle-fixed-width)
1517 (buffer-string))))
1518 (should
1519 (equal ": \n: \n"
1520 (org-test-with-temp-text "\n\n"
1521 (transient-mark-mode 1)
1522 (push-mark (point) t t)
1523 (goto-char (point-max))
1524 (org-toggle-fixed-width)
1525 (buffer-string)))))
1529 ;;; Headline
1531 (ert-deftest test-org/get-heading ()
1532 "Test `org-get-heading' specifications."
1533 ;; Return current heading, even if point is not on it.
1534 (should
1535 (equal "H"
1536 (org-test-with-temp-text "* H"
1537 (org-get-heading))))
1538 (should
1539 (equal "H"
1540 (org-test-with-temp-text "* H\nText<point>"
1541 (org-get-heading))))
1542 ;; Without any optional argument, return TODO keywords and tags.
1543 (should
1544 (equal "TODO H"
1545 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1546 (org-get-heading))))
1547 (should
1548 (equal "H :tag:"
1549 (org-test-with-temp-text "* H :tag:"
1550 (org-get-heading))))
1551 ;; With NO-TAGS argument, ignore tags.
1552 (should
1553 (equal "TODO H"
1554 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1555 (org-get-heading t))))
1556 (should
1557 (equal "H"
1558 (org-test-with-temp-text "* H :tag:"
1559 (org-get-heading t))))
1560 ;; With NO-TODO, ignore TODO keyword.
1561 (should
1562 (equal "H"
1563 (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
1564 (org-get-heading nil t))))
1565 (should
1566 (equal "H :tag:"
1567 (org-test-with-temp-text "* H :tag:"
1568 (org-get-heading nil t))))
1569 ;; TODO keywords are case-sensitive.
1570 (should
1571 (equal "Todo H"
1572 (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
1573 (org-get-heading nil t))))
1574 ;; On an empty headline, return value is consistent.
1575 (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
1576 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
1577 (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
1578 (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t)))))
1580 (ert-deftest test-org/in-commented-heading-p ()
1581 "Test `org-in-commented-heading-p' specifications."
1582 ;; Commented headline.
1583 (should
1584 (org-test-with-temp-text "* COMMENT Headline\nBody"
1585 (goto-char (point-max))
1586 (org-in-commented-heading-p)))
1587 ;; Commented ancestor.
1588 (should
1589 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1590 (goto-char (point-max))
1591 (org-in-commented-heading-p)))
1592 ;; Comment keyword is case-sensitive.
1593 (should-not
1594 (org-test-with-temp-text "* Comment Headline\nBody"
1595 (goto-char (point-max))
1596 (org-in-commented-heading-p)))
1597 ;; Keyword is standalone.
1598 (should-not
1599 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1600 (goto-char (point-max))
1601 (org-in-commented-heading-p)))
1602 ;; Optional argument.
1603 (should-not
1604 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1605 (goto-char (point-max))
1606 (org-in-commented-heading-p t))))
1608 (ert-deftest test-org/entry-blocked-p ()
1609 ;; Check other dependencies.
1610 (should
1611 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
1612 (let ((org-enforce-todo-dependencies t)
1613 (org-blocker-hook
1614 '(org-block-todo-from-children-or-siblings-or-parent)))
1615 (org-entry-blocked-p))))
1616 (should-not
1617 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
1618 (let ((org-enforce-todo-dependencies t)
1619 (org-blocker-hook
1620 '(org-block-todo-from-children-or-siblings-or-parent)))
1621 (org-entry-blocked-p))))
1622 ;; Entry without a TODO keyword or with a DONE keyword cannot be
1623 ;; blocked.
1624 (should-not
1625 (org-test-with-temp-text "* Blocked\n** TODO one"
1626 (let ((org-enforce-todo-dependencies t)
1627 (org-blocker-hook
1628 '(org-block-todo-from-children-or-siblings-or-parent)))
1629 (org-entry-blocked-p))))
1630 (should-not
1631 (org-test-with-temp-text "* DONE Blocked\n** TODO one"
1632 (let ((org-enforce-todo-dependencies t)
1633 (org-blocker-hook
1634 '(org-block-todo-from-children-or-siblings-or-parent)))
1635 (org-entry-blocked-p))))
1636 ;; Follow :ORDERED: specifications.
1637 (should
1638 (org-test-with-temp-text
1639 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
1640 (let ((org-enforce-todo-dependencies t)
1641 (org-blocker-hook
1642 '(org-block-todo-from-children-or-siblings-or-parent)))
1643 (org-entry-blocked-p))))
1644 (should-not
1645 (org-test-with-temp-text
1646 "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
1647 (let ((org-enforce-todo-dependencies t)
1648 (org-blocker-hook
1649 '(org-block-todo-from-children-or-siblings-or-parent)))
1650 (org-entry-blocked-p)))))
1652 (ert-deftest test-org/get-outline-path ()
1653 "Test `org-get-outline-path' specifications."
1654 ;; Top-level headlines have no outline path.
1655 (should-not
1656 (org-test-with-temp-text "* H"
1657 (org-get-outline-path)))
1658 ;; Otherwise, outline path is the path leading to the headline.
1659 (should
1660 (equal '("H")
1661 (org-test-with-temp-text "* H\n** S<point>"
1662 (org-get-outline-path))))
1663 ;; Find path even when point is not on a headline.
1664 (should
1665 (equal '("H")
1666 (org-test-with-temp-text "* H\n** S\nText<point>"
1667 (org-get-outline-path))))
1668 ;; TODO keywords, tags and statistics cookies are ignored.
1669 (should
1670 (equal '("H")
1671 (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
1672 (org-get-outline-path))))
1673 ;; Links are replaced with their description or their path.
1674 (should
1675 (equal '("Org")
1676 (org-test-with-temp-text
1677 "* [[http://orgmode.org][Org]]\n** S<point>"
1678 (org-get-outline-path))))
1679 (should
1680 (equal '("http://orgmode.org")
1681 (org-test-with-temp-text
1682 "* [[http://orgmode.org]]\n** S<point>"
1683 (org-get-outline-path))))
1684 ;; When WITH-SELF is non-nil, include current heading.
1685 (should
1686 (equal '("H")
1687 (org-test-with-temp-text "* H"
1688 (org-get-outline-path t))))
1689 (should
1690 (equal '("H" "S")
1691 (org-test-with-temp-text "* H\n** S\nText<point>"
1692 (org-get-outline-path t))))
1693 ;; Using cache is transparent to the user.
1694 (should
1695 (equal '("H")
1696 (org-test-with-temp-text "* H\n** S<point>"
1697 (setq org-outline-path-cache nil)
1698 (org-get-outline-path nil t))))
1699 ;; Do not corrupt cache when finding outline path in distant part of
1700 ;; the buffer.
1701 (should
1702 (equal '("H2")
1703 (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
1704 (setq org-outline-path-cache nil)
1705 (org-get-outline-path nil t)
1706 (search-forward "S2")
1707 (org-get-outline-path nil t))))
1708 ;; Do not choke on empty headlines.
1709 (should
1710 (org-test-with-temp-text "* H\n** <point>"
1711 (org-get-outline-path)))
1712 (should
1713 (org-test-with-temp-text "* \n** H<point>"
1714 (org-get-outline-path))))
1716 (ert-deftest test-org/format-outline-path ()
1717 "Test `org-format-outline-path' specifications."
1718 (should
1719 (string= (org-format-outline-path (list "one" "two" "three"))
1720 "one/two/three"))
1721 ;; Empty path.
1722 (should
1723 (string= (org-format-outline-path '())
1724 ""))
1725 (should
1726 (string= (org-format-outline-path '(nil))
1727 ""))
1728 ;; Empty path and prefix.
1729 (should
1730 (string= (org-format-outline-path '() nil ">>")
1731 ">>"))
1732 ;; Trailing whitespace in headings.
1733 (should
1734 (string= (org-format-outline-path (list "one\t" "tw o " "three "))
1735 "one/tw o/three"))
1736 ;; Non-default prefix and separators.
1737 (should
1738 (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
1739 ">>|one|two|three"))
1740 ;; Truncate.
1741 (should
1742 (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
1743 "one/two/.."))
1744 ;; Give a very narrow width.
1745 (should
1746 (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
1747 "on"))
1748 ;; Give a prefix that extends beyond the width.
1749 (should
1750 (string= (org-format-outline-path (list "one" "two" "three" "four") 10
1751 ">>>>>>>>>>")
1752 ">>>>>>>>..")))
1754 (ert-deftest test-org/map-entries ()
1755 "Test `org-map-entries' specifications."
1756 ;; Full match.
1757 (should
1758 (equal '(1 11)
1759 (org-test-with-temp-text "* Level 1\n** Level 2"
1760 (org-map-entries #'point))))
1761 ;; Level match.
1762 (should
1763 (equal '(1)
1764 (org-test-with-temp-text "* Level 1\n** Level 2"
1765 (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
1766 (should
1767 (equal '(11)
1768 (org-test-with-temp-text "* Level 1\n** Level 2"
1769 (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
1770 ;; Tag match.
1771 (should
1772 (equal '(11)
1773 (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
1774 (org-map-entries #'point "yes"))))
1775 (should
1776 (equal '(14)
1777 (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
1778 (org-map-entries #'point "+yes-a"))))
1779 (should
1780 (equal '(11 23)
1781 (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
1782 (org-map-entries #'point "{yes?}"))))
1783 ;; Priority match.
1784 (should
1785 (equal '(1)
1786 (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
1787 (org-map-entries #'point "PRIORITY=\"A\""))))
1788 ;; Date match.
1789 (should
1790 (equal '(36)
1791 (org-test-with-temp-text "
1792 * H1
1793 SCHEDULED: <2012-03-29 thu.>
1794 * H2
1795 SCHEDULED: <2014-03-04 tue.>"
1796 (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
1797 (should
1798 (equal '(2)
1799 (org-test-with-temp-text "
1800 * H1
1801 SCHEDULED: <2012-03-29 thu.>
1802 * H2
1803 SCHEDULED: <2014-03-04 tue.>"
1804 (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
1805 ;; Regular property match.
1806 (should
1807 (equal '(2)
1808 (org-test-with-temp-text "
1809 * H1
1810 :PROPERTIES:
1811 :TEST: 1
1812 :END:
1813 * H2
1814 :PROPERTIES:
1815 :TEST: 2
1816 :END:"
1817 (org-map-entries #'point "TEST=1"))))
1818 ;; Multiple criteria.
1819 (should
1820 (equal '(23)
1821 (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
1822 (let (org-odd-levels-only
1823 (org-use-tag-inheritance nil))
1824 (org-map-entries #'point "yes+LEVEL=1")))))
1825 ;; "or" criteria.
1826 (should
1827 (equal '(12 24)
1828 (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
1829 (let (org-odd-levels-only)
1830 (org-map-entries #'point "LEVEL=2|no")))))
1831 (should
1832 (equal '(1 12)
1833 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
1834 (let (org-odd-levels-only)
1835 (org-map-entries #'point "yes|no")))))
1836 ;; "and" criteria.
1837 (should
1838 (equal '(22)
1839 (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
1840 (let (org-odd-levels-only)
1841 (org-map-entries #'point "yes&no"))))))
1843 (ert-deftest test-org/edit-headline ()
1844 "Test `org-edit-headline' specifications."
1845 (should
1846 (equal "* B"
1847 (org-test-with-temp-text "* A"
1848 (org-edit-headline "B")
1849 (buffer-string))))
1850 ;; Handle empty headings.
1851 (should
1852 (equal "* "
1853 (org-test-with-temp-text "* A"
1854 (org-edit-headline "")
1855 (buffer-string))))
1856 (should
1857 (equal "* A"
1858 (org-test-with-temp-text "* "
1859 (org-edit-headline "A")
1860 (buffer-string))))
1861 ;; Handle TODO keywords and priority cookies.
1862 (should
1863 (equal "* TODO B"
1864 (org-test-with-temp-text "* TODO A"
1865 (org-edit-headline "B")
1866 (buffer-string))))
1867 (should
1868 (equal "* [#A] B"
1869 (org-test-with-temp-text "* [#A] A"
1870 (org-edit-headline "B")
1871 (buffer-string))))
1872 (should
1873 (equal "* TODO [#A] B"
1874 (org-test-with-temp-text "* TODO [#A] A"
1875 (org-edit-headline "B")
1876 (buffer-string))))
1877 ;; Handle tags.
1878 (equal "* B :tag:"
1879 (org-test-with-temp-text "* A :tag:"
1880 (let ((org-tags-column 4)) (org-edit-headline "B"))
1881 (buffer-string))))
1885 ;;; Keywords
1887 (ert-deftest test-org/set-regexps-and-options ()
1888 "Test `org-set-regexps-and-options' specifications."
1889 ;; TAGS keyword.
1890 (should
1891 (equal '(("A"))
1892 (let ((org-tag-alist '(("A")))
1893 (org-tag-persistent-alist nil))
1894 (org-test-with-temp-text ""
1895 (org-mode-restart)
1896 org-current-tag-alist))))
1897 (should
1898 (equal '(("B"))
1899 (let ((org-tag-alist '(("A")))
1900 (org-tag-persistent-alist nil))
1901 (org-test-with-temp-text "#+TAGS: B"
1902 (org-mode-restart)
1903 org-current-tag-alist))))
1904 (should
1905 (equal '(("C") ("B"))
1906 (let ((org-tag-alist '(("A")))
1907 (org-tag-persistent-alist '(("C"))))
1908 (org-test-with-temp-text "#+TAGS: B"
1909 (org-mode-restart)
1910 org-current-tag-alist))))
1911 (should
1912 (equal '(("B"))
1913 (let ((org-tag-alist '(("A")))
1914 (org-tag-persistent-alist '(("C"))))
1915 (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
1916 (org-mode-restart)
1917 org-current-tag-alist))))
1918 (should
1919 (equal '(("A" . ?a) ("B") ("C"))
1920 (let ((org-tag-persistant-alist nil))
1921 (org-test-with-temp-text "#+TAGS: A(a) B C"
1922 (org-mode-restart)
1923 org-current-tag-alist))))
1924 (should
1925 (equal '(("A") (:newline) ("B"))
1926 (let ((org-tag-persistent-alist nil))
1927 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1928 (org-mode-restart)
1929 org-current-tag-alist))))
1930 (should
1931 (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
1932 (let ((org-tag-persistent-alist nil))
1933 (org-test-with-temp-text "#+TAGS: { A B } C"
1934 (org-mode-restart)
1935 org-current-tag-alist))))
1936 (should
1937 (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
1938 (let ((org-tag-persistent-alist nil))
1939 (org-test-with-temp-text "#+TAGS: { A : B C }"
1940 (org-mode-restart)
1941 org-current-tag-alist))))
1942 (should
1943 (equal '(("A" "B" "C"))
1944 (let ((org-tag-persistent-alist nil))
1945 (org-test-with-temp-text "#+TAGS: { A : B C }"
1946 (org-mode-restart)
1947 org-tag-groups-alist))))
1948 (should
1949 (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
1950 (let ((org-tag-persistent-alist nil))
1951 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1952 (org-mode-restart)
1953 org-current-tag-alist))))
1954 (should
1955 (equal '(("A" "B" "C"))
1956 (let ((org-tag-persistent-alist nil))
1957 (org-test-with-temp-text "#+TAGS: [ A : B C ]"
1958 (org-mode-restart)
1959 org-tag-groups-alist))))
1960 ;; FILETAGS keyword.
1961 (should
1962 (equal '("A" "B" "C")
1963 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1964 (org-mode-restart)
1965 org-file-tags)))
1966 ;; PROPERTY keyword. Property names are case-insensitive.
1967 (should
1968 (equal "foo=1"
1969 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1970 (org-mode-restart)
1971 (cdr (assoc "var" org-file-properties)))))
1972 (should
1973 (equal
1974 "foo=1 bar=2"
1975 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1976 (org-mode-restart)
1977 (cdr (assoc "var" org-file-properties)))))
1978 (should
1979 (equal
1980 "foo=1 bar=2"
1981 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1982 (org-mode-restart)
1983 (cdr (assoc "var" org-file-properties)))))
1984 ;; ARCHIVE keyword.
1985 (should
1986 (equal "%s_done::"
1987 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1988 (org-mode-restart)
1989 org-archive-location)))
1990 ;; CATEGORY keyword.
1991 (should
1992 (eq 'test
1993 (org-test-with-temp-text "#+CATEGORY: test"
1994 (org-mode-restart)
1995 org-category)))
1996 (should
1997 (equal "test"
1998 (org-test-with-temp-text "#+CATEGORY: test"
1999 (org-mode-restart)
2000 (cdr (assoc "CATEGORY" org-file-properties)))))
2001 ;; COLUMNS keyword.
2002 (should
2003 (equal "%25ITEM %TAGS %PRIORITY %TODO"
2004 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
2005 (org-mode-restart)
2006 org-columns-default-format)))
2007 ;; CONSTANTS keyword. Constants names are case sensitive.
2008 (should
2009 (equal '("299792458." "3.14")
2010 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
2011 (org-mode-restart)
2012 (mapcar
2013 (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
2014 '("c" "pi")))))
2015 (should
2016 (equal "3.14"
2017 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
2018 (org-mode-restart)
2019 (cdr (assoc "pi" org-table-formula-constants-local)))))
2020 (should
2021 (equal "22/7"
2022 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
2023 (org-mode-restart)
2024 (cdr (assoc "PI" org-table-formula-constants-local)))))
2025 ;; LINK keyword.
2026 (should
2027 (equal
2028 '("url1" "url2")
2029 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
2030 (org-mode-restart)
2031 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
2032 '("a" "b")))))
2033 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
2034 (should
2035 (equal
2036 '(?X ?Z ?Y)
2037 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
2038 (org-mode-restart)
2039 (list org-highest-priority org-lowest-priority org-default-priority))))
2040 (should
2041 (equal
2042 '(?A ?C ?B)
2043 (org-test-with-temp-text "#+PRIORITIES: X Z"
2044 (org-mode-restart)
2045 (list org-highest-priority org-lowest-priority org-default-priority))))
2046 ;; STARTUP keyword.
2047 (should
2048 (equal '(t t)
2049 (org-test-with-temp-text "#+STARTUP: fold odd"
2050 (org-mode-restart)
2051 (list org-startup-folded org-odd-levels-only))))
2052 ;; TODO keywords.
2053 (should
2054 (equal '(("A" "B") ("C"))
2055 (org-test-with-temp-text "#+TODO: A B | C"
2056 (org-mode-restart)
2057 (list org-not-done-keywords org-done-keywords))))
2058 (should
2059 (equal '(("A" "C") ("B" "D"))
2060 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
2061 (org-mode-restart)
2062 (list org-not-done-keywords org-done-keywords))))
2063 (should
2064 (equal '(("A" "B") ("C"))
2065 (org-test-with-temp-text "#+TYP_TODO: A B | C"
2066 (org-mode-restart)
2067 (list org-not-done-keywords org-done-keywords))))
2068 (should
2069 (equal '((:startgroup) ("A" . ?a) (:endgroup))
2070 (org-test-with-temp-text "#+TODO: A(a)"
2071 (org-mode-restart)
2072 org-todo-key-alist)))
2073 (should
2074 (equal '(("D" note nil) ("C" time nil) ("B" note time))
2075 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
2076 (org-mode-restart)
2077 org-todo-log-states)))
2078 ;; Enter SETUPFILE keyword.
2079 (should
2080 (equal "1"
2081 (org-test-with-temp-text
2082 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
2083 (org-mode-restart)
2084 (cdr (assoc "a" org-file-properties))))))
2088 ;;; Links
2090 ;;;; Coderefs
2092 (ert-deftest test-org/coderef ()
2093 "Test coderef links specifications."
2094 (should
2095 (org-test-with-temp-text "
2096 #+BEGIN_SRC emacs-lisp
2097 \(+ 1 1) (ref:sc)
2098 #+END_SRC
2099 \[[(sc)<point>]]"
2100 (org-open-at-point)
2101 (looking-at "(ref:sc)")))
2102 ;; Find coderef even with alternate label format.
2103 (should
2104 (org-test-with-temp-text "
2105 #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
2106 \(+ 1 1) {ref:sc}
2107 #+END_SRC
2108 \[[(sc)<point>]]"
2109 (org-open-at-point)
2110 (looking-at "{ref:sc}"))))
2112 ;;;; Custom ID
2114 (ert-deftest test-org/custom-id ()
2115 "Test custom ID links specifications."
2116 (should
2117 (org-test-with-temp-text
2118 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2119 (org-open-at-point)
2120 (looking-at-p "\\* H1")))
2121 ;; Throw an error on false positives.
2122 (should-error
2123 (org-test-with-temp-text
2124 "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
2125 (org-open-at-point)
2126 (looking-at-p "\\* H1"))))
2128 ;;;; Fuzzy Links
2130 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
2131 ;; a named element (#+name: text) and to headlines (* Text).
2133 (ert-deftest test-org/fuzzy-links ()
2134 "Test fuzzy links specifications."
2135 ;; Fuzzy link goes in priority to a matching target.
2136 (should
2137 (org-test-with-temp-text
2138 "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
2139 (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
2140 (looking-at "<<Test>>")))
2141 ;; Then fuzzy link points to an element with a given name.
2142 (should
2143 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
2144 (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
2145 (looking-at "#\\+NAME: Test")))
2146 ;; A target still lead to a matching headline otherwise.
2147 (should
2148 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
2149 (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
2150 (looking-at "\\* Head2")))
2151 ;; With a leading star in link, enforce heading match.
2152 (should
2153 (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
2154 (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
2155 (looking-at "\\* Test")))
2156 ;; With a leading star in link, enforce exact heading match, even
2157 ;; with `org-link-search-must-match-exact-headline' set to nil.
2158 (should-error
2159 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
2160 (let ((org-link-search-must-match-exact-headline nil))
2161 (org-open-at-point))))
2162 ;; Handle non-nil `org-link-search-must-match-exact-headline'.
2163 (should
2164 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
2165 (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
2166 (looking-at "\\* Test")))
2167 (should
2168 (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
2169 (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
2170 (looking-at "\\* Test")))
2171 ;; Heading match should not care about spaces, cookies, TODO
2172 ;; keywords, priorities, and tags. However, TODO keywords are
2173 ;; case-sensitive.
2174 (should
2175 (let ((first-line
2176 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
2177 (org-test-with-temp-text
2178 (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
2179 (let ((org-link-search-must-match-exact-headline nil)
2180 (org-todo-regexp "TODO"))
2181 (org-open-at-point))
2182 (looking-at (regexp-quote first-line)))))
2183 (should-error
2184 (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
2185 (let ((org-link-search-must-match-exact-headline nil)
2186 (org-todo-regexp "TODO"))
2187 (org-open-at-point))))
2188 ;; Heading match should still be exact.
2189 (should-error
2190 (org-test-with-temp-text "
2191 ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
2192 Foo Bar
2193 <point>[[*Test 1]]"
2194 (let ((org-link-search-must-match-exact-headline nil)
2195 (org-todo-regexp "TODO"))
2196 (org-open-at-point))))
2197 (should
2198 (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
2199 (let ((org-link-search-must-match-exact-headline nil)
2200 (org-todo-regexp "TODO"))
2201 (org-open-at-point))
2202 (looking-at-p (regexp-quote "** Test 1 2"))))
2203 ;; Heading match ignores COMMENT keyword.
2204 (should
2205 (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
2206 (org-open-at-point)
2207 (looking-at "\\* COMMENT Test")))
2208 (should
2209 (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
2210 (org-open-at-point)
2211 (looking-at "\\* TODO COMMENT Test")))
2212 ;; Correctly un-hexify fuzzy links.
2213 (should
2214 (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
2215 (org-open-at-point)
2216 (bobp)))
2217 (should
2218 (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
2219 (org-open-at-point)
2220 (bobp)))
2221 ;; Match search strings containing newline characters, including
2222 ;; blank lines.
2223 (should
2224 (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
2225 (let ((file (buffer-file-name)))
2226 (goto-char (point-max))
2227 (insert (format "[[file:%s::line1 line2]]" file))
2228 (beginning-of-line)
2229 (let ((org-link-search-must-match-exact-headline nil))
2230 (org-open-at-point 0))
2231 (looking-at-p "line1"))))
2232 (should
2233 (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
2234 (let ((file (buffer-file-name)))
2235 (goto-char (point-max))
2236 (insert (format "[[file:%s::line1 line2]]" file))
2237 (beginning-of-line)
2238 (let ((org-link-search-must-match-exact-headline nil))
2239 (org-open-at-point 0))
2240 (looking-at-p "line1")))))
2242 ;;;; Link Escaping
2244 (ert-deftest test-org/org-link-escape-ascii-character ()
2245 "Escape an ascii character."
2246 (should
2247 (string=
2248 "%5B"
2249 (org-link-escape "["))))
2251 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
2252 "Escape an ascii control character."
2253 (should
2254 (string=
2255 "%09"
2256 (org-link-escape "\t"))))
2258 (ert-deftest test-org/org-link-escape-multibyte-character ()
2259 "Escape an unicode multibyte character."
2260 (should
2261 (string=
2262 "%E2%82%AC"
2263 (org-link-escape "€"))))
2265 (ert-deftest test-org/org-link-escape-custom-table ()
2266 "Escape string with custom character table."
2267 (should
2268 (string=
2269 "Foo%3A%42ar%0A"
2270 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
2272 (ert-deftest test-org/org-link-escape-custom-table-merge ()
2273 "Escape string with custom table merged with default table."
2274 (should
2275 (string=
2276 "%5BF%6F%6F%3A%42ar%0A%5D"
2277 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
2279 (ert-deftest test-org/org-link-unescape-ascii-character ()
2280 "Unescape an ascii character."
2281 (should
2282 (string=
2284 (org-link-unescape "%5B"))))
2286 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
2287 "Unescpae an ascii control character."
2288 (should
2289 (string=
2290 "\n"
2291 (org-link-unescape "%0A"))))
2293 (ert-deftest test-org/org-link-unescape-multibyte-character ()
2294 "Unescape unicode multibyte character."
2295 (should
2296 (string=
2297 "€"
2298 (org-link-unescape "%E2%82%AC"))))
2300 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
2301 "Unescape old style percent escaped character."
2302 (should
2303 (string=
2304 "àâçèéêîôùû"
2305 (decode-coding-string
2306 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
2308 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
2309 "Escape and unescape a URL that includes an escaped char.
2310 http://article.gmane.org/gmane.emacs.orgmode/21459/"
2311 (should
2312 (string=
2313 "http://some.host.com/form?&id=blah%2Bblah25"
2314 (org-link-unescape
2315 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
2317 ;;;; Open at point
2319 (ert-deftest test-org/open-at-point-in-keyword ()
2320 "Does `org-open-at-point' open link in a keyword line?"
2321 (should
2322 (org-test-with-temp-text
2323 "<<top>>\n#+KEYWORD: <point>[[top]]"
2324 (org-open-at-point) t)))
2326 (ert-deftest test-org/open-at-point-in-property ()
2327 "Does `org-open-at-point' open link in property drawer?"
2328 (should
2329 (org-test-with-temp-text
2330 "* Headline
2331 :PROPERTIES:
2332 :URL: <point>[[*Headline]]
2333 :END:"
2334 (org-open-at-point) t)))
2336 (ert-deftest test-org/open-at-point-in-comment ()
2337 "Does `org-open-at-point' open link in a commented line?"
2338 (should
2339 (org-test-with-temp-text
2340 "<<top>>\n# <point>[[top]]"
2341 (org-open-at-point) t)))
2343 (ert-deftest test-org/open-at-point/inline-image ()
2344 "Test `org-open-at-point' on nested links."
2345 (should
2346 (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
2347 (org-open-at-point)
2348 (bobp))))
2350 (ert-deftest test-org/open-at-point/radio-target ()
2351 "Test `org-open-at-point' on radio targets."
2352 (should
2353 (org-test-with-temp-text "<<<target>>> <point>target"
2354 (org-update-radio-target-regexp)
2355 (org-open-at-point)
2356 (eq (org-element-type (org-element-context)) 'radio-target))))
2358 ;;;; Stored links
2360 (ert-deftest test-org/store-link ()
2361 "Test `org-store-link' specifications."
2362 ;; On a headline, link to that headline. Use heading as the
2363 ;; description of the link.
2364 (should
2365 (let (org-store-link-props org-stored-links)
2366 (org-test-with-temp-text-in-file "* H1"
2367 (let ((file (buffer-file-name)))
2368 (equal (format "[[file:%s::*H1][H1]]" file)
2369 (org-store-link nil))))))
2370 ;; On a headline, remove any link from description.
2371 (should
2372 (let (org-store-link-props org-stored-links)
2373 (org-test-with-temp-text-in-file "* [[#l][d]]"
2374 (let ((file (buffer-file-name)))
2375 (equal (format "[[file:%s::*%s][d]]"
2376 file
2377 (org-link-escape "[[#l][d]]"))
2378 (org-store-link nil))))))
2379 (should
2380 (let (org-store-link-props org-stored-links)
2381 (org-test-with-temp-text-in-file "* [[l]]"
2382 (let ((file (buffer-file-name)))
2383 (equal (format "[[file:%s::*%s][l]]" file (org-link-escape "[[l]]"))
2384 (org-store-link nil))))))
2385 (should
2386 (let (org-store-link-props org-stored-links)
2387 (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
2388 (let ((file (buffer-file-name)))
2389 (equal (format "[[file:%s::*%s][d1 d2]]"
2390 file
2391 (org-link-escape "[[l1][d1]] [[l2][d2]]"))
2392 (org-store-link nil))))))
2393 ;; On a named element, link to that element.
2394 (should
2395 (let (org-store-link-props org-stored-links)
2396 (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
2397 (let ((file (buffer-file-name)))
2398 (equal (format "[[file:%s::foo][foo]]" file)
2399 (org-store-link nil)))))))
2402 ;;; Node Properties
2404 (ert-deftest test-org/accumulated-properties-in-drawers ()
2405 "Ensure properties accumulate in subtree drawers."
2406 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
2407 (org-babel-next-src-block)
2408 (should (equal '(2 1) (org-babel-execute-src-block)))))
2410 (ert-deftest test-org/custom-properties ()
2411 "Test custom properties specifications."
2412 ;; Standard test.
2413 (should
2414 (let ((org-custom-properties '("FOO")))
2415 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2416 (org-toggle-custom-properties-visibility)
2417 (org-invisible-p2))))
2418 ;; Properties are case-insensitive.
2419 (should
2420 (let ((org-custom-properties '("FOO")))
2421 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
2422 (org-toggle-custom-properties-visibility)
2423 (org-invisible-p2))))
2424 (should
2425 (let ((org-custom-properties '("foo")))
2426 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
2427 (org-toggle-custom-properties-visibility)
2428 (org-invisible-p2))))
2429 ;; Multiple custom properties in the same drawer.
2430 (should
2431 (let ((org-custom-properties '("FOO" "BAR")))
2432 (org-test-with-temp-text
2433 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
2434 (org-toggle-custom-properties-visibility)
2435 (and (org-invisible-p2)
2436 (not (progn (forward-line) (org-invisible-p2)))
2437 (progn (forward-line) (org-invisible-p2))))))
2438 ;; Hide custom properties with an empty value.
2439 (should
2440 (let ((org-custom-properties '("FOO")))
2441 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
2442 (org-toggle-custom-properties-visibility)
2443 (org-invisible-p2))))
2444 ;; Do not hide fake properties.
2445 (should-not
2446 (let ((org-custom-properties '("FOO")))
2447 (org-test-with-temp-text ":FOO: val\n"
2448 (org-toggle-custom-properties-visibility)
2449 (org-invisible-p2))))
2450 (should-not
2451 (let ((org-custom-properties '("A")))
2452 (org-test-with-temp-text
2453 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
2454 (org-toggle-custom-properties-visibility)
2455 (org-invisible-p2)))))
2459 ;;; Mark Region
2461 (ert-deftest test-org/mark-subtree ()
2462 "Test `org-mark-subtree' specifications."
2463 ;; Error when point is before first headline.
2464 (should-error
2465 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
2466 (progn (transient-mark-mode 1)
2467 (org-mark-subtree))))
2468 ;; Without argument, mark current subtree.
2469 (should
2470 (equal
2471 '(12 32)
2472 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2473 (progn (transient-mark-mode 1)
2474 (forward-line 2)
2475 (org-mark-subtree)
2476 (list (region-beginning) (region-end))))))
2477 ;; With an argument, move ARG up.
2478 (should
2479 (equal
2480 '(1 32)
2481 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
2482 (progn (transient-mark-mode 1)
2483 (forward-line 2)
2484 (org-mark-subtree 1)
2485 (list (region-beginning) (region-end))))))
2486 ;; Do not get fooled by inlinetasks.
2487 (when (featurep 'org-inlinetask)
2488 (should
2489 (= 1
2490 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
2491 (progn (transient-mark-mode 1)
2492 (forward-line 1)
2493 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
2494 (region-beginning)))))))
2498 ;;; Miscellaneous
2500 (ert-deftest test-org/in-regexp ()
2501 "Test `org-in-regexp' specifications."
2502 ;; Standard tests.
2503 (should
2504 (org-test-with-temp-text "xx ab<point>c xx"
2505 (org-in-regexp "abc")))
2506 (should-not
2507 (org-test-with-temp-text "xx abc <point>xx"
2508 (org-in-regexp "abc")))
2509 ;; Return non-nil even with multiple matching regexps in the same
2510 ;; line.
2511 (should
2512 (org-test-with-temp-text "abc xx ab<point>c xx"
2513 (org-in-regexp "abc")))
2514 ;; With optional argument NLINES, check extra lines around point.
2515 (should-not
2516 (org-test-with-temp-text "A\nB<point>\nC"
2517 (org-in-regexp "A\nB\nC")))
2518 (should
2519 (org-test-with-temp-text "A\nB<point>\nC"
2520 (org-in-regexp "A\nB\nC" 1)))
2521 (should-not
2522 (org-test-with-temp-text "A\nB\nC<point>"
2523 (org-in-regexp "A\nB\nC" 1)))
2524 ;; When optional argument VISUALLY is non-nil, return nil if at
2525 ;; regexp boundaries.
2526 (should
2527 (org-test-with-temp-text "xx abc<point> xx"
2528 (org-in-regexp "abc")))
2529 (should-not
2530 (org-test-with-temp-text "xx abc<point> xx"
2531 (org-in-regexp "abc" nil t))))
2534 ;;; Navigation
2536 (ert-deftest test-org/end-of-meta-data ()
2537 "Test `org-end-of-meta-data' specifications."
2538 ;; Skip planning line.
2539 (should
2540 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
2541 (org-end-of-meta-data)
2542 (eobp)))
2543 ;; Skip properties drawer.
2544 (should
2545 (org-test-with-temp-text
2546 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
2547 (org-end-of-meta-data)
2548 (eobp)))
2549 ;; Skip both.
2550 (should
2551 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
2552 (org-end-of-meta-data)
2553 (eobp)))
2554 ;; Nothing to skip, go to first line.
2555 (should
2556 (org-test-with-temp-text "* Headline\nContents"
2557 (org-end-of-meta-data)
2558 (looking-at "Contents")))
2559 ;; With option argument, skip empty lines, regular drawers and
2560 ;; clocking lines.
2561 (should
2562 (org-test-with-temp-text "* Headline\n\nContents"
2563 (org-end-of-meta-data t)
2564 (looking-at "Contents")))
2565 (should
2566 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
2567 (org-end-of-meta-data t)
2568 (looking-at "Contents")))
2569 (should
2570 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
2571 (org-end-of-meta-data t)
2572 (looking-at "Contents")))
2573 ;; Special case: do not skip incomplete drawers.
2574 (should
2575 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
2576 (org-end-of-meta-data t)
2577 (looking-at ":LOGBOOK:")))
2578 ;; Special case: Be careful about consecutive headlines.
2579 (should-not
2580 (org-test-with-temp-text "* H1\n*H2\nContents"
2581 (org-end-of-meta-data t)
2582 (looking-at "Contents"))))
2584 (ert-deftest test-org/beginning-of-line ()
2585 "Test `org-beginning-of-line' specifications."
2586 ;; Move to beginning of line. If current line in invisible, move to
2587 ;; beginning of visible line instead.
2588 (should
2589 (org-test-with-temp-text "Some text\nSome other text<point>"
2590 (org-beginning-of-line)
2591 (bolp)))
2592 (should
2593 (org-test-with-temp-text "* H1\n** H2<point>"
2594 (org-overview)
2595 (org-beginning-of-line)
2596 (= (line-beginning-position) 1)))
2597 ;; With `visual-line-mode' active, move to beginning of visual line.
2598 (should-not
2599 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2600 (visual-line-mode)
2601 (dotimes (i 1000) (insert "very "))
2602 (org-beginning-of-line)
2603 (bolp)))
2604 ;; In a wide headline, with `visual-line-mode', prefer going to the
2605 ;; beginning of a visual line than to the logical beginning of line,
2606 ;; even if special movement is active.
2607 (should-not
2608 (org-test-with-temp-text "* A <point>long headline"
2609 (visual-line-mode)
2610 (dotimes (i 1000) (insert "very "))
2611 (goto-char (point-max))
2612 (org-beginning-of-line)
2613 (bobp)))
2614 (should-not
2615 (org-test-with-temp-text "* A <point>long headline"
2616 (visual-line-mode)
2617 (dotimes (i 1000) (insert "very "))
2618 (goto-char (point-max))
2619 (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
2620 (bobp)))
2621 ;; At an headline with special movement, first move at beginning of
2622 ;; title, then at the beginning of line, rinse, repeat.
2623 (should
2624 (org-test-with-temp-text "* TODO Headline<point>"
2625 (let ((org-special-ctrl-a/e t))
2626 (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
2627 (progn (org-beginning-of-line) (bolp))
2628 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2629 (should
2630 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2631 (let ((org-special-ctrl-a/e t))
2632 (org-beginning-of-line)
2633 (looking-at "Headline"))))
2634 (should
2635 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2636 (let ((org-special-ctrl-a/e '(t . nil)))
2637 (org-beginning-of-line)
2638 (looking-at "Headline"))))
2639 (should-not
2640 (org-test-with-temp-text "* TODO [#A] Headline<point>"
2641 (let ((org-special-ctrl-a/e '(nil . nil)))
2642 (org-beginning-of-line)
2643 (looking-at "Headline"))))
2644 ;; At an headline with reversed movement, first move to beginning of
2645 ;; line, then to the beginning of title.
2646 (should
2647 (org-test-with-temp-text "* TODO Headline<point>"
2648 (let ((org-special-ctrl-a/e 'reversed)
2649 (this-command last-command))
2650 (and (progn (org-beginning-of-line) (bolp))
2651 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2652 (should
2653 (org-test-with-temp-text "* TODO Headline<point>"
2654 (let ((org-special-ctrl-a/e '(reversed . nil))
2655 (this-command last-command))
2656 (and (progn (org-beginning-of-line) (bolp))
2657 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2658 (should-not
2659 (org-test-with-temp-text "* TODO Headline<point>"
2660 (let ((org-special-ctrl-a/e '(t . nil))
2661 (this-command last-command))
2662 (and (progn (org-beginning-of-line) (bolp))
2663 (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
2664 ;; At an item with special movement, first move after to beginning
2665 ;; of title, then to the beginning of line, rinse, repeat.
2666 (should
2667 (org-test-with-temp-text "- [ ] Item<point>"
2668 (let ((org-special-ctrl-a/e t))
2669 (and (progn (org-beginning-of-line) (looking-at-p "Item"))
2670 (progn (org-beginning-of-line) (bolp))
2671 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2672 ;; At an item with reversed movement, first move to beginning of
2673 ;; line, then to the beginning of title.
2674 (should
2675 (org-test-with-temp-text "- [X] Item<point>"
2676 (let ((org-special-ctrl-a/e 'reversed)
2677 (this-command last-command))
2678 (and (progn (org-beginning-of-line) (bolp))
2679 (progn (org-beginning-of-line) (looking-at-p "Item"))))))
2680 ;; Leave point before invisible characters at column 0.
2681 (should
2682 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2683 (let ((org-special-ctrl-a/e nil))
2684 (org-beginning-of-line)
2685 (bolp))))
2686 (should
2687 (org-test-with-temp-text "[[http://orgmode.org]]<point>"
2688 (let ((org-special-ctrl-a/e t))
2689 (org-beginning-of-line)
2690 (bolp))))
2691 (should
2692 (org-test-with-temp-text "[[http<point>://orgmode.org]]"
2693 (visual-line-mode)
2694 (org-beginning-of-line)
2695 (bolp)))
2696 ;; Special case: Do not error when the buffer contains only a single
2697 ;; asterisk.
2698 (should
2699 (org-test-with-temp-text "*<point>"
2700 (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
2701 (should
2702 (org-test-with-temp-text "*<point>"
2703 (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
2705 (ert-deftest test-org/end-of-line ()
2706 "Test `org-end-of-line' specifications."
2707 ;; Standard test.
2708 (should
2709 (org-test-with-temp-text "Some text\nSome other text"
2710 (org-end-of-line)
2711 (eolp)))
2712 ;; With `visual-line-mode' active, move to end of visible line.
2713 ;; However, never go past ellipsis.
2714 (should-not
2715 (org-test-with-temp-text "A <point>long line of text\nSome other text"
2716 (visual-line-mode)
2717 (dotimes (i 1000) (insert "very "))
2718 (goto-char (point-min))
2719 (org-end-of-line)
2720 (eolp)))
2721 (should-not
2722 (org-test-with-temp-text "* A short headline\nSome contents"
2723 (visual-line-mode)
2724 (org-overview)
2725 (org-end-of-line)
2726 (eobp)))
2727 ;; In a wide headline, with `visual-line-mode', prefer going to end
2728 ;; of visible line if tags, or end of line, are farther.
2729 (should-not
2730 (org-test-with-temp-text "* A <point>long headline"
2731 (visual-line-mode)
2732 (dotimes (i 1000) (insert "very "))
2733 (goto-char (point-min))
2734 (org-end-of-line)
2735 (eolp)))
2736 (should-not
2737 (org-test-with-temp-text "* A <point>long headline :tag:"
2738 (visual-line-mode)
2739 (dotimes (i 1000) (insert "very "))
2740 (goto-char (point-min))
2741 (org-end-of-line)
2742 (eolp)))
2743 ;; At an headline without special movement, go to end of line.
2744 ;; However, never go past ellipsis.
2745 (should
2746 (org-test-with-temp-text "* Headline2b :tag:\n"
2747 (let ((org-special-ctrl-a/e nil))
2748 (and (progn (org-end-of-line) (eolp))
2749 (progn (org-end-of-line) (eolp))))))
2750 (should
2751 (org-test-with-temp-text "* Headline2b :tag:\n"
2752 (let ((org-special-ctrl-a/e '(t . nil)))
2753 (and (progn (org-end-of-line) (eolp))
2754 (progn (org-end-of-line) (eolp))))))
2755 (should
2756 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2757 (org-overview)
2758 (let ((org-special-ctrl-a/e nil))
2759 (org-end-of-line)
2760 (= 1 (line-beginning-position)))))
2761 ;; At an headline with special movement, first move before tags,
2762 ;; then at the end of line, rinse, repeat. However, never go past
2763 ;; ellipsis.
2764 (should
2765 (org-test-with-temp-text "* Headline1 :tag:\n"
2766 (let ((org-special-ctrl-a/e t))
2767 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2768 (progn (org-end-of-line) (eolp))
2769 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2770 (should
2771 (org-test-with-temp-text "* Headline1 :tag:\n"
2772 (let ((org-special-ctrl-a/e '(nil . t)))
2773 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2774 (progn (org-end-of-line) (eolp))
2775 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2776 (should-not
2777 (org-test-with-temp-text "* Headline1 :tag:\n"
2778 (let ((org-special-ctrl-a/e '(nil . nil)))
2779 (and (progn (org-end-of-line) (looking-at-p " :tag:"))
2780 (progn (org-end-of-line) (eolp))
2781 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2782 (should
2783 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2784 (org-overview)
2785 (let ((org-special-ctrl-a/e t))
2786 (org-end-of-line)
2787 (org-end-of-line)
2788 (= 1 (line-beginning-position)))))
2789 ;; At an headline, with reversed movement, first go to end of line,
2790 ;; then before tags. However, never go past ellipsis.
2791 (should
2792 (org-test-with-temp-text "* Headline3 :tag:\n"
2793 (let ((org-special-ctrl-a/e 'reversed)
2794 (this-command last-command))
2795 (and (progn (org-end-of-line) (eolp))
2796 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2797 (should
2798 (org-test-with-temp-text "* Headline3 :tag:\n"
2799 (let ((org-special-ctrl-a/e '(nil . reversed))
2800 (this-command last-command))
2801 (and (progn (org-end-of-line) (eolp))
2802 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2803 (should-not
2804 (org-test-with-temp-text "* Headline3 :tag:\n"
2805 (let ((org-special-ctrl-a/e '(nil . t))
2806 (this-command last-command))
2807 (and (progn (org-end-of-line) (eolp))
2808 (progn (org-end-of-line) (looking-at-p " :tag:"))))))
2809 (should
2810 (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
2811 (org-overview)
2812 (let ((org-special-ctrl-a/e 'reversed))
2813 (org-end-of-line)
2814 (= 1 (line-beginning-position)))))
2815 ;; At a block without hidden contents.
2816 (should
2817 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2818 (progn (org-end-of-line) (eolp))))
2819 ;; At a block with hidden contents.
2820 (should-not
2821 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
2822 (let ((org-special-ctrl-a/e t))
2823 (org-hide-block-toggle)
2824 (org-end-of-line)
2825 (eobp))))
2826 ;; Get past invisible characters at the end of line.
2827 (should
2828 (org-test-with-temp-text "[[http://orgmode.org]]"
2829 (org-end-of-line)
2830 (eolp))))
2832 (ert-deftest test-org/open-line ()
2833 "Test `org-open-line' specifications."
2834 ;; Call `open-line' outside of tables.
2835 (should
2836 (equal "\nText"
2837 (org-test-with-temp-text "Text"
2838 (org-open-line 1)
2839 (buffer-string))))
2840 ;; At a table, create a row above.
2841 (should
2842 (equal "\n| |\n| a |"
2843 (org-test-with-temp-text "\n<point>| a |"
2844 (org-open-line 1)
2845 (buffer-string))))
2846 ;; At the very first character of the buffer, also call `open-line'.
2847 (should
2848 (equal "\n| a |"
2849 (org-test-with-temp-text "| a |"
2850 (org-open-line 1)
2851 (buffer-string))))
2852 ;; Narrowing does not count.
2853 (should
2854 (equal "Text\n| |\n| a |"
2855 (org-test-with-temp-text "Text\n<point>| a |"
2856 (narrow-to-region (point) (point-max))
2857 (org-open-line 1)
2858 (widen)
2859 (buffer-string)))))
2861 (ert-deftest test-org/forward-sentence ()
2862 "Test `org-forward-sentence' specifications."
2863 ;; At the end of a table cell, move to the end of the next one.
2864 (should
2865 (org-test-with-temp-text "| a<point> | b |"
2866 (org-forward-sentence)
2867 (looking-at " |$")))
2868 ;; Elsewhere in a cell, move to its end.
2869 (should
2870 (org-test-with-temp-text "| a<point>c | b |"
2871 (org-forward-sentence)
2872 (looking-at " | b |$")))
2873 ;; Otherwise, simply call `forward-sentence'.
2874 (should
2875 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2876 (org-forward-sentence)
2877 (looking-at " Sentence 2.")))
2878 (should
2879 (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
2880 (org-forward-sentence)
2881 (org-forward-sentence)
2882 (eobp)))
2883 ;; At the end of an element, jump to the next one, without stopping
2884 ;; on blank lines in-between.
2885 (should
2886 (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
2887 (org-forward-sentence)
2888 (eobp))))
2890 (ert-deftest test-org/backward-sentence ()
2891 "Test `org-backward-sentence' specifications."
2892 ;; At the beginning of a table cell, move to the beginning of the
2893 ;; previous one.
2894 (should
2895 (org-test-with-temp-text "| a | <point>b |"
2896 (org-backward-sentence)
2897 (looking-at "a | b |$")))
2898 ;; Elsewhere in a cell, move to its beginning.
2899 (should
2900 (org-test-with-temp-text "| a | b<point>c |"
2901 (org-backward-sentence)
2902 (looking-at "bc |$")))
2903 ;; Otherwise, simply call `backward-sentence'.
2904 (should
2905 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2906 (org-backward-sentence)
2907 (looking-at "Sentence 2.")))
2908 (should
2909 (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
2910 (org-backward-sentence)
2911 (org-backward-sentence)
2912 (bobp)))
2913 ;; Make sure to hit the beginning of a sentence on the same line as
2914 ;; an item.
2915 (should
2916 (org-test-with-temp-text "- Line 1\n line <point>2."
2917 (org-backward-sentence)
2918 (looking-at "Line 1"))))
2920 (ert-deftest test-org/forward-paragraph ()
2921 "Test `org-forward-paragraph' specifications."
2922 ;; At end of buffer, return an error.
2923 (should-error
2924 (org-test-with-temp-text "Paragraph"
2925 (goto-char (point-max))
2926 (org-forward-paragraph)))
2927 ;; Standard test.
2928 (should
2929 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2930 (org-forward-paragraph)
2931 (looking-at "P2")))
2932 ;; Ignore depth.
2933 (should
2934 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
2935 (org-forward-paragraph)
2936 (looking-at "P1")))
2937 ;; Do not enter elements with invisible contents.
2938 (should
2939 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
2940 (org-hide-block-toggle)
2941 (org-forward-paragraph)
2942 (looking-at "P3")))
2943 ;; On an affiliated keyword, jump to the beginning of the element.
2944 (should
2945 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
2946 (org-forward-paragraph)
2947 (looking-at "Para")))
2948 ;; On an item or a footnote definition, move to the second element
2949 ;; inside, if any.
2950 (should
2951 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
2952 (org-forward-paragraph)
2953 (looking-at " Paragraph")))
2954 (should
2955 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
2956 (org-forward-paragraph)
2957 (looking-at "Paragraph")))
2958 ;; On an item, or a footnote definition, when the first line is
2959 ;; empty, move to the first item.
2960 (should
2961 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
2962 (org-forward-paragraph)
2963 (looking-at " Paragraph")))
2964 (should
2965 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
2966 (org-forward-paragraph)
2967 (looking-at "Paragraph")))
2968 ;; On a table (resp. a property drawer) do not move through table
2969 ;; rows (resp. node properties).
2970 (should
2971 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
2972 (org-forward-paragraph)
2973 (looking-at "Paragraph")))
2974 (should
2975 (org-test-with-temp-text
2976 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
2977 (org-forward-paragraph)
2978 (looking-at "Paragraph")))
2979 ;; On a verse or source block, stop after blank lines.
2980 (should
2981 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
2982 (org-forward-paragraph)
2983 (looking-at "L2")))
2984 (should
2985 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
2986 (org-forward-paragraph)
2987 (looking-at "L2"))))
2989 (ert-deftest test-org/backward-paragraph ()
2990 "Test `org-backward-paragraph' specifications."
2991 ;; Error at beginning of buffer.
2992 (should-error
2993 (org-test-with-temp-text "Paragraph"
2994 (org-backward-paragraph)))
2995 ;; Regular test.
2996 (should
2997 (org-test-with-temp-text "P1\n\nP2\n\nP3"
2998 (goto-char (point-max))
2999 (org-backward-paragraph)
3000 (looking-at "P3")))
3001 (should
3002 (org-test-with-temp-text "P1\n\nP2\n\nP3"
3003 (goto-char (point-max))
3004 (beginning-of-line)
3005 (org-backward-paragraph)
3006 (looking-at "P2")))
3007 ;; Ignore depth.
3008 (should
3009 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
3010 (goto-char (point-max))
3011 (beginning-of-line)
3012 (org-backward-paragraph)
3013 (looking-at "P2")))
3014 ;; Ignore invisible elements.
3015 (should
3016 (org-test-with-temp-text "* H1\n P1\n* H2"
3017 (org-cycle)
3018 (goto-char (point-max))
3019 (beginning-of-line)
3020 (org-backward-paragraph)
3021 (bobp)))
3022 ;; On an affiliated keyword, jump to the first one.
3023 (should
3024 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
3025 (search-forward "c2")
3026 (org-backward-paragraph)
3027 (looking-at "#\\+name")))
3028 ;; On the second element in an item or a footnote definition, jump
3029 ;; to item or the definition.
3030 (should
3031 (org-test-with-temp-text "- line1\n\n line2"
3032 (goto-char (point-max))
3033 (beginning-of-line)
3034 (org-backward-paragraph)
3035 (looking-at "- line1")))
3036 (should
3037 (org-test-with-temp-text "[fn:1] line1\n\n line2"
3038 (goto-char (point-max))
3039 (beginning-of-line)
3040 (org-backward-paragraph)
3041 (looking-at "\\[fn:1\\] line1")))
3042 ;; On a table (resp. a property drawer), ignore table rows
3043 ;; (resp. node properties).
3044 (should
3045 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
3046 (goto-char (point-max))
3047 (beginning-of-line)
3048 (org-backward-paragraph)
3049 (bobp)))
3050 (should
3051 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
3052 (org-backward-paragraph)
3053 (looking-at ":PROPERTIES:")))
3054 ;; On a source or verse block, stop before blank lines.
3055 (should
3056 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
3057 (search-forward "L3")
3058 (beginning-of-line)
3059 (org-backward-paragraph)
3060 (looking-at "L2")))
3061 (should
3062 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
3063 (search-forward "L3")
3064 (beginning-of-line)
3065 (org-backward-paragraph)
3066 (looking-at "L2"))))
3068 (ert-deftest test-org/forward-element ()
3069 "Test `org-forward-element' specifications."
3070 ;; 1. At EOB: should error.
3071 (org-test-with-temp-text "Some text\n"
3072 (goto-char (point-max))
3073 (should-error (org-forward-element)))
3074 ;; 2. Standard move: expected to ignore blank lines.
3075 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
3076 (org-forward-element)
3077 (should (looking-at (regexp-quote "Second paragraph."))))
3078 ;; 3. Headline tests.
3079 (org-test-with-temp-text "
3080 * Head 1
3081 ** Head 1.1
3082 *** Head 1.1.1
3083 ** Head 1.2"
3084 ;; 3.1. At an headline beginning: move to next headline at the
3085 ;; same level.
3086 (goto-line 3)
3087 (org-forward-element)
3088 (should (looking-at (regexp-quote "** Head 1.2")))
3089 ;; 3.2. At an headline beginning: move to parent headline if no
3090 ;; headline at the same level.
3091 (goto-line 3)
3092 (org-forward-element)
3093 (should (looking-at (regexp-quote "** Head 1.2"))))
3094 ;; 4. Greater element tests.
3095 (org-test-with-temp-text
3096 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
3097 ;; 4.1. At a greater element: expected to skip contents.
3098 (org-forward-element)
3099 (should (looking-at (regexp-quote "Outside.")))
3100 ;; 4.2. At the end of greater element contents: expected to skip
3101 ;; to the end of the greater element.
3102 (goto-line 2)
3103 (org-forward-element)
3104 (should (looking-at (regexp-quote "Outside."))))
3105 ;; 5. List tests.
3106 (org-test-with-temp-text "
3107 - item1
3109 - sub1
3111 - sub2
3113 - sub3
3115 Inner paragraph.
3117 - item2
3119 Outside."
3120 ;; 5.1. At list top point: expected to move to the element after
3121 ;; the list.
3122 (goto-line 2)
3123 (org-forward-element)
3124 (should (looking-at (regexp-quote "Outside.")))
3125 ;; 5.2. Special case: at the first line of a sub-list, but not at
3126 ;; beginning of line, move to next item.
3127 (goto-line 2)
3128 (forward-char)
3129 (org-forward-element)
3130 (should (looking-at "- item2"))
3131 (goto-line 4)
3132 (forward-char)
3133 (org-forward-element)
3134 (should (looking-at " - sub2"))
3135 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
3136 (goto-line 4)
3137 (org-forward-element)
3138 (should (looking-at (regexp-quote " Inner paragraph.")))
3139 ;; 5.4. At sub-list end: expected to move outside the sub-list.
3140 (goto-line 8)
3141 (org-forward-element)
3142 (should (looking-at (regexp-quote " Inner paragraph.")))
3143 ;; 5.5. At an item: expected to move to next item, if any.
3144 (goto-line 6)
3145 (org-forward-element)
3146 (should (looking-at " - sub3"))))
3148 (ert-deftest test-org/backward-element ()
3149 "Test `org-backward-element' specifications."
3150 ;; 1. Should error at BOB.
3151 (org-test-with-temp-text " \nParagraph."
3152 (should-error (org-backward-element)))
3153 ;; 2. Should move at BOB when called on the first element in buffer.
3154 (should
3155 (org-test-with-temp-text "\n#+TITLE: test"
3156 (progn (forward-line)
3157 (org-backward-element)
3158 (bobp))))
3159 ;; 3. Not at the beginning of an element: move at its beginning.
3160 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3161 (goto-line 3)
3162 (end-of-line)
3163 (org-backward-element)
3164 (should (looking-at (regexp-quote "Paragraph2."))))
3165 ;; 4. Headline tests.
3166 (org-test-with-temp-text "
3167 * Head 1
3168 ** Head 1.1
3169 *** Head 1.1.1
3170 ** Head 1.2"
3171 ;; 4.1. At an headline beginning: move to previous headline at the
3172 ;; same level.
3173 (goto-line 5)
3174 (org-backward-element)
3175 (should (looking-at (regexp-quote "** Head 1.1")))
3176 ;; 4.2. At an headline beginning: move to parent headline if no
3177 ;; headline at the same level.
3178 (goto-line 3)
3179 (org-backward-element)
3180 (should (looking-at (regexp-quote "* Head 1")))
3181 ;; 4.3. At the first top-level headline: should error.
3182 (goto-line 2)
3183 (should-error (org-backward-element)))
3184 ;; 5. At beginning of first element inside a greater element:
3185 ;; expected to move to greater element's beginning.
3186 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
3187 (goto-line 3)
3188 (org-backward-element)
3189 (should (looking-at "#\\+BEGIN_CENTER")))
3190 ;; 6. At the beginning of the first element in a section: should
3191 ;; move back to headline, if any.
3192 (should
3193 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
3194 (progn (goto-char (point-max))
3195 (beginning-of-line)
3196 (org-backward-element)
3197 (org-at-heading-p))))
3198 ;; 7. List tests.
3199 (org-test-with-temp-text "
3200 - item1
3202 - sub1
3204 - sub2
3206 - sub3
3208 Inner paragraph.
3210 - item2
3213 Outside."
3214 ;; 7.1. At beginning of sub-list: expected to move to the
3215 ;; paragraph before it.
3216 (goto-line 4)
3217 (org-backward-element)
3218 (should (looking-at "item1"))
3219 ;; 7.2. At an item in a list: expected to move at previous item.
3220 (goto-line 8)
3221 (org-backward-element)
3222 (should (looking-at " - sub2"))
3223 (goto-line 12)
3224 (org-backward-element)
3225 (should (looking-at "- item1"))
3226 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
3227 ;; beginning.
3228 (goto-line 10)
3229 (org-backward-element)
3230 (should (looking-at " - sub1"))
3231 (goto-line 15)
3232 (org-backward-element)
3233 (should (looking-at "- item1"))
3234 ;; 7.4. At blank-lines before list end: expected to move to top
3235 ;; item.
3236 (goto-line 14)
3237 (org-backward-element)
3238 (should (looking-at "- item1"))))
3240 (ert-deftest test-org/up-element ()
3241 "Test `org-up-element' specifications."
3242 ;; 1. At BOB or with no surrounding element: should error.
3243 (org-test-with-temp-text "Paragraph."
3244 (should-error (org-up-element)))
3245 (org-test-with-temp-text "* Head1\n* Head2"
3246 (goto-line 2)
3247 (should-error (org-up-element)))
3248 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
3249 (goto-line 3)
3250 (should-error (org-up-element)))
3251 ;; 2. At an headline: move to parent headline.
3252 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
3253 (goto-line 3)
3254 (org-up-element)
3255 (should (looking-at "\\* Head1")))
3256 ;; 3. Inside a greater element: move to greater element beginning.
3257 (org-test-with-temp-text
3258 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
3259 (goto-line 3)
3260 (org-up-element)
3261 (should (looking-at "#\\+BEGIN_CENTER")))
3262 ;; 4. List tests.
3263 (org-test-with-temp-text "* Top
3264 - item1
3266 - sub1
3268 - sub2
3270 Paragraph within sub2.
3272 - item2"
3273 ;; 4.1. Within an item: move to the item beginning.
3274 (goto-line 8)
3275 (org-up-element)
3276 (should (looking-at " - sub2"))
3277 ;; 4.2. At an item in a sub-list: move to parent item.
3278 (goto-line 4)
3279 (org-up-element)
3280 (should (looking-at "- item1"))
3281 ;; 4.3. At an item in top list: move to beginning of whole list.
3282 (goto-line 10)
3283 (org-up-element)
3284 (should (looking-at "- item1"))
3285 ;; 4.4. Special case. At very top point: should move to parent of
3286 ;; list.
3287 (goto-line 2)
3288 (org-up-element)
3289 (should (looking-at "\\* Top"))))
3291 (ert-deftest test-org/down-element ()
3292 "Test `org-down-element' specifications."
3293 ;; Error when the element hasn't got a recursive type.
3294 (org-test-with-temp-text "Paragraph."
3295 (should-error (org-down-element)))
3296 ;; Error when the element has no contents
3297 (org-test-with-temp-text "* Headline"
3298 (should-error (org-down-element)))
3299 ;; When at a plain-list, move to first item.
3300 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
3301 (goto-line 2)
3302 (org-down-element)
3303 (should (looking-at " - Item 1.1")))
3304 (org-test-with-temp-text "#+NAME: list\n- Item 1"
3305 (org-down-element)
3306 (should (looking-at " Item 1")))
3307 ;; When at a table, move to first row
3308 (org-test-with-temp-text "#+NAME: table\n| a | b |"
3309 (org-down-element)
3310 (should (looking-at " a | b |")))
3311 ;; Otherwise, move inside the greater element.
3312 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
3313 (org-down-element)
3314 (should (looking-at "Paragraph"))))
3316 (ert-deftest test-org/drag-element-backward ()
3317 "Test `org-drag-element-backward' specifications."
3318 ;; Standard test.
3319 (should
3320 (equal
3321 "#+key2: val2\n#+key1: val1\n#+key3: val3"
3322 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
3323 (org-drag-element-backward)
3324 (buffer-string))))
3325 (should
3326 (equal
3327 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
3328 (org-test-with-temp-text
3329 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
3330 (org-drag-element-backward)
3331 (buffer-string))))
3332 ;; Preserve blank lines.
3333 (should
3334 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
3335 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
3336 (org-drag-element-backward)
3337 (buffer-string))))
3338 ;; Preserve column.
3339 (should
3340 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
3341 (org-drag-element-backward)
3342 (looking-at-p "2")))
3343 ;; Error when trying to move first element of buffer.
3344 (should-error
3345 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3346 (org-drag-element-backward))
3347 :type 'user-error)
3348 ;; Error when trying to swap nested elements.
3349 (should-error
3350 (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
3351 (org-drag-element-backward))
3352 :type 'user-error)
3353 ;; Error when trying to swap an headline element and a non-headline
3354 ;; element.
3355 (should-error
3356 (org-test-with-temp-text "Test.\n<point>* Head 1"
3357 (org-drag-element-backward))
3358 :type 'error)
3359 ;; Error when called before first element.
3360 (should-error
3361 (org-test-with-temp-text "\n<point>"
3362 (org-drag-element-backward))
3363 :type 'user-error)
3364 ;; Preserve visibility of elements and their contents.
3365 (should
3366 (equal '((63 . 82) (26 . 48))
3367 (org-test-with-temp-text "
3368 #+BEGIN_CENTER
3369 Text.
3370 #+END_CENTER
3371 - item 1
3372 #+BEGIN_QUOTE
3373 Text.
3374 #+END_QUOTE"
3375 (while (search-forward "BEGIN_" nil t) (org-cycle))
3376 (search-backward "- item 1")
3377 (org-drag-element-backward)
3378 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
3379 (overlays-in (point-min) (point-max))))))
3380 ;; Pathological case: handle call with point in blank lines right
3381 ;; after a headline.
3382 (should
3383 (equal "* H2\n* H1\nText\n\n"
3384 (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
3385 (org-drag-element-backward)
3386 (buffer-string)))))
3388 (ert-deftest test-org/drag-element-forward ()
3389 "Test `org-drag-element-forward' specifications."
3390 ;; 1. Error when trying to move first element of buffer.
3391 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
3392 (goto-line 3)
3393 (should-error (org-drag-element-forward)))
3394 ;; 2. Error when trying to swap nested elements.
3395 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
3396 (forward-line)
3397 (should-error (org-drag-element-forward)))
3398 ;; 3. Error when trying to swap a non-headline element and an
3399 ;; headline.
3400 (org-test-with-temp-text "Test.\n* Head 1"
3401 (should-error (org-drag-element-forward)))
3402 ;; 4. Error when called before first element.
3403 (should-error
3404 (org-test-with-temp-text "\n"
3405 (forward-line)
3406 (org-drag-element-backward))
3407 :type 'user-error)
3408 ;; 5. Otherwise, swap elements, preserving column and blank lines
3409 ;; between elements.
3410 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
3411 (search-forward "graph")
3412 (org-drag-element-forward)
3413 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
3414 (should (looking-at " 1")))
3415 ;; 5. Preserve visibility of elements and their contents.
3416 (org-test-with-temp-text "
3417 #+BEGIN_CENTER
3418 Text.
3419 #+END_CENTER
3420 - item 1
3421 #+BEGIN_QUOTE
3422 Text.
3423 #+END_QUOTE"
3424 (while (search-forward "BEGIN_" nil t) (org-cycle))
3425 (search-backward "#+BEGIN_CENTER")
3426 (org-drag-element-forward)
3427 (should
3428 (equal
3429 '((63 . 82) (26 . 48))
3430 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
3431 (overlays-in (point-min) (point-max)))))))
3433 (ert-deftest test-org/next-block ()
3434 "Test `org-next-block' specifications."
3435 ;; Regular test.
3436 (should
3437 (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3438 (org-next-block 1)
3439 (looking-at "#\\+BEGIN_CENTER")))
3440 ;; Ignore case.
3441 (should
3442 (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
3443 (let ((case-fold-search nil))
3444 (org-next-block 1)
3445 (looking-at "#\\+begin_center"))))
3446 ;; Ignore current line.
3447 (should
3448 (org-test-with-temp-text
3449 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
3450 (org-next-block 1)
3451 (looking-at "#\\+BEGIN_CENTER")))
3452 ;; Throw an error when no block is found.
3453 (should-error
3454 (org-test-with-temp-text "Paragraph"
3455 (org-next-block 1)))
3456 ;; With an argument, skip many blocks at once.
3457 (should
3458 (org-test-with-temp-text
3459 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3460 (org-next-block 2)
3461 (looking-at "#\\+BEGIN_QUOTE")))
3462 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3463 (should
3464 (org-test-with-temp-text
3465 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
3466 (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
3467 (looking-at "#\\+BEGIN_QUOTE")))
3468 ;; Optional argument is also case-insensitive.
3469 (should
3470 (org-test-with-temp-text
3471 "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
3472 (let ((case-fold-search nil))
3473 (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
3474 (looking-at "#\\+begin_quote")))))
3476 (ert-deftest test-org/previous-block ()
3477 "Test `org-previous-block' specifications."
3478 ;; Regular test.
3479 (should
3480 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
3481 (org-previous-block 1)
3482 (looking-at "#\\+BEGIN_CENTER")))
3483 ;; Ignore case.
3484 (should
3485 (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
3486 (let ((case-fold-search nil))
3487 (org-previous-block 1)
3488 (looking-at "#\\+begin_center"))))
3489 ;; Ignore current line.
3490 (should
3491 (org-test-with-temp-text
3492 "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
3493 (org-previous-block 1)
3494 (looking-at "#\\+BEGIN_QUOTE")))
3495 ;; Throw an error when no block is found.
3496 (should-error
3497 (org-test-with-temp-text "Paragraph<point>"
3498 (org-previous-block 1)))
3499 ;; With an argument, skip many blocks at once.
3500 (should
3501 (org-test-with-temp-text
3502 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3503 (org-previous-block 2)
3504 (looking-at "#\\+BEGIN_CENTER")))
3505 ;; With optional argument BLOCK-REGEXP, filter matched blocks.
3506 (should
3507 (org-test-with-temp-text
3508 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
3509 (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3510 (looking-at "#\\+BEGIN_QUOTE")))
3511 ;; Optional argument is also case-insensitive.
3512 (should
3513 (org-test-with-temp-text
3514 "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
3515 (let ((case-fold-search nil))
3516 (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
3517 (looking-at "#\\+begin_quote")))))
3520 ;;; Outline structure
3522 (ert-deftest test-org/demote ()
3523 "Test `org-demote' specifications."
3524 ;; Add correct number of stars according to `org-odd-levels-only'.
3525 (should
3526 (= 2
3527 (org-test-with-temp-text "* H"
3528 (let ((org-odd-levels-only nil)) (org-demote))
3529 (org-current-level))))
3530 (should
3531 (= 3
3532 (org-test-with-temp-text "* H"
3533 (let ((org-odd-levels-only t)) (org-demote))
3534 (org-current-level))))
3535 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3536 (should
3537 (org-test-with-temp-text "* H :tag:"
3538 (let ((org-tags-column 10)
3539 (org-auto-align-tags t)
3540 (org-odd-levels-only nil))
3541 (org-demote))
3542 (org-move-to-column 10)
3543 (looking-at-p ":tag:$")))
3544 (should-not
3545 (org-test-with-temp-text "* H :tag:"
3546 (let ((org-tags-column 10)
3547 (org-auto-align-tags nil)
3548 (org-odd-levels-only nil))
3549 (org-demote))
3550 (org-move-to-column 10)
3551 (looking-at-p ":tag:$")))
3552 ;; When `org-adapt-indentation' is non-nil, always indent planning
3553 ;; info and property drawers accordingly.
3554 (should
3555 (= 3
3556 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3557 (let ((org-odd-levels-only nil)
3558 (org-adapt-indentation t))
3559 (org-demote))
3560 (forward-line)
3561 (org-get-indentation))))
3562 (should
3563 (= 3
3564 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3565 (let ((org-odd-levels-only nil)
3566 (org-adapt-indentation t))
3567 (org-demote))
3568 (forward-line)
3569 (org-get-indentation))))
3570 (should-not
3571 (= 3
3572 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
3573 (let ((org-odd-levels-only nil)
3574 (org-adapt-indentation nil))
3575 (org-demote))
3576 (forward-line)
3577 (org-get-indentation))))
3578 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3579 ;; section accordingly. Ignore, however, footnote definitions and
3580 ;; inlinetasks boundaries.
3581 (should
3582 (= 3
3583 (org-test-with-temp-text "* H\n Paragraph"
3584 (let ((org-odd-levels-only nil)
3585 (org-adapt-indentation t))
3586 (org-demote))
3587 (forward-line)
3588 (org-get-indentation))))
3589 (should
3590 (= 2
3591 (org-test-with-temp-text "* H\n Paragraph"
3592 (let ((org-odd-levels-only nil)
3593 (org-adapt-indentation nil))
3594 (org-demote))
3595 (forward-line)
3596 (org-get-indentation))))
3597 (should
3598 (zerop
3599 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
3600 (let ((org-odd-levels-only nil)
3601 (org-adapt-indentation t))
3602 (org-demote))
3603 (goto-char (point-max))
3604 (org-get-indentation))))
3605 (should
3606 (= 3
3607 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
3608 (let ((org-odd-levels-only nil)
3609 (org-adapt-indentation t))
3610 (org-demote))
3611 (goto-char (point-max))
3612 (org-get-indentation))))
3613 (when (featurep 'org-inlinetask)
3614 (should
3615 (zerop
3616 (let ((org-inlinetask-min-level 5)
3617 (org-adapt-indentation t))
3618 (org-test-with-temp-text "* H\n***** I\n***** END"
3619 (org-demote)
3620 (forward-line)
3621 (org-get-indentation))))))
3622 (when (featurep 'org-inlinetask)
3623 (should
3624 (= 3
3625 (let ((org-inlinetask-min-level 5)
3626 (org-adapt-indentation t))
3627 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
3628 (org-demote)
3629 (forward-line 2)
3630 (org-get-indentation))))))
3631 ;; Ignore contents of source blocks or example blocks when
3632 ;; indentation should be preserved (through
3633 ;; `org-src-preserve-indentation' or "-i" flag).
3634 (should-not
3635 (zerop
3636 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3637 (let ((org-adapt-indentation t)
3638 (org-src-preserve-indentation nil))
3639 (org-demote))
3640 (forward-line 2)
3641 (org-get-indentation))))
3642 (should
3643 (zerop
3644 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
3645 (let ((org-adapt-indentation t)
3646 (org-src-preserve-indentation t))
3647 (org-demote))
3648 (forward-line 2)
3649 (org-get-indentation))))
3650 (should
3651 (zerop
3652 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
3653 (let ((org-adapt-indentation t)
3654 (org-src-preserve-indentation t))
3655 (org-demote))
3656 (forward-line 2)
3657 (org-get-indentation))))
3658 (should
3659 (zerop
3660 (org-test-with-temp-text
3661 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
3662 (let ((org-adapt-indentation t)
3663 (org-src-preserve-indentation nil))
3664 (org-demote))
3665 (forward-line 2)
3666 (org-get-indentation)))))
3668 (ert-deftest test-org/promote ()
3669 "Test `org-promote' specifications."
3670 ;; Return an error if headline is to be promoted to level 0, unless
3671 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
3672 ;; headline becomes a comment.
3673 (should-error
3674 (org-test-with-temp-text "* H"
3675 (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
3676 (should
3677 (equal "# H"
3678 (org-test-with-temp-text "* H"
3679 (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
3680 (buffer-string))))
3681 ;; Remove correct number of stars according to
3682 ;; `org-odd-levels-only'.
3683 (should
3684 (= 2
3685 (org-test-with-temp-text "*** H"
3686 (let ((org-odd-levels-only nil)) (org-promote))
3687 (org-current-level))))
3688 (should
3689 (= 1
3690 (org-test-with-temp-text "*** H"
3691 (let ((org-odd-levels-only t)) (org-promote))
3692 (org-current-level))))
3693 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
3694 (should
3695 (org-test-with-temp-text "** H :tag:"
3696 (let ((org-tags-column 10)
3697 (org-auto-align-tags t)
3698 (org-odd-levels-only nil))
3699 (org-promote))
3700 (org-move-to-column 10)
3701 (looking-at-p ":tag:$")))
3702 (should-not
3703 (org-test-with-temp-text "** H :tag:"
3704 (let ((org-tags-column 10)
3705 (org-auto-align-tags nil)
3706 (org-odd-levels-only nil))
3707 (org-promote))
3708 (org-move-to-column 10)
3709 (looking-at-p ":tag:$")))
3710 ;; When `org-adapt-indentation' is non-nil, always indent planning
3711 ;; info and property drawers.
3712 (should
3713 (= 2
3714 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3715 (let ((org-odd-levels-only nil)
3716 (org-adapt-indentation t))
3717 (org-promote))
3718 (forward-line)
3719 (org-get-indentation))))
3720 (should
3721 (= 2
3722 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
3723 (let ((org-odd-levels-only nil)
3724 (org-adapt-indentation t))
3725 (org-promote))
3726 (forward-line)
3727 (org-get-indentation))))
3728 (should-not
3729 (= 2
3730 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
3731 (let ((org-odd-levels-only nil)
3732 (org-adapt-indentation nil))
3733 (org-promote))
3734 (forward-line)
3735 (org-get-indentation))))
3736 ;; When `org-adapt-indentation' is non-nil, shift all lines in
3737 ;; section accordingly. Ignore, however, footnote definitions and
3738 ;; inlinetasks boundaries.
3739 (should
3740 (= 2
3741 (org-test-with-temp-text "** H\n Paragraph"
3742 (let ((org-odd-levels-only nil)
3743 (org-adapt-indentation t))
3744 (org-promote))
3745 (forward-line)
3746 (org-get-indentation))))
3747 (should-not
3748 (= 2
3749 (org-test-with-temp-text "** H\n Paragraph"
3750 (let ((org-odd-levels-only nil)
3751 (org-adapt-indentation nil))
3752 (org-promote))
3753 (forward-line)
3754 (org-get-indentation))))
3755 (should
3756 (= 2
3757 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
3758 (let ((org-odd-levels-only nil)
3759 (org-adapt-indentation t))
3760 (org-promote))
3761 (forward-line)
3762 (org-get-indentation))))
3763 (when (featurep 'org-inlinetask)
3764 (should
3765 (zerop
3766 (let ((org-inlinetask-min-level 5)
3767 (org-adapt-indentation t))
3768 (org-test-with-temp-text "** H\n***** I\n***** END"
3769 (org-promote)
3770 (forward-line)
3771 (org-get-indentation))))))
3772 (when (featurep 'org-inlinetask)
3773 (should
3774 (= 2
3775 (let ((org-inlinetask-min-level 5)
3776 (org-adapt-indentation t))
3777 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
3778 (org-promote)
3779 (forward-line 2)
3780 (org-get-indentation))))))
3781 ;; Give up shifting if it would break document's structure
3782 ;; otherwise.
3783 (should
3784 (= 3
3785 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
3786 (let ((org-odd-levels-only nil)
3787 (org-adapt-indentation t))
3788 (org-promote))
3789 (forward-line)
3790 (org-get-indentation))))
3791 (should
3792 (= 3
3793 (org-test-with-temp-text "** H\n Paragraph\n * list."
3794 (let ((org-odd-levels-only nil)
3795 (org-adapt-indentation t))
3796 (org-promote))
3797 (forward-line)
3798 (org-get-indentation))))
3799 ;; Ignore contents of source blocks or example blocks when
3800 ;; indentation should be preserved (through
3801 ;; `org-src-preserve-indentation' or "-i" flag).
3802 (should-not
3803 (zerop
3804 (org-test-with-temp-text
3805 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3806 (let ((org-adapt-indentation t)
3807 (org-src-preserve-indentation nil)
3808 (org-odd-levels-only nil))
3809 (org-promote))
3810 (forward-line)
3811 (org-get-indentation))))
3812 (should
3813 (zerop
3814 (org-test-with-temp-text
3815 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
3816 (let ((org-adapt-indentation t)
3817 (org-src-preserve-indentation t)
3818 (org-odd-levels-only nil))
3819 (org-promote))
3820 (forward-line)
3821 (org-get-indentation))))
3822 (should
3823 (zerop
3824 (org-test-with-temp-text
3825 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
3826 (let ((org-adapt-indentation t)
3827 (org-src-preserve-indentation t)
3828 (org-odd-levels-only nil))
3829 (org-promote))
3830 (forward-line)
3831 (org-get-indentation))))
3832 (should
3833 (zerop
3834 (org-test-with-temp-text
3835 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
3836 (let ((org-adapt-indentation t)
3837 (org-src-preserve-indentation nil)
3838 (org-odd-levels-only nil))
3839 (org-promote))
3840 (forward-line)
3841 (org-get-indentation)))))
3844 ;;; Planning
3846 (ert-deftest test-org/at-planning-p ()
3847 "Test `org-at-planning-p' specifications."
3848 ;; Regular test.
3849 (should
3850 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
3851 (org-at-planning-p)))
3852 (should-not
3853 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
3854 (org-at-planning-p)))
3855 ;; Correctly find planning attached to inlinetasks.
3856 (when (featurep 'org-inlinetask)
3857 (should
3858 (org-test-with-temp-text
3859 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
3860 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3861 (should-not
3862 (org-test-with-temp-text
3863 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3864 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3865 (should-not
3866 (org-test-with-temp-text
3867 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
3868 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
3869 (should-not
3870 (org-test-with-temp-text
3871 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
3872 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
3874 (ert-deftest test-org/add-planning-info ()
3875 "Test `org-add-planning-info'."
3876 ;; Create deadline when `org-adapt-indentation' is non-nil.
3877 (should
3878 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3879 (org-test-with-temp-text "* H\nParagraph<point>"
3880 (let ((org-adapt-indentation t))
3881 (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
3882 (replace-regexp-in-string
3883 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3884 nil nil 1))))
3885 ;; Create deadline when `org-adapt-indentation' is nil.
3886 (should
3887 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3888 (org-test-with-temp-text "* H\nParagraph<point>"
3889 (let ((org-adapt-indentation nil))
3890 (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
3891 (replace-regexp-in-string
3892 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3893 nil nil 1))))
3894 ;; Update deadline when `org-adapt-indentation' is non-nil.
3895 (should
3896 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3897 (org-test-with-temp-text "\
3899 DEADLINE: <2015-06-24 Wed>
3900 Paragraph<point>"
3901 (let ((org-adapt-indentation t))
3902 (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
3903 (replace-regexp-in-string
3904 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3905 nil nil 1))))
3906 ;; Update deadline when `org-adapt-indentation' is nil.
3907 (should
3908 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
3909 (org-test-with-temp-text "\
3911 DEADLINE: <2015-06-24 Wed>
3912 Paragraph<point>"
3913 (let ((org-adapt-indentation nil))
3914 (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
3915 (replace-regexp-in-string
3916 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3917 nil nil 1))))
3918 ;; Schedule when `org-adapt-indentation' is non-nil.
3919 (should
3920 (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
3921 (org-test-with-temp-text "* H\nParagraph<point>"
3922 (let ((org-adapt-indentation t))
3923 (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
3924 (replace-regexp-in-string
3925 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3926 nil nil 1))))
3927 ;; Schedule when `org-adapt-indentation' is nil.
3928 (should
3929 (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
3930 (org-test-with-temp-text "* H\nParagraph<point>"
3931 (let ((org-adapt-indentation nil))
3932 (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
3933 (replace-regexp-in-string
3934 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3935 nil nil 1))))
3936 ;; Add deadline when scheduled.
3937 (should
3938 (equal "\
3940 DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
3941 Paragraph"
3942 (org-test-with-temp-text "\
3944 SCHEDULED: <2015-06-24 Wed>
3945 Paragraph<point>"
3946 (let ((org-adapt-indentation t))
3947 (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
3948 (replace-regexp-in-string
3949 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3950 nil nil 1))))
3951 ;; Remove middle entry.
3952 (should
3953 (equal "\
3955 CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
3956 Paragraph"
3957 (org-test-with-temp-text "\
3959 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3960 Paragraph<point>"
3961 (let ((org-adapt-indentation t))
3962 (org-add-planning-info nil nil 'deadline))
3963 (replace-regexp-in-string
3964 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3965 nil nil 1))))
3966 ;; Remove last entry and then middle entry (order should not
3967 ;; matter).
3968 (should
3969 (equal "\
3971 CLOSED: [2015-06-24]
3972 Paragraph"
3973 (org-test-with-temp-text "\
3975 CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
3976 Paragraph<point>"
3977 (let ((org-adapt-indentation t))
3978 (org-add-planning-info nil nil 'scheduled 'deadline))
3979 (replace-regexp-in-string
3980 "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
3981 nil nil 1))))
3982 ;; Remove closed when `org-adapt-indentation' is non-nil.
3983 (should
3984 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
3985 (org-test-with-temp-text "\
3987 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
3988 Paragraph<point>"
3989 (let ((org-adapt-indentation t))
3990 (org-add-planning-info nil nil 'closed))
3991 (replace-regexp-in-string
3992 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
3993 nil nil 1))))
3994 (should
3995 (equal "* H\n Paragraph"
3996 (org-test-with-temp-text "\
3998 CLOSED: [2015-06-25 Thu]
3999 Paragraph<point>"
4000 (let ((org-adapt-indentation t))
4001 (org-add-planning-info nil nil 'closed))
4002 (replace-regexp-in-string
4003 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4004 nil nil 1))))
4005 ;; Remove closed when `org-adapt-indentation' is nil.
4006 (should
4007 (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
4008 (org-test-with-temp-text "\
4010 CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
4011 Paragraph<point>"
4012 (let ((org-adapt-indentation nil))
4013 (org-add-planning-info nil nil 'closed))
4014 (replace-regexp-in-string
4015 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4016 nil nil 1))))
4017 (should
4018 (equal "* H\nParagraph"
4019 (org-test-with-temp-text "\
4021 CLOSED: [2015-06-25 Thu]
4022 Paragraph<point>"
4023 (let ((org-adapt-indentation nil))
4024 (org-add-planning-info nil nil 'closed))
4025 (replace-regexp-in-string
4026 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4027 nil nil 1))))
4028 ;; Remove closed entry and delete empty line.
4029 (should
4030 (equal "\
4032 Paragraph"
4033 (org-test-with-temp-text "\
4035 CLOSED: [2015-06-24 Wed]
4036 Paragraph<point>"
4037 (let ((org-adapt-indentation t))
4038 (org-add-planning-info nil nil 'closed))
4039 (replace-regexp-in-string
4040 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4041 nil nil 1))))
4042 ;; Remove one entry and update another.
4043 (should
4044 (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
4045 (org-test-with-temp-text "\
4047 SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
4048 Paragraph<point>"
4049 (let ((org-adapt-indentation t))
4050 (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
4051 (replace-regexp-in-string
4052 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4053 nil nil 1)))))
4055 (ert-deftest test-org/deadline ()
4056 "Test `org-deadline' specifications."
4057 ;; Insert a new value or replace existing one.
4058 (should
4059 (equal "* H\nDEADLINE: <2012-03-29>\n"
4060 (org-test-with-temp-text "* H"
4061 (let ((org-adapt-indentation nil)
4062 (org-last-inserted-timestamp nil))
4063 (org-deadline nil "<2012-03-29 Tue>"))
4064 (replace-regexp-in-string
4065 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4066 nil nil 1))))
4067 (should
4068 (equal "* H\nDEADLINE: <2014-03-04>"
4069 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4070 (let ((org-adapt-indentation nil)
4071 (org-last-inserted-timestamp nil))
4072 (org-deadline nil "<2014-03-04 Thu>"))
4073 (replace-regexp-in-string
4074 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4075 nil nil 1))))
4076 ;; Accept delta time, e.g., "+2d".
4077 (should
4078 (equal "* H\nDEADLINE: <2015-03-04>\n"
4079 (cl-letf (((symbol-function 'current-time)
4080 (lambda (&rest args)
4081 (apply #'encode-time
4082 (org-parse-time-string "2014-03-04")))))
4083 (org-test-with-temp-text "* H"
4084 (let ((org-adapt-indentation nil)
4085 (org-last-inserted-timestamp nil))
4086 (org-deadline nil "+1y"))
4087 (replace-regexp-in-string
4088 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
4089 ;; Preserve repeater.
4090 (should
4091 (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
4092 (org-test-with-temp-text "* H"
4093 (let ((org-adapt-indentation nil)
4094 (org-last-inserted-timestamp nil))
4095 (org-deadline nil "<2012-03-29 Tue +2y>"))
4096 (replace-regexp-in-string
4097 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
4098 ;; Remove CLOSED keyword, if any.
4099 (should
4100 (equal "* H\nDEADLINE: <2012-03-29>"
4101 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4102 (let ((org-adapt-indentation nil)
4103 (org-last-inserted-timestamp nil))
4104 (org-deadline nil "<2012-03-29 Tue>"))
4105 (replace-regexp-in-string
4106 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
4107 ;; With C-u argument, remove DEADLINE keyword.
4108 (should
4109 (equal "* H\n"
4110 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4111 (let ((org-adapt-indentation nil)
4112 (org-last-inserted-timestamp nil))
4113 (org-deadline '(4)))
4114 (buffer-string))))
4115 (should
4116 (equal "* H"
4117 (org-test-with-temp-text "* H"
4118 (let ((org-adapt-indentation nil)
4119 (org-last-inserted-timestamp nil))
4120 (org-deadline '(4)))
4121 (buffer-string))))
4122 ;; With C-u C-u argument, prompt for a delay cookie.
4123 (should
4124 (equal "* H\nDEADLINE: <2012-03-29 -705d>"
4125 (cl-letf (((symbol-function 'org-read-date)
4126 (lambda (&rest args)
4127 (apply #'encode-time
4128 (org-parse-time-string "2014-03-04")))))
4129 (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
4130 (let ((org-adapt-indentation nil)
4131 (org-last-inserted-timestamp nil))
4132 (org-deadline '(16)))
4133 (buffer-string)))))
4134 (should-error
4135 (cl-letf (((symbol-function 'org-read-date)
4136 (lambda (&rest args)
4137 (apply #'encode-time
4138 (org-parse-time-string "2014-03-04")))))
4139 (org-test-with-temp-text "* H"
4140 (let ((org-adapt-indentation nil)
4141 (org-last-inserted-timestamp nil))
4142 (org-deadline '(16)))
4143 (buffer-string))))
4144 ;; When a region is active and
4145 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4146 ;; same value in all headlines in region.
4147 (should
4148 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4149 (org-test-with-temp-text "* H1\n* H2"
4150 (let ((org-adapt-indentation nil)
4151 (org-last-inserted-timestamp nil)
4152 (org-loop-over-headlines-in-active-region t))
4153 (transient-mark-mode 1)
4154 (push-mark (point) t t)
4155 (goto-char (point-max))
4156 (org-deadline nil "2012-03-29"))
4157 (replace-regexp-in-string
4158 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
4159 (should-not
4160 (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
4161 (org-test-with-temp-text "* H1\n* H2"
4162 (let ((org-adapt-indentation nil)
4163 (org-last-inserted-timestamp nil)
4164 (org-loop-over-headlines-in-active-region nil))
4165 (transient-mark-mode 1)
4166 (push-mark (point) t t)
4167 (goto-char (point-max))
4168 (org-deadline nil "2012-03-29"))
4169 (replace-regexp-in-string
4170 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
4172 (ert-deftest test-org/schedule ()
4173 "Test `org-schedule' specifications."
4174 ;; Insert a new value or replace existing one.
4175 (should
4176 (equal "* H\nSCHEDULED: <2012-03-29>\n"
4177 (org-test-with-temp-text "* H"
4178 (let ((org-adapt-indentation nil)
4179 (org-last-inserted-timestamp nil))
4180 (org-schedule nil "<2012-03-29 Tue>"))
4181 (replace-regexp-in-string
4182 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4183 nil nil 1))))
4184 (should
4185 (equal "* H\nSCHEDULED: <2014-03-04>"
4186 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4187 (let ((org-adapt-indentation nil)
4188 (org-last-inserted-timestamp nil))
4189 (org-schedule nil "<2014-03-04 Thu>"))
4190 (replace-regexp-in-string
4191 "\\( [.A-Za-z]+\\)>" "" (buffer-string)
4192 nil nil 1))))
4193 ;; Accept delta time, e.g., "+2d".
4194 (should
4195 (equal "* H\nSCHEDULED: <2015-03-04>\n"
4196 (cl-letf (((symbol-function 'current-time)
4197 (lambda (&rest args)
4198 (apply #'encode-time
4199 (org-parse-time-string "2014-03-04")))))
4200 (org-test-with-temp-text "* H"
4201 (let ((org-adapt-indentation nil)
4202 (org-last-inserted-timestamp nil))
4203 (org-schedule nil "+1y"))
4204 (replace-regexp-in-string
4205 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
4206 ;; Preserve repeater.
4207 (should
4208 (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
4209 (org-test-with-temp-text "* H"
4210 (let ((org-adapt-indentation nil)
4211 (org-last-inserted-timestamp nil))
4212 (org-schedule nil "<2012-03-29 Tue +2y>"))
4213 (replace-regexp-in-string
4214 "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
4215 ;; Remove CLOSED keyword, if any.
4216 (should
4217 (equal "* H\nSCHEDULED: <2012-03-29>"
4218 (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
4219 (let ((org-adapt-indentation nil)
4220 (org-last-inserted-timestamp nil))
4221 (org-schedule nil "<2012-03-29 Tue>"))
4222 (replace-regexp-in-string
4223 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
4224 ;; With C-u argument, remove SCHEDULED keyword.
4225 (should
4226 (equal "* H\n"
4227 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4228 (let ((org-adapt-indentation nil)
4229 (org-last-inserted-timestamp nil))
4230 (org-schedule '(4)))
4231 (buffer-string))))
4232 (should
4233 (equal "* H"
4234 (org-test-with-temp-text "* H"
4235 (let ((org-adapt-indentation nil)
4236 (org-last-inserted-timestamp nil))
4237 (org-schedule '(4)))
4238 (buffer-string))))
4239 ;; With C-u C-u argument, prompt for a delay cookie.
4240 (should
4241 (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
4242 (cl-letf (((symbol-function 'org-read-date)
4243 (lambda (&rest args)
4244 (apply #'encode-time
4245 (org-parse-time-string "2014-03-04")))))
4246 (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
4247 (let ((org-adapt-indentation nil)
4248 (org-last-inserted-timestamp nil))
4249 (org-schedule '(16)))
4250 (buffer-string)))))
4251 (should-error
4252 (cl-letf (((symbol-function 'org-read-date)
4253 (lambda (&rest args)
4254 (apply #'encode-time
4255 (org-parse-time-string "2014-03-04")))))
4256 (org-test-with-temp-text "* H"
4257 (let ((org-adapt-indentation nil)
4258 (org-last-inserted-timestamp nil))
4259 (org-schedule '(16)))
4260 (buffer-string))))
4261 ;; When a region is active and
4262 ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
4263 ;; same value in all headlines in region.
4264 (should
4265 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4266 (org-test-with-temp-text "* H1\n* H2"
4267 (let ((org-adapt-indentation nil)
4268 (org-last-inserted-timestamp nil)
4269 (org-loop-over-headlines-in-active-region t))
4270 (transient-mark-mode 1)
4271 (push-mark (point) t t)
4272 (goto-char (point-max))
4273 (org-schedule nil "2012-03-29"))
4274 (replace-regexp-in-string
4275 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
4276 (should-not
4277 (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
4278 (org-test-with-temp-text "* H1\n* H2"
4279 (let ((org-adapt-indentation nil)
4280 (org-last-inserted-timestamp nil)
4281 (org-loop-over-headlines-in-active-region nil))
4282 (transient-mark-mode 1)
4283 (push-mark (point) t t)
4284 (goto-char (point-max))
4285 (org-schedule nil "2012-03-29"))
4286 (replace-regexp-in-string
4287 "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
4288 (should
4289 ;; check if a repeater survives re-scheduling.
4290 (string-match-p
4291 "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
4292 (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
4293 (let ((org-adapt-indentation nil)
4294 (org-last-inserted-timestamp nil))
4295 (org-schedule nil "2017-02-01"))
4296 (buffer-string)))))
4299 ;;; Property API
4301 (ert-deftest test-org/buffer-property-keys ()
4302 "Test `org-buffer-property-keys' specifications."
4303 ;; Retrieve properties accross siblings.
4304 (should
4305 (equal '("A" "B")
4306 (org-test-with-temp-text "
4307 * H1
4308 :PROPERTIES:
4309 :A: 1
4310 :END:
4311 * H2
4312 :PROPERTIES:
4313 :B: 1
4314 :END:"
4315 (org-buffer-property-keys))))
4316 ;; Retrieve properties accross children.
4317 (should
4318 (equal '("A" "B")
4319 (org-test-with-temp-text "
4320 * H1
4321 :PROPERTIES:
4322 :A: 1
4323 :END:
4324 ** H2
4325 :PROPERTIES:
4326 :B: 1
4327 :END:"
4328 (org-buffer-property-keys))))
4329 ;; Retrieve muliple properties in the same drawer.
4330 (should
4331 (equal '("A" "B")
4332 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4333 (org-buffer-property-keys))))
4334 ;; Ignore extension symbol in property name.
4335 (should
4336 (equal '("A")
4337 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4338 (org-buffer-property-keys))))
4339 ;; With non-nil COLUMNS, extract property names from columns.
4340 (should
4341 (equal '("A" "B")
4342 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
4343 (org-buffer-property-keys nil nil t))))
4344 (should
4345 (equal '("A" "B" "COLUMNS")
4346 (org-test-with-temp-text
4347 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
4348 (org-buffer-property-keys nil nil t))))
4349 ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
4350 (should
4351 (equal '("A")
4352 (org-test-with-temp-text
4353 "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
4354 (org-buffer-property-keys nil nil nil t)))))
4356 (ert-deftest test-org/property-values ()
4357 "Test `org-property-values' specifications."
4358 ;; Regular test.
4359 (should
4360 (equal '("2" "1")
4361 (org-test-with-temp-text
4362 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
4363 (org-property-values "A"))))
4364 ;; Ignore empty values.
4365 (should-not
4366 (org-test-with-temp-text
4367 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
4368 (org-property-values "A")))
4369 ;; Take into consideration extended values.
4370 (should
4371 (equal '("1 2")
4372 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
4373 (org-property-values "A")))))
4375 (ert-deftest test-org/find-property ()
4376 "Test `org-find-property' specifications."
4377 ;; Regular test.
4378 (should
4379 (= 1
4380 (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
4381 (org-find-property "prop"))))
4382 ;; Ignore false positives.
4383 (should
4384 (= 27
4385 (org-test-with-temp-text
4386 "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
4387 (org-find-property "A"))))
4388 ;; Return first entry found in buffer.
4389 (should
4390 (= 1
4391 (org-test-with-temp-text
4392 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4393 (org-find-property "A"))))
4394 ;; Only search visible part of the buffer.
4395 (should
4396 (= 31
4397 (org-test-with-temp-text
4398 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
4399 (org-narrow-to-subtree)
4400 (org-find-property "A"))))
4401 ;; With optional argument, only find entries with a specific value.
4402 (should-not
4403 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4404 (org-find-property "A" "2")))
4405 (should
4406 (= 31
4407 (org-test-with-temp-text
4408 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
4409 (org-find-property "A" "2"))))
4410 ;; Use "nil" for explicit nil values.
4411 (should
4412 (= 31
4413 (org-test-with-temp-text
4414 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
4415 (org-find-property "A" "nil")))))
4417 (ert-deftest test-org/entry-delete ()
4418 "Test `org-entry-delete' specifications."
4419 ;; Regular test.
4420 (should
4421 (string-match
4422 " *:PROPERTIES:\n *:B: +2\n *:END:"
4423 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4424 (org-entry-delete (point) "A")
4425 (buffer-string))))
4426 ;; Also remove accumulated properties.
4427 (should-not
4428 (string-match
4429 ":A"
4430 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
4431 (org-entry-delete (point) "A")
4432 (buffer-string))))
4433 ;; When last property is removed, remove the property drawer.
4434 (should-not
4435 (string-match
4436 ":PROPERTIES:"
4437 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
4438 (org-entry-delete (point) "A")
4439 (buffer-string))))
4440 ;; Return a non-nil value when some property was removed.
4441 (should
4442 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4443 (org-entry-delete (point) "A")))
4444 (should-not
4445 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
4446 (org-entry-delete (point) "C")))
4447 ;; Special properties cannot be located in a drawer. Allow to
4448 ;; remove them anyway, in case of user error.
4449 (should
4450 (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
4451 (org-entry-delete (point) "SCHEDULED"))))
4453 (ert-deftest test-org/entry-get ()
4454 "Test `org-entry-get' specifications."
4455 ;; Regular test.
4456 (should
4457 (equal "1"
4458 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4459 (org-entry-get (point) "A"))))
4460 ;; Ignore case.
4461 (should
4462 (equal "1"
4463 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4464 (org-entry-get (point) "a"))))
4465 ;; Handle extended values, both before and after base value.
4466 (should
4467 (equal "1 2 3"
4468 (org-test-with-temp-text
4469 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4470 (org-entry-get (point) "A"))))
4471 ;; Empty values are returned as the empty string.
4472 (should
4473 (equal ""
4474 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
4475 (org-entry-get (point) "A"))))
4476 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
4477 ;; otherwise, return nil.
4478 (should-not
4479 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4480 (org-entry-get (point) "A")))
4481 (should
4482 (equal "nil"
4483 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
4484 (org-entry-get (point) "A" nil t))))
4485 ;; Return nil when no property is found, independently on the
4486 ;; LITERAL-NIL argument.
4487 (should-not
4488 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4489 (org-entry-get (point) "B")))
4490 (should-not
4491 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4492 (org-entry-get (point) "B" nil t)))
4493 ;; Handle inheritance, when allowed. Include extended values and
4494 ;; possibly global values.
4495 (should
4496 (equal
4498 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4499 (org-entry-get (point) "A" t))))
4500 (should
4501 (equal
4503 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4504 (let ((org-use-property-inheritance t))
4505 (org-entry-get (point) "A" 'selective)))))
4506 (should-not
4507 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
4508 (let ((org-use-property-inheritance nil))
4509 (org-entry-get (point) "A" 'selective))))
4510 (should
4511 (equal
4512 "1 2"
4513 (org-test-with-temp-text
4514 "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
4515 (org-entry-get (point-max) "A" t))))
4516 (should
4517 (equal "1"
4518 (org-test-with-temp-text
4519 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
4520 (org-mode-restart)
4521 (org-entry-get (point-max) "A" t))))
4522 (should
4523 (equal "0 1"
4524 (org-test-with-temp-text
4525 "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
4526 (org-mode-restart)
4527 (org-entry-get (point-max) "A" t)))))
4529 (ert-deftest test-org/entry-properties ()
4530 "Test `org-entry-properties' specifications."
4531 ;; Get "ITEM" property.
4532 (should
4533 (equal "H"
4534 (org-test-with-temp-text "* TODO H"
4535 (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
4536 (should
4537 (equal "H"
4538 (org-test-with-temp-text "* TODO H"
4539 (cdr (assoc "ITEM" (org-entry-properties))))))
4540 ;; Get "TODO" property. TODO keywords are case sensitive.
4541 (should
4542 (equal "TODO"
4543 (org-test-with-temp-text "* TODO H"
4544 (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
4545 (should
4546 (equal "TODO"
4547 (org-test-with-temp-text "* TODO H"
4548 (cdr (assoc "TODO" (org-entry-properties))))))
4549 (should-not
4550 (org-test-with-temp-text "* H"
4551 (assoc "TODO" (org-entry-properties nil "TODO"))))
4552 (should-not
4553 (org-test-with-temp-text "* todo H"
4554 (assoc "TODO" (org-entry-properties nil "TODO"))))
4555 ;; Get "PRIORITY" property.
4556 (should
4557 (equal "A"
4558 (org-test-with-temp-text "* [#A] H"
4559 (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
4560 (should
4561 (equal "A"
4562 (org-test-with-temp-text "* [#A] H"
4563 (cdr (assoc "PRIORITY" (org-entry-properties))))))
4564 (should
4565 (equal (char-to-string org-default-priority)
4566 (org-test-with-temp-text "* H"
4567 (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
4568 ;; Get "FILE" property.
4569 (should
4570 (org-test-with-temp-text-in-file "* H\nParagraph"
4571 (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
4572 (buffer-file-name))))
4573 (should
4574 (org-test-with-temp-text-in-file "* H\nParagraph"
4575 (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
4576 (buffer-file-name))))
4577 (should-not
4578 (org-test-with-temp-text "* H\nParagraph"
4579 (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
4580 ;; Get "TAGS" property.
4581 (should
4582 (equal ":tag1:tag2:"
4583 (org-test-with-temp-text "* H :tag1:tag2:"
4584 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
4585 (should
4586 (equal ":tag1:tag2:"
4587 (org-test-with-temp-text "* H :tag1:tag2:"
4588 (cdr (assoc "TAGS" (org-entry-properties))))))
4589 (should-not
4590 (org-test-with-temp-text "* H"
4591 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
4592 ;; Get "ALLTAGS" property.
4593 (should
4594 (equal ":tag1:tag2:"
4595 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4596 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
4597 (should
4598 (equal ":tag1:tag2:"
4599 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
4600 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
4601 (should-not
4602 (org-test-with-temp-text "* H"
4603 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
4604 ;; Get "BLOCKED" property.
4605 (should
4606 (equal "t"
4607 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
4608 (let ((org-enforce-todo-dependencies t)
4609 (org-blocker-hook
4610 '(org-block-todo-from-children-or-siblings-or-parent)))
4611 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
4612 (should
4613 (equal ""
4614 (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
4615 (let ((org-enforce-todo-dependencies t)
4616 (org-blocker-hook
4617 '(org-block-todo-from-children-or-siblings-or-parent)))
4618 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
4619 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
4620 (should
4621 (equal
4622 "[2012-03-29 thu.]"
4623 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4624 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
4625 (should
4626 (equal
4627 "[2012-03-29 thu.]"
4628 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
4629 (cdr (assoc "CLOSED" (org-entry-properties))))))
4630 (should-not
4631 (org-test-with-temp-text "* H"
4632 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
4633 (should
4634 (equal
4635 "<2014-03-04 tue.>"
4636 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4637 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
4638 (should
4639 (equal
4640 "<2014-03-04 tue.>"
4641 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4642 (cdr (assoc "DEADLINE" (org-entry-properties))))))
4643 (should-not
4644 (org-test-with-temp-text "* H"
4645 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
4646 (should
4647 (equal
4648 "<2014-03-04 tue.>"
4649 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4650 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
4651 (should
4652 (equal
4653 "<2014-03-04 tue.>"
4654 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4655 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
4656 (should-not
4657 (org-test-with-temp-text "* H"
4658 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
4659 ;; Get "CATEGORY"
4660 (should
4661 (equal "cat"
4662 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4663 (cdr (assoc "CATEGORY" (org-entry-properties))))))
4664 (should
4665 (equal "cat"
4666 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
4667 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
4668 (should
4669 (equal "cat"
4670 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
4671 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
4672 (should
4673 (equal "cat2"
4674 (org-test-with-temp-text
4675 (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
4676 "\n"
4677 "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
4678 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
4679 ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
4680 (should
4681 (equal "<2012-03-29 thu.>"
4682 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
4683 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4684 (should
4685 (equal "[2012-03-29 thu.]"
4686 (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
4687 (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
4688 (should
4689 (equal "<2012-03-29 thu.>"
4690 (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
4691 (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
4692 (should
4693 (equal "[2014-03-04 tue.]"
4694 (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
4695 (cdr (assoc "TIMESTAMP_IA"
4696 (org-entry-properties nil "TIMESTAMP_IA"))))))
4697 (should-not
4698 (equal "<2012-03-29 thu.>"
4699 (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
4700 (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
4701 ;; Get standard properties.
4702 (should
4703 (equal "1"
4704 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4705 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
4706 ;; Handle extended properties.
4707 (should
4708 (equal "1 2 3"
4709 (org-test-with-temp-text
4710 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
4711 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
4712 (should
4713 (equal "1 2 3"
4714 (org-test-with-temp-text
4715 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
4716 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
4717 ;; Ignore forbidden (special) properties.
4718 (should-not
4719 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
4720 (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
4722 (ert-deftest test-org/entry-put ()
4723 "Test `org-entry-put' specifications."
4724 ;; Error when not a string or nil.
4725 (should-error
4726 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4727 (org-entry-put 1 "test" 2)))
4728 ;; Error when property name is invalid.
4729 (should-error
4730 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4731 (org-entry-put 1 "no space" "value")))
4732 (should-error
4733 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
4734 (org-entry-put 1 "" "value")))
4735 ;; Set "TODO" property.
4736 (should
4737 (string-match (regexp-quote " TODO H")
4738 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4739 (org-entry-put (point) "TODO" "TODO")
4740 (buffer-string))))
4741 (should
4742 (string-match (regexp-quote "* H")
4743 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
4744 (org-entry-put (point) "TODO" nil)
4745 (buffer-string))))
4746 ;; Set "PRIORITY" property.
4747 (should
4748 (equal "* [#A] H"
4749 (org-test-with-temp-text "* [#B] H"
4750 (org-entry-put (point) "PRIORITY" "A")
4751 (buffer-string))))
4752 (should
4753 (equal "* H"
4754 (org-test-with-temp-text "* [#B] H"
4755 (org-entry-put (point) "PRIORITY" nil)
4756 (buffer-string))))
4757 ;; Set "SCHEDULED" property.
4758 (should
4759 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
4760 (org-test-with-temp-text "* H"
4761 (org-entry-put (point) "SCHEDULED" "2014-03-04")
4762 (buffer-string))))
4763 (should
4764 (string= "* H\n"
4765 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4766 (org-entry-put (point) "SCHEDULED" nil)
4767 (buffer-string))))
4768 (should
4769 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
4770 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4771 (org-entry-put (point) "SCHEDULED" "earlier")
4772 (buffer-string))))
4773 (should
4774 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
4775 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
4776 (org-entry-put (point) "SCHEDULED" "later")
4777 (buffer-string))))
4778 ;; Set "DEADLINE" property.
4779 (should
4780 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
4781 (org-test-with-temp-text "* H"
4782 (org-entry-put (point) "DEADLINE" "2014-03-04")
4783 (buffer-string))))
4784 (should
4785 (string= "* H\n"
4786 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4787 (org-entry-put (point) "DEADLINE" nil)
4788 (buffer-string))))
4789 (should
4790 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
4791 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4792 (org-entry-put (point) "DEADLINE" "earlier")
4793 (buffer-string))))
4794 (should
4795 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
4796 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
4797 (org-entry-put (point) "DEADLINE" "later")
4798 (buffer-string))))
4799 ;; Set "CATEGORY" property
4800 (should
4801 (string-match "^ *:CATEGORY: cat"
4802 (org-test-with-temp-text "* H"
4803 (org-entry-put (point) "CATEGORY" "cat")
4804 (buffer-string))))
4805 ;; Regular properties, with or without pre-existing drawer.
4806 (should
4807 (string-match "^ *:A: +2$"
4808 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4809 (org-entry-put (point) "A" "2")
4810 (buffer-string))))
4811 (should
4812 (string-match "^ *:A: +1$"
4813 (org-test-with-temp-text "* H"
4814 (org-entry-put (point) "A" "1")
4815 (buffer-string))))
4816 ;; Special case: two consecutive headlines.
4817 (should
4818 (string-match "\\* A\n *:PROPERTIES:"
4819 (org-test-with-temp-text "* A\n** B"
4820 (org-entry-put (point) "A" "1")
4821 (buffer-string)))))
4823 (ert-deftest test-org/refresh-properties ()
4824 "Test `org-refresh-properties' specifications."
4825 (should
4826 (equal "1"
4827 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4828 (org-refresh-properties "A" 'org-test)
4829 (get-text-property (point) 'org-test))))
4830 (should-not
4831 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
4832 (org-refresh-properties "B" 'org-test)
4833 (get-text-property (point) 'org-test)))
4834 ;; Handle properties only defined with extension syntax, i.e.,
4835 ;; "PROPERTY+".
4836 (should
4837 (equal "1"
4838 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
4839 (org-refresh-properties "A" 'org-test)
4840 (get-text-property (point) 'org-test))))
4841 ;; When property is inherited, add text property to the whole
4842 ;; sub-tree.
4843 (should
4844 (equal "1"
4845 (org-test-with-temp-text
4846 "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
4847 (let ((org-use-property-inheritance t))
4848 (org-refresh-properties "A" 'org-test))
4849 (get-text-property (point) 'org-test))))
4850 ;; When property is inherited, use global value across the whole
4851 ;; buffer. However local values have precedence.
4852 (should-not
4853 (equal "1"
4854 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4855 (org-mode-restart)
4856 (let ((org-use-property-inheritance nil))
4857 (org-refresh-properties "A" 'org-test))
4858 (get-text-property (point) 'org-test))))
4859 (should
4860 (equal "1"
4861 (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
4862 (org-mode-restart)
4863 (let ((org-use-property-inheritance t))
4864 (org-refresh-properties "A" 'org-test))
4865 (get-text-property (point) 'org-test))))
4866 (should
4867 (equal "2"
4868 (org-test-with-temp-text
4869 "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
4870 (org-mode-restart)
4871 (let ((org-use-property-inheritance t))
4872 (org-refresh-properties "A" 'org-test))
4873 (get-text-property (point) 'org-test)))))
4876 ;;; Radio Targets
4878 (ert-deftest test-org/update-radio-target-regexp ()
4879 "Test `org-update-radio-target-regexp' specifications."
4880 ;; Properly update cache with no previous radio target regexp.
4881 (should
4882 (eq 'link
4883 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4884 (save-excursion (goto-char (point-max)) (org-element-context))
4885 (insert "<<<")
4886 (search-forward "o")
4887 (insert ">>>")
4888 (org-update-radio-target-regexp)
4889 (goto-char (point-max))
4890 (org-element-type (org-element-context)))))
4891 ;; Properly update cache with previous radio target regexp.
4892 (should
4893 (eq 'link
4894 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
4895 (save-excursion (goto-char (point-max)) (org-element-context))
4896 (insert "<<<")
4897 (search-forward "o")
4898 (insert ">>>")
4899 (org-update-radio-target-regexp)
4900 (search-backward "r")
4901 (delete-char 5)
4902 (insert "new")
4903 (org-update-radio-target-regexp)
4904 (goto-char (point-max))
4905 (delete-region (line-beginning-position) (point))
4906 (insert "new")
4907 (org-element-type (org-element-context))))))
4910 ;;; Sparse trees
4912 (ert-deftest test-org/match-sparse-tree ()
4913 "Test `org-match-sparse-tree' specifications."
4914 ;; Match tags.
4915 (should-not
4916 (org-test-with-temp-text "* H\n** H1 :tag:"
4917 (org-match-sparse-tree nil "tag")
4918 (search-forward "H1")
4919 (org-invisible-p2)))
4920 (should
4921 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
4922 (org-match-sparse-tree nil "tag")
4923 (search-forward "H2")
4924 (org-invisible-p2)))
4925 ;; "-" operator for tags.
4926 (should-not
4927 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4928 (org-match-sparse-tree nil "tag1-tag2")
4929 (search-forward "H1")
4930 (org-invisible-p2)))
4931 (should
4932 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4933 (org-match-sparse-tree nil "tag1-tag2")
4934 (search-forward "H2")
4935 (org-invisible-p2)))
4936 ;; "&" operator for tags.
4937 (should
4938 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4939 (org-match-sparse-tree nil "tag1&tag2")
4940 (search-forward "H1")
4941 (org-invisible-p2)))
4942 (should-not
4943 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4944 (org-match-sparse-tree nil "tag1&tag2")
4945 (search-forward "H2")
4946 (org-invisible-p2)))
4947 ;; "|" operator for tags.
4948 (should-not
4949 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4950 (org-match-sparse-tree nil "tag1|tag2")
4951 (search-forward "H1")
4952 (org-invisible-p2)))
4953 (should-not
4954 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
4955 (org-match-sparse-tree nil "tag1|tag2")
4956 (search-forward "H2")
4957 (org-invisible-p2)))
4958 ;; Regexp match on tags.
4959 (should-not
4960 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4961 (org-match-sparse-tree nil "{^tag.*}")
4962 (search-forward "H1")
4963 (org-invisible-p2)))
4964 (should
4965 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
4966 (org-match-sparse-tree nil "{^tag.*}")
4967 (search-forward "H2")
4968 (org-invisible-p2)))
4969 ;; Match group tags.
4970 (should-not
4971 (org-test-with-temp-text
4972 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4973 (org-match-sparse-tree nil "work")
4974 (search-forward "H1")
4975 (org-invisible-p2)))
4976 (should-not
4977 (org-test-with-temp-text
4978 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
4979 (org-match-sparse-tree nil "work")
4980 (search-forward "H2")
4981 (org-invisible-p2)))
4982 ;; Match group tags with hard brackets.
4983 (should-not
4984 (org-test-with-temp-text
4985 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4986 (org-match-sparse-tree nil "work")
4987 (search-forward "H1")
4988 (org-invisible-p2)))
4989 (should-not
4990 (org-test-with-temp-text
4991 "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
4992 (org-match-sparse-tree nil "work")
4993 (search-forward "H2")
4994 (org-invisible-p2)))
4995 ;; Match tags in hierarchies
4996 (should-not
4997 (org-test-with-temp-text
4998 "#+TAGS: [ Lev_1 : Lev_2 ]\n
4999 #+TAGS: [ Lev_2 : Lev_3 ]\n
5000 #+TAGS: { Lev_3 : Lev_4 }\n
5001 * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
5002 (org-match-sparse-tree nil "Lev_1")
5003 (search-forward "H4")
5004 (org-invisible-p2)))
5005 ;; Match regular expressions in tags
5006 (should-not
5007 (org-test-with-temp-text
5008 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
5009 (org-match-sparse-tree nil "Lev")
5010 (search-forward "H1")
5011 (org-invisible-p2)))
5012 (should
5013 (org-test-with-temp-text
5014 "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
5015 (org-match-sparse-tree nil "Lev")
5016 (search-forward "H1")
5017 (org-invisible-p2)))
5018 ;; Match properties.
5019 (should
5020 (org-test-with-temp-text
5021 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
5022 (org-match-sparse-tree nil "A=\"1\"")
5023 (search-forward "H2")
5024 (org-invisible-p2)))
5025 (should-not
5026 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5027 (org-match-sparse-tree nil "A=\"1\"")
5028 (search-forward "H2")
5029 (org-invisible-p2)))
5030 ;; Case is not significant when matching properties.
5031 (should-not
5032 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
5033 (org-match-sparse-tree nil "a=\"1\"")
5034 (search-forward "H2")
5035 (org-invisible-p2)))
5036 (should-not
5037 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
5038 (org-match-sparse-tree nil "A=\"1\"")
5039 (search-forward "H2")
5040 (org-invisible-p2)))
5041 ;; Match special LEVEL property.
5042 (should-not
5043 (org-test-with-temp-text "* H\n** H1\n*** H2"
5044 (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
5045 (search-forward "H1")
5046 (org-invisible-p2)))
5047 (should
5048 (org-test-with-temp-text "* H\n** H1\n*** H2"
5049 (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
5050 (search-forward "H2")
5051 (org-invisible-p2)))
5052 ;; Comparison operators when matching properties.
5053 (should
5054 (org-test-with-temp-text
5055 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5056 (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
5057 (search-forward "H1")
5058 (org-invisible-p2)))
5059 (should-not
5060 (org-test-with-temp-text
5061 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
5062 (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
5063 (search-forward "H2")
5064 (org-invisible-p2)))
5065 ;; Regexp match on properties values.
5066 (should-not
5067 (org-test-with-temp-text
5068 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5069 (org-match-sparse-tree nil "A={f.*}")
5070 (search-forward "H1")
5071 (org-invisible-p2)))
5072 (should
5073 (org-test-with-temp-text
5074 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
5075 (org-match-sparse-tree nil "A={f.*}")
5076 (search-forward "H2")
5077 (org-invisible-p2)))
5078 ;; With an optional argument, limit match to TODO entries.
5079 (should-not
5080 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5081 (org-match-sparse-tree t "tag")
5082 (search-forward "H1")
5083 (org-invisible-p2)))
5084 (should
5085 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
5086 (org-match-sparse-tree t "tag")
5087 (search-forward "H2")
5088 (org-invisible-p2))))
5090 (ert-deftest test-org/occur ()
5091 "Test `org-occur' specifications."
5092 ;; Count number of matches.
5093 (should
5094 (= 1
5095 (org-test-with-temp-text "* H\nA\n* H2"
5096 (org-occur "A"))))
5097 (should
5098 (= 2
5099 (org-test-with-temp-text "* H\nA\n* H2\nA"
5100 (org-occur "A"))))
5101 ;; Test CALLBACK optional argument.
5102 (should
5103 (= 0
5104 (org-test-with-temp-text "* H\nA\n* H2"
5105 (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
5106 (should
5107 (= 1
5108 (org-test-with-temp-text "* H\nA\n* H2\nA"
5109 (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
5110 ;; Case-fold searches according to `org-occur-case-fold-search'.
5111 (should
5112 (= 2
5113 (org-test-with-temp-text "Aa"
5114 (let ((org-occur-case-fold-search t)) (org-occur "A")))))
5115 (should
5116 (= 2
5117 (org-test-with-temp-text "Aa"
5118 (let ((org-occur-case-fold-search t)) (org-occur "a")))))
5119 (should
5120 (= 1
5121 (org-test-with-temp-text "Aa"
5122 (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
5123 (should
5124 (= 1
5125 (org-test-with-temp-text "Aa"
5126 (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
5127 (should
5128 (= 1
5129 (org-test-with-temp-text "Aa"
5130 (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
5131 (should
5132 (= 2
5133 (org-test-with-temp-text "Aa"
5134 (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
5137 ;;; Tags
5139 (ert-deftest test-org/tag-string-to-alist ()
5140 "Test `org-tag-string-to-alist' specifications."
5141 ;; Tag without selection key.
5142 (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
5143 ;; Tag with selection key.
5144 (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
5145 ;; Tag group.
5146 (should
5147 (equal
5148 (org-tag-string-to-alist "[ group : t1 t2 ]")
5149 '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
5150 ;; Mutually exclusive tags.
5151 (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
5152 '((:startgroup) ("tag1") ("tag2") (:endgroup))))
5153 (should
5154 (equal
5155 (org-tag-string-to-alist "{ group : tag1 tag2 }")
5156 '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
5158 (ert-deftest test-org/tag-alist-to-string ()
5159 "Test `org-tag-alist-to-string' specifications."
5160 (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
5161 (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
5162 (should
5163 (equal
5164 (org-tag-alist-to-string
5165 '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
5166 "[ group : t1 t2 ]"))
5167 (should
5168 (equal (org-tag-alist-to-string
5169 '((:startgroup) ("tag1") ("tag2") (:endgroup)))
5170 "{ tag1 tag2 }"))
5171 (should
5172 (equal
5173 (org-tag-alist-to-string
5174 '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
5175 "{ group : tag1 tag2 }")))
5177 (ert-deftest test-org/tag-alist-to-groups ()
5178 "Test `org-tag-alist-to-groups' specifications."
5179 (should
5180 (equal (org-tag-alist-to-groups
5181 '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
5182 '(("group" "t1" "t2"))))
5183 (should
5184 (equal
5185 (org-tag-alist-to-groups
5186 '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
5187 '(("group" "t1" "t2"))))
5188 (should-not
5189 (org-tag-alist-to-groups
5190 '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
5192 (ert-deftest test-org/tag-align ()
5193 "Test tags alignment."
5194 ;; Test aligning tags with different display width.
5195 (should
5196 ;; 12345678901234567890
5197 (equal "* Test :abc:"
5198 (org-test-with-temp-text "* Test :abc:"
5199 (let ((org-tags-column -20)
5200 (indent-tabs-mode nil))
5201 (org-fix-tags-on-the-fly))
5202 (buffer-string))))
5203 (should
5204 ;; 12345678901234567890
5205 (equal "* Test :日本語:"
5206 (org-test-with-temp-text "* Test :日本語:"
5207 (let ((org-tags-column -20)
5208 (indent-tabs-mode nil))
5209 (org-fix-tags-on-the-fly))
5210 (buffer-string))))
5211 ;; Make sure aligning tags do not skip invisible text.
5212 (should
5213 (equal "* [[linkx]] :tag:"
5214 (org-test-with-temp-text "* [[link<point>]] :tag:"
5215 (let ((org-tags-column 0))
5216 (org-fix-tags-on-the-fly)
5217 (insert "x")
5218 (buffer-string))))))
5220 (ert-deftest test-org/tags-at ()
5221 (should
5222 (equal '("foo" "bar")
5223 (org-test-with-temp-text
5224 "* T<point>est :foo:bar:"
5225 (org-get-tags-at)))))
5228 ;;; Timestamps API
5230 (ert-deftest test-org/time-stamp ()
5231 "Test `org-time-stamp' specifications."
5232 ;; Insert chosen time stamp at point.
5233 (should
5234 (string-match
5235 "Te<2014-03-04 .*?>xt"
5236 (org-test-with-temp-text "Te<point>xt"
5237 (cl-letf (((symbol-function 'org-read-date)
5238 (lambda (&rest args)
5239 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5240 (org-time-stamp nil)
5241 (buffer-string)))))
5242 ;; With a prefix argument, also insert time.
5243 (should
5244 (string-match
5245 "Te<2014-03-04 .*? 00:41>xt"
5246 (org-test-with-temp-text "Te<point>xt"
5247 (cl-letf (((symbol-function 'org-read-date)
5248 (lambda (&rest args)
5249 (apply #'encode-time
5250 (org-parse-time-string "2014-03-04 00:41")))))
5251 (org-time-stamp '(4))
5252 (buffer-string)))))
5253 ;; With two universal prefix arguments, insert an active timestamp
5254 ;; with the current time without prompting the user.
5255 (should
5256 (string-match
5257 "Te<2014-03-04 .*? 00:41>xt"
5258 (org-test-with-temp-text "Te<point>xt"
5259 (cl-letf (((symbol-function 'current-time)
5260 (lambda ()
5261 (apply #'encode-time
5262 (org-parse-time-string "2014-03-04 00:41")))))
5263 (org-time-stamp '(16))
5264 (buffer-string)))))
5265 ;; When optional argument is non-nil, insert an inactive timestamp.
5266 (should
5267 (string-match
5268 "Te\\[2014-03-04 .*?\\]xt"
5269 (org-test-with-temp-text "Te<point>xt"
5270 (cl-letf (((symbol-function 'org-read-date)
5271 (lambda (&rest args)
5272 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5273 (org-time-stamp nil t)
5274 (buffer-string)))))
5275 ;; When called from a timestamp, replace existing one.
5276 (should
5277 (string-match
5278 "<2014-03-04 .*?>"
5279 (org-test-with-temp-text "<2012-03-29<point> thu.>"
5280 (cl-letf (((symbol-function 'org-read-date)
5281 (lambda (&rest args)
5282 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5283 (org-time-stamp nil)
5284 (buffer-string)))))
5285 (should
5286 (string-match
5287 "<2014-03-04 .*?>--<2014-03-04 .*?>"
5288 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
5289 (cl-letf (((symbol-function 'org-read-date)
5290 (lambda (&rest args)
5291 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5292 (org-time-stamp nil)
5293 (buffer-string)))))
5294 ;; When replacing a timestamp, preserve repeater, if any.
5295 (should
5296 (string-match
5297 "<2014-03-04 .*? \\+2y>"
5298 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
5299 (cl-letf (((symbol-function 'org-read-date)
5300 (lambda (&rest args)
5301 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5302 (org-time-stamp nil)
5303 (buffer-string)))))
5304 ;; When called twice in a raw, build a date range.
5305 (should
5306 (string-match
5307 "<2012-03-29 .*?>--<2014-03-04 .*?>"
5308 (org-test-with-temp-text "<2012-03-29 thu.><point>"
5309 (cl-letf (((symbol-function 'org-read-date)
5310 (lambda (&rest args)
5311 (apply #'encode-time (org-parse-time-string "2014-03-04")))))
5312 (let ((last-command 'org-time-stamp)
5313 (this-command 'org-time-stamp))
5314 (org-time-stamp nil))
5315 (buffer-string))))))
5317 (ert-deftest test-org/timestamp-has-time-p ()
5318 "Test `org-timestamp-has-time-p' specifications."
5319 ;; With time.
5320 (should
5321 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5322 (org-timestamp-has-time-p (org-element-context))))
5323 ;; Without time.
5324 (should-not
5325 (org-test-with-temp-text "<2012-03-29 Thu>"
5326 (org-timestamp-has-time-p (org-element-context)))))
5328 (ert-deftest test-org/timestamp-format ()
5329 "Test `org-timestamp-format' specifications."
5330 ;; Regular test.
5331 (should
5332 (equal
5333 "2012-03-29 16:40"
5334 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
5335 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
5336 ;; Range end.
5337 (should
5338 (equal
5339 "2012-03-29"
5340 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
5341 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
5343 (ert-deftest test-org/timestamp-split-range ()
5344 "Test `org-timestamp-split-range' specifications."
5345 ;; Extract range start (active).
5346 (should
5347 (equal '(2012 3 29)
5348 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5349 (let ((ts (org-timestamp-split-range (org-element-context))))
5350 (mapcar (lambda (p) (org-element-property p ts))
5351 '(:year-end :month-end :day-end))))))
5352 ;; Extract range start (inactive)
5353 (should
5354 (equal '(2012 3 29)
5355 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5356 (let ((ts (org-timestamp-split-range (org-element-context))))
5357 (mapcar (lambda (p) (org-element-property p ts))
5358 '(:year-end :month-end :day-end))))))
5359 ;; Extract range end (active).
5360 (should
5361 (equal '(2012 3 30)
5362 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5363 (let ((ts (org-timestamp-split-range
5364 (org-element-context) t)))
5365 (mapcar (lambda (p) (org-element-property p ts))
5366 '(:year-end :month-end :day-end))))))
5367 ;; Extract range end (inactive)
5368 (should
5369 (equal '(2012 3 30)
5370 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
5371 (let ((ts (org-timestamp-split-range
5372 (org-element-context) t)))
5373 (mapcar (lambda (p) (org-element-property p ts))
5374 '(:year-end :month-end :day-end))))))
5375 ;; Return the timestamp if not a range.
5376 (should
5377 (org-test-with-temp-text "[2012-03-29 Thu]"
5378 (let* ((ts-orig (org-element-context))
5379 (ts-copy (org-timestamp-split-range ts-orig)))
5380 (eq ts-orig ts-copy))))
5381 (should
5382 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5383 (let* ((ts-orig (org-element-context))
5384 (ts-copy (org-timestamp-split-range ts-orig)))
5385 (eq ts-orig ts-copy)))))
5387 (ert-deftest test-org/timestamp-translate ()
5388 "Test `org-timestamp-translate' specifications."
5389 ;; Translate whole date range.
5390 (should
5391 (equal "<29>--<30>"
5392 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5393 (let ((org-display-custom-times t)
5394 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
5395 (org-timestamp-translate (org-element-context))))))
5396 ;; Translate date range start.
5397 (should
5398 (equal "<29>"
5399 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5400 (let ((org-display-custom-times t)
5401 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
5402 (org-timestamp-translate (org-element-context) 'start)))))
5403 ;; Translate date range end.
5404 (should
5405 (equal "<30>"
5406 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
5407 (let ((org-display-custom-times t)
5408 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
5409 (org-timestamp-translate (org-element-context) 'end)))))
5410 ;; Translate time range.
5411 (should
5412 (equal "<08>--<16>"
5413 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
5414 (let ((org-display-custom-times t)
5415 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
5416 (org-timestamp-translate (org-element-context))))))
5417 ;; Translate non-range timestamp.
5418 (should
5419 (equal "<29>"
5420 (org-test-with-temp-text "<2012-03-29 Thu>"
5421 (let ((org-display-custom-times t)
5422 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
5423 (org-timestamp-translate (org-element-context))))))
5424 ;; Do not change `diary' timestamps.
5425 (should
5426 (equal "<%%(org-float t 4 2)>"
5427 (org-test-with-temp-text "<%%(org-float t 4 2)>"
5428 (let ((org-display-custom-times t)
5429 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
5430 (org-timestamp-translate (org-element-context)))))))
5434 ;;; Visibility
5436 (ert-deftest test-org/flag-drawer ()
5437 "Test `org-flag-drawer' specifications."
5438 ;; Hide drawer.
5439 (should
5440 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5441 (org-flag-drawer t)
5442 (get-char-property (line-end-position) 'invisible)))
5443 ;; Show drawer.
5444 (should-not
5445 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5446 (org-flag-drawer t)
5447 (org-flag-drawer nil)
5448 (get-char-property (line-end-position) 'invisible)))
5449 ;; Test optional argument.
5450 (should
5451 (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5452 (let ((drawer (save-excursion (search-forward ":D2")
5453 (org-element-at-point))))
5454 (org-flag-drawer t drawer)
5455 (get-char-property (progn (search-forward ":D2") (line-end-position))
5456 'invisible))))
5457 (should-not
5458 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
5459 (let ((drawer (save-excursion (search-forward ":D2")
5460 (org-element-at-point))))
5461 (org-flag-drawer t drawer)
5462 (get-char-property (line-end-position) 'invisible))))
5463 ;; Do not hide fake drawers.
5464 (should-not
5465 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
5466 (forward-line 1)
5467 (org-flag-drawer t)
5468 (get-char-property (line-end-position) 'invisible)))
5469 ;; Do not hide incomplete drawers.
5470 (should-not
5471 (org-test-with-temp-text ":D:\nparagraph"
5472 (forward-line 1)
5473 (org-flag-drawer t)
5474 (get-char-property (line-end-position) 'invisible)))
5475 ;; Do not hide drawers when called from final blank lines.
5476 (should-not
5477 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
5478 (goto-char (point-max))
5479 (org-flag-drawer t)
5480 (goto-char (point-min))
5481 (get-char-property (line-end-position) 'invisible)))
5482 ;; Don't leave point in an invisible part of the buffer when hiding
5483 ;; a drawer away.
5484 (should-not
5485 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
5486 (goto-char (point-max))
5487 (org-flag-drawer t)
5488 (get-char-property (point) 'invisible))))
5490 (ert-deftest test-org/hide-block-toggle ()
5491 "Test `org-hide-block-toggle' specifications."
5492 ;; Error when not at a block.
5493 (should-error
5494 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
5495 (org-hide-block-toggle 'off)
5496 (get-char-property (line-end-position) 'invisible)))
5497 ;; Hide block.
5498 (should
5499 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
5500 (org-hide-block-toggle)
5501 (get-char-property (line-end-position) 'invisible)))
5502 (should
5503 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
5504 (org-hide-block-toggle)
5505 (get-char-property (line-end-position) 'invisible)))
5506 ;; Show block unconditionally when optional argument is `off'.
5507 (should-not
5508 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5509 (org-hide-block-toggle)
5510 (org-hide-block-toggle 'off)
5511 (get-char-property (line-end-position) 'invisible)))
5512 (should-not
5513 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5514 (org-hide-block-toggle 'off)
5515 (get-char-property (line-end-position) 'invisible)))
5516 ;; Hide block unconditionally when optional argument is non-nil.
5517 (should
5518 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5519 (org-hide-block-toggle t)
5520 (get-char-property (line-end-position) 'invisible)))
5521 (should
5522 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
5523 (org-hide-block-toggle)
5524 (org-hide-block-toggle t)
5525 (get-char-property (line-end-position) 'invisible)))
5526 ;; Do not hide block when called from final blank lines.
5527 (should-not
5528 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
5529 (org-hide-block-toggle)
5530 (goto-char (point-min))
5531 (get-char-property (line-end-position) 'invisible)))
5532 ;; Don't leave point in an invisible part of the buffer when hiding
5533 ;; a block away.
5534 (should-not
5535 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
5536 (org-hide-block-toggle)
5537 (get-char-property (point) 'invisible))))
5539 (ert-deftest test-org/hide-block-toggle-maybe ()
5540 "Test `org-hide-block-toggle-maybe' specifications."
5541 (should
5542 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
5543 (org-hide-block-toggle-maybe)))
5544 (should-not
5545 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
5547 (ert-deftest test-org/set-tags ()
5548 "Test `org-set-tags' specifications."
5549 ;; Tags set via fast-tag-selection should be visible afterwards
5550 (should
5551 (let ((org-tag-alist '(("NEXT" . ?n)))
5552 (org-fast-tag-selection-single-key t))
5553 (cl-letf (((symbol-function 'read-char-exclusive) (lambda () ?n))
5554 ((symbol-function 'window-width) (lambda (&rest args) 100)))
5555 (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
5556 ;; Show only headlines
5557 (org-content)
5558 ;; Set NEXT tag on current entry
5559 (org-set-tags nil nil)
5560 ;; Move point to that NEXT tag
5561 (search-forward "NEXT") (backward-word)
5562 ;; And it should be visible (i.e. no overlays)
5563 (not (overlays-at (point))))))))
5565 (ert-deftest test-org/show-set-visibility ()
5566 "Test `org-show-set-visibility' specifications."
5567 ;; Do not throw an error before first heading.
5568 (should
5569 (org-test-with-temp-text "Preamble\n* Headline"
5570 (org-show-set-visibility 'tree)
5572 ;; Test all visibility spans, both on headline and in entry.
5573 (let ((list-visible-lines
5574 (lambda (state headerp)
5575 (org-test-with-temp-text "* Grandmother (0)
5576 ** Uncle (1)
5577 *** Heir (2)
5578 ** Father (3)
5579 Ancestor text (4)
5580 *** Sister (5)
5581 Sibling text (6)
5582 *** Self (7)
5583 Match (8)
5584 **** First born (9)
5585 Child text (10)
5586 **** The other child (11)
5587 *** Brother (12)
5588 ** Aunt (13)
5590 (org-cycle t)
5591 (search-forward (if headerp "Self" "Match"))
5592 (org-show-set-visibility state)
5593 (goto-char (point-min))
5594 (let (result (line 0))
5595 (while (not (eobp))
5596 (unless (org-invisible-p2) (push line result))
5597 (incf line)
5598 (forward-line))
5599 (nreverse result))))))
5600 (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
5601 (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
5602 (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
5603 (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
5604 (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
5605 (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
5606 (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
5607 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
5608 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
5609 (should (equal '(0 1 3 5 7 8 9 11 12 13)
5610 (funcall list-visible-lines 'tree nil)))
5611 (should (equal '(0 1 3 4 5 7 12 13)
5612 (funcall list-visible-lines 'canonical t)))
5613 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
5614 (funcall list-visible-lines 'canonical nil))))
5615 ;; When point is hidden in a drawer or a block, make sure to make it
5616 ;; visible.
5617 (should-not
5618 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
5619 (org-hide-block-toggle)
5620 (search-forward "Text")
5621 (org-show-set-visibility 'minimal)
5622 (org-invisible-p2)))
5623 (should-not
5624 (org-test-with-temp-text ":DRAWER:\nText\n:END:"
5625 (org-flag-drawer t)
5626 (search-forward "Text")
5627 (org-show-set-visibility 'minimal)
5628 (org-invisible-p2)))
5629 (should-not
5630 (org-test-with-temp-text
5631 "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
5632 (org-flag-drawer t)
5633 (forward-line -1)
5634 (org-hide-block-toggle)
5635 (search-forward "Text")
5636 (org-show-set-visibility 'minimal)
5637 (org-invisible-p2))))
5640 (provide 'test-org)
5642 ;;; test-org.el ends here