Revert "added Makefile targets to check single tests"
[org-mode.git] / testing / lisp / test-org.el
blobf4672ebb3f84930c92ff5c51b4d0ce60ed5ab046
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/comment-dwim ()
31 "Test `comment-dwim' behaviour in an Org buffer."
32 ;; No region selected, no comment on current line and line not
33 ;; empty: insert comment on line above.
34 (should
35 (equal "# \nComment"
36 (org-test-with-temp-text "Comment"
37 (progn (call-interactively 'comment-dwim)
38 (buffer-string)))))
39 ;; No region selected, no comment on current line and line empty:
40 ;; insert comment on this line.
41 (should
42 (equal "# \nParagraph"
43 (org-test-with-temp-text "\nParagraph"
44 (progn (call-interactively 'comment-dwim)
45 (buffer-string)))))
46 ;; No region selected, and a comment on this line: indent it.
47 (should
48 (equal "* Headline\n # Comment"
49 (org-test-with-temp-text "* Headline\n# Comment"
50 (progn (forward-line)
51 (let ((org-adapt-indentation t))
52 (call-interactively 'comment-dwim))
53 (buffer-string)))))
54 ;; Also recognize single # at column 0 as comments.
55 (should
56 (equal "# Comment"
57 (org-test-with-temp-text "# Comment"
58 (progn (forward-line)
59 (call-interactively 'comment-dwim)
60 (buffer-string)))))
61 ;; Region selected and only comments and blank lines within it:
62 ;; un-comment all commented lines.
63 (should
64 (equal "Comment 1\n\nComment 2"
65 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
66 (progn
67 (transient-mark-mode 1)
68 (push-mark (point) t t)
69 (goto-char (point-max))
70 (call-interactively 'comment-dwim)
71 (buffer-string)))))
72 ;; Region selected without comments: comment all lines if
73 ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
74 (should
75 (equal "# Comment 1\n\n# Comment 2"
76 (org-test-with-temp-text "Comment 1\n\nComment 2"
77 (progn
78 (transient-mark-mode 1)
79 (push-mark (point) t t)
80 (goto-char (point-max))
81 (let ((comment-empty-lines nil))
82 (call-interactively 'comment-dwim))
83 (buffer-string)))))
84 (should
85 (equal "# Comment 1\n# \n# Comment 2"
86 (org-test-with-temp-text "Comment 1\n\nComment 2"
87 (progn
88 (transient-mark-mode 1)
89 (push-mark (point) t t)
90 (goto-char (point-max))
91 (let ((comment-empty-lines t))
92 (call-interactively 'comment-dwim))
93 (buffer-string)))))
94 ;; In front of a keyword without region, insert a new comment.
95 (should
96 (equal "# \n#+KEYWORD: value"
97 (org-test-with-temp-text "#+KEYWORD: value"
98 (progn (call-interactively 'comment-dwim)
99 (buffer-string)))))
100 ;; In a source block, use appropriate syntax.
101 (should
102 (equal " ;; "
103 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
104 (forward-line)
105 (let ((org-edit-src-content-indentation 2))
106 (call-interactively 'comment-dwim))
107 (buffer-substring-no-properties (line-beginning-position) (point)))))
108 (should
109 (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
110 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
111 (forward-line)
112 (transient-mark-mode 1)
113 (push-mark (point) t t)
114 (forward-line 2)
115 (let ((org-edit-src-content-indentation 2))
116 (call-interactively 'comment-dwim))
117 (buffer-string)))))
121 ;;; Date and time analysis
123 (ert-deftest test-org/org-read-date ()
124 "Test `org-read-date' specifications."
125 ;; Parse ISO date with abbreviated year and month.
126 (should (equal "2012-03-29 16:40"
127 (let ((org-time-was-given t))
128 (org-read-date t nil "12-3-29 16:40"))))
129 ;; Parse Europeans dates.
130 (should (equal "2012-03-29 16:40"
131 (let ((org-time-was-given t))
132 (org-read-date t nil "29.03.2012 16:40"))))
133 ;; Parse Europeans dates without year.
134 (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
135 (let ((org-time-was-given t))
136 (org-read-date t nil "29.03. 16:40")))))
138 (ert-deftest test-org/org-parse-time-string ()
139 "Test `org-parse-time-string'."
140 (should (equal (org-parse-time-string "2012-03-29 16:40")
141 '(0 40 16 29 3 2012 nil nil nil)))
142 (should (equal (org-parse-time-string "[2012-03-29 16:40]")
143 '(0 40 16 29 3 2012 nil nil nil)))
144 (should (equal (org-parse-time-string "<2012-03-29 16:40>")
145 '(0 40 16 29 3 2012 nil nil nil)))
146 (should (equal (org-parse-time-string "<2012-03-29>")
147 '(0 0 0 29 3 2012 nil nil nil)))
148 (should (equal (org-parse-time-string "<2012-03-29>" t)
149 '(0 nil nil 29 3 2012 nil nil nil))))
152 ;;; Filling
154 (ert-deftest test-org/fill-paragraph ()
155 "Test `org-fill-paragraph' specifications."
156 ;; At an Org table, align it.
157 (should
158 (equal "| a |\n"
159 (org-test-with-temp-text "|a|"
160 (org-fill-paragraph)
161 (buffer-string))))
162 (should
163 (equal "#+name: table\n| a |\n"
164 (org-test-with-temp-text "#+name: table\n| a |"
165 (org-fill-paragraph)
166 (buffer-string))))
167 ;; At a paragraph, preserve line breaks.
168 (org-test-with-temp-text "some \\\\\nlong\ntext"
169 (let ((fill-column 20))
170 (org-fill-paragraph)
171 (should (equal (buffer-string) "some \\\\\nlong text"))))
172 ;; Correctly fill a paragraph when point is at its very end.
173 (should
174 (equal "A B"
175 (org-test-with-temp-text "A\nB"
176 (let ((fill-column 20))
177 (goto-char (point-max))
178 (org-fill-paragraph)
179 (buffer-string)))))
180 ;; Correctly fill the last paragraph of a greater element.
181 (should
182 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
183 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
184 (let ((fill-column 8))
185 (forward-line)
186 (end-of-line)
187 (org-fill-paragraph)
188 (buffer-string)))))
189 ;; Correctly fill an element in a narrowed buffer.
190 (should
191 (equal "01234\n6"
192 (org-test-with-temp-text "01234 6789"
193 (let ((fill-column 5))
194 (narrow-to-region 1 8)
195 (org-fill-paragraph)
196 (buffer-string)))))
197 ;; Handle `adaptive-fill-regexp' in paragraphs.
198 (should
199 (equal "> a b"
200 (org-test-with-temp-text "> a\n> b"
201 (let ((fill-column 5)
202 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
203 (org-fill-paragraph)
204 (buffer-string)))))
205 ;; Special case: Fill first paragraph when point is at an item or
206 ;; a plain-list or a footnote reference.
207 (should
208 (equal "- A B"
209 (org-test-with-temp-text "- A\n B"
210 (let ((fill-column 20))
211 (org-fill-paragraph)
212 (buffer-string)))))
213 (should
214 (equal "[fn:1] A B"
215 (org-test-with-temp-text "[fn:1] A\nB"
216 (let ((fill-column 20))
217 (org-fill-paragraph)
218 (buffer-string)))))
219 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
220 (let ((fill-column 20))
221 (org-fill-paragraph)
222 (should (equal (buffer-string)
223 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
224 ;; Fill contents of `comment-block' elements.
225 (should
226 (equal
227 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
228 (let ((fill-column 20))
229 (forward-line)
230 (org-fill-paragraph)
231 (buffer-string)))
232 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
233 ;; Fill `comment' elements.
234 (should
235 (equal " # A B"
236 (org-test-with-temp-text " # A\n # B"
237 (let ((fill-column 20))
238 (org-fill-paragraph)
239 (buffer-string)))))
240 ;; Do not mix consecutive comments when filling one of them.
241 (should
242 (equal "# A B\n\n# C"
243 (org-test-with-temp-text "# A\n# B\n\n# C"
244 (let ((fill-column 20))
245 (org-fill-paragraph)
246 (buffer-string)))))
247 ;; Use commented empty lines as separators when filling comments.
248 (should
249 (equal "# A B\n#\n# C"
250 (org-test-with-temp-text "# A\n# B\n#\n# C"
251 (let ((fill-column 20))
252 (org-fill-paragraph)
253 (buffer-string)))))
254 ;; Handle `adaptive-fill-regexp' in comments.
255 (should
256 (equal "# > a b"
257 (org-test-with-temp-text "# > a\n# > b"
258 (let ((fill-column 20)
259 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
260 (org-fill-paragraph)
261 (buffer-string)))))
262 ;; Do nothing at affiliated keywords.
263 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
264 (let ((fill-column 20))
265 (org-fill-paragraph)
266 (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
267 ;; Do not move point after table when filling a table.
268 (should-not
269 (org-test-with-temp-text "| a | b |\n| c | d |\n"
270 (forward-char)
271 (org-fill-paragraph)
272 (eobp))))
274 (ert-deftest test-org/auto-fill-function ()
275 "Test auto-filling features."
276 ;; Auto fill paragraph.
277 (should
278 (equal "12345\n7890"
279 (org-test-with-temp-text "12345 7890"
280 (let ((fill-column 5))
281 (end-of-line)
282 (org-auto-fill-function)
283 (buffer-string)))))
284 ;; Auto fill first paragraph in an item.
285 (should
286 (equal "- 12345\n 7890"
287 (org-test-with-temp-text "- 12345 7890"
288 (let ((fill-column 7))
289 (end-of-line)
290 (org-auto-fill-function)
291 (buffer-string)))))
292 ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
293 (should
294 (equal "> 12345\n 7890"
295 (org-test-with-temp-text "> 12345 7890"
296 (let ((fill-column 10)
297 (adaptive-fill-regexp "[ \t]*>+[ \t]*")
298 (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
299 (end-of-line)
300 (org-auto-fill-function)
301 (buffer-string)))))
302 (should
303 (equal "> 12345\n> 12345\n> 7890"
304 (org-test-with-temp-text "> 12345\n> 12345 7890"
305 (let ((fill-column 10)
306 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
307 (goto-char (point-max))
308 (org-auto-fill-function)
309 (buffer-string)))))
310 (should-not
311 (equal " 12345\n *12345\n *12345"
312 (org-test-with-temp-text " 12345\n *12345 12345"
313 (let ((fill-column 10)
314 (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
315 (goto-char (point-max))
316 (org-auto-fill-function)
317 (buffer-string)))))
318 ;; Auto fill comments.
319 (should
320 (equal " # 12345\n # 7890"
321 (org-test-with-temp-text " # 12345 7890"
322 (let ((fill-column 10))
323 (end-of-line)
324 (org-auto-fill-function)
325 (buffer-string)))))
326 ;; A hash within a line isn't a comment.
327 (should-not
328 (equal "12345 # 7890\n# 1"
329 (org-test-with-temp-text "12345 # 7890 1"
330 (let ((fill-column 12))
331 (end-of-line)
332 (org-auto-fill-function)
333 (buffer-string)))))
334 ;; Correctly interpret empty prefix.
335 (should-not
336 (equal "# a\n# b\nRegular\n# paragraph"
337 (org-test-with-temp-text "# a\n# b\nRegular paragraph"
338 (let ((fill-column 12))
339 (end-of-line 3)
340 (org-auto-fill-function)
341 (buffer-string)))))
342 ;; Comment block: auto fill contents.
343 (should
344 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
345 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
346 (let ((fill-column 5))
347 (forward-line)
348 (end-of-line)
349 (org-auto-fill-function)
350 (buffer-string)))))
351 (should
352 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
353 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
354 (let ((fill-column 5))
355 (forward-line)
356 (end-of-line)
357 (org-auto-fill-function)
358 (buffer-string)))))
359 ;; Do not fill if a new item could be created.
360 (should-not
361 (equal "12345\n- 90"
362 (org-test-with-temp-text "12345 - 90"
363 (let ((fill-column 5))
364 (end-of-line)
365 (org-auto-fill-function)
366 (buffer-string)))))
367 ;; Do not fill if a line break could be introduced.
368 (should-not
369 (equal "123\\\\\n7890"
370 (org-test-with-temp-text "123\\\\ 7890"
371 (let ((fill-column 6))
372 (end-of-line)
373 (org-auto-fill-function)
374 (buffer-string)))))
375 ;; Do not fill affiliated keywords.
376 (should-not
377 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
378 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
379 (let ((fill-column 20))
380 (end-of-line)
381 (org-auto-fill-function)
382 (buffer-string))))))
386 ;;; Editing
388 ;;;; Insert elements
390 (ert-deftest test-org/meta-return ()
391 "Test M-RET (`org-meta-return')."
392 ;; In a table field insert a row above.
393 (should
394 (org-test-with-temp-text "| a |"
395 (forward-char)
396 (org-meta-return)
397 (forward-line -1)
398 (looking-at "| |$")))
399 ;; In a paragraph change current line into a header.
400 (should
401 (org-test-with-temp-text "a"
402 (org-meta-return)
403 (beginning-of-line)
404 (looking-at "\* a$")))
405 ;; In an item insert an item, in this case above.
406 (should
407 (org-test-with-temp-text "- a"
408 (org-meta-return)
409 (beginning-of-line)
410 (looking-at "- $")))
411 ;; In a drawer and paragraph insert an empty line, in this case above.
412 (should
413 (org-test-with-temp-text ":MYDRAWER:\na\n:END:"
414 (forward-line)
415 (org-meta-return)
416 (forward-line -1)
417 (looking-at "$")))
418 ;; In a drawer and item insert an item, in this case above.
419 (should
420 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
421 (forward-line)
422 (org-meta-return)
423 (beginning-of-line)
424 (looking-at "- $"))))
426 (ert-deftest test-org/insert-todo-heading-respect-content ()
427 "Test `org-insert-todo-heading-respect-content' specifications."
428 ;; Create a TODO heading.
429 (should
430 (org-test-with-temp-text "* H1\n Body"
431 (org-insert-todo-heading-respect-content)
432 (nth 2 (org-heading-components))))
433 ;; Add headline after body of current subtree.
434 (should
435 (org-test-with-temp-text "* H1\nBody"
436 (org-insert-todo-heading-respect-content)
437 (eobp)))
438 (should
439 (org-test-with-temp-text "* H1\n** H2\nBody"
440 (org-insert-todo-heading-respect-content)
441 (eobp)))
442 ;; In a list, do not create a new item.
443 (should
444 (org-test-with-temp-text "* H\n- an item\n- another one"
445 (search-forward "an ")
446 (org-insert-todo-heading-respect-content)
447 (and (eobp) (org-at-heading-p)))))
451 ;;; Links
453 ;;;; Fuzzy Links
455 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
456 ;; a named element (#+name: text) and to headlines (* Text).
458 (ert-deftest test-org/fuzzy-links ()
459 "Test fuzzy links specifications."
460 ;; 1. Fuzzy link goes in priority to a matching target.
461 (should
462 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
463 (goto-line 5)
464 (org-open-at-point)
465 (looking-at "<<Test>>")))
466 ;; 2. Then fuzzy link points to an element with a given name.
467 (should
468 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
469 (goto-line 5)
470 (org-open-at-point)
471 (looking-at "#\\+NAME: Test")))
472 ;; 3. A target still lead to a matching headline otherwise.
473 (should
474 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
475 (goto-line 4)
476 (org-open-at-point)
477 (looking-at "\\* Head2")))
478 ;; 4. With a leading star in link, enforce heading match.
479 (should
480 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
481 (goto-line 3)
482 (org-open-at-point)
483 (looking-at "\\* Test"))))
486 ;;;; Link Escaping
488 (ert-deftest test-org/org-link-escape-ascii-character ()
489 "Escape an ascii character."
490 (should
491 (string=
492 "%5B"
493 (org-link-escape "["))))
495 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
496 "Escape an ascii control character."
497 (should
498 (string=
499 "%09"
500 (org-link-escape "\t"))))
502 (ert-deftest test-org/org-link-escape-multibyte-character ()
503 "Escape an unicode multibyte character."
504 (should
505 (string=
506 "%E2%82%AC"
507 (org-link-escape "€"))))
509 (ert-deftest test-org/org-link-escape-custom-table ()
510 "Escape string with custom character table."
511 (should
512 (string=
513 "Foo%3A%42ar%0A"
514 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
516 (ert-deftest test-org/org-link-escape-custom-table-merge ()
517 "Escape string with custom table merged with default table."
518 (should
519 (string=
520 "%5BF%6F%6F%3A%42ar%0A%5D"
521 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
523 (ert-deftest test-org/org-link-unescape-ascii-character ()
524 "Unescape an ascii character."
525 (should
526 (string=
528 (org-link-unescape "%5B"))))
530 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
531 "Unescpae an ascii control character."
532 (should
533 (string=
534 "\n"
535 (org-link-unescape "%0A"))))
537 (ert-deftest test-org/org-link-unescape-multibyte-character ()
538 "Unescape unicode multibyte character."
539 (should
540 (string=
541 "€"
542 (org-link-unescape "%E2%82%AC"))))
544 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
545 "Unescape old style percent escaped character."
546 (should
547 (string=
548 "àâçèéêîôùû"
549 (decode-coding-string
550 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
552 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
553 "Escape and unescape a URL that includes an escaped char.
554 http://article.gmane.org/gmane.emacs.orgmode/21459/"
555 (should
556 (string=
557 "http://some.host.com/form?&id=blah%2Bblah25"
558 (org-link-unescape
559 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
561 (ert-deftest test-org/org-link-escape-chars-browser ()
562 "Escape a URL to pass to `browse-url'."
563 (should
564 (string=
565 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
566 "%22Release%208.2%22&idxname=emacs-orgmode")
567 (org-link-escape-browser
568 (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
569 "\"Release 8.2\"&idxname=emacs-orgmode")))))
573 ;;; Node Properties
575 (ert-deftest test-org/accumulated-properties-in-drawers ()
576 "Ensure properties accumulate in subtree drawers."
577 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
578 (org-babel-next-src-block)
579 (should (equal '(2 1) (org-babel-execute-src-block)))))
583 ;;; Mark Region
585 (ert-deftest test-org/mark-subtree ()
586 "Test `org-mark-subtree' specifications."
587 ;; Error when point is before first headline.
588 (should-error
589 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
590 (progn (transient-mark-mode 1)
591 (org-mark-subtree))))
592 ;; Without argument, mark current subtree.
593 (should
594 (equal
595 '(12 32)
596 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
597 (progn (transient-mark-mode 1)
598 (forward-line 2)
599 (org-mark-subtree)
600 (list (region-beginning) (region-end))))))
601 ;; With an argument, move ARG up.
602 (should
603 (equal
604 '(1 32)
605 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
606 (progn (transient-mark-mode 1)
607 (forward-line 2)
608 (org-mark-subtree 1)
609 (list (region-beginning) (region-end))))))
610 ;; Do not get fooled by inlinetasks.
611 (when (featurep 'org-inlinetask)
612 (should
613 (= 1
614 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
615 (progn (transient-mark-mode 1)
616 (forward-line 1)
617 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
618 (region-beginning)))))))
622 ;;; Navigation
624 (ert-deftest test-org/beginning-of-line ()
625 "Test `org-beginning-of-line' specifications."
626 ;; Standard test.
627 (should
628 (org-test-with-temp-text "Some text\nSome other text"
629 (progn (org-beginning-of-line) (bolp))))
630 ;; Standard test with `visual-line-mode'.
631 (should-not
632 (org-test-with-temp-text "A long line of text\nSome other text"
633 (progn (visual-line-mode)
634 (forward-char 2)
635 (dotimes (i 1000) (insert "very "))
636 (org-beginning-of-line)
637 (bolp))))
638 ;; At an headline with special movement.
639 (should
640 (org-test-with-temp-text "* TODO Headline"
641 (let ((org-special-ctrl-a/e t))
642 (org-end-of-line)
643 (and (progn (org-beginning-of-line) (looking-at "Headline"))
644 (progn (org-beginning-of-line) (bolp))
645 (progn (org-beginning-of-line) (looking-at "Headline")))))))
647 (ert-deftest test-org/end-of-line ()
648 "Test `org-end-of-line' specifications."
649 ;; Standard test.
650 (should
651 (org-test-with-temp-text "Some text\nSome other text"
652 (progn (org-end-of-line) (eolp))))
653 ;; Standard test with `visual-line-mode'.
654 (should-not
655 (org-test-with-temp-text "A long line of text\nSome other text"
656 (progn (visual-line-mode)
657 (forward-char 2)
658 (dotimes (i 1000) (insert "very "))
659 (goto-char (point-min))
660 (org-end-of-line)
661 (eolp))))
662 ;; At an headline with special movement.
663 (should
664 (org-test-with-temp-text "* Headline1 :tag:\n"
665 (let ((org-special-ctrl-a/e t))
666 (and (progn (org-end-of-line) (looking-at " :tag:"))
667 (progn (org-end-of-line) (eolp))
668 (progn (org-end-of-line) (looking-at " :tag:"))))))
669 ;; At an headline without special movement.
670 (should
671 (org-test-with-temp-text "* Headline2 :tag:\n"
672 (let ((org-special-ctrl-a/e nil))
673 (and (progn (org-end-of-line) (eolp))
674 (progn (org-end-of-line) (eolp))))))
675 ;; At an headline, with reversed movement.
676 (should
677 (org-test-with-temp-text "* Headline3 :tag:\n"
678 (let ((org-special-ctrl-a/e 'reversed)
679 (this-command last-command))
680 (and (progn (org-end-of-line) (eolp))
681 (progn (org-end-of-line) (looking-at " :tag:"))))))
682 ;; At a block without hidden contents.
683 (should
684 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
685 (progn (org-end-of-line) (eolp))))
686 ;; At a block with hidden contents.
687 (should-not
688 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
689 (let ((org-special-ctrl-a/e t))
690 (org-hide-block-toggle)
691 (org-end-of-line)
692 (eobp)))))
694 (ert-deftest test-org/forward-paragraph ()
695 "Test `org-forward-paragraph' specifications."
696 ;; At end of buffer, return an error.
697 (should-error
698 (org-test-with-temp-text "Paragraph"
699 (goto-char (point-max))
700 (org-forward-paragraph)))
701 ;; Standard test.
702 (should
703 (org-test-with-temp-text "P1\n\nP2\n\nP3"
704 (org-forward-paragraph)
705 (looking-at "P2")))
706 ;; Ignore depth.
707 (should
708 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
709 (org-forward-paragraph)
710 (looking-at "P1")))
711 ;; Do not enter elements with invisible contents.
712 (should
713 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
714 (org-hide-block-toggle)
715 (org-forward-paragraph)
716 (looking-at "P3")))
717 ;; On an affiliated keyword, jump to the beginning of the element.
718 (should
719 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
720 (org-forward-paragraph)
721 (looking-at "Para")))
722 ;; On an item or a footnote definition, move to the second element
723 ;; inside, if any.
724 (should
725 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
726 (org-forward-paragraph)
727 (looking-at " Paragraph")))
728 (should
729 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
730 (org-forward-paragraph)
731 (looking-at "Paragraph")))
732 ;; On an item, or a footnote definition, when the first line is
733 ;; empty, move to the first item.
734 (should
735 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
736 (org-forward-paragraph)
737 (looking-at " Paragraph")))
738 (should
739 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
740 (org-forward-paragraph)
741 (looking-at "Paragraph")))
742 ;; On a table (resp. a property drawer) do not move through table
743 ;; rows (resp. node properties).
744 (should
745 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
746 (org-forward-paragraph)
747 (looking-at "Paragraph")))
748 (should
749 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nParagraph"
750 (org-forward-paragraph)
751 (looking-at "Paragraph")))
752 ;; On a verse or source block, stop after blank lines.
753 (should
754 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
755 (org-forward-paragraph)
756 (looking-at "L2")))
757 (should
758 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
759 (org-forward-paragraph)
760 (looking-at "L2"))))
762 (ert-deftest test-org/backward-paragraph ()
763 "Test `org-backward-paragraph' specifications."
764 ;; Error at beginning of buffer.
765 (should-error
766 (org-test-with-temp-text "Paragraph"
767 (org-backward-paragraph)))
768 ;; Regular test.
769 (should
770 (org-test-with-temp-text "P1\n\nP2\n\nP3"
771 (goto-char (point-max))
772 (org-backward-paragraph)
773 (looking-at "P3")))
774 (should
775 (org-test-with-temp-text "P1\n\nP2\n\nP3"
776 (goto-char (point-max))
777 (beginning-of-line)
778 (org-backward-paragraph)
779 (looking-at "P2")))
780 ;; Ignore depth.
781 (should
782 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
783 (goto-char (point-max))
784 (beginning-of-line)
785 (org-backward-paragraph)
786 (looking-at "P2")))
787 ;; Ignore invisible elements.
788 (should
789 (org-test-with-temp-text "* H1\n P1\n* H2"
790 (org-cycle)
791 (goto-char (point-max))
792 (beginning-of-line)
793 (org-backward-paragraph)
794 (bobp)))
795 ;; On an affiliated keyword, jump to the first one.
796 (should
797 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
798 (search-forward "c2")
799 (org-backward-paragraph)
800 (looking-at "#\\+name")))
801 ;; On the second element in an item or a footnote definition, jump
802 ;; to item or the definition.
803 (should
804 (org-test-with-temp-text "- line1\n\n line2"
805 (goto-char (point-max))
806 (beginning-of-line)
807 (org-backward-paragraph)
808 (looking-at "- line1")))
809 (should
810 (org-test-with-temp-text "[fn:1] line1\n\n line2"
811 (goto-char (point-max))
812 (beginning-of-line)
813 (org-backward-paragraph)
814 (looking-at "\\[fn:1\\] line1")))
815 ;; On a table (resp. a property drawer), ignore table rows
816 ;; (resp. node properties).
817 (should
818 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
819 (goto-char (point-max))
820 (beginning-of-line)
821 (org-backward-paragraph)
822 (bobp)))
823 (should
824 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nP1"
825 (goto-char (point-max))
826 (beginning-of-line)
827 (org-backward-paragraph)
828 (bobp)))
829 ;; On a source or verse block, stop before blank lines.
830 (should
831 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
832 (search-forward "L3")
833 (beginning-of-line)
834 (org-backward-paragraph)
835 (looking-at "L2")))
836 (should
837 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
838 (search-forward "L3")
839 (beginning-of-line)
840 (org-backward-paragraph)
841 (looking-at "L2"))))
843 (ert-deftest test-org/forward-element ()
844 "Test `org-forward-element' specifications."
845 ;; 1. At EOB: should error.
846 (org-test-with-temp-text "Some text\n"
847 (goto-char (point-max))
848 (should-error (org-forward-element)))
849 ;; 2. Standard move: expected to ignore blank lines.
850 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
851 (org-forward-element)
852 (should (looking-at (regexp-quote "Second paragraph."))))
853 ;; 3. Headline tests.
854 (org-test-with-temp-text "
855 * Head 1
856 ** Head 1.1
857 *** Head 1.1.1
858 ** Head 1.2"
859 ;; 3.1. At an headline beginning: move to next headline at the
860 ;; same level.
861 (goto-line 3)
862 (org-forward-element)
863 (should (looking-at (regexp-quote "** Head 1.2")))
864 ;; 3.2. At an headline beginning: move to parent headline if no
865 ;; headline at the same level.
866 (goto-line 3)
867 (org-forward-element)
868 (should (looking-at (regexp-quote "** Head 1.2"))))
869 ;; 4. Greater element tests.
870 (org-test-with-temp-text
871 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
872 ;; 4.1. At a greater element: expected to skip contents.
873 (org-forward-element)
874 (should (looking-at (regexp-quote "Outside.")))
875 ;; 4.2. At the end of greater element contents: expected to skip
876 ;; to the end of the greater element.
877 (goto-line 2)
878 (org-forward-element)
879 (should (looking-at (regexp-quote "Outside."))))
880 ;; 5. List tests.
881 (org-test-with-temp-text "
882 - item1
884 - sub1
886 - sub2
888 - sub3
890 Inner paragraph.
892 - item2
894 Outside."
895 ;; 5.1. At list top point: expected to move to the element after
896 ;; the list.
897 (goto-line 2)
898 (org-forward-element)
899 (should (looking-at (regexp-quote "Outside.")))
900 ;; 5.2. Special case: at the first line of a sub-list, but not at
901 ;; beginning of line, move to next item.
902 (goto-line 2)
903 (forward-char)
904 (org-forward-element)
905 (should (looking-at "- item2"))
906 (goto-line 4)
907 (forward-char)
908 (org-forward-element)
909 (should (looking-at " - sub2"))
910 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
911 (goto-line 4)
912 (org-forward-element)
913 (should (looking-at (regexp-quote " Inner paragraph.")))
914 ;; 5.4. At sub-list end: expected to move outside the sub-list.
915 (goto-line 8)
916 (org-forward-element)
917 (should (looking-at (regexp-quote " Inner paragraph.")))
918 ;; 5.5. At an item: expected to move to next item, if any.
919 (goto-line 6)
920 (org-forward-element)
921 (should (looking-at " - sub3"))))
923 (ert-deftest test-org/backward-element ()
924 "Test `org-backward-element' specifications."
925 ;; 1. Should error at BOB.
926 (org-test-with-temp-text " \nParagraph."
927 (should-error (org-backward-element)))
928 ;; 2. Should move at BOB when called on the first element in buffer.
929 (should
930 (org-test-with-temp-text "\n#+TITLE: test"
931 (progn (forward-line)
932 (org-backward-element)
933 (bobp))))
934 ;; 3. Not at the beginning of an element: move at its beginning.
935 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
936 (goto-line 3)
937 (end-of-line)
938 (org-backward-element)
939 (should (looking-at (regexp-quote "Paragraph2."))))
940 ;; 4. Headline tests.
941 (org-test-with-temp-text "
942 * Head 1
943 ** Head 1.1
944 *** Head 1.1.1
945 ** Head 1.2"
946 ;; 4.1. At an headline beginning: move to previous headline at the
947 ;; same level.
948 (goto-line 5)
949 (org-backward-element)
950 (should (looking-at (regexp-quote "** Head 1.1")))
951 ;; 4.2. At an headline beginning: move to parent headline if no
952 ;; headline at the same level.
953 (goto-line 3)
954 (org-backward-element)
955 (should (looking-at (regexp-quote "* Head 1")))
956 ;; 4.3. At the first top-level headline: should error.
957 (goto-line 2)
958 (should-error (org-backward-element)))
959 ;; 5. At beginning of first element inside a greater element:
960 ;; expected to move to greater element's beginning.
961 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
962 (goto-line 3)
963 (org-backward-element)
964 (should (looking-at "#\\+BEGIN_CENTER")))
965 ;; 6. At the beginning of the first element in a section: should
966 ;; move back to headline, if any.
967 (should
968 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
969 (progn (goto-char (point-max))
970 (beginning-of-line)
971 (org-backward-element)
972 (org-at-heading-p))))
973 ;; 7. List tests.
974 (org-test-with-temp-text "
975 - item1
977 - sub1
979 - sub2
981 - sub3
983 Inner paragraph.
985 - item2
988 Outside."
989 ;; 7.1. At beginning of sub-list: expected to move to the
990 ;; paragraph before it.
991 (goto-line 4)
992 (org-backward-element)
993 (should (looking-at "item1"))
994 ;; 7.2. At an item in a list: expected to move at previous item.
995 (goto-line 8)
996 (org-backward-element)
997 (should (looking-at " - sub2"))
998 (goto-line 12)
999 (org-backward-element)
1000 (should (looking-at "- item1"))
1001 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1002 ;; beginning.
1003 (goto-line 10)
1004 (org-backward-element)
1005 (should (looking-at " - sub1"))
1006 (goto-line 15)
1007 (org-backward-element)
1008 (should (looking-at "- item1"))
1009 ;; 7.4. At blank-lines before list end: expected to move to top
1010 ;; item.
1011 (goto-line 14)
1012 (org-backward-element)
1013 (should (looking-at "- item1"))))
1015 (ert-deftest test-org/up-element ()
1016 "Test `org-up-element' specifications."
1017 ;; 1. At BOB or with no surrounding element: should error.
1018 (org-test-with-temp-text "Paragraph."
1019 (should-error (org-up-element)))
1020 (org-test-with-temp-text "* Head1\n* Head2"
1021 (goto-line 2)
1022 (should-error (org-up-element)))
1023 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1024 (goto-line 3)
1025 (should-error (org-up-element)))
1026 ;; 2. At an headline: move to parent headline.
1027 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1028 (goto-line 3)
1029 (org-up-element)
1030 (should (looking-at "\\* Head1")))
1031 ;; 3. Inside a greater element: move to greater element beginning.
1032 (org-test-with-temp-text
1033 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1034 (goto-line 3)
1035 (org-up-element)
1036 (should (looking-at "#\\+BEGIN_CENTER")))
1037 ;; 4. List tests.
1038 (org-test-with-temp-text "* Top
1039 - item1
1041 - sub1
1043 - sub2
1045 Paragraph within sub2.
1047 - item2"
1048 ;; 4.1. Within an item: move to the item beginning.
1049 (goto-line 8)
1050 (org-up-element)
1051 (should (looking-at " - sub2"))
1052 ;; 4.2. At an item in a sub-list: move to parent item.
1053 (goto-line 4)
1054 (org-up-element)
1055 (should (looking-at "- item1"))
1056 ;; 4.3. At an item in top list: move to beginning of whole list.
1057 (goto-line 10)
1058 (org-up-element)
1059 (should (looking-at "- item1"))
1060 ;; 4.4. Special case. At very top point: should move to parent of
1061 ;; list.
1062 (goto-line 2)
1063 (org-up-element)
1064 (should (looking-at "\\* Top"))))
1066 (ert-deftest test-org/down-element ()
1067 "Test `org-down-element' specifications."
1068 ;; Error when the element hasn't got a recursive type.
1069 (org-test-with-temp-text "Paragraph."
1070 (should-error (org-down-element)))
1071 ;; Error when the element has no contents
1072 (org-test-with-temp-text "* Headline"
1073 (should-error (org-down-element)))
1074 ;; When at a plain-list, move to first item.
1075 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1076 (goto-line 2)
1077 (org-down-element)
1078 (should (looking-at " - Item 1.1")))
1079 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1080 (org-down-element)
1081 (should (looking-at " Item 1")))
1082 ;; When at a table, move to first row
1083 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1084 (org-down-element)
1085 (should (looking-at " a | b |")))
1086 ;; Otherwise, move inside the greater element.
1087 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1088 (org-down-element)
1089 (should (looking-at "Paragraph"))))
1091 (ert-deftest test-org/drag-element-backward ()
1092 "Test `org-drag-element-backward' specifications."
1093 ;; 1. Error when trying to move first element of buffer.
1094 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1095 (should-error (org-drag-element-backward)))
1096 ;; 2. Error when trying to swap nested elements.
1097 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1098 (forward-line)
1099 (should-error (org-drag-element-backward)))
1100 ;; 3. Error when trying to swap an headline element and
1101 ;; a non-headline element.
1102 (org-test-with-temp-text "Test.\n* Head 1"
1103 (forward-line)
1104 (should-error (org-drag-element-backward)))
1105 ;; 4. Otherwise, swap elements, preserving column and blank lines
1106 ;; between elements.
1107 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
1108 (search-forward "graph")
1109 (org-drag-element-backward)
1110 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
1111 (should (looking-at " 2")))
1112 ;; 5. Preserve visibility of elements and their contents.
1113 (org-test-with-temp-text "
1114 #+BEGIN_CENTER
1115 Text.
1116 #+END_CENTER
1117 - item 1
1118 #+BEGIN_QUOTE
1119 Text.
1120 #+END_QUOTE"
1121 (while (search-forward "BEGIN_" nil t) (org-cycle))
1122 (search-backward "- item 1")
1123 (org-drag-element-backward)
1124 (should
1125 (equal
1126 '((63 . 82) (26 . 48))
1127 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1128 (overlays-in (point-min) (point-max)))))))
1130 (ert-deftest test-org/drag-element-forward ()
1131 "Test `org-drag-element-forward' specifications."
1132 ;; 1. Error when trying to move first element of buffer.
1133 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1134 (goto-line 3)
1135 (should-error (org-drag-element-forward)))
1136 ;; 2. Error when trying to swap nested elements.
1137 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1138 (forward-line)
1139 (should-error (org-drag-element-forward)))
1140 ;; 3. Error when trying to swap a non-headline element and an
1141 ;; headline.
1142 (org-test-with-temp-text "Test.\n* Head 1"
1143 (should-error (org-drag-element-forward)))
1144 ;; 4. Otherwise, swap elements, preserving column and blank lines
1145 ;; between elements.
1146 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
1147 (search-forward "graph")
1148 (org-drag-element-forward)
1149 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
1150 (should (looking-at " 1")))
1151 ;; 5. Preserve visibility of elements and their contents.
1152 (org-test-with-temp-text "
1153 #+BEGIN_CENTER
1154 Text.
1155 #+END_CENTER
1156 - item 1
1157 #+BEGIN_QUOTE
1158 Text.
1159 #+END_QUOTE"
1160 (while (search-forward "BEGIN_" nil t) (org-cycle))
1161 (search-backward "#+BEGIN_CENTER")
1162 (org-drag-element-forward)
1163 (should
1164 (equal
1165 '((63 . 82) (26 . 48))
1166 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1167 (overlays-in (point-min) (point-max)))))))
1171 ;;; Planning
1173 (ert-deftest test-org/timestamp-has-time-p ()
1174 "Test `org-timestamp-has-time-p' specifications."
1175 ;; With time.
1176 (should
1177 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1178 (org-timestamp-has-time-p (org-element-context))))
1179 ;; Without time.
1180 (should-not
1181 (org-test-with-temp-text "<2012-03-29 Thu>"
1182 (org-timestamp-has-time-p (org-element-context)))))
1184 (ert-deftest test-org/timestamp-format ()
1185 "Test `org-timestamp-format' specifications."
1186 ;; Regular test.
1187 (should
1188 (equal
1189 "2012-03-29 16:40"
1190 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1191 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
1192 ;; Range end.
1193 (should
1194 (equal
1195 "2012-03-29"
1196 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1197 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
1199 (ert-deftest test-org/timestamp-split-range ()
1200 "Test `org-timestamp-split-range' specifications."
1201 ;; Extract range start (active).
1202 (should
1203 (equal '(2012 3 29)
1204 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1205 (let ((ts (org-timestamp-split-range (org-element-context))))
1206 (mapcar (lambda (p) (org-element-property p ts))
1207 '(:year-end :month-end :day-end))))))
1208 ;; Extract range start (inactive)
1209 (should
1210 (equal '(2012 3 29)
1211 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1212 (let ((ts (org-timestamp-split-range (org-element-context))))
1213 (mapcar (lambda (p) (org-element-property p ts))
1214 '(:year-end :month-end :day-end))))))
1215 ;; Extract range end (active).
1216 (should
1217 (equal '(2012 3 30)
1218 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1219 (let ((ts (org-timestamp-split-range
1220 (org-element-context) t)))
1221 (mapcar (lambda (p) (org-element-property p ts))
1222 '(:year-end :month-end :day-end))))))
1223 ;; Extract range end (inactive)
1224 (should
1225 (equal '(2012 3 30)
1226 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1227 (let ((ts (org-timestamp-split-range
1228 (org-element-context) t)))
1229 (mapcar (lambda (p) (org-element-property p ts))
1230 '(:year-end :month-end :day-end))))))
1231 ;; Return the timestamp if not a range.
1232 (should
1233 (org-test-with-temp-text "[2012-03-29 Thu]"
1234 (let* ((ts-orig (org-element-context))
1235 (ts-copy (org-timestamp-split-range ts-orig)))
1236 (eq ts-orig ts-copy))))
1237 (should
1238 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1239 (let* ((ts-orig (org-element-context))
1240 (ts-copy (org-timestamp-split-range ts-orig)))
1241 (eq ts-orig ts-copy))))
1242 ;; Check that parent is the same when a range was split.
1243 (should
1244 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1245 (let* ((ts-orig (org-element-context))
1246 (ts-copy (org-timestamp-split-range ts-orig)))
1247 (eq (org-element-property :parent ts-orig)
1248 (org-element-property :parent ts-copy))))))
1250 (ert-deftest test-org/timestamp-translate ()
1251 "Test `org-timestamp-translate' specifications."
1252 ;; Translate whole date range.
1253 (should
1254 (equal "<29>--<30>"
1255 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1256 (let ((org-display-custom-times t)
1257 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1258 (org-timestamp-translate (org-element-context))))))
1259 ;; Translate date range start.
1260 (should
1261 (equal "<29>"
1262 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1263 (let ((org-display-custom-times t)
1264 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1265 (org-timestamp-translate (org-element-context) 'start)))))
1266 ;; Translate date range end.
1267 (should
1268 (equal "<30>"
1269 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1270 (let ((org-display-custom-times t)
1271 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1272 (org-timestamp-translate (org-element-context) 'end)))))
1273 ;; Translate time range.
1274 (should
1275 (equal "<08>--<16>"
1276 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
1277 (let ((org-display-custom-times t)
1278 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
1279 (org-timestamp-translate (org-element-context))))))
1280 ;; Translate non-range timestamp.
1281 (should
1282 (equal "<29>"
1283 (org-test-with-temp-text "<2012-03-29 Thu>"
1284 (let ((org-display-custom-times t)
1285 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1286 (org-timestamp-translate (org-element-context))))))
1287 ;; Do not change `diary' timestamps.
1288 (should
1289 (equal "<%%(org-float t 4 2)>"
1290 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1291 (let ((org-display-custom-times t)
1292 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1293 (org-timestamp-translate (org-element-context)))))))
1297 ;;; Targets and Radio Targets
1299 (ert-deftest test-org/all-targets ()
1300 "Test `org-all-targets' specifications."
1301 ;; Without an argument.
1302 (should
1303 (equal '("radio-target" "target")
1304 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
1305 (org-all-targets))))
1306 (should
1307 (equal '("radio-target")
1308 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
1309 ;; With argument.
1310 (should
1311 (equal '("radio-target")
1312 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
1313 (org-all-targets t)))))
1316 ;;; Visibility
1318 (ert-deftest test-org/flag-drawer ()
1319 "Test `org-flag-drawer' specifications."
1320 ;; Hide drawer.
1321 (should
1322 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
1323 (org-flag-drawer t)
1324 (get-char-property (line-end-position) 'invisible)))
1325 ;; Show drawer.
1326 (should-not
1327 (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
1328 (org-flag-drawer t)
1329 (org-flag-drawer nil)
1330 (get-char-property (line-end-position) 'invisible)))
1331 ;; Test optional argument.
1332 (should
1333 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
1334 (let ((drawer (save-excursion (search-forward ":D2")
1335 (org-element-at-point))))
1336 (org-flag-drawer t drawer)
1337 (get-char-property (progn (search-forward ":D2") (line-end-position))
1338 'invisible))))
1339 (should-not
1340 (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
1341 (let ((drawer (save-excursion (search-forward ":D2")
1342 (org-element-at-point))))
1343 (org-flag-drawer t drawer)
1344 (get-char-property (line-end-position) 'invisible))))
1345 ;; Do not hide fake drawers.
1346 (should-not
1347 (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
1348 (forward-line 1)
1349 (org-flag-drawer t)
1350 (get-char-property (line-end-position) 'invisible)))
1351 ;; Do not hide incomplete drawers.
1352 (should-not
1353 (org-test-with-temp-text ":D:\nparagraph"
1354 (forward-line 1)
1355 (org-flag-drawer t)
1356 (get-char-property (line-end-position) 'invisible))))
1359 (provide 'test-org)
1361 ;;; test-org.el ends here