Update custom properties handling
[org-mode/org-tableheadings.git] / testing / lisp / test-org.el
blob6617ebcab65569f97538bda8a1c3d3d193669d5e
1 ;;; test-org.el --- tests for org.el
3 ;; Copyright (c) David Maus
4 ;; Authors: David Maus
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Comments:
23 ;; Template test file for Org-mode tests
25 ;;; Code:
28 ;;; Comments
30 (ert-deftest test-org/toggle-comment ()
31 "Test `org-toggle-comment' specifications."
32 ;; Simple headline.
33 (should
34 (equal "* Test"
35 (org-test-with-temp-text "* COMMENT Test"
36 (org-toggle-comment)
37 (buffer-string))))
38 (should
39 (equal "* COMMENT Test"
40 (org-test-with-temp-text "* Test"
41 (org-toggle-comment)
42 (buffer-string))))
43 ;; Headline with a regular keyword.
44 (should
45 (equal "* TODO Test"
46 (org-test-with-temp-text "* TODO COMMENT Test"
47 (org-toggle-comment)
48 (buffer-string))))
49 (should
50 (equal "* TODO COMMENT Test"
51 (org-test-with-temp-text "* TODO Test"
52 (org-toggle-comment)
53 (buffer-string))))
54 ;; Empty headline.
55 (should
56 (equal "* "
57 (org-test-with-temp-text "* COMMENT"
58 (org-toggle-comment)
59 (buffer-string))))
60 (should
61 (equal "* COMMENT"
62 (org-test-with-temp-text "* "
63 (org-toggle-comment)
64 (buffer-string))))
65 ;; Headline with a single keyword.
66 (should
67 (equal "* TODO "
68 (org-test-with-temp-text "* TODO COMMENT"
69 (org-toggle-comment)
70 (buffer-string))))
71 (should
72 (equal "* TODO COMMENT"
73 (org-test-with-temp-text "* TODO"
74 (org-toggle-comment)
75 (buffer-string))))
76 ;; Headline with a keyword, a priority cookie and contents.
77 (should
78 (equal "* TODO [#A] Headline"
79 (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
80 (org-toggle-comment)
81 (buffer-string))))
82 (should
83 (equal "* TODO [#A] COMMENT Headline"
84 (org-test-with-temp-text "* TODO [#A] Headline"
85 (org-toggle-comment)
86 (buffer-string)))))
88 (ert-deftest test-org/comment-dwim ()
89 "Test `comment-dwim' behaviour in an Org buffer."
90 ;; No region selected, no comment on current line and line not
91 ;; empty: insert comment on line above.
92 (should
93 (equal "# \nComment"
94 (org-test-with-temp-text "Comment"
95 (progn (call-interactively 'comment-dwim)
96 (buffer-string)))))
97 ;; No region selected, no comment on current line and line empty:
98 ;; insert comment on this line.
99 (should
100 (equal "# \nParagraph"
101 (org-test-with-temp-text "\nParagraph"
102 (progn (call-interactively 'comment-dwim)
103 (buffer-string)))))
104 ;; No region selected, and a comment on this line: indent it.
105 (should
106 (equal "* Headline\n # Comment"
107 (org-test-with-temp-text "* Headline\n# Comment"
108 (progn (forward-line)
109 (let ((org-adapt-indentation t))
110 (call-interactively 'comment-dwim))
111 (buffer-string)))))
112 ;; Also recognize single # at column 0 as comments.
113 (should
114 (equal "# Comment"
115 (org-test-with-temp-text "# Comment"
116 (progn (forward-line)
117 (call-interactively 'comment-dwim)
118 (buffer-string)))))
119 ;; Region selected and only comments and blank lines within it:
120 ;; un-comment all commented lines.
121 (should
122 (equal "Comment 1\n\nComment 2"
123 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
124 (progn
125 (transient-mark-mode 1)
126 (push-mark (point) t t)
127 (goto-char (point-max))
128 (call-interactively 'comment-dwim)
129 (buffer-string)))))
130 ;; Region selected without comments: comment all lines if
131 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
132 (should
133 (equal "# Comment 1\n\n# Comment 2"
134 (org-test-with-temp-text "Comment 1\n\nComment 2"
135 (progn
136 (transient-mark-mode 1)
137 (push-mark (point) t t)
138 (goto-char (point-max))
139 (let ((comment-empty-lines nil))
140 (call-interactively 'comment-dwim))
141 (buffer-string)))))
142 (should
143 (equal "# Comment 1\n# \n# Comment 2"
144 (org-test-with-temp-text "Comment 1\n\nComment 2"
145 (progn
146 (transient-mark-mode 1)
147 (push-mark (point) t t)
148 (goto-char (point-max))
149 (let ((comment-empty-lines t))
150 (call-interactively 'comment-dwim))
151 (buffer-string)))))
152 ;; In front of a keyword without region, insert a new comment.
153 (should
154 (equal "# \n#+KEYWORD: value"
155 (org-test-with-temp-text "#+KEYWORD: value"
156 (progn (call-interactively 'comment-dwim)
157 (buffer-string)))))
158 ;; In a source block, use appropriate syntax.
159 (should
160 (equal " ;; "
161 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
162 (forward-line)
163 (let ((org-edit-src-content-indentation 2))
164 (call-interactively 'comment-dwim))
165 (buffer-substring-no-properties (line-beginning-position) (point)))))
166 (should
167 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
168 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
169 (forward-line)
170 (transient-mark-mode 1)
171 (push-mark (point) t t)
172 (forward-line 2)
173 (let ((org-edit-src-content-indentation 2))
174 (call-interactively 'comment-dwim))
175 (buffer-string)))))
179 ;;; Date and time analysis
181 (ert-deftest test-org/org-read-date ()
182 "Test `org-read-date' specifications."
183 ;; Parse ISO date with abbreviated year and month.
184 (should (equal "2012-03-29 16:40"
185 (let ((org-time-was-given t))
186 (org-read-date t nil "12-3-29 16:40"))))
187 ;; Parse Europeans dates.
188 (should (equal "2012-03-29 16:40"
189 (let ((org-time-was-given t))
190 (org-read-date t nil "29.03.2012 16:40"))))
191 ;; Parse Europeans dates without year.
192 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
193 (let ((org-time-was-given t))
194 (org-read-date t nil "29.03. 16:40")))))
196 (ert-deftest test-org/org-parse-time-string ()
197 "Test `org-parse-time-string'."
198 (should (equal (org-parse-time-string "2012-03-29 16:40")
199 '(0 40 16 29 3 2012 nil nil nil)))
200 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
201 '(0 40 16 29 3 2012 nil nil nil)))
202 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
203 '(0 40 16 29 3 2012 nil nil nil)))
204 (should (equal (org-parse-time-string "<2012-03-29>")
205 '(0 0 0 29 3 2012 nil nil nil)))
206 (should (equal (org-parse-time-string "<2012-03-29>" t)
207 '(0 nil nil 29 3 2012 nil nil nil))))
210 ;;; Drawers
212 (ert-deftest test-org/insert-property-drawer ()
213 "Test `org-insert-property-drawer' specifications."
214 ;; Error before first headline.
215 (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
216 ;; Insert drawer right after headline if there is no planning line,
217 ;; or after it otherwise.
218 (should
219 (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
220 (org-test-with-temp-text "* H\nParagraph<point>"
221 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
222 (buffer-string))))
223 (should
224 (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
225 (org-test-with-temp-text
226 "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
227 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
228 (buffer-string))))
229 ;; Indent inserted drawer.
230 (should
231 (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
232 (org-test-with-temp-text "* H\nParagraph<point>"
233 (let ((org-adapt-indentation t)) (org-insert-property-drawer))
234 (buffer-string))))
235 ;; Handle insertion at eob.
236 (should
237 (equal "* H\n:PROPERTIES:\n:END:\n"
238 (org-test-with-temp-text "* H"
239 (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
240 (buffer-string))))
241 ;; Skip inlinetasks before point.
242 (when (featurep 'org-inlinetask)
243 (should
244 (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
245 (org-test-with-temp-text
246 "* H\n*************** I\n*************** END\nP<point>"
247 (let ((org-adapt-indentation nil)
248 (org-inlinetask-min-level 15))
249 (org-insert-property-drawer))
250 (buffer-string)))))
251 ;; Correctly set drawer in an inlinetask.
252 (when (featurep 'org-inlinetask)
253 (should
254 (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
255 (org-test-with-temp-text
256 "* H\n*************** I\nP<point>\n*************** END"
257 (let ((org-adapt-indentation nil)
258 (org-inlinetask-min-level 15))
259 (org-insert-property-drawer))
260 (buffer-string))))))
263 ;;; Filling
265 (ert-deftest test-org/fill-paragraph ()
266 "Test `org-fill-paragraph' specifications."
267 ;; At an Org table, align it.
268 (should
269 (equal "| a |\n"
270 (org-test-with-temp-text "|a|"
271 (org-fill-paragraph)
272 (buffer-string))))
273 (should
274 (equal "#+name: table\n| a |\n"
275 (org-test-with-temp-text "#+name: table\n| a |"
276 (org-fill-paragraph)
277 (buffer-string))))
278 ;; At a paragraph, preserve line breaks.
279 (org-test-with-temp-text "some \\\\\nlong\ntext"
280 (let ((fill-column 20))
281 (org-fill-paragraph)
282 (should (equal (buffer-string) "some \\\\\nlong text"))))
283 ;; Correctly fill a paragraph when point is at its very end.
284 (should
285 (equal "A B"
286 (org-test-with-temp-text "A\nB"
287 (let ((fill-column 20))
288 (goto-char (point-max))
289 (org-fill-paragraph)
290 (buffer-string)))))
291 ;; Correctly fill the last paragraph of a greater element.
292 (should
293 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
294 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
295 (let ((fill-column 8))
296 (forward-line)
297 (end-of-line)
298 (org-fill-paragraph)
299 (buffer-string)))))
300 ;; Correctly fill an element in a narrowed buffer.
301 (should
302 (equal "01234\n6"
303 (org-test-with-temp-text "01234 6789"
304 (let ((fill-column 5))
305 (narrow-to-region 1 8)
306 (org-fill-paragraph)
307 (buffer-string)))))
308 ;; Handle `adaptive-fill-regexp' in paragraphs.
309 (should
310 (equal "> a b"
311 (org-test-with-temp-text "> a\n> b"
312 (let ((fill-column 5)
313 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
314 (org-fill-paragraph)
315 (buffer-string)))))
316 ;; Special case: Fill first paragraph when point is at an item or
317 ;; a plain-list or a footnote reference.
318 (should
319 (equal "- A B"
320 (org-test-with-temp-text "- A\n B"
321 (let ((fill-column 20))
322 (org-fill-paragraph)
323 (buffer-string)))))
324 (should
325 (equal "[fn:1] A B"
326 (org-test-with-temp-text "[fn:1] A\nB"
327 (let ((fill-column 20))
328 (org-fill-paragraph)
329 (buffer-string)))))
330 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
331 (let ((fill-column 20))
332 (org-fill-paragraph)
333 (should (equal (buffer-string)
334 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
335 ;; Fill contents of `comment-block' elements.
336 (should
337 (equal
338 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
339 (let ((fill-column 20))
340 (forward-line)
341 (org-fill-paragraph)
342 (buffer-string)))
343 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
344 ;; Fill `comment' elements.
345 (should
346 (equal " # A B"
347 (org-test-with-temp-text " # A\n # B"
348 (let ((fill-column 20))
349 (org-fill-paragraph)
350 (buffer-string)))))
351 ;; Do not mix consecutive comments when filling one of them.
352 (should
353 (equal "# A B\n\n# C"
354 (org-test-with-temp-text "# A\n# B\n\n# C"
355 (let ((fill-column 20))
356 (org-fill-paragraph)
357 (buffer-string)))))
358 ;; Use commented empty lines as separators when filling comments.
359 (should
360 (equal "# A B\n#\n# C"
361 (org-test-with-temp-text "# A\n# B\n#\n# C"
362 (let ((fill-column 20))
363 (org-fill-paragraph)
364 (buffer-string)))))
365 ;; Handle `adaptive-fill-regexp' in comments.
366 (should
367 (equal "# > a b"
368 (org-test-with-temp-text "# > a\n# > b"
369 (let ((fill-column 20)
370 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
371 (org-fill-paragraph)
372 (buffer-string)))))
373 ;; Do nothing at affiliated keywords.
374 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
375 (let ((fill-column 20))
376 (org-fill-paragraph)
377 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
378 ;; Do not move point after table when filling a table.
379 (should-not
380 (org-test-with-temp-text "| a | b |\n| c | d |\n"
381 (forward-char)
382 (org-fill-paragraph)
383 (eobp))))
385 (ert-deftest test-org/auto-fill-function ()
386 "Test auto-filling features."
387 ;; Auto fill paragraph.
388 (should
389 (equal "12345\n7890"
390 (org-test-with-temp-text "12345 7890"
391 (let ((fill-column 5))
392 (end-of-line)
393 (org-auto-fill-function)
394 (buffer-string)))))
395 ;; Auto fill first paragraph in an item.
396 (should
397 (equal "- 12345\n 7890"
398 (org-test-with-temp-text "- 12345 7890"
399 (let ((fill-column 7))
400 (end-of-line)
401 (org-auto-fill-function)
402 (buffer-string)))))
403 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
404 (should
405 (equal "> 12345\n 7890"
406 (org-test-with-temp-text "> 12345 7890"
407 (let ((fill-column 10)
408 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
409 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
410 (end-of-line)
411 (org-auto-fill-function)
412 (buffer-string)))))
413 (should
414 (equal "> 12345\n> 12345\n> 7890"
415 (org-test-with-temp-text "> 12345\n> 12345 7890"
416 (let ((fill-column 10)
417 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
418 (goto-char (point-max))
419 (org-auto-fill-function)
420 (buffer-string)))))
421 (should-not
422 (equal " 12345\n *12345\n *12345"
423 (org-test-with-temp-text " 12345\n *12345 12345"
424 (let ((fill-column 10)
425 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
426 (goto-char (point-max))
427 (org-auto-fill-function)
428 (buffer-string)))))
429 ;; Auto fill comments.
430 (should
431 (equal " # 12345\n # 7890"
432 (org-test-with-temp-text " # 12345 7890"
433 (let ((fill-column 10))
434 (end-of-line)
435 (org-auto-fill-function)
436 (buffer-string)))))
437 ;; A hash within a line isn't a comment.
438 (should-not
439 (equal "12345 # 7890\n# 1"
440 (org-test-with-temp-text "12345 # 7890 1"
441 (let ((fill-column 12))
442 (end-of-line)
443 (org-auto-fill-function)
444 (buffer-string)))))
445 ;; Correctly interpret empty prefix.
446 (should-not
447 (equal "# a\n# b\nRegular\n# paragraph"
448 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
449 (let ((fill-column 12))
450 (end-of-line 3)
451 (org-auto-fill-function)
452 (buffer-string)))))
453 ;; Comment block: auto fill contents.
454 (should
455 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
456 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
457 (let ((fill-column 5))
458 (forward-line)
459 (end-of-line)
460 (org-auto-fill-function)
461 (buffer-string)))))
462 (should
463 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
464 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
465 (let ((fill-column 5))
466 (forward-line)
467 (end-of-line)
468 (org-auto-fill-function)
469 (buffer-string)))))
470 ;; Do not fill if a new item could be created.
471 (should-not
472 (equal "12345\n- 90"
473 (org-test-with-temp-text "12345 - 90"
474 (let ((fill-column 5))
475 (end-of-line)
476 (org-auto-fill-function)
477 (buffer-string)))))
478 ;; Do not fill if a line break could be introduced.
479 (should-not
480 (equal "123\\\\\n7890"
481 (org-test-with-temp-text "123\\\\ 7890"
482 (let ((fill-column 6))
483 (end-of-line)
484 (org-auto-fill-function)
485 (buffer-string)))))
486 ;; Do not fill affiliated keywords.
487 (should-not
488 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
489 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
490 (let ((fill-column 20))
491 (end-of-line)
492 (org-auto-fill-function)
493 (buffer-string))))))
497 ;;; Indentation
499 (ert-deftest test-org/indent-line ()
500 "Test `org-indent-line' specifications."
501 ;; Do not indent footnote definitions or headlines.
502 (should
503 (zerop
504 (org-test-with-temp-text "* H"
505 (org-indent-line)
506 (org-get-indentation))))
507 (should
508 (zerop
509 (org-test-with-temp-text "[fn:1] fn"
510 (let ((org-adapt-indentation t)) (org-indent-line))
511 (org-get-indentation))))
512 ;; Do not indent before first headline.
513 (should
514 (zerop
515 (org-test-with-temp-text ""
516 (org-indent-line)
517 (org-get-indentation))))
518 ;; Indent according to headline level otherwise, unless
519 ;; `org-adapt-indentation' is nil.
520 (should
521 (= 2
522 (org-test-with-temp-text "* H\nA"
523 (forward-line)
524 (let ((org-adapt-indentation t)) (org-indent-line))
525 (org-get-indentation))))
526 (should
527 (= 2
528 (org-test-with-temp-text "* H\n\nA"
529 (forward-line)
530 (let ((org-adapt-indentation t)) (org-indent-line))
531 (org-get-indentation))))
532 (should
533 (zerop
534 (org-test-with-temp-text "* H\nA"
535 (forward-line)
536 (let ((org-adapt-indentation nil)) (org-indent-line))
537 (org-get-indentation))))
538 ;; Indenting preserves point position.
539 (should
540 (org-test-with-temp-text "* H\nAB"
541 (forward-line)
542 (forward-char)
543 (let ((org-adapt-indentation t)) (org-indent-line))
544 (looking-at "B")))
545 ;; Do not change indentation at an item.
546 (should
547 (= 1
548 (org-test-with-temp-text "* H\n - A"
549 (forward-line)
550 (let ((org-adapt-indentation t)) (org-indent-line))
551 (org-get-indentation))))
552 ;; On blank lines at the end of a list, indent like last element
553 ;; within it if the line is still in the list. Otherwise, indent
554 ;; like the whole list.
555 (should
556 (= 4
557 (org-test-with-temp-text "* H\n- A\n - AA\n"
558 (goto-char (point-max))
559 (let ((org-adapt-indentation t)) (org-indent-line))
560 (org-get-indentation))))
561 (should
562 (zerop
563 (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
564 (goto-char (point-max))
565 (let ((org-adapt-indentation t)) (org-indent-line))
566 (org-get-indentation))))
567 ;; Likewise, on a blank line at the end of a footnote definition,
568 ;; indent at column 0 if line belongs to the definition. Otherwise,
569 ;; indent like the definition itself.
570 (should
571 (zerop
572 (org-test-with-temp-text "* H\n[fn:1] Definition\n"
573 (goto-char (point-max))
574 (let ((org-adapt-indentation t)) (org-indent-line))
575 (org-get-indentation))))
576 (should
577 (zerop
578 (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
579 (goto-char (point-max))
580 (let ((org-adapt-indentation t)) (org-indent-line))
581 (org-get-indentation))))
582 ;; After the end of the contents of a greater element, indent like
583 ;; the beginning of the element.
584 (should
585 (= 1
586 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
587 (forward-line 2)
588 (org-indent-line)
589 (org-get-indentation))))
590 ;; At the first line of an element, indent like previous element's
591 ;; first line, ignoring footnotes definitions and inline tasks, or
592 ;; according to parent.
593 (should
594 (= 2
595 (org-test-with-temp-text "A\n\n B\n\nC"
596 (goto-char (point-max))
597 (org-indent-line)
598 (org-get-indentation))))
599 (should
600 (= 1
601 (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
602 (goto-char (point-max))
603 (org-indent-line)
604 (org-get-indentation))))
605 (should
606 (= 1
607 (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
608 (forward-line 1)
609 (org-indent-line)
610 (org-get-indentation))))
611 ;; Within code part of a source block, use language major mode if
612 ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
613 ;; according to line above.
614 (should
615 (= 6
616 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
617 (forward-line 2)
618 (let ((org-src-tab-acts-natively t)
619 (org-edit-src-content-indentation 0))
620 (org-indent-line))
621 (org-get-indentation))))
622 (should
623 (= 1
624 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
625 (forward-line 2)
626 (let ((org-src-tab-acts-natively nil)
627 (org-edit-src-content-indentation 0))
628 (org-indent-line))
629 (org-get-indentation))))
630 ;; Otherwise, indent like the first non-blank line above.
631 (should
632 (zerop
633 (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
634 (forward-line 3)
635 (org-indent-line)
636 (org-get-indentation))))
637 ;; Align node properties according to `org-property-format'. Handle
638 ;; nicely empty values.
639 (should
640 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
641 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
642 (let ((org-property-format "%-10s %s")) (org-indent-line))
643 (buffer-string))))
644 (should
645 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
646 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
647 (let ((org-property-format "%-10s %s")) (org-indent-line))
648 (buffer-string)))))
650 (ert-deftest test-org/indent-region ()
651 "Test `org-indent-region' specifications."
652 ;; Indent paragraph.
653 (should
654 (equal "A\nB\nC"
655 (org-test-with-temp-text " A\nB\n C"
656 (org-indent-region (point-min) (point-max))
657 (buffer-string))))
658 ;; Indent greater elements along with their contents.
659 (should
660 (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
661 (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
662 (org-indent-region (point-min) (point-max))
663 (buffer-string))))
664 ;; Ignore contents of verse blocks and example blocks.
665 (should
666 (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
667 (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
668 (org-indent-region (point-min) (point-max))
669 (buffer-string))))
670 (should
671 (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
672 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
673 (org-indent-region (point-min) (point-max))
674 (buffer-string))))
675 ;; Indent according to mode if `org-src-tab-acts-natively' is
676 ;; non-nil. Otherwise, do not indent code at all.
677 (should
678 (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
679 (org-test-with-temp-text
680 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
681 (let ((org-src-tab-acts-natively t)
682 (org-edit-src-content-indentation 0))
683 (org-indent-region (point-min) (point-max)))
684 (buffer-string))))
685 (should
686 (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
687 (org-test-with-temp-text
688 "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
689 (let ((org-src-tab-acts-natively nil)
690 (org-edit-src-content-indentation 0))
691 (org-indent-region (point-min) (point-max)))
692 (buffer-string))))
693 ;; Align node properties according to `org-property-format'. Handle
694 ;; nicely empty values.
695 (should
696 (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
697 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
698 (let ((org-property-format "%-10s %s")
699 (org-adapt-indentation nil))
700 (org-indent-region (point) (point-max)))
701 (buffer-string))))
702 (should
703 (equal "* H\n:PROPERTIES:\n:key:\n:END:"
704 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
705 (let ((org-property-format "%-10s %s")
706 (org-adapt-indentation nil))
707 (org-indent-region (point) (point-max)))
708 (buffer-string))))
709 ;; Indent plain lists.
710 (should
711 (equal "- A\n B\n - C\n\n D"
712 (org-test-with-temp-text "- A\n B\n - C\n\n D"
713 (org-indent-region (point-min) (point-max))
714 (buffer-string))))
715 (should
716 (equal "- A\n\n- B"
717 (org-test-with-temp-text " - A\n\n - B"
718 (org-indent-region (point-min) (point-max))
719 (buffer-string))))
720 ;; Indent footnote definitions.
721 (should
722 (equal "[fn:1] Definition\n\nDefinition"
723 (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
724 (org-indent-region (point-min) (point-max))
725 (buffer-string))))
726 ;; Special case: Start indenting on a blank line.
727 (should
728 (equal "\nParagraph"
729 (org-test-with-temp-text "\n Paragraph"
730 (org-indent-region (point-min) (point-max))
731 (buffer-string)))))
735 ;;; Editing
737 ;;;; Insert elements
739 (ert-deftest test-org/meta-return ()
740 "Test M-RET (`org-meta-return')."
741 ;; In a table field insert a row above.
742 (should
743 (org-test-with-temp-text "| a |"
744 (forward-char)
745 (org-meta-return)
746 (forward-line -1)
747 (looking-at "| |$")))
748 ;; In a paragraph change current line into a header.
749 (should
750 (org-test-with-temp-text "a"
751 (org-meta-return)
752 (beginning-of-line)
753 (looking-at "\* a$")))
754 ;; In an item insert an item, in this case above.
755 (should
756 (org-test-with-temp-text "- a"
757 (org-meta-return)
758 (beginning-of-line)
759 (looking-at "- $")))
760 ;; In a drawer and item insert an item, in this case above.
761 (should
762 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
763 (forward-line)
764 (org-meta-return)
765 (beginning-of-line)
766 (looking-at "- $"))))
768 (ert-deftest test-org/insert-heading ()
769 "Test `org-insert-heading' specifications."
770 ;; FIXME: Test coverage is incomplete yet.
772 ;; In an empty buffer, insert a new headline.
773 (should
774 (equal "* "
775 (org-test-with-temp-text ""
776 (org-insert-heading)
777 (buffer-string))))
778 ;; At the beginning of a line, turn it into a headline
779 (should
780 (equal "* P"
781 (org-test-with-temp-text "<point>P"
782 (org-insert-heading)
783 (buffer-string))))
784 ;; In the middle of a line, split the line if allowed, otherwise,
785 ;; insert the headline at its end.
786 (should
787 (equal "Para\n* graph"
788 (org-test-with-temp-text "Para<point>graph"
789 (let ((org-M-RET-may-split-line '((default . t))))
790 (org-insert-heading))
791 (buffer-string))))
792 (should
793 (equal "Paragraph\n* "
794 (org-test-with-temp-text "Para<point>graph"
795 (let ((org-M-RET-may-split-line '((default . nil))))
796 (org-insert-heading))
797 (buffer-string))))
798 ;; Corner case: correctly insert a headline after an empty one.
799 (should
800 (equal "* \n* "
801 (org-test-with-temp-text "* <point>"
802 (org-insert-heading)
803 (buffer-string)))))
805 (ert-deftest test-org/insert-todo-heading-respect-content ()
806 "Test `org-insert-todo-heading-respect-content' specifications."
807 ;; Create a TODO heading.
808 (should
809 (org-test-with-temp-text "* H1\n Body"
810 (org-insert-todo-heading-respect-content)
811 (nth 2 (org-heading-components))))
812 ;; Add headline at the end of the first subtree
813 (should
814 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
815 (search-forward "H1Body")
816 (org-insert-todo-heading-respect-content)
817 (and (eobp) (org-at-heading-p))))
818 ;; In a list, do not create a new item.
819 (should
820 (org-test-with-temp-text "* H\n- an item\n- another one"
821 (search-forward "an ")
822 (org-insert-todo-heading-respect-content)
823 (and (eobp) (org-at-heading-p)))))
827 ;;; Fixed-Width Areas
829 (ert-deftest test-org/toggle-fixed-width ()
830 "Test `org-toggle-fixed-width' specifications."
831 ;; No region: Toggle on fixed-width marker in paragraphs.
832 (should
833 (equal ": A"
834 (org-test-with-temp-text "A"
835 (org-toggle-fixed-width)
836 (buffer-string))))
837 ;; No region: Toggle off fixed-width markers in fixed-width areas.
838 (should
839 (equal "A"
840 (org-test-with-temp-text ": A"
841 (org-toggle-fixed-width)
842 (buffer-string))))
843 ;; No region: Toggle on marker in blank lines after elements or just
844 ;; after a headline.
845 (should
846 (equal "* H\n: "
847 (org-test-with-temp-text "* H\n"
848 (forward-line)
849 (org-toggle-fixed-width)
850 (buffer-string))))
851 (should
852 (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
853 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
854 (goto-char (point-max))
855 (org-toggle-fixed-width)
856 (buffer-string))))
857 ;; No region: Toggle on marker in front of one line elements (e.g.,
858 ;; headlines, clocks)
859 (should
860 (equal ": * Headline"
861 (org-test-with-temp-text "* Headline"
862 (org-toggle-fixed-width)
863 (buffer-string))))
864 (should
865 (equal ": #+KEYWORD: value"
866 (org-test-with-temp-text "#+KEYWORD: value"
867 (org-toggle-fixed-width)
868 (buffer-string))))
869 ;; No region: error in other situations.
870 (should-error
871 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
872 (forward-line)
873 (org-toggle-fixed-width)
874 (buffer-string)))
875 ;; No region: Indentation is preserved.
876 (should
877 (equal "- A\n : B"
878 (org-test-with-temp-text "- A\n B"
879 (forward-line)
880 (org-toggle-fixed-width)
881 (buffer-string))))
882 ;; Region: If it contains only fixed-width elements and blank lines,
883 ;; toggle off fixed-width markup.
884 (should
885 (equal "A\n\nB"
886 (org-test-with-temp-text ": A\n\n: B"
887 (transient-mark-mode 1)
888 (push-mark (point) t t)
889 (goto-char (point-max))
890 (org-toggle-fixed-width)
891 (buffer-string))))
892 ;; Region: If it contains anything else, toggle on fixed-width but
893 ;; not on fixed-width areas.
894 (should
895 (equal ": A\n: \n: B\n: \n: C"
896 (org-test-with-temp-text "A\n\n: B\n\nC"
897 (transient-mark-mode 1)
898 (push-mark (point) t t)
899 (goto-char (point-max))
900 (org-toggle-fixed-width)
901 (buffer-string))))
902 ;; Region: Ignore blank lines at its end, unless it contains only
903 ;; such lines.
904 (should
905 (equal ": A\n\n"
906 (org-test-with-temp-text "A\n\n"
907 (transient-mark-mode 1)
908 (push-mark (point) t t)
909 (goto-char (point-max))
910 (org-toggle-fixed-width)
911 (buffer-string))))
912 (should
913 (equal ": \n: \n"
914 (org-test-with-temp-text "\n\n"
915 (transient-mark-mode 1)
916 (push-mark (point) t t)
917 (goto-char (point-max))
918 (org-toggle-fixed-width)
919 (buffer-string)))))
923 ;;; Headline
925 (ert-deftest test-org/in-commented-heading-p ()
926 "Test `org-in-commented-heading-p' specifications."
927 ;; Commented headline.
928 (should
929 (org-test-with-temp-text "* COMMENT Headline\nBody"
930 (goto-char (point-max))
931 (org-in-commented-heading-p)))
932 ;; Commented ancestor.
933 (should
934 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
935 (goto-char (point-max))
936 (org-in-commented-heading-p)))
937 ;; Comment keyword is case-sensitive.
938 (should-not
939 (org-test-with-temp-text "* Comment Headline\nBody"
940 (goto-char (point-max))
941 (org-in-commented-heading-p)))
942 ;; Keyword is standalone.
943 (should-not
944 (org-test-with-temp-text "* COMMENTHeadline\nBody"
945 (goto-char (point-max))
946 (org-in-commented-heading-p)))
947 ;; Optional argument.
948 (should-not
949 (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
950 (goto-char (point-max))
951 (org-in-commented-heading-p t))))
955 ;;; Keywords
957 (ert-deftest test-org/set-regexps-and-options ()
958 "Test `org-set-regexps-and-options' specifications."
959 ;; TAGS keyword.
960 (should
961 (equal '(("A" . ?a) ("B") ("C"))
962 (org-test-with-temp-text "#+TAGS: A(a) B C"
963 (org-mode-restart)
964 org-tag-alist)))
965 (should
966 (equal '(("A") (:newline) ("B"))
967 (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
968 (org-mode-restart)
969 org-tag-alist)))
970 (should
971 (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
972 (org-test-with-temp-text "#+TAGS: { A B } C"
973 (org-mode-restart)
974 org-tag-alist)))
975 (should
976 (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
977 (org-test-with-temp-text "#+TAGS: { A : B C }"
978 (org-mode-restart)
979 org-tag-alist)))
980 (should
981 (equal '(("A" "B" "C"))
982 (org-test-with-temp-text "#+TAGS: { A : B C }"
983 (org-mode-restart)
984 org-tag-groups-alist)))
985 ;; FILETAGS keyword.
986 (should
987 (equal '("A" "B" "C")
988 (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
989 (org-mode-restart)
990 org-file-tags)))
991 ;; PROPERTY keyword. Property names are case-insensitive.
992 (should
993 (equal "foo=1"
994 (org-test-with-temp-text "#+PROPERTY: var foo=1"
995 (org-mode-restart)
996 (cdr (assoc "var" org-file-properties)))))
997 (should
998 (equal
999 "foo=1 bar=2"
1000 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
1001 (org-mode-restart)
1002 (cdr (assoc "var" org-file-properties)))))
1003 (should
1004 (equal
1005 "foo=1 bar=2"
1006 (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
1007 (org-mode-restart)
1008 (cdr (assoc "var" org-file-properties)))))
1009 ;; ARCHIVE keyword.
1010 (should
1011 (equal "%s_done::"
1012 (org-test-with-temp-text "#+ARCHIVE: %s_done::"
1013 (org-mode-restart)
1014 org-archive-location)))
1015 ;; CATEGORY keyword.
1016 (should
1017 (eq 'test
1018 (org-test-with-temp-text "#+CATEGORY: test"
1019 (org-mode-restart)
1020 org-category)))
1021 (should
1022 (equal "test"
1023 (org-test-with-temp-text "#+CATEGORY: test"
1024 (org-mode-restart)
1025 (cdr (assoc "CATEGORY" org-file-properties)))))
1026 ;; COLUMNS keyword.
1027 (should
1028 (equal "%25ITEM %TAGS %PRIORITY %TODO"
1029 (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
1030 (org-mode-restart)
1031 org-columns-default-format)))
1032 ;; CONSTANTS keyword. Constants names are case sensitive.
1033 (should
1034 (equal '("299792458." "3.14")
1035 (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
1036 (org-mode-restart)
1037 (mapcar
1038 (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
1039 '("c" "pi")))))
1040 (should
1041 (equal "3.14"
1042 (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
1043 (org-mode-restart)
1044 (cdr (assoc "pi" org-table-formula-constants-local)))))
1045 (should
1046 (equal "22/7"
1047 (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
1048 (org-mode-restart)
1049 (cdr (assoc "PI" org-table-formula-constants-local)))))
1050 ;; LINK keyword.
1051 (should
1052 (equal
1053 '("url1" "url2")
1054 (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
1055 (org-mode-restart)
1056 (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
1057 '("a" "b")))))
1058 ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
1059 (should
1060 (equal
1061 '(?X ?Z ?Y)
1062 (org-test-with-temp-text "#+PRIORITIES: X Z Y"
1063 (org-mode-restart)
1064 (list org-highest-priority org-lowest-priority org-default-priority))))
1065 (should
1066 (equal
1067 '(?A ?C ?B)
1068 (org-test-with-temp-text "#+PRIORITIES: X Z"
1069 (org-mode-restart)
1070 (list org-highest-priority org-lowest-priority org-default-priority))))
1071 ;; STARTUP keyword.
1072 (should
1073 (equal '(t t)
1074 (org-test-with-temp-text "#+STARTUP: fold odd"
1075 (org-mode-restart)
1076 (list org-startup-folded org-odd-levels-only))))
1077 ;; TODO keywords.
1078 (should
1079 (equal '(("A" "B") ("C"))
1080 (org-test-with-temp-text "#+TODO: A B | C"
1081 (org-mode-restart)
1082 (list org-not-done-keywords org-done-keywords))))
1083 (should
1084 (equal '(("A" "C") ("B" "D"))
1085 (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
1086 (org-mode-restart)
1087 (list org-not-done-keywords org-done-keywords))))
1088 (should
1089 (equal '(("A" "B") ("C"))
1090 (org-test-with-temp-text "#+TYP_TODO: A B | C"
1091 (org-mode-restart)
1092 (list org-not-done-keywords org-done-keywords))))
1093 (should
1094 (equal '((:startgroup) ("A" . ?a) (:endgroup))
1095 (org-test-with-temp-text "#+TODO: A(a)"
1096 (org-mode-restart)
1097 org-todo-key-alist)))
1098 (should
1099 (equal '(("D" note nil) ("C" time nil) ("B" note time))
1100 (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
1101 (org-mode-restart)
1102 org-todo-log-states)))
1103 ;; Enter SETUPFILE keyword.
1104 (should
1105 (equal "1"
1106 (org-test-with-temp-text
1107 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
1108 (org-mode-restart)
1109 (cdr (assoc "a" org-file-properties))))))
1113 ;;; Links
1115 ;;;; Coderefs
1117 (ert-deftest test-org/coderef ()
1118 "Test coderef links specifications."
1119 (should
1120 (org-test-with-temp-text "
1121 #+BEGIN_SRC emacs-lisp
1122 \(+ 1 1) (ref:sc)
1123 #+END_SRC
1124 \[[(sc)]]"
1125 (goto-char (point-max))
1126 (org-open-at-point)
1127 (looking-at "(ref:sc)"))))
1129 ;;;; Custom ID
1131 (ert-deftest test-org/custom-id ()
1132 "Test custom ID links specifications."
1133 (should
1134 (org-test-with-temp-text
1135 "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
1136 (goto-char (point-max))
1137 (org-open-at-point)
1138 (org-looking-at-p "\\* H1"))))
1140 ;;;; Fuzzy Links
1142 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
1143 ;; a named element (#+name: text) and to headlines (* Text).
1145 (ert-deftest test-org/fuzzy-links ()
1146 "Test fuzzy links specifications."
1147 ;; Fuzzy link goes in priority to a matching target.
1148 (should
1149 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
1150 (goto-line 5)
1151 (org-open-at-point)
1152 (looking-at "<<Test>>")))
1153 ;; Then fuzzy link points to an element with a given name.
1154 (should
1155 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
1156 (goto-line 5)
1157 (org-open-at-point)
1158 (looking-at "#\\+NAME: Test")))
1159 ;; A target still lead to a matching headline otherwise.
1160 (should
1161 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
1162 (goto-line 4)
1163 (org-open-at-point)
1164 (looking-at "\\* Head2")))
1165 ;; With a leading star in link, enforce heading match.
1166 (should
1167 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
1168 (goto-line 3)
1169 (org-open-at-point)
1170 (looking-at "\\* Test")))
1171 ;; Correctly un-hexify fuzzy links.
1172 (should
1173 (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
1174 (goto-char (point-max))
1175 (org-open-at-point)
1176 (bobp))))
1178 ;;;; Link Escaping
1180 (ert-deftest test-org/org-link-escape-ascii-character ()
1181 "Escape an ascii character."
1182 (should
1183 (string=
1184 "%5B"
1185 (org-link-escape "["))))
1187 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
1188 "Escape an ascii control character."
1189 (should
1190 (string=
1191 "%09"
1192 (org-link-escape "\t"))))
1194 (ert-deftest test-org/org-link-escape-multibyte-character ()
1195 "Escape an unicode multibyte character."
1196 (should
1197 (string=
1198 "%E2%82%AC"
1199 (org-link-escape "€"))))
1201 (ert-deftest test-org/org-link-escape-custom-table ()
1202 "Escape string with custom character table."
1203 (should
1204 (string=
1205 "Foo%3A%42ar%0A"
1206 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
1208 (ert-deftest test-org/org-link-escape-custom-table-merge ()
1209 "Escape string with custom table merged with default table."
1210 (should
1211 (string=
1212 "%5BF%6F%6F%3A%42ar%0A%5D"
1213 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
1215 (ert-deftest test-org/org-link-unescape-ascii-character ()
1216 "Unescape an ascii character."
1217 (should
1218 (string=
1220 (org-link-unescape "%5B"))))
1222 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
1223 "Unescpae an ascii control character."
1224 (should
1225 (string=
1226 "\n"
1227 (org-link-unescape "%0A"))))
1229 (ert-deftest test-org/org-link-unescape-multibyte-character ()
1230 "Unescape unicode multibyte character."
1231 (should
1232 (string=
1233 "€"
1234 (org-link-unescape "%E2%82%AC"))))
1236 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
1237 "Unescape old style percent escaped character."
1238 (should
1239 (string=
1240 "àâçèéêîôùû"
1241 (decode-coding-string
1242 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
1244 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
1245 "Escape and unescape a URL that includes an escaped char.
1246 http://article.gmane.org/gmane.emacs.orgmode/21459/"
1247 (should
1248 (string=
1249 "http://some.host.com/form?&id=blah%2Bblah25"
1250 (org-link-unescape
1251 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
1253 (ert-deftest test-org/org-link-escape-chars-browser ()
1254 "Test of the constant `org-link-escape-chars-browser'.
1255 See there why this test is a candidate to be removed once Org
1256 drops support for Emacs 24.1 and 24.2."
1257 (should
1258 (string=
1259 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1260 "%22Release%208.2%22&idxname=emacs-orgmode")
1261 (org-link-escape-browser ; Do not replace with `url-encode-url',
1262 ; see docstring above.
1263 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
1264 "\"Release 8.2\"&idxname=emacs-orgmode")))))
1266 ;;;; Open at point
1268 (ert-deftest test-org/open-at-point-in-property ()
1269 "Does `org-open-at-point' open link in property drawer?"
1270 (should
1271 (org-test-with-temp-text
1272 "* Headline
1273 :PROPERTIES:
1274 :URL: <point>[[info:emacs#Top]]
1275 :END:"
1276 (org-open-at-point) t)))
1278 (ert-deftest test-org/open-at-point-in-comment ()
1279 "Does `org-open-at-point' open link in a commented line?"
1280 (should
1281 (org-test-with-temp-text
1282 "# <point>[[info:emacs#Top]]"
1283 (org-open-at-point) t)))
1285 (ert-deftest test-org/open-at-point/info ()
1286 "Test `org-open-at-point' on info links."
1287 (should
1288 (org-test-with-temp-text
1289 "<point>[[info:emacs#Top]]"
1290 (org-open-at-point)
1291 (and (switch-to-buffer "*info*")
1292 (prog1
1293 (looking-at "\nThe Emacs Editor")
1294 (kill-buffer))))))
1297 ;;; Node Properties
1299 (ert-deftest test-org/accumulated-properties-in-drawers ()
1300 "Ensure properties accumulate in subtree drawers."
1301 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
1302 (org-babel-next-src-block)
1303 (should (equal '(2 1) (org-babel-execute-src-block)))))
1305 (ert-deftest test-org/custom-properties ()
1306 "Test custom properties specifications."
1307 ;; Standard test.
1308 (should
1309 (let ((org-custom-properties '("FOO")))
1310 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1311 (org-toggle-custom-properties-visibility)
1312 (org-invisible-p2))))
1313 ;; Properties are case-insensitive.
1314 (should
1315 (let ((org-custom-properties '("FOO")))
1316 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
1317 (org-toggle-custom-properties-visibility)
1318 (org-invisible-p2))))
1319 (should
1320 (let ((org-custom-properties '("foo")))
1321 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
1322 (org-toggle-custom-properties-visibility)
1323 (org-invisible-p2))))
1324 ;; Multiple custom properties in the same drawer.
1325 (should
1326 (let ((org-custom-properties '("FOO" "BAR")))
1327 (org-test-with-temp-text
1328 "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
1329 (org-toggle-custom-properties-visibility)
1330 (and (org-invisible-p2)
1331 (not (progn (forward-line) (org-invisible-p2)))
1332 (progn (forward-line) (org-invisible-p2))))))
1333 ;; Hide custom properties with an empty value.
1334 (should
1335 (let ((org-custom-properties '("FOO")))
1336 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
1337 (org-toggle-custom-properties-visibility)
1338 (org-invisible-p2))))
1339 ;; Do not hide fake properties.
1340 (should-not
1341 (let ((org-custom-properties '("FOO")))
1342 (org-test-with-temp-text ":FOO: val\n"
1343 (org-toggle-custom-properties-visibility)
1344 (org-invisible-p2))))
1345 (should-not
1346 (let ((org-custom-properties '("A")))
1347 (org-test-with-temp-text
1348 "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
1349 (org-toggle-custom-properties-visibility)
1350 (org-invisible-p2)))))
1354 ;;; Mark Region
1356 (ert-deftest test-org/mark-subtree ()
1357 "Test `org-mark-subtree' specifications."
1358 ;; Error when point is before first headline.
1359 (should-error
1360 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
1361 (progn (transient-mark-mode 1)
1362 (org-mark-subtree))))
1363 ;; Without argument, mark current subtree.
1364 (should
1365 (equal
1366 '(12 32)
1367 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1368 (progn (transient-mark-mode 1)
1369 (forward-line 2)
1370 (org-mark-subtree)
1371 (list (region-beginning) (region-end))))))
1372 ;; With an argument, move ARG up.
1373 (should
1374 (equal
1375 '(1 32)
1376 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
1377 (progn (transient-mark-mode 1)
1378 (forward-line 2)
1379 (org-mark-subtree 1)
1380 (list (region-beginning) (region-end))))))
1381 ;; Do not get fooled by inlinetasks.
1382 (when (featurep 'org-inlinetask)
1383 (should
1384 (= 1
1385 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
1386 (progn (transient-mark-mode 1)
1387 (forward-line 1)
1388 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
1389 (region-beginning)))))))
1393 ;;; Navigation
1395 (ert-deftest test-org/beginning-of-line ()
1396 "Test `org-beginning-of-line' specifications."
1397 ;; Standard test.
1398 (should
1399 (org-test-with-temp-text "Some text\nSome other text"
1400 (progn (org-beginning-of-line) (bolp))))
1401 ;; Standard test with `visual-line-mode'.
1402 (should-not
1403 (org-test-with-temp-text "A long line of text\nSome other text"
1404 (progn (visual-line-mode)
1405 (forward-char 2)
1406 (dotimes (i 1000) (insert "very "))
1407 (org-beginning-of-line)
1408 (bolp))))
1409 ;; At an headline with special movement.
1410 (should
1411 (org-test-with-temp-text "* TODO Headline"
1412 (let ((org-special-ctrl-a/e t))
1413 (org-end-of-line)
1414 (and (progn (org-beginning-of-line) (looking-at "Headline"))
1415 (progn (org-beginning-of-line) (bolp))
1416 (progn (org-beginning-of-line) (looking-at "Headline")))))))
1418 (ert-deftest test-org/end-of-line ()
1419 "Test `org-end-of-line' specifications."
1420 ;; Standard test.
1421 (should
1422 (org-test-with-temp-text "Some text\nSome other text"
1423 (progn (org-end-of-line) (eolp))))
1424 ;; Standard test with `visual-line-mode'.
1425 (should-not
1426 (org-test-with-temp-text "A long line of text\nSome other text"
1427 (progn (visual-line-mode)
1428 (forward-char 2)
1429 (dotimes (i 1000) (insert "very "))
1430 (goto-char (point-min))
1431 (org-end-of-line)
1432 (eolp))))
1433 ;; At an headline with special movement.
1434 (should
1435 (org-test-with-temp-text "* Headline1 :tag:\n"
1436 (let ((org-special-ctrl-a/e t))
1437 (and (progn (org-end-of-line) (looking-at " :tag:"))
1438 (progn (org-end-of-line) (eolp))
1439 (progn (org-end-of-line) (looking-at " :tag:"))))))
1440 ;; At an headline without special movement.
1441 (should
1442 (org-test-with-temp-text "* Headline2 :tag:\n"
1443 (let ((org-special-ctrl-a/e nil))
1444 (and (progn (org-end-of-line) (eolp))
1445 (progn (org-end-of-line) (eolp))))))
1446 ;; At an headline, with reversed movement.
1447 (should
1448 (org-test-with-temp-text "* Headline3 :tag:\n"
1449 (let ((org-special-ctrl-a/e 'reversed)
1450 (this-command last-command))
1451 (and (progn (org-end-of-line) (eolp))
1452 (progn (org-end-of-line) (looking-at " :tag:"))))))
1453 ;; At a block without hidden contents.
1454 (should
1455 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1456 (progn (org-end-of-line) (eolp))))
1457 ;; At a block with hidden contents.
1458 (should-not
1459 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
1460 (let ((org-special-ctrl-a/e t))
1461 (org-hide-block-toggle)
1462 (org-end-of-line)
1463 (eobp)))))
1465 (ert-deftest test-org/forward-paragraph ()
1466 "Test `org-forward-paragraph' specifications."
1467 ;; At end of buffer, return an error.
1468 (should-error
1469 (org-test-with-temp-text "Paragraph"
1470 (goto-char (point-max))
1471 (org-forward-paragraph)))
1472 ;; Standard test.
1473 (should
1474 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1475 (org-forward-paragraph)
1476 (looking-at "P2")))
1477 ;; Ignore depth.
1478 (should
1479 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
1480 (org-forward-paragraph)
1481 (looking-at "P1")))
1482 ;; Do not enter elements with invisible contents.
1483 (should
1484 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
1485 (org-hide-block-toggle)
1486 (org-forward-paragraph)
1487 (looking-at "P3")))
1488 ;; On an affiliated keyword, jump to the beginning of the element.
1489 (should
1490 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
1491 (org-forward-paragraph)
1492 (looking-at "Para")))
1493 ;; On an item or a footnote definition, move to the second element
1494 ;; inside, if any.
1495 (should
1496 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
1497 (org-forward-paragraph)
1498 (looking-at " Paragraph")))
1499 (should
1500 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
1501 (org-forward-paragraph)
1502 (looking-at "Paragraph")))
1503 ;; On an item, or a footnote definition, when the first line is
1504 ;; empty, move to the first item.
1505 (should
1506 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
1507 (org-forward-paragraph)
1508 (looking-at " Paragraph")))
1509 (should
1510 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
1511 (org-forward-paragraph)
1512 (looking-at "Paragraph")))
1513 ;; On a table (resp. a property drawer) do not move through table
1514 ;; rows (resp. node properties).
1515 (should
1516 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
1517 (org-forward-paragraph)
1518 (looking-at "Paragraph")))
1519 (should
1520 (org-test-with-temp-text
1521 "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
1522 (org-forward-paragraph)
1523 (looking-at "Paragraph")))
1524 ;; On a verse or source block, stop after blank lines.
1525 (should
1526 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
1527 (org-forward-paragraph)
1528 (looking-at "L2")))
1529 (should
1530 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
1531 (org-forward-paragraph)
1532 (looking-at "L2"))))
1534 (ert-deftest test-org/backward-paragraph ()
1535 "Test `org-backward-paragraph' specifications."
1536 ;; Error at beginning of buffer.
1537 (should-error
1538 (org-test-with-temp-text "Paragraph"
1539 (org-backward-paragraph)))
1540 ;; Regular test.
1541 (should
1542 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1543 (goto-char (point-max))
1544 (org-backward-paragraph)
1545 (looking-at "P3")))
1546 (should
1547 (org-test-with-temp-text "P1\n\nP2\n\nP3"
1548 (goto-char (point-max))
1549 (beginning-of-line)
1550 (org-backward-paragraph)
1551 (looking-at "P2")))
1552 ;; Ignore depth.
1553 (should
1554 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
1555 (goto-char (point-max))
1556 (beginning-of-line)
1557 (org-backward-paragraph)
1558 (looking-at "P2")))
1559 ;; Ignore invisible elements.
1560 (should
1561 (org-test-with-temp-text "* H1\n P1\n* H2"
1562 (org-cycle)
1563 (goto-char (point-max))
1564 (beginning-of-line)
1565 (org-backward-paragraph)
1566 (bobp)))
1567 ;; On an affiliated keyword, jump to the first one.
1568 (should
1569 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
1570 (search-forward "c2")
1571 (org-backward-paragraph)
1572 (looking-at "#\\+name")))
1573 ;; On the second element in an item or a footnote definition, jump
1574 ;; to item or the definition.
1575 (should
1576 (org-test-with-temp-text "- line1\n\n line2"
1577 (goto-char (point-max))
1578 (beginning-of-line)
1579 (org-backward-paragraph)
1580 (looking-at "- line1")))
1581 (should
1582 (org-test-with-temp-text "[fn:1] line1\n\n line2"
1583 (goto-char (point-max))
1584 (beginning-of-line)
1585 (org-backward-paragraph)
1586 (looking-at "\\[fn:1\\] line1")))
1587 ;; On a table (resp. a property drawer), ignore table rows
1588 ;; (resp. node properties).
1589 (should
1590 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
1591 (goto-char (point-max))
1592 (beginning-of-line)
1593 (org-backward-paragraph)
1594 (bobp)))
1595 (should
1596 (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
1597 (org-backward-paragraph)
1598 (looking-at ":PROPERTIES:")))
1599 ;; On a source or verse block, stop before blank lines.
1600 (should
1601 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
1602 (search-forward "L3")
1603 (beginning-of-line)
1604 (org-backward-paragraph)
1605 (looking-at "L2")))
1606 (should
1607 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
1608 (search-forward "L3")
1609 (beginning-of-line)
1610 (org-backward-paragraph)
1611 (looking-at "L2"))))
1613 (ert-deftest test-org/forward-element ()
1614 "Test `org-forward-element' specifications."
1615 ;; 1. At EOB: should error.
1616 (org-test-with-temp-text "Some text\n"
1617 (goto-char (point-max))
1618 (should-error (org-forward-element)))
1619 ;; 2. Standard move: expected to ignore blank lines.
1620 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
1621 (org-forward-element)
1622 (should (looking-at (regexp-quote "Second paragraph."))))
1623 ;; 3. Headline tests.
1624 (org-test-with-temp-text "
1625 * Head 1
1626 ** Head 1.1
1627 *** Head 1.1.1
1628 ** Head 1.2"
1629 ;; 3.1. At an headline beginning: move to next headline at the
1630 ;; same level.
1631 (goto-line 3)
1632 (org-forward-element)
1633 (should (looking-at (regexp-quote "** Head 1.2")))
1634 ;; 3.2. At an headline beginning: move to parent headline if no
1635 ;; headline at the same level.
1636 (goto-line 3)
1637 (org-forward-element)
1638 (should (looking-at (regexp-quote "** Head 1.2"))))
1639 ;; 4. Greater element tests.
1640 (org-test-with-temp-text
1641 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
1642 ;; 4.1. At a greater element: expected to skip contents.
1643 (org-forward-element)
1644 (should (looking-at (regexp-quote "Outside.")))
1645 ;; 4.2. At the end of greater element contents: expected to skip
1646 ;; to the end of the greater element.
1647 (goto-line 2)
1648 (org-forward-element)
1649 (should (looking-at (regexp-quote "Outside."))))
1650 ;; 5. List tests.
1651 (org-test-with-temp-text "
1652 - item1
1654 - sub1
1656 - sub2
1658 - sub3
1660 Inner paragraph.
1662 - item2
1664 Outside."
1665 ;; 5.1. At list top point: expected to move to the element after
1666 ;; the list.
1667 (goto-line 2)
1668 (org-forward-element)
1669 (should (looking-at (regexp-quote "Outside.")))
1670 ;; 5.2. Special case: at the first line of a sub-list, but not at
1671 ;; beginning of line, move to next item.
1672 (goto-line 2)
1673 (forward-char)
1674 (org-forward-element)
1675 (should (looking-at "- item2"))
1676 (goto-line 4)
1677 (forward-char)
1678 (org-forward-element)
1679 (should (looking-at " - sub2"))
1680 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
1681 (goto-line 4)
1682 (org-forward-element)
1683 (should (looking-at (regexp-quote " Inner paragraph.")))
1684 ;; 5.4. At sub-list end: expected to move outside the sub-list.
1685 (goto-line 8)
1686 (org-forward-element)
1687 (should (looking-at (regexp-quote " Inner paragraph.")))
1688 ;; 5.5. At an item: expected to move to next item, if any.
1689 (goto-line 6)
1690 (org-forward-element)
1691 (should (looking-at " - sub3"))))
1693 (ert-deftest test-org/backward-element ()
1694 "Test `org-backward-element' specifications."
1695 ;; 1. Should error at BOB.
1696 (org-test-with-temp-text " \nParagraph."
1697 (should-error (org-backward-element)))
1698 ;; 2. Should move at BOB when called on the first element in buffer.
1699 (should
1700 (org-test-with-temp-text "\n#+TITLE: test"
1701 (progn (forward-line)
1702 (org-backward-element)
1703 (bobp))))
1704 ;; 3. Not at the beginning of an element: move at its beginning.
1705 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1706 (goto-line 3)
1707 (end-of-line)
1708 (org-backward-element)
1709 (should (looking-at (regexp-quote "Paragraph2."))))
1710 ;; 4. Headline tests.
1711 (org-test-with-temp-text "
1712 * Head 1
1713 ** Head 1.1
1714 *** Head 1.1.1
1715 ** Head 1.2"
1716 ;; 4.1. At an headline beginning: move to previous headline at the
1717 ;; same level.
1718 (goto-line 5)
1719 (org-backward-element)
1720 (should (looking-at (regexp-quote "** Head 1.1")))
1721 ;; 4.2. At an headline beginning: move to parent headline if no
1722 ;; headline at the same level.
1723 (goto-line 3)
1724 (org-backward-element)
1725 (should (looking-at (regexp-quote "* Head 1")))
1726 ;; 4.3. At the first top-level headline: should error.
1727 (goto-line 2)
1728 (should-error (org-backward-element)))
1729 ;; 5. At beginning of first element inside a greater element:
1730 ;; expected to move to greater element's beginning.
1731 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
1732 (goto-line 3)
1733 (org-backward-element)
1734 (should (looking-at "#\\+BEGIN_CENTER")))
1735 ;; 6. At the beginning of the first element in a section: should
1736 ;; move back to headline, if any.
1737 (should
1738 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
1739 (progn (goto-char (point-max))
1740 (beginning-of-line)
1741 (org-backward-element)
1742 (org-at-heading-p))))
1743 ;; 7. List tests.
1744 (org-test-with-temp-text "
1745 - item1
1747 - sub1
1749 - sub2
1751 - sub3
1753 Inner paragraph.
1755 - item2
1758 Outside."
1759 ;; 7.1. At beginning of sub-list: expected to move to the
1760 ;; paragraph before it.
1761 (goto-line 4)
1762 (org-backward-element)
1763 (should (looking-at "item1"))
1764 ;; 7.2. At an item in a list: expected to move at previous item.
1765 (goto-line 8)
1766 (org-backward-element)
1767 (should (looking-at " - sub2"))
1768 (goto-line 12)
1769 (org-backward-element)
1770 (should (looking-at "- item1"))
1771 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1772 ;; beginning.
1773 (goto-line 10)
1774 (org-backward-element)
1775 (should (looking-at " - sub1"))
1776 (goto-line 15)
1777 (org-backward-element)
1778 (should (looking-at "- item1"))
1779 ;; 7.4. At blank-lines before list end: expected to move to top
1780 ;; item.
1781 (goto-line 14)
1782 (org-backward-element)
1783 (should (looking-at "- item1"))))
1785 (ert-deftest test-org/up-element ()
1786 "Test `org-up-element' specifications."
1787 ;; 1. At BOB or with no surrounding element: should error.
1788 (org-test-with-temp-text "Paragraph."
1789 (should-error (org-up-element)))
1790 (org-test-with-temp-text "* Head1\n* Head2"
1791 (goto-line 2)
1792 (should-error (org-up-element)))
1793 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1794 (goto-line 3)
1795 (should-error (org-up-element)))
1796 ;; 2. At an headline: move to parent headline.
1797 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1798 (goto-line 3)
1799 (org-up-element)
1800 (should (looking-at "\\* Head1")))
1801 ;; 3. Inside a greater element: move to greater element beginning.
1802 (org-test-with-temp-text
1803 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1804 (goto-line 3)
1805 (org-up-element)
1806 (should (looking-at "#\\+BEGIN_CENTER")))
1807 ;; 4. List tests.
1808 (org-test-with-temp-text "* Top
1809 - item1
1811 - sub1
1813 - sub2
1815 Paragraph within sub2.
1817 - item2"
1818 ;; 4.1. Within an item: move to the item beginning.
1819 (goto-line 8)
1820 (org-up-element)
1821 (should (looking-at " - sub2"))
1822 ;; 4.2. At an item in a sub-list: move to parent item.
1823 (goto-line 4)
1824 (org-up-element)
1825 (should (looking-at "- item1"))
1826 ;; 4.3. At an item in top list: move to beginning of whole list.
1827 (goto-line 10)
1828 (org-up-element)
1829 (should (looking-at "- item1"))
1830 ;; 4.4. Special case. At very top point: should move to parent of
1831 ;; list.
1832 (goto-line 2)
1833 (org-up-element)
1834 (should (looking-at "\\* Top"))))
1836 (ert-deftest test-org/down-element ()
1837 "Test `org-down-element' specifications."
1838 ;; Error when the element hasn't got a recursive type.
1839 (org-test-with-temp-text "Paragraph."
1840 (should-error (org-down-element)))
1841 ;; Error when the element has no contents
1842 (org-test-with-temp-text "* Headline"
1843 (should-error (org-down-element)))
1844 ;; When at a plain-list, move to first item.
1845 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1846 (goto-line 2)
1847 (org-down-element)
1848 (should (looking-at " - Item 1.1")))
1849 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1850 (org-down-element)
1851 (should (looking-at " Item 1")))
1852 ;; When at a table, move to first row
1853 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1854 (org-down-element)
1855 (should (looking-at " a | b |")))
1856 ;; Otherwise, move inside the greater element.
1857 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1858 (org-down-element)
1859 (should (looking-at "Paragraph"))))
1861 (ert-deftest test-org/drag-element-backward ()
1862 "Test `org-drag-element-backward' specifications."
1863 ;; Standard test.
1864 (should
1865 (equal
1866 "#+key2: val2\n#+key1: val1\n#+key3: val3"
1867 (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
1868 (org-drag-element-backward)
1869 (buffer-string))))
1870 (should
1871 (equal
1872 "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
1873 (org-test-with-temp-text
1874 "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
1875 (org-drag-element-backward)
1876 (buffer-string))))
1877 ;; Preserve blank lines.
1878 (should
1879 (equal "Paragraph 2\n\n\nPara1\n\nPara3"
1880 (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
1881 (org-drag-element-backward)
1882 (buffer-string))))
1883 ;; Preserve column.
1884 (should
1885 (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
1886 (org-drag-element-backward)
1887 (org-looking-at-p "2")))
1888 ;; Error when trying to move first element of buffer.
1889 (should-error
1890 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1891 (org-drag-element-backward)))
1892 ;; Error when trying to swap nested elements.
1893 (should-error
1894 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1895 (forward-line)
1896 (org-drag-element-backward)))
1897 ;; Error when trying to swap an headline element and a non-headline
1898 ;; element.
1899 (should-error
1900 (org-test-with-temp-text "Test.\n* Head 1"
1901 (forward-line)
1902 (org-drag-element-backward)))
1903 ;; Preserve visibility of elements and their contents.
1904 (should
1905 (equal '((63 . 82) (26 . 48))
1906 (org-test-with-temp-text "
1907 #+BEGIN_CENTER
1908 Text.
1909 #+END_CENTER
1910 - item 1
1911 #+BEGIN_QUOTE
1912 Text.
1913 #+END_QUOTE"
1914 (while (search-forward "BEGIN_" nil t) (org-cycle))
1915 (search-backward "- item 1")
1916 (org-drag-element-backward)
1917 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1918 (overlays-in (point-min) (point-max)))))))
1920 (ert-deftest test-org/drag-element-forward ()
1921 "Test `org-drag-element-forward' specifications."
1922 ;; 1. Error when trying to move first element of buffer.
1923 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1924 (goto-line 3)
1925 (should-error (org-drag-element-forward)))
1926 ;; 2. Error when trying to swap nested elements.
1927 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1928 (forward-line)
1929 (should-error (org-drag-element-forward)))
1930 ;; 3. Error when trying to swap a non-headline element and an
1931 ;; headline.
1932 (org-test-with-temp-text "Test.\n* Head 1"
1933 (should-error (org-drag-element-forward)))
1934 ;; 4. Otherwise, swap elements, preserving column and blank lines
1935 ;; between elements.
1936 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
1937 (search-forward "graph")
1938 (org-drag-element-forward)
1939 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
1940 (should (looking-at " 1")))
1941 ;; 5. Preserve visibility of elements and their contents.
1942 (org-test-with-temp-text "
1943 #+BEGIN_CENTER
1944 Text.
1945 #+END_CENTER
1946 - item 1
1947 #+BEGIN_QUOTE
1948 Text.
1949 #+END_QUOTE"
1950 (while (search-forward "BEGIN_" nil t) (org-cycle))
1951 (search-backward "#+BEGIN_CENTER")
1952 (org-drag-element-forward)
1953 (should
1954 (equal
1955 '((63 . 82) (26 . 48))
1956 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1957 (overlays-in (point-min) (point-max)))))))
1961 ;;; Planning
1963 (ert-deftest test-org/timestamp-has-time-p ()
1964 "Test `org-timestamp-has-time-p' specifications."
1965 ;; With time.
1966 (should
1967 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1968 (org-timestamp-has-time-p (org-element-context))))
1969 ;; Without time.
1970 (should-not
1971 (org-test-with-temp-text "<2012-03-29 Thu>"
1972 (org-timestamp-has-time-p (org-element-context)))))
1974 (ert-deftest test-org/timestamp-format ()
1975 "Test `org-timestamp-format' specifications."
1976 ;; Regular test.
1977 (should
1978 (equal
1979 "2012-03-29 16:40"
1980 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1981 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
1982 ;; Range end.
1983 (should
1984 (equal
1985 "2012-03-29"
1986 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1987 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
1989 (ert-deftest test-org/timestamp-split-range ()
1990 "Test `org-timestamp-split-range' specifications."
1991 ;; Extract range start (active).
1992 (should
1993 (equal '(2012 3 29)
1994 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1995 (let ((ts (org-timestamp-split-range (org-element-context))))
1996 (mapcar (lambda (p) (org-element-property p ts))
1997 '(:year-end :month-end :day-end))))))
1998 ;; Extract range start (inactive)
1999 (should
2000 (equal '(2012 3 29)
2001 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2002 (let ((ts (org-timestamp-split-range (org-element-context))))
2003 (mapcar (lambda (p) (org-element-property p ts))
2004 '(:year-end :month-end :day-end))))))
2005 ;; Extract range end (active).
2006 (should
2007 (equal '(2012 3 30)
2008 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2009 (let ((ts (org-timestamp-split-range
2010 (org-element-context) t)))
2011 (mapcar (lambda (p) (org-element-property p ts))
2012 '(:year-end :month-end :day-end))))))
2013 ;; Extract range end (inactive)
2014 (should
2015 (equal '(2012 3 30)
2016 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2017 (let ((ts (org-timestamp-split-range
2018 (org-element-context) t)))
2019 (mapcar (lambda (p) (org-element-property p ts))
2020 '(:year-end :month-end :day-end))))))
2021 ;; Return the timestamp if not a range.
2022 (should
2023 (org-test-with-temp-text "[2012-03-29 Thu]"
2024 (let* ((ts-orig (org-element-context))
2025 (ts-copy (org-timestamp-split-range ts-orig)))
2026 (eq ts-orig ts-copy))))
2027 (should
2028 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2029 (let* ((ts-orig (org-element-context))
2030 (ts-copy (org-timestamp-split-range ts-orig)))
2031 (eq ts-orig ts-copy))))
2032 ;; Check that parent is the same when a range was split.
2033 (should
2034 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2035 (let* ((ts-orig (org-element-context))
2036 (ts-copy (org-timestamp-split-range ts-orig)))
2037 (eq (org-element-property :parent ts-orig)
2038 (org-element-property :parent ts-copy))))))
2040 (ert-deftest test-org/timestamp-translate ()
2041 "Test `org-timestamp-translate' specifications."
2042 ;; Translate whole date range.
2043 (should
2044 (equal "<29>--<30>"
2045 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2046 (let ((org-display-custom-times t)
2047 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2048 (org-timestamp-translate (org-element-context))))))
2049 ;; Translate date range start.
2050 (should
2051 (equal "<29>"
2052 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2053 (let ((org-display-custom-times t)
2054 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2055 (org-timestamp-translate (org-element-context) 'start)))))
2056 ;; Translate date range end.
2057 (should
2058 (equal "<30>"
2059 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2060 (let ((org-display-custom-times t)
2061 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2062 (org-timestamp-translate (org-element-context) 'end)))))
2063 ;; Translate time range.
2064 (should
2065 (equal "<08>--<16>"
2066 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
2067 (let ((org-display-custom-times t)
2068 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
2069 (org-timestamp-translate (org-element-context))))))
2070 ;; Translate non-range timestamp.
2071 (should
2072 (equal "<29>"
2073 (org-test-with-temp-text "<2012-03-29 Thu>"
2074 (let ((org-display-custom-times t)
2075 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2076 (org-timestamp-translate (org-element-context))))))
2077 ;; Do not change `diary' timestamps.
2078 (should
2079 (equal "<%%(org-float t 4 2)>"
2080 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2081 (let ((org-display-custom-times t)
2082 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
2083 (org-timestamp-translate (org-element-context)))))))
2087 ;;; Property API
2089 (ert-deftest test-org/buffer-property-keys ()
2090 "Test `org-buffer-property-keys' specifications."
2091 ;; Retrieve properties accross siblings.
2092 (should
2093 (equal '("A" "B")
2094 (org-test-with-temp-text "
2095 * H1
2096 :PROPERTIES:
2097 :A: 1
2098 :END:
2099 * H2
2100 :PROPERTIES:
2101 :B: 1
2102 :END:"
2103 (org-buffer-property-keys))))
2104 ;; Retrieve properties accross children.
2105 (should
2106 (equal '("A" "B")
2107 (org-test-with-temp-text "
2108 * H1
2109 :PROPERTIES:
2110 :A: 1
2111 :END:
2112 ** H2
2113 :PROPERTIES:
2114 :B: 1
2115 :END:"
2116 (org-buffer-property-keys))))
2117 ;; Retrieve muliple properties in the same drawer.
2118 (should
2119 (equal '("A" "B")
2120 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2121 (org-buffer-property-keys))))
2122 ;; Ignore extension symbol in property name.
2123 (should
2124 (equal '("A")
2125 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2126 (org-buffer-property-keys))))
2127 ;; With non-nil COLUMNS, extract property names from columns.
2128 (should
2129 (equal '("A" "B")
2130 (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
2131 (org-buffer-property-keys nil nil t))))
2132 (should
2133 (equal '("A" "B" "COLUMNS")
2134 (org-test-with-temp-text
2135 "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
2136 (org-buffer-property-keys nil nil t)))))
2138 (ert-deftest test-org/property-values ()
2139 "Test `org-property-values' specifications."
2140 ;; Regular test.
2141 (should
2142 (equal '("2" "1")
2143 (org-test-with-temp-text
2144 "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
2145 (org-property-values "A"))))
2146 ;; Ignore empty values.
2147 (should-not
2148 (org-test-with-temp-text
2149 "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
2150 (org-property-values "A")))
2151 ;; Take into consideration extended values.
2152 (should
2153 (equal '("1 2")
2154 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
2155 (org-property-values "A")))))
2157 (ert-deftest test-org/entry-delete ()
2158 "Test `org-entry-delete' specifications."
2159 ;; Regular test.
2160 (should
2161 (string-match
2162 " *:PROPERTIES:\n *:B: +2\n *:END:"
2163 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
2164 (org-entry-delete (point) "A")
2165 (buffer-string))))
2166 ;; When last property is removed, remove the property drawer.
2167 (should-not
2168 (string-match
2169 ":PROPERTIES:"
2170 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
2171 (org-entry-delete (point) "A")
2172 (buffer-string)))))
2174 (ert-deftest test-org/entry-get ()
2175 "Test `org-entry-get' specifications."
2176 ;; Regular test.
2177 (should
2178 (equal "1"
2179 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2180 (org-entry-get (point) "A"))))
2181 ;; Ignore case.
2182 (should
2183 (equal "1"
2184 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2185 (org-entry-get (point) "a"))))
2186 ;; Handle extended values, both before and after base value.
2187 (should
2188 (equal "1 2 3"
2189 (org-test-with-temp-text
2190 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2191 (org-entry-get (point) "A"))))
2192 ;; Empty values are returned as the empty string.
2193 (should
2194 (equal ""
2195 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
2196 (org-entry-get (point) "A"))))
2197 ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
2198 ;; otherwise, return nil.
2199 (should-not
2200 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2201 (org-entry-get (point) "A")))
2202 (should
2203 (equal "nil"
2204 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
2205 (org-entry-get (point) "A" nil t))))
2206 ;; Return nil when no property is found, independently on the
2207 ;; LITERAL-NIL argument.
2208 (should-not
2209 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2210 (org-entry-get (point) "B")))
2211 (should-not
2212 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2213 (org-entry-get (point) "B" nil t)))
2214 ;; Handle inheritance, when allowed.
2215 (should
2216 (equal
2218 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2219 (org-entry-get (point) "A" t))))
2220 (should
2221 (equal
2223 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2224 (let ((org-use-property-inheritance t))
2225 (org-entry-get (point) "A" 'selective)))))
2226 (should-not
2227 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
2228 (let ((org-use-property-inheritance nil))
2229 (org-entry-get (point) "A" 'selective)))))
2231 (ert-deftest test-org/entry-properties ()
2232 "Test `org-entry-properties' specifications."
2233 ;; Get "TODO" property.
2234 (should
2235 (equal "TODO"
2236 (org-test-with-temp-text "* TODO H"
2237 (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
2238 (should-not
2239 (org-test-with-temp-text "* H"
2240 (assoc "TODO" (org-entry-properties nil "TODO"))))
2241 ;; Get "PRIORITY" property.
2242 (should
2243 (equal "A"
2244 (org-test-with-temp-text "* [#A] H"
2245 (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
2246 (should-not
2247 (org-test-with-temp-text "* H"
2248 (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))
2249 ;; Get "FILE" property.
2250 (should
2251 (org-test-with-temp-text-in-file "* H\nParagraph"
2252 (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
2253 (buffer-file-name))))
2254 (should-not
2255 (org-test-with-temp-text "* H\nParagraph"
2256 (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
2257 ;; Get "TAGS" property.
2258 (should
2259 (equal ":tag1:tag2:"
2260 (org-test-with-temp-text "* H :tag1:tag2:"
2261 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
2262 (should-not
2263 (org-test-with-temp-text "* H"
2264 (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
2265 ;; Get "ALLTAGS" property.
2266 (should
2267 (equal ":tag1:tag2:"
2268 (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
2269 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
2270 (should-not
2271 (org-test-with-temp-text "* H"
2272 (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
2273 ;; Get "BLOCKED" property.
2274 (should
2275 (equal "t"
2276 (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
2277 (let ((org-enforce-todo-dependencies t)
2278 (org-blocker-hook
2279 '(org-block-todo-from-children-or-siblings-or-parent)))
2280 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2281 (should
2282 (equal ""
2283 (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
2284 (let ((org-enforce-todo-dependencies t))
2285 (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
2286 ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
2287 (should
2288 (equal
2289 "[2012-03-29 thu.]"
2290 (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
2291 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
2292 (should-not
2293 (org-test-with-temp-text "* H"
2294 (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
2295 (should
2296 (equal
2297 "<2014-03-04 tue.>"
2298 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2299 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
2300 (should-not
2301 (org-test-with-temp-text "* H"
2302 (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
2303 (should
2304 (equal
2305 "<2014-03-04 tue.>"
2306 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2307 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
2308 (should-not
2309 (org-test-with-temp-text "* H"
2310 (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
2311 ;; Get "CATEGORY"
2312 (should
2313 (equal "cat"
2314 (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
2315 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2316 (should
2317 (equal "cat"
2318 (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
2319 (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
2320 ;; Get standard properties.
2321 (should
2322 (equal "1"
2323 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2324 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2325 ;; Handle extended properties.
2326 (should
2327 (equal "1 2 3"
2328 (org-test-with-temp-text
2329 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
2330 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2331 (should
2332 (equal "1 2 3"
2333 (org-test-with-temp-text
2334 "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
2335 (cdr (assoc "A" (org-entry-properties nil 'standard))))))
2336 ;; Ignore forbidden (special) properties.
2337 (should-not
2338 (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
2339 (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
2341 (ert-deftest test-org/entry-put ()
2342 "Test `org-entry-put' specifications."
2343 ;; Error when not a string or nil.
2344 (should-error
2345 (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
2346 (org-entry-put 1 "test" 2)))
2347 ;; Set "TODO" property.
2348 (should
2349 (string-match (regexp-quote " TODO H")
2350 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2351 (org-entry-put (point) "TODO" "TODO")
2352 (buffer-string))))
2353 (should
2354 (string-match (regexp-quote "* H")
2355 (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
2356 (org-entry-put (point) "TODO" nil)
2357 (buffer-string))))
2358 ;; Set "PRIORITY" property.
2359 (should
2360 (equal "* [#A] H"
2361 (org-test-with-temp-text "* [#B] H"
2362 (org-entry-put (point) "PRIORITY" "A")
2363 (buffer-string))))
2364 (should
2365 (equal "* H"
2366 (org-test-with-temp-text "* [#B] H"
2367 (org-entry-put (point) "PRIORITY" nil)
2368 (buffer-string))))
2369 ;; Set "SCHEDULED" property.
2370 (should
2371 (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
2372 (org-test-with-temp-text "* H"
2373 (org-entry-put (point) "SCHEDULED" "2014-03-04")
2374 (buffer-string))))
2375 (should
2376 (string= "* H\n"
2377 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2378 (org-entry-put (point) "SCHEDULED" nil)
2379 (buffer-string))))
2380 (should
2381 (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
2382 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2383 (org-entry-put (point) "SCHEDULED" "earlier")
2384 (buffer-string))))
2385 (should
2386 (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
2387 (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
2388 (org-entry-put (point) "SCHEDULED" "later")
2389 (buffer-string))))
2390 ;; Set "DEADLINE" property.
2391 (should
2392 (string-match "^ *DEADLINE: <2014-03-04 .*?>"
2393 (org-test-with-temp-text "* H"
2394 (org-entry-put (point) "DEADLINE" "2014-03-04")
2395 (buffer-string))))
2396 (should
2397 (string= "* H\n"
2398 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2399 (org-entry-put (point) "DEADLINE" nil)
2400 (buffer-string))))
2401 (should
2402 (string-match "^ *DEADLINE: <2014-03-03 .*?>"
2403 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2404 (org-entry-put (point) "DEADLINE" "earlier")
2405 (buffer-string))))
2406 (should
2407 (string-match "^ *DEADLINE: <2014-03-05 .*?>"
2408 (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
2409 (org-entry-put (point) "DEADLINE" "later")
2410 (buffer-string))))
2411 ;; Regular properties, with or without pre-existing drawer.
2412 (should
2413 (string-match "^ *:A: +2$"
2414 (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
2415 (org-entry-put (point) "A" "2")
2416 (buffer-string))))
2417 (should
2418 (string-match "^ *:A: +1$"
2419 (org-test-with-temp-text "* H"
2420 (org-entry-put (point) "A" "1")
2421 (buffer-string))))
2422 ;; Special case: two consecutive headlines.
2423 (should
2424 (string-match "\\* A\n *:PROPERTIES:"
2425 (org-test-with-temp-text "* A\n** B"
2426 (org-entry-put (point) "A" "1")
2427 (buffer-string)))))
2430 ;;; Radio Targets
2432 (ert-deftest test-org/update-radio-target-regexp ()
2433 "Test `org-update-radio-target-regexp' specifications."
2434 ;; Properly update cache with no previous radio target regexp.
2435 (should
2436 (eq 'link
2437 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2438 (save-excursion (goto-char (point-max)) (org-element-context))
2439 (insert "<<<")
2440 (search-forward "o")
2441 (insert ">>>")
2442 (org-update-radio-target-regexp)
2443 (goto-char (point-max))
2444 (org-element-type (org-element-context)))))
2445 ;; Properly update cache with previous radio target regexp.
2446 (should
2447 (eq 'link
2448 (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
2449 (save-excursion (goto-char (point-max)) (org-element-context))
2450 (insert "<<<")
2451 (search-forward "o")
2452 (insert ">>>")
2453 (org-update-radio-target-regexp)
2454 (search-backward "r")
2455 (delete-char 5)
2456 (insert "new")
2457 (org-update-radio-target-regexp)
2458 (goto-char (point-max))
2459 (delete-region (line-beginning-position) (point))
2460 (insert "new")
2461 (org-element-type (org-element-context))))))
2465 ;;; Visibility
2467 (ert-deftest test-org/flag-drawer ()
2468 "Test `org-flag-drawer' specifications."
2469 ;; Hide drawer.
2470 (should
2471 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2472 (org-flag-drawer t)
2473 (get-char-property (line-end-position) 'invisible)))
2474 ;; Show drawer.
2475 (should-not
2476 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2477 (org-flag-drawer t)
2478 (org-flag-drawer nil)
2479 (get-char-property (line-end-position) 'invisible)))
2480 ;; Test optional argument.
2481 (should
2482 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2483 (let ((drawer (save-excursion (search-forward ":D2")
2484 (org-element-at-point))))
2485 (org-flag-drawer t drawer)
2486 (get-char-property (progn (search-forward ":D2") (line-end-position))
2487 'invisible))))
2488 (should-not
2489 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
2490 (let ((drawer (save-excursion (search-forward ":D2")
2491 (org-element-at-point))))
2492 (org-flag-drawer t drawer)
2493 (get-char-property (line-end-position) 'invisible))))
2494 ;; Do not hide fake drawers.
2495 (should-not
2496 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
2497 (forward-line 1)
2498 (org-flag-drawer t)
2499 (get-char-property (line-end-position) 'invisible)))
2500 ;; Do not hide incomplete drawers.
2501 (should-not
2502 (org-test-with-temp-text ":D:\nparagraph"
2503 (forward-line 1)
2504 (org-flag-drawer t)
2505 (get-char-property (line-end-position) 'invisible)))
2506 ;; Do not hide drawers when called from final blank lines.
2507 (should-not
2508 (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
2509 (goto-char (point-max))
2510 (org-flag-drawer t)
2511 (goto-char (point-min))
2512 (get-char-property (line-end-position) 'invisible)))
2513 ;; Don't leave point in an invisible part of the buffer when hiding
2514 ;; a drawer away.
2515 (should-not
2516 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
2517 (goto-char (point-max))
2518 (org-flag-drawer t)
2519 (get-char-property (point) 'invisible))))
2521 (ert-deftest test-org/hide-block-toggle ()
2522 "Test `org-hide-block-toggle' specifications."
2523 ;; Error when not at a block.
2524 (should-error
2525 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
2526 (org-hide-block-toggle 'off)
2527 (get-char-property (line-end-position) 'invisible)))
2528 ;; Hide block.
2529 (should
2530 (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
2531 (org-hide-block-toggle)
2532 (get-char-property (line-end-position) 'invisible)))
2533 (should
2534 (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
2535 (org-hide-block-toggle)
2536 (get-char-property (line-end-position) 'invisible)))
2537 ;; Show block unconditionally when optional argument is `off'.
2538 (should-not
2539 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2540 (org-hide-block-toggle)
2541 (org-hide-block-toggle 'off)
2542 (get-char-property (line-end-position) 'invisible)))
2543 (should-not
2544 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2545 (org-hide-block-toggle 'off)
2546 (get-char-property (line-end-position) 'invisible)))
2547 ;; Hide block unconditionally when optional argument is non-nil.
2548 (should
2549 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2550 (org-hide-block-toggle t)
2551 (get-char-property (line-end-position) 'invisible)))
2552 (should
2553 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
2554 (org-hide-block-toggle)
2555 (org-hide-block-toggle t)
2556 (get-char-property (line-end-position) 'invisible)))
2557 ;; Do not hide block when called from final blank lines.
2558 (should-not
2559 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
2560 (org-hide-block-toggle)
2561 (goto-char (point-min))
2562 (get-char-property (line-end-position) 'invisible)))
2563 ;; Don't leave point in an invisible part of the buffer when hiding
2564 ;; a block away.
2565 (should-not
2566 (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
2567 (org-hide-block-toggle)
2568 (get-char-property (point) 'invisible))))
2570 (ert-deftest test-org/hide-block-toggle-maybe ()
2571 "Test `org-hide-block-toggle-maybe' specifications."
2572 (should
2573 (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
2574 (org-hide-block-toggle-maybe)))
2575 (should-not
2576 (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
2579 (provide 'test-org)
2581 ;;; test-org.el ends here