Simplify `org-show-context' configuration
[org-mode.git] / testing / lisp / test-org.el
blob5c10dd43c770eb00076f20d8aeb69200bb02c178
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-mode 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 (flet ((current-time () (apply #'encode-time
201 (org-parse-time-string "2014-03-04"))))
202 (org-read-date
203 t nil "+1y" nil
204 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
205 (should
206 (equal
207 "2013-03-29"
208 (flet ((current-time () (apply #'encode-time
209 (org-parse-time-string "2014-03-04"))))
210 (org-read-date
211 t nil "++1y" nil
212 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
213 ;; When `org-read-date-prefer-future' is non-nil, prefer future
214 ;; dates (relatively to now) when incomplete. Otherwise, use
215 ;; default date.
216 (should
217 (equal
218 "2014-04-01"
219 (flet ((current-time () (apply #'encode-time
220 (org-parse-time-string "2014-03-04"))))
221 (let ((org-read-date-prefer-future t))
222 (org-read-date t nil "1")))))
223 (should
224 (equal
225 "2013-03-04"
226 (flet ((current-time () (apply #'encode-time
227 (org-parse-time-string "2012-03-29"))))
228 (let ((org-read-date-prefer-future t))
229 (org-read-date t nil "3-4")))))
230 (should
231 (equal
232 "2012-03-04"
233 (flet ((current-time () (apply #'encode-time
234 (org-parse-time-string "2012-03-29"))))
235 (let ((org-read-date-prefer-future nil))
236 (org-read-date t nil "3-4")))))
237 ;; When set to `org-read-date-prefer-future' is set to `time', read
238 ;; day is moved to tomorrow if specified hour is before current
239 ;; time. However, it only happens in no other part of the date is
240 ;; specified.
241 (should
242 (equal
243 "2012-03-30"
244 (flet ((current-time () (apply #'encode-time
245 (org-parse-time-string "2012-03-29 16:40"))))
246 (let ((org-read-date-prefer-future 'time))
247 (org-read-date t nil "00:40" nil)))))
248 (should-not
249 (equal
250 "2012-03-30"
251 (flet ((current-time () (apply #'encode-time
252 (org-parse-time-string "2012-03-29 16:40"))))
253 (let ((org-read-date-prefer-future 'time))
254 (org-read-date t nil "29 00:40" nil)))))
255 ;; Caveat: `org-read-date-prefer-future' always refers to current
256 ;; time, not default time, when they differ.
257 (should
258 (equal
259 "2014-04-01"
260 (flet ((current-time
261 () (apply #'encode-time (org-parse-time-string "2014-03-04"))))
262 (let ((org-read-date-prefer-future t))
263 (org-read-date
264 t nil "1" nil
265 (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
266 (should
267 (equal
268 "2014-03-25"
269 (flet ((current-time
270 () (apply #'encode-time (org-parse-time-string "2014-03-04"))))
271 (let ((org-read-date-prefer-future t))
272 (org-read-date
273 t nil "25" nil
274 (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
276 (ert-deftest test-org/org-parse-time-string ()
277 "Test `org-parse-time-string'."
278 (should (equal (org-parse-time-string "2012-03-29 16:40")
279 '(0 40 16 29 3 2012 nil nil nil)))
280 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
281 '(0 40 16 29 3 2012 nil nil nil)))
282 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
283 '(0 40 16 29 3 2012 nil nil nil)))
284 (should (equal (org-parse-time-string "<2012-03-29>")
285 '(0 0 0 29 3 2012 nil nil nil)))
286 (should (equal (org-parse-time-string "<2012-03-29>" t)
287 '(0 nil nil 29 3 2012 nil nil nil))))
290 ;;; Drawers
292 (ert-deftest test-org/insert-property-drawer ()
293 "Test `org-insert-property-drawer' specifications."
294 ;; Error before first headline.
295 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
296 ;; Insert drawer right after headline if there is no planning line,
297 ;; or after it otherwise.
298 (should
299 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
300 (org-test-with-temp-text "* H\nParagraph<point>"
301 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
302 (buffer-string))))
303 (should
304 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
305 (org-test-with-temp-text
306 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
307 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
308 (buffer-string))))
309 ;; Indent inserted drawer.
310 (should
311 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
312 (org-test-with-temp-text "* H\nParagraph<point>"
313 (let ((org-adapt-indentation t)) (org-insert-property-drawer))
314 (buffer-string))))
315 ;; Handle insertion at eob.
316 (should
317 (equal "* H\n:PROPERTIES:\n:END:\n"
318 (org-test-with-temp-text "* H"
319 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
320 (buffer-string))))
321 ;; Skip inlinetasks before point.
322 (when (featurep 'org-inlinetask)
323 (should
324 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
325 (org-test-with-temp-text
326 "* H\n*************** I\n*************** END\nP<point>"
327 (let ((org-adapt-indentation nil)
328 (org-inlinetask-min-level 15))
329 (org-insert-property-drawer))
330 (buffer-string)))))
331 ;; Correctly set drawer in an inlinetask.
332 (when (featurep 'org-inlinetask)
333 (should
334 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
335 (org-test-with-temp-text
336 "* H\n*************** I\nP<point>\n*************** END"
337 (let ((org-adapt-indentation nil)
338 (org-inlinetask-min-level 15))
339 (org-insert-property-drawer))
340 (buffer-string))))))
343 ;;; Filling
345 (ert-deftest test-org/fill-paragraph ()
346 "Test `org-fill-paragraph' specifications."
347 ;; At an Org table, align it.
348 (should
349 (equal "| a |\n"
350 (org-test-with-temp-text "|a|"
351 (org-fill-paragraph)
352 (buffer-string))))
353 (should
354 (equal "#+name: table\n| a |\n"
355 (org-test-with-temp-text "#+name: table\n| a |"
356 (org-fill-paragraph)
357 (buffer-string))))
358 ;; At a paragraph, preserve line breaks.
359 (org-test-with-temp-text "some \\\\\nlong\ntext"
360 (let ((fill-column 20))
361 (org-fill-paragraph)
362 (should (equal (buffer-string) "some \\\\\nlong text"))))
363 ;; Correctly fill a paragraph when point is at its very end.
364 (should
365 (equal "A B"
366 (org-test-with-temp-text "A\nB"
367 (let ((fill-column 20))
368 (goto-char (point-max))
369 (org-fill-paragraph)
370 (buffer-string)))))
371 ;; Correctly fill the last paragraph of a greater element.
372 (should
373 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
374 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
375 (let ((fill-column 8))
376 (forward-line)
377 (end-of-line)
378 (org-fill-paragraph)
379 (buffer-string)))))
380 ;; Correctly fill an element in a narrowed buffer.
381 (should
382 (equal "01234\n6"
383 (org-test-with-temp-text "01234 6789"
384 (let ((fill-column 5))
385 (narrow-to-region 1 8)
386 (org-fill-paragraph)
387 (buffer-string)))))
388 ;; Handle `adaptive-fill-regexp' in paragraphs.
389 (should
390 (equal "> a b"
391 (org-test-with-temp-text "> a\n> b"
392 (let ((fill-column 5)
393 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
394 (org-fill-paragraph)
395 (buffer-string)))))
396 ;; Special case: Fill first paragraph when point is at an item or
397 ;; a plain-list or a footnote reference.
398 (should
399 (equal "- A B"
400 (org-test-with-temp-text "- A\n B"
401 (let ((fill-column 20))
402 (org-fill-paragraph)
403 (buffer-string)))))
404 (should
405 (equal "[fn:1] A B"
406 (org-test-with-temp-text "[fn:1] A\nB"
407 (let ((fill-column 20))
408 (org-fill-paragraph)
409 (buffer-string)))))
410 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
411 (let ((fill-column 20))
412 (org-fill-paragraph)
413 (should (equal (buffer-string)
414 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
415 ;; Fill contents of `comment-block' elements.
416 (should
417 (equal
418 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
419 (let ((fill-column 20))
420 (forward-line)
421 (org-fill-paragraph)
422 (buffer-string)))
423 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
424 ;; Fill `comment' elements.
425 (should
426 (equal " # A B"
427 (org-test-with-temp-text " # A\n # B"
428 (let ((fill-column 20))
429 (org-fill-paragraph)
430 (buffer-string)))))
431 ;; Do not mix consecutive comments when filling one of them.
432 (should
433 (equal "# A B\n\n# C"
434 (org-test-with-temp-text "# A\n# B\n\n# C"
435 (let ((fill-column 20))
436 (org-fill-paragraph)
437 (buffer-string)))))
438 ;; Use commented empty lines as separators when filling comments.
439 (should
440 (equal "# A B\n#\n# C"
441 (org-test-with-temp-text "# A\n# B\n#\n# C"
442 (let ((fill-column 20))
443 (org-fill-paragraph)
444 (buffer-string)))))
445 ;; Handle `adaptive-fill-regexp' in comments.
446 (should
447 (equal "# > a b"
448 (org-test-with-temp-text "# > a\n# > b"
449 (let ((fill-column 20)
450 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
451 (org-fill-paragraph)
452 (buffer-string)))))
453 ;; Do nothing at affiliated keywords.
454 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
455 (let ((fill-column 20))
456 (org-fill-paragraph)
457 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
458 ;; Do not move point after table when filling a table.
459 (should-not
460 (org-test-with-temp-text "| a | b |\n| c | d |\n"
461 (forward-char)
462 (org-fill-paragraph)
463 (eobp))))
465 (ert-deftest test-org/auto-fill-function ()
466 "Test auto-filling features."
467 ;; Auto fill paragraph.
468 (should
469 (equal "12345\n7890"
470 (org-test-with-temp-text "12345 7890"
471 (let ((fill-column 5))
472 (end-of-line)
473 (org-auto-fill-function)
474 (buffer-string)))))
475 ;; Auto fill first paragraph in an item.
476 (should
477 (equal "- 12345\n 7890"
478 (org-test-with-temp-text "- 12345 7890"
479 (let ((fill-column 7))
480 (end-of-line)
481 (org-auto-fill-function)
482 (buffer-string)))))
483 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
484 (should
485 (equal "> 12345\n 7890"
486 (org-test-with-temp-text "> 12345 7890"
487 (let ((fill-column 10)
488 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
489 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
490 (end-of-line)
491 (org-auto-fill-function)
492 (buffer-string)))))
493 (should
494 (equal "> 12345\n> 12345\n> 7890"
495 (org-test-with-temp-text "> 12345\n> 12345 7890"
496 (let ((fill-column 10)
497 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
498 (goto-char (point-max))
499 (org-auto-fill-function)
500 (buffer-string)))))
501 (should-not
502 (equal " 12345\n *12345\n *12345"
503 (org-test-with-temp-text " 12345\n *12345 12345"
504 (let ((fill-column 10)
505 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
506 (goto-char (point-max))
507 (org-auto-fill-function)
508 (buffer-string)))))
509 ;; Auto fill comments.
510 (should
511 (equal " # 12345\n # 7890"
512 (org-test-with-temp-text " # 12345 7890"
513 (let ((fill-column 10))
514 (end-of-line)
515 (org-auto-fill-function)
516 (buffer-string)))))
517 ;; A hash within a line isn't a comment.
518 (should-not
519 (equal "12345 # 7890\n# 1"
520 (org-test-with-temp-text "12345 # 7890 1"
521 (let ((fill-column 12))
522 (end-of-line)
523 (org-auto-fill-function)
524 (buffer-string)))))
525 ;; Correctly interpret empty prefix.
526 (should-not
527 (equal "# a\n# b\nRegular\n# paragraph"
528 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
529 (let ((fill-column 12))
530 (end-of-line 3)
531 (org-auto-fill-function)
532 (buffer-string)))))
533 ;; Comment block: auto fill contents.
534 (should
535 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
536 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
537 (let ((fill-column 5))
538 (forward-line)
539 (end-of-line)
540 (org-auto-fill-function)
541 (buffer-string)))))
542 (should
543 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
544 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
545 (let ((fill-column 5))
546 (forward-line)
547 (end-of-line)
548 (org-auto-fill-function)
549 (buffer-string)))))
550 ;; Do not fill if a new item could be created.
551 (should-not
552 (equal "12345\n- 90"
553 (org-test-with-temp-text "12345 - 90"
554 (let ((fill-column 5))
555 (end-of-line)
556 (org-auto-fill-function)
557 (buffer-string)))))
558 ;; Do not fill if a line break could be introduced.
559 (should-not
560 (equal "123\\\\\n7890"
561 (org-test-with-temp-text "123\\\\ 7890"
562 (let ((fill-column 6))
563 (end-of-line)
564 (org-auto-fill-function)
565 (buffer-string)))))
566 ;; Do not fill affiliated keywords.
567 (should-not
568 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
569 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
570 (let ((fill-column 20))
571 (end-of-line)
572 (org-auto-fill-function)
573 (buffer-string))))))
577 ;;; Indentation
579 (ert-deftest test-org/indent-line ()
580 "Test `org-indent-line' specifications."
581 ;; Do not indent footnote definitions or headlines.
582 (should
583 (zerop
584 (org-test-with-temp-text "* H"
585 (org-indent-line)
586 (org-get-indentation))))
587 (should
588 (zerop
589 (org-test-with-temp-text "[fn:1] fn"
590 (let ((org-adapt-indentation t)) (org-indent-line))
591 (org-get-indentation))))
592 ;; Do not indent before first headline.
593 (should
594 (zerop
595 (org-test-with-temp-text ""
596 (org-indent-line)
597 (org-get-indentation))))
598 ;; Indent according to headline level otherwise, unless
599 ;; `org-adapt-indentation' is nil.
600 (should
601 (= 2
602 (org-test-with-temp-text "* H\nA"
603 (forward-line)
604 (let ((org-adapt-indentation t)) (org-indent-line))
605 (org-get-indentation))))
606 (should
607 (= 2
608 (org-test-with-temp-text "* H\n\nA"
609 (forward-line)
610 (let ((org-adapt-indentation t)) (org-indent-line))
611 (org-get-indentation))))
612 (should
613 (zerop
614 (org-test-with-temp-text "* H\nA"
615 (forward-line)
616 (let ((org-adapt-indentation nil)) (org-indent-line))
617 (org-get-indentation))))
618 ;; Indenting preserves point position.
619 (should
620 (org-test-with-temp-text "* H\nAB"
621 (forward-line)
622 (forward-char)
623 (let ((org-adapt-indentation t)) (org-indent-line))
624 (looking-at "B")))
625 ;; Do not change indentation at an item.
626 (should
627 (= 1
628 (org-test-with-temp-text "* H\n - A"
629 (forward-line)
630 (let ((org-adapt-indentation t)) (org-indent-line))
631 (org-get-indentation))))
632 ;; On blank lines at the end of a list, indent like last element
633 ;; within it if the line is still in the list. Otherwise, indent
634 ;; like the whole list.
635 (should
636 (= 4
637 (org-test-with-temp-text "* H\n- A\n - AA\n"
638 (goto-char (point-max))
639 (let ((org-adapt-indentation t)) (org-indent-line))
640 (org-get-indentation))))
641 (should
642 (zerop
643 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
644 (goto-char (point-max))
645 (let ((org-adapt-indentation t)) (org-indent-line))
646 (org-get-indentation))))
647 ;; Likewise, on a blank line at the end of a footnote definition,
648 ;; indent at column 0 if line belongs to the definition. Otherwise,
649 ;; indent like the definition itself.
650 (should
651 (zerop
652 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
653 (goto-char (point-max))
654 (let ((org-adapt-indentation t)) (org-indent-line))
655 (org-get-indentation))))
656 (should
657 (zerop
658 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
659 (goto-char (point-max))
660 (let ((org-adapt-indentation t)) (org-indent-line))
661 (org-get-indentation))))
662 ;; After the end of the contents of a greater element, indent like
663 ;; the beginning of the element.
664 (should
665 (= 1
666 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
667 (forward-line 2)
668 (org-indent-line)
669 (org-get-indentation))))
670 ;; On blank lines after a paragraph, indent like its last non-empty
671 ;; line.
672 (should
673 (= 1
674 (org-test-with-temp-text " Paragraph\n\n<point>"
675 (org-indent-line)
676 (org-get-indentation))))
677 ;; At the first line of an element, indent like previous element's
678 ;; first line, ignoring footnotes definitions and inline tasks, or
679 ;; according to parent.
680 (should
681 (= 2
682 (org-test-with-temp-text "A\n\n B\n\nC"
683 (goto-char (point-max))
684 (org-indent-line)
685 (org-get-indentation))))
686 (should
687 (= 1
688 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
689 (goto-char (point-max))
690 (org-indent-line)
691 (org-get-indentation))))
692 (should
693 (= 1
694 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
695 (forward-line 1)
696 (org-indent-line)
697 (org-get-indentation))))
698 ;; Within code part of a source block, use language major mode if
699 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
700 ;; according to line above.
701 (should
702 (= 6
703 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
704 (forward-line 2)
705 (let ((org-src-tab-acts-natively t)
706 (org-edit-src-content-indentation 0))
707 (org-indent-line))
708 (org-get-indentation))))
709 (should
710 (= 1
711 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
712 (forward-line 2)
713 (let ((org-src-tab-acts-natively nil)
714 (org-edit-src-content-indentation 0))
715 (org-indent-line))
716 (org-get-indentation))))
717 ;; Otherwise, indent like the first non-blank line above.
718 (should
719 (zerop
720 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
721 (forward-line 3)
722 (org-indent-line)
723 (org-get-indentation))))
724 ;; Align node properties according to `org-property-format'. Handle
725 ;; nicely empty values.
726 (should
727 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
728 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
729 (let ((org-property-format "%-10s %s")) (org-indent-line))
730 (buffer-string))))
731 (should
732 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
733 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
734 (let ((org-property-format "%-10s %s")) (org-indent-line))
735 (buffer-string)))))
737 (ert-deftest test-org/indent-region ()
738 "Test `org-indent-region' specifications."
739 ;; Indent paragraph.
740 (should
741 (equal "A\nB\nC"
742 (org-test-with-temp-text " A\nB\n C"
743 (org-indent-region (point-min) (point-max))
744 (buffer-string))))
745 ;; Indent greater elements along with their contents.
746 (should
747 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
748 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
749 (org-indent-region (point-min) (point-max))
750 (buffer-string))))
751 ;; Ignore contents of verse blocks and example blocks.
752 (should
753 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
754 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
755 (org-indent-region (point-min) (point-max))
756 (buffer-string))))
757 (should
758 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
759 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
760 (org-indent-region (point-min) (point-max))
761 (buffer-string))))
762 ;; Indent according to mode if `org-src-tab-acts-natively' is
763 ;; non-nil. Otherwise, do not indent code at all.
764 (should
765 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
766 (org-test-with-temp-text
767 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
768 (let ((org-src-tab-acts-natively t)
769 (org-edit-src-content-indentation 0))
770 (org-indent-region (point-min) (point-max)))
771 (buffer-string))))
772 (should
773 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
774 (org-test-with-temp-text
775 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
776 (let ((org-src-tab-acts-natively nil)
777 (org-edit-src-content-indentation 0))
778 (org-indent-region (point-min) (point-max)))
779 (buffer-string))))
780 ;; Align node properties according to `org-property-format'. Handle
781 ;; nicely empty values.
782 (should
783 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
784 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
785 (let ((org-property-format "%-10s %s")
786 (org-adapt-indentation nil))
787 (org-indent-region (point) (point-max)))
788 (buffer-string))))
789 (should
790 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
791 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
792 (let ((org-property-format "%-10s %s")
793 (org-adapt-indentation nil))
794 (org-indent-region (point) (point-max)))
795 (buffer-string))))
796 ;; Indent plain lists.
797 (should
798 (equal "- A\n B\n - C\n\n D"
799 (org-test-with-temp-text "- A\n B\n - C\n\n D"
800 (org-indent-region (point-min) (point-max))
801 (buffer-string))))
802 (should
803 (equal "- A\n\n- B"
804 (org-test-with-temp-text " - A\n\n - B"
805 (org-indent-region (point-min) (point-max))
806 (buffer-string))))
807 ;; Indent footnote definitions.
808 (should
809 (equal "[fn:1] Definition\n\nDefinition"
810 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
811 (org-indent-region (point-min) (point-max))
812 (buffer-string))))
813 ;; Special case: Start indenting on a blank line.
814 (should
815 (equal "\nParagraph"
816 (org-test-with-temp-text "\n Paragraph"
817 (org-indent-region (point-min) (point-max))
818 (buffer-string)))))
822 ;;; Editing
824 (ert-deftest test-org/return ()
825 "Test RET (`org-return') specifications."
826 ;; Regular test.
827 (should
828 (equal "Para\ngraph"
829 (org-test-with-temp-text "Para<point>graph"
830 (org-return)
831 (buffer-string))))
832 ;; With optional argument, indent line.
833 (should
834 (equal " Para\n graph"
835 (org-test-with-temp-text " Para<point>graph"
836 (org-return t)
837 (buffer-string))))
838 ;; On a table, call `org-table-next-row'.
839 (should
840 (org-test-with-temp-text "| <point>a |\n| b |"
841 (org-return)
842 (org-looking-at-p "b")))
843 ;; Open link or timestamp under point when `org-return-follows-link'
844 ;; is non-nil.
845 (should
846 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
847 (let ((org-return-follows-link t)) (org-return))
848 (org-looking-at-p "<<target>>")))
849 (should-not
850 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
851 (let ((org-return-follows-link nil)) (org-return))
852 (org-looking-at-p "<<target>>")))
853 ;; However, do not open link when point is in a table.
854 (should
855 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
856 (let ((org-return-follows-link t)) (org-return))
857 (org-looking-at-p "between")))
858 ;; Special case: in a list, when indenting, do not break structure.
859 (should
860 (equal "- A\n B"
861 (org-test-with-temp-text "- A <point>B"
862 (org-return t)
863 (buffer-string))))
864 (should
865 (equal "- A\n\n- B"
866 (org-test-with-temp-text "- A\n<point>- B"
867 (org-return t)
868 (buffer-string))))
869 ;; Special case: on tags part of a headline, add a newline below it
870 ;; instead of breaking it.
871 (should
872 (equal "* H :tag:\n"
873 (org-test-with-temp-text "* H :<point>tag:"
874 (org-return)
875 (buffer-string)))))
877 (ert-deftest test-org/meta-return ()
878 "Test M-RET (`org-meta-return') specifications."
879 ;; In a table field insert a row above.
880 (should
881 (org-test-with-temp-text "| a |"
882 (forward-char)
883 (org-meta-return)
884 (forward-line -1)
885 (looking-at "| |$")))
886 ;; In a paragraph change current line into a header.
887 (should
888 (org-test-with-temp-text "a"
889 (org-meta-return)
890 (beginning-of-line)
891 (looking-at "\* a$")))
892 ;; In an item insert an item, in this case above.
893 (should
894 (org-test-with-temp-text "- a"
895 (org-meta-return)
896 (beginning-of-line)
897 (looking-at "- $")))
898 ;; In a drawer and item insert an item, in this case above.
899 (should
900 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
901 (forward-line)
902 (org-meta-return)
903 (beginning-of-line)
904 (looking-at "- $"))))
906 (ert-deftest test-org/insert-heading ()
907 "Test `org-insert-heading' specifications."
908 ;; In an empty buffer, insert a new headline.
909 (should
910 (equal "* "
911 (org-test-with-temp-text ""
912 (org-insert-heading)
913 (buffer-string))))
914 ;; At the beginning of a line, turn it into a headline
915 (should
916 (equal "* P"
917 (org-test-with-temp-text "<point>P"
918 (org-insert-heading)
919 (buffer-string))))
920 ;; In the middle of a line, split the line if allowed, otherwise,
921 ;; insert the headline at its end.
922 (should
923 (equal "Para\n* graph"
924 (org-test-with-temp-text "Para<point>graph"
925 (let ((org-M-RET-may-split-line '((default . t))))
926 (org-insert-heading))
927 (buffer-string))))
928 (should
929 (equal "Paragraph\n* "
930 (org-test-with-temp-text "Para<point>graph"
931 (let ((org-M-RET-may-split-line '((default . nil))))
932 (org-insert-heading))
933 (buffer-string))))
934 ;; When on a list, insert an item instead, unless called with an
935 ;; universal argument or if list is invisible. In this case, create
936 ;; a new headline after contents.
937 (should
938 (equal "* H\n- item\n- "
939 (org-test-with-temp-text "* H\n- item<point>"
940 (let ((org-insert-heading-respect-content nil))
941 (org-insert-heading))
942 (buffer-string))))
943 (should
944 (equal "* H\n- item\n- item 2\n* "
945 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
946 (let ((org-insert-heading-respect-content nil))
947 (org-insert-heading '(4)))
948 (buffer-string))))
949 (should
950 (equal "* H\n- item\n* "
951 (org-test-with-temp-text "* H\n- item"
952 (org-cycle)
953 (goto-char (point-max))
954 (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
955 (buffer-string))))
956 ;; When called with two universal arguments, insert a new headline
957 ;; at the end of the grandparent subtree.
958 (should
959 (equal "* H1\n** H3\n- item\n** H2\n** "
960 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
961 (let ((org-insert-heading-respect-content nil))
962 (org-insert-heading '(16)))
963 (buffer-string))))
964 ;; When optional TOP-LEVEL argument is non-nil, always insert
965 ;; a level 1 heading.
966 (should
967 (equal "* H1\n** H2\n* "
968 (org-test-with-temp-text "* H1\n** H2<point>"
969 (org-insert-heading nil nil t)
970 (buffer-string))))
971 (should
972 (equal "* H1\n- item\n* "
973 (org-test-with-temp-text "* H1\n- item<point>"
974 (org-insert-heading nil nil t)
975 (buffer-string))))
976 ;; Corner case: correctly insert a headline after an empty one.
977 (should
978 (equal "* \n* "
979 (org-test-with-temp-text "* <point>"
980 (org-insert-heading)
981 (buffer-string)))))
983 (ert-deftest test-org/insert-todo-heading-respect-content ()
984 "Test `org-insert-todo-heading-respect-content' specifications."
985 ;; Create a TODO heading.
986 (should
987 (org-test-with-temp-text "* H1\n Body"
988 (org-insert-todo-heading-respect-content)
989 (nth 2 (org-heading-components))))
990 ;; Add headline at the end of the first subtree
991 (should
992 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
993 (search-forward "H1Body")
994 (org-insert-todo-heading-respect-content)
995 (and (eobp) (org-at-heading-p))))
996 ;; In a list, do not create a new item.
997 (should
998 (org-test-with-temp-text "* H\n- an item\n- another one"
999 (search-forward "an ")
1000 (org-insert-todo-heading-respect-content)
1001 (and (eobp) (org-at-heading-p)))))
1005 ;;; Fixed-Width Areas
1007 (ert-deftest test-org/toggle-fixed-width ()
1008 "Test `org-toggle-fixed-width' specifications."
1009 ;; No region: Toggle on fixed-width marker in paragraphs.
1010 (should
1011 (equal ": A"
1012 (org-test-with-temp-text "A"
1013 (org-toggle-fixed-width)
1014 (buffer-string))))
1015 ;; No region: Toggle off fixed-width markers in fixed-width areas.
1016 (should
1017 (equal "A"
1018 (org-test-with-temp-text ": A"
1019 (org-toggle-fixed-width)
1020 (buffer-string))))
1021 ;; No region: Toggle on marker in blank lines after elements or just
1022 ;; after a headline.
1023 (should
1024 (equal "* H\n: "
1025 (org-test-with-temp-text "* H\n"
1026 (forward-line)
1027 (org-toggle-fixed-width)
1028 (buffer-string))))
1029 (should
1030 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
1031 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
1032 (goto-char (point-max))
1033 (org-toggle-fixed-width)
1034 (buffer-string))))
1035 ;; No region: Toggle on marker in front of one line elements (e.g.,
1036 ;; headlines, clocks)
1037 (should
1038 (equal ": * Headline"
1039 (org-test-with-temp-text "* Headline"
1040 (org-toggle-fixed-width)
1041 (buffer-string))))
1042 (should
1043 (equal ": #+KEYWORD: value"
1044 (org-test-with-temp-text "#+KEYWORD: value"
1045 (org-toggle-fixed-width)
1046 (buffer-string))))
1047 ;; No region: error in other situations.
1048 (should-error
1049 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
1050 (forward-line)
1051 (org-toggle-fixed-width)
1052 (buffer-string)))
1053 ;; No region: Indentation is preserved.
1054 (should
1055 (equal "- A\n : B"
1056 (org-test-with-temp-text "- A\n B"
1057 (forward-line)
1058 (org-toggle-fixed-width)
1059 (buffer-string))))
1060 ;; Region: If it contains only fixed-width elements and blank lines,
1061 ;; toggle off fixed-width markup.
1062 (should
1063 (equal "A\n\nB"
1064 (org-test-with-temp-text ": A\n\n: B"
1065 (transient-mark-mode 1)
1066 (push-mark (point) t t)
1067 (goto-char (point-max))
1068 (org-toggle-fixed-width)
1069 (buffer-string))))
1070 ;; Region: If it contains anything else, toggle on fixed-width but
1071 ;; not on fixed-width areas.
1072 (should
1073 (equal ": A\n: \n: B\n: \n: C"
1074 (org-test-with-temp-text "A\n\n: B\n\nC"
1075 (transient-mark-mode 1)
1076 (push-mark (point) t t)
1077 (goto-char (point-max))
1078 (org-toggle-fixed-width)
1079 (buffer-string))))
1080 ;; Region: Ignore blank lines at its end, unless it contains only
1081 ;; such lines.
1082 (should
1083 (equal ": A\n\n"
1084 (org-test-with-temp-text "A\n\n"
1085 (transient-mark-mode 1)
1086 (push-mark (point) t t)
1087 (goto-char (point-max))
1088 (org-toggle-fixed-width)
1089 (buffer-string))))
1090 (should
1091 (equal ": \n: \n"
1092 (org-test-with-temp-text "\n\n"
1093 (transient-mark-mode 1)
1094 (push-mark (point) t t)
1095 (goto-char (point-max))
1096 (org-toggle-fixed-width)
1097 (buffer-string)))))
1101 ;;; Headline
1103 (ert-deftest test-org/in-commented-heading-p ()
1104 "Test `org-in-commented-heading-p' specifications."
1105 ;; Commented headline.
1106 (should
1107 (org-test-with-temp-text "* COMMENT Headline\nBody"
1108 (goto-char (point-max))
1109 (org-in-commented-heading-p)))
1110 ;; Commented ancestor.
1111 (should
1112 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1113 (goto-char (point-max))
1114 (org-in-commented-heading-p)))
1115 ;; Comment keyword is case-sensitive.
1116 (should-not
1117 (org-test-with-temp-text "* Comment Headline\nBody"
1118 (goto-char (point-max))
1119 (org-in-commented-heading-p)))
1120 ;; Keyword is standalone.
1121 (should-not
1122 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1123 (goto-char (point-max))
1124 (org-in-commented-heading-p)))
1125 ;; Optional argument.
1126 (should-not
1127 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1128 (goto-char (point-max))
1129 (org-in-commented-heading-p t))))
1133 ;;; Keywords
1135 (ert-deftest test-org/set-regexps-and-options ()
1136 "Test `org-set-regexps-and-options' specifications."
1137 ;; TAGS keyword.
1138 (should
1139 (equal '(("A" . ?a) ("B") ("C"))
1140 (org-test-with-temp-text "#+TAGS: A(a) B C"
1141 (org-mode-restart)
1142 org-tag-alist)))
1143 (should
1144 (equal '(("A") (:newline) ("B"))
1145 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1146 (org-mode-restart)
1147 org-tag-alist)))
1148 (should
1149 (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
1150 (org-test-with-temp-text "#+TAGS: { A B } C"
1151 (org-mode-restart)
1152 org-tag-alist)))
1153 (should
1154 (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
1155 (org-test-with-temp-text "#+TAGS: { A : B C }"
1156 (org-mode-restart)
1157 org-tag-alist)))
1158 (should
1159 (equal '(("A" "B" "C"))
1160 (org-test-with-temp-text "#+TAGS: { A : B C }"
1161 (org-mode-restart)
1162 org-tag-groups-alist)))
1163 ;; FILETAGS keyword.
1164 (should
1165 (equal '("A" "B" "C")
1166 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1167 (org-mode-restart)
1168 org-file-tags)))
1169 ;; PROPERTY keyword. Property names are case-insensitive.
1170 (should
1171 (equal "foo=1"
1172 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1173 (org-mode-restart)
1174 (cdr (assoc "var" org-file-properties)))))
1175 (should
1176 (equal
1177 "foo=1 bar=2"
1178 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1179 (org-mode-restart)
1180 (cdr (assoc "var" org-file-properties)))))
1181 (should
1182 (equal
1183 "foo=1 bar=2"
1184 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1185 (org-mode-restart)
1186 (cdr (assoc "var" org-file-properties)))))
1187 ;; ARCHIVE keyword.
1188 (should
1189 (equal "%s_done::"
1190 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1191 (org-mode-restart)
1192 org-archive-location)))
1193 ;; CATEGORY keyword.
1194 (should
1195 (eq 'test
1196 (org-test-with-temp-text "#+CATEGORY: test"
1197 (org-mode-restart)
1198 org-category)))
1199 (should
1200 (equal "test"
1201 (org-test-with-temp-text "#+CATEGORY: test"
1202 (org-mode-restart)
1203 (cdr (assoc "CATEGORY" org-file-properties)))))
1204 ;; COLUMNS keyword.
1205 (should
1206 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1207 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1208 (org-mode-restart)
1209 org-columns-default-format)))
1210 ;; CONSTANTS keyword. Constants names are case sensitive.
1211 (should
1212 (equal '("299792458." "3.14")
1213 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1214 (org-mode-restart)
1215 (mapcar
1216 (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
1217 '("c" "pi")))))
1218 (should
1219 (equal "3.14"
1220 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1221 (org-mode-restart)
1222 (cdr (assoc "pi" org-table-formula-constants-local)))))
1223 (should
1224 (equal "22/7"
1225 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1226 (org-mode-restart)
1227 (cdr (assoc "PI" org-table-formula-constants-local)))))
1228 ;; LINK keyword.
1229 (should
1230 (equal
1231 '("url1" "url2")
1232 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1233 (org-mode-restart)
1234 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
1235 '("a" "b")))))
1236 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1237 (should
1238 (equal
1239 '(?X ?Z ?Y)
1240 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1241 (org-mode-restart)
1242 (list org-highest-priority org-lowest-priority org-default-priority))))
1243 (should
1244 (equal
1245 '(?A ?C ?B)
1246 (org-test-with-temp-text "#+PRIORITIES: X Z"
1247 (org-mode-restart)
1248 (list org-highest-priority org-lowest-priority org-default-priority))))
1249 ;; STARTUP keyword.
1250 (should
1251 (equal '(t t)
1252 (org-test-with-temp-text "#+STARTUP: fold odd"
1253 (org-mode-restart)
1254 (list org-startup-folded org-odd-levels-only))))
1255 ;; TODO keywords.
1256 (should
1257 (equal '(("A" "B") ("C"))
1258 (org-test-with-temp-text "#+TODO: A B | C"
1259 (org-mode-restart)
1260 (list org-not-done-keywords org-done-keywords))))
1261 (should
1262 (equal '(("A" "C") ("B" "D"))
1263 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1264 (org-mode-restart)
1265 (list org-not-done-keywords org-done-keywords))))
1266 (should
1267 (equal '(("A" "B") ("C"))
1268 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1269 (org-mode-restart)
1270 (list org-not-done-keywords org-done-keywords))))
1271 (should
1272 (equal '((:startgroup) ("A" . ?a) (:endgroup))
1273 (org-test-with-temp-text "#+TODO: A(a)"
1274 (org-mode-restart)
1275 org-todo-key-alist)))
1276 (should
1277 (equal '(("D" note nil) ("C" time nil) ("B" note time))
1278 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1279 (org-mode-restart)
1280 org-todo-log-states)))
1281 ;; Enter SETUPFILE keyword.
1282 (should
1283 (equal "1"
1284 (org-test-with-temp-text
1285 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
1286 (org-mode-restart)
1287 (cdr (assoc "a" org-file-properties))))))
1291 ;;; Links
1293 ;;;; Coderefs
1295 (ert-deftest test-org/coderef ()
1296 "Test coderef links specifications."
1297 (should
1298 (org-test-with-temp-text "
1299 #+BEGIN_SRC emacs-lisp
1300 \(+ 1 1) (ref:sc)
1301 #+END_SRC
1302 \[[(sc)]]"
1303 (goto-char (point-max))
1304 (org-open-at-point)
1305 (looking-at "(ref:sc)"))))
1307 ;;;; Custom ID
1309 (ert-deftest test-org/custom-id ()
1310 "Test custom ID links specifications."
1311 (should
1312 (org-test-with-temp-text
1313 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1314 (goto-char (point-max))
1315 (org-open-at-point)
1316 (org-looking-at-p "\\* H1"))))
1318 ;;;; Fuzzy Links
1320 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1321 ;; a named element (#+name: text) and to headlines (* Text).
1323 (ert-deftest test-org/fuzzy-links ()
1324 "Test fuzzy links specifications."
1325 ;; Fuzzy link goes in priority to a matching target.
1326 (should
1327 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1328 (goto-line 5)
1329 (org-open-at-point)
1330 (looking-at "<<Test>>")))
1331 ;; Then fuzzy link points to an element with a given name.
1332 (should
1333 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1334 (goto-line 5)
1335 (org-open-at-point)
1336 (looking-at "#\\+NAME: Test")))
1337 ;; A target still lead to a matching headline otherwise.
1338 (should
1339 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1340 (goto-line 4)
1341 (org-open-at-point)
1342 (looking-at "\\* Head2")))
1343 ;; With a leading star in link, enforce heading match.
1344 (should
1345 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1346 (goto-line 3)
1347 (org-open-at-point)
1348 (looking-at "\\* Test")))
1349 ;; With a leading star in link, enforce exact heading match, even
1350 ;; with `org-link-search-must-match-exact-headline' set to nil.
1351 (should-error
1352 (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
1353 (let ((org-link-search-must-match-exact-headline nil))
1354 (org-open-at-point))))
1355 ;; Heading match should not care about spaces, cookies, todo
1356 ;; keywords, priorities, and tags.
1357 (should
1358 (let ((first-line
1359 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1360 (org-test-with-temp-text
1361 (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
1362 (let ((org-link-search-must-match-exact-headline nil)
1363 (org-todo-regexp "TODO"))
1364 (org-open-at-point))
1365 (looking-at (regexp-quote first-line)))))
1366 ;; Heading match should still be exact.
1367 (should-error
1368 (let ((first-line
1369 "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
1370 (org-test-with-temp-text
1371 (concat first-line "\nFoo Bar\n<point>[[*Test 1]]")
1372 (let ((org-link-search-must-match-exact-headline nil)
1373 (org-todo-regexp "TODO"))
1374 (org-open-at-point)))))
1375 ;; Correctly un-hexify fuzzy links.
1376 (should
1377 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1378 (goto-char (point-max))
1379 (org-open-at-point)
1380 (bobp))))
1382 ;;;; Link Escaping
1384 (ert-deftest test-org/org-link-escape-ascii-character ()
1385 "Escape an ascii character."
1386 (should
1387 (string=
1388 "%5B"
1389 (org-link-escape "["))))
1391 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
1392 "Escape an ascii control character."
1393 (should
1394 (string=
1395 "%09"
1396 (org-link-escape "\t"))))
1398 (ert-deftest test-org/org-link-escape-multibyte-character ()
1399 "Escape an unicode multibyte character."
1400 (should
1401 (string=
1402 "%E2%82%AC"
1403 (org-link-escape "€"))))
1405 (ert-deftest test-org/org-link-escape-custom-table ()
1406 "Escape string with custom character table."
1407 (should
1408 (string=
1409 "Foo%3A%42ar%0A"
1410 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
1412 (ert-deftest test-org/org-link-escape-custom-table-merge ()
1413 "Escape string with custom table merged with default table."
1414 (should
1415 (string=
1416 "%5BF%6F%6F%3A%42ar%0A%5D"
1417 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
1419 (ert-deftest test-org/org-link-unescape-ascii-character ()
1420 "Unescape an ascii character."
1421 (should
1422 (string=
1424 (org-link-unescape "%5B"))))
1426 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
1427 "Unescpae an ascii control character."
1428 (should
1429 (string=
1430 "\n"
1431 (org-link-unescape "%0A"))))
1433 (ert-deftest test-org/org-link-unescape-multibyte-character ()
1434 "Unescape unicode multibyte character."
1435 (should
1436 (string=
1437 "€"
1438 (org-link-unescape "%E2%82%AC"))))
1440 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
1441 "Unescape old style percent escaped character."
1442 (should
1443 (string=
1444 "àâçèéêîôùû"
1445 (decode-coding-string
1446 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
1448 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
1449 "Escape and unescape a URL that includes an escaped char.
1450 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1451 (should
1452 (string=
1453 "http://some.host.com/form?&id=blah%2Bblah25"
1454 (org-link-unescape
1455 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1457 (ert-deftest test-org/org-link-escape-chars-browser ()
1458 "Test of the constant `org-link-escape-chars-browser'.
1459 See there why this test is a candidate to be removed once Org
1460 drops support for Emacs 24.1 and 24.2."
1461 (should
1462 (string=
1463 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1464 "%22Release%208.2%22&idxname=emacs-orgmode")
1465 (org-link-escape-browser ; Do not replace with `url-encode-url',
1466 ; see docstring above.
1467 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1468 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1470 ;;;; Open at point
1472 (ert-deftest test-org/open-at-point-in-property ()
1473 "Does `org-open-at-point' open link in property drawer?"
1474 (should
1475 (org-test-with-temp-text
1476 "* Headline
1477 :PROPERTIES:
1478 :URL: <point>[[info:emacs#Top]]
1479 :END:"
1480 (org-open-at-point) t)))
1482 (ert-deftest test-org/open-at-point-in-comment ()
1483 "Does `org-open-at-point' open link in a commented line?"
1484 (should
1485 (org-test-with-temp-text
1486 "# <point>[[info:emacs#Top]]"
1487 (org-open-at-point) t)))
1489 (ert-deftest test-org/open-at-point/info ()
1490 "Test `org-open-at-point' on info links."
1491 (should
1492 (org-test-with-temp-text
1493 "<point>[[info:emacs#Top]]"
1494 (org-open-at-point)
1495 (and (switch-to-buffer "*info*")
1496 (prog1
1497 (looking-at "\nThe Emacs Editor")
1498 (kill-buffer))))))
1500 (ert-deftest test-org/open-at-point/inline-image ()
1501 "Test `org-open-at-point' on nested links."
1502 (should
1503 (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
1504 (org-open-at-point)
1505 (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
1506 (kill-buffer "*info*")))))
1509 ;;; Node Properties
1511 (ert-deftest test-org/accumulated-properties-in-drawers ()
1512 "Ensure properties accumulate in subtree drawers."
1513 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1514 (org-babel-next-src-block)
1515 (should (equal '(2 1) (org-babel-execute-src-block)))))
1517 (ert-deftest test-org/custom-properties ()
1518 "Test custom properties specifications."
1519 ;; Standard test.
1520 (should
1521 (let ((org-custom-properties '("FOO")))
1522 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1523 (org-toggle-custom-properties-visibility)
1524 (org-invisible-p2))))
1525 ;; Properties are case-insensitive.
1526 (should
1527 (let ((org-custom-properties '("FOO")))
1528 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1529 (org-toggle-custom-properties-visibility)
1530 (org-invisible-p2))))
1531 (should
1532 (let ((org-custom-properties '("foo")))
1533 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1534 (org-toggle-custom-properties-visibility)
1535 (org-invisible-p2))))
1536 ;; Multiple custom properties in the same drawer.
1537 (should
1538 (let ((org-custom-properties '("FOO" "BAR")))
1539 (org-test-with-temp-text
1540 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1541 (org-toggle-custom-properties-visibility)
1542 (and (org-invisible-p2)
1543 (not (progn (forward-line) (org-invisible-p2)))
1544 (progn (forward-line) (org-invisible-p2))))))
1545 ;; Hide custom properties with an empty value.
1546 (should
1547 (let ((org-custom-properties '("FOO")))
1548 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1549 (org-toggle-custom-properties-visibility)
1550 (org-invisible-p2))))
1551 ;; Do not hide fake properties.
1552 (should-not
1553 (let ((org-custom-properties '("FOO")))
1554 (org-test-with-temp-text ":FOO: val\n"
1555 (org-toggle-custom-properties-visibility)
1556 (org-invisible-p2))))
1557 (should-not
1558 (let ((org-custom-properties '("A")))
1559 (org-test-with-temp-text
1560 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1561 (org-toggle-custom-properties-visibility)
1562 (org-invisible-p2)))))
1566 ;;; Mark Region
1568 (ert-deftest test-org/mark-subtree ()
1569 "Test `org-mark-subtree' specifications."
1570 ;; Error when point is before first headline.
1571 (should-error
1572 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1573 (progn (transient-mark-mode 1)
1574 (org-mark-subtree))))
1575 ;; Without argument, mark current subtree.
1576 (should
1577 (equal
1578 '(12 32)
1579 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1580 (progn (transient-mark-mode 1)
1581 (forward-line 2)
1582 (org-mark-subtree)
1583 (list (region-beginning) (region-end))))))
1584 ;; With an argument, move ARG up.
1585 (should
1586 (equal
1587 '(1 32)
1588 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1589 (progn (transient-mark-mode 1)
1590 (forward-line 2)
1591 (org-mark-subtree 1)
1592 (list (region-beginning) (region-end))))))
1593 ;; Do not get fooled by inlinetasks.
1594 (when (featurep 'org-inlinetask)
1595 (should
1596 (= 1
1597 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1598 (progn (transient-mark-mode 1)
1599 (forward-line 1)
1600 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1601 (region-beginning)))))))
1605 ;;; Navigation
1607 (ert-deftest test-org/end-of-meta-data ()
1608 "Test `org-end-of-meta-data' specifications."
1609 ;; Skip planning line.
1610 (should
1611 (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
1612 (org-end-of-meta-data)
1613 (eobp)))
1614 ;; Skip properties drawer.
1615 (should
1616 (org-test-with-temp-text
1617 "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
1618 (org-end-of-meta-data)
1619 (eobp)))
1620 ;; Skip both.
1621 (should
1622 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
1623 (org-end-of-meta-data)
1624 (eobp)))
1625 ;; Nothing to skip, go to first line.
1626 (should
1627 (org-test-with-temp-text "* Headline\nContents"
1628 (org-end-of-meta-data)
1629 (looking-at "Contents")))
1630 ;; With option argument, skip empty lines, regular drawers and
1631 ;; clocking lines.
1632 (should
1633 (org-test-with-temp-text "* Headline\n\nContents"
1634 (org-end-of-meta-data t)
1635 (looking-at "Contents")))
1636 (should
1637 (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
1638 (org-end-of-meta-data t)
1639 (looking-at "Contents")))
1640 (should
1641 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
1642 (org-end-of-meta-data t)
1643 (looking-at "Contents")))
1644 ;; Special case: do not skip incomplete drawers.
1645 (should
1646 (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
1647 (org-end-of-meta-data t)
1648 (looking-at ":LOGBOOK:")))
1649 ;; Special case: Be careful about consecutive headlines.
1650 (should-not
1651 (org-test-with-temp-text "* H1\n*H2\nContents"
1652 (org-end-of-meta-data t)
1653 (looking-at "Contents"))))
1655 (ert-deftest test-org/beginning-of-line ()
1656 "Test `org-beginning-of-line' specifications."
1657 ;; Standard test.
1658 (should
1659 (org-test-with-temp-text "Some text\nSome other text"
1660 (progn (org-beginning-of-line) (bolp))))
1661 ;; Standard test with `visual-line-mode'.
1662 (should-not
1663 (org-test-with-temp-text "A long line of text\nSome other text"
1664 (progn (visual-line-mode)
1665 (forward-char 2)
1666 (dotimes (i 1000) (insert "very "))
1667 (org-beginning-of-line)
1668 (bolp))))
1669 ;; At an headline with special movement.
1670 (should
1671 (org-test-with-temp-text "* TODO Headline"
1672 (let ((org-special-ctrl-a/e t))
1673 (org-end-of-line)
1674 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1675 (progn (org-beginning-of-line) (bolp))
1676 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1678 (ert-deftest test-org/end-of-line ()
1679 "Test `org-end-of-line' specifications."
1680 ;; Standard test.
1681 (should
1682 (org-test-with-temp-text "Some text\nSome other text"
1683 (progn (org-end-of-line) (eolp))))
1684 ;; Standard test with `visual-line-mode'.
1685 (should-not
1686 (org-test-with-temp-text "A long line of text\nSome other text"
1687 (progn (visual-line-mode)
1688 (forward-char 2)
1689 (dotimes (i 1000) (insert "very "))
1690 (goto-char (point-min))
1691 (org-end-of-line)
1692 (eolp))))
1693 ;; At an headline with special movement.
1694 (should
1695 (org-test-with-temp-text "* Headline1 :tag:\n"
1696 (let ((org-special-ctrl-a/e t))
1697 (and (progn (org-end-of-line) (looking-at " :tag:"))
1698 (progn (org-end-of-line) (eolp))
1699 (progn (org-end-of-line) (looking-at " :tag:"))))))
1700 ;; At an headline without special movement.
1701 (should
1702 (org-test-with-temp-text "* Headline2 :tag:\n"
1703 (let ((org-special-ctrl-a/e nil))
1704 (and (progn (org-end-of-line) (eolp))
1705 (progn (org-end-of-line) (eolp))))))
1706 ;; At an headline, with reversed movement.
1707 (should
1708 (org-test-with-temp-text "* Headline3 :tag:\n"
1709 (let ((org-special-ctrl-a/e 'reversed)
1710 (this-command last-command))
1711 (and (progn (org-end-of-line) (eolp))
1712 (progn (org-end-of-line) (looking-at " :tag:"))))))
1713 ;; At a block without hidden contents.
1714 (should
1715 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1716 (progn (org-end-of-line) (eolp))))
1717 ;; At a block with hidden contents.
1718 (should-not
1719 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1720 (let ((org-special-ctrl-a/e t))
1721 (org-hide-block-toggle)
1722 (org-end-of-line)
1723 (eobp)))))
1725 (ert-deftest test-org/forward-paragraph ()
1726 "Test `org-forward-paragraph' specifications."
1727 ;; At end of buffer, return an error.
1728 (should-error
1729 (org-test-with-temp-text "Paragraph"
1730 (goto-char (point-max))
1731 (org-forward-paragraph)))
1732 ;; Standard test.
1733 (should
1734 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1735 (org-forward-paragraph)
1736 (looking-at "P2")))
1737 ;; Ignore depth.
1738 (should
1739 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1740 (org-forward-paragraph)
1741 (looking-at "P1")))
1742 ;; Do not enter elements with invisible contents.
1743 (should
1744 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1745 (org-hide-block-toggle)
1746 (org-forward-paragraph)
1747 (looking-at "P3")))
1748 ;; On an affiliated keyword, jump to the beginning of the element.
1749 (should
1750 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1751 (org-forward-paragraph)
1752 (looking-at "Para")))
1753 ;; On an item or a footnote definition, move to the second element
1754 ;; inside, if any.
1755 (should
1756 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1757 (org-forward-paragraph)
1758 (looking-at " Paragraph")))
1759 (should
1760 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1761 (org-forward-paragraph)
1762 (looking-at "Paragraph")))
1763 ;; On an item, or a footnote definition, when the first line is
1764 ;; empty, move to the first item.
1765 (should
1766 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1767 (org-forward-paragraph)
1768 (looking-at " Paragraph")))
1769 (should
1770 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1771 (org-forward-paragraph)
1772 (looking-at "Paragraph")))
1773 ;; On a table (resp. a property drawer) do not move through table
1774 ;; rows (resp. node properties).
1775 (should
1776 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1777 (org-forward-paragraph)
1778 (looking-at "Paragraph")))
1779 (should
1780 (org-test-with-temp-text
1781 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1782 (org-forward-paragraph)
1783 (looking-at "Paragraph")))
1784 ;; On a verse or source block, stop after blank lines.
1785 (should
1786 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1787 (org-forward-paragraph)
1788 (looking-at "L2")))
1789 (should
1790 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1791 (org-forward-paragraph)
1792 (looking-at "L2"))))
1794 (ert-deftest test-org/backward-paragraph ()
1795 "Test `org-backward-paragraph' specifications."
1796 ;; Error at beginning of buffer.
1797 (should-error
1798 (org-test-with-temp-text "Paragraph"
1799 (org-backward-paragraph)))
1800 ;; Regular test.
1801 (should
1802 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1803 (goto-char (point-max))
1804 (org-backward-paragraph)
1805 (looking-at "P3")))
1806 (should
1807 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1808 (goto-char (point-max))
1809 (beginning-of-line)
1810 (org-backward-paragraph)
1811 (looking-at "P2")))
1812 ;; Ignore depth.
1813 (should
1814 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1815 (goto-char (point-max))
1816 (beginning-of-line)
1817 (org-backward-paragraph)
1818 (looking-at "P2")))
1819 ;; Ignore invisible elements.
1820 (should
1821 (org-test-with-temp-text "* H1\n P1\n* H2"
1822 (org-cycle)
1823 (goto-char (point-max))
1824 (beginning-of-line)
1825 (org-backward-paragraph)
1826 (bobp)))
1827 ;; On an affiliated keyword, jump to the first one.
1828 (should
1829 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1830 (search-forward "c2")
1831 (org-backward-paragraph)
1832 (looking-at "#\\+name")))
1833 ;; On the second element in an item or a footnote definition, jump
1834 ;; to item or the definition.
1835 (should
1836 (org-test-with-temp-text "- line1\n\n line2"
1837 (goto-char (point-max))
1838 (beginning-of-line)
1839 (org-backward-paragraph)
1840 (looking-at "- line1")))
1841 (should
1842 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1843 (goto-char (point-max))
1844 (beginning-of-line)
1845 (org-backward-paragraph)
1846 (looking-at "\\[fn:1\\] line1")))
1847 ;; On a table (resp. a property drawer), ignore table rows
1848 ;; (resp. node properties).
1849 (should
1850 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1851 (goto-char (point-max))
1852 (beginning-of-line)
1853 (org-backward-paragraph)
1854 (bobp)))
1855 (should
1856 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1857 (org-backward-paragraph)
1858 (looking-at ":PROPERTIES:")))
1859 ;; On a source or verse block, stop before blank lines.
1860 (should
1861 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1862 (search-forward "L3")
1863 (beginning-of-line)
1864 (org-backward-paragraph)
1865 (looking-at "L2")))
1866 (should
1867 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1868 (search-forward "L3")
1869 (beginning-of-line)
1870 (org-backward-paragraph)
1871 (looking-at "L2"))))
1873 (ert-deftest test-org/forward-element ()
1874 "Test `org-forward-element' specifications."
1875 ;; 1. At EOB: should error.
1876 (org-test-with-temp-text "Some text\n"
1877 (goto-char (point-max))
1878 (should-error (org-forward-element)))
1879 ;; 2. Standard move: expected to ignore blank lines.
1880 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1881 (org-forward-element)
1882 (should (looking-at (regexp-quote "Second paragraph."))))
1883 ;; 3. Headline tests.
1884 (org-test-with-temp-text "
1885 * Head 1
1886 ** Head 1.1
1887 *** Head 1.1.1
1888 ** Head 1.2"
1889 ;; 3.1. At an headline beginning: move to next headline at the
1890 ;; same level.
1891 (goto-line 3)
1892 (org-forward-element)
1893 (should (looking-at (regexp-quote "** Head 1.2")))
1894 ;; 3.2. At an headline beginning: move to parent headline if no
1895 ;; headline at the same level.
1896 (goto-line 3)
1897 (org-forward-element)
1898 (should (looking-at (regexp-quote "** Head 1.2"))))
1899 ;; 4. Greater element tests.
1900 (org-test-with-temp-text
1901 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1902 ;; 4.1. At a greater element: expected to skip contents.
1903 (org-forward-element)
1904 (should (looking-at (regexp-quote "Outside.")))
1905 ;; 4.2. At the end of greater element contents: expected to skip
1906 ;; to the end of the greater element.
1907 (goto-line 2)
1908 (org-forward-element)
1909 (should (looking-at (regexp-quote "Outside."))))
1910 ;; 5. List tests.
1911 (org-test-with-temp-text "
1912 - item1
1914 - sub1
1916 - sub2
1918 - sub3
1920 Inner paragraph.
1922 - item2
1924 Outside."
1925 ;; 5.1. At list top point: expected to move to the element after
1926 ;; the list.
1927 (goto-line 2)
1928 (org-forward-element)
1929 (should (looking-at (regexp-quote "Outside.")))
1930 ;; 5.2. Special case: at the first line of a sub-list, but not at
1931 ;; beginning of line, move to next item.
1932 (goto-line 2)
1933 (forward-char)
1934 (org-forward-element)
1935 (should (looking-at "- item2"))
1936 (goto-line 4)
1937 (forward-char)
1938 (org-forward-element)
1939 (should (looking-at " - sub2"))
1940 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1941 (goto-line 4)
1942 (org-forward-element)
1943 (should (looking-at (regexp-quote " Inner paragraph.")))
1944 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1945 (goto-line 8)
1946 (org-forward-element)
1947 (should (looking-at (regexp-quote " Inner paragraph.")))
1948 ;; 5.5. At an item: expected to move to next item, if any.
1949 (goto-line 6)
1950 (org-forward-element)
1951 (should (looking-at " - sub3"))))
1953 (ert-deftest test-org/backward-element ()
1954 "Test `org-backward-element' specifications."
1955 ;; 1. Should error at BOB.
1956 (org-test-with-temp-text " \nParagraph."
1957 (should-error (org-backward-element)))
1958 ;; 2. Should move at BOB when called on the first element in buffer.
1959 (should
1960 (org-test-with-temp-text "\n#+TITLE: test"
1961 (progn (forward-line)
1962 (org-backward-element)
1963 (bobp))))
1964 ;; 3. Not at the beginning of an element: move at its beginning.
1965 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1966 (goto-line 3)
1967 (end-of-line)
1968 (org-backward-element)
1969 (should (looking-at (regexp-quote "Paragraph2."))))
1970 ;; 4. Headline tests.
1971 (org-test-with-temp-text "
1972 * Head 1
1973 ** Head 1.1
1974 *** Head 1.1.1
1975 ** Head 1.2"
1976 ;; 4.1. At an headline beginning: move to previous headline at the
1977 ;; same level.
1978 (goto-line 5)
1979 (org-backward-element)
1980 (should (looking-at (regexp-quote "** Head 1.1")))
1981 ;; 4.2. At an headline beginning: move to parent headline if no
1982 ;; headline at the same level.
1983 (goto-line 3)
1984 (org-backward-element)
1985 (should (looking-at (regexp-quote "* Head 1")))
1986 ;; 4.3. At the first top-level headline: should error.
1987 (goto-line 2)
1988 (should-error (org-backward-element)))
1989 ;; 5. At beginning of first element inside a greater element:
1990 ;; expected to move to greater element's beginning.
1991 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1992 (goto-line 3)
1993 (org-backward-element)
1994 (should (looking-at "#\\+BEGIN_CENTER")))
1995 ;; 6. At the beginning of the first element in a section: should
1996 ;; move back to headline, if any.
1997 (should
1998 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1999 (progn (goto-char (point-max))
2000 (beginning-of-line)
2001 (org-backward-element)
2002 (org-at-heading-p))))
2003 ;; 7. List tests.
2004 (org-test-with-temp-text "
2005 - item1
2007 - sub1
2009 - sub2
2011 - sub3
2013 Inner paragraph.
2015 - item2
2018 Outside."
2019 ;; 7.1. At beginning of sub-list: expected to move to the
2020 ;; paragraph before it.
2021 (goto-line 4)
2022 (org-backward-element)
2023 (should (looking-at "item1"))
2024 ;; 7.2. At an item in a list: expected to move at previous item.
2025 (goto-line 8)
2026 (org-backward-element)
2027 (should (looking-at " - sub2"))
2028 (goto-line 12)
2029 (org-backward-element)
2030 (should (looking-at "- item1"))
2031 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
2032 ;; beginning.
2033 (goto-line 10)
2034 (org-backward-element)
2035 (should (looking-at " - sub1"))
2036 (goto-line 15)
2037 (org-backward-element)
2038 (should (looking-at "- item1"))
2039 ;; 7.4. At blank-lines before list end: expected to move to top
2040 ;; item.
2041 (goto-line 14)
2042 (org-backward-element)
2043 (should (looking-at "- item1"))))
2045 (ert-deftest test-org/up-element ()
2046 "Test `org-up-element' specifications."
2047 ;; 1. At BOB or with no surrounding element: should error.
2048 (org-test-with-temp-text "Paragraph."
2049 (should-error (org-up-element)))
2050 (org-test-with-temp-text "* Head1\n* Head2"
2051 (goto-line 2)
2052 (should-error (org-up-element)))
2053 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
2054 (goto-line 3)
2055 (should-error (org-up-element)))
2056 ;; 2. At an headline: move to parent headline.
2057 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
2058 (goto-line 3)
2059 (org-up-element)
2060 (should (looking-at "\\* Head1")))
2061 ;; 3. Inside a greater element: move to greater element beginning.
2062 (org-test-with-temp-text
2063 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
2064 (goto-line 3)
2065 (org-up-element)
2066 (should (looking-at "#\\+BEGIN_CENTER")))
2067 ;; 4. List tests.
2068 (org-test-with-temp-text "* Top
2069 - item1
2071 - sub1
2073 - sub2
2075 Paragraph within sub2.
2077 - item2"
2078 ;; 4.1. Within an item: move to the item beginning.
2079 (goto-line 8)
2080 (org-up-element)
2081 (should (looking-at " - sub2"))
2082 ;; 4.2. At an item in a sub-list: move to parent item.
2083 (goto-line 4)
2084 (org-up-element)
2085 (should (looking-at "- item1"))
2086 ;; 4.3. At an item in top list: move to beginning of whole list.
2087 (goto-line 10)
2088 (org-up-element)
2089 (should (looking-at "- item1"))
2090 ;; 4.4. Special case. At very top point: should move to parent of
2091 ;; list.
2092 (goto-line 2)
2093 (org-up-element)
2094 (should (looking-at "\\* Top"))))
2096 (ert-deftest test-org/down-element ()
2097 "Test `org-down-element' specifications."
2098 ;; Error when the element hasn't got a recursive type.
2099 (org-test-with-temp-text "Paragraph."
2100 (should-error (org-down-element)))
2101 ;; Error when the element has no contents
2102 (org-test-with-temp-text "* Headline"
2103 (should-error (org-down-element)))
2104 ;; When at a plain-list, move to first item.
2105 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
2106 (goto-line 2)
2107 (org-down-element)
2108 (should (looking-at " - Item 1.1")))
2109 (org-test-with-temp-text "#+NAME: list\n- Item 1"
2110 (org-down-element)
2111 (should (looking-at " Item 1")))
2112 ;; When at a table, move to first row
2113 (org-test-with-temp-text "#+NAME: table\n| a | b |"
2114 (org-down-element)
2115 (should (looking-at " a | b |")))
2116 ;; Otherwise, move inside the greater element.
2117 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
2118 (org-down-element)
2119 (should (looking-at "Paragraph"))))
2121 (ert-deftest test-org/drag-element-backward ()
2122 "Test `org-drag-element-backward' specifications."
2123 ;; Standard test.
2124 (should
2125 (equal
2126 "#+key2: val2\n#+key1: val1\n#+key3: val3"
2127 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
2128 (org-drag-element-backward)
2129 (buffer-string))))
2130 (should
2131 (equal
2132 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
2133 (org-test-with-temp-text
2134 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
2135 (org-drag-element-backward)
2136 (buffer-string))))
2137 ;; Preserve blank lines.
2138 (should
2139 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
2140 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
2141 (org-drag-element-backward)
2142 (buffer-string))))
2143 ;; Preserve column.
2144 (should
2145 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
2146 (org-drag-element-backward)
2147 (org-looking-at-p "2")))
2148 ;; Error when trying to move first element of buffer.
2149 (should-error
2150 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2151 (org-drag-element-backward)))
2152 ;; Error when trying to swap nested elements.
2153 (should-error
2154 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2155 (forward-line)
2156 (org-drag-element-backward)))
2157 ;; Error when trying to swap an headline element and a non-headline
2158 ;; element.
2159 (should-error
2160 (org-test-with-temp-text "Test.\n* Head 1"
2161 (forward-line)
2162 (org-drag-element-backward)))
2163 ;; Preserve visibility of elements and their contents.
2164 (should
2165 (equal '((63 . 82) (26 . 48))
2166 (org-test-with-temp-text "
2167 #+BEGIN_CENTER
2168 Text.
2169 #+END_CENTER
2170 - item 1
2171 #+BEGIN_QUOTE
2172 Text.
2173 #+END_QUOTE"
2174 (while (search-forward "BEGIN_" nil t) (org-cycle))
2175 (search-backward "- item 1")
2176 (org-drag-element-backward)
2177 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
2178 (overlays-in (point-min) (point-max)))))))
2180 (ert-deftest test-org/drag-element-forward ()
2181 "Test `org-drag-element-forward' specifications."
2182 ;; 1. Error when trying to move first element of buffer.
2183 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2184 (goto-line 3)
2185 (should-error (org-drag-element-forward)))
2186 ;; 2. Error when trying to swap nested elements.
2187 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2188 (forward-line)
2189 (should-error (org-drag-element-forward)))
2190 ;; 3. Error when trying to swap a non-headline element and an
2191 ;; headline.
2192 (org-test-with-temp-text "Test.\n* Head 1"
2193 (should-error (org-drag-element-forward)))
2194 ;; 4. Otherwise, swap elements, preserving column and blank lines
2195 ;; between elements.
2196 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2197 (search-forward "graph")
2198 (org-drag-element-forward)
2199 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2200 (should (looking-at " 1")))
2201 ;; 5. Preserve visibility of elements and their contents.
2202 (org-test-with-temp-text "
2203 #+BEGIN_CENTER
2204 Text.
2205 #+END_CENTER
2206 - item 1
2207 #+BEGIN_QUOTE
2208 Text.
2209 #+END_QUOTE"
2210 (while (search-forward "BEGIN_" nil t) (org-cycle))
2211 (search-backward "#+BEGIN_CENTER")
2212 (org-drag-element-forward)
2213 (should
2214 (equal
2215 '((63 . 82) (26 . 48))
2216 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
2217 (overlays-in (point-min) (point-max)))))))
2220 ;;; Outline structure
2222 (ert-deftest test-org/demote ()
2223 "Test `org-demote' specifications."
2224 ;; Add correct number of stars according to `org-odd-levels-only'.
2225 (should
2226 (= 2
2227 (org-test-with-temp-text "* H"
2228 (let ((org-odd-levels-only nil)) (org-demote))
2229 (org-current-level))))
2230 (should
2231 (= 3
2232 (org-test-with-temp-text "* H"
2233 (let ((org-odd-levels-only t)) (org-demote))
2234 (org-current-level))))
2235 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2236 (should
2237 (org-test-with-temp-text "* H :tag:"
2238 (let ((org-tags-column 10)
2239 (org-auto-align-tags t)
2240 (org-odd-levels-only nil))
2241 (org-demote))
2242 (org-move-to-column 10)
2243 (org-looking-at-p ":tag:$")))
2244 (should-not
2245 (org-test-with-temp-text "* H :tag:"
2246 (let ((org-tags-column 10)
2247 (org-auto-align-tags nil)
2248 (org-odd-levels-only nil))
2249 (org-demote))
2250 (org-move-to-column 10)
2251 (org-looking-at-p ":tag:$")))
2252 ;; When `org-adapt-indentation' is non-nil, always indent planning
2253 ;; info and property drawers accordingly.
2254 (should
2255 (= 3
2256 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2257 (let ((org-odd-levels-only nil)
2258 (org-adapt-indentation t))
2259 (org-demote))
2260 (forward-line)
2261 (org-get-indentation))))
2262 (should
2263 (= 3
2264 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2265 (let ((org-odd-levels-only nil)
2266 (org-adapt-indentation t))
2267 (org-demote))
2268 (forward-line)
2269 (org-get-indentation))))
2270 (should-not
2271 (= 3
2272 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2273 (let ((org-odd-levels-only nil)
2274 (org-adapt-indentation nil))
2275 (org-demote))
2276 (forward-line)
2277 (org-get-indentation))))
2278 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2279 ;; section accordingly. Ignore, however, footnote definitions and
2280 ;; inlinetasks boundaries.
2281 (should
2282 (= 3
2283 (org-test-with-temp-text "* H\n Paragraph"
2284 (let ((org-odd-levels-only nil)
2285 (org-adapt-indentation t))
2286 (org-demote))
2287 (forward-line)
2288 (org-get-indentation))))
2289 (should
2290 (= 2
2291 (org-test-with-temp-text "* H\n Paragraph"
2292 (let ((org-odd-levels-only nil)
2293 (org-adapt-indentation nil))
2294 (org-demote))
2295 (forward-line)
2296 (org-get-indentation))))
2297 (should
2298 (zerop
2299 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2300 (let ((org-odd-levels-only nil)
2301 (org-adapt-indentation t))
2302 (org-demote))
2303 (goto-char (point-max))
2304 (org-get-indentation))))
2305 (should
2306 (= 3
2307 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2308 (let ((org-odd-levels-only nil)
2309 (org-adapt-indentation t))
2310 (org-demote))
2311 (goto-char (point-max))
2312 (org-get-indentation))))
2313 (when (featurep 'org-inlinetask)
2314 (should
2315 (zerop
2316 (let ((org-inlinetask-min-level 5)
2317 (org-adapt-indentation t))
2318 (org-test-with-temp-text "* H\n***** I\n***** END"
2319 (org-demote)
2320 (forward-line)
2321 (org-get-indentation))))))
2322 (when (featurep 'org-inlinetask)
2323 (should
2324 (= 3
2325 (let ((org-inlinetask-min-level 5)
2326 (org-adapt-indentation t))
2327 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2328 (org-demote)
2329 (forward-line 2)
2330 (org-get-indentation))))))
2331 ;; Ignore contents of source blocks or example blocks when
2332 ;; indentation should be preserved (through
2333 ;; `org-src-preserve-indentation' or "-i" flag).
2334 (should-not
2335 (zerop
2336 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2337 (let ((org-adapt-indentation t)
2338 (org-src-preserve-indentation nil))
2339 (org-demote))
2340 (forward-line 2)
2341 (org-get-indentation))))
2342 (should
2343 (zerop
2344 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2345 (let ((org-adapt-indentation t)
2346 (org-src-preserve-indentation t))
2347 (org-demote))
2348 (forward-line 2)
2349 (org-get-indentation))))
2350 (should
2351 (zerop
2352 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2353 (let ((org-adapt-indentation t)
2354 (org-src-preserve-indentation t))
2355 (org-demote))
2356 (forward-line 2)
2357 (org-get-indentation))))
2358 (should
2359 (zerop
2360 (org-test-with-temp-text
2361 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2362 (let ((org-adapt-indentation t)
2363 (org-src-preserve-indentation nil))
2364 (org-demote))
2365 (forward-line 2)
2366 (org-get-indentation)))))
2368 (ert-deftest test-org/promote ()
2369 "Test `org-promote' specifications."
2370 ;; Return an error if headline is to be promoted to level 0, unless
2371 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2372 ;; headline becomes a comment.
2373 (should-error
2374 (org-test-with-temp-text "* H"
2375 (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
2376 (should
2377 (equal "# H"
2378 (org-test-with-temp-text "* H"
2379 (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
2380 (buffer-string))))
2381 ;; Remove correct number of stars according to
2382 ;; `org-odd-levels-only'.
2383 (should
2384 (= 2
2385 (org-test-with-temp-text "*** H"
2386 (let ((org-odd-levels-only nil)) (org-promote))
2387 (org-current-level))))
2388 (should
2389 (= 1
2390 (org-test-with-temp-text "*** H"
2391 (let ((org-odd-levels-only t)) (org-promote))
2392 (org-current-level))))
2393 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2394 (should
2395 (org-test-with-temp-text "** H :tag:"
2396 (let ((org-tags-column 10)
2397 (org-auto-align-tags t)
2398 (org-odd-levels-only nil))
2399 (org-promote))
2400 (org-move-to-column 10)
2401 (org-looking-at-p ":tag:$")))
2402 (should-not
2403 (org-test-with-temp-text "** H :tag:"
2404 (let ((org-tags-column 10)
2405 (org-auto-align-tags nil)
2406 (org-odd-levels-only nil))
2407 (org-promote))
2408 (org-move-to-column 10)
2409 (org-looking-at-p ":tag:$")))
2410 ;; When `org-adapt-indentation' is non-nil, always indent planning
2411 ;; info and property drawers.
2412 (should
2413 (= 2
2414 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2415 (let ((org-odd-levels-only nil)
2416 (org-adapt-indentation t))
2417 (org-promote))
2418 (forward-line)
2419 (org-get-indentation))))
2420 (should
2421 (= 2
2422 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2423 (let ((org-odd-levels-only nil)
2424 (org-adapt-indentation t))
2425 (org-promote))
2426 (forward-line)
2427 (org-get-indentation))))
2428 (should-not
2429 (= 2
2430 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2431 (let ((org-odd-levels-only nil)
2432 (org-adapt-indentation nil))
2433 (org-promote))
2434 (forward-line)
2435 (org-get-indentation))))
2436 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2437 ;; section accordingly. Ignore, however, footnote definitions and
2438 ;; inlinetasks boundaries.
2439 (should
2440 (= 2
2441 (org-test-with-temp-text "** H\n Paragraph"
2442 (let ((org-odd-levels-only nil)
2443 (org-adapt-indentation t))
2444 (org-promote))
2445 (forward-line)
2446 (org-get-indentation))))
2447 (should-not
2448 (= 2
2449 (org-test-with-temp-text "** H\n Paragraph"
2450 (let ((org-odd-levels-only nil)
2451 (org-adapt-indentation nil))
2452 (org-promote))
2453 (forward-line)
2454 (org-get-indentation))))
2455 (should
2456 (= 2
2457 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2458 (let ((org-odd-levels-only nil)
2459 (org-adapt-indentation t))
2460 (org-promote))
2461 (forward-line)
2462 (org-get-indentation))))
2463 (when (featurep 'org-inlinetask)
2464 (should
2465 (zerop
2466 (let ((org-inlinetask-min-level 5)
2467 (org-adapt-indentation t))
2468 (org-test-with-temp-text "** H\n***** I\n***** END"
2469 (org-promote)
2470 (forward-line)
2471 (org-get-indentation))))))
2472 (when (featurep 'org-inlinetask)
2473 (should
2474 (= 2
2475 (let ((org-inlinetask-min-level 5)
2476 (org-adapt-indentation t))
2477 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2478 (org-promote)
2479 (forward-line 2)
2480 (org-get-indentation))))))
2481 ;; Give up shifting if it would break document's structure
2482 ;; otherwise.
2483 (should
2484 (= 3
2485 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2486 (let ((org-odd-levels-only nil)
2487 (org-adapt-indentation t))
2488 (org-promote))
2489 (forward-line)
2490 (org-get-indentation))))
2491 (should
2492 (= 3
2493 (org-test-with-temp-text "** H\n Paragraph\n * list."
2494 (let ((org-odd-levels-only nil)
2495 (org-adapt-indentation t))
2496 (org-promote))
2497 (forward-line)
2498 (org-get-indentation))))
2499 ;; Ignore contents of source blocks or example blocks when
2500 ;; indentation should be preserved (through
2501 ;; `org-src-preserve-indentation' or "-i" flag).
2502 (should-not
2503 (zerop
2504 (org-test-with-temp-text
2505 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2506 (let ((org-adapt-indentation t)
2507 (org-src-preserve-indentation nil)
2508 (org-odd-levels-only nil))
2509 (org-promote))
2510 (forward-line)
2511 (org-get-indentation))))
2512 (should
2513 (zerop
2514 (org-test-with-temp-text
2515 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2516 (let ((org-adapt-indentation t)
2517 (org-src-preserve-indentation t)
2518 (org-odd-levels-only nil))
2519 (org-promote))
2520 (forward-line)
2521 (org-get-indentation))))
2522 (should
2523 (zerop
2524 (org-test-with-temp-text
2525 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2526 (let ((org-adapt-indentation t)
2527 (org-src-preserve-indentation t)
2528 (org-odd-levels-only nil))
2529 (org-promote))
2530 (forward-line)
2531 (org-get-indentation))))
2532 (should
2533 (zerop
2534 (org-test-with-temp-text
2535 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2536 (let ((org-adapt-indentation t)
2537 (org-src-preserve-indentation nil)
2538 (org-odd-levels-only nil))
2539 (org-promote))
2540 (forward-line)
2541 (org-get-indentation)))))
2544 ;;; Planning
2546 (ert-deftest test-org/at-planning-p ()
2547 "Test `org-at-planning-p' specifications."
2548 ;; Regular test.
2549 (should
2550 (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
2551 (org-at-planning-p)))
2552 (should-not
2553 (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
2554 (org-at-planning-p)))
2555 ;; Correctly find planning attached to inlinetasks.
2556 (when (featurep 'org-inlinetask)
2557 (should
2558 (org-test-with-temp-text
2559 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
2560 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2561 (should-not
2562 (org-test-with-temp-text
2563 "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2564 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2565 (should-not
2566 (org-test-with-temp-text
2567 "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
2568 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
2569 (should-not
2570 (org-test-with-temp-text
2571 "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
2572 (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
2575 ;;; Property API
2577 (ert-deftest test-org/buffer-property-keys ()
2578 "Test `org-buffer-property-keys' specifications."
2579 ;; Retrieve properties accross siblings.
2580 (should
2581 (equal '("A" "B")
2582 (org-test-with-temp-text "
2583 * H1
2584 :PROPERTIES:
2585 :A: 1
2586 :END:
2587 * H2
2588 :PROPERTIES:
2589 :B: 1
2590 :END:"
2591 (org-buffer-property-keys))))
2592 ;; Retrieve properties accross children.
2593 (should
2594 (equal '("A" "B")
2595 (org-test-with-temp-text "
2596 * H1
2597 :PROPERTIES:
2598 :A: 1
2599 :END:
2600 ** H2
2601 :PROPERTIES:
2602 :B: 1
2603 :END:"
2604 (org-buffer-property-keys))))
2605 ;; Retrieve muliple properties in the same drawer.
2606 (should
2607 (equal '("A" "B")
2608 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2609 (org-buffer-property-keys))))
2610 ;; Ignore extension symbol in property name.
2611 (should
2612 (equal '("A")
2613 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2614 (org-buffer-property-keys))))
2615 ;; With non-nil COLUMNS, extract property names from columns.
2616 (should
2617 (equal '("A" "B")
2618 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2619 (org-buffer-property-keys nil nil t))))
2620 (should
2621 (equal '("A" "B" "COLUMNS")
2622 (org-test-with-temp-text
2623 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2624 (org-buffer-property-keys nil nil t)))))
2626 (ert-deftest test-org/property-values ()
2627 "Test `org-property-values' specifications."
2628 ;; Regular test.
2629 (should
2630 (equal '("2" "1")
2631 (org-test-with-temp-text
2632 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2633 (org-property-values "A"))))
2634 ;; Ignore empty values.
2635 (should-not
2636 (org-test-with-temp-text
2637 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2638 (org-property-values "A")))
2639 ;; Take into consideration extended values.
2640 (should
2641 (equal '("1 2")
2642 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2643 (org-property-values "A")))))
2645 (ert-deftest test-org/entry-delete ()
2646 "Test `org-entry-delete' specifications."
2647 ;; Regular test.
2648 (should
2649 (string-match
2650 " *:PROPERTIES:\n *:B: +2\n *:END:"
2651 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2652 (org-entry-delete (point) "A")
2653 (buffer-string))))
2654 ;; When last property is removed, remove the property drawer.
2655 (should-not
2656 (string-match
2657 ":PROPERTIES:"
2658 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2659 (org-entry-delete (point) "A")
2660 (buffer-string)))))
2662 (ert-deftest test-org/entry-get ()
2663 "Test `org-entry-get' specifications."
2664 ;; Regular test.
2665 (should
2666 (equal "1"
2667 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2668 (org-entry-get (point) "A"))))
2669 ;; Ignore case.
2670 (should
2671 (equal "1"
2672 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2673 (org-entry-get (point) "a"))))
2674 ;; Handle extended values, both before and after base value.
2675 (should
2676 (equal "1 2 3"
2677 (org-test-with-temp-text
2678 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2679 (org-entry-get (point) "A"))))
2680 ;; Empty values are returned as the empty string.
2681 (should
2682 (equal ""
2683 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2684 (org-entry-get (point) "A"))))
2685 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2686 ;; otherwise, return nil.
2687 (should-not
2688 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2689 (org-entry-get (point) "A")))
2690 (should
2691 (equal "nil"
2692 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2693 (org-entry-get (point) "A" nil t))))
2694 ;; Return nil when no property is found, independently on the
2695 ;; LITERAL-NIL argument.
2696 (should-not
2697 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2698 (org-entry-get (point) "B")))
2699 (should-not
2700 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2701 (org-entry-get (point) "B" nil t)))
2702 ;; Handle inheritance, when allowed.
2703 (should
2704 (equal
2706 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2707 (org-entry-get (point) "A" t))))
2708 (should
2709 (equal
2711 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2712 (let ((org-use-property-inheritance t))
2713 (org-entry-get (point) "A" 'selective)))))
2714 (should-not
2715 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2716 (let ((org-use-property-inheritance nil))
2717 (org-entry-get (point) "A" 'selective)))))
2719 (ert-deftest test-org/entry-properties ()
2720 "Test `org-entry-properties' specifications."
2721 ;; Get "ITEM" property.
2722 (should
2723 (equal "* H"
2724 (org-test-with-temp-text "* TODO H"
2725 (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
2726 (should
2727 (equal "* H"
2728 (org-test-with-temp-text "* TODO H"
2729 (cdr (assoc "ITEM" (org-entry-properties))))))
2730 ;; Get "TODO" property.
2731 (should
2732 (equal "TODO"
2733 (org-test-with-temp-text "* TODO H"
2734 (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
2735 (should
2736 (equal "TODO"
2737 (org-test-with-temp-text "* TODO H"
2738 (cdr (assoc "TODO" (org-entry-properties))))))
2739 (should-not
2740 (org-test-with-temp-text "* H"
2741 (assoc "TODO" (org-entry-properties nil "TODO"))))
2742 ;; Get "PRIORITY" property.
2743 (should
2744 (equal "A"
2745 (org-test-with-temp-text "* [#A] H"
2746 (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
2747 (should
2748 (equal "A"
2749 (org-test-with-temp-text "* [#A] H"
2750 (cdr (assoc "PRIORITY" (org-entry-properties))))))
2751 (should-not
2752 (org-test-with-temp-text "* H"
2753 (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))
2754 ;; Get "FILE" property.
2755 (should
2756 (org-test-with-temp-text-in-file "* H\nParagraph"
2757 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
2758 (buffer-file-name))))
2759 (should
2760 (org-test-with-temp-text-in-file "* H\nParagraph"
2761 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
2762 (buffer-file-name))))
2763 (should-not
2764 (org-test-with-temp-text "* H\nParagraph"
2765 (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
2766 ;; Get "TAGS" property.
2767 (should
2768 (equal ":tag1:tag2:"
2769 (org-test-with-temp-text "* H :tag1:tag2:"
2770 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
2771 (should
2772 (equal ":tag1:tag2:"
2773 (org-test-with-temp-text "* H :tag1:tag2:"
2774 (cdr (assoc "TAGS" (org-entry-properties))))))
2775 (should-not
2776 (org-test-with-temp-text "* H"
2777 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
2778 ;; Get "ALLTAGS" property.
2779 (should
2780 (equal ":tag1:tag2:"
2781 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2782 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
2783 (should
2784 (equal ":tag1:tag2:"
2785 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2786 (cdr (assoc "ALLTAGS" (org-entry-properties))))))
2787 (should-not
2788 (org-test-with-temp-text "* H"
2789 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
2790 ;; Get "BLOCKED" property.
2791 (should
2792 (equal "t"
2793 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2794 (let ((org-enforce-todo-dependencies t)
2795 (org-blocker-hook
2796 '(org-block-todo-from-children-or-siblings-or-parent)))
2797 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2798 (should
2799 (equal "t"
2800 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2801 (let ((org-enforce-todo-dependencies t)
2802 (org-blocker-hook
2803 '(org-block-todo-from-children-or-siblings-or-parent)))
2804 (cdr (assoc "BLOCKED" (org-entry-properties)))))))
2805 (should
2806 (equal ""
2807 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2808 (let ((org-enforce-todo-dependencies t))
2809 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2810 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2811 (should
2812 (equal
2813 "[2012-03-29 thu.]"
2814 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2815 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
2816 (should
2817 (equal
2818 "[2012-03-29 thu.]"
2819 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2820 (cdr (assoc "CLOSED" (org-entry-properties))))))
2821 (should-not
2822 (org-test-with-temp-text "* H"
2823 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
2824 (should
2825 (equal
2826 "<2014-03-04 tue.>"
2827 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2828 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
2829 (should
2830 (equal
2831 "<2014-03-04 tue.>"
2832 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2833 (cdr (assoc "DEADLINE" (org-entry-properties))))))
2834 (should-not
2835 (org-test-with-temp-text "* H"
2836 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
2837 (should
2838 (equal
2839 "<2014-03-04 tue.>"
2840 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2841 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
2842 (should
2843 (equal
2844 "<2014-03-04 tue.>"
2845 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2846 (cdr (assoc "SCHEDULED" (org-entry-properties))))))
2847 (should-not
2848 (org-test-with-temp-text "* H"
2849 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
2850 ;; Get "CATEGORY"
2851 (should
2852 (equal "cat"
2853 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2854 (cdr (assoc "CATEGORY" (org-entry-properties))))))
2855 (should
2856 (equal "cat"
2857 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2858 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2859 (should
2860 (equal "cat"
2861 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2862 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2863 ;; Get standard properties.
2864 (should
2865 (equal "1"
2866 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2867 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2868 ;; Handle extended properties.
2869 (should
2870 (equal "1 2 3"
2871 (org-test-with-temp-text
2872 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2873 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2874 (should
2875 (equal "1 2 3"
2876 (org-test-with-temp-text
2877 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2878 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2879 ;; Ignore forbidden (special) properties.
2880 (should-not
2881 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2882 (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
2884 (ert-deftest test-org/entry-put ()
2885 "Test `org-entry-put' specifications."
2886 ;; Error when not a string or nil.
2887 (should-error
2888 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2889 (org-entry-put 1 "test" 2)))
2890 ;; Set "TODO" property.
2891 (should
2892 (string-match (regexp-quote " TODO H")
2893 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2894 (org-entry-put (point) "TODO" "TODO")
2895 (buffer-string))))
2896 (should
2897 (string-match (regexp-quote "* H")
2898 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2899 (org-entry-put (point) "TODO" nil)
2900 (buffer-string))))
2901 ;; Set "PRIORITY" property.
2902 (should
2903 (equal "* [#A] H"
2904 (org-test-with-temp-text "* [#B] H"
2905 (org-entry-put (point) "PRIORITY" "A")
2906 (buffer-string))))
2907 (should
2908 (equal "* H"
2909 (org-test-with-temp-text "* [#B] H"
2910 (org-entry-put (point) "PRIORITY" nil)
2911 (buffer-string))))
2912 ;; Set "SCHEDULED" property.
2913 (should
2914 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2915 (org-test-with-temp-text "* H"
2916 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2917 (buffer-string))))
2918 (should
2919 (string= "* H\n"
2920 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2921 (org-entry-put (point) "SCHEDULED" nil)
2922 (buffer-string))))
2923 (should
2924 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
2925 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2926 (org-entry-put (point) "SCHEDULED" "earlier")
2927 (buffer-string))))
2928 (should
2929 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
2930 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2931 (org-entry-put (point) "SCHEDULED" "later")
2932 (buffer-string))))
2933 ;; Set "DEADLINE" property.
2934 (should
2935 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
2936 (org-test-with-temp-text "* H"
2937 (org-entry-put (point) "DEADLINE" "2014-03-04")
2938 (buffer-string))))
2939 (should
2940 (string= "* H\n"
2941 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2942 (org-entry-put (point) "DEADLINE" nil)
2943 (buffer-string))))
2944 (should
2945 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
2946 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2947 (org-entry-put (point) "DEADLINE" "earlier")
2948 (buffer-string))))
2949 (should
2950 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
2951 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2952 (org-entry-put (point) "DEADLINE" "later")
2953 (buffer-string))))
2954 ;; Regular properties, with or without pre-existing drawer.
2955 (should
2956 (string-match "^ *:A: +2$"
2957 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2958 (org-entry-put (point) "A" "2")
2959 (buffer-string))))
2960 (should
2961 (string-match "^ *:A: +1$"
2962 (org-test-with-temp-text "* H"
2963 (org-entry-put (point) "A" "1")
2964 (buffer-string))))
2965 ;; Special case: two consecutive headlines.
2966 (should
2967 (string-match "\\* A\n *:PROPERTIES:"
2968 (org-test-with-temp-text "* A\n** B"
2969 (org-entry-put (point) "A" "1")
2970 (buffer-string)))))
2973 ;;; Radio Targets
2975 (ert-deftest test-org/update-radio-target-regexp ()
2976 "Test `org-update-radio-target-regexp' specifications."
2977 ;; Properly update cache with no previous radio target regexp.
2978 (should
2979 (eq 'link
2980 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2981 (save-excursion (goto-char (point-max)) (org-element-context))
2982 (insert "<<<")
2983 (search-forward "o")
2984 (insert ">>>")
2985 (org-update-radio-target-regexp)
2986 (goto-char (point-max))
2987 (org-element-type (org-element-context)))))
2988 ;; Properly update cache with previous radio target regexp.
2989 (should
2990 (eq 'link
2991 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2992 (save-excursion (goto-char (point-max)) (org-element-context))
2993 (insert "<<<")
2994 (search-forward "o")
2995 (insert ">>>")
2996 (org-update-radio-target-regexp)
2997 (search-backward "r")
2998 (delete-char 5)
2999 (insert "new")
3000 (org-update-radio-target-regexp)
3001 (goto-char (point-max))
3002 (delete-region (line-beginning-position) (point))
3003 (insert "new")
3004 (org-element-type (org-element-context))))))
3007 ;;; Sparse trees
3009 (ert-deftest test-org/match-sparse-tree ()
3010 "Test `org-match-sparse-tree' specifications."
3011 ;; Match tags.
3012 (should-not
3013 (org-test-with-temp-text "* H\n** H1 :tag:"
3014 (org-match-sparse-tree nil "tag")
3015 (search-forward "H1")
3016 (org-invisible-p2)))
3017 (should
3018 (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
3019 (org-match-sparse-tree nil "tag")
3020 (search-forward "H2")
3021 (org-invisible-p2)))
3022 ;; "-" operator for tags.
3023 (should-not
3024 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3025 (org-match-sparse-tree nil "tag1-tag2")
3026 (search-forward "H1")
3027 (org-invisible-p2)))
3028 (should
3029 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3030 (org-match-sparse-tree nil "tag1-tag2")
3031 (search-forward "H2")
3032 (org-invisible-p2)))
3033 ;; "&" operator for tags.
3034 (should
3035 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3036 (org-match-sparse-tree nil "tag1&tag2")
3037 (search-forward "H1")
3038 (org-invisible-p2)))
3039 (should-not
3040 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3041 (org-match-sparse-tree nil "tag1&tag2")
3042 (search-forward "H2")
3043 (org-invisible-p2)))
3044 ;; "|" operator for tags.
3045 (should-not
3046 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3047 (org-match-sparse-tree nil "tag1|tag2")
3048 (search-forward "H1")
3049 (org-invisible-p2)))
3050 (should-not
3051 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
3052 (org-match-sparse-tree nil "tag1|tag2")
3053 (search-forward "H2")
3054 (org-invisible-p2)))
3055 ;; Regexp match on tags.
3056 (should-not
3057 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3058 (org-match-sparse-tree nil "{^tag.*}")
3059 (search-forward "H1")
3060 (org-invisible-p2)))
3061 (should
3062 (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
3063 (org-match-sparse-tree nil "{^tag.*}")
3064 (search-forward "H2")
3065 (org-invisible-p2)))
3066 ;; Match group tags.
3067 (should-not
3068 (org-test-with-temp-text
3069 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3070 (org-match-sparse-tree nil "work")
3071 (search-forward "H1")
3072 (org-invisible-p2)))
3073 (should-not
3074 (org-test-with-temp-text
3075 "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
3076 (org-match-sparse-tree nil "work")
3077 (search-forward "H2")
3078 (org-invisible-p2)))
3079 ;; Match properties.
3080 (should
3081 (org-test-with-temp-text
3082 "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
3083 (org-match-sparse-tree nil "A=\"1\"")
3084 (search-forward "H2")
3085 (org-invisible-p2)))
3086 (should-not
3087 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3088 (org-match-sparse-tree nil "A=\"1\"")
3089 (search-forward "H2")
3090 (org-invisible-p2)))
3091 ;; Case is not significant when matching properties.
3092 (should-not
3093 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
3094 (org-match-sparse-tree nil "a=\"1\"")
3095 (search-forward "H2")
3096 (org-invisible-p2)))
3097 (should-not
3098 (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
3099 (org-match-sparse-tree nil "A=\"1\"")
3100 (search-forward "H2")
3101 (org-invisible-p2)))
3102 ;; Match special LEVEL property.
3103 (should-not
3104 (org-test-with-temp-text "* H\n** H1\n*** H2"
3105 (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
3106 (search-forward "H1")
3107 (org-invisible-p2)))
3108 (should
3109 (org-test-with-temp-text "* H\n** H1\n*** H2"
3110 (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
3111 (search-forward "H2")
3112 (org-invisible-p2)))
3113 ;; Comparison operators when matching properties.
3114 (should
3115 (org-test-with-temp-text
3116 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3117 (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
3118 (search-forward "H1")
3119 (org-invisible-p2)))
3120 (should-not
3121 (org-test-with-temp-text
3122 "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
3123 (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
3124 (search-forward "H2")
3125 (org-invisible-p2)))
3126 ;; Regexp match on properties values.
3127 (should-not
3128 (org-test-with-temp-text
3129 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3130 (org-match-sparse-tree nil "A={f.*}")
3131 (search-forward "H1")
3132 (org-invisible-p2)))
3133 (should
3134 (org-test-with-temp-text
3135 "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
3136 (org-match-sparse-tree nil "A={f.*}")
3137 (search-forward "H2")
3138 (org-invisible-p2)))
3139 ;; With an optional argument, limit match to TODO entries.
3140 (should-not
3141 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3142 (org-match-sparse-tree t "tag")
3143 (search-forward "H1")
3144 (org-invisible-p2)))
3145 (should
3146 (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
3147 (org-match-sparse-tree t "tag")
3148 (search-forward "H2")
3149 (org-invisible-p2))))
3152 ;;; Timestamps API
3154 (ert-deftest test-org/time-stamp ()
3155 "Test `org-time-stamp' specifications."
3156 ;; Insert chosen time stamp at point.
3157 (should
3158 (string-match
3159 "Te<2014-03-04 .*?>xt"
3160 (org-test-with-temp-text "Te<point>xt"
3161 (flet ((org-read-date
3162 (&rest args)
3163 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3164 (org-time-stamp nil)
3165 (buffer-string)))))
3166 ;; With a prefix argument, also insert time.
3167 (should
3168 (string-match
3169 "Te<2014-03-04 .*? 00:41>xt"
3170 (org-test-with-temp-text "Te<point>xt"
3171 (flet ((org-read-date
3172 (&rest args)
3173 (apply #'encode-time (org-parse-time-string "2014-03-04 00:41"))))
3174 (org-time-stamp '(4))
3175 (buffer-string)))))
3176 ;; With two universal prefix arguments, insert an active timestamp
3177 ;; with the current time without prompting the user.
3178 (should
3179 (string-match
3180 "Te<2014-03-04 .*? 00:41>xt"
3181 (org-test-with-temp-text "Te<point>xt"
3182 (flet ((current-time
3184 (apply #'encode-time (org-parse-time-string "2014-03-04 00:41"))))
3185 (org-time-stamp '(16))
3186 (buffer-string)))))
3187 ;; When optional argument is non-nil, insert an inactive timestamp.
3188 (should
3189 (string-match
3190 "Te\\[2014-03-04 .*?\\]xt"
3191 (org-test-with-temp-text "Te<point>xt"
3192 (flet ((org-read-date
3193 (&rest args)
3194 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3195 (org-time-stamp nil t)
3196 (buffer-string)))))
3197 ;; When called from a timestamp, replace existing one.
3198 (should
3199 (string-match
3200 "<2014-03-04 .*?>"
3201 (org-test-with-temp-text "<2012-03-29<point> thu.>"
3202 (flet ((org-read-date
3203 (&rest args)
3204 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3205 (org-time-stamp nil)
3206 (buffer-string)))))
3207 (should
3208 (string-match
3209 "<2014-03-04 .*?>--<2014-03-04 .*?>"
3210 (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
3211 (flet ((org-read-date
3212 (&rest args)
3213 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3214 (org-time-stamp nil)
3215 (buffer-string)))))
3216 ;; When replacing a timestamp, preserve repeater, if any.
3217 (should
3218 (string-match
3219 "<2014-03-04 .*? \\+2y>"
3220 (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
3221 (flet ((org-read-date
3222 (&rest args)
3223 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3224 (org-time-stamp nil)
3225 (buffer-string)))))
3226 ;; When called twice in a raw, build a date range.
3227 (should
3228 (string-match
3229 "<2012-03-29 .*?>--<2014-03-04 .*?>"
3230 (org-test-with-temp-text "<2012-03-29 thu.><point>"
3231 (flet ((org-read-date
3232 (&rest args)
3233 (apply #'encode-time (org-parse-time-string "2014-03-04"))))
3234 (let ((last-command 'org-time-stamp)
3235 (this-command 'org-time-stamp))
3236 (org-time-stamp nil))
3237 (buffer-string))))))
3239 (ert-deftest test-org/timestamp-has-time-p ()
3240 "Test `org-timestamp-has-time-p' specifications."
3241 ;; With time.
3242 (should
3243 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3244 (org-timestamp-has-time-p (org-element-context))))
3245 ;; Without time.
3246 (should-not
3247 (org-test-with-temp-text "<2012-03-29 Thu>"
3248 (org-timestamp-has-time-p (org-element-context)))))
3250 (ert-deftest test-org/timestamp-format ()
3251 "Test `org-timestamp-format' specifications."
3252 ;; Regular test.
3253 (should
3254 (equal
3255 "2012-03-29 16:40"
3256 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
3257 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
3258 ;; Range end.
3259 (should
3260 (equal
3261 "2012-03-29"
3262 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
3263 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
3265 (ert-deftest test-org/timestamp-split-range ()
3266 "Test `org-timestamp-split-range' specifications."
3267 ;; Extract range start (active).
3268 (should
3269 (equal '(2012 3 29)
3270 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3271 (let ((ts (org-timestamp-split-range (org-element-context))))
3272 (mapcar (lambda (p) (org-element-property p ts))
3273 '(:year-end :month-end :day-end))))))
3274 ;; Extract range start (inactive)
3275 (should
3276 (equal '(2012 3 29)
3277 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3278 (let ((ts (org-timestamp-split-range (org-element-context))))
3279 (mapcar (lambda (p) (org-element-property p ts))
3280 '(:year-end :month-end :day-end))))))
3281 ;; Extract range end (active).
3282 (should
3283 (equal '(2012 3 30)
3284 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3285 (let ((ts (org-timestamp-split-range
3286 (org-element-context) t)))
3287 (mapcar (lambda (p) (org-element-property p ts))
3288 '(:year-end :month-end :day-end))))))
3289 ;; Extract range end (inactive)
3290 (should
3291 (equal '(2012 3 30)
3292 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
3293 (let ((ts (org-timestamp-split-range
3294 (org-element-context) t)))
3295 (mapcar (lambda (p) (org-element-property p ts))
3296 '(:year-end :month-end :day-end))))))
3297 ;; Return the timestamp if not a range.
3298 (should
3299 (org-test-with-temp-text "[2012-03-29 Thu]"
3300 (let* ((ts-orig (org-element-context))
3301 (ts-copy (org-timestamp-split-range ts-orig)))
3302 (eq ts-orig ts-copy))))
3303 (should
3304 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3305 (let* ((ts-orig (org-element-context))
3306 (ts-copy (org-timestamp-split-range ts-orig)))
3307 (eq ts-orig ts-copy)))))
3309 (ert-deftest test-org/timestamp-translate ()
3310 "Test `org-timestamp-translate' specifications."
3311 ;; Translate whole date range.
3312 (should
3313 (equal "<29>--<30>"
3314 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3315 (let ((org-display-custom-times t)
3316 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
3317 (org-timestamp-translate (org-element-context))))))
3318 ;; Translate date range start.
3319 (should
3320 (equal "<29>"
3321 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3322 (let ((org-display-custom-times t)
3323 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
3324 (org-timestamp-translate (org-element-context) 'start)))))
3325 ;; Translate date range end.
3326 (should
3327 (equal "<30>"
3328 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
3329 (let ((org-display-custom-times t)
3330 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
3331 (org-timestamp-translate (org-element-context) 'end)))))
3332 ;; Translate time range.
3333 (should
3334 (equal "<08>--<16>"
3335 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
3336 (let ((org-display-custom-times t)
3337 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
3338 (org-timestamp-translate (org-element-context))))))
3339 ;; Translate non-range timestamp.
3340 (should
3341 (equal "<29>"
3342 (org-test-with-temp-text "<2012-03-29 Thu>"
3343 (let ((org-display-custom-times t)
3344 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
3345 (org-timestamp-translate (org-element-context))))))
3346 ;; Do not change `diary' timestamps.
3347 (should
3348 (equal "<%%(org-float t 4 2)>"
3349 (org-test-with-temp-text "<%%(org-float t 4 2)>"
3350 (let ((org-display-custom-times t)
3351 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
3352 (org-timestamp-translate (org-element-context)))))))
3356 ;;; Visibility
3358 (ert-deftest test-org/flag-drawer ()
3359 "Test `org-flag-drawer' specifications."
3360 ;; Hide drawer.
3361 (should
3362 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3363 (org-flag-drawer t)
3364 (get-char-property (line-end-position) 'invisible)))
3365 ;; Show drawer.
3366 (should-not
3367 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3368 (org-flag-drawer t)
3369 (org-flag-drawer nil)
3370 (get-char-property (line-end-position) 'invisible)))
3371 ;; Test optional argument.
3372 (should
3373 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3374 (let ((drawer (save-excursion (search-forward ":D2")
3375 (org-element-at-point))))
3376 (org-flag-drawer t drawer)
3377 (get-char-property (progn (search-forward ":D2") (line-end-position))
3378 'invisible))))
3379 (should-not
3380 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
3381 (let ((drawer (save-excursion (search-forward ":D2")
3382 (org-element-at-point))))
3383 (org-flag-drawer t drawer)
3384 (get-char-property (line-end-position) 'invisible))))
3385 ;; Do not hide fake drawers.
3386 (should-not
3387 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
3388 (forward-line 1)
3389 (org-flag-drawer t)
3390 (get-char-property (line-end-position) 'invisible)))
3391 ;; Do not hide incomplete drawers.
3392 (should-not
3393 (org-test-with-temp-text ":D:\nparagraph"
3394 (forward-line 1)
3395 (org-flag-drawer t)
3396 (get-char-property (line-end-position) 'invisible)))
3397 ;; Do not hide drawers when called from final blank lines.
3398 (should-not
3399 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
3400 (goto-char (point-max))
3401 (org-flag-drawer t)
3402 (goto-char (point-min))
3403 (get-char-property (line-end-position) 'invisible)))
3404 ;; Don't leave point in an invisible part of the buffer when hiding
3405 ;; a drawer away.
3406 (should-not
3407 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
3408 (goto-char (point-max))
3409 (org-flag-drawer t)
3410 (get-char-property (point) 'invisible))))
3412 (ert-deftest test-org/hide-block-toggle ()
3413 "Test `org-hide-block-toggle' specifications."
3414 ;; Error when not at a block.
3415 (should-error
3416 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
3417 (org-hide-block-toggle 'off)
3418 (get-char-property (line-end-position) 'invisible)))
3419 ;; Hide block.
3420 (should
3421 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
3422 (org-hide-block-toggle)
3423 (get-char-property (line-end-position) 'invisible)))
3424 (should
3425 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
3426 (org-hide-block-toggle)
3427 (get-char-property (line-end-position) 'invisible)))
3428 ;; Show block unconditionally when optional argument is `off'.
3429 (should-not
3430 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3431 (org-hide-block-toggle)
3432 (org-hide-block-toggle 'off)
3433 (get-char-property (line-end-position) 'invisible)))
3434 (should-not
3435 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3436 (org-hide-block-toggle 'off)
3437 (get-char-property (line-end-position) 'invisible)))
3438 ;; Hide block unconditionally when optional argument is non-nil.
3439 (should
3440 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3441 (org-hide-block-toggle t)
3442 (get-char-property (line-end-position) 'invisible)))
3443 (should
3444 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
3445 (org-hide-block-toggle)
3446 (org-hide-block-toggle t)
3447 (get-char-property (line-end-position) 'invisible)))
3448 ;; Do not hide block when called from final blank lines.
3449 (should-not
3450 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
3451 (org-hide-block-toggle)
3452 (goto-char (point-min))
3453 (get-char-property (line-end-position) 'invisible)))
3454 ;; Don't leave point in an invisible part of the buffer when hiding
3455 ;; a block away.
3456 (should-not
3457 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
3458 (org-hide-block-toggle)
3459 (get-char-property (point) 'invisible))))
3461 (ert-deftest test-org/hide-block-toggle-maybe ()
3462 "Test `org-hide-block-toggle-maybe' specifications."
3463 (should
3464 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
3465 (org-hide-block-toggle-maybe)))
3466 (should-not
3467 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
3469 (ert-deftest test-org/show-set-visibility ()
3470 "Test `org-show-set-visibility' specifications."
3471 ;; Do not throw an error before first heading.
3472 (should
3473 (org-test-with-temp-text "Preamble\n* Headline"
3474 (org-show-set-visibility 'tree)
3476 ;; Test all visibility spans, both on headline and in entry.
3477 (let ((list-visible-lines
3478 (lambda (state headerp)
3479 (org-test-with-temp-text "* Grandmother (0)
3480 ** Uncle (1)
3481 *** Heir (2)
3482 ** Father (3)
3483 Ancestor text (4)
3484 *** Sister (5)
3485 Sibling text (6)
3486 *** Self (7)
3487 Match (8)
3488 **** First born (9)
3489 Child text (10)
3490 **** The other child (11)
3491 *** Brother (12)
3492 ** Aunt (13)
3494 (org-cycle t)
3495 (search-forward (if headerp "Self" "Match"))
3496 (org-show-set-visibility state)
3497 (goto-char (point-min))
3498 (let (result (line 0))
3499 (while (not (eobp))
3500 (unless (org-invisible-p2) (push line result))
3501 (incf line)
3502 (forward-line))
3503 (nreverse result))))))
3504 (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
3505 (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
3506 (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
3507 (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
3508 (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
3509 (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
3510 (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
3511 (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
3512 (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
3513 (should (equal '(0 1 3 5 7 8 9 11 12 13)
3514 (funcall list-visible-lines 'tree nil)))
3515 (should (equal '(0 1 3 4 5 7 12 13)
3516 (funcall list-visible-lines 'canonical t)))
3517 (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
3518 (funcall list-visible-lines 'canonical nil)))))
3521 (provide 'test-org)
3523 ;;; test-org.el ends here