3 ;; Copyright (c) ߚ David Maus
6 ;; Released under the GNU General Public License version 3
7 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
11 ;; Template test file for Org-mode tests
14 (ert-deftest test-org
/org-link-escape-ascii-character
()
15 "Escape an ascii character."
19 (org-link-escape "["))))
21 (ert-deftest test-org
/org-link-escape-ascii-ctrl-character
()
22 "Escape an ascii control character."
26 (org-link-escape "\t"))))
28 (ert-deftest test-org
/org-link-escape-multibyte-character
()
29 "Escape an unicode multibyte character."
33 (org-link-escape "€"))))
35 (ert-deftest test-org
/org-link-escape-custom-table
()
36 "Escape string with custom character table."
40 (org-link-escape "Foo:Bar\n" '(?\
: ?\B
)))))
42 (ert-deftest test-org
/org-link-escape-custom-table-merge
()
43 "Escape string with custom table merged with default table."
46 "%5BF%6F%6F%3A%42ar%0A%5D"
47 (org-link-escape "[Foo:Bar\n]" '(?\
: ?\B ?\o
) t
))))
49 (ert-deftest test-org
/org-link-unescape-ascii-character
()
50 "Unescape an ascii character."
54 (org-link-unescape "%5B"))))
56 (ert-deftest test-org
/org-link-unescape-ascii-ctrl-character
()
57 "Unescpae an ascii control character."
61 (org-link-unescape "%0A"))))
63 (ert-deftest test-org
/org-link-unescape-multibyte-character
()
64 "Unescape unicode multibyte character."
68 (org-link-unescape "%E2%82%AC"))))
70 (ert-deftest test-org
/org-link-unescape-ascii-extended-char
()
71 "Unescape old style percent escaped character."
75 (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1
))))
77 (ert-deftest test-org
/org-link-escape-url-with-escaped-char
()
78 "Escape and unscape a URL that includes an escaped char.
79 http://article.gmane.org/gmane.emacs.orgmode/21459/"
82 "http://some.host.com/form?&id=blah%2Bblah25"
83 (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
85 (ert-deftest test-org
/accumulated-properties-in-drawers
()
86 "Ensure properties accumulate in subtree drawers."
87 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
88 (org-babel-next-src-block)
89 (should (equal '(2 1) (org-babel-execute-src-block)))))
97 ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
98 ;; a target keyword (aka an invisible target: #+TARGET: text), to
99 ;; a named element (#+name: text) and to headlines (* Text).
101 (ert-deftest test-org
/fuzzy-links
()
102 "Test fuzzy links specifications."
103 ;; 1. Fuzzy link goes in priority to a matching target.
104 (org-test-with-temp-text
105 "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
108 (should (looking-at "<<Test>>")))
109 ;; 2. Fuzzy link should then go to a matching target keyword.
110 (org-test-with-temp-text
111 "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
114 (should (looking-at "#\\+TARGET: Test")))
115 ;; 3. Then fuzzy link points to an element with a given name.
116 (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
119 (should (looking-at "#\\+NAME: Test")))
120 ;; 4. A target still lead to a matching headline otherwise.
121 (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
124 (should (looking-at "\\* Head2")))
125 ;; 5. With a leading star in link, enforce heading match.
126 (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
129 (should (looking-at "\\* Test"))))
135 (ert-deftest test-org
/fill-paragraph
()
136 "Test `org-fill-paragraph' specifications."
137 ;; At an Org table, align it.
138 (org-test-with-temp-text "|a|"
140 (should (equal (buffer-string) "| a |\n")))
141 ;; At a paragraph, preserve line breaks.
142 (org-test-with-temp-text "some \\\\\nlong\ntext"
143 (let ((fill-column 20))
145 (should (equal (buffer-string) "some \\\\\nlong text"))))
146 ;; Correctly fill a paragraph when point is at its very end.
149 (org-test-with-temp-text "A\nB"
150 (let ((fill-column 20))
151 (goto-char (point-max))
154 ;; Correctly fill the last paragraph of a greater element.
156 (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
157 (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
158 (let ((fill-column 8))
163 ;; Special case: Fill first paragraph when point is at an item or
164 ;; a plain-list or a footnote reference.
167 (org-test-with-temp-text "- A\n B"
168 (let ((fill-column 20))
173 (org-test-with-temp-text "[fn:1] A\nB"
174 (let ((fill-column 20))
177 ;; At a verse block, fill paragraph at point, also preserving line
178 ;; breaks. Though, do nothing when point is at the block
180 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
182 (let ((fill-column 20))
184 (should (equal (buffer-string)
185 "#+BEGIN_VERSE\nSome \\\\\nlong text\n#+END_VERSE"))))
186 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
187 (let ((fill-column 20))
189 (should (equal (buffer-string)
190 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
191 ;; Fill contents of `comment-block' elements.
194 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
195 (let ((fill-column 20))
199 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
200 ;; Fill `comment' elements.
203 (org-test-with-temp-text " # A\n # B"
204 (let ((fill-column 20))
207 ;; Do nothing at affiliated keywords.
208 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
209 (let ((fill-column 20))
211 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
213 (ert-deftest test-org
/auto-fill-function
()
214 "Test auto-filling features."
215 ;; Auto fill paragraph.
218 (org-test-with-temp-text "12345 7890"
219 (let ((fill-column 5))
221 (org-auto-fill-function)
223 ;; Auto fill first paragraph in an item.
225 (equal "- 12345\n 7890"
226 (org-test-with-temp-text "- 12345 7890"
227 (let ((fill-column 7))
229 (org-auto-fill-function)
231 ;; Auto fill comments.
233 (equal " # 12345\n # 7890"
234 (org-test-with-temp-text " # 12345 7890"
235 (let ((fill-column 10))
237 (org-auto-fill-function)
239 ;; Verse and comment block: auto fill contents.
241 (equal "#+BEGIN_VERSE\n12345\n7890\n#+END_VERSE"
242 (org-test-with-temp-text "#+BEGIN_VERSE\n12345 7890\n#+END_VERSE"
243 (let ((fill-column 5))
246 (org-auto-fill-function)
249 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
250 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
251 (let ((fill-column 5))
254 (org-auto-fill-function)
256 ;; Do not fill if a new item could be created.
259 (org-test-with-temp-text "12345 - 90"
260 (let ((fill-column 5))
262 (org-auto-fill-function)
264 ;; Do not fill if a line break could be introduced.
266 (equal "123\\\\\n7890"
267 (org-test-with-temp-text "123\\\\ 7890"
268 (let ((fill-column 6))
270 (org-auto-fill-function)
272 ;; Do not fill affiliated keywords.
274 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
275 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
276 (let ((fill-column 20))
278 (org-auto-fill-function)
285 (ert-deftest test-org
/comment-dwim
()
286 "Test `comment-dwim' behaviour in an Org buffer."
287 ;; No region selected, no comment on current line and line not
288 ;; empty: insert comment on line above.
291 (org-test-with-temp-text "Comment"
292 (progn (call-interactively 'comment-dwim
)
294 ;; No region selected, no comment on current line and line empty:
295 ;; insert comment on this line.
297 (equal "# \nParagraph"
298 (org-test-with-temp-text "\nParagraph"
299 (progn (call-interactively 'comment-dwim
)
301 ;; No region selected, and a comment on this line: indent it.
303 (equal "* Headline\n # Comment"
304 (org-test-with-temp-text "* Headline\n# Comment"
305 (progn (forward-line)
306 (let ((org-adapt-indentation t
))
307 (call-interactively 'comment-dwim
))
309 ;; Also recognize single # at column 0 as comments.
312 (org-test-with-temp-text "# Comment"
313 (progn (forward-line)
314 (call-interactively 'comment-dwim
)
316 ;; Region selected and only comments and blank lines within it:
317 ;; un-comment all commented lines.
319 (equal "Comment 1\n\nComment 2"
320 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
322 (transient-mark-mode 1)
323 (push-mark (point) t t
)
324 (goto-char (point-max))
325 (call-interactively 'comment-dwim
)
327 ;; Region selected without comments: comment all non-blank lines.
329 (equal "# Comment 1\n\n# Comment 2"
330 (org-test-with-temp-text "Comment 1\n\nComment 2"
332 (transient-mark-mode 1)
333 (push-mark (point) t t
)
334 (goto-char (point-max))
335 (call-interactively 'comment-dwim
)
342 (ert-deftest test-org
/mark-subtree
()
343 "Test `org-mark-subtree' specifications."
344 ;; Error when point is before first headline.
346 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
347 (progn (transient-mark-mode 1)
348 (org-mark-subtree))))
349 ;; Without argument, mark current subtree.
353 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
354 (progn (transient-mark-mode 1)
357 (list (region-beginning) (region-end))))))
358 ;; With an argument, move ARG up.
362 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
363 (progn (transient-mark-mode 1)
366 (list (region-beginning) (region-end))))))
367 ;; Do not get fooled with inlinetasks.
368 (when (featurep 'org-inlinetask
)
371 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
372 (progn (transient-mark-mode 1)
374 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
375 (region-beginning)))))))
381 (ert-deftest test-org
/forward-element
()
382 "Test `org-forward-element' specifications."
383 ;; 1. At EOB: should error.
384 (org-test-with-temp-text "Some text\n"
385 (goto-char (point-max))
386 (should-error (org-forward-element)))
387 ;; 2. Standard move: expected to ignore blank lines.
388 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
389 (org-forward-element)
390 (should (looking-at "Second paragraph.")))
391 ;; 3. Headline tests.
392 (org-test-with-temp-text "
397 ;; 3.1. At an headline beginning: move to next headline at the
400 (org-forward-element)
401 (should (looking-at "** Head 1.2"))
402 ;; 3.2. At an headline beginning: move to parent headline if no
403 ;; headline at the same level.
405 (org-forward-element)
406 (should (looking-at "** Head 1.2")))
407 ;; 4. Greater element tests.
408 (org-test-with-temp-text
409 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
410 ;; 4.1. At a greater element: expected to skip contents.
411 (org-forward-element)
412 (should (looking-at "Outside."))
413 ;; 4.2. At the end of greater element contents: expected to skip
414 ;; to the end of the greater element.
416 (org-forward-element)
417 (should (looking-at "Outside.")))
419 (org-test-with-temp-text "
433 ;; 5.1. At list top point: expected to move to the element after
436 (org-forward-element)
437 (should (looking-at "Outside."))
438 ;; 5.2. Special case: at the first line of a sub-list, but not at
439 ;; beginning of line, move to next item.
442 (org-forward-element)
443 (should (looking-at "- item2"))
446 (org-forward-element)
447 (should (looking-at " - sub2"))
448 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
450 (org-forward-element)
451 (should (looking-at " Inner paragraph."))
452 ;; 5.4. At sub-list end: expected to move outside the sub-list.
454 (org-forward-element)
455 (should (looking-at " Inner paragraph."))
456 ;; 5.5. At an item: expected to move to next item, if any.
458 (org-forward-element)
459 (should (looking-at " - sub3"))))
461 (ert-deftest test-org
/backward-element
()
462 "Test `org-backward-element' specifications."
463 ;; 1. At BOB (modulo some white spaces): should error.
464 (org-test-with-temp-text " \nParagraph."
465 (org-skip-whitespace)
466 (should-error (org-backward-element)))
467 ;; 2. Not at the beginning of an element: move at its beginning.
468 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
471 (org-backward-element)
472 (should (looking-at "Paragraph2.")))
473 ;; 3. Headline tests.
474 (org-test-with-temp-text "
479 ;; 3.1. At an headline beginning: move to previous headline at the
482 (org-backward-element)
483 (should (looking-at "** Head 1.1"))
484 ;; 3.2. At an headline beginning: move to parent headline if no
485 ;; headline at the same level.
487 (org-backward-element)
488 (should (looking-at "* Head 1"))
489 ;; 3.3. At the first top-level headline: should error.
491 (should-error (org-backward-element)))
492 ;; 4. At beginning of first element inside a greater element:
493 ;; expected to move to greater element's beginning.
494 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER."
496 (org-backward-element)
497 (should (looking-at "#\\+BEGIN_CENTER")))
499 (org-test-with-temp-text "
514 ;; 5.1. At beginning of sub-list: expected to move to the
515 ;; paragraph before it.
517 (org-backward-element)
518 (should (looking-at "item1"))
519 ;; 5.2. At an item in a list: expected to move at previous item.
521 (org-backward-element)
522 (should (looking-at " - sub2"))
524 (org-backward-element)
525 (should (looking-at "- item1"))
526 ;; 5.3. At end of list/sub-list: expected to move to list/sub-list
529 (org-backward-element)
530 (should (looking-at " - sub1"))
532 (org-backward-element)
533 (should (looking-at "- item1"))
534 ;; 5.4. At blank-lines before list end: expected to move to top
537 (org-backward-element)
538 (should (looking-at "- item1"))))
540 (ert-deftest test-org
/up-element
()
541 "Test `org-up-element' specifications."
542 ;; 1. At BOB or with no surrounding element: should error.
543 (org-test-with-temp-text "Paragraph."
544 (should-error (org-up-element)))
545 (org-test-with-temp-text "* Head1\n* Head2"
547 (should-error (org-up-element)))
548 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
550 (should-error (org-up-element)))
551 ;; 2. At an headline: move to parent headline.
552 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
555 (should (looking-at "\\* Head1")))
556 ;; 3. Inside a greater element: move to greater element beginning.
557 (org-test-with-temp-text
558 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
561 (should (looking-at "#\\+BEGIN_CENTER")))
563 (org-test-with-temp-text "* Top
570 Paragraph within sub2.
573 ;; 4.1. Within an item: move to the item beginning.
576 (should (looking-at " - sub2"))
577 ;; 4.2. At an item in a sub-list: move to parent item.
580 (should (looking-at "- item1"))
581 ;; 4.3. At an item in top list: move to beginning of whole list.
584 (should (looking-at "- item1"))
585 ;; 4.4. Special case. At very top point: should move to parent of
589 (should (looking-at "\\* Top"))))
591 (ert-deftest test-org
/down-element
()
592 "Test `org-down-element' specifications."
593 ;; Error when the element hasn't got a recursive type.
594 (org-test-with-temp-text "Paragraph."
595 (should-error (org-down-element)))
596 ;; Error when the element has no contents
597 (org-test-with-temp-text "* Headline"
598 (should-error (org-down-element)))
599 ;; When at a plain-list, move to first item.
600 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
603 (should (looking-at " - Item 1.1")))
604 (org-test-with-temp-text "#+NAME: list\n- Item 1"
606 (should (looking-at " Item 1")))
607 ;; When at a table, move to first row
608 (org-test-with-temp-text "#+NAME: table\n| a | b |"
610 (should (looking-at " a | b |")))
611 ;; Otherwise, move inside the greater element.
612 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
614 (should (looking-at "Paragraph"))))
616 (ert-deftest test-org
/drag-element-backward
()
617 "Test `org-drag-element-backward' specifications."
618 ;; 1. Error when trying to move first element of buffer.
619 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
620 (should-error (org-drag-element-backward)))
621 ;; 2. Error when trying to swap nested elements.
622 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
624 (should-error (org-drag-element-backward)))
625 ;; 3. Error when trying to swap an headline element and
626 ;; a non-headline element.
627 (org-test-with-temp-text "Test.\n* Head 1"
629 (should-error (org-drag-element-backward)))
630 ;; 4. Otherwise, swap elements, preserving column and blank lines
632 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
633 (search-forward "graph")
634 (org-drag-element-backward)
635 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
636 (should (looking-at " 2")))
637 ;; 5. Preserve visibility of elements and their contents.
638 (org-test-with-temp-text "
646 (while (search-forward "BEGIN_" nil t
) (org-cycle))
647 (search-backward "- item 1")
648 (org-drag-element-backward)
651 '((63 .
82) (26 .
48))
652 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
653 (overlays-in (point-min) (point-max)))))))
655 (ert-deftest test-org
/drag-element-forward
()
656 "Test `org-drag-element-forward' specifications."
657 ;; 1. Error when trying to move first element of buffer.
658 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
660 (should-error (org-drag-element-forward)))
661 ;; 2. Error when trying to swap nested elements.
662 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
664 (should-error (org-drag-element-forward)))
665 ;; 3. Error when trying to swap a non-headline element and an
667 (org-test-with-temp-text "Test.\n* Head 1"
668 (should-error (org-drag-element-forward)))
669 ;; 4. Otherwise, swap elements, preserving column and blank lines
671 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
672 (search-forward "graph")
673 (org-drag-element-forward)
674 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
675 (should (looking-at " 1")))
676 ;; 5. Preserve visibility of elements and their contents.
677 (org-test-with-temp-text "
685 (while (search-forward "BEGIN_" nil t
) (org-cycle))
686 (search-backward "#+BEGIN_CENTER")
687 (org-drag-element-forward)
690 '((63 .
82) (26 .
48))
691 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
692 (overlays-in (point-min) (point-max)))))))
697 ;;; test-org.el ends here