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