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 ;; Correctly fill an element in a narrowed buffer.
166 (org-test-with-temp-text "01234 6789"
167 (let ((fill-column 5))
168 (narrow-to-region 1 8)
171 ;; Special case: Fill first paragraph when point is at an item or
172 ;; a plain-list or a footnote reference.
175 (org-test-with-temp-text "- A\n B"
176 (let ((fill-column 20))
181 (org-test-with-temp-text "[fn:1] A\nB"
182 (let ((fill-column 20))
185 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
186 (let ((fill-column 20))
188 (should (equal (buffer-string)
189 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
190 ;; Fill contents of `comment-block' elements.
193 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
194 (let ((fill-column 20))
198 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
199 ;; Fill `comment' elements.
202 (org-test-with-temp-text " # A\n # B"
203 (let ((fill-column 20))
206 ;; Do nothing at affiliated keywords.
207 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
208 (let ((fill-column 20))
210 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
212 (ert-deftest test-org
/auto-fill-function
()
213 "Test auto-filling features."
214 ;; Auto fill paragraph.
217 (org-test-with-temp-text "12345 7890"
218 (let ((fill-column 5))
220 (org-auto-fill-function)
222 ;; Auto fill first paragraph in an item.
224 (equal "- 12345\n 7890"
225 (org-test-with-temp-text "- 12345 7890"
226 (let ((fill-column 7))
228 (org-auto-fill-function)
230 ;; Auto fill comments.
232 (equal " # 12345\n # 7890"
233 (org-test-with-temp-text " # 12345 7890"
234 (let ((fill-column 10))
236 (org-auto-fill-function)
238 ;; Comment block: auto fill contents.
240 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
241 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
242 (let ((fill-column 5))
245 (org-auto-fill-function)
248 (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
249 (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
250 (let ((fill-column 5))
253 (org-auto-fill-function)
255 ;; Do not fill if a new item could be created.
258 (org-test-with-temp-text "12345 - 90"
259 (let ((fill-column 5))
261 (org-auto-fill-function)
263 ;; Do not fill if a line break could be introduced.
265 (equal "123\\\\\n7890"
266 (org-test-with-temp-text "123\\\\ 7890"
267 (let ((fill-column 6))
269 (org-auto-fill-function)
271 ;; Do not fill affiliated keywords.
273 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
274 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
275 (let ((fill-column 20))
277 (org-auto-fill-function)
284 (ert-deftest test-org
/comment-dwim
()
285 "Test `comment-dwim' behaviour in an Org buffer."
286 ;; No region selected, no comment on current line and line not
287 ;; empty: insert comment on line above.
290 (org-test-with-temp-text "Comment"
291 (progn (call-interactively 'comment-dwim
)
293 ;; No region selected, no comment on current line and line empty:
294 ;; insert comment on this line.
296 (equal "# \nParagraph"
297 (org-test-with-temp-text "\nParagraph"
298 (progn (call-interactively 'comment-dwim
)
300 ;; No region selected, and a comment on this line: indent it.
302 (equal "* Headline\n # Comment"
303 (org-test-with-temp-text "* Headline\n# Comment"
304 (progn (forward-line)
305 (let ((org-adapt-indentation t
))
306 (call-interactively 'comment-dwim
))
308 ;; Also recognize single # at column 0 as comments.
311 (org-test-with-temp-text "# Comment"
312 (progn (forward-line)
313 (call-interactively 'comment-dwim
)
315 ;; Region selected and only comments and blank lines within it:
316 ;; un-comment all commented lines.
318 (equal "Comment 1\n\nComment 2"
319 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
321 (transient-mark-mode 1)
322 (push-mark (point) t t
)
323 (goto-char (point-max))
324 (call-interactively 'comment-dwim
)
326 ;; Region selected without comments: comment all non-blank lines.
328 (equal "# Comment 1\n\n# Comment 2"
329 (org-test-with-temp-text "Comment 1\n\nComment 2"
331 (transient-mark-mode 1)
332 (push-mark (point) t t
)
333 (goto-char (point-max))
334 (call-interactively 'comment-dwim
)
336 ;; In front of a keyword without region, insert a new comment.
338 (equal "# \n#+KEYWORD: value"
339 (org-test-with-temp-text "#+KEYWORD: value"
340 (progn (call-interactively 'comment-dwim
)
347 (ert-deftest test-org
/mark-subtree
()
348 "Test `org-mark-subtree' specifications."
349 ;; Error when point is before first headline.
351 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
352 (progn (transient-mark-mode 1)
353 (org-mark-subtree))))
354 ;; Without argument, mark current subtree.
358 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
359 (progn (transient-mark-mode 1)
362 (list (region-beginning) (region-end))))))
363 ;; With an argument, move ARG up.
367 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
368 (progn (transient-mark-mode 1)
371 (list (region-beginning) (region-end))))))
372 ;; Do not get fooled with inlinetasks.
373 (when (featurep 'org-inlinetask
)
376 (org-test-with-temp-text "* Headline\n*************** Task\nContents"
377 (progn (transient-mark-mode 1)
379 (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
380 (region-beginning)))))))
386 (ert-deftest test-org
/forward-element
()
387 "Test `org-forward-element' specifications."
388 ;; 1. At EOB: should error.
389 (org-test-with-temp-text "Some text\n"
390 (goto-char (point-max))
391 (should-error (org-forward-element)))
392 ;; 2. Standard move: expected to ignore blank lines.
393 (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
394 (org-forward-element)
395 (should (looking-at "Second paragraph.")))
396 ;; 3. Headline tests.
397 (org-test-with-temp-text "
402 ;; 3.1. At an headline beginning: move to next headline at the
405 (org-forward-element)
406 (should (looking-at "** Head 1.2"))
407 ;; 3.2. At an headline beginning: move to parent headline if no
408 ;; headline at the same level.
410 (org-forward-element)
411 (should (looking-at "** Head 1.2")))
412 ;; 4. Greater element tests.
413 (org-test-with-temp-text
414 "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
415 ;; 4.1. At a greater element: expected to skip contents.
416 (org-forward-element)
417 (should (looking-at "Outside."))
418 ;; 4.2. At the end of greater element contents: expected to skip
419 ;; to the end of the greater element.
421 (org-forward-element)
422 (should (looking-at "Outside.")))
424 (org-test-with-temp-text "
438 ;; 5.1. At list top point: expected to move to the element after
441 (org-forward-element)
442 (should (looking-at "Outside."))
443 ;; 5.2. Special case: at the first line of a sub-list, but not at
444 ;; beginning of line, move to next item.
447 (org-forward-element)
448 (should (looking-at "- item2"))
451 (org-forward-element)
452 (should (looking-at " - sub2"))
453 ;; 5.3 At sub-list beginning: expected to move after the sub-list.
455 (org-forward-element)
456 (should (looking-at " Inner paragraph."))
457 ;; 5.4. At sub-list end: expected to move outside the sub-list.
459 (org-forward-element)
460 (should (looking-at " Inner paragraph."))
461 ;; 5.5. At an item: expected to move to next item, if any.
463 (org-forward-element)
464 (should (looking-at " - sub3"))))
466 (ert-deftest test-org
/backward-element
()
467 "Test `org-backward-element' specifications."
468 ;; 1. At BOB (modulo some white spaces): should error.
469 (org-test-with-temp-text " \nParagraph."
470 (org-skip-whitespace)
471 (should-error (org-backward-element)))
472 ;; 2. Not at the beginning of an element: move at its beginning.
473 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
476 (org-backward-element)
477 (should (looking-at "Paragraph2.")))
478 ;; 3. Headline tests.
479 (org-test-with-temp-text "
484 ;; 3.1. At an headline beginning: move to previous headline at the
487 (org-backward-element)
488 (should (looking-at "** Head 1.1"))
489 ;; 3.2. At an headline beginning: move to parent headline if no
490 ;; headline at the same level.
492 (org-backward-element)
493 (should (looking-at "* Head 1"))
494 ;; 3.3. At the first top-level headline: should error.
496 (should-error (org-backward-element)))
497 ;; 4. At beginning of first element inside a greater element:
498 ;; expected to move to greater element's beginning.
499 (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER."
501 (org-backward-element)
502 (should (looking-at "#\\+BEGIN_CENTER")))
504 (org-test-with-temp-text "
519 ;; 5.1. At beginning of sub-list: expected to move to the
520 ;; paragraph before it.
522 (org-backward-element)
523 (should (looking-at "item1"))
524 ;; 5.2. At an item in a list: expected to move at previous item.
526 (org-backward-element)
527 (should (looking-at " - sub2"))
529 (org-backward-element)
530 (should (looking-at "- item1"))
531 ;; 5.3. At end of list/sub-list: expected to move to list/sub-list
534 (org-backward-element)
535 (should (looking-at " - sub1"))
537 (org-backward-element)
538 (should (looking-at "- item1"))
539 ;; 5.4. At blank-lines before list end: expected to move to top
542 (org-backward-element)
543 (should (looking-at "- item1"))))
545 (ert-deftest test-org
/up-element
()
546 "Test `org-up-element' specifications."
547 ;; 1. At BOB or with no surrounding element: should error.
548 (org-test-with-temp-text "Paragraph."
549 (should-error (org-up-element)))
550 (org-test-with-temp-text "* Head1\n* Head2"
552 (should-error (org-up-element)))
553 (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
555 (should-error (org-up-element)))
556 ;; 2. At an headline: move to parent headline.
557 (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
560 (should (looking-at "\\* Head1")))
561 ;; 3. Inside a greater element: move to greater element beginning.
562 (org-test-with-temp-text
563 "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
566 (should (looking-at "#\\+BEGIN_CENTER")))
568 (org-test-with-temp-text "* Top
575 Paragraph within sub2.
578 ;; 4.1. Within an item: move to the item beginning.
581 (should (looking-at " - sub2"))
582 ;; 4.2. At an item in a sub-list: move to parent item.
585 (should (looking-at "- item1"))
586 ;; 4.3. At an item in top list: move to beginning of whole list.
589 (should (looking-at "- item1"))
590 ;; 4.4. Special case. At very top point: should move to parent of
594 (should (looking-at "\\* Top"))))
596 (ert-deftest test-org
/down-element
()
597 "Test `org-down-element' specifications."
598 ;; Error when the element hasn't got a recursive type.
599 (org-test-with-temp-text "Paragraph."
600 (should-error (org-down-element)))
601 ;; Error when the element has no contents
602 (org-test-with-temp-text "* Headline"
603 (should-error (org-down-element)))
604 ;; When at a plain-list, move to first item.
605 (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
608 (should (looking-at " - Item 1.1")))
609 (org-test-with-temp-text "#+NAME: list\n- Item 1"
611 (should (looking-at " Item 1")))
612 ;; When at a table, move to first row
613 (org-test-with-temp-text "#+NAME: table\n| a | b |"
615 (should (looking-at " a | b |")))
616 ;; Otherwise, move inside the greater element.
617 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
619 (should (looking-at "Paragraph"))))
621 (ert-deftest test-org
/drag-element-backward
()
622 "Test `org-drag-element-backward' specifications."
623 ;; 1. Error when trying to move first element of buffer.
624 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
625 (should-error (org-drag-element-backward)))
626 ;; 2. Error when trying to swap nested elements.
627 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
629 (should-error (org-drag-element-backward)))
630 ;; 3. Error when trying to swap an headline element and
631 ;; a non-headline element.
632 (org-test-with-temp-text "Test.\n* Head 1"
634 (should-error (org-drag-element-backward)))
635 ;; 4. Otherwise, swap elements, preserving column and blank lines
637 (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
638 (search-forward "graph")
639 (org-drag-element-backward)
640 (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
641 (should (looking-at " 2")))
642 ;; 5. Preserve visibility of elements and their contents.
643 (org-test-with-temp-text "
651 (while (search-forward "BEGIN_" nil t
) (org-cycle))
652 (search-backward "- item 1")
653 (org-drag-element-backward)
656 '((63 .
82) (26 .
48))
657 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
658 (overlays-in (point-min) (point-max)))))))
660 (ert-deftest test-org
/drag-element-forward
()
661 "Test `org-drag-element-forward' specifications."
662 ;; 1. Error when trying to move first element of buffer.
663 (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
665 (should-error (org-drag-element-forward)))
666 ;; 2. Error when trying to swap nested elements.
667 (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
669 (should-error (org-drag-element-forward)))
670 ;; 3. Error when trying to swap a non-headline element and an
672 (org-test-with-temp-text "Test.\n* Head 1"
673 (should-error (org-drag-element-forward)))
674 ;; 4. Otherwise, swap elements, preserving column and blank lines
676 (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
677 (search-forward "graph")
678 (org-drag-element-forward)
679 (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
680 (should (looking-at " 1")))
681 ;; 5. Preserve visibility of elements and their contents.
682 (org-test-with-temp-text "
690 (while (search-forward "BEGIN_" nil t
) (org-cycle))
691 (search-backward "#+BEGIN_CENTER")
692 (org-drag-element-forward)
695 '((63 .
82) (26 .
48))
696 (mapcar (lambda (ov) (cons (overlay-start ov
) (overlay-end ov
)))
697 (overlays-in (point-min) (point-max)))))))
702 ;;; test-org.el ends here