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