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 ;; Special case: Fill first paragraph when point is at an item or
155 ;; a plain-list or a footnote reference.
158 (org-test-with-temp-text "- A\n B"
159 (let ((fill-column 20))
164 (org-test-with-temp-text "[fn:1] A\nB"
165 (let ((fill-column 20))
168 ;; At a verse block, fill paragraph at point, also preserving line
169 ;; breaks. Though, do nothing when point is at the block
171 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
173 (let ((fill-column 20))
175 (should (equal (buffer-string)
176 "#+BEGIN_VERSE\nSome \\\\\nlong text\n#+END_VERSE"))))
177 (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
178 (let ((fill-column 20))
180 (should (equal (buffer-string)
181 "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
182 ;; Fill contents of `comment-block' elements.
185 (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
186 (let ((fill-column 20))
190 "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
191 ;; Fill `comment' elements.
194 (org-test-with-temp-text " # A\n # B"
195 (let ((fill-column 20))
198 ;; Do nothing at affiliated keywords.
199 (org-test-with-temp-text "#+NAME: para\nSome\ntext."
200 (let ((fill-column 20))
202 (should (equal (buffer-string) "#+NAME: para\nSome\ntext.")))))
204 (ert-deftest test-org
/auto-fill-function
()
205 "Test auto-filling features."
206 ;; Auto fill paragraph.
209 (org-test-with-temp-text "12345 7890"
210 (let ((fill-column 5))
212 (org-auto-fill-function)
214 ;; Auto fill first paragraph in an item.
216 (equal "- 12345\n 7890"
217 (org-test-with-temp-text "- 12345 7890"
218 (let ((fill-column 7))
220 (org-auto-fill-function)
222 ;; Auto fill comments.
224 (equal " # 12345\n # 7890"
225 (org-test-with-temp-text " # 12345 7890"
226 (let ((fill-column 10))
228 (org-auto-fill-function)
230 ;; Verse and comment block: auto fill contents.
232 (equal "#+BEGIN_VERSE\n12345\n7890\n#+END_VERSE"
233 (org-test-with-temp-text "#+BEGIN_VERSE\n12345 7890\n#+END_VERSE"
234 (let ((fill-column 5))
237 (org-auto-fill-function)
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)
247 ;; Do not fill if a new item could be created.
250 (org-test-with-temp-text "12345 - 90"
251 (let ((fill-column 5))
253 (org-auto-fill-function)
255 ;; Do not fill if a line break could be introduced.
257 (equal "123\\\\\n7890"
258 (org-test-with-temp-text "123\\\\ 7890"
259 (let ((fill-column 6))
261 (org-auto-fill-function)
263 ;; Do not fill affiliated keywords.
265 (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
266 (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
267 (let ((fill-column 20))
269 (org-auto-fill-function)
276 (ert-deftest test-org
/comment-dwim
()
277 "Test `comment-dwim' behaviour in an Org buffer."
278 ;; No region selected, no comment on current line and line not
279 ;; empty: insert comment on line above.
282 (org-test-with-temp-text "Comment"
283 (progn (call-interactively 'comment-dwim
)
285 ;; No region selected, no comment on current line and line empty:
286 ;; insert comment on this line.
288 (equal "# \nParagraph"
289 (org-test-with-temp-text "\nParagraph"
290 (progn (call-interactively 'comment-dwim
)
292 ;; No region selected, and a comment on this line: indent it.
294 (equal "* Headline\n # Comment"
295 (org-test-with-temp-text "* Headline\n# Comment"
296 (progn (forward-line)
297 (let ((org-adapt-indentation t
))
298 (call-interactively 'comment-dwim
))
300 ;; Also recognize single # at column 0 as comments.
303 (org-test-with-temp-text "# Comment"
304 (progn (forward-line)
305 (call-interactively 'comment-dwim
)
307 ;; Region selected and only comments and blank lines within it:
308 ;; un-comment all commented lines.
310 (equal "Comment 1\n\nComment 2"
311 (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
313 (transient-mark-mode 1)
314 (push-mark (point) t t
)
315 (goto-char (point-max))
316 (call-interactively 'comment-dwim
)
318 ;; Region selected without comments: comment all non-blank lines.
320 (equal "# Comment 1\n\n# Comment 2"
321 (org-test-with-temp-text "Comment 1\n\nComment 2"
323 (transient-mark-mode 1)
324 (push-mark (point) t t
)
325 (goto-char (point-max))
326 (call-interactively 'comment-dwim
)
333 (ert-deftest test-org
/mark-subtree
()
334 "Test `org-mark-subtree' specifications."
335 ;; Error when point is before first headline.
337 (org-test-with-temp-text "Paragraph\n* Headline\nBody"
338 (progn (transient-mark-mode 1)
339 (org-mark-subtree))))
340 ;; Without argument, mark current subtree.
344 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
345 (progn (transient-mark-mode 1)
348 (list (region-beginning) (region-end))))))
349 ;; With an argument, move ARG up.
353 (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
354 (progn (transient-mark-mode 1)
357 (list (region-beginning) (region-end)))))))
362 ;;; test-org.el ends here