Fix headline insertion after an empty headline
[org-mode.git] / testing / lisp / test-org.el
blobacd3d54cfd5632dc030834a8bee3ba2264a7c6ae
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 item insert an item, in this case above.
394 (should
395 (let ((org-drawers '("MYDRAWER")))
396 (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
397 (forward-line)
398 (org-meta-return)
399 (beginning-of-line)
400 (looking-at "- $")))))
402 (ert-deftest test-org/insert-heading ()
403 "Test `org-insert-heading' specifications."
404 ;; FIXME: Test coverage is incomplete yet.
406 ;; In an empty buffer, insert a new headline.
407 (should
408 (equal "* "
409 (org-test-with-temp-text ""
410 (org-insert-heading)
411 (buffer-string))))
412 ;; At the beginning of a line, turn it into a headline
413 (should
414 (equal "* P"
415 (org-test-with-temp-text "<point>P"
416 (org-insert-heading)
417 (buffer-string))))
418 ;; In the middle of a line, split the line if allowed, otherwise,
419 ;; insert the headline at its end.
420 (should
421 (equal "Para\n* graph"
422 (org-test-with-temp-text "Para<point>graph"
423 (let ((org-M-RET-may-split-line '((default . t))))
424 (org-insert-heading))
425 (buffer-string))))
426 (should
427 (equal "Paragraph\n* "
428 (org-test-with-temp-text "Para<point>graph"
429 (let ((org-M-RET-may-split-line '((default . nil))))
430 (org-insert-heading))
431 (buffer-string))))
432 ;; Corner case: correctly insert a headline after an empty one.
433 (should
434 (equal "* \n* "
435 (org-test-with-temp-text "* <point>"
436 (org-insert-heading)
437 (buffer-string)))))
439 (ert-deftest test-org/insert-todo-heading-respect-content ()
440 "Test `org-insert-todo-heading-respect-content' specifications."
441 ;; Create a TODO heading.
442 (should
443 (org-test-with-temp-text "* H1\n Body"
444 (org-insert-todo-heading-respect-content)
445 (nth 2 (org-heading-components))))
446 ;; Add headline at the end of the first subtree
447 (should
448 (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
449 (search-forward "H1Body")
450 (org-insert-todo-heading-respect-content)
451 (and (eobp) (org-at-heading-p))))
452 ;; In a list, do not create a new item.
453 (should
454 (org-test-with-temp-text "* H\n- an item\n- another one"
455 (search-forward "an ")
456 (org-insert-todo-heading-respect-content)
457 (and (eobp) (org-at-heading-p)))))
461 ;;; Links
463 ;;;; Fuzzy Links
465 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
466 ;; a named element (#+name: text) and to headlines (* Text).
468 (ert-deftest test-org/fuzzy-links ()
469 "Test fuzzy links specifications."
470 ;; 1. Fuzzy link goes in priority to a matching target.
471 (should
472 (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
473 (goto-line 5)
474 (org-open-at-point)
475 (looking-at "<<Test>>")))
476 ;; 2. Then fuzzy link points to an element with a given name.
477 (should
478 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
479 (goto-line 5)
480 (org-open-at-point)
481 (looking-at "#\\+NAME: Test")))
482 ;; 3. A target still lead to a matching headline otherwise.
483 (should
484 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
485 (goto-line 4)
486 (org-open-at-point)
487 (looking-at "\\* Head2")))
488 ;; 4. With a leading star in link, enforce heading match.
489 (should
490 (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
491 (goto-line 3)
492 (org-open-at-point)
493 (looking-at "\\* Test"))))
496 ;;;; Link Escaping
498 (ert-deftest test-org/org-link-escape-ascii-character ()
499 "Escape an ascii character."
500 (should
501 (string=
502 "%5B"
503 (org-link-escape "["))))
505 (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
506 "Escape an ascii control character."
507 (should
508 (string=
509 "%09"
510 (org-link-escape "\t"))))
512 (ert-deftest test-org/org-link-escape-multibyte-character ()
513 "Escape an unicode multibyte character."
514 (should
515 (string=
516 "%E2%82%AC"
517 (org-link-escape "€"))))
519 (ert-deftest test-org/org-link-escape-custom-table ()
520 "Escape string with custom character table."
521 (should
522 (string=
523 "Foo%3A%42ar%0A"
524 (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
526 (ert-deftest test-org/org-link-escape-custom-table-merge ()
527 "Escape string with custom table merged with default table."
528 (should
529 (string=
530 "%5BF%6F%6F%3A%42ar%0A%5D"
531 (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
533 (ert-deftest test-org/org-link-unescape-ascii-character ()
534 "Unescape an ascii character."
535 (should
536 (string=
538 (org-link-unescape "%5B"))))
540 (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
541 "Unescpae an ascii control character."
542 (should
543 (string=
544 "\n"
545 (org-link-unescape "%0A"))))
547 (ert-deftest test-org/org-link-unescape-multibyte-character ()
548 "Unescape unicode multibyte character."
549 (should
550 (string=
551 "€"
552 (org-link-unescape "%E2%82%AC"))))
554 (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
555 "Unescape old style percent escaped character."
556 (should
557 (string=
558 "àâçèéêîôùû"
559 (decode-coding-string
560 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
562 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
563 "Escape and unescape a URL that includes an escaped char.
564 http://article.gmane.org/gmane.emacs.orgmode/21459/"
565 (should
566 (string=
567 "http://some.host.com/form?&id=blah%2Bblah25"
568 (org-link-unescape
569 (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
571 (ert-deftest test-org/org-link-escape-chars-browser ()
572 "Escape a URL to pass to `browse-url'."
573 (should
574 (string=
575 "http://some.host.com/search?q=%22Org%20mode%22"
576 (org-link-escape "http://some.host.com/search?q=\"Org mode\""
577 org-link-escape-chars-browser))))
581 ;;; Node Properties
583 (ert-deftest test-org/accumulated-properties-in-drawers ()
584 "Ensure properties accumulate in subtree drawers."
585 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
586 (org-babel-next-src-block)
587 (should (equal '(2 1) (org-babel-execute-src-block)))))
591 ;;; Mark Region
593 (ert-deftest test-org/mark-subtree ()
594 "Test `org-mark-subtree' specifications."
595 ;; Error when point is before first headline.
596 (should-error
597 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
598 (progn (transient-mark-mode 1)
599 (org-mark-subtree))))
600 ;; Without argument, mark current subtree.
601 (should
602 (equal
603 '(12 32)
604 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
605 (progn (transient-mark-mode 1)
606 (forward-line 2)
607 (org-mark-subtree)
608 (list (region-beginning) (region-end))))))
609 ;; With an argument, move ARG up.
610 (should
611 (equal
612 '(1 32)
613 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
614 (progn (transient-mark-mode 1)
615 (forward-line 2)
616 (org-mark-subtree 1)
617 (list (region-beginning) (region-end))))))
618 ;; Do not get fooled by inlinetasks.
619 (when (featurep 'org-inlinetask)
620 (should
621 (= 1
622 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
623 (progn (transient-mark-mode 1)
624 (forward-line 1)
625 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
626 (region-beginning)))))))
630 ;;; Navigation
632 (ert-deftest test-org/beginning-of-line ()
633 "Test `org-beginning-of-line' specifications."
634 ;; Standard test.
635 (should
636 (org-test-with-temp-text "Some text\nSome other text"
637 (progn (org-beginning-of-line) (bolp))))
638 ;; Standard test with `visual-line-mode'.
639 (should-not
640 (org-test-with-temp-text "A long line of text\nSome other text"
641 (progn (visual-line-mode)
642 (forward-char 2)
643 (dotimes (i 1000) (insert "very "))
644 (org-beginning-of-line)
645 (bolp))))
646 ;; At an headline with special movement.
647 (should
648 (org-test-with-temp-text "* TODO Headline"
649 (let ((org-special-ctrl-a/e t))
650 (org-end-of-line)
651 (and (progn (org-beginning-of-line) (looking-at "Headline"))
652 (progn (org-beginning-of-line) (bolp))
653 (progn (org-beginning-of-line) (looking-at "Headline")))))))
655 (ert-deftest test-org/end-of-line ()
656 "Test `org-end-of-line' specifications."
657 ;; Standard test.
658 (should
659 (org-test-with-temp-text "Some text\nSome other text"
660 (progn (org-end-of-line) (eolp))))
661 ;; Standard test with `visual-line-mode'.
662 (should-not
663 (org-test-with-temp-text "A long line of text\nSome other text"
664 (progn (visual-line-mode)
665 (forward-char 2)
666 (dotimes (i 1000) (insert "very "))
667 (goto-char (point-min))
668 (org-end-of-line)
669 (eolp))))
670 ;; At an headline with special movement.
671 (should
672 (org-test-with-temp-text "* Headline1 :tag:\n"
673 (let ((org-special-ctrl-a/e t))
674 (and (progn (org-end-of-line) (looking-at " :tag:"))
675 (progn (org-end-of-line) (eolp))
676 (progn (org-end-of-line) (looking-at " :tag:"))))))
677 ;; At an headline without special movement.
678 (should
679 (org-test-with-temp-text "* Headline2 :tag:\n"
680 (let ((org-special-ctrl-a/e nil))
681 (and (progn (org-end-of-line) (eolp))
682 (progn (org-end-of-line) (eolp))))))
683 ;; At an headline, with reversed movement.
684 (should
685 (org-test-with-temp-text "* Headline3 :tag:\n"
686 (let ((org-special-ctrl-a/e 'reversed)
687 (this-command last-command))
688 (and (progn (org-end-of-line) (eolp))
689 (progn (org-end-of-line) (looking-at " :tag:"))))))
690 ;; At a block without hidden contents.
691 (should
692 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
693 (progn (org-end-of-line) (eolp))))
694 ;; At a block with hidden contents.
695 (should-not
696 (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
697 (let ((org-special-ctrl-a/e t))
698 (org-hide-block-toggle)
699 (org-end-of-line)
700 (eobp)))))
702 (ert-deftest test-org/forward-paragraph ()
703 "Test `org-forward-paragraph' specifications."
704 ;; At end of buffer, return an error.
705 (should-error
706 (org-test-with-temp-text "Paragraph"
707 (goto-char (point-max))
708 (org-forward-paragraph)))
709 ;; Standard test.
710 (should
711 (org-test-with-temp-text "P1\n\nP2\n\nP3"
712 (org-forward-paragraph)
713 (looking-at "P2")))
714 ;; Ignore depth.
715 (should
716 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
717 (org-forward-paragraph)
718 (looking-at "P1")))
719 ;; Do not enter elements with invisible contents.
720 (should
721 (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
722 (org-hide-block-toggle)
723 (org-forward-paragraph)
724 (looking-at "P3")))
725 ;; On an affiliated keyword, jump to the beginning of the element.
726 (should
727 (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
728 (org-forward-paragraph)
729 (looking-at "Para")))
730 ;; On an item or a footnote definition, move to the second element
731 ;; inside, if any.
732 (should
733 (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
734 (org-forward-paragraph)
735 (looking-at " Paragraph")))
736 (should
737 (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
738 (org-forward-paragraph)
739 (looking-at "Paragraph")))
740 ;; On an item, or a footnote definition, when the first line is
741 ;; empty, move to the first item.
742 (should
743 (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
744 (org-forward-paragraph)
745 (looking-at " Paragraph")))
746 (should
747 (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
748 (org-forward-paragraph)
749 (looking-at "Paragraph")))
750 ;; On a table (resp. a property drawer) do not move through table
751 ;; rows (resp. node properties).
752 (should
753 (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
754 (org-forward-paragraph)
755 (looking-at "Paragraph")))
756 (should
757 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nParagraph"
758 (org-forward-paragraph)
759 (looking-at "Paragraph")))
760 ;; On a verse or source block, stop after blank lines.
761 (should
762 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
763 (org-forward-paragraph)
764 (looking-at "L2")))
765 (should
766 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
767 (org-forward-paragraph)
768 (looking-at "L2"))))
770 (ert-deftest test-org/backward-paragraph ()
771 "Test `org-backward-paragraph' specifications."
772 ;; Error at beginning of buffer.
773 (should-error
774 (org-test-with-temp-text "Paragraph"
775 (org-backward-paragraph)))
776 ;; Regular test.
777 (should
778 (org-test-with-temp-text "P1\n\nP2\n\nP3"
779 (goto-char (point-max))
780 (org-backward-paragraph)
781 (looking-at "P3")))
782 (should
783 (org-test-with-temp-text "P1\n\nP2\n\nP3"
784 (goto-char (point-max))
785 (beginning-of-line)
786 (org-backward-paragraph)
787 (looking-at "P2")))
788 ;; Ignore depth.
789 (should
790 (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
791 (goto-char (point-max))
792 (beginning-of-line)
793 (org-backward-paragraph)
794 (looking-at "P2")))
795 ;; Ignore invisible elements.
796 (should
797 (org-test-with-temp-text "* H1\n P1\n* H2"
798 (org-cycle)
799 (goto-char (point-max))
800 (beginning-of-line)
801 (org-backward-paragraph)
802 (bobp)))
803 ;; On an affiliated keyword, jump to the first one.
804 (should
805 (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
806 (search-forward "c2")
807 (org-backward-paragraph)
808 (looking-at "#\\+name")))
809 ;; On the second element in an item or a footnote definition, jump
810 ;; to item or the definition.
811 (should
812 (org-test-with-temp-text "- line1\n\n line2"
813 (goto-char (point-max))
814 (beginning-of-line)
815 (org-backward-paragraph)
816 (looking-at "- line1")))
817 (should
818 (org-test-with-temp-text "[fn:1] line1\n\n line2"
819 (goto-char (point-max))
820 (beginning-of-line)
821 (org-backward-paragraph)
822 (looking-at "\\[fn:1\\] line1")))
823 ;; On a table (resp. a property drawer), ignore table rows
824 ;; (resp. node properties).
825 (should
826 (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
827 (goto-char (point-max))
828 (beginning-of-line)
829 (org-backward-paragraph)
830 (bobp)))
831 (should
832 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nP1"
833 (goto-char (point-max))
834 (beginning-of-line)
835 (org-backward-paragraph)
836 (bobp)))
837 ;; On a source or verse block, stop before blank lines.
838 (should
839 (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
840 (search-forward "L3")
841 (beginning-of-line)
842 (org-backward-paragraph)
843 (looking-at "L2")))
844 (should
845 (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
846 (search-forward "L3")
847 (beginning-of-line)
848 (org-backward-paragraph)
849 (looking-at "L2"))))
851 (ert-deftest test-org/forward-element ()
852 "Test `org-forward-element' specifications."
853 ;; 1. At EOB: should error.
854 (org-test-with-temp-text "Some text\n"
855 (goto-char (point-max))
856 (should-error (org-forward-element)))
857 ;; 2. Standard move: expected to ignore blank lines.
858 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
859 (org-forward-element)
860 (should (looking-at (regexp-quote "Second paragraph."))))
861 ;; 3. Headline tests.
862 (org-test-with-temp-text "
863 * Head 1
864 ** Head 1.1
865 *** Head 1.1.1
866 ** Head 1.2"
867 ;; 3.1. At an headline beginning: move to next headline at the
868 ;; same level.
869 (goto-line 3)
870 (org-forward-element)
871 (should (looking-at (regexp-quote "** Head 1.2")))
872 ;; 3.2. At an headline beginning: move to parent headline if no
873 ;; headline at the same level.
874 (goto-line 3)
875 (org-forward-element)
876 (should (looking-at (regexp-quote "** Head 1.2"))))
877 ;; 4. Greater element tests.
878 (org-test-with-temp-text
879 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
880 ;; 4.1. At a greater element: expected to skip contents.
881 (org-forward-element)
882 (should (looking-at (regexp-quote "Outside.")))
883 ;; 4.2. At the end of greater element contents: expected to skip
884 ;; to the end of the greater element.
885 (goto-line 2)
886 (org-forward-element)
887 (should (looking-at (regexp-quote "Outside."))))
888 ;; 5. List tests.
889 (org-test-with-temp-text "
890 - item1
892 - sub1
894 - sub2
896 - sub3
898 Inner paragraph.
900 - item2
902 Outside."
903 ;; 5.1. At list top point: expected to move to the element after
904 ;; the list.
905 (goto-line 2)
906 (org-forward-element)
907 (should (looking-at (regexp-quote "Outside.")))
908 ;; 5.2. Special case: at the first line of a sub-list, but not at
909 ;; beginning of line, move to next item.
910 (goto-line 2)
911 (forward-char)
912 (org-forward-element)
913 (should (looking-at "- item2"))
914 (goto-line 4)
915 (forward-char)
916 (org-forward-element)
917 (should (looking-at " - sub2"))
918 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
919 (goto-line 4)
920 (org-forward-element)
921 (should (looking-at (regexp-quote " Inner paragraph.")))
922 ;; 5.4. At sub-list end: expected to move outside the sub-list.
923 (goto-line 8)
924 (org-forward-element)
925 (should (looking-at (regexp-quote " Inner paragraph.")))
926 ;; 5.5. At an item: expected to move to next item, if any.
927 (goto-line 6)
928 (org-forward-element)
929 (should (looking-at " - sub3"))))
931 (ert-deftest test-org/backward-element ()
932 "Test `org-backward-element' specifications."
933 ;; 1. Should error at BOB.
934 (org-test-with-temp-text " \nParagraph."
935 (should-error (org-backward-element)))
936 ;; 2. Should move at BOB when called on the first element in buffer.
937 (should
938 (org-test-with-temp-text "\n#+TITLE: test"
939 (progn (forward-line)
940 (org-backward-element)
941 (bobp))))
942 ;; 3. Not at the beginning of an element: move at its beginning.
943 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
944 (goto-line 3)
945 (end-of-line)
946 (org-backward-element)
947 (should (looking-at (regexp-quote "Paragraph2."))))
948 ;; 4. Headline tests.
949 (org-test-with-temp-text "
950 * Head 1
951 ** Head 1.1
952 *** Head 1.1.1
953 ** Head 1.2"
954 ;; 4.1. At an headline beginning: move to previous headline at the
955 ;; same level.
956 (goto-line 5)
957 (org-backward-element)
958 (should (looking-at (regexp-quote "** Head 1.1")))
959 ;; 4.2. At an headline beginning: move to parent headline if no
960 ;; headline at the same level.
961 (goto-line 3)
962 (org-backward-element)
963 (should (looking-at (regexp-quote "* Head 1")))
964 ;; 4.3. At the first top-level headline: should error.
965 (goto-line 2)
966 (should-error (org-backward-element)))
967 ;; 5. At beginning of first element inside a greater element:
968 ;; expected to move to greater element's beginning.
969 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
970 (goto-line 3)
971 (org-backward-element)
972 (should (looking-at "#\\+BEGIN_CENTER")))
973 ;; 6. At the beginning of the first element in a section: should
974 ;; move back to headline, if any.
975 (should
976 (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
977 (progn (goto-char (point-max))
978 (beginning-of-line)
979 (org-backward-element)
980 (org-at-heading-p))))
981 ;; 7. List tests.
982 (org-test-with-temp-text "
983 - item1
985 - sub1
987 - sub2
989 - sub3
991 Inner paragraph.
993 - item2
996 Outside."
997 ;; 7.1. At beginning of sub-list: expected to move to the
998 ;; paragraph before it.
999 (goto-line 4)
1000 (org-backward-element)
1001 (should (looking-at "item1"))
1002 ;; 7.2. At an item in a list: expected to move at previous item.
1003 (goto-line 8)
1004 (org-backward-element)
1005 (should (looking-at " - sub2"))
1006 (goto-line 12)
1007 (org-backward-element)
1008 (should (looking-at "- item1"))
1009 ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
1010 ;; beginning.
1011 (goto-line 10)
1012 (org-backward-element)
1013 (should (looking-at " - sub1"))
1014 (goto-line 15)
1015 (org-backward-element)
1016 (should (looking-at "- item1"))
1017 ;; 7.4. At blank-lines before list end: expected to move to top
1018 ;; item.
1019 (goto-line 14)
1020 (org-backward-element)
1021 (should (looking-at "- item1"))))
1023 (ert-deftest test-org/up-element ()
1024 "Test `org-up-element' specifications."
1025 ;; 1. At BOB or with no surrounding element: should error.
1026 (org-test-with-temp-text "Paragraph."
1027 (should-error (org-up-element)))
1028 (org-test-with-temp-text "* Head1\n* Head2"
1029 (goto-line 2)
1030 (should-error (org-up-element)))
1031 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
1032 (goto-line 3)
1033 (should-error (org-up-element)))
1034 ;; 2. At an headline: move to parent headline.
1035 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
1036 (goto-line 3)
1037 (org-up-element)
1038 (should (looking-at "\\* Head1")))
1039 ;; 3. Inside a greater element: move to greater element beginning.
1040 (org-test-with-temp-text
1041 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
1042 (goto-line 3)
1043 (org-up-element)
1044 (should (looking-at "#\\+BEGIN_CENTER")))
1045 ;; 4. List tests.
1046 (org-test-with-temp-text "* Top
1047 - item1
1049 - sub1
1051 - sub2
1053 Paragraph within sub2.
1055 - item2"
1056 ;; 4.1. Within an item: move to the item beginning.
1057 (goto-line 8)
1058 (org-up-element)
1059 (should (looking-at " - sub2"))
1060 ;; 4.2. At an item in a sub-list: move to parent item.
1061 (goto-line 4)
1062 (org-up-element)
1063 (should (looking-at "- item1"))
1064 ;; 4.3. At an item in top list: move to beginning of whole list.
1065 (goto-line 10)
1066 (org-up-element)
1067 (should (looking-at "- item1"))
1068 ;; 4.4. Special case. At very top point: should move to parent of
1069 ;; list.
1070 (goto-line 2)
1071 (org-up-element)
1072 (should (looking-at "\\* Top"))))
1074 (ert-deftest test-org/down-element ()
1075 "Test `org-down-element' specifications."
1076 ;; Error when the element hasn't got a recursive type.
1077 (org-test-with-temp-text "Paragraph."
1078 (should-error (org-down-element)))
1079 ;; Error when the element has no contents
1080 (org-test-with-temp-text "* Headline"
1081 (should-error (org-down-element)))
1082 ;; When at a plain-list, move to first item.
1083 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
1084 (goto-line 2)
1085 (org-down-element)
1086 (should (looking-at " - Item 1.1")))
1087 (org-test-with-temp-text "#+NAME: list\n- Item 1"
1088 (org-down-element)
1089 (should (looking-at " Item 1")))
1090 ;; When at a table, move to first row
1091 (org-test-with-temp-text "#+NAME: table\n| a | b |"
1092 (org-down-element)
1093 (should (looking-at " a | b |")))
1094 ;; Otherwise, move inside the greater element.
1095 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
1096 (org-down-element)
1097 (should (looking-at "Paragraph"))))
1099 (ert-deftest test-org/drag-element-backward ()
1100 "Test `org-drag-element-backward' specifications."
1101 ;; 1. Error when trying to move first element of buffer.
1102 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1103 (should-error (org-drag-element-backward)))
1104 ;; 2. Error when trying to swap nested elements.
1105 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1106 (forward-line)
1107 (should-error (org-drag-element-backward)))
1108 ;; 3. Error when trying to swap an headline element and
1109 ;; a non-headline element.
1110 (org-test-with-temp-text "Test.\n* Head 1"
1111 (forward-line)
1112 (should-error (org-drag-element-backward)))
1113 ;; 4. Otherwise, swap elements, preserving column and blank lines
1114 ;; between elements.
1115 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
1116 (search-forward "graph")
1117 (org-drag-element-backward)
1118 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
1119 (should (looking-at " 2")))
1120 ;; 5. Preserve visibility of elements and their contents.
1121 (org-test-with-temp-text "
1122 #+BEGIN_CENTER
1123 Text.
1124 #+END_CENTER
1125 - item 1
1126 #+BEGIN_QUOTE
1127 Text.
1128 #+END_QUOTE"
1129 (while (search-forward "BEGIN_" nil t) (org-cycle))
1130 (search-backward "- item 1")
1131 (org-drag-element-backward)
1132 (should
1133 (equal
1134 '((63 . 82) (26 . 48))
1135 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1136 (overlays-in (point-min) (point-max)))))))
1138 (ert-deftest test-org/drag-element-forward ()
1139 "Test `org-drag-element-forward' specifications."
1140 ;; 1. Error when trying to move first element of buffer.
1141 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
1142 (goto-line 3)
1143 (should-error (org-drag-element-forward)))
1144 ;; 2. Error when trying to swap nested elements.
1145 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
1146 (forward-line)
1147 (should-error (org-drag-element-forward)))
1148 ;; 3. Error when trying to swap a non-headline element and an
1149 ;; headline.
1150 (org-test-with-temp-text "Test.\n* Head 1"
1151 (should-error (org-drag-element-forward)))
1152 ;; 4. Otherwise, swap elements, preserving column and blank lines
1153 ;; between elements.
1154 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
1155 (search-forward "graph")
1156 (org-drag-element-forward)
1157 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
1158 (should (looking-at " 1")))
1159 ;; 5. Preserve visibility of elements and their contents.
1160 (org-test-with-temp-text "
1161 #+BEGIN_CENTER
1162 Text.
1163 #+END_CENTER
1164 - item 1
1165 #+BEGIN_QUOTE
1166 Text.
1167 #+END_QUOTE"
1168 (while (search-forward "BEGIN_" nil t) (org-cycle))
1169 (search-backward "#+BEGIN_CENTER")
1170 (org-drag-element-forward)
1171 (should
1172 (equal
1173 '((63 . 82) (26 . 48))
1174 (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
1175 (overlays-in (point-min) (point-max)))))))
1179 ;;; Planning
1181 (ert-deftest test-org/timestamp-has-time-p ()
1182 "Test `org-timestamp-has-time-p' specifications."
1183 ;; With time.
1184 (should
1185 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1186 (org-timestamp-has-time-p (org-element-context))))
1187 ;; Without time.
1188 (should-not
1189 (org-test-with-temp-text "<2012-03-29 Thu>"
1190 (org-timestamp-has-time-p (org-element-context)))))
1192 (ert-deftest test-org/timestamp-format ()
1193 "Test `org-timestamp-format' specifications."
1194 ;; Regular test.
1195 (should
1196 (equal
1197 "2012-03-29 16:40"
1198 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1199 (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
1200 ;; Range end.
1201 (should
1202 (equal
1203 "2012-03-29"
1204 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1205 (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
1207 (ert-deftest test-org/timestamp-split-range ()
1208 "Test `org-timestamp-split-range' specifications."
1209 ;; Extract range start (active).
1210 (should
1211 (equal '(2012 3 29)
1212 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1213 (let ((ts (org-timestamp-split-range (org-element-context))))
1214 (mapcar (lambda (p) (org-element-property p ts))
1215 '(:year-end :month-end :day-end))))))
1216 ;; Extract range start (inactive)
1217 (should
1218 (equal '(2012 3 29)
1219 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1220 (let ((ts (org-timestamp-split-range (org-element-context))))
1221 (mapcar (lambda (p) (org-element-property p ts))
1222 '(:year-end :month-end :day-end))))))
1223 ;; Extract range end (active).
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 ;; Extract range end (inactive)
1232 (should
1233 (equal '(2012 3 30)
1234 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1235 (let ((ts (org-timestamp-split-range
1236 (org-element-context) t)))
1237 (mapcar (lambda (p) (org-element-property p ts))
1238 '(:year-end :month-end :day-end))))))
1239 ;; Return the timestamp if not a range.
1240 (should
1241 (org-test-with-temp-text "[2012-03-29 Thu]"
1242 (let* ((ts-orig (org-element-context))
1243 (ts-copy (org-timestamp-split-range ts-orig)))
1244 (eq ts-orig ts-copy))))
1245 (should
1246 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1247 (let* ((ts-orig (org-element-context))
1248 (ts-copy (org-timestamp-split-range ts-orig)))
1249 (eq ts-orig ts-copy))))
1250 ;; Check that parent is the same when a range was split.
1251 (should
1252 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
1253 (let* ((ts-orig (org-element-context))
1254 (ts-copy (org-timestamp-split-range ts-orig)))
1255 (eq (org-element-property :parent ts-orig)
1256 (org-element-property :parent ts-copy))))))
1258 (ert-deftest test-org/timestamp-translate ()
1259 "Test `org-timestamp-translate' specifications."
1260 ;; Translate whole date range.
1261 (should
1262 (equal "<29>--<30>"
1263 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1264 (let ((org-display-custom-times t)
1265 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1266 (org-timestamp-translate (org-element-context))))))
1267 ;; Translate date range start.
1268 (should
1269 (equal "<29>"
1270 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1271 (let ((org-display-custom-times t)
1272 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1273 (org-timestamp-translate (org-element-context) 'start)))))
1274 ;; Translate date range end.
1275 (should
1276 (equal "<30>"
1277 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
1278 (let ((org-display-custom-times t)
1279 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1280 (org-timestamp-translate (org-element-context) 'end)))))
1281 ;; Translate time range.
1282 (should
1283 (equal "<08>--<16>"
1284 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
1285 (let ((org-display-custom-times t)
1286 (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
1287 (org-timestamp-translate (org-element-context))))))
1288 ;; Translate non-range timestamp.
1289 (should
1290 (equal "<29>"
1291 (org-test-with-temp-text "<2012-03-29 Thu>"
1292 (let ((org-display-custom-times t)
1293 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1294 (org-timestamp-translate (org-element-context))))))
1295 ;; Do not change `diary' timestamps.
1296 (should
1297 (equal "<%%(org-float t 4 2)>"
1298 (org-test-with-temp-text "<%%(org-float t 4 2)>"
1299 (let ((org-display-custom-times t)
1300 (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
1301 (org-timestamp-translate (org-element-context)))))))
1305 ;;; Targets and Radio Targets
1307 (ert-deftest test-org/all-targets ()
1308 "Test `org-all-targets' specifications."
1309 ;; Without an argument.
1310 (should
1311 (equal '("radio-target" "target")
1312 (org-test-with-temp-text "<<target>> <<<radio-target>>>\n: <<verb>>"
1313 (org-all-targets))))
1314 (should
1315 (equal '("radio-target")
1316 (org-test-with-temp-text "<<<radio-target>>>!" (org-all-targets))))
1317 ;; With argument.
1318 (should
1319 (equal '("radio-target")
1320 (org-test-with-temp-text "<<target>> <<<radio-target>>>"
1321 (org-all-targets t)))))
1324 (provide 'test-org)
1326 ;;; test-org.el ends here