Merge branch 'maint'
[org-mode.git] / testing / lisp / test-org.el
blobcc06432c4f02c43776c469becf01b1df9917a340
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")))))
196 (ert-deftest test-org/org-parse-time-string ()
197 "Test `org-parse-time-string'."
198 (should (equal (org-parse-time-string "2012-03-29 16:40")
199 '(0 40 16 29 3 2012 nil nil nil)))
200 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
201 '(0 40 16 29 3 2012 nil nil nil)))
202 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
203 '(0 40 16 29 3 2012 nil nil nil)))
204 (should (equal (org-parse-time-string "<2012-03-29>")
205 '(0 0 0 29 3 2012 nil nil nil)))
206 (should (equal (org-parse-time-string "<2012-03-29>" t)
207 '(0 nil nil 29 3 2012 nil nil nil))))
210 ;;; Drawers
212 (ert-deftest test-org/insert-property-drawer ()
213 "Test `org-insert-property-drawer' specifications."
214 ;; Error before first headline.
215 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
216 ;; Insert drawer right after headline if there is no planning line,
217 ;; or after it otherwise.
218 (should
219 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
220 (org-test-with-temp-text "* H\nParagraph<point>"
221 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
222 (buffer-string))))
223 (should
224 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
225 (org-test-with-temp-text
226 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
227 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
228 (buffer-string))))
229 ;; Indent inserted drawer.
230 (should
231 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
232 (org-test-with-temp-text "* H\nParagraph<point>"
233 (let ((org-adapt-indentation t)) (org-insert-property-drawer))
234 (buffer-string))))
235 ;; Handle insertion at eob.
236 (should
237 (equal "* H\n:PROPERTIES:\n:END:\n"
238 (org-test-with-temp-text "* H"
239 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
240 (buffer-string))))
241 ;; Skip inlinetasks before point.
242 (when (featurep 'org-inlinetask)
243 (should
244 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
245 (org-test-with-temp-text
246 "* H\n*************** I\n*************** END\nP<point>"
247 (let ((org-adapt-indentation nil)
248 (org-inlinetask-min-level 15))
249 (org-insert-property-drawer))
250 (buffer-string)))))
251 ;; Correctly set drawer in an inlinetask.
252 (when (featurep 'org-inlinetask)
253 (should
254 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
255 (org-test-with-temp-text
256 "* H\n*************** I\nP<point>\n*************** END"
257 (let ((org-adapt-indentation nil)
258 (org-inlinetask-min-level 15))
259 (org-insert-property-drawer))
260 (buffer-string))))))
263 ;;; Filling
265 (ert-deftest test-org/fill-paragraph ()
266 "Test `org-fill-paragraph' specifications."
267 ;; At an Org table, align it.
268 (should
269 (equal "| a |\n"
270 (org-test-with-temp-text "|a|"
271 (org-fill-paragraph)
272 (buffer-string))))
273 (should
274 (equal "#+name: table\n| a |\n"
275 (org-test-with-temp-text "#+name: table\n| a |"
276 (org-fill-paragraph)
277 (buffer-string))))
278 ;; At a paragraph, preserve line breaks.
279 (org-test-with-temp-text "some \\\\\nlong\ntext"
280 (let ((fill-column 20))
281 (org-fill-paragraph)
282 (should (equal (buffer-string) "some \\\\\nlong text"))))
283 ;; Correctly fill a paragraph when point is at its very end.
284 (should
285 (equal "A B"
286 (org-test-with-temp-text "A\nB"
287 (let ((fill-column 20))
288 (goto-char (point-max))
289 (org-fill-paragraph)
290 (buffer-string)))))
291 ;; Correctly fill the last paragraph of a greater element.
292 (should
293 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
294 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
295 (let ((fill-column 8))
296 (forward-line)
297 (end-of-line)
298 (org-fill-paragraph)
299 (buffer-string)))))
300 ;; Correctly fill an element in a narrowed buffer.
301 (should
302 (equal "01234\n6"
303 (org-test-with-temp-text "01234 6789"
304 (let ((fill-column 5))
305 (narrow-to-region 1 8)
306 (org-fill-paragraph)
307 (buffer-string)))))
308 ;; Handle `adaptive-fill-regexp' in paragraphs.
309 (should
310 (equal "> a b"
311 (org-test-with-temp-text "> a\n> b"
312 (let ((fill-column 5)
313 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
314 (org-fill-paragraph)
315 (buffer-string)))))
316 ;; Special case: Fill first paragraph when point is at an item or
317 ;; a plain-list or a footnote reference.
318 (should
319 (equal "- A B"
320 (org-test-with-temp-text "- A\n B"
321 (let ((fill-column 20))
322 (org-fill-paragraph)
323 (buffer-string)))))
324 (should
325 (equal "[fn:1] A B"
326 (org-test-with-temp-text "[fn:1] A\nB"
327 (let ((fill-column 20))
328 (org-fill-paragraph)
329 (buffer-string)))))
330 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
331 (let ((fill-column 20))
332 (org-fill-paragraph)
333 (should (equal (buffer-string)
334 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
335 ;; Fill contents of `comment-block' elements.
336 (should
337 (equal
338 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
339 (let ((fill-column 20))
340 (forward-line)
341 (org-fill-paragraph)
342 (buffer-string)))
343 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
344 ;; Fill `comment' elements.
345 (should
346 (equal " # A B"
347 (org-test-with-temp-text " # A\n # B"
348 (let ((fill-column 20))
349 (org-fill-paragraph)
350 (buffer-string)))))
351 ;; Do not mix consecutive comments when filling one of them.
352 (should
353 (equal "# A B\n\n# C"
354 (org-test-with-temp-text "# A\n# B\n\n# C"
355 (let ((fill-column 20))
356 (org-fill-paragraph)
357 (buffer-string)))))
358 ;; Use commented empty lines as separators when filling comments.
359 (should
360 (equal "# A B\n#\n# C"
361 (org-test-with-temp-text "# A\n# B\n#\n# C"
362 (let ((fill-column 20))
363 (org-fill-paragraph)
364 (buffer-string)))))
365 ;; Handle `adaptive-fill-regexp' in comments.
366 (should
367 (equal "# > a b"
368 (org-test-with-temp-text "# > a\n# > b"
369 (let ((fill-column 20)
370 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
371 (org-fill-paragraph)
372 (buffer-string)))))
373 ;; Do nothing at affiliated keywords.
374 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
375 (let ((fill-column 20))
376 (org-fill-paragraph)
377 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
378 ;; Do not move point after table when filling a table.
379 (should-not
380 (org-test-with-temp-text "| a | b |\n| c | d |\n"
381 (forward-char)
382 (org-fill-paragraph)
383 (eobp))))
385 (ert-deftest test-org/auto-fill-function ()
386 "Test auto-filling features."
387 ;; Auto fill paragraph.
388 (should
389 (equal "12345\n7890"
390 (org-test-with-temp-text "12345 7890"
391 (let ((fill-column 5))
392 (end-of-line)
393 (org-auto-fill-function)
394 (buffer-string)))))
395 ;; Auto fill first paragraph in an item.
396 (should
397 (equal "- 12345\n 7890"
398 (org-test-with-temp-text "- 12345 7890"
399 (let ((fill-column 7))
400 (end-of-line)
401 (org-auto-fill-function)
402 (buffer-string)))))
403 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
404 (should
405 (equal "> 12345\n 7890"
406 (org-test-with-temp-text "> 12345 7890"
407 (let ((fill-column 10)
408 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
409 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
410 (end-of-line)
411 (org-auto-fill-function)
412 (buffer-string)))))
413 (should
414 (equal "> 12345\n> 12345\n> 7890"
415 (org-test-with-temp-text "> 12345\n> 12345 7890"
416 (let ((fill-column 10)
417 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
418 (goto-char (point-max))
419 (org-auto-fill-function)
420 (buffer-string)))))
421 (should-not
422 (equal " 12345\n *12345\n *12345"
423 (org-test-with-temp-text " 12345\n *12345 12345"
424 (let ((fill-column 10)
425 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
426 (goto-char (point-max))
427 (org-auto-fill-function)
428 (buffer-string)))))
429 ;; Auto fill comments.
430 (should
431 (equal " # 12345\n # 7890"
432 (org-test-with-temp-text " # 12345 7890"
433 (let ((fill-column 10))
434 (end-of-line)
435 (org-auto-fill-function)
436 (buffer-string)))))
437 ;; A hash within a line isn't a comment.
438 (should-not
439 (equal "12345 # 7890\n# 1"
440 (org-test-with-temp-text "12345 # 7890 1"
441 (let ((fill-column 12))
442 (end-of-line)
443 (org-auto-fill-function)
444 (buffer-string)))))
445 ;; Correctly interpret empty prefix.
446 (should-not
447 (equal "# a\n# b\nRegular\n# paragraph"
448 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
449 (let ((fill-column 12))
450 (end-of-line 3)
451 (org-auto-fill-function)
452 (buffer-string)))))
453 ;; Comment block: auto fill contents.
454 (should
455 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
456 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
457 (let ((fill-column 5))
458 (forward-line)
459 (end-of-line)
460 (org-auto-fill-function)
461 (buffer-string)))))
462 (should
463 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
464 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
465 (let ((fill-column 5))
466 (forward-line)
467 (end-of-line)
468 (org-auto-fill-function)
469 (buffer-string)))))
470 ;; Do not fill if a new item could be created.
471 (should-not
472 (equal "12345\n- 90"
473 (org-test-with-temp-text "12345 - 90"
474 (let ((fill-column 5))
475 (end-of-line)
476 (org-auto-fill-function)
477 (buffer-string)))))
478 ;; Do not fill if a line break could be introduced.
479 (should-not
480 (equal "123\\\\\n7890"
481 (org-test-with-temp-text "123\\\\ 7890"
482 (let ((fill-column 6))
483 (end-of-line)
484 (org-auto-fill-function)
485 (buffer-string)))))
486 ;; Do not fill affiliated keywords.
487 (should-not
488 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
489 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
490 (let ((fill-column 20))
491 (end-of-line)
492 (org-auto-fill-function)
493 (buffer-string))))))
497 ;;; Indentation
499 (ert-deftest test-org/indent-line ()
500 "Test `org-indent-line' specifications."
501 ;; Do not indent footnote definitions or headlines.
502 (should
503 (zerop
504 (org-test-with-temp-text "* H"
505 (org-indent-line)
506 (org-get-indentation))))
507 (should
508 (zerop
509 (org-test-with-temp-text "[fn:1] fn"
510 (let ((org-adapt-indentation t)) (org-indent-line))
511 (org-get-indentation))))
512 ;; Do not indent before first headline.
513 (should
514 (zerop
515 (org-test-with-temp-text ""
516 (org-indent-line)
517 (org-get-indentation))))
518 ;; Indent according to headline level otherwise, unless
519 ;; `org-adapt-indentation' is nil.
520 (should
521 (= 2
522 (org-test-with-temp-text "* H\nA"
523 (forward-line)
524 (let ((org-adapt-indentation t)) (org-indent-line))
525 (org-get-indentation))))
526 (should
527 (= 2
528 (org-test-with-temp-text "* H\n\nA"
529 (forward-line)
530 (let ((org-adapt-indentation t)) (org-indent-line))
531 (org-get-indentation))))
532 (should
533 (zerop
534 (org-test-with-temp-text "* H\nA"
535 (forward-line)
536 (let ((org-adapt-indentation nil)) (org-indent-line))
537 (org-get-indentation))))
538 ;; Indenting preserves point position.
539 (should
540 (org-test-with-temp-text "* H\nAB"
541 (forward-line)
542 (forward-char)
543 (let ((org-adapt-indentation t)) (org-indent-line))
544 (looking-at "B")))
545 ;; Do not change indentation at an item.
546 (should
547 (= 1
548 (org-test-with-temp-text "* H\n - A"
549 (forward-line)
550 (let ((org-adapt-indentation t)) (org-indent-line))
551 (org-get-indentation))))
552 ;; On blank lines at the end of a list, indent like last element
553 ;; within it if the line is still in the list. Otherwise, indent
554 ;; like the whole list.
555 (should
556 (= 4
557 (org-test-with-temp-text "* H\n- A\n - AA\n"
558 (goto-char (point-max))
559 (let ((org-adapt-indentation t)) (org-indent-line))
560 (org-get-indentation))))
561 (should
562 (zerop
563 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
564 (goto-char (point-max))
565 (let ((org-adapt-indentation t)) (org-indent-line))
566 (org-get-indentation))))
567 ;; Likewise, on a blank line at the end of a footnote definition,
568 ;; indent at column 0 if line belongs to the definition. Otherwise,
569 ;; indent like the definition itself.
570 (should
571 (zerop
572 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
573 (goto-char (point-max))
574 (let ((org-adapt-indentation t)) (org-indent-line))
575 (org-get-indentation))))
576 (should
577 (zerop
578 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
579 (goto-char (point-max))
580 (let ((org-adapt-indentation t)) (org-indent-line))
581 (org-get-indentation))))
582 ;; After the end of the contents of a greater element, indent like
583 ;; the beginning of the element.
584 (should
585 (= 1
586 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
587 (forward-line 2)
588 (org-indent-line)
589 (org-get-indentation))))
590 ;; At the first line of an element, indent like previous element's
591 ;; first line, ignoring footnotes definitions and inline tasks, or
592 ;; according to parent.
593 (should
594 (= 2
595 (org-test-with-temp-text "A\n\n B\n\nC"
596 (goto-char (point-max))
597 (org-indent-line)
598 (org-get-indentation))))
599 (should
600 (= 1
601 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
602 (goto-char (point-max))
603 (org-indent-line)
604 (org-get-indentation))))
605 (should
606 (= 1
607 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
608 (forward-line 1)
609 (org-indent-line)
610 (org-get-indentation))))
611 ;; Within code part of a source block, use language major mode if
612 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
613 ;; according to line above.
614 (should
615 (= 6
616 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
617 (forward-line 2)
618 (let ((org-src-tab-acts-natively t)
619 (org-edit-src-content-indentation 0))
620 (org-indent-line))
621 (org-get-indentation))))
622 (should
623 (= 1
624 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
625 (forward-line 2)
626 (let ((org-src-tab-acts-natively nil)
627 (org-edit-src-content-indentation 0))
628 (org-indent-line))
629 (org-get-indentation))))
630 ;; Otherwise, indent like the first non-blank line above.
631 (should
632 (zerop
633 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
634 (forward-line 3)
635 (org-indent-line)
636 (org-get-indentation))))
637 ;; Align node properties according to `org-property-format'. Handle
638 ;; nicely empty values.
639 (should
640 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
641 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
642 (let ((org-property-format "%-10s %s")) (org-indent-line))
643 (buffer-string))))
644 (should
645 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
646 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
647 (let ((org-property-format "%-10s %s")) (org-indent-line))
648 (buffer-string)))))
650 (ert-deftest test-org/indent-region ()
651 "Test `org-indent-region' specifications."
652 ;; Indent paragraph.
653 (should
654 (equal "A\nB\nC"
655 (org-test-with-temp-text " A\nB\n C"
656 (org-indent-region (point-min) (point-max))
657 (buffer-string))))
658 ;; Indent greater elements along with their contents.
659 (should
660 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
661 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
662 (org-indent-region (point-min) (point-max))
663 (buffer-string))))
664 ;; Ignore contents of verse blocks and example blocks.
665 (should
666 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
667 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
668 (org-indent-region (point-min) (point-max))
669 (buffer-string))))
670 (should
671 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
672 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
673 (org-indent-region (point-min) (point-max))
674 (buffer-string))))
675 ;; Indent according to mode if `org-src-tab-acts-natively' is
676 ;; non-nil. Otherwise, do not indent code at all.
677 (should
678 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
679 (org-test-with-temp-text
680 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
681 (let ((org-src-tab-acts-natively t)
682 (org-edit-src-content-indentation 0))
683 (org-indent-region (point-min) (point-max)))
684 (buffer-string))))
685 (should
686 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
687 (org-test-with-temp-text
688 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
689 (let ((org-src-tab-acts-natively nil)
690 (org-edit-src-content-indentation 0))
691 (org-indent-region (point-min) (point-max)))
692 (buffer-string))))
693 ;; Align node properties according to `org-property-format'. Handle
694 ;; nicely empty values.
695 (should
696 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
697 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
698 (let ((org-property-format "%-10s %s")
699 (org-adapt-indentation nil))
700 (org-indent-region (point) (point-max)))
701 (buffer-string))))
702 (should
703 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
704 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
705 (let ((org-property-format "%-10s %s")
706 (org-adapt-indentation nil))
707 (org-indent-region (point) (point-max)))
708 (buffer-string))))
709 ;; Indent plain lists.
710 (should
711 (equal "- A\n B\n - C\n\n D"
712 (org-test-with-temp-text "- A\n B\n - C\n\n D"
713 (org-indent-region (point-min) (point-max))
714 (buffer-string))))
715 (should
716 (equal "- A\n\n- B"
717 (org-test-with-temp-text " - A\n\n - B"
718 (org-indent-region (point-min) (point-max))
719 (buffer-string))))
720 ;; Indent footnote definitions.
721 (should
722 (equal "[fn:1] Definition\n\nDefinition"
723 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
724 (org-indent-region (point-min) (point-max))
725 (buffer-string))))
726 ;; Special case: Start indenting on a blank line.
727 (should
728 (equal "\nParagraph"
729 (org-test-with-temp-text "\n Paragraph"
730 (org-indent-region (point-min) (point-max))
731 (buffer-string)))))
735 ;;; Editing
737 (ert-deftest test-org/return ()
738 "Test RET (`org-return') specifications."
739 ;; Regular test.
740 (should
741 (equal "Para\ngraph"
742 (org-test-with-temp-text "Para<point>graph"
743 (org-return)
744 (buffer-string))))
745 ;; With optional argument, indent line.
746 (should
747 (equal " Para\n graph"
748 (org-test-with-temp-text " Para<point>graph"
749 (org-return t)
750 (buffer-string))))
751 ;; On a table, call `org-table-next-row'.
752 (should
753 (org-test-with-temp-text "| <point>a |\n| b |"
754 (org-return)
755 (org-looking-at-p "b")))
756 ;; Open link or timestamp under point when `org-return-follows-link'
757 ;; is non-nil.
758 (should
759 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
760 (let ((org-return-follows-link t)) (org-return))
761 (org-looking-at-p "<<target>>")))
762 (should-not
763 (org-test-with-temp-text "Link [[target<point>]] <<target>>"
764 (let ((org-return-follows-link nil)) (org-return))
765 (org-looking-at-p "<<target>>")))
766 ;; However, do not open link when point is in a table.
767 (should
768 (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
769 (let ((org-return-follows-link t)) (org-return))
770 (org-looking-at-p "between")))
771 ;; Special case: in a list, when indenting, do not break structure.
772 (should
773 (equal "- A\n B"
774 (org-test-with-temp-text "- A <point>B"
775 (org-return t)
776 (buffer-string))))
777 ;; Special case: on tags part of a headline, add a newline below it
778 ;; instead of breaking it.
779 (should
780 (equal "* H :tag:\n"
781 (org-test-with-temp-text "* H :<point>tag:"
782 (org-return)
783 (buffer-string)))))
785 (ert-deftest test-org/meta-return ()
786 "Test M-RET (`org-meta-return') specifications."
787 ;; In a table field insert a row above.
788 (should
789 (org-test-with-temp-text "| a |"
790 (forward-char)
791 (org-meta-return)
792 (forward-line -1)
793 (looking-at "| |$")))
794 ;; In a paragraph change current line into a header.
795 (should
796 (org-test-with-temp-text "a"
797 (org-meta-return)
798 (beginning-of-line)
799 (looking-at "\* a$")))
800 ;; In an item insert an item, in this case above.
801 (should
802 (org-test-with-temp-text "- a"
803 (org-meta-return)
804 (beginning-of-line)
805 (looking-at "- $")))
806 ;; In a drawer and item insert an item, in this case above.
807 (should
808 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
809 (forward-line)
810 (org-meta-return)
811 (beginning-of-line)
812 (looking-at "- $"))))
814 (ert-deftest test-org/insert-heading ()
815 "Test `org-insert-heading' specifications."
816 ;; FIXME: Test coverage is incomplete yet.
818 ;; In an empty buffer, insert a new headline.
819 (should
820 (equal "* "
821 (org-test-with-temp-text ""
822 (org-insert-heading)
823 (buffer-string))))
824 ;; At the beginning of a line, turn it into a headline
825 (should
826 (equal "* P"
827 (org-test-with-temp-text "<point>P"
828 (org-insert-heading)
829 (buffer-string))))
830 ;; In the middle of a line, split the line if allowed, otherwise,
831 ;; insert the headline at its end.
832 (should
833 (equal "Para\n* graph"
834 (org-test-with-temp-text "Para<point>graph"
835 (let ((org-M-RET-may-split-line '((default . t))))
836 (org-insert-heading))
837 (buffer-string))))
838 (should
839 (equal "Paragraph\n* "
840 (org-test-with-temp-text "Para<point>graph"
841 (let ((org-M-RET-may-split-line '((default . nil))))
842 (org-insert-heading))
843 (buffer-string))))
844 ;; When on a list, insert an item instead, unless called with an
845 ;; universal argument or if list is invisible. In this case, create
846 ;; a new headline after contents.
847 (should
848 (equal "* H\n- item\n- "
849 (org-test-with-temp-text "* H\n- item<point>"
850 (let ((org-insert-heading-respect-content nil))
851 (org-insert-heading))
852 (buffer-string))))
853 (should
854 (equal "* H\n- item\n- item 2\n* "
855 (org-test-with-temp-text "* H\n- item<point>\n- item 2"
856 (let ((org-insert-heading-respect-content nil))
857 (org-insert-heading '(4)))
858 (buffer-string))))
859 (should
860 (equal "* H\n- item\n* "
861 (org-test-with-temp-text "* H\n- item"
862 (org-cycle)
863 (goto-char (point-max))
864 (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
865 (buffer-string))))
866 ;; When called with two universal arguments, insert a new headline
867 ;; at the end of the grandparent subtree.
868 (should
869 (equal "* H1\n** H3\n- item\n** H2\n** "
870 (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
871 (let ((org-insert-heading-respect-content nil))
872 (org-insert-heading '(16)))
873 (buffer-string))))
874 ;; Corner case: correctly insert a headline after an empty one.
875 (should
876 (equal "* \n* "
877 (org-test-with-temp-text "* <point>"
878 (org-insert-heading)
879 (buffer-string)))))
881 (ert-deftest test-org/insert-todo-heading-respect-content ()
882 "Test `org-insert-todo-heading-respect-content' specifications."
883 ;; Create a TODO heading.
884 (should
885 (org-test-with-temp-text "* H1\n Body"
886 (org-insert-todo-heading-respect-content)
887 (nth 2 (org-heading-components))))
888 ;; Add headline at the end of the first subtree
889 (should
890 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
891 (search-forward "H1Body")
892 (org-insert-todo-heading-respect-content)
893 (and (eobp) (org-at-heading-p))))
894 ;; In a list, do not create a new item.
895 (should
896 (org-test-with-temp-text "* H\n- an item\n- another one"
897 (search-forward "an ")
898 (org-insert-todo-heading-respect-content)
899 (and (eobp) (org-at-heading-p)))))
903 ;;; Fixed-Width Areas
905 (ert-deftest test-org/toggle-fixed-width ()
906 "Test `org-toggle-fixed-width' specifications."
907 ;; No region: Toggle on fixed-width marker in paragraphs.
908 (should
909 (equal ": A"
910 (org-test-with-temp-text "A"
911 (org-toggle-fixed-width)
912 (buffer-string))))
913 ;; No region: Toggle off fixed-width markers in fixed-width areas.
914 (should
915 (equal "A"
916 (org-test-with-temp-text ": A"
917 (org-toggle-fixed-width)
918 (buffer-string))))
919 ;; No region: Toggle on marker in blank lines after elements or just
920 ;; after a headline.
921 (should
922 (equal "* H\n: "
923 (org-test-with-temp-text "* H\n"
924 (forward-line)
925 (org-toggle-fixed-width)
926 (buffer-string))))
927 (should
928 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
929 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
930 (goto-char (point-max))
931 (org-toggle-fixed-width)
932 (buffer-string))))
933 ;; No region: Toggle on marker in front of one line elements (e.g.,
934 ;; headlines, clocks)
935 (should
936 (equal ": * Headline"
937 (org-test-with-temp-text "* Headline"
938 (org-toggle-fixed-width)
939 (buffer-string))))
940 (should
941 (equal ": #+KEYWORD: value"
942 (org-test-with-temp-text "#+KEYWORD: value"
943 (org-toggle-fixed-width)
944 (buffer-string))))
945 ;; No region: error in other situations.
946 (should-error
947 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
948 (forward-line)
949 (org-toggle-fixed-width)
950 (buffer-string)))
951 ;; No region: Indentation is preserved.
952 (should
953 (equal "- A\n : B"
954 (org-test-with-temp-text "- A\n B"
955 (forward-line)
956 (org-toggle-fixed-width)
957 (buffer-string))))
958 ;; Region: If it contains only fixed-width elements and blank lines,
959 ;; toggle off fixed-width markup.
960 (should
961 (equal "A\n\nB"
962 (org-test-with-temp-text ": A\n\n: B"
963 (transient-mark-mode 1)
964 (push-mark (point) t t)
965 (goto-char (point-max))
966 (org-toggle-fixed-width)
967 (buffer-string))))
968 ;; Region: If it contains anything else, toggle on fixed-width but
969 ;; not on fixed-width areas.
970 (should
971 (equal ": A\n: \n: B\n: \n: C"
972 (org-test-with-temp-text "A\n\n: B\n\nC"
973 (transient-mark-mode 1)
974 (push-mark (point) t t)
975 (goto-char (point-max))
976 (org-toggle-fixed-width)
977 (buffer-string))))
978 ;; Region: Ignore blank lines at its end, unless it contains only
979 ;; such lines.
980 (should
981 (equal ": A\n\n"
982 (org-test-with-temp-text "A\n\n"
983 (transient-mark-mode 1)
984 (push-mark (point) t t)
985 (goto-char (point-max))
986 (org-toggle-fixed-width)
987 (buffer-string))))
988 (should
989 (equal ": \n: \n"
990 (org-test-with-temp-text "\n\n"
991 (transient-mark-mode 1)
992 (push-mark (point) t t)
993 (goto-char (point-max))
994 (org-toggle-fixed-width)
995 (buffer-string)))))
999 ;;; Headline
1001 (ert-deftest test-org/in-commented-heading-p ()
1002 "Test `org-in-commented-heading-p' specifications."
1003 ;; Commented headline.
1004 (should
1005 (org-test-with-temp-text "* COMMENT Headline\nBody"
1006 (goto-char (point-max))
1007 (org-in-commented-heading-p)))
1008 ;; Commented ancestor.
1009 (should
1010 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1011 (goto-char (point-max))
1012 (org-in-commented-heading-p)))
1013 ;; Comment keyword is case-sensitive.
1014 (should-not
1015 (org-test-with-temp-text "* Comment Headline\nBody"
1016 (goto-char (point-max))
1017 (org-in-commented-heading-p)))
1018 ;; Keyword is standalone.
1019 (should-not
1020 (org-test-with-temp-text "* COMMENTHeadline\nBody"
1021 (goto-char (point-max))
1022 (org-in-commented-heading-p)))
1023 ;; Optional argument.
1024 (should-not
1025 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
1026 (goto-char (point-max))
1027 (org-in-commented-heading-p t))))
1031 ;;; Keywords
1033 (ert-deftest test-org/set-regexps-and-options ()
1034 "Test `org-set-regexps-and-options' specifications."
1035 ;; TAGS keyword.
1036 (should
1037 (equal '(("A" . ?a) ("B") ("C"))
1038 (org-test-with-temp-text "#+TAGS: A(a) B C"
1039 (org-mode-restart)
1040 org-tag-alist)))
1041 (should
1042 (equal '(("A") (:newline) ("B"))
1043 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
1044 (org-mode-restart)
1045 org-tag-alist)))
1046 (should
1047 (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
1048 (org-test-with-temp-text "#+TAGS: { A B } C"
1049 (org-mode-restart)
1050 org-tag-alist)))
1051 (should
1052 (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
1053 (org-test-with-temp-text "#+TAGS: { A : B C }"
1054 (org-mode-restart)
1055 org-tag-alist)))
1056 (should
1057 (equal '(("A" "B" "C"))
1058 (org-test-with-temp-text "#+TAGS: { A : B C }"
1059 (org-mode-restart)
1060 org-tag-groups-alist)))
1061 ;; FILETAGS keyword.
1062 (should
1063 (equal '("A" "B" "C")
1064 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
1065 (org-mode-restart)
1066 org-file-tags)))
1067 ;; PROPERTY keyword. Property names are case-insensitive.
1068 (should
1069 (equal "foo=1"
1070 (org-test-with-temp-text "#+PROPERTY: var foo=1"
1071 (org-mode-restart)
1072 (cdr (assoc "var" org-file-properties)))))
1073 (should
1074 (equal
1075 "foo=1 bar=2"
1076 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1077 (org-mode-restart)
1078 (cdr (assoc "var" org-file-properties)))))
1079 (should
1080 (equal
1081 "foo=1 bar=2"
1082 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1083 (org-mode-restart)
1084 (cdr (assoc "var" org-file-properties)))))
1085 ;; ARCHIVE keyword.
1086 (should
1087 (equal "%s_done::"
1088 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1089 (org-mode-restart)
1090 org-archive-location)))
1091 ;; CATEGORY keyword.
1092 (should
1093 (eq 'test
1094 (org-test-with-temp-text "#+CATEGORY: test"
1095 (org-mode-restart)
1096 org-category)))
1097 (should
1098 (equal "test"
1099 (org-test-with-temp-text "#+CATEGORY: test"
1100 (org-mode-restart)
1101 (cdr (assoc "CATEGORY" org-file-properties)))))
1102 ;; COLUMNS keyword.
1103 (should
1104 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1105 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1106 (org-mode-restart)
1107 org-columns-default-format)))
1108 ;; CONSTANTS keyword. Constants names are case sensitive.
1109 (should
1110 (equal '("299792458." "3.14")
1111 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1112 (org-mode-restart)
1113 (mapcar
1114 (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
1115 '("c" "pi")))))
1116 (should
1117 (equal "3.14"
1118 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1119 (org-mode-restart)
1120 (cdr (assoc "pi" org-table-formula-constants-local)))))
1121 (should
1122 (equal "22/7"
1123 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1124 (org-mode-restart)
1125 (cdr (assoc "PI" org-table-formula-constants-local)))))
1126 ;; LINK keyword.
1127 (should
1128 (equal
1129 '("url1" "url2")
1130 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1131 (org-mode-restart)
1132 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
1133 '("a" "b")))))
1134 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1135 (should
1136 (equal
1137 '(?X ?Z ?Y)
1138 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1139 (org-mode-restart)
1140 (list org-highest-priority org-lowest-priority org-default-priority))))
1141 (should
1142 (equal
1143 '(?A ?C ?B)
1144 (org-test-with-temp-text "#+PRIORITIES: X Z"
1145 (org-mode-restart)
1146 (list org-highest-priority org-lowest-priority org-default-priority))))
1147 ;; STARTUP keyword.
1148 (should
1149 (equal '(t t)
1150 (org-test-with-temp-text "#+STARTUP: fold odd"
1151 (org-mode-restart)
1152 (list org-startup-folded org-odd-levels-only))))
1153 ;; TODO keywords.
1154 (should
1155 (equal '(("A" "B") ("C"))
1156 (org-test-with-temp-text "#+TODO: A B | C"
1157 (org-mode-restart)
1158 (list org-not-done-keywords org-done-keywords))))
1159 (should
1160 (equal '(("A" "C") ("B" "D"))
1161 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1162 (org-mode-restart)
1163 (list org-not-done-keywords org-done-keywords))))
1164 (should
1165 (equal '(("A" "B") ("C"))
1166 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1167 (org-mode-restart)
1168 (list org-not-done-keywords org-done-keywords))))
1169 (should
1170 (equal '((:startgroup) ("A" . ?a) (:endgroup))
1171 (org-test-with-temp-text "#+TODO: A(a)"
1172 (org-mode-restart)
1173 org-todo-key-alist)))
1174 (should
1175 (equal '(("D" note nil) ("C" time nil) ("B" note time))
1176 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1177 (org-mode-restart)
1178 org-todo-log-states)))
1179 ;; Enter SETUPFILE keyword.
1180 (should
1181 (equal "1"
1182 (org-test-with-temp-text
1183 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
1184 (org-mode-restart)
1185 (cdr (assoc "a" org-file-properties))))))
1189 ;;; Links
1191 ;;;; Coderefs
1193 (ert-deftest test-org/coderef ()
1194 "Test coderef links specifications."
1195 (should
1196 (org-test-with-temp-text "
1197 #+BEGIN_SRC emacs-lisp
1198 \(+ 1 1) (ref:sc)
1199 #+END_SRC
1200 \[[(sc)]]"
1201 (goto-char (point-max))
1202 (org-open-at-point)
1203 (looking-at "(ref:sc)"))))
1205 ;;;; Custom ID
1207 (ert-deftest test-org/custom-id ()
1208 "Test custom ID links specifications."
1209 (should
1210 (org-test-with-temp-text
1211 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1212 (goto-char (point-max))
1213 (org-open-at-point)
1214 (org-looking-at-p "\\* H1"))))
1216 ;;;; Fuzzy Links
1218 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1219 ;; a named element (#+name: text) and to headlines (* Text).
1221 (ert-deftest test-org/fuzzy-links ()
1222 "Test fuzzy links specifications."
1223 ;; Fuzzy link goes in priority to a matching target.
1224 (should
1225 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1226 (goto-line 5)
1227 (org-open-at-point)
1228 (looking-at "<<Test>>")))
1229 ;; Then fuzzy link points to an element with a given name.
1230 (should
1231 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1232 (goto-line 5)
1233 (org-open-at-point)
1234 (looking-at "#\\+NAME: Test")))
1235 ;; A target still lead to a matching headline otherwise.
1236 (should
1237 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1238 (goto-line 4)
1239 (org-open-at-point)
1240 (looking-at "\\* Head2")))
1241 ;; With a leading star in link, enforce heading match.
1242 (should
1243 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1244 (goto-line 3)
1245 (org-open-at-point)
1246 (looking-at "\\* Test")))
1247 ;; Correctly un-hexify fuzzy links.
1248 (should
1249 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1250 (goto-char (point-max))
1251 (org-open-at-point)
1252 (bobp))))
1254 ;;;; Link Escaping
1256 (ert-deftest test-org/org-link-escape-ascii-character ()
1257 "Escape an ascii character."
1258 (should
1259 (string=
1260 "%5B"
1261 (org-link-escape "["))))
1263 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
1264 "Escape an ascii control character."
1265 (should
1266 (string=
1267 "%09"
1268 (org-link-escape "\t"))))
1270 (ert-deftest test-org/org-link-escape-multibyte-character ()
1271 "Escape an unicode multibyte character."
1272 (should
1273 (string=
1274 "%E2%82%AC"
1275 (org-link-escape "€"))))
1277 (ert-deftest test-org/org-link-escape-custom-table ()
1278 "Escape string with custom character table."
1279 (should
1280 (string=
1281 "Foo%3A%42ar%0A"
1282 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
1284 (ert-deftest test-org/org-link-escape-custom-table-merge ()
1285 "Escape string with custom table merged with default table."
1286 (should
1287 (string=
1288 "%5BF%6F%6F%3A%42ar%0A%5D"
1289 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
1291 (ert-deftest test-org/org-link-unescape-ascii-character ()
1292 "Unescape an ascii character."
1293 (should
1294 (string=
1296 (org-link-unescape "%5B"))))
1298 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
1299 "Unescpae an ascii control character."
1300 (should
1301 (string=
1302 "\n"
1303 (org-link-unescape "%0A"))))
1305 (ert-deftest test-org/org-link-unescape-multibyte-character ()
1306 "Unescape unicode multibyte character."
1307 (should
1308 (string=
1309 "€"
1310 (org-link-unescape "%E2%82%AC"))))
1312 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
1313 "Unescape old style percent escaped character."
1314 (should
1315 (string=
1316 "àâçèéêîôùû"
1317 (decode-coding-string
1318 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
1320 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
1321 "Escape and unescape a URL that includes an escaped char.
1322 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1323 (should
1324 (string=
1325 "http://some.host.com/form?&id=blah%2Bblah25"
1326 (org-link-unescape
1327 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1329 (ert-deftest test-org/org-link-escape-chars-browser ()
1330 "Test of the constant `org-link-escape-chars-browser'.
1331 See there why this test is a candidate to be removed once Org
1332 drops support for Emacs 24.1 and 24.2."
1333 (should
1334 (string=
1335 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1336 "%22Release%208.2%22&idxname=emacs-orgmode")
1337 (org-link-escape-browser ; Do not replace with `url-encode-url',
1338 ; see docstring above.
1339 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1340 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1342 ;;;; Open at point
1344 (ert-deftest test-org/open-at-point-in-property ()
1345 "Does `org-open-at-point' open link in property drawer?"
1346 (should
1347 (org-test-with-temp-text
1348 "* Headline
1349 :PROPERTIES:
1350 :URL: <point>[[info:emacs#Top]]
1351 :END:"
1352 (org-open-at-point) t)))
1354 (ert-deftest test-org/open-at-point-in-comment ()
1355 "Does `org-open-at-point' open link in a commented line?"
1356 (should
1357 (org-test-with-temp-text
1358 "# <point>[[info:emacs#Top]]"
1359 (org-open-at-point) t)))
1361 (ert-deftest test-org/open-at-point/info ()
1362 "Test `org-open-at-point' on info links."
1363 (should
1364 (org-test-with-temp-text
1365 "<point>[[info:emacs#Top]]"
1366 (org-open-at-point)
1367 (and (switch-to-buffer "*info*")
1368 (prog1
1369 (looking-at "\nThe Emacs Editor")
1370 (kill-buffer))))))
1373 ;;; Node Properties
1375 (ert-deftest test-org/accumulated-properties-in-drawers ()
1376 "Ensure properties accumulate in subtree drawers."
1377 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1378 (org-babel-next-src-block)
1379 (should (equal '(2 1) (org-babel-execute-src-block)))))
1381 (ert-deftest test-org/custom-properties ()
1382 "Test custom properties specifications."
1383 ;; Standard test.
1384 (should
1385 (let ((org-custom-properties '("FOO")))
1386 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1387 (org-toggle-custom-properties-visibility)
1388 (org-invisible-p2))))
1389 ;; Properties are case-insensitive.
1390 (should
1391 (let ((org-custom-properties '("FOO")))
1392 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1393 (org-toggle-custom-properties-visibility)
1394 (org-invisible-p2))))
1395 (should
1396 (let ((org-custom-properties '("foo")))
1397 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1398 (org-toggle-custom-properties-visibility)
1399 (org-invisible-p2))))
1400 ;; Multiple custom properties in the same drawer.
1401 (should
1402 (let ((org-custom-properties '("FOO" "BAR")))
1403 (org-test-with-temp-text
1404 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1405 (org-toggle-custom-properties-visibility)
1406 (and (org-invisible-p2)
1407 (not (progn (forward-line) (org-invisible-p2)))
1408 (progn (forward-line) (org-invisible-p2))))))
1409 ;; Hide custom properties with an empty value.
1410 (should
1411 (let ((org-custom-properties '("FOO")))
1412 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1413 (org-toggle-custom-properties-visibility)
1414 (org-invisible-p2))))
1415 ;; Do not hide fake properties.
1416 (should-not
1417 (let ((org-custom-properties '("FOO")))
1418 (org-test-with-temp-text ":FOO: val\n"
1419 (org-toggle-custom-properties-visibility)
1420 (org-invisible-p2))))
1421 (should-not
1422 (let ((org-custom-properties '("A")))
1423 (org-test-with-temp-text
1424 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1425 (org-toggle-custom-properties-visibility)
1426 (org-invisible-p2)))))
1430 ;;; Mark Region
1432 (ert-deftest test-org/mark-subtree ()
1433 "Test `org-mark-subtree' specifications."
1434 ;; Error when point is before first headline.
1435 (should-error
1436 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1437 (progn (transient-mark-mode 1)
1438 (org-mark-subtree))))
1439 ;; Without argument, mark current subtree.
1440 (should
1441 (equal
1442 '(12 32)
1443 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1444 (progn (transient-mark-mode 1)
1445 (forward-line 2)
1446 (org-mark-subtree)
1447 (list (region-beginning) (region-end))))))
1448 ;; With an argument, move ARG up.
1449 (should
1450 (equal
1451 '(1 32)
1452 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1453 (progn (transient-mark-mode 1)
1454 (forward-line 2)
1455 (org-mark-subtree 1)
1456 (list (region-beginning) (region-end))))))
1457 ;; Do not get fooled by inlinetasks.
1458 (when (featurep 'org-inlinetask)
1459 (should
1460 (= 1
1461 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1462 (progn (transient-mark-mode 1)
1463 (forward-line 1)
1464 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1465 (region-beginning)))))))
1469 ;;; Navigation
1471 (ert-deftest test-org/beginning-of-line ()
1472 "Test `org-beginning-of-line' specifications."
1473 ;; Standard test.
1474 (should
1475 (org-test-with-temp-text "Some text\nSome other text"
1476 (progn (org-beginning-of-line) (bolp))))
1477 ;; Standard test with `visual-line-mode'.
1478 (should-not
1479 (org-test-with-temp-text "A long line of text\nSome other text"
1480 (progn (visual-line-mode)
1481 (forward-char 2)
1482 (dotimes (i 1000) (insert "very "))
1483 (org-beginning-of-line)
1484 (bolp))))
1485 ;; At an headline with special movement.
1486 (should
1487 (org-test-with-temp-text "* TODO Headline"
1488 (let ((org-special-ctrl-a/e t))
1489 (org-end-of-line)
1490 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1491 (progn (org-beginning-of-line) (bolp))
1492 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1494 (ert-deftest test-org/end-of-line ()
1495 "Test `org-end-of-line' specifications."
1496 ;; Standard test.
1497 (should
1498 (org-test-with-temp-text "Some text\nSome other text"
1499 (progn (org-end-of-line) (eolp))))
1500 ;; Standard test with `visual-line-mode'.
1501 (should-not
1502 (org-test-with-temp-text "A long line of text\nSome other text"
1503 (progn (visual-line-mode)
1504 (forward-char 2)
1505 (dotimes (i 1000) (insert "very "))
1506 (goto-char (point-min))
1507 (org-end-of-line)
1508 (eolp))))
1509 ;; At an headline with special movement.
1510 (should
1511 (org-test-with-temp-text "* Headline1 :tag:\n"
1512 (let ((org-special-ctrl-a/e t))
1513 (and (progn (org-end-of-line) (looking-at " :tag:"))
1514 (progn (org-end-of-line) (eolp))
1515 (progn (org-end-of-line) (looking-at " :tag:"))))))
1516 ;; At an headline without special movement.
1517 (should
1518 (org-test-with-temp-text "* Headline2 :tag:\n"
1519 (let ((org-special-ctrl-a/e nil))
1520 (and (progn (org-end-of-line) (eolp))
1521 (progn (org-end-of-line) (eolp))))))
1522 ;; At an headline, with reversed movement.
1523 (should
1524 (org-test-with-temp-text "* Headline3 :tag:\n"
1525 (let ((org-special-ctrl-a/e 'reversed)
1526 (this-command last-command))
1527 (and (progn (org-end-of-line) (eolp))
1528 (progn (org-end-of-line) (looking-at " :tag:"))))))
1529 ;; At a block without hidden contents.
1530 (should
1531 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1532 (progn (org-end-of-line) (eolp))))
1533 ;; At a block with hidden contents.
1534 (should-not
1535 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1536 (let ((org-special-ctrl-a/e t))
1537 (org-hide-block-toggle)
1538 (org-end-of-line)
1539 (eobp)))))
1541 (ert-deftest test-org/forward-paragraph ()
1542 "Test `org-forward-paragraph' specifications."
1543 ;; At end of buffer, return an error.
1544 (should-error
1545 (org-test-with-temp-text "Paragraph"
1546 (goto-char (point-max))
1547 (org-forward-paragraph)))
1548 ;; Standard test.
1549 (should
1550 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1551 (org-forward-paragraph)
1552 (looking-at "P2")))
1553 ;; Ignore depth.
1554 (should
1555 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1556 (org-forward-paragraph)
1557 (looking-at "P1")))
1558 ;; Do not enter elements with invisible contents.
1559 (should
1560 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1561 (org-hide-block-toggle)
1562 (org-forward-paragraph)
1563 (looking-at "P3")))
1564 ;; On an affiliated keyword, jump to the beginning of the element.
1565 (should
1566 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1567 (org-forward-paragraph)
1568 (looking-at "Para")))
1569 ;; On an item or a footnote definition, move to the second element
1570 ;; inside, if any.
1571 (should
1572 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1573 (org-forward-paragraph)
1574 (looking-at " Paragraph")))
1575 (should
1576 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1577 (org-forward-paragraph)
1578 (looking-at "Paragraph")))
1579 ;; On an item, or a footnote definition, when the first line is
1580 ;; empty, move to the first item.
1581 (should
1582 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1583 (org-forward-paragraph)
1584 (looking-at " Paragraph")))
1585 (should
1586 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1587 (org-forward-paragraph)
1588 (looking-at "Paragraph")))
1589 ;; On a table (resp. a property drawer) do not move through table
1590 ;; rows (resp. node properties).
1591 (should
1592 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1593 (org-forward-paragraph)
1594 (looking-at "Paragraph")))
1595 (should
1596 (org-test-with-temp-text
1597 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1598 (org-forward-paragraph)
1599 (looking-at "Paragraph")))
1600 ;; On a verse or source block, stop after blank lines.
1601 (should
1602 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1603 (org-forward-paragraph)
1604 (looking-at "L2")))
1605 (should
1606 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1607 (org-forward-paragraph)
1608 (looking-at "L2"))))
1610 (ert-deftest test-org/backward-paragraph ()
1611 "Test `org-backward-paragraph' specifications."
1612 ;; Error at beginning of buffer.
1613 (should-error
1614 (org-test-with-temp-text "Paragraph"
1615 (org-backward-paragraph)))
1616 ;; Regular test.
1617 (should
1618 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1619 (goto-char (point-max))
1620 (org-backward-paragraph)
1621 (looking-at "P3")))
1622 (should
1623 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1624 (goto-char (point-max))
1625 (beginning-of-line)
1626 (org-backward-paragraph)
1627 (looking-at "P2")))
1628 ;; Ignore depth.
1629 (should
1630 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1631 (goto-char (point-max))
1632 (beginning-of-line)
1633 (org-backward-paragraph)
1634 (looking-at "P2")))
1635 ;; Ignore invisible elements.
1636 (should
1637 (org-test-with-temp-text "* H1\n P1\n* H2"
1638 (org-cycle)
1639 (goto-char (point-max))
1640 (beginning-of-line)
1641 (org-backward-paragraph)
1642 (bobp)))
1643 ;; On an affiliated keyword, jump to the first one.
1644 (should
1645 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1646 (search-forward "c2")
1647 (org-backward-paragraph)
1648 (looking-at "#\\+name")))
1649 ;; On the second element in an item or a footnote definition, jump
1650 ;; to item or the definition.
1651 (should
1652 (org-test-with-temp-text "- line1\n\n line2"
1653 (goto-char (point-max))
1654 (beginning-of-line)
1655 (org-backward-paragraph)
1656 (looking-at "- line1")))
1657 (should
1658 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1659 (goto-char (point-max))
1660 (beginning-of-line)
1661 (org-backward-paragraph)
1662 (looking-at "\\[fn:1\\] line1")))
1663 ;; On a table (resp. a property drawer), ignore table rows
1664 ;; (resp. node properties).
1665 (should
1666 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1667 (goto-char (point-max))
1668 (beginning-of-line)
1669 (org-backward-paragraph)
1670 (bobp)))
1671 (should
1672 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1673 (org-backward-paragraph)
1674 (looking-at ":PROPERTIES:")))
1675 ;; On a source or verse block, stop before blank lines.
1676 (should
1677 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1678 (search-forward "L3")
1679 (beginning-of-line)
1680 (org-backward-paragraph)
1681 (looking-at "L2")))
1682 (should
1683 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1684 (search-forward "L3")
1685 (beginning-of-line)
1686 (org-backward-paragraph)
1687 (looking-at "L2"))))
1689 (ert-deftest test-org/forward-element ()
1690 "Test `org-forward-element' specifications."
1691 ;; 1. At EOB: should error.
1692 (org-test-with-temp-text "Some text\n"
1693 (goto-char (point-max))
1694 (should-error (org-forward-element)))
1695 ;; 2. Standard move: expected to ignore blank lines.
1696 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1697 (org-forward-element)
1698 (should (looking-at (regexp-quote "Second paragraph."))))
1699 ;; 3. Headline tests.
1700 (org-test-with-temp-text "
1701 * Head 1
1702 ** Head 1.1
1703 *** Head 1.1.1
1704 ** Head 1.2"
1705 ;; 3.1. At an headline beginning: move to next headline at the
1706 ;; same level.
1707 (goto-line 3)
1708 (org-forward-element)
1709 (should (looking-at (regexp-quote "** Head 1.2")))
1710 ;; 3.2. At an headline beginning: move to parent headline if no
1711 ;; headline at the same level.
1712 (goto-line 3)
1713 (org-forward-element)
1714 (should (looking-at (regexp-quote "** Head 1.2"))))
1715 ;; 4. Greater element tests.
1716 (org-test-with-temp-text
1717 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1718 ;; 4.1. At a greater element: expected to skip contents.
1719 (org-forward-element)
1720 (should (looking-at (regexp-quote "Outside.")))
1721 ;; 4.2. At the end of greater element contents: expected to skip
1722 ;; to the end of the greater element.
1723 (goto-line 2)
1724 (org-forward-element)
1725 (should (looking-at (regexp-quote "Outside."))))
1726 ;; 5. List tests.
1727 (org-test-with-temp-text "
1728 - item1
1730 - sub1
1732 - sub2
1734 - sub3
1736 Inner paragraph.
1738 - item2
1740 Outside."
1741 ;; 5.1. At list top point: expected to move to the element after
1742 ;; the list.
1743 (goto-line 2)
1744 (org-forward-element)
1745 (should (looking-at (regexp-quote "Outside.")))
1746 ;; 5.2. Special case: at the first line of a sub-list, but not at
1747 ;; beginning of line, move to next item.
1748 (goto-line 2)
1749 (forward-char)
1750 (org-forward-element)
1751 (should (looking-at "- item2"))
1752 (goto-line 4)
1753 (forward-char)
1754 (org-forward-element)
1755 (should (looking-at " - sub2"))
1756 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1757 (goto-line 4)
1758 (org-forward-element)
1759 (should (looking-at (regexp-quote " Inner paragraph.")))
1760 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1761 (goto-line 8)
1762 (org-forward-element)
1763 (should (looking-at (regexp-quote " Inner paragraph.")))
1764 ;; 5.5. At an item: expected to move to next item, if any.
1765 (goto-line 6)
1766 (org-forward-element)
1767 (should (looking-at " - sub3"))))
1769 (ert-deftest test-org/backward-element ()
1770 "Test `org-backward-element' specifications."
1771 ;; 1. Should error at BOB.
1772 (org-test-with-temp-text " \nParagraph."
1773 (should-error (org-backward-element)))
1774 ;; 2. Should move at BOB when called on the first element in buffer.
1775 (should
1776 (org-test-with-temp-text "\n#+TITLE: test"
1777 (progn (forward-line)
1778 (org-backward-element)
1779 (bobp))))
1780 ;; 3. Not at the beginning of an element: move at its beginning.
1781 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1782 (goto-line 3)
1783 (end-of-line)
1784 (org-backward-element)
1785 (should (looking-at (regexp-quote "Paragraph2."))))
1786 ;; 4. Headline tests.
1787 (org-test-with-temp-text "
1788 * Head 1
1789 ** Head 1.1
1790 *** Head 1.1.1
1791 ** Head 1.2"
1792 ;; 4.1. At an headline beginning: move to previous headline at the
1793 ;; same level.
1794 (goto-line 5)
1795 (org-backward-element)
1796 (should (looking-at (regexp-quote "** Head 1.1")))
1797 ;; 4.2. At an headline beginning: move to parent headline if no
1798 ;; headline at the same level.
1799 (goto-line 3)
1800 (org-backward-element)
1801 (should (looking-at (regexp-quote "* Head 1")))
1802 ;; 4.3. At the first top-level headline: should error.
1803 (goto-line 2)
1804 (should-error (org-backward-element)))
1805 ;; 5. At beginning of first element inside a greater element:
1806 ;; expected to move to greater element's beginning.
1807 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1808 (goto-line 3)
1809 (org-backward-element)
1810 (should (looking-at "#\\+BEGIN_CENTER")))
1811 ;; 6. At the beginning of the first element in a section: should
1812 ;; move back to headline, if any.
1813 (should
1814 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1815 (progn (goto-char (point-max))
1816 (beginning-of-line)
1817 (org-backward-element)
1818 (org-at-heading-p))))
1819 ;; 7. List tests.
1820 (org-test-with-temp-text "
1821 - item1
1823 - sub1
1825 - sub2
1827 - sub3
1829 Inner paragraph.
1831 - item2
1834 Outside."
1835 ;; 7.1. At beginning of sub-list: expected to move to the
1836 ;; paragraph before it.
1837 (goto-line 4)
1838 (org-backward-element)
1839 (should (looking-at "item1"))
1840 ;; 7.2. At an item in a list: expected to move at previous item.
1841 (goto-line 8)
1842 (org-backward-element)
1843 (should (looking-at " - sub2"))
1844 (goto-line 12)
1845 (org-backward-element)
1846 (should (looking-at "- item1"))
1847 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1848 ;; beginning.
1849 (goto-line 10)
1850 (org-backward-element)
1851 (should (looking-at " - sub1"))
1852 (goto-line 15)
1853 (org-backward-element)
1854 (should (looking-at "- item1"))
1855 ;; 7.4. At blank-lines before list end: expected to move to top
1856 ;; item.
1857 (goto-line 14)
1858 (org-backward-element)
1859 (should (looking-at "- item1"))))
1861 (ert-deftest test-org/up-element ()
1862 "Test `org-up-element' specifications."
1863 ;; 1. At BOB or with no surrounding element: should error.
1864 (org-test-with-temp-text "Paragraph."
1865 (should-error (org-up-element)))
1866 (org-test-with-temp-text "* Head1\n* Head2"
1867 (goto-line 2)
1868 (should-error (org-up-element)))
1869 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1870 (goto-line 3)
1871 (should-error (org-up-element)))
1872 ;; 2. At an headline: move to parent headline.
1873 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1874 (goto-line 3)
1875 (org-up-element)
1876 (should (looking-at "\\* Head1")))
1877 ;; 3. Inside a greater element: move to greater element beginning.
1878 (org-test-with-temp-text
1879 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1880 (goto-line 3)
1881 (org-up-element)
1882 (should (looking-at "#\\+BEGIN_CENTER")))
1883 ;; 4. List tests.
1884 (org-test-with-temp-text "* Top
1885 - item1
1887 - sub1
1889 - sub2
1891 Paragraph within sub2.
1893 - item2"
1894 ;; 4.1. Within an item: move to the item beginning.
1895 (goto-line 8)
1896 (org-up-element)
1897 (should (looking-at " - sub2"))
1898 ;; 4.2. At an item in a sub-list: move to parent item.
1899 (goto-line 4)
1900 (org-up-element)
1901 (should (looking-at "- item1"))
1902 ;; 4.3. At an item in top list: move to beginning of whole list.
1903 (goto-line 10)
1904 (org-up-element)
1905 (should (looking-at "- item1"))
1906 ;; 4.4. Special case. At very top point: should move to parent of
1907 ;; list.
1908 (goto-line 2)
1909 (org-up-element)
1910 (should (looking-at "\\* Top"))))
1912 (ert-deftest test-org/down-element ()
1913 "Test `org-down-element' specifications."
1914 ;; Error when the element hasn't got a recursive type.
1915 (org-test-with-temp-text "Paragraph."
1916 (should-error (org-down-element)))
1917 ;; Error when the element has no contents
1918 (org-test-with-temp-text "* Headline"
1919 (should-error (org-down-element)))
1920 ;; When at a plain-list, move to first item.
1921 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1922 (goto-line 2)
1923 (org-down-element)
1924 (should (looking-at " - Item 1.1")))
1925 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1926 (org-down-element)
1927 (should (looking-at " Item 1")))
1928 ;; When at a table, move to first row
1929 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1930 (org-down-element)
1931 (should (looking-at " a | b |")))
1932 ;; Otherwise, move inside the greater element.
1933 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1934 (org-down-element)
1935 (should (looking-at "Paragraph"))))
1937 (ert-deftest test-org/drag-element-backward ()
1938 "Test `org-drag-element-backward' specifications."
1939 ;; Standard test.
1940 (should
1941 (equal
1942 "#+key2: val2\n#+key1: val1\n#+key3: val3"
1943 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
1944 (org-drag-element-backward)
1945 (buffer-string))))
1946 (should
1947 (equal
1948 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
1949 (org-test-with-temp-text
1950 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
1951 (org-drag-element-backward)
1952 (buffer-string))))
1953 ;; Preserve blank lines.
1954 (should
1955 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
1956 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
1957 (org-drag-element-backward)
1958 (buffer-string))))
1959 ;; Preserve column.
1960 (should
1961 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
1962 (org-drag-element-backward)
1963 (org-looking-at-p "2")))
1964 ;; Error when trying to move first element of buffer.
1965 (should-error
1966 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1967 (org-drag-element-backward)))
1968 ;; Error when trying to swap nested elements.
1969 (should-error
1970 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1971 (forward-line)
1972 (org-drag-element-backward)))
1973 ;; Error when trying to swap an headline element and a non-headline
1974 ;; element.
1975 (should-error
1976 (org-test-with-temp-text "Test.\n* Head 1"
1977 (forward-line)
1978 (org-drag-element-backward)))
1979 ;; Preserve visibility of elements and their contents.
1980 (should
1981 (equal '((63 . 82) (26 . 48))
1982 (org-test-with-temp-text "
1983 #+BEGIN_CENTER
1984 Text.
1985 #+END_CENTER
1986 - item 1
1987 #+BEGIN_QUOTE
1988 Text.
1989 #+END_QUOTE"
1990 (while (search-forward "BEGIN_" nil t) (org-cycle))
1991 (search-backward "- item 1")
1992 (org-drag-element-backward)
1993 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1994 (overlays-in (point-min) (point-max)))))))
1996 (ert-deftest test-org/drag-element-forward ()
1997 "Test `org-drag-element-forward' specifications."
1998 ;; 1. Error when trying to move first element of buffer.
1999 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
2000 (goto-line 3)
2001 (should-error (org-drag-element-forward)))
2002 ;; 2. Error when trying to swap nested elements.
2003 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
2004 (forward-line)
2005 (should-error (org-drag-element-forward)))
2006 ;; 3. Error when trying to swap a non-headline element and an
2007 ;; headline.
2008 (org-test-with-temp-text "Test.\n* Head 1"
2009 (should-error (org-drag-element-forward)))
2010 ;; 4. Otherwise, swap elements, preserving column and blank lines
2011 ;; between elements.
2012 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
2013 (search-forward "graph")
2014 (org-drag-element-forward)
2015 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
2016 (should (looking-at " 1")))
2017 ;; 5. Preserve visibility of elements and their contents.
2018 (org-test-with-temp-text "
2019 #+BEGIN_CENTER
2020 Text.
2021 #+END_CENTER
2022 - item 1
2023 #+BEGIN_QUOTE
2024 Text.
2025 #+END_QUOTE"
2026 (while (search-forward "BEGIN_" nil t) (org-cycle))
2027 (search-backward "#+BEGIN_CENTER")
2028 (org-drag-element-forward)
2029 (should
2030 (equal
2031 '((63 . 82) (26 . 48))
2032 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
2033 (overlays-in (point-min) (point-max)))))))
2037 ;;; Outline structure
2039 (ert-deftest test-org/demote ()
2040 "Test `org-demote' specifications."
2041 ;; Add correct number of stars according to `org-odd-levels-only'.
2042 (should
2043 (= 2
2044 (org-test-with-temp-text "* H"
2045 (let ((org-odd-levels-only nil)) (org-demote))
2046 (org-current-level))))
2047 (should
2048 (= 3
2049 (org-test-with-temp-text "* H"
2050 (let ((org-odd-levels-only t)) (org-demote))
2051 (org-current-level))))
2052 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2053 (should
2054 (org-test-with-temp-text "* H :tag:"
2055 (let ((org-tags-column 10)
2056 (org-auto-align-tags t)
2057 (org-odd-levels-only nil))
2058 (org-demote))
2059 (org-move-to-column 10)
2060 (org-looking-at-p ":tag:$")))
2061 (should-not
2062 (org-test-with-temp-text "* H :tag:"
2063 (let ((org-tags-column 10)
2064 (org-auto-align-tags nil)
2065 (org-odd-levels-only nil))
2066 (org-demote))
2067 (org-move-to-column 10)
2068 (org-looking-at-p ":tag:$")))
2069 ;; When `org-adapt-indentation' is non-nil, always indent planning
2070 ;; info and property drawers accordingly.
2071 (should
2072 (= 3
2073 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2074 (let ((org-odd-levels-only nil)
2075 (org-adapt-indentation t))
2076 (org-demote))
2077 (forward-line)
2078 (org-get-indentation))))
2079 (should
2080 (= 3
2081 (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2082 (let ((org-odd-levels-only nil)
2083 (org-adapt-indentation t))
2084 (org-demote))
2085 (forward-line)
2086 (org-get-indentation))))
2087 (should-not
2088 (= 3
2089 (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
2090 (let ((org-odd-levels-only nil)
2091 (org-adapt-indentation nil))
2092 (org-demote))
2093 (forward-line)
2094 (org-get-indentation))))
2095 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2096 ;; section accordingly. Ignore, however, footnote definitions and
2097 ;; inlinetasks boundaries.
2098 (should
2099 (= 3
2100 (org-test-with-temp-text "* H\n Paragraph"
2101 (let ((org-odd-levels-only nil)
2102 (org-adapt-indentation t))
2103 (org-demote))
2104 (forward-line)
2105 (org-get-indentation))))
2106 (should
2107 (= 2
2108 (org-test-with-temp-text "* H\n Paragraph"
2109 (let ((org-odd-levels-only nil)
2110 (org-adapt-indentation nil))
2111 (org-demote))
2112 (forward-line)
2113 (org-get-indentation))))
2114 (should
2115 (zerop
2116 (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
2117 (let ((org-odd-levels-only nil)
2118 (org-adapt-indentation t))
2119 (org-demote))
2120 (goto-char (point-max))
2121 (org-get-indentation))))
2122 (should
2123 (= 3
2124 (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
2125 (let ((org-odd-levels-only nil)
2126 (org-adapt-indentation t))
2127 (org-demote))
2128 (goto-char (point-max))
2129 (org-get-indentation))))
2130 (when (featurep 'org-inlinetask)
2131 (should
2132 (zerop
2133 (let ((org-inlinetask-min-level 5)
2134 (org-adapt-indentation t))
2135 (org-test-with-temp-text "* H\n***** I\n***** END"
2136 (org-demote)
2137 (forward-line)
2138 (org-get-indentation))))))
2139 (when (featurep 'org-inlinetask)
2140 (should
2141 (= 3
2142 (let ((org-inlinetask-min-level 5)
2143 (org-adapt-indentation t))
2144 (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
2145 (org-demote)
2146 (forward-line 2)
2147 (org-get-indentation))))))
2148 ;; Ignore contents of source blocks or example blocks when
2149 ;; indentation should be preserved (through
2150 ;; `org-src-preserve-indentation' or "-i" flag).
2151 (should-not
2152 (zerop
2153 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2154 (let ((org-adapt-indentation t)
2155 (org-src-preserve-indentation nil))
2156 (org-demote))
2157 (forward-line 2)
2158 (org-get-indentation))))
2159 (should
2160 (zerop
2161 (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2162 (let ((org-adapt-indentation t)
2163 (org-src-preserve-indentation t))
2164 (org-demote))
2165 (forward-line 2)
2166 (org-get-indentation))))
2167 (should
2168 (zerop
2169 (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2170 (let ((org-adapt-indentation t)
2171 (org-src-preserve-indentation t))
2172 (org-demote))
2173 (forward-line 2)
2174 (org-get-indentation))))
2175 (should
2176 (zerop
2177 (org-test-with-temp-text
2178 "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
2179 (let ((org-adapt-indentation t)
2180 (org-src-preserve-indentation nil))
2181 (org-demote))
2182 (forward-line 2)
2183 (org-get-indentation)))))
2185 (ert-deftest test-org/promote ()
2186 "Test `org-promote' specifications."
2187 ;; Return an error if headline is to be promoted to level 0, unless
2188 ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
2189 ;; headline becomes a comment.
2190 (should-error
2191 (org-test-with-temp-text "* H"
2192 (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
2193 (should
2194 (equal "# H"
2195 (org-test-with-temp-text "* H"
2196 (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
2197 (buffer-string))))
2198 ;; Remove correct number of stars according to
2199 ;; `org-odd-levels-only'.
2200 (should
2201 (= 2
2202 (org-test-with-temp-text "*** H"
2203 (let ((org-odd-levels-only nil)) (org-promote))
2204 (org-current-level))))
2205 (should
2206 (= 1
2207 (org-test-with-temp-text "*** H"
2208 (let ((org-odd-levels-only t)) (org-promote))
2209 (org-current-level))))
2210 ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
2211 (should
2212 (org-test-with-temp-text "** H :tag:"
2213 (let ((org-tags-column 10)
2214 (org-auto-align-tags t)
2215 (org-odd-levels-only nil))
2216 (org-promote))
2217 (org-move-to-column 10)
2218 (org-looking-at-p ":tag:$")))
2219 (should-not
2220 (org-test-with-temp-text "** H :tag:"
2221 (let ((org-tags-column 10)
2222 (org-auto-align-tags nil)
2223 (org-odd-levels-only nil))
2224 (org-promote))
2225 (org-move-to-column 10)
2226 (org-looking-at-p ":tag:$")))
2227 ;; When `org-adapt-indentation' is non-nil, always indent planning
2228 ;; info and property drawers.
2229 (should
2230 (= 2
2231 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2232 (let ((org-odd-levels-only nil)
2233 (org-adapt-indentation t))
2234 (org-promote))
2235 (forward-line)
2236 (org-get-indentation))))
2237 (should
2238 (= 2
2239 (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
2240 (let ((org-odd-levels-only nil)
2241 (org-adapt-indentation t))
2242 (org-promote))
2243 (forward-line)
2244 (org-get-indentation))))
2245 (should-not
2246 (= 2
2247 (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
2248 (let ((org-odd-levels-only nil)
2249 (org-adapt-indentation nil))
2250 (org-promote))
2251 (forward-line)
2252 (org-get-indentation))))
2253 ;; When `org-adapt-indentation' is non-nil, shift all lines in
2254 ;; section accordingly. Ignore, however, footnote definitions and
2255 ;; inlinetasks boundaries.
2256 (should
2257 (= 2
2258 (org-test-with-temp-text "** H\n Paragraph"
2259 (let ((org-odd-levels-only nil)
2260 (org-adapt-indentation t))
2261 (org-promote))
2262 (forward-line)
2263 (org-get-indentation))))
2264 (should-not
2265 (= 2
2266 (org-test-with-temp-text "** H\n Paragraph"
2267 (let ((org-odd-levels-only nil)
2268 (org-adapt-indentation nil))
2269 (org-promote))
2270 (forward-line)
2271 (org-get-indentation))))
2272 (should
2273 (= 2
2274 (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
2275 (let ((org-odd-levels-only nil)
2276 (org-adapt-indentation t))
2277 (org-promote))
2278 (forward-line)
2279 (org-get-indentation))))
2280 (when (featurep 'org-inlinetask)
2281 (should
2282 (zerop
2283 (let ((org-inlinetask-min-level 5)
2284 (org-adapt-indentation t))
2285 (org-test-with-temp-text "** H\n***** I\n***** END"
2286 (org-promote)
2287 (forward-line)
2288 (org-get-indentation))))))
2289 (when (featurep 'org-inlinetask)
2290 (should
2291 (= 2
2292 (let ((org-inlinetask-min-level 5)
2293 (org-adapt-indentation t))
2294 (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
2295 (org-promote)
2296 (forward-line 2)
2297 (org-get-indentation))))))
2298 ;; Give up shifting if it would break document's structure
2299 ;; otherwise.
2300 (should
2301 (= 3
2302 (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
2303 (let ((org-odd-levels-only nil)
2304 (org-adapt-indentation t))
2305 (org-promote))
2306 (forward-line)
2307 (org-get-indentation))))
2308 (should
2309 (= 3
2310 (org-test-with-temp-text "** H\n Paragraph\n * list."
2311 (let ((org-odd-levels-only nil)
2312 (org-adapt-indentation t))
2313 (org-promote))
2314 (forward-line)
2315 (org-get-indentation))))
2316 ;; Ignore contents of source blocks or example blocks when
2317 ;; indentation should be preserved (through
2318 ;; `org-src-preserve-indentation' or "-i" flag).
2319 (should-not
2320 (zerop
2321 (org-test-with-temp-text
2322 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2323 (let ((org-adapt-indentation t)
2324 (org-src-preserve-indentation nil)
2325 (org-odd-levels-only nil))
2326 (org-promote))
2327 (forward-line)
2328 (org-get-indentation))))
2329 (should
2330 (zerop
2331 (org-test-with-temp-text
2332 "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
2333 (let ((org-adapt-indentation t)
2334 (org-src-preserve-indentation t)
2335 (org-odd-levels-only nil))
2336 (org-promote))
2337 (forward-line)
2338 (org-get-indentation))))
2339 (should
2340 (zerop
2341 (org-test-with-temp-text
2342 "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
2343 (let ((org-adapt-indentation t)
2344 (org-src-preserve-indentation t)
2345 (org-odd-levels-only nil))
2346 (org-promote))
2347 (forward-line)
2348 (org-get-indentation))))
2349 (should
2350 (zerop
2351 (org-test-with-temp-text
2352 "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
2353 (let ((org-adapt-indentation t)
2354 (org-src-preserve-indentation nil)
2355 (org-odd-levels-only nil))
2356 (org-promote))
2357 (forward-line)
2358 (org-get-indentation)))))
2361 ;;; Planning
2363 (ert-deftest test-org/timestamp-has-time-p ()
2364 "Test `org-timestamp-has-time-p' specifications."
2365 ;; With time.
2366 (should
2367 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2368 (org-timestamp-has-time-p (org-element-context))))
2369 ;; Without time.
2370 (should-not
2371 (org-test-with-temp-text "<2012-03-29 Thu>"
2372 (org-timestamp-has-time-p (org-element-context)))))
2374 (ert-deftest test-org/timestamp-format ()
2375 "Test `org-timestamp-format' specifications."
2376 ;; Regular test.
2377 (should
2378 (equal
2379 "2012-03-29 16:40"
2380 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2381 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
2382 ;; Range end.
2383 (should
2384 (equal
2385 "2012-03-29"
2386 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
2387 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
2389 (ert-deftest test-org/timestamp-split-range ()
2390 "Test `org-timestamp-split-range' specifications."
2391 ;; Extract range start (active).
2392 (should
2393 (equal '(2012 3 29)
2394 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2395 (let ((ts (org-timestamp-split-range (org-element-context))))
2396 (mapcar (lambda (p) (org-element-property p ts))
2397 '(:year-end :month-end :day-end))))))
2398 ;; Extract range start (inactive)
2399 (should
2400 (equal '(2012 3 29)
2401 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2402 (let ((ts (org-timestamp-split-range (org-element-context))))
2403 (mapcar (lambda (p) (org-element-property p ts))
2404 '(:year-end :month-end :day-end))))))
2405 ;; Extract range end (active).
2406 (should
2407 (equal '(2012 3 30)
2408 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2409 (let ((ts (org-timestamp-split-range
2410 (org-element-context) t)))
2411 (mapcar (lambda (p) (org-element-property p ts))
2412 '(:year-end :month-end :day-end))))))
2413 ;; Extract range end (inactive)
2414 (should
2415 (equal '(2012 3 30)
2416 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2417 (let ((ts (org-timestamp-split-range
2418 (org-element-context) t)))
2419 (mapcar (lambda (p) (org-element-property p ts))
2420 '(:year-end :month-end :day-end))))))
2421 ;; Return the timestamp if not a range.
2422 (should
2423 (org-test-with-temp-text "[2012-03-29 Thu]"
2424 (let* ((ts-orig (org-element-context))
2425 (ts-copy (org-timestamp-split-range ts-orig)))
2426 (eq ts-orig ts-copy))))
2427 (should
2428 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2429 (let* ((ts-orig (org-element-context))
2430 (ts-copy (org-timestamp-split-range ts-orig)))
2431 (eq ts-orig ts-copy))))
2432 ;; Check that parent is the same when a range was split.
2433 (should
2434 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2435 (let* ((ts-orig (org-element-context))
2436 (ts-copy (org-timestamp-split-range ts-orig)))
2437 (eq (org-element-property :parent ts-orig)
2438 (org-element-property :parent ts-copy))))))
2440 (ert-deftest test-org/timestamp-translate ()
2441 "Test `org-timestamp-translate' specifications."
2442 ;; Translate whole date range.
2443 (should
2444 (equal "<29>--<30>"
2445 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2446 (let ((org-display-custom-times t)
2447 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2448 (org-timestamp-translate (org-element-context))))))
2449 ;; Translate date range start.
2450 (should
2451 (equal "<29>"
2452 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2453 (let ((org-display-custom-times t)
2454 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2455 (org-timestamp-translate (org-element-context) 'start)))))
2456 ;; Translate date range end.
2457 (should
2458 (equal "<30>"
2459 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2460 (let ((org-display-custom-times t)
2461 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2462 (org-timestamp-translate (org-element-context) 'end)))))
2463 ;; Translate time range.
2464 (should
2465 (equal "<08>--<16>"
2466 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
2467 (let ((org-display-custom-times t)
2468 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
2469 (org-timestamp-translate (org-element-context))))))
2470 ;; Translate non-range timestamp.
2471 (should
2472 (equal "<29>"
2473 (org-test-with-temp-text "<2012-03-29 Thu>"
2474 (let ((org-display-custom-times t)
2475 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2476 (org-timestamp-translate (org-element-context))))))
2477 ;; Do not change `diary' timestamps.
2478 (should
2479 (equal "<%%(org-float t 4 2)>"
2480 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2481 (let ((org-display-custom-times t)
2482 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2483 (org-timestamp-translate (org-element-context)))))))
2487 ;;; Property API
2489 (ert-deftest test-org/buffer-property-keys ()
2490 "Test `org-buffer-property-keys' specifications."
2491 ;; Retrieve properties accross siblings.
2492 (should
2493 (equal '("A" "B")
2494 (org-test-with-temp-text "
2495 * H1
2496 :PROPERTIES:
2497 :A: 1
2498 :END:
2499 * H2
2500 :PROPERTIES:
2501 :B: 1
2502 :END:"
2503 (org-buffer-property-keys))))
2504 ;; Retrieve properties accross children.
2505 (should
2506 (equal '("A" "B")
2507 (org-test-with-temp-text "
2508 * H1
2509 :PROPERTIES:
2510 :A: 1
2511 :END:
2512 ** H2
2513 :PROPERTIES:
2514 :B: 1
2515 :END:"
2516 (org-buffer-property-keys))))
2517 ;; Retrieve muliple properties in the same drawer.
2518 (should
2519 (equal '("A" "B")
2520 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2521 (org-buffer-property-keys))))
2522 ;; Ignore extension symbol in property name.
2523 (should
2524 (equal '("A")
2525 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2526 (org-buffer-property-keys))))
2527 ;; With non-nil COLUMNS, extract property names from columns.
2528 (should
2529 (equal '("A" "B")
2530 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2531 (org-buffer-property-keys nil nil t))))
2532 (should
2533 (equal '("A" "B" "COLUMNS")
2534 (org-test-with-temp-text
2535 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2536 (org-buffer-property-keys nil nil t)))))
2538 (ert-deftest test-org/property-values ()
2539 "Test `org-property-values' specifications."
2540 ;; Regular test.
2541 (should
2542 (equal '("2" "1")
2543 (org-test-with-temp-text
2544 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2545 (org-property-values "A"))))
2546 ;; Ignore empty values.
2547 (should-not
2548 (org-test-with-temp-text
2549 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2550 (org-property-values "A")))
2551 ;; Take into consideration extended values.
2552 (should
2553 (equal '("1 2")
2554 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2555 (org-property-values "A")))))
2557 (ert-deftest test-org/entry-delete ()
2558 "Test `org-entry-delete' specifications."
2559 ;; Regular test.
2560 (should
2561 (string-match
2562 " *:PROPERTIES:\n *:B: +2\n *:END:"
2563 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2564 (org-entry-delete (point) "A")
2565 (buffer-string))))
2566 ;; When last property is removed, remove the property drawer.
2567 (should-not
2568 (string-match
2569 ":PROPERTIES:"
2570 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2571 (org-entry-delete (point) "A")
2572 (buffer-string)))))
2574 (ert-deftest test-org/entry-get ()
2575 "Test `org-entry-get' specifications."
2576 ;; Regular test.
2577 (should
2578 (equal "1"
2579 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2580 (org-entry-get (point) "A"))))
2581 ;; Ignore case.
2582 (should
2583 (equal "1"
2584 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2585 (org-entry-get (point) "a"))))
2586 ;; Handle extended values, both before and after base value.
2587 (should
2588 (equal "1 2 3"
2589 (org-test-with-temp-text
2590 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2591 (org-entry-get (point) "A"))))
2592 ;; Empty values are returned as the empty string.
2593 (should
2594 (equal ""
2595 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2596 (org-entry-get (point) "A"))))
2597 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2598 ;; otherwise, return nil.
2599 (should-not
2600 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2601 (org-entry-get (point) "A")))
2602 (should
2603 (equal "nil"
2604 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2605 (org-entry-get (point) "A" nil t))))
2606 ;; Return nil when no property is found, independently on the
2607 ;; LITERAL-NIL argument.
2608 (should-not
2609 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2610 (org-entry-get (point) "B")))
2611 (should-not
2612 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2613 (org-entry-get (point) "B" nil t)))
2614 ;; Handle inheritance, when allowed.
2615 (should
2616 (equal
2618 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2619 (org-entry-get (point) "A" t))))
2620 (should
2621 (equal
2623 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2624 (let ((org-use-property-inheritance t))
2625 (org-entry-get (point) "A" 'selective)))))
2626 (should-not
2627 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2628 (let ((org-use-property-inheritance nil))
2629 (org-entry-get (point) "A" 'selective)))))
2631 (ert-deftest test-org/entry-properties ()
2632 "Test `org-entry-properties' specifications."
2633 ;; Get "ITEM" property.
2634 (should
2635 (equal "* H"
2636 (org-test-with-temp-text "* TODO H"
2637 (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
2638 ;; Get "TODO" property.
2639 (should
2640 (equal "TODO"
2641 (org-test-with-temp-text "* TODO H"
2642 (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
2643 (should-not
2644 (org-test-with-temp-text "* H"
2645 (assoc "TODO" (org-entry-properties nil "TODO"))))
2646 ;; Get "PRIORITY" property.
2647 (should
2648 (equal "A"
2649 (org-test-with-temp-text "* [#A] H"
2650 (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
2651 (should-not
2652 (org-test-with-temp-text "* H"
2653 (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))
2654 ;; Get "FILE" property.
2655 (should
2656 (org-test-with-temp-text-in-file "* H\nParagraph"
2657 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
2658 (buffer-file-name))))
2659 (should-not
2660 (org-test-with-temp-text "* H\nParagraph"
2661 (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
2662 ;; Get "TAGS" property.
2663 (should
2664 (equal ":tag1:tag2:"
2665 (org-test-with-temp-text "* H :tag1:tag2:"
2666 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
2667 (should-not
2668 (org-test-with-temp-text "* H"
2669 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
2670 ;; Get "ALLTAGS" property.
2671 (should
2672 (equal ":tag1:tag2:"
2673 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2674 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
2675 (should-not
2676 (org-test-with-temp-text "* H"
2677 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
2678 ;; Get "BLOCKED" property.
2679 (should
2680 (equal "t"
2681 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2682 (let ((org-enforce-todo-dependencies t)
2683 (org-blocker-hook
2684 '(org-block-todo-from-children-or-siblings-or-parent)))
2685 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2686 (should
2687 (equal ""
2688 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2689 (let ((org-enforce-todo-dependencies t))
2690 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2691 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2692 (should
2693 (equal
2694 "[2012-03-29 thu.]"
2695 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2696 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
2697 (should-not
2698 (org-test-with-temp-text "* H"
2699 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
2700 (should
2701 (equal
2702 "<2014-03-04 tue.>"
2703 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2704 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
2705 (should-not
2706 (org-test-with-temp-text "* H"
2707 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
2708 (should
2709 (equal
2710 "<2014-03-04 tue.>"
2711 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2712 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
2713 (should-not
2714 (org-test-with-temp-text "* H"
2715 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
2716 ;; Get "CATEGORY"
2717 (should
2718 (equal "cat"
2719 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2720 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2721 (should
2722 (equal "cat"
2723 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2724 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2725 ;; Get standard properties.
2726 (should
2727 (equal "1"
2728 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2729 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2730 ;; Handle extended properties.
2731 (should
2732 (equal "1 2 3"
2733 (org-test-with-temp-text
2734 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2735 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2736 (should
2737 (equal "1 2 3"
2738 (org-test-with-temp-text
2739 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2740 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2741 ;; Ignore forbidden (special) properties.
2742 (should-not
2743 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2744 (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
2746 (ert-deftest test-org/entry-put ()
2747 "Test `org-entry-put' specifications."
2748 ;; Error when not a string or nil.
2749 (should-error
2750 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2751 (org-entry-put 1 "test" 2)))
2752 ;; Set "TODO" property.
2753 (should
2754 (string-match (regexp-quote " TODO H")
2755 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2756 (org-entry-put (point) "TODO" "TODO")
2757 (buffer-string))))
2758 (should
2759 (string-match (regexp-quote "* H")
2760 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2761 (org-entry-put (point) "TODO" nil)
2762 (buffer-string))))
2763 ;; Set "PRIORITY" property.
2764 (should
2765 (equal "* [#A] H"
2766 (org-test-with-temp-text "* [#B] H"
2767 (org-entry-put (point) "PRIORITY" "A")
2768 (buffer-string))))
2769 (should
2770 (equal "* H"
2771 (org-test-with-temp-text "* [#B] H"
2772 (org-entry-put (point) "PRIORITY" nil)
2773 (buffer-string))))
2774 ;; Set "SCHEDULED" property.
2775 (should
2776 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2777 (org-test-with-temp-text "* H"
2778 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2779 (buffer-string))))
2780 (should
2781 (string= "* H\n"
2782 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2783 (org-entry-put (point) "SCHEDULED" nil)
2784 (buffer-string))))
2785 (should
2786 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
2787 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2788 (org-entry-put (point) "SCHEDULED" "earlier")
2789 (buffer-string))))
2790 (should
2791 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
2792 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2793 (org-entry-put (point) "SCHEDULED" "later")
2794 (buffer-string))))
2795 ;; Set "DEADLINE" property.
2796 (should
2797 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
2798 (org-test-with-temp-text "* H"
2799 (org-entry-put (point) "DEADLINE" "2014-03-04")
2800 (buffer-string))))
2801 (should
2802 (string= "* H\n"
2803 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2804 (org-entry-put (point) "DEADLINE" nil)
2805 (buffer-string))))
2806 (should
2807 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
2808 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2809 (org-entry-put (point) "DEADLINE" "earlier")
2810 (buffer-string))))
2811 (should
2812 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
2813 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2814 (org-entry-put (point) "DEADLINE" "later")
2815 (buffer-string))))
2816 ;; Regular properties, with or without pre-existing drawer.
2817 (should
2818 (string-match "^ *:A: +2$"
2819 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2820 (org-entry-put (point) "A" "2")
2821 (buffer-string))))
2822 (should
2823 (string-match "^ *:A: +1$"
2824 (org-test-with-temp-text "* H"
2825 (org-entry-put (point) "A" "1")
2826 (buffer-string))))
2827 ;; Special case: two consecutive headlines.
2828 (should
2829 (string-match "\\* A\n *:PROPERTIES:"
2830 (org-test-with-temp-text "* A\n** B"
2831 (org-entry-put (point) "A" "1")
2832 (buffer-string)))))
2835 ;;; Radio Targets
2837 (ert-deftest test-org/update-radio-target-regexp ()
2838 "Test `org-update-radio-target-regexp' specifications."
2839 ;; Properly update cache with no previous radio target regexp.
2840 (should
2841 (eq 'link
2842 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2843 (save-excursion (goto-char (point-max)) (org-element-context))
2844 (insert "<<<")
2845 (search-forward "o")
2846 (insert ">>>")
2847 (org-update-radio-target-regexp)
2848 (goto-char (point-max))
2849 (org-element-type (org-element-context)))))
2850 ;; Properly update cache with previous radio target regexp.
2851 (should
2852 (eq 'link
2853 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2854 (save-excursion (goto-char (point-max)) (org-element-context))
2855 (insert "<<<")
2856 (search-forward "o")
2857 (insert ">>>")
2858 (org-update-radio-target-regexp)
2859 (search-backward "r")
2860 (delete-char 5)
2861 (insert "new")
2862 (org-update-radio-target-regexp)
2863 (goto-char (point-max))
2864 (delete-region (line-beginning-position) (point))
2865 (insert "new")
2866 (org-element-type (org-element-context))))))
2870 ;;; Visibility
2872 (ert-deftest test-org/flag-drawer ()
2873 "Test `org-flag-drawer' specifications."
2874 ;; Hide drawer.
2875 (should
2876 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2877 (org-flag-drawer t)
2878 (get-char-property (line-end-position) 'invisible)))
2879 ;; Show drawer.
2880 (should-not
2881 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2882 (org-flag-drawer t)
2883 (org-flag-drawer nil)
2884 (get-char-property (line-end-position) 'invisible)))
2885 ;; Test optional argument.
2886 (should
2887 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2888 (let ((drawer (save-excursion (search-forward ":D2")
2889 (org-element-at-point))))
2890 (org-flag-drawer t drawer)
2891 (get-char-property (progn (search-forward ":D2") (line-end-position))
2892 'invisible))))
2893 (should-not
2894 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2895 (let ((drawer (save-excursion (search-forward ":D2")
2896 (org-element-at-point))))
2897 (org-flag-drawer t drawer)
2898 (get-char-property (line-end-position) 'invisible))))
2899 ;; Do not hide fake drawers.
2900 (should-not
2901 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
2902 (forward-line 1)
2903 (org-flag-drawer t)
2904 (get-char-property (line-end-position) 'invisible)))
2905 ;; Do not hide incomplete drawers.
2906 (should-not
2907 (org-test-with-temp-text ":D:\nparagraph"
2908 (forward-line 1)
2909 (org-flag-drawer t)
2910 (get-char-property (line-end-position) 'invisible)))
2911 ;; Do not hide drawers when called from final blank lines.
2912 (should-not
2913 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
2914 (goto-char (point-max))
2915 (org-flag-drawer t)
2916 (goto-char (point-min))
2917 (get-char-property (line-end-position) 'invisible)))
2918 ;; Don't leave point in an invisible part of the buffer when hiding
2919 ;; a drawer away.
2920 (should-not
2921 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2922 (goto-char (point-max))
2923 (org-flag-drawer t)
2924 (get-char-property (point) 'invisible))))
2926 (ert-deftest test-org/hide-block-toggle ()
2927 "Test `org-hide-block-toggle' specifications."
2928 ;; Error when not at a block.
2929 (should-error
2930 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
2931 (org-hide-block-toggle 'off)
2932 (get-char-property (line-end-position) 'invisible)))
2933 ;; Hide block.
2934 (should
2935 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2936 (org-hide-block-toggle)
2937 (get-char-property (line-end-position) 'invisible)))
2938 (should
2939 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
2940 (org-hide-block-toggle)
2941 (get-char-property (line-end-position) 'invisible)))
2942 ;; Show block unconditionally when optional argument is `off'.
2943 (should-not
2944 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2945 (org-hide-block-toggle)
2946 (org-hide-block-toggle 'off)
2947 (get-char-property (line-end-position) 'invisible)))
2948 (should-not
2949 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2950 (org-hide-block-toggle 'off)
2951 (get-char-property (line-end-position) 'invisible)))
2952 ;; Hide block unconditionally when optional argument is non-nil.
2953 (should
2954 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2955 (org-hide-block-toggle t)
2956 (get-char-property (line-end-position) 'invisible)))
2957 (should
2958 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2959 (org-hide-block-toggle)
2960 (org-hide-block-toggle t)
2961 (get-char-property (line-end-position) 'invisible)))
2962 ;; Do not hide block when called from final blank lines.
2963 (should-not
2964 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
2965 (org-hide-block-toggle)
2966 (goto-char (point-min))
2967 (get-char-property (line-end-position) 'invisible)))
2968 ;; Don't leave point in an invisible part of the buffer when hiding
2969 ;; a block away.
2970 (should-not
2971 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
2972 (org-hide-block-toggle)
2973 (get-char-property (point) 'invisible))))
2975 (ert-deftest test-org/hide-block-toggle-maybe ()
2976 "Test `org-hide-block-toggle-maybe' specifications."
2977 (should
2978 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
2979 (org-hide-block-toggle-maybe)))
2980 (should-not
2981 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
2984 (provide 'test-org)
2986 ;;; test-org.el ends here