org-element: Refactor code, add tests
[org-mode.git] / testing / lisp / test-org-element.el
blobab2b446f076ccdc72b05ea7101d783ecc5031e3f
1 ;;; test-org-element.el --- Tests for org-element.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;;; Code:
24 (unless (featurep 'org-element)
25 (signal 'missing-test-dependency "org-element"))
27 (defun org-test-parse-and-interpret (text)
28 "Parse TEXT as Org syntax and interpret it.
29 Return interpreted string."
30 (with-temp-buffer
31 (org-mode)
32 (insert text)
33 (org-element-interpret-data (org-element-parse-buffer))))
37 ;;; Test Parsers
39 ;;;; Babel Call
41 (ert-deftest test-org-element/babel-call-parser ()
42 "Test `babel-call' parsing."
43 (should
44 (equal
45 (org-test-with-temp-text "#+CALL: test()"
46 (org-element-map (org-element-parse-buffer) 'babel-call 'identity nil t))
47 '(babel-call (:begin 1 :end 15 :info ("test()" nil 0) :post-blank 0)))))
50 ;;;; Bold
52 (ert-deftest test-org-element/bold-parser ()
53 "Test `bold' parser."
54 ;; Regular test.
55 (should
56 (equal
57 (org-test-with-temp-text "*bold*"
58 (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))
59 '(bold (:begin 1 :end 7 :contents-begin 2 :contents-end 6 :post-blank 0)
60 "bold")))
61 ;; Multi-line markup.
62 (should
63 (equal
64 (org-test-with-temp-text "*first line\nsecond line*"
65 (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))
66 '(bold (:begin 1 :end 25 :contents-begin 2 :contents-end 24 :post-blank 0)
67 "first line\nsecond line"))))
70 ;;;; Center Block
72 (ert-deftest test-org-element/center-block-parser ()
73 "Test `center-block' parser."
74 ;; Regular test.
75 (should
76 (equal
77 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
78 (org-element-map
79 (org-element-parse-buffer) 'center-block 'identity nil t))
80 '(center-block
81 (:begin 1 :end 33 :hiddenp nil :contents-begin 16 :contents-end 21
82 :post-blank 0)
83 (paragraph
84 (:begin 16 :end 21 :contents-begin 16 :contents-end 20 :post-blank 0)
85 "Text"))))
86 ;; Test folded block.
87 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
88 (org-cycle)
89 (should
90 (org-element-property
91 :hiddenp
92 (org-element-map
93 (org-element-parse-buffer) 'center-block 'identity nil t))))
94 ;; Ignore incomplete block.
95 (should-not
96 (org-test-with-temp-text "#+BEGIN_CENTER"
97 (org-element-map
98 (org-element-parse-buffer) 'center-block 'identity nil t))))
101 ;;;; Clock
103 (ert-deftest test-org-element/clock-parser ()
104 "Test `clock' parser."
105 ;; Running clock.
106 (should
107 (equal
108 (let ((org-clock-string "CLOCK:"))
109 (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
110 (org-element-map
111 (org-element-parse-buffer) 'clock 'identity nil t)))
112 '(clock
113 (:status running :value "[2012-01-01 sun. 00:01]" :time nil :begin 1
114 :end 31 :post-blank 0))))
115 ;; Closed clock.
116 (should
117 (equal
118 (let ((org-clock-string "CLOCK:"))
119 (org-test-with-temp-text "
120 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
121 (org-element-map
122 (org-element-parse-buffer) 'clock 'identity nil t)))
123 '(clock
124 (:status closed
125 :value "[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"
126 :time "0:01" :begin 2 :end 66 :post-blank 0)))))
129 ;;;; Code
131 (ert-deftest test-org-element/code-parser ()
132 "Test `code' parser."
133 ;; Regular test.
134 (should
135 (equal
136 (org-test-with-temp-text "~code~"
137 (org-element-map (org-element-parse-buffer) 'code 'identity nil t))
138 '(code (:value "code" :begin 1 :end 7 :post-blank 0))))
139 ;; Multi-line markup.
140 (should
141 (equal
142 (org-test-with-temp-text "~first line\nsecond line~"
143 (org-element-map (org-element-parse-buffer) 'code 'identity nil t))
144 '(code (:value "first line\nsecond line" :begin 1 :end 25 :post-blank 0)))))
147 ;;;; Comment
149 (ert-deftest test-org-element/comment-parser ()
150 "Test `comment' parser."
151 ;; Regular comment.
152 (should
153 (equal
154 (org-test-with-temp-text "# Comment"
155 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t))
156 '(comment (:begin 1 :end 10 :value "Comment\n" :post-blank 0))))
157 ;; Inline comment.
158 (should
159 (equal
160 (org-test-with-temp-text "#+ Comment"
161 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t))
162 '(comment (:begin 1 :end 11 :value "Comment\n" :post-blank 0))))
163 ;; Preserve indentation.
164 (should
165 (equal
166 (org-test-with-temp-text "#+ No blank\n#+ One blank"
167 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t))
168 '(comment (:begin 1 :end 26 :value "No blank\n One blank\n" :post-blank 0))))
169 ;; Comment with blank lines.
170 (should
171 (equal
172 (org-test-with-temp-text "#+ First part\n#+ \n#+\n#+ Second part"
173 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t))
174 '(comment
175 (:begin 1 :end 36 :value "First part\n\n\nSecond part\n"
176 :post-blank 0)))))
179 ;;;; Comment Block
181 (ert-deftest test-org-element/comment-block-parser ()
182 "Test `comment-block' parser."
183 ;; Regular tests.
184 (should
185 (equal
186 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
187 (org-element-map
188 (org-element-parse-buffer) 'comment-block 'identity nil t))
189 '(comment-block (:begin 1 :end 35 :value "Text\n" :hiddenp nil
190 :post-blank 0))))
191 ;; Test folded block.
192 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
193 (org-cycle)
194 (should
195 (org-element-property
196 :hiddenp
197 (org-element-map
198 (org-element-parse-buffer) 'comment-block 'identity nil t))))
199 ;; Ignore incomplete block.
200 (should-not
201 (org-test-with-temp-text "#+BEGIN_COMMENT"
202 (org-element-map
203 (org-element-parse-buffer) 'comment-block 'identity nil t))))
206 ;;;; Drawer
208 (ert-deftest test-org-element/drawer-parser ()
209 "Test `drawer' parser."
210 ;; Regular test.
211 (should
212 (equal
213 (let ((org-drawers '("TEST")))
214 (org-test-with-temp-text ":TEST:\nText\n:END:"
215 (org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
216 '(drawer
217 (:begin 1 :end 18 :drawer-name "TEST" :hiddenp nil :contents-begin 8
218 :contents-end 13 :post-blank 0)
219 (paragraph
220 (:begin 8 :end 13 :contents-begin 8 :contents-end 12 :post-blank 0)
221 "Text"))))
222 ;; Do not mix regular drawers and property drawers.
223 (should-not
224 (let ((org-drawers '("PROPERTIES")))
225 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
226 (org-element-map
227 (org-element-parse-buffer) 'drawer 'identity nil t))))
228 ;; Ignore incomplete drawer.
229 (should-not
230 (let ((org-drawers '("TEST")))
231 (org-test-with-temp-text ":TEST:"
232 (org-element-map
233 (org-element-parse-buffer) 'drawer 'identity nil t)))))
236 ;;;; Dynamic Block
238 (ert-deftest test-org-element/dynamic-block-parser ()
239 "Test `dynamic-block' parser."
240 ;; Regular test.
241 (should
242 (equal
243 (org-test-with-temp-text
244 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
245 (org-element-map
246 (org-element-parse-buffer) 'dynamic-block 'identity nil t))
247 '(dynamic-block
248 (:begin 1 :end 55 :block-name "myblock"
249 :arguments ":param1 val1 :param2 val2" :hiddenp nil
250 :contents-begin 44 :contents-end 49 :post-blank 0)
251 (paragraph
252 (:begin 44 :end 49 :contents-begin 44 :contents-end 48 :post-blank 0)
253 "Text"))))
254 ;; Folded view
255 (org-test-with-temp-text
256 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
257 (org-cycle)
258 (should
259 (org-element-property
260 :hiddenp
261 (org-element-map
262 (org-element-parse-buffer) 'dynamic-block 'identity nil t))))
263 ;; Ignore incomplete block.
264 (should-not
265 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
266 (org-element-map
267 (org-element-parse-buffer) 'dynamic-block 'identity nil t))))
270 ;;;; Entity
272 (ert-deftest test-org-element/entity-parser ()
273 "Test `entity' parser."
274 ;; Without brackets.
275 (should
276 (equal
277 (org-test-with-temp-text "\\sin"
278 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))
279 '(entity
280 (:name "sin" :latex "\\sin" :latex-math-p t :html "sin"
281 :ascii "sin" :latin1 "sin" :utf-8 "sin" :begin 1 :end 5
282 :use-brackets-p nil :post-blank 0))))
283 ;; With brackets.
284 (should
285 (org-element-property
286 :use-brackets-p
287 (org-test-with-temp-text "\\alpha{}text"
288 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
289 ;; User-defined entity.
290 (should
291 (equal
292 (org-element-property
293 :name
294 (let ((org-entities-user
295 '(("test" "test" nil "test" "test" "test" "test"))))
296 (org-test-with-temp-text "\\test"
297 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
298 "test")))
301 ;;;; Example Block
303 (ert-deftest test-org-element/example-block-parser ()
304 "Test `example-block' parser."
305 ;; Regular tests.
306 (should
307 (equal
308 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
309 (org-element-map
310 (org-element-parse-buffer) 'example-block 'identity nil t))
311 '(example-block
312 (:begin 1 :end 35 :value "Text\n" :switches nil
313 :number-lines nil :preserve-indent nil :retain-labels t
314 :use-labels t :label-fmt nil :hiddenp nil :post-blank 0))))
315 ;; Test folded block.
316 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
317 (org-cycle)
318 (should
319 (org-element-property
320 :hiddenp
321 (org-element-map
322 (org-element-parse-buffer) 'example-block 'identity nil t))))
323 ;; Ignore incomplete block.
324 (should-not
325 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
326 (org-element-map
327 (org-element-parse-buffer) 'example-block 'identity nil t))))
329 (ert-deftest test-org-element/block-switches ()
330 "Test `example-block' and `src-block' switches parsing."
331 (let ((org-coderef-label-format "(ref:%s)"))
332 ;; 1. Test "-i" switch.
333 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
334 (let ((element (org-element-current-element)))
335 (should-not (org-element-property :preserve-indent element))))
336 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
337 (let ((element (org-element-current-element)))
338 (should (org-element-property :preserve-indent element))))
339 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
340 (let ((element (org-element-current-element)))
341 (should-not (org-element-property :preserve-indent element))))
342 (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
343 (let ((element (org-element-current-element)))
344 (should (org-element-property :preserve-indent element))))
345 ;; 2. "-n -r -k" combination should number lines, retain labels but
346 ;; not use them in coderefs.
347 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
348 (let ((element (org-element-current-element)))
349 (should (and (org-element-property :number-lines element)
350 (org-element-property :retain-labels element)
351 (not (org-element-property :use-labels element))))))
352 (org-test-with-temp-text
353 "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
354 (let ((element (org-element-current-element)))
355 (should (and (org-element-property :number-lines element)
356 (org-element-property :retain-labels element)
357 (not (org-element-property :use-labels element))))))
358 ;; 3. "-n -r" combination should number-lines remove labels and not
359 ;; use them in coderefs.
360 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
361 (let ((element (org-element-current-element)))
362 (should (and (org-element-property :number-lines element)
363 (not (org-element-property :retain-labels element))
364 (not (org-element-property :use-labels element))))))
365 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
366 (let ((element (org-element-current-element)))
367 (should (and (org-element-property :number-lines element)
368 (not (org-element-property :retain-labels element))
369 (not (org-element-property :use-labels element))))))
370 ;; 4. "-n" or "+n" should number lines, retain labels and use them
371 ;; in coderefs.
372 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
373 (let ((element (org-element-current-element)))
374 (should (and (org-element-property :number-lines element)
375 (org-element-property :retain-labels element)
376 (org-element-property :use-labels element)))))
377 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
378 (let ((element (org-element-current-element)))
379 (should (and (org-element-property :number-lines element)
380 (org-element-property :retain-labels element)
381 (org-element-property :use-labels element)))))
382 (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
383 (let ((element (org-element-current-element)))
384 (should (and (org-element-property :number-lines element)
385 (org-element-property :retain-labels element)
386 (org-element-property :use-labels element)))))
387 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
388 (let ((element (org-element-current-element)))
389 (should (and (org-element-property :number-lines element)
390 (org-element-property :retain-labels element)
391 (org-element-property :use-labels element)))))
392 ;; 5. No switch should not number lines, but retain labels and use
393 ;; them in coderefs.
394 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
395 (let ((element (org-element-current-element)))
396 (should (and (not (org-element-property :number-lines element))
397 (org-element-property :retain-labels element)
398 (org-element-property :use-labels element)))))
399 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
400 (let ((element (org-element-current-element)))
401 (should (and (not (org-element-property :number-lines element))
402 (org-element-property :retain-labels element)
403 (org-element-property :use-labels element)))))
404 ;; 6. "-r" switch only: do not number lines, remove labels, and
405 ;; don't use labels in coderefs.
406 (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
407 (let ((element (org-element-current-element)))
408 (should (and (not (org-element-property :number-lines element))
409 (not (org-element-property :retain-labels element))
410 (not (org-element-property :use-labels element))))))
411 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
412 (let ((element (org-element-current-element)))
413 (should (and (not (org-element-property :number-lines element))
414 (not (org-element-property :retain-labels element))
415 (not (org-element-property :use-labels element))))))
416 ;; 7. Recognize coderefs with user-defined syntax.
417 (org-test-with-temp-text
418 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
419 (let ((element (org-element-current-element)))
420 (should
421 (equal (org-element-property :label-fmt element) "[ref:%s]"))))
422 (org-test-with-temp-text
423 "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
424 (let ((element (org-element-current-element)))
425 (should
426 (equal (org-element-property :label-fmt element) "[ref:%s]"))))))
429 ;;;; Export Block
431 (ert-deftest test-org-element/export-block-parser ()
432 "Test `export-block' parser."
433 ;; Regular tests.
434 (should
435 (equal
436 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
437 (org-element-map
438 (org-element-parse-buffer) 'export-block 'identity nil t))
439 '(export-block
440 (:begin 1 :end 31 :type "LATEX" :value "Text\n" :hiddenp nil
441 :post-blank 0))))
442 ;; Test folded block.
443 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
444 (org-cycle)
445 (should
446 (org-element-property
447 :hiddenp
448 (org-element-map
449 (org-element-parse-buffer) 'export-block 'identity nil t))))
450 ;; Ignore incomplete block.
451 (should-not
452 (org-test-with-temp-text "#+BEGIN_LATEX"
453 (org-element-map
454 (org-element-parse-buffer) 'export-block 'identity nil t))))
457 ;;;; Export Snippet
459 (ert-deftest test-org-element/export-snippet-parser ()
460 "Test `export-snippet' parser."
461 (should
462 (equal
463 (org-test-with-temp-text "<back-end@contents>"
464 (org-element-map
465 (org-element-parse-buffer) 'export-snippet 'identity nil t))
466 '(export-snippet
467 (:back-end "back-end"
468 :value "contents" :begin 1 :end 20 :post-blank 0)))))
471 ;;;; Fixed Width
473 (ert-deftest test-org-element/fixed-width ()
474 "Test fixed-width area parsing."
475 ;; Preserve indentation.
476 (should
477 (equal
478 (org-test-with-temp-text ": no blank\n: one blank"
479 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity nil t))
480 '(fixed-width
481 (:begin 1 :end 24 :value "no blank\n one blank\n" :post-blank 0))))
482 ;; Fixed-width with empty lines.
483 (should
484 (equal
485 (org-test-with-temp-text ": first part\n:\n: \n: second part"
486 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity nil t))
487 '(fixed-width
488 (:begin 1 :end 32 :value "first part\n\n\nsecond part\n" :post-blank 0))))
489 ;; Parse indented fixed-width markers.
490 (should
491 (equal
492 (org-test-with-temp-text "Text\n : no blank\n : one blank"
493 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity nil t))
494 '(fixed-width
495 (:begin 6 :end 33 :value "no blank\n one blank\n" :post-blank 0))))
496 ;; Distinguish fixed-width areas within a list and outside of it.
497 (should
498 (= 2
499 (length
500 (org-test-with-temp-text "
501 - Item
502 : fixed-width inside
503 : fixed-width outside"
504 (org-element-map
505 (org-element-parse-buffer) 'fixed-width 'identity))))))
508 ;;;; Footnote Definition.
510 (ert-deftest test-org-element/footnote-definition-parser ()
511 "Test `footnote-definition' parser."
512 (should
513 (equal
514 (org-test-with-temp-text "[fn:1] Definition"
515 (org-element-map
516 (org-element-parse-buffer) 'footnote-definition 'identity nil t))
517 '(footnote-definition
518 (:label "fn:1" :begin 1 :end 18 :contents-begin 8 :contents-end 18
519 :post-blank 0)
520 (paragraph
521 (:begin 8 :end 18 :contents-begin 8 :contents-end 18 :post-blank 0)
522 "Definition")))))
525 ;;;; Footnotes Reference
527 (ert-deftest test-org-element/footnote-reference-parser ()
528 "Test `footnote-reference' parser."
529 ;; 1. Parse a standard reference.
530 (org-test-with-temp-text "[fn:label]"
531 (should (equal (org-element-footnote-reference-parser)
532 '(footnote-reference
533 (:label "fn:label" :type standard :inline-definition nil
534 :begin 1 :end 11 :post-blank 0)))))
535 ;; 2. Parse a normalized reference.
536 (org-test-with-temp-text "[1]"
537 (should (equal (org-element-footnote-reference-parser)
538 '(footnote-reference
539 (:label "1" :type standard :inline-definition nil
540 :begin 1 :end 4 :post-blank 0)))))
541 ;; 3. Parse an inline reference.
542 (org-test-with-temp-text "[fn:test:def]"
543 (should (equal (org-element-footnote-reference-parser)
544 '(footnote-reference
545 (:label "fn:test" :type inline :inline-definition ("def")
546 :begin 1 :end 14 :post-blank 0)))))
547 ;; 4. Parse an anonymous reference.
548 (org-test-with-temp-text "[fn::def]"
549 (should (equal (org-element-footnote-reference-parser)
550 '(footnote-reference
551 (:label nil :type inline :inline-definition ("def")
552 :begin 1 :end 10 :post-blank 0)))))
553 ;; 5. Parse nested footnotes.
554 (org-test-with-temp-text "[fn::def [fn:label]]"
555 (should
556 (equal
557 (org-element-footnote-reference-parser)
558 '(footnote-reference
559 (:label nil :type inline
560 :inline-definition
561 ("def "
562 (footnote-reference
563 (:label "fn:label" :type standard :inline-definition nil
564 :begin 5 :end 15 :post-blank 0)))
565 :begin 1 :end 21 :post-blank 0)))))
566 ;; 6. Parse adjacent footnotes.
567 (org-test-with-temp-text "[fn:label1][fn:label2]"
568 (should
569 (equal
570 (org-element-footnote-reference-parser)
571 '(footnote-reference
572 (:label "fn:label1" :type standard :inline-definition nil :begin 1
573 :end 12 :post-blank 0)))))
574 ;; 7. Only properly closed footnotes are recognized as such.
575 (org-test-with-temp-text "Text [fn:label"
576 (should-not
577 (org-element-map
578 (org-element-parse-buffer) 'footnote-reference 'identity))))
581 ;;;; Headlines
583 (ert-deftest test-org-element/headline-quote-keyword ()
584 "Test QUOTE keyword recognition."
585 ;; Reference test.
586 (org-test-with-temp-text "* Headline"
587 (let ((org-quote-string "QUOTE"))
588 (should-not (org-element-property :quotedp (org-element-at-point)))))
589 ;; Standard position.
590 (org-test-with-temp-text "* QUOTE Headline"
591 (let ((org-quote-string "QUOTE"))
592 (let ((headline (org-element-at-point)))
593 (should (org-element-property :quotedp headline))
594 ;; Test removal from raw value.
595 (should (equal (org-element-property :raw-value headline) "Headline"))))
596 ;; Case sensitivity.
597 (let ((org-quote-string "Quote"))
598 (should-not (org-element-property :quotedp (org-element-at-point)))))
599 ;; With another keyword.
600 (org-test-with-temp-text "* TODO QUOTE Headline"
601 (let ((org-quote-string "QUOTE")
602 (org-todo-keywords '((sequence "TODO" "DONE"))))
603 (should (org-element-property :quotedp (org-element-at-point))))))
605 (ert-deftest test-org-element/headline-comment-keyword ()
606 "Test COMMENT keyword recognition."
607 ;; Reference test.
608 (org-test-with-temp-text "* Headline"
609 (let ((org-comment-string "COMMENT"))
610 (should-not (org-element-property :commentedp (org-element-at-point)))))
611 ;; Standard position.
612 (org-test-with-temp-text "* COMMENT Headline"
613 (let ((org-comment-string "COMMENT"))
614 (let ((headline (org-element-at-point)))
615 (should (org-element-property :commentedp headline))
616 ;; Test removal from raw value.
617 (should (equal (org-element-property :raw-value headline) "Headline"))))
618 ;; Case sensitivity.
619 (let ((org-comment-string "Comment"))
620 (should-not (org-element-property :commentedp (org-element-at-point)))))
621 ;; With another keyword.
622 (org-test-with-temp-text "* TODO COMMENT Headline"
623 (let ((org-comment-string "COMMENT")
624 (org-todo-keywords '((sequence "TODO" "DONE"))))
625 (should (org-element-property :commentedp (org-element-at-point))))))
627 (ert-deftest test-org-element/headline-archive-tag ()
628 "Test ARCHIVE tag recognition."
629 ;; Reference test.
630 (org-test-with-temp-text "* Headline"
631 (let ((org-archive-tag "ARCHIVE"))
632 (should-not (org-element-property :archivedp (org-element-at-point)))))
633 ;; Single tag.
634 (org-test-with-temp-text "* Headline :ARCHIVE:"
635 (let ((org-archive-tag "ARCHIVE"))
636 (let ((headline (org-element-at-point)))
637 (should (org-element-property :archivedp headline))
638 ;; Test tag removal.
639 (should-not (org-element-property :tags headline))))
640 (let ((org-archive-tag "Archive"))
641 (should-not (org-element-property :archivedp (org-element-at-point)))))
642 ;; Multiple tags.
643 (org-test-with-temp-text "* Headline :test:ARCHIVE:"
644 (let ((org-archive-tag "ARCHIVE"))
645 (let ((headline (org-element-at-point)))
646 (should (org-element-property :archivedp headline))
647 ;; Test tag removal.
648 (should (equal (org-element-property :tags headline) '("test")))))))
651 ;;;; Inlinetask.
653 (ert-deftest test-org-element/inlinetask-parser ()
654 "Test `inlinetask' parser."
655 (when (featurep 'org-inlinetask)
656 (let ((org-inlinetask-min-level 15))
657 ;; 1. Regular inlinetask.
658 (should
659 (equal
660 (org-test-with-temp-text
661 "*************** Task\nTest\n*************** END"
662 (org-element-map
663 (org-element-parse-buffer) 'inlinetask 'identity nil t))
664 '(inlinetask
665 (:title ("Task") :begin 1 :end 46 :hiddenp nil :contents-begin 22
666 :contents-end 27 :level 15 :priority nil :tags nil
667 :todo-keyword nil :todo-type nil :scheduled nil :deadline nil
668 :timestamp nil :clock nil :post-blank 0 :category "???")
669 (paragraph
670 (:begin 22 :end 27 :contents-begin 22 :contents-end 26 :post-blank 0)
671 "Test"))))
672 ;; 2. Degenerate inlinetask.
673 (should
674 (equal
675 (org-test-with-temp-text
676 "*************** Task"
677 (org-element-map
678 (org-element-parse-buffer) 'inlinetask 'identity nil t))
679 '(inlinetask
680 (:title ("Task") :begin 1 :end 21 :hiddenp nil :contents-begin 21
681 :contents-end 21 :level 15 :priority nil :tags nil
682 :todo-keyword nil :todo-type nil :scheduled nil :deadline nil
683 :timestamp nil :clock nil :post-blank 0 :category nil))))
684 ;; TODO keyword.
685 (should
686 (equal
687 "TODO"
688 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
689 (org-test-with-temp-text "*************** TODO Task"
690 (org-element-property
691 :todo-keyword
692 (org-element-map
693 (org-element-parse-buffer) 'inlinetask 'identity nil t))))))
694 ;; Planning info.
695 (should
696 (equal
697 "2012-03-29 thu."
698 (org-test-with-temp-text "
699 *************** Task
700 DEADLINE: <2012-03-29 thu.>"
701 (org-element-property
702 :deadline
703 (org-element-map
704 (org-element-parse-buffer) 'inlinetask 'identity nil t)))))
705 ;; Priority.
706 (should
707 (equal
709 (org-test-with-temp-text "
710 *************** [#A] Task"
711 (org-element-property
712 :priority
713 (org-element-map
714 (org-element-parse-buffer) 'inlinetask 'identity nil t)))))
715 ;; Tags.
716 (should
717 (equal
718 '("test")
719 (org-test-with-temp-text "
720 *************** Task :test:"
721 (org-element-property
722 :tags
723 (org-element-map
724 (org-element-parse-buffer) 'inlinetask 'identity nil t))))))))
727 ;;;; Item.
729 (ert-deftest test-org-element/item-parser ()
730 "Test `item' parser."
731 ;; Standard test.
732 (should
733 (equal
734 (org-test-with-temp-text "- item"
735 (org-element-map (org-element-parse-buffer) 'item 'identity nil t))
736 '(item
737 (:bullet "- " :begin 1 :end 7 :contents-begin 3 :contents-end 7
738 :checkbox nil :counter nil :tag nil :hiddenp nil
739 :structure ((1 0 "- " nil nil nil 7))
740 :post-blank 0)
741 (paragraph
742 (:begin 3 :end 7 :contents-begin 3 :contents-end 7 :post-blank 0)
743 "item"))))
744 ;; Counter.
745 (should
746 (= 6
747 (org-element-property
748 :counter
749 (org-test-with-temp-text "6. [@6] item"
750 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
751 ;; Tag
752 (should
753 (equal
754 '("tag")
755 (org-element-property
756 :tag
757 (org-test-with-temp-text "- tag :: description"
758 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
759 ;; Check-boxes
760 (should
761 (equal
762 '(trans on off)
763 (org-test-with-temp-text "
764 - [-] item 1
765 - [X] item 1.1
766 - [ ] item 1.2"
767 (org-element-map
768 (org-element-parse-buffer) 'item
769 (lambda (item) (org-element-property :checkbox item))))))
770 ;; Folded state.
771 (org-test-with-temp-text "* Headline
772 - item
774 paragraph below"
775 (forward-line)
776 (let ((org-cycle-include-plain-lists t)) (org-cycle))
777 (should
778 (org-element-property
779 :hiddenp
780 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
783 ;;;; Link
785 (ert-deftest test-org-element/link-parser ()
786 "Test `link' parser."
787 ;; 1. Radio target.
788 (should
789 (equal (org-test-with-temp-text "A radio link"
790 (org-element-map
791 (let ((org-target-link-regexp "radio")) (org-element-parse-buffer))
792 'link 'identity nil t))
793 '(link (:type "radio" :path "radio" :raw-link "radio" :begin 3 :end 9
794 :contents-begin nil :contents-end nil :post-blank 1))))
795 ;; 2. Standard link.
797 ;; 2.1. With description.
798 (should
799 (equal (org-test-with-temp-text "[[http://orgmode.org][Orgmode.org]]"
800 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
801 '(link (:type "http" :path "//orgmode.org"
802 :raw-link "http://orgmode.org" :begin 1 :end 36
803 :contents-begin 23 :contents-end 34 :post-blank 0)
804 "Orgmode.org")))
805 ;; 2.2. Without description.
806 (should
807 (equal (org-test-with-temp-text "[[http://orgmode.org]]"
808 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
809 '(link (:type "http" :path "//orgmode.org"
810 :raw-link "http://orgmode.org" :begin 1 :end 23
811 :contents-begin nil :contents-end nil :post-blank 0))))
812 ;; 2.3. With expansion.
813 (should
814 (equal (org-test-with-temp-text "[[Org:worg]]"
815 (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/"))))
816 (org-element-map
817 (org-element-parse-buffer) 'link 'identity nil t)))
818 '(link (:type "http" :path "//orgmode.org/worg" :raw-link "Org:worg"
819 :begin 1 :end 13 :contents-begin nil :contents-end nil
820 :post-blank 0))))
821 ;; 2.4. With translation.
822 (should
823 (equal (org-test-with-temp-text "[[http://orgmode.org]]"
824 (flet ((link-translate (type path) (cons type "127.0.0.1")))
825 (let ((org-link-translation-function 'link-translate))
826 (org-element-map
827 (org-element-parse-buffer) 'link 'identity nil t))))
828 '(link (:type "http" :path "127.0.0.1" :raw-link "http://orgmode.org"
829 :begin 1 :end 23 :contents-begin nil :contents-end nil
830 :post-blank 0))))
831 ;; 2.5. Id link.
832 (should
833 (equal (org-test-with-temp-text "[[id:aaaa]]"
834 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
835 '(link (:type "id" :path "aaaa" :raw-link "id:aaaa" :begin 1 :end 12
836 :contents-begin nil :contents-end nil :post-blank 0))))
837 ;; 2.6. Custom-id link.
838 (should
839 (equal (org-test-with-temp-text "[[#some-id]]"
840 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
841 '(link (:type "custom-id" :path "some-id" :raw-link "#some-id"
842 :begin 1 :end 13 :contents-begin nil :contents-end nil
843 :post-blank 0))))
844 ;; 2.7 Coderef link.
845 (should
846 (equal (org-test-with-temp-text "[[(reference)]]"
847 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
848 '(link (:type "coderef" :path "reference" :raw-link "(reference)"
849 :begin 1 :end 16 :contents-begin nil :contents-end nil
850 :post-blank 0))))
851 ;; 2.8 Fuzzy link.
852 (should
853 (equal (org-test-with-temp-text "[[target-or-title]]"
854 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
855 '(link (:type "fuzzy" :path "target-or-title"
856 :raw-link "target-or-title" :begin 1 :end 20
857 :contents-begin nil :contents-end nil :post-blank 0))))
858 ;; 3. Plain link.
859 (should
860 (equal (org-test-with-temp-text "A link: http://orgmode.org"
861 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
862 '(link (:type "http" :path "//orgmode.org"
863 :raw-link "http://orgmode.org" :begin 9 :end 27
864 :contents-begin nil :contents-end nil :post-blank 0))))
865 ;; 4. Angular link.
866 (should
867 (equal (org-test-with-temp-text "A link: <http://orgmode.org>"
868 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
869 '(link (:type "http" :path "//orgmode.org"
870 :raw-link "http://orgmode.org" :begin 9 :end 29
871 :contents-begin nil :contents-end nil :post-blank 0)))))
874 ;;;; Plain List.
876 (ert-deftest test-org-element/plain-list-parser ()
877 "Test `plain-list' parser."
878 (should
879 (equal
880 (org-test-with-temp-text "- item"
881 (org-element-map (org-element-parse-buffer) 'plain-list 'identity nil t))
882 '(plain-list
883 (:type unordered :begin 1 :end 7 :contents-begin 1 :contents-end 7
884 :structure ((1 0 "- " nil nil nil 7)) :post-blank 0)
885 (item
886 (:bullet "- " :begin 1 :end 7 :contents-begin 3 :contents-end 7
887 :checkbox nil :counter nil :tag nil :hiddenp nil
888 :structure ((1 0 "- " nil nil nil 7)) :post-blank 0)
889 (paragraph
890 (:begin 3 :end 7 :contents-begin 3 :contents-end 7 :post-blank 0)
891 "item")))))
892 ;; Blank lines after the list only belong to outer plain list.
893 (org-test-with-temp-text "
894 - outer
895 - inner
897 Outside list"
898 (let ((endings (org-element-map
899 (org-element-parse-buffer) 'plain-list
900 (lambda (pl) (org-element-property :end pl)))))
901 ;; Move to ending of outer list.
902 (goto-char (car endings))
903 (should (looking-at "Outside list"))
904 ;; Move to ending of inner list.
905 (goto-char (nth 1 endings))
906 (should (looking-at "^$")))))
909 ;;;; Src Block.
911 (ert-deftest test-org-element/src-block-parser ()
912 "Test `src-block' parser."
913 ;; Regular tests.
914 (should
915 (equal
916 (org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
917 (org-element-map
918 (org-element-parse-buffer) 'src-block 'identity nil t))
919 '(src-block
920 (:language nil :switches nil :parameters nil :begin 1 :end 27
921 :number-lines nil :preserve-indent nil :retain-labels t
922 :use-labels t :label-fmt nil :hiddenp nil :value "Text\n"
923 :post-blank 0))))
924 ;; Test folded block.
925 (org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
926 (org-cycle)
927 (should
928 (org-element-property
929 :hiddenp
930 (org-element-map
931 (org-element-parse-buffer) 'src-block 'identity nil t))))
932 ;; Ignore incomplete block.
933 (should-not
934 (org-test-with-temp-text "#+BEGIN_SRC"
935 (org-element-map
936 (org-element-parse-buffer) 'src-block 'identity nil t))))
939 ;;;; Quote Block
941 (ert-deftest test-org-element/quote-block-parser ()
942 "Test `quote-block' parser."
943 ;; Regular test.
944 (should
945 (equal
946 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
947 (org-element-map
948 (org-element-parse-buffer) 'quote-block 'identity nil t))
949 '(quote-block
950 (:begin 1 :end 31 :hiddenp nil :contents-begin 15 :contents-end 20
951 :post-blank 0)
952 (paragraph
953 (:begin 15 :end 20 :contents-begin 15 :contents-end 19 :post-blank 0)
954 "Text"))))
955 ;; Test folded block.
956 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
957 (org-cycle)
958 (should
959 (org-element-property
960 :hiddenp
961 (org-element-map
962 (org-element-parse-buffer) 'quote-block 'identity nil t))))
963 ;; Ignore incomplete block.
964 (should-not
965 (org-test-with-temp-text "#+BEGIN_QUOTE"
966 (org-element-map
967 (org-element-parse-buffer) 'quote-block 'identity nil t))))
970 ;;;; Section
972 (ert-deftest test-org-element/section-parser ()
973 "Test `section' parser."
974 ;; Standard test.
975 (should
976 (equal
977 (org-test-with-temp-text "* Headline\nText"
978 (org-element-map (org-element-parse-buffer) 'section 'identity nil t))
979 '(section
980 (:begin 12 :end 16 :contents-begin 12 :contents-end 16 :post-blank 0)
981 (paragraph
982 (:begin 12 :end 16 :contents-begin 12 :contents-end 16 :post-blank 0)
983 "Text"))))
984 ;; There's a section before the first headline.
985 (should
986 (org-test-with-temp-text "Text"
987 (org-element-map (org-element-parse-buffer) 'section 'identity)))
988 ;; A section cannot be empty.
989 (should-not
990 (org-test-with-temp-text "* Headline 1\n* Headline 2"
991 (org-element-map (org-element-parse-buffer) 'section 'identity))))
994 ;;;; Special Block
996 (ert-deftest test-org-element/special-block-parser ()
997 "Test `special-block' parser."
998 ;; Regular test.
999 (should
1000 (equal
1001 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1002 (org-element-map
1003 (org-element-parse-buffer) 'special-block 'identity nil t))
1004 '(special-block
1005 (:type "SPECIAL" :begin 1 :end 35 :hiddenp nil :contents-begin 17
1006 :contents-end 22 :post-blank 0)
1007 (paragraph
1008 (:begin 17 :end 22 :contents-begin 17 :contents-end 21 :post-blank 0)
1009 "Text"))))
1010 ;; Test folded block.
1011 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1012 (org-cycle)
1013 (should
1014 (org-element-property
1015 :hiddenp
1016 (org-element-map
1017 (org-element-parse-buffer) 'special-block 'identity nil t))))
1018 ;; Ignore incomplete block.
1019 (should-not
1020 (org-test-with-temp-text "#+BEGIN_SPECIAL"
1021 (org-element-map
1022 (org-element-parse-buffer) 'special-block 'identity nil t))))
1025 ;;;; Verse Block
1027 (ert-deftest test-org-element/verse-block-parser ()
1028 "Test `verse-block' parser."
1029 ;; Standard test.
1030 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
1031 (should
1032 (equal
1033 (org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)
1034 '(verse-block
1035 (:begin 1 :end 38 :contents-begin 15 :contents-end 27 :hiddenp nil
1036 :post-blank 0)
1037 "Verse block\n"))))
1038 ;; Ignore case.
1039 (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
1040 (should
1041 (equal
1042 (org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)
1043 '(verse-block
1044 (:begin 1 :end 38 :contents-begin 15 :contents-end 27 :hiddenp nil
1045 :post-blank 0)
1046 "Verse block\n"))))
1047 ;; Parse folding.
1048 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
1049 (org-hide-block-all)
1050 (should
1051 (equal
1052 (org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)
1053 '(verse-block
1054 (:begin 1 :end 38 :contents-begin 15 :contents-end 27
1055 :hiddenp org-hide-block :post-blank 0)
1056 "Verse block\n"))))
1057 ;; Parse objects in verse blocks.
1058 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
1059 (should (org-element-map (org-element-parse-buffer) 'entity 'identity)))
1060 ;; Ignore incomplete verse block.
1061 (should-not
1062 (org-test-with-temp-text "#+BEGIN_VERSE"
1063 (org-element-map
1064 (org-element-parse-buffer) 'verse-block 'identity nil t))))
1068 ;;; Test Interpreters.
1070 (ert-deftest test-org-element/interpret-affiliated-keywords ()
1071 "Test if affiliated keywords are correctly interpreted."
1072 ;; Interpret simple keywords.
1073 (should
1074 (equal
1075 (org-element-interpret-data
1076 '(org-data nil (paragraph (:name "para") "Paragraph")))
1077 "#+NAME: para\nParagraph\n"))
1078 ;; Interpret multiple keywords.
1079 (should
1080 (equal
1081 (org-element-interpret-data
1082 '(org-data nil (paragraph (:attr_ascii ("line1" "line2")) "Paragraph")))
1083 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
1084 ;; Interpret parsed keywords.
1085 (should
1086 (equal
1087 (org-element-interpret-data
1088 '(org-data nil (paragraph (:caption ("caption")) "Paragraph")))
1089 "#+CAPTION: caption\nParagraph\n"))
1090 ;; Interpret dual keywords.
1091 (should
1092 (equal
1093 (org-element-interpret-data
1094 '(org-data nil (paragraph (:caption (("long") "short")) "Paragraph")))
1095 "#+CAPTION[short]: long\nParagraph\n")))
1097 (ert-deftest test-org-element/center-block-interpreter ()
1098 "Test center block interpreter."
1099 (should
1100 (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
1101 "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
1103 (ert-deftest test-org-element/drawer-interpreter ()
1104 "Test drawer interpreter."
1105 (should
1106 (equal (let ((org-drawers '("TEST")))
1107 (org-test-parse-and-interpret ":TEST:\nTest\n:END:"))
1108 ":TEST:\nTest\n:END:\n")))
1110 (ert-deftest test-org-element/dynamic-block-interpreter ()
1111 "Test dynamic block interpreter."
1112 (should
1113 (equal (org-test-parse-and-interpret
1114 "#+BEGIN: myblock :parameter value1\nTest\n#+END:")
1115 "#+BEGIN: myblock :parameter value1\nTest\n#+END:\n")))
1117 (ert-deftest test-org-element/footnote-definition-interpreter ()
1118 "Test footnote definition interpreter."
1119 (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")))
1121 (ert-deftest test-org-element/headline-interpreter ()
1122 "Test headline and section interpreters."
1123 ;; 1. Standard test.
1124 (should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
1125 ;; 2. With TODO keywords.
1126 (should
1127 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
1128 (org-test-parse-and-interpret "* TODO Headline"))
1129 "* TODO Headline\n"))
1130 ;; 3. With tags...
1132 ;; 3.1. ... and a positive `org-tags-column' value.
1133 (should
1134 (equal (let ((org-tags-column 20))
1135 (org-test-parse-and-interpret "* Headline :tag:"))
1136 "* Headline :tag:\n"))
1137 ;; 3.2. ... and a negative `org-tags-column' value.
1138 (should
1139 (equal (let ((org-tags-column -20))
1140 (org-test-parse-and-interpret "* Headline :tag:"))
1141 "* Headline :tag:\n"))
1142 ;; 3.3. ... and a null `org-tags-column' value.
1143 (should
1144 (equal (let ((org-tags-column 0))
1145 (org-test-parse-and-interpret "* Headline :tag:"))
1146 "* Headline :tag:\n"))
1147 ;; 4. With priority cookie.
1148 (should
1149 (equal (org-test-parse-and-interpret "* [#B] Headline")
1150 "* [#B] Headline\n"))
1151 ;; 5. With comment keyword.
1152 (should
1153 (equal (let ((org-comment-string "COMMENT"))
1154 (org-test-parse-and-interpret "* COMMENT Headline"))
1155 "* COMMENT Headline\n"))
1156 ;; 6. With quote section.
1157 (should
1158 (equal (let ((org-quote-string "QUOTE"))
1159 (org-test-parse-and-interpret "* QUOTE Headline"))
1160 "* QUOTE Headline\n"))
1161 ;; 7. Keep same number of blank lines before body.
1162 (should
1163 (equal (org-test-parse-and-interpret
1164 "* Headline\n\n\nText after two blank lines.")
1165 "* Headline\n\n\nText after two blank lines.\n")))
1167 (ert-deftest test-org-element/inlinetask-interpreter ()
1168 "Test inlinetask interpretation."
1169 (when (featurep 'org-inlinetask)
1170 (let ((org-inlinetask-min-level 15))
1171 ;; 1. Regular inlinetask.
1172 (should (equal (org-test-parse-and-interpret
1173 "*************** Task\nTest\n*************** END")
1174 "*************** Task\nTest\n*************** END\n"))
1175 ;; 2. Degenerate inlinetask.
1176 (should (equal (org-test-parse-and-interpret "*************** Task")
1177 "*************** Task\n"))
1178 ;; 3. Prefer degenerate form when there are no contents.
1179 (should (equal (org-test-parse-and-interpret
1180 "*************** Task\n*************** END")
1181 "*************** Task\n"))
1182 ;; 4. With TODO keywords.
1183 (should
1184 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
1185 (org-test-parse-and-interpret "*************** TODO Task"))
1186 "*************** TODO Task\n"))
1187 ;; 5. With tags...
1189 ;; 5.1. ... and a positive `org-tags-column' value.
1190 (should
1191 (equal (let ((org-tags-column 30))
1192 (org-test-parse-and-interpret "*************** Task :tag:"))
1193 "*************** Task :tag:\n"))
1194 ;; 5.2. ... and a negative `org-tags-column' value.
1195 (should
1196 (equal (let ((org-tags-column -30))
1197 (org-test-parse-and-interpret "*************** Task :tag:"))
1198 "*************** Task :tag:\n"))
1199 ;; 5.3. ... and a null `org-tags-column' value.
1200 (should
1201 (equal (let ((org-tags-column 0))
1202 (org-test-parse-and-interpret "*************** Task :tag:"))
1203 "*************** Task :tag:\n"))
1204 ;; 6. With priority cookie.
1205 (should
1206 (equal (org-test-parse-and-interpret "*************** [#B] Task")
1207 "*************** [#B] Task\n")))))
1209 (ert-deftest test-org-element/plain-list-interpreter ()
1210 "Test plain-list and item interpreters."
1211 ;; 1. Unordered list.
1212 (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
1213 ;; 2. Description list.
1214 (should
1215 (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
1216 ;; 3. Ordered list.
1217 (should
1218 (equal (let ((org-plain-list-ordered-item-terminator t))
1219 (org-test-parse-and-interpret "1. Item"))
1220 "1. Item\n"))
1221 ;; 4. Ordered list with counter.
1222 (should
1223 (equal (let ((org-plain-list-ordered-item-terminator t))
1224 (org-test-parse-and-interpret "1. [@5] Item"))
1225 "5. [@5] Item\n"))
1226 ;; 5. List with check-boxes.
1227 (should
1228 (equal (org-test-parse-and-interpret
1229 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
1230 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n")))
1232 (ert-deftest test-org-element/quote-block-interpreter ()
1233 "Test quote block interpreter."
1234 (should (equal (org-test-parse-and-interpret
1235 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
1236 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
1238 (ert-deftest test-org-element/special-block-interpreter ()
1239 "Test special block interpreter."
1240 (should (equal (org-test-parse-and-interpret
1241 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
1242 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
1244 (ert-deftest test-org-element/babel-call-interpreter ()
1245 "Test babel call interpreter."
1246 ;; 1. Without argument.
1247 (should (equal (org-test-parse-and-interpret "#+CALL: test()")
1248 "#+CALL: test()\n"))
1249 ;; 2. With argument.
1250 (should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
1251 "#+CALL: test(x=2)\n"))
1252 ;; 3. With header arguments.
1253 (should (equal (org-test-parse-and-interpret
1254 "#+CALL: test[:results output]()[:results html]")
1255 "#+CALL: test[:results output]()[:results html]\n")))
1257 (ert-deftest test-org-element/clock-interpreter ()
1258 "Test clock interpreter."
1259 ;; Running clock.
1260 (should
1261 (equal (let ((org-clock-string "CLOCK:"))
1262 (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]"))
1263 "CLOCK: [2012-01-01 sun. 00:01]\n"))
1264 ;; Closed clock.
1265 (should
1266 (equal
1267 (let ((org-clock-string "CLOCK:"))
1268 (org-test-parse-and-interpret "
1269 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))
1270 "CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01\n")))
1272 (ert-deftest test-org-element/comment-interpreter ()
1273 "Test comment interpreter."
1274 ;; Regular comment.
1275 (should (equal (org-test-parse-and-interpret "#Comment") "#+ Comment\n"))
1276 ;; Inline comment.
1277 (should (equal (org-test-parse-and-interpret " #+ Comment")
1278 "#+ Comment\n"))
1279 ;; Preserve indentation.
1280 (should (equal (org-test-parse-and-interpret " #+ No blank\n#+ One blank")
1281 "#+ No blank\n#+ One blank\n")))
1283 (ert-deftest test-org-element/comment-block-interpreter ()
1284 "Test comment block interpreter."
1285 (should (equal (org-test-parse-and-interpret
1286 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
1287 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n")))
1289 (ert-deftest test-org-element/example-block-interpreter ()
1290 "Test example block interpreter."
1291 ;; Without switches.
1292 (should (equal (org-test-parse-and-interpret
1293 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE")
1294 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"))
1295 ;; With switches.
1296 (should
1297 (equal (org-test-parse-and-interpret
1298 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
1299 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n")))
1301 (ert-deftest test-org-element/export-block-interpreter ()
1302 "Test export block interpreter."
1303 (should (equal (org-test-parse-and-interpret
1304 "#+BEGIN_HTML\nTest\n#+END_HTML")
1305 "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
1307 (ert-deftest test-org-element/fixed-width-interpreter ()
1308 "Test fixed width interpreter."
1309 ;; Standard test.
1310 (should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
1311 ;; Preserve indentation.
1312 (should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
1313 ": 2 blanks\n: 1 blank\n")))
1315 (ert-deftest test-org-element/horizontal-rule-interpreter ()
1316 "Test horizontal rule interpreter."
1317 (should (equal (org-test-parse-and-interpret "-------") "-----\n")))
1319 (ert-deftest test-org-element/keyword-interpreter ()
1320 "Test keyword interpreter."
1321 (should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
1322 "#+KEYWORD: value\n")))
1324 (ert-deftest test-org-element/latex-environment-interpreter ()
1325 "Test latex environment interpreter."
1326 (should (equal (org-test-parse-and-interpret
1327 "\\begin{equation}\n1+1=2\n\\end{equation}")
1328 "\\begin{equation}\n1+1=2\n\\end{equation}\n")))
1330 (ert-deftest test-org-element/planning-interpreter ()
1331 "Test planning interpreter."
1332 (let ((org-closed-string "CLOSED:")
1333 (org-deadline-string "DEADLINE:")
1334 (org-scheduled-string "SCHEDULED:"))
1335 (should
1336 (equal
1337 (org-test-parse-and-interpret
1338 "* Headline
1339 CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>")
1340 "* Headline
1341 CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n"))))
1343 (ert-deftest test-org-element/property-drawer-interpreter ()
1344 "Test property drawer interpreter."
1345 (should (equal (let ((org-property-format "%-10s %s"))
1346 (org-test-parse-and-interpret
1347 ":PROPERTIES:\n:prop: value\n:END:"))
1348 ":PROPERTIES:\n:prop: value\n:END:\n")))
1350 (ert-deftest test-org-element/src-block-interpreter ()
1351 "Test src block interpreter."
1352 ;; With arguments.
1353 (should
1354 (equal (org-test-parse-and-interpret
1355 "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC")
1356 "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC\n"))
1357 ;; With switches.
1358 (should
1359 (equal (org-test-parse-and-interpret
1360 "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC")
1361 "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC\n")))
1363 (ert-deftest test-org-element/table-interpreter ()
1364 "Test table, table-row and table-cell interpreters."
1365 ;; 1. Simple table.
1366 (should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
1367 "| a | b |\n| c | d |\n"))
1368 ;; 2. Table with horizontal rules.
1369 (should (equal (org-test-parse-and-interpret
1370 "| a | b |\n|---+---|\n| c | d |")
1371 "| a | b |\n|---+---|\n| c | d |\n"))
1372 ;; 3. Table with meta-data.
1373 (should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
1374 "| / | < | > |\n| * | 1 | 2 |\n")))
1376 (ert-deftest test-org-element/verse-block-interpreter ()
1377 "Test verse block interpretation."
1378 (should
1379 (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
1380 "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
1382 (ert-deftest test-org-element/bold-interpreter ()
1383 "Test bold interpreter."
1384 (should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
1386 (ert-deftest test-org-element/code-interpreter ()
1387 "Test code interpreter."
1388 (should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
1390 (ert-deftest test-org-element/entity-interpreter ()
1391 "Test entity interpreter."
1392 ;; 1. Without brackets.
1393 (should
1394 (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
1395 ;; 2. With brackets.
1396 (should
1397 (equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
1399 (ert-deftest test-org-element/export-snippet-interpreter ()
1400 "Test export snippet interpreter."
1401 (should (equal (org-test-parse-and-interpret "<back-end@contents>")
1402 "<back-end@contents>\n")))
1404 (ert-deftest test-org-element/footnote-reference-interpreter ()
1405 "Test footnote reference interpreter."
1406 ;; 1. Regular reference.
1407 (should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
1408 ;; 2. Normalized reference.
1409 (should (equal (org-test-parse-and-interpret "Text[1]") "Text[1]\n"))
1410 ;; 3. Named reference.
1411 (should (equal (org-test-parse-and-interpret "Text[fn:label]")
1412 "Text[fn:label]\n"))
1413 ;; 4. Inline reference.
1414 (should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
1415 "Text[fn:label:def]\n"))
1416 ;; 5. Anonymous reference.
1417 (should (equal (org-test-parse-and-interpret "Text[fn::def]")
1418 "Text[fn::def]\n")))
1420 (ert-deftest test-org-element/inline-babel-call-interpreter ()
1421 "Test inline babel call interpreter."
1422 ;; 1. Without arguments.
1423 (should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
1424 ;; 2. With arguments.
1425 (should (equal (org-test-parse-and-interpret "call_test(x=2)")
1426 "call_test(x=2)\n"))
1427 ;; 3. With header arguments.
1428 (should (equal (org-test-parse-and-interpret
1429 "call_test[:results output]()[:results html]")
1430 "call_test[:results output]()[:results html]\n")))
1432 (ert-deftest test-org-element/inline-src-block-interpreter ()
1433 "Test inline src block interpreter."
1434 ;; 1. Without header argument.
1435 (should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
1436 "src_emacs-lisp{(+ 1 1)}\n"))
1437 ;; 2. With header arguments.
1438 (should (equal (org-test-parse-and-interpret
1439 "src_emacs-lisp[:results silent]{(+ 1 1)}")
1440 "src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
1442 (ert-deftest test-org-element/italic-interpreter ()
1443 "Test italic interpreter."
1444 (should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
1446 (ert-deftest test-org-element/latex-fragment-interpreter ()
1447 "Test latex fragment interpreter."
1448 (let ((org-latex-regexps
1449 '(("begin" "^[ ]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^