1 ;;; test-org-element.el --- Tests for org-element.el
3 ;; Copyright (C) 2012, 2013 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/>.
22 (unless (featurep 'org-element
)
23 (signal 'missing-test-dependency
"org-element"))
25 (defun org-test-parse-and-interpret (text)
26 "Parse TEXT as Org syntax and interpret it.
27 Return interpreted string."
31 (org-element-interpret-data (org-element-parse-buffer))))
35 ;;; Test `org-element-map'
37 (ert-deftest test-org-element
/map
()
38 "Test `org-element-map'."
39 ;; Can map to `plain-text' objects.
42 (org-test-with-temp-text "Some text \alpha
48 (org-element-parse-buffer) 'plain-text
49 (lambda (s) (when (string-match "text" s
) (incf count
))))
51 ;; Applies to secondary strings
53 (org-element-map '("some " (bold nil
"bold") "text") 'bold
'identity
))
54 ;; Enter secondary strings before entering contents.
60 (org-test-with-temp-text "* Some \\alpha headline\n\\beta entity."
61 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
)))))
62 ;; Apply NO-RECURSION argument.
64 (org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
66 (org-element-parse-buffer) 'entity
'identity nil nil
'center-block
)))
67 ;; Use WITH-AFFILIATED argument.
71 (org-test-with-temp-text "#+CAPTION[a]: 1\n#+CAPTION[b]: 2\nParagraph"
73 (org-element-at-point) 'plain-text
'identity nil nil nil t
)))))
79 (ert-deftest test-org-element
/put-property
()
80 "Test `org-element-put-property' specifications."
82 (org-test-with-temp-text "* Headline\n *a*"
83 (let ((tree (org-element-parse-buffer)))
84 (org-element-put-property
85 (org-element-map tree
'bold
'identity nil t
) :test
1)
86 (should (org-element-property
87 :test
(org-element-map tree
'bold
'identity nil t
)))))
88 ;; Put property on a string.
90 (org-element-property :test
(org-element-put-property "Paragraph" :test t
))))
92 (ert-deftest test-org-element
/set-contents
()
93 "Test `org-element-set-contents' specifications."
94 ;; Accept multiple entries.
96 (equal '("b" (italic nil
"a"))
97 (org-test-with-temp-text "* Headline\n *a*"
98 (let ((tree (org-element-parse-buffer)))
99 (org-element-set-contents
100 (org-element-map tree
'bold
'identity nil t
) "b" '(italic nil
"a"))
101 (org-element-contents
102 (org-element-map tree
'bold
'identity nil t
))))))
103 ;; Accept atoms and elements.
106 (org-test-with-temp-text "* Headline\n *a*"
107 (let ((tree (org-element-parse-buffer)))
108 (org-element-set-contents
109 (org-element-map tree
'bold
'identity nil t
) "b")
110 (org-element-contents
111 (org-element-map tree
'bold
'identity nil t
))))))
113 (equal '((italic nil
"b"))
114 (org-test-with-temp-text "* Headline\n *a*"
115 (let ((tree (org-element-parse-buffer)))
116 (org-element-set-contents
117 (org-element-map tree
'bold
'identity nil t
) '(italic nil
"b"))
118 (org-element-contents
119 (org-element-map tree
'bold
'identity nil t
))))))
120 ;; Allow nil contents.
122 (org-test-with-temp-text "* Headline\n *a*"
123 (let ((tree (org-element-parse-buffer)))
124 (org-element-set-contents (org-element-map tree
'bold
'identity nil t
))
125 (org-element-contents (org-element-map tree
'bold
'identity nil t
))))))
127 (ert-deftest test-org-element
/set-element
()
128 "Test `org-element-set-element' specifications."
129 (org-test-with-temp-text "* Headline\n*a*"
130 (let ((tree (org-element-parse-buffer)))
131 (org-element-set-element
132 (org-element-map tree
'bold
'identity nil t
)
134 ;; Check if object is correctly replaced.
135 (should (org-element-map tree
'italic
'identity
))
136 (should-not (org-element-map tree
'bold
'identity
))
137 ;; Check if new object's parent is correctly set.
140 (org-element-property :parent
141 (org-element-map tree
'italic
'identity nil t
))
142 (org-element-map tree
'paragraph
'identity nil t
))))))
144 (ert-deftest test-org-element
/adopt-elements
()
145 "Test `org-element-adopt-elements' specifications."
148 (equal '(plain-text italic
)
149 (org-test-with-temp-text "* Headline\n *a*"
150 (let ((tree (org-element-parse-buffer)))
151 (org-element-adopt-elements
152 (org-element-map tree
'bold
'identity nil t
) '(italic nil
"a"))
153 (mapcar (lambda (blob) (org-element-type blob
))
154 (org-element-contents
155 (org-element-map tree
'bold
'identity nil t
)))))))
159 (org-test-with-temp-text "* Headline\n *a*"
160 (let ((tree (org-element-parse-buffer)))
161 (org-element-adopt-elements
162 (org-element-map tree
'bold
'identity nil t
) "b")
163 (org-element-contents
164 (org-element-map tree
'bold
'identity nil t
)))))))
170 ;;;; Affiliated Keywords
172 (ert-deftest test-org-element
/affiliated-keywords-parser
()
173 "Test affiliated keywords parsing."
174 ;; Read simple keywords.
177 (org-element-property
179 (org-test-with-temp-text "#+NAME: para\nParagraph"
180 (org-element-at-point)))))
183 (org-element-property
185 (org-test-with-temp-text "#+NAME: para\nParagraph"
186 (org-element-at-point)))))
187 ;; Parse multiple keywords.
191 (org-element-property
193 (org-test-with-temp-text
194 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
195 (org-element-at-point)))))
196 ;; Parse "parsed" keywords.
200 (org-test-with-temp-text "#+CAPTION: caption\nParagraph"
201 (car (org-element-property :caption
(org-element-at-point))))))
202 ;; Parse dual keywords.
205 '((("long") "short"))
206 (org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
207 (org-element-property :caption
(org-element-at-point)))))
208 ;; Allow multiple caption keywords.
211 '((("l2") "s2") (("l1") "s1"))
212 (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
213 (org-element-property :caption
(org-element-at-point)))))
216 '((("l1")) (nil "s1"))
217 (org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
218 (org-element-property :caption
(org-element-at-point)))))
219 ;; Corner case: orphaned keyword at the end of an element.
222 (org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
223 (progn (search-forward "name")
224 (org-element-type (org-element-at-point))))))
226 (org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
227 (progn (search-forward "Some")
228 (org-element-property :name
(org-element-at-point))))))
233 (ert-deftest test-org-element
/babel-call-parser
()
234 "Test `babel-call' parsing."
237 (org-test-with-temp-text "#+CALL: test()"
238 (org-element-map (org-element-parse-buffer) 'babel-call
'identity
)))
241 (org-test-with-temp-text "#+call: test()"
242 (org-element-map (org-element-parse-buffer) 'babel-call
'identity
))))
247 (ert-deftest test-org-element
/bold-parser
()
248 "Test `bold' parser."
251 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
252 (org-test-with-temp-text "*bold*"
253 (org-element-map (org-element-parse-buffer) 'bold
'identity nil t
))))
254 ;; Multi-line markup.
257 (org-element-contents
258 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
259 (org-test-with-temp-text "*first line\nsecond line*"
260 (org-element-map (org-element-parse-buffer) 'bold
'identity nil t
))))
261 '("first line\nsecond line"))))
266 (ert-deftest test-org-element
/center-block-parser
()
267 "Test `center-block' parser."
270 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
271 (org-element-map (org-element-parse-buffer) 'center-block
'identity
)))
274 (org-test-with-temp-text "#+begin_center\nText\n#+end_center"
275 (org-element-map (org-element-parse-buffer) 'center-block
'identity
)))
276 ;; Ignore incomplete block.
278 (org-test-with-temp-text "#+BEGIN_CENTER"
280 (org-element-parse-buffer) 'center-block
'identity nil t
))))
285 (ert-deftest test-org-element
/clock-parser
()
286 "Test `clock' parser."
288 (let* ((org-clock-string "CLOCK:")
289 (clock (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
290 (org-element-at-point))))
291 (should (eq (org-element-property :status clock
) 'running
))
293 (equal (org-element-property :raw-value
294 (org-element-property :value clock
))
295 "[2012-01-01 sun. 00:01]"))
296 (should-not (org-element-property :duration clock
)))
298 (let* ((org-clock-string "CLOCK:")
300 (org-test-with-temp-text
301 "CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
302 (org-element-at-point))))
303 (should (eq (org-element-property :status clock
) 'closed
))
304 (should (equal (org-element-property :raw-value
305 (org-element-property :value clock
))
306 "[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"))
307 (should (equal (org-element-property :duration clock
) "0:01"))))
312 (ert-deftest test-org-element
/code-parser
()
313 "Test `code' parser."
316 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
317 (org-test-with-temp-text "~code~"
318 (org-element-map (org-element-parse-buffer) 'code
'identity
))))
319 ;; Multi-line markup.
322 (org-element-property
324 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
325 (org-test-with-temp-text "~first line\nsecond line~"
327 (org-element-parse-buffer) 'code
'identity nil t
))))
328 "first line\nsecond line")))
333 (ert-deftest test-org-element
/comment-parser
()
334 "Test `comment' parser."
337 (org-test-with-temp-text "# Comment"
338 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
341 (org-test-with-temp-text " # Comment"
342 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
343 ;; Preserve indentation.
346 (org-element-property
348 (org-test-with-temp-text "# No blank\n# One blank"
349 (org-element-map (org-element-parse-buffer) 'comment
'identity nil t
)))
350 "No blank\n One blank"))
351 ;; Comment with blank lines.
354 (org-element-property
356 (org-test-with-temp-text "# First part\n# \n#\n# Second part"
357 (org-element-map (org-element-parse-buffer) 'comment
'identity nil t
)))
358 "First part\n\n\nSecond part"))
359 ;; Do not mix comments and keywords.
362 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
363 (length (org-element-map
364 (org-element-parse-buffer) 'comment
'identity
)))))
367 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
368 (org-element-property
371 (org-element-parse-buffer) 'comment
'identity nil t
))))))
376 (ert-deftest test-org-element
/comment-block-parser
()
377 "Test `comment-block' parser."
380 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
382 (org-element-parse-buffer) 'comment-block
'identity
)))
385 (org-test-with-temp-text "#+begin_comment\nText\n#+end_comment"
387 (org-element-parse-buffer) 'comment-block
'identity
)))
388 ;; Ignore incomplete block.
390 (org-test-with-temp-text "#+BEGIN_COMMENT"
392 (org-element-parse-buffer) 'comment-block
'identity nil t
))))
397 (ert-deftest test-org-element
/diary-sexp-parser
()
398 "Test `diary-sexp' parser."
402 (org-test-with-temp-text
403 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old"
404 (org-element-type (org-element-at-point)))))
405 ;; Diary sexp must live at beginning of line
408 (org-test-with-temp-text " %%(org-bbdb-anniversaries)"
409 (org-element-type (org-element-at-point))))))
414 (ert-deftest test-org-element
/drawer-parser
()
415 "Test `drawer' parser."
418 (let ((org-drawers '("TEST")))
419 (org-test-with-temp-text ":TEST:\nText\n:END:"
420 (org-element-map (org-element-parse-buffer) 'drawer
'identity
))))
421 ;; Do not mix regular drawers and property drawers.
423 (let ((org-drawers '("PROPERTIES")))
424 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
426 (org-element-parse-buffer) 'drawer
'identity nil t
))))
427 ;; Ignore incomplete drawer.
429 (let ((org-drawers '("TEST")))
430 (org-test-with-temp-text ":TEST:"
432 (org-element-parse-buffer) 'drawer
'identity nil t
)))))
437 (ert-deftest test-org-element
/dynamic-block-parser
()
438 "Test `dynamic-block' parser."
441 (org-test-with-temp-text
442 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
443 (org-element-map (org-element-parse-buffer) 'dynamic-block
'identity
)))
446 (org-test-with-temp-text
447 "#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
448 (org-element-map (org-element-parse-buffer) 'dynamic-block
'identity
)))
449 ;; Ignore incomplete block.
451 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
453 (org-element-parse-buffer) 'dynamic-block
'identity nil t
))))
458 (ert-deftest test-org-element
/entity-parser
()
459 "Test `entity' parser."
462 (org-test-with-temp-text "\\sin"
463 (org-element-map (org-element-parse-buffer) 'entity
'identity
)))
466 (org-element-property
468 (org-test-with-temp-text "\\alpha{}text"
469 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
))))
470 ;; User-defined entity.
473 (org-element-property
475 (let ((org-entities-user
476 '(("test" "test" nil
"test" "test" "test" "test"))))
477 (org-test-with-temp-text "\\test"
478 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
))))
480 ;; Special case: entity at the end of a container.
483 (org-test-with-temp-text "*\\alpha \\beta*"
484 (search-forward "be")
485 (org-element-type (org-element-context))))))
490 (ert-deftest test-org-element
/example-block-parser
()
491 "Test `example-block' parser."
494 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
495 (org-element-map (org-element-parse-buffer) 'example-block
'identity
)))
496 ;; Ignore incomplete block.
499 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
500 (org-element-type (org-element-at-point)))))
501 ;; Properly un-escape code.
503 (equal "* Headline\n #+keyword\nText\n"
504 (org-test-with-temp-text
505 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
506 (org-element-property :value
(org-element-at-point)))))
507 ;; Nil `org-src-preserve-indentation': Remove maximum common
511 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n L1\n L2\n#+END_EXAMPLE"
512 (let ((org-src-preserve-indentation nil
))
513 (org-element-property :value
(org-element-at-point))))))
514 ;; Non-nil `org-src-preserve-indentation': Remove block indentation
515 ;; only, unless block contents are less indented than block
519 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
520 (let ((org-src-preserve-indentation t
))
521 (org-element-property :value
(org-element-at-point))))))
525 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
526 (let ((org-src-preserve-indentation t
))
527 (org-element-property :value
(org-element-at-point)))))))
529 (ert-deftest test-org-element
/block-switches
()
530 "Test `example-block' and `src-block' switches parsing."
531 (let ((org-coderef-label-format "(ref:%s)"))
532 ;; 1. Test "-i" switch.
534 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
535 (org-element-property :preserve-indent
(org-element-at-point))))
537 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
538 (org-element-property :preserve-indent
(org-element-at-point))))
540 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
541 (org-element-property :preserve-indent
(org-element-at-point))))
543 (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
544 (org-element-property :preserve-indent
(org-element-at-point))))
545 ;; 2. "-n -r -k" combination should number lines, retain labels but
546 ;; not use them in coderefs.
548 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
549 (let ((element (org-element-at-point)))
550 (and (org-element-property :number-lines element
)
551 (org-element-property :retain-labels element
)
552 (not (org-element-property :use-labels element
))))))
554 (org-test-with-temp-text
555 "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
556 (let ((element (org-element-at-point)))
557 (and (org-element-property :number-lines element
)
558 (org-element-property :retain-labels element
)
559 (not (org-element-property :use-labels element
))))))
560 ;; 3. "-n -r" combination should number-lines remove labels and not
561 ;; use them in coderefs.
563 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
564 (let ((element (org-element-at-point)))
565 (and (org-element-property :number-lines element
)
566 (not (org-element-property :retain-labels element
))
567 (not (org-element-property :use-labels element
))))))
569 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
570 (let ((element (org-element-at-point)))
571 (and (org-element-property :number-lines element
)
572 (not (org-element-property :retain-labels element
))
573 (not (org-element-property :use-labels element
))))))
574 ;; 4. "-n" or "+n" should number lines, retain labels and use them
577 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
578 (let ((element (org-element-at-point)))
579 (and (org-element-property :number-lines element
)
580 (org-element-property :retain-labels element
)
581 (org-element-property :use-labels element
)))))
583 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
584 (let ((element (org-element-at-point)))
585 (and (org-element-property :number-lines element
)
586 (org-element-property :retain-labels element
)
587 (org-element-property :use-labels element
)))))
589 (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
590 (let ((element (org-element-at-point)))
591 (and (org-element-property :number-lines element
)
592 (org-element-property :retain-labels element
)
593 (org-element-property :use-labels element
)))))
595 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
596 (let ((element (org-element-at-point)))
597 (and (org-element-property :number-lines element
)
598 (org-element-property :retain-labels element
)
599 (org-element-property :use-labels element
)))))
600 ;; 5. No switch should not number lines, but retain labels and use
603 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
604 (let ((element (org-element-at-point)))
605 (and (not (org-element-property :number-lines element
))
606 (org-element-property :retain-labels element
)
607 (org-element-property :use-labels element
)))))
609 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
610 (let ((element (org-element-at-point)))
611 (and (not (org-element-property :number-lines element
))
612 (org-element-property :retain-labels element
)
613 (org-element-property :use-labels element
)))))
614 ;; 6. "-r" switch only: do not number lines, remove labels, and
615 ;; don't use labels in coderefs.
617 (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
618 (let ((element (org-element-at-point)))
619 (and (not (org-element-property :number-lines element
))
620 (not (org-element-property :retain-labels element
))
621 (not (org-element-property :use-labels element
))))))
623 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
624 (let ((element (org-element-at-point)))
625 (and (not (org-element-property :number-lines element
))
626 (not (org-element-property :retain-labels element
))
627 (not (org-element-property :use-labels element
))))))
628 ;; 7. Recognize coderefs with user-defined syntax.
632 (org-test-with-temp-text
633 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
634 (org-element-property :label-fmt
(org-element-at-point)))))
638 (org-test-with-temp-text
639 "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
640 (org-element-property :label-fmt
(org-element-at-point)))))))
645 (ert-deftest test-org-element
/export-block-parser
()
646 "Test `export-block' parser."
649 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
651 (let ((org-element-block-name-alist
652 '(("LATEX" . org-element-export-block-parser
))))
653 (org-element-parse-buffer))
654 'export-block
'identity
)))
657 (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
659 (let ((org-element-block-name-alist
660 '(("LATEX" . org-element-export-block-parser
))))
661 (org-element-parse-buffer))
662 'export-block
'identity
)))
663 ;; Ignore incomplete block.
665 (org-test-with-temp-text "#+BEGIN_LATEX"
667 (let ((org-element-block-name-alist
668 '(("LATEX" . org-element-export-block-parser
))))
669 (org-element-parse-buffer))
670 'export-block
'identity nil t
))))
675 (ert-deftest test-org-element
/export-snippet-parser
()
676 "Test `export-snippet' parser."
679 '("back-end" .
"contents")
680 (org-test-with-temp-text "@@back-end:contents@@"
682 (org-element-parse-buffer) 'export-snippet
683 (lambda (snippet) (cons (org-element-property :back-end snippet
)
684 (org-element-property :value snippet
)))
690 (ert-deftest test-org-element
/fixed-width
()
691 "Test fixed-width area parsing."
692 ;; Preserve indentation.
694 (org-test-with-temp-text ": no blank\n: one blank"
695 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
696 ;; Fixed-width with empty lines.
698 (org-test-with-temp-text ": first part\n:\n: \n: second part"
699 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
700 ;; Parse indented fixed-width markers.
702 (org-test-with-temp-text "Text\n : no blank\n : one blank"
703 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
704 ;; Distinguish fixed-width areas within a list and outside of it.
708 (org-test-with-temp-text "
711 : fixed-width outside"
713 (org-element-parse-buffer) 'fixed-width
'identity
))))))
716 ;;;; Footnote Definition
718 (ert-deftest test-org-element
/footnote-definition-parser
()
719 "Test `footnote-definition' parser."
721 (org-test-with-temp-text "[fn:1] Definition"
722 (org-element-map (org-element-parse-buffer) 'footnote-definition
724 ;; Footnote with more contents
727 (org-element-property
729 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
730 (org-element-map (org-element-parse-buffer) 'footnote-definition
732 ;; Footnote starting with special syntax.
734 (org-test-with-temp-text "[fn:1] - no item"
735 (org-element-map (org-element-parse-buffer) 'item
'identity
)))
736 ;; Correctly handle footnote starting with an empty line.
739 (org-test-with-temp-text "[fn:1]\n\n Body"
740 (org-element-property :contents-begin
741 (org-element-at-point))))))
744 ;;;; Footnotes Reference.
746 (ert-deftest test-org-element
/footnote-reference-parser
()
747 "Test `footnote-reference' parser."
748 ;; 1. Parse a standard reference.
749 (org-test-with-temp-text "Text[fn:label]"
752 (org-element-parse-buffer) 'footnote-reference
'identity
)))
753 ;; 2. Parse a normalized reference.
754 (org-test-with-temp-text "Text[1]"
757 (org-element-parse-buffer) 'footnote-reference
'identity
)))
758 ;; 3. Parse an inline reference.
759 (org-test-with-temp-text "Text[fn:test:def]"
762 (org-element-parse-buffer) 'footnote-reference
'identity
)))
763 ;; 4. Parse an anonymous reference.
764 (org-test-with-temp-text "Text[fn::def]"
767 (org-element-parse-buffer) 'footnote-reference
'identity
)))
768 ;; 5. Parse nested footnotes.
769 (org-test-with-temp-text "Text[fn::def [fn:label]]"
774 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
775 ;; 6. Parse adjacent footnotes.
776 (org-test-with-temp-text "Text[fn:label1][fn:label2]"
781 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
782 ;; 7. Only properly closed footnotes are recognized as such.
783 (org-test-with-temp-text "Text[fn:label"
786 (org-element-parse-buffer) 'footnote-reference
'identity
))))
791 (ert-deftest test-org-element
/headline-quote-keyword
()
792 "Test QUOTE keyword recognition."
794 (org-test-with-temp-text "* Headline"
795 (let ((org-quote-string "QUOTE"))
796 (should-not (org-element-property :quotedp
(org-element-at-point)))))
797 ;; Standard position.
798 (org-test-with-temp-text "* QUOTE Headline"
799 (let* ((org-quote-string "QUOTE")
800 (headline (org-element-at-point)))
801 (should (org-element-property :quotedp headline
))
802 ;; Test removal from raw value.
803 (should (equal (org-element-property :raw-value headline
) "Headline"))))
805 (org-test-with-temp-text "* QUOTE Headline"
806 (let* ((org-quote-string "Quote")
807 (headline (org-element-at-point)))
808 (should-not (org-element-property :quotedp headline
))
809 (should (equal (org-element-property :raw-value headline
)
811 ;; With another keyword.
812 (org-test-with-temp-text "* TODO QUOTE Headline"
813 (let* ((org-quote-string "QUOTE")
814 (org-todo-keywords '((sequence "TODO" "DONE")))
815 (headline (org-element-at-point)))
816 (should (org-element-property :quotedp headline
))
817 (should (equal (org-element-property :raw-value headline
) "Headline"))))
818 ;; With the keyword only.
819 (org-test-with-temp-text "* QUOTE"
820 (let* ((org-quote-string "QUOTE")
821 (headline (org-element-at-point)))
822 (should (org-element-property :quotedp headline
))
823 (should (equal (org-element-property :raw-value headline
) "")))))
825 (ert-deftest test-org-element
/headline-comment-keyword
()
826 "Test COMMENT keyword recognition."
828 (org-test-with-temp-text "* Headline"
829 (let ((org-comment-string "COMMENT"))
830 (should-not (org-element-property :commentedp
(org-element-at-point)))))
831 ;; Standard position.
832 (org-test-with-temp-text "* COMMENT Headline"
833 (let ((org-comment-string "COMMENT")
834 (headline (org-element-at-point)))
835 (should (org-element-property :commentedp headline
))
836 (should (equal (org-element-property :raw-value headline
) "Headline"))))
838 (org-test-with-temp-text "* COMMENT Headline"
839 (let* ((org-comment-string "Comment")
840 (headline (org-element-at-point)))
841 (should-not (org-element-property :commentedp headline
))
842 (should (equal (org-element-property :raw-value headline
)
843 "COMMENT Headline"))))
844 ;; With another keyword.
845 (org-test-with-temp-text "* TODO COMMENT Headline"
846 (let* ((org-comment-string "COMMENT")
847 (org-todo-keywords '((sequence "TODO" "DONE")))
848 (headline (org-element-at-point)))
849 (should (org-element-property :commentedp headline
))
850 (should (equal (org-element-property :raw-value headline
) "Headline"))))
851 ;; With the keyword only.
852 (org-test-with-temp-text "* COMMENT"
853 (let* ((org-comment-string "COMMENT")
854 (headline (org-element-at-point)))
855 (should (org-element-property :commentedp headline
))
856 (should (equal (org-element-property :raw-value headline
) "")))))
858 (ert-deftest test-org-element
/headline-archive-tag
()
859 "Test ARCHIVE tag recognition."
861 (org-test-with-temp-text "* Headline"
862 (let ((org-archive-tag "ARCHIVE"))
863 (should-not (org-element-property :archivedp
(org-element-at-point)))))
865 (org-test-with-temp-text "* Headline :ARCHIVE:"
866 (let ((org-archive-tag "ARCHIVE"))
867 (let ((headline (org-element-at-point)))
868 (should (org-element-property :archivedp headline
))
870 (should-not (org-element-property :tags headline
))))
871 (let ((org-archive-tag "Archive"))
872 (should-not (org-element-property :archivedp
(org-element-at-point)))))
874 (org-test-with-temp-text "* Headline :test:ARCHIVE:"
875 (let ((org-archive-tag "ARCHIVE"))
876 (let ((headline (org-element-at-point)))
877 (should (org-element-property :archivedp headline
))
879 (should (equal (org-element-property :tags headline
) '("test")))))))
881 (ert-deftest test-org-element
/headline-properties
()
882 "Test properties from property drawer."
883 ;; All properties from property drawer have their symbol upper
886 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
887 (org-element-property :FOO
(org-element-at-point))))
889 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
890 (org-element-property :foo
(org-element-at-point)))))
895 (ert-deftest test-org-element
/horizontal-rule-parser
()
896 "Test `horizontal-rule' parser."
899 (org-test-with-temp-text "-----"
900 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
903 (org-test-with-temp-text " -----"
904 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
905 ;; Hyphen must be alone on the line.
907 (org-test-with-temp-text "-----wrong"
908 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
909 ;; 4 hyphens is too small.
911 (org-test-with-temp-text "----"
912 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
))))
915 ;;;; Inline Babel Call
917 (ert-deftest test-org-element
/inline-babel-call-parser
()
918 "Test `inline-babel-call' parser."
920 (org-test-with-temp-text "call_test()"
922 (org-element-parse-buffer) 'inline-babel-call
'identity
))))
925 ;;;; Inline Src Block
927 (ert-deftest test-org-element
/inline-src-block-parser
()
928 "Test `inline-src-block' parser."
930 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
931 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
)))
932 ;; Test parsing at the beginning of an item.
934 (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
935 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
))))
940 (ert-deftest test-org-element
/inlinetask-parser
()
941 "Test `inlinetask' parser."
942 (when (featurep 'org-inlinetask
)
943 (let ((org-inlinetask-min-level 15))
944 ;; 1. Regular inlinetask.
946 (org-test-with-temp-text
947 "*************** Task\nTest\n*************** END"
948 (org-element-map (org-element-parse-buffer) 'inlinetask
'identity
)))
949 ;; 2. Degenerate inlinetask.
951 (org-test-with-temp-text "*************** Task"
952 (org-element-map (org-element-parse-buffer) 'inlinetask
'identity
)))
957 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
958 (org-test-with-temp-text "*************** TODO Task"
959 (org-element-property
961 (org-element-map (org-element-parse-buffer) 'inlinetask
962 'identity nil t
))))))
967 (org-test-with-temp-text "
969 DEADLINE: <2012-03-29 thu.>"
970 (org-element-property
972 (org-element-map (org-element-parse-buffer) 'inlinetask
'identity nil t
)))))
977 (org-test-with-temp-text "
978 *************** [#A] Task"
979 (org-element-property
982 (org-element-parse-buffer) 'inlinetask
'identity nil t
)))))
987 (org-test-with-temp-text "
988 *************** Task :test:"
989 (org-element-property
992 (org-element-parse-buffer) 'inlinetask
'identity nil t
)))))
993 ;; Regular properties are accessed through upper case keywords.
995 (org-test-with-temp-text "
1000 *************** END"
1002 (org-element-property :FOO
(org-element-at-point))))
1004 (org-test-with-temp-text "
1005 *************** Task
1009 *************** END"
1011 (org-element-property :foo
(org-element-at-point)))))))
1016 (ert-deftest test-org-element
/italic-parser
()
1017 "Test `italic' parser."
1020 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1021 (org-test-with-temp-text "/italic/"
1022 (org-element-map (org-element-parse-buffer) 'italic
'identity nil t
))))
1023 ;; Multi-line markup.
1026 (org-element-contents
1027 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1028 (org-test-with-temp-text "/first line\nsecond line/"
1029 (org-element-map (org-element-parse-buffer) 'italic
'identity nil t
))))
1030 '("first line\nsecond line"))))
1035 (ert-deftest test-org-element
/item-parser
()
1036 "Test `item' parser."
1039 (org-test-with-temp-text "- item"
1040 (org-element-map (org-element-parse-buffer) 'item
'identity
)))
1044 (org-element-property
1046 (org-test-with-temp-text "6. [@6] item"
1047 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
1052 (org-element-property
1054 (org-test-with-temp-text "- tag :: description"
1055 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
1056 ;; No tags in ordered lists.
1058 (org-element-property
1060 (org-test-with-temp-text "1. tag :: description"
1061 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
))))
1066 (org-test-with-temp-text "
1071 (org-element-parse-buffer) 'item
1072 (lambda (item) (org-element-property :checkbox item
))))))
1073 ;; Item starting with special syntax.
1075 (equal '(("- item"))
1076 (org-test-with-temp-text "- - item"
1078 (org-element-parse-buffer) 'paragraph
'org-element-contents
))))
1079 ;; Block in an item: ignore indentation within the block.
1081 (org-test-with-temp-text "- item\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1083 (goto-char (org-element-property :end
(org-element-at-point)))
1089 (ert-deftest test-org-element
/keyword-parser
()
1090 "Test `keyword' parser."
1093 (org-test-with-temp-text "#+KEYWORD: value"
1094 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1095 ;; Keywords are case-insensitive.
1097 (org-test-with-temp-text "#+keyword: value"
1098 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1099 ;; Affiliated keywords are not keywords.
1101 (org-test-with-temp-text "#+NAME: value
1103 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1104 ;; Do not mix keywords with Babel calls and dynamic blocks.
1106 (org-test-with-temp-text "#+CALL: fun()"
1107 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1109 (org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
1110 (org-element-map (org-element-parse-buffer) 'keyword
'identity
))))
1113 ;;;; Latex Environment
1115 (ert-deftest test-org-element
/latex-environment-parser
()
1116 "Test `latex-environment' parser."
1118 (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
1119 (org-element-map (org-element-parse-buffer) 'latex-environment
'identity
)))
1120 ;; Allow nested environments.
1128 (org-test-with-temp-text "
1134 (org-element-property
1137 (org-element-parse-buffer) 'latex-environment
'identity nil t
)))))
1138 ;; Allow environments with options and arguments.
1140 (eq 'latex-environment
1141 (org-test-with-temp-text
1142 "\\begin{theorem}[Euler]\ne^{i\\pi}+1=0\n\\end{theorem}"
1143 (org-element-type (org-element-at-point)))))
1145 (eq 'latex-environment
1146 (org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
1147 (org-element-type (org-element-at-point)))))
1149 (eq 'latex-environment
1150 (org-test-with-temp-text "\\begin{env}{arg} something\nvalue\n\\end{env}"
1151 (org-element-type (org-element-at-point))))))
1156 (ert-deftest test-org-element
/latex-fragment-parser
()
1157 "Test `latex-fragment' parser."
1159 (org-test-with-temp-text "$a$"
1160 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1162 (org-test-with-temp-text "$$a$$"
1163 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1165 (org-test-with-temp-text "\\(a\\)"
1166 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1168 (org-test-with-temp-text "\\[a\\]"
1170 (org-element-parse-buffer) 'latex-fragment
'identity
)))
1171 ;; Test fragment at the beginning of an item.
1174 (org-test-with-temp-text "- $x$"
1175 (progn (search-forward "$")
1176 (org-element-type (org-element-context)))))))
1181 (ert-deftest test-org-element
/line-break-parser
()
1182 "Test `line-break' parser."
1185 (org-test-with-temp-text "Text \\\\"
1186 (org-element-map (org-element-parse-buffer) 'line-break
'identity
)))
1187 ;; Line break with trailing white spaces.
1189 (org-test-with-temp-text "Text \\\\ "
1190 (org-element-map (org-element-parse-buffer) 'line-break
'identity
)))
1191 ;; Three backslashes are too much.
1193 (org-test-with-temp-text "Text \\\\\\"
1194 (org-element-map (org-element-parse-buffer) 'line-break
'identity
))))
1199 (ert-deftest test-org-element
/link-parser
()
1200 "Test `link' parser."
1205 (org-test-with-temp-text "A radio link"
1206 (org-element-property
1209 (let ((org-target-link-regexp "radio")) (org-element-parse-buffer))
1210 'link
'identity nil t
)))))
1213 ;; ... with description.
1217 (org-test-with-temp-text "[[http://orgmode.org][Orgmode.org]]"
1218 (org-element-contents
1219 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1220 ;; ... without description.
1224 (org-test-with-temp-text "[[http://orgmode.org]]"
1225 (org-element-property
1227 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1228 ;; ... with expansion.
1231 "//orgmode.org/worg"
1232 (org-test-with-temp-text "[[Org:worg]]"
1233 (let ((org-link-abbrev-alist '(("Org" .
"http://orgmode.org/"))))
1234 (org-element-property
1236 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))))))
1237 ;; ... with translation.
1241 (org-test-with-temp-text "[[http://orgmode.org]]"
1242 (flet ((link-translate (type path
) (cons type
"127.0.0.1")))
1243 (let ((org-link-translation-function 'link-translate
))
1244 (org-element-property
1246 (org-element-map (org-element-parse-buffer) 'link
1247 'identity nil t
)))))))
1252 (org-test-with-temp-text "[[id:aaaa]]"
1253 (org-element-property
1255 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1256 ;; ... custom-id link.
1260 (org-test-with-temp-text "[[#some-id]]"
1261 (org-element-property
1263 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1264 ;; ... coderef link.
1268 (org-test-with-temp-text "[[(reference)]]"
1269 (org-element-property
1271 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1276 (org-test-with-temp-text "[[target-or-title]]"
1277 (org-element-property
1279 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1280 ;; ... file-type link with search option.
1283 '(("file" "projects.org" "*task title"))
1284 (org-test-with-temp-text "[[file:projects.org::*task title]]"
1285 (org-element-map (org-element-parse-buffer) 'link
1286 (lambda (l) (list (org-element-property :type l
)
1287 (org-element-property :path l
)
1288 (org-element-property :search-option l
)))))))
1289 ;; ... file-type link with application.
1292 '(("file" "projects.org" "docview"))
1293 (org-test-with-temp-text "[[docview:projects.org]]"
1294 (org-element-map (org-element-parse-buffer) 'link
1295 (lambda (l) (list (org-element-property :type l
)
1296 (org-element-property :path l
)
1297 (org-element-property :application l
)))))))
1300 (org-test-with-temp-text "A link: http://orgmode.org"
1301 (org-element-map (org-element-parse-buffer) 'link
'identity
)))
1304 (org-test-with-temp-text "A link: <http://orgmode.org>"
1305 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))
1306 ;; Link abbreviation.
1309 (org-test-with-temp-text
1310 "#+LINK: orgmode http://www.orgmode.org/\n[[orgmode:#docs]]"
1311 (progn (org-mode-restart)
1312 (goto-char (1- (point-max)))
1313 (org-element-property :type
(org-element-context))))))
1314 ;; Link abbreviation in a secondary string.
1317 (org-test-with-temp-text
1318 "#+LINK: orgmode http://www.orgmode.org/\n* H [[orgmode:#docs]]"
1319 (progn (org-mode-restart)
1320 (org-element-map (org-element-parse-buffer) 'link
1321 (lambda (link) (org-element-property :type link
))
1323 ;; Plain links are allowed as description of regular links.
1326 (org-test-with-temp-text "[[http://orgmode.org][file:unicorn.jpg]]"
1327 (search-forward "file:")
1328 (org-element-property :type
(org-element-context))))))
1333 (ert-deftest test-org-element
/macro-parser
()
1334 "Test `macro' parser."
1335 ;; Without arguments.
1337 (org-test-with-temp-text "{{{macro}}}"
1338 (org-element-map (org-element-parse-buffer) 'macro
'identity
)))
1341 (org-test-with-temp-text "{{{macro(arg1,arg2)}}}"
1342 (org-element-map (org-element-parse-buffer) 'macro
'identity
)))
1343 ;; Properly handle protected commas in arguments...
1347 (org-test-with-temp-text "{{{macro(arg1\\,arg1,arg2)}}}"
1348 (org-element-property :args
(org-element-context))))))
1349 ;; ... even when last argument ends with a protected comma.
1352 (org-test-with-temp-text "{{{macro(C-\\,)}}}"
1353 (org-element-property :args
(org-element-context)))))
1354 ;; Allow to escape escaping character.
1357 (org-test-with-temp-text "{{{macro(C-\\\\,)}}}"
1358 (org-element-property :args
(org-element-context)))))
1359 ;; No need to escape backslashes elsewhere.
1362 (org-test-with-temp-text "{{{macro(\\)}}}"
1363 (org-element-property :args
(org-element-context))))))
1368 (ert-deftest test-org-element
/node-property
()
1369 "Test `node-property' parser."
1372 (equal '("abc" "value")
1373 (org-test-with-temp-text ":PROPERTIES:\n:abc: value\n:END:"
1374 (progn (forward-line)
1375 (let ((element (org-element-at-point)))
1376 (list (org-element-property :key element
)
1377 (org-element-property :value element
)))))))
1378 ;; Value should be trimmed.
1381 (org-test-with-temp-text ":PROPERTIES:\n:abc: value \n:END:"
1382 (progn (forward-line)
1383 (let ((element (org-element-at-point)))
1384 (org-element-property :value element
))))))
1385 ;; A node property requires to be wrapped within a property drawer.
1388 (org-test-with-temp-text ":abc: value"
1389 (org-element-type (org-element-at-point))))))
1394 (ert-deftest test-org-element
/paragraph-parser
()
1395 "Test `paragraph' parser."
1398 (org-test-with-temp-text "Paragraph"
1399 (org-element-map (org-element-parse-buffer) 'paragraph
'identity nil t
)))
1400 ;; Property find end of a paragraph stuck to another element.
1403 (org-test-with-temp-text "Paragraph\n# Comment"
1405 (org-element-parse-buffer) 'paragraph
1406 (lambda (p) (char-after (org-element-property :end p
)))
1408 ;; Include ill-formed Keywords.
1410 (org-test-with-temp-text "#+wrong_keyword something"
1411 (org-element-map (org-element-parse-buffer) 'paragraph
'identity
)))
1412 ;; Include incomplete-drawers.
1414 (let ((org-drawers '("TEST")))
1415 (org-test-with-temp-text ":TEST:\nParagraph"
1416 (let ((elem (org-element-at-point)))
1417 (and (eq (org-element-type elem
) 'paragraph
)
1418 (= (point-max) (org-element-property :end elem
)))))))
1419 ;; Include non-existent drawers.
1421 (let ((org-drawers '("TEST")))
1422 (org-test-with-temp-text ":NONAME:"
1423 (org-element-map (org-element-parse-buffer) 'paragraph
'identity
))))
1424 ;; Include incomplete blocks.
1426 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph"
1427 (let ((elem (org-element-at-point)))
1428 (and (eq (org-element-type elem
) 'paragraph
)
1429 (= (point-max) (org-element-property :end elem
))))))
1430 ;; Include incomplete dynamic blocks.
1432 (org-test-with-temp-text "#+BEGIN: \nParagraph"
1433 (let ((elem (org-element-at-point)))
1434 (and (eq (org-element-type elem
) 'paragraph
)
1435 (= (point-max) (org-element-property :end elem
))))))
1436 ;; Include incomplete latex environments.
1438 (org-test-with-temp-text "\begin{equation}\nParagraph"
1439 (let ((elem (org-element-at-point)))
1440 (and (eq (org-element-type elem
) 'paragraph
)
1441 (= (point-max) (org-element-property :end elem
))))))
1442 ;; Do not steal affiliated keywords from container.
1444 (org-test-with-temp-text "#+ATTR_LATEX: test\n- item 1"
1445 (let ((elem (progn (search-forward "item") (org-element-at-point))))
1446 (and (eq (org-element-type elem
) 'paragraph
)
1447 (not (org-element-property :attr_latex elem
))
1448 (/= (org-element-property :begin elem
) 1))))))
1453 (ert-deftest test-org-element
/plain-list-parser
()
1454 "Test `plain-list' parser."
1455 (org-test-with-temp-text "- item"
1456 (should (org-element-map (org-element-parse-buffer) 'plain-list
'identity
)))
1457 ;; Blank lines after the list only belong to outer plain list.
1461 (org-test-with-temp-text "
1466 (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
1467 (lambda (pl) (org-element-property :end pl
)))))
1469 ;; Move to ending of outer list.
1470 (progn (goto-char (car endings
)) (looking-at "Outside list"))
1471 ;; Move to ending of inner list.
1472 (progn (goto-char (nth 1 endings
)) (looking-at "^$")))))))
1473 ;; Correctly compute end of list if it doesn't end at a line
1476 (org-test-with-temp-text "- list\n \n "
1477 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1482 (ert-deftest test-org-element
/planning-parser
()
1483 "Test `planning' parser."
1485 (equal "[2012-03-29 thu.]"
1486 (org-element-property
1488 (org-element-property
1490 (org-test-with-temp-text "CLOSED: [2012-03-29 thu.]"
1491 (org-element-at-point))))))
1493 (equal "<2012-03-29 thu.>"
1494 (org-element-property
1496 (org-element-property
1498 (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
1499 (org-element-at-point))))))
1501 (equal "<2012-03-29 thu.>"
1502 (org-element-property
1504 (org-element-property
1506 (org-test-with-temp-text "SCHEDULED: <2012-03-29 thu.>"
1507 (org-element-at-point)))))))
1510 ;;;; Property Drawer
1512 (ert-deftest test-org-element
/property-drawer
()
1513 "Test `property-drawer' parser."
1516 (let ((org-drawers '("PROPERTIES")))
1517 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
1519 (org-element-parse-buffer) 'property-drawer
'identity nil t
))))
1520 ;; Do not mix property drawers and regular drawers.
1522 (let ((org-drawers '("TEST")))
1523 (org-test-with-temp-text ":TEST:\n:prop: value\n:END:"
1525 (org-element-parse-buffer) 'property-drawer
'identity nil t
))))
1526 ;; Ignore incomplete drawer.
1528 (let ((org-drawers '("PROPERTIES")))
1529 (org-test-with-temp-text ":PROPERTIES:\n:prop: value"
1531 (org-element-parse-buffer) 'property-drawer
'identity nil t
)))))
1536 (ert-deftest test-org-element
/quote-block-parser
()
1537 "Test `quote-block' parser."
1540 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
1541 (org-element-map (org-element-parse-buffer) 'quote-block
'identity
)))
1542 ;; Ignore incomplete block.
1544 (org-test-with-temp-text "#+BEGIN_QUOTE"
1546 (org-element-parse-buffer) 'quote-block
'identity nil t
))))
1551 (ert-deftest test-org-element
/quote-section-parser
()
1552 "Test `quote-section' parser."
1554 (let ((org-quote-string "QUOTE"))
1555 (org-test-with-temp-text "* QUOTE Headline\nBody"
1556 (org-element-map (org-element-parse-buffer) 'quote-section
'identity
))))
1558 (let ((org-quote-string "TEST"))
1559 (org-test-with-temp-text "* QUOTE Headline\nBody"
1560 (org-element-map (org-element-parse-buffer) 'quote-section
'identity
)))))
1565 (ert-deftest test-org-element
/radio-target-parser
()
1566 "Test `radio-target' parser."
1569 (org-test-with-temp-text "<<<radio>>>"
1570 (org-element-map (org-element-parse-buffer) 'radio-target
'identity
)))
1571 ;; Radio targets with objects.
1573 (org-test-with-temp-text "<<<radio \\alpha>>>"
1574 (org-element-map (org-element-parse-buffer) 'radio-target
'identity
))))
1579 (ert-deftest test-org-element
/section-parser
()
1580 "Test `section' parser."
1583 (org-test-with-temp-text "* Headline\nText"
1584 (org-element-map (org-element-parse-buffer) 'section
'identity
)))
1585 ;; There's a section before the first headline.
1587 (org-test-with-temp-text "Text"
1588 (org-element-map (org-element-parse-buffer) 'section
'identity
)))
1589 ;; A section cannot be empty.
1591 (org-test-with-temp-text "* Headline 1\n* Headline 2"
1592 (org-element-map (org-element-parse-buffer) 'section
'identity
)))
1593 ;; A section doesn't contain sub-trees.
1595 (org-test-with-temp-text "* Head\nText\n** Sub-Head"
1597 (org-element-map (org-element-parse-buffer) 'section
'identity nil t
)
1598 'headline
'identity
))))
1603 (ert-deftest test-org-element
/special-block-parser
()
1604 "Test `special-block' parser."
1608 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1609 (org-element-property :type
(org-element-at-point)))))
1610 ;; Special blocks can contain paragraphs.
1613 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1615 (org-element-type (org-element-at-point)))))
1616 ;; Ignore incomplete block.
1619 (org-test-with-temp-text "#+BEGIN_SPECIAL"
1620 (org-element-type (org-element-at-point)))))
1621 ;; Allow special characters in type.
1623 (equal '(special-block "SPECIAL*")
1624 (org-test-with-temp-text "#+BEGIN_SPECIAL*\nContents\n#+END_SPECIAL*"
1625 (let ((element (org-element-at-point)))
1626 (list (org-element-type element
)
1627 (org-element-property :type element
)))))))
1632 (ert-deftest test-org-element
/src-block-parser
()
1633 "Test `src-block' parser."
1636 (org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
1637 (org-element-map (org-element-parse-buffer) 'src-block
'identity
)))
1638 ;; Ignore incomplete block.
1640 (org-test-with-temp-text "#+BEGIN_SRC"
1641 (org-element-map (org-element-parse-buffer) 'src-block
'identity
)))
1642 ;; Properly un-escape code.
1644 (equal "* Headline\n #+keyword\nText\n"
1645 (org-test-with-temp-text
1646 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
1647 (org-element-property :value
(org-element-at-point)))))
1648 ;; Nil `org-src-preserve-indentation': Remove maximum common
1652 (org-test-with-temp-text "#+BEGIN_SRC org\n L1\n L2\n#+END_SRC"
1653 (let ((org-src-preserve-indentation nil
))
1654 (org-element-property :value
(org-element-at-point))))))
1655 ;; Non-nil `org-src-preserve-indentation': Remove block indentation
1656 ;; only, unless block contents are less indented than block
1660 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1661 (let ((org-src-preserve-indentation t
))
1662 (org-element-property :value
(org-element-at-point))))))
1666 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1667 (let ((org-src-preserve-indentation t
))
1668 (org-element-property :value
(org-element-at-point)))))))
1671 ;;;; Statistics Cookie
1673 (ert-deftest test-org-element
/statistics-cookie
()
1674 "Test `statistics-cookie' parser."
1677 (org-test-with-temp-text "[1/2]"
1678 (org-element-map (org-element-parse-buffer) 'statistics-cookie
'identity
)))
1681 (org-test-with-temp-text "[33%]"
1683 (org-element-parse-buffer) 'statistics-cookie
'identity
))))
1688 (ert-deftest test-org-element
/strike-through-parser
()
1689 "Test `strike-through' parser."
1692 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1693 (org-test-with-temp-text "+strike-through+"
1694 (org-element-map (org-element-parse-buffer) 'strike-through
'identity
))))
1695 ;; Multi-line markup.
1698 (org-element-contents
1699 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1700 (org-test-with-temp-text "+first line\nsecond line+"
1702 (org-element-parse-buffer) 'strike-through
'identity nil t
))))
1703 '("first line\nsecond line"))))
1708 (ert-deftest test-org-element
/subscript-parser
()
1709 "Test `subscript' parser."
1712 (org-test-with-temp-text "a_b"
1713 (org-element-map (org-element-parse-buffer) 'subscript
'identity
)))
1716 (org-test-with-temp-text "a_{b}"
1717 (org-element-map (org-element-parse-buffer) 'subscript
'identity
)))
1718 ;; Multiple subscripts in a paragraph.
1721 (org-test-with-temp-text "a_b and c_d"
1723 (org-element-map (org-element-parse-buffer) 'subscript
'identity
))))))
1728 (ert-deftest test-org-element
/superscript-parser
()
1729 "Test `superscript' parser."
1732 (org-test-with-temp-text "a^b"
1733 (org-element-map (org-element-parse-buffer) 'superscript
'identity
)))
1736 (org-test-with-temp-text "a^{b}"
1737 (org-element-map (org-element-parse-buffer) 'superscript
'identity
)))
1738 ;; Multiple superscript in a paragraph.
1741 (org-test-with-temp-text "a^b and c^d"
1744 (org-element-parse-buffer) 'superscript
'identity
))))))
1749 (ert-deftest test-org-element
/table-parser
()
1750 "Test `table' parser."
1752 (org-test-with-temp-text "| a |"
1753 (org-element-map (org-element-parse-buffer) 'table
'identity
)))
1754 ;; TBLFM keyword is case insensitive.
1756 (org-test-with-temp-text "| a |\n#+tblfm: test"
1757 (org-element-property
1759 (org-element-map (org-element-parse-buffer) 'table
'identity nil t
))))
1760 ;; Handle multiple TBLFM lines.
1763 (org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
1764 (length (org-element-property
1767 (org-element-parse-buffer) 'table
'identity nil t
))))))
1768 ;; Do not error when parsing a table with trailing white spaces.
1769 (should (org-test-with-temp-text "| a |\n " (org-element-parse-buffer))))
1774 (ert-deftest test-org-element
/table-cell-parser
()
1775 "Test `table-cell' parser."
1777 (org-test-with-temp-text "| a |"
1778 (org-element-map (org-element-parse-buffer) 'table-cell
'identity
))))
1783 (ert-deftest test-org-element
/table-row-parser
()
1784 "Test `table-row' parser."
1786 (equal '(standard rule
)
1787 (org-test-with-temp-text "| a |\n|---|"
1789 (org-element-parse-buffer) 'table-row
1790 (lambda (row) (org-element-property :type row
)))))))
1795 (ert-deftest test-org-element
/target-parser
()
1796 "Test `target' parser."
1798 (org-test-with-temp-text "<<target>>"
1799 (org-element-map (org-element-parse-buffer) 'target
'identity
))))
1804 (ert-deftest test-org-element
/timestamp
()
1805 "Test `timestamp' parser."
1806 ;; Active timestamp.
1808 (org-test-with-temp-text "<2012-03-29 16:40>"
1809 (eq (org-element-property :type
(org-element-context)) 'active
)))
1811 (org-test-with-temp-text "<2012-03-29 Thu>"
1812 (let ((timestamp (org-element-context)))
1813 (or (org-element-property :hour-start timestamp
)
1814 (org-element-property :minute-start timestamp
)))))
1816 (equal '(2012 3 29 16 40)
1817 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
1818 (let ((object (org-element-context)))
1819 (list (org-element-property :year-start object
)
1820 (org-element-property :month-start object
)
1821 (org-element-property :day-start object
)
1822 (org-element-property :hour-start object
)
1823 (org-element-property :minute-start object
))))))
1824 ;; Inactive timestamp.
1826 (org-test-with-temp-text "[2012-03-29 Thu 16:40]"
1827 (eq (org-element-property :type
(org-element-context)) 'inactive
)))
1830 (equal '(2012 3 29 16 40 7 30)
1831 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
1832 (let ((object (org-element-context)))
1833 (list (org-element-property :year-end object
)
1834 (org-element-property :month-end object
)
1835 (org-element-property :day-end object
)
1836 (org-element-property :hour-end object
)
1837 (org-element-property :minute-end object
)
1838 (org-element-property :hour-start object
)
1839 (org-element-property :minute-start object
))))))
1842 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
1843 (org-element-property :type
(org-element-context)))))
1846 (org-test-with-temp-text "[2012-03-29 Thu 16:40]--[2012-03-29 Thu 16:41]"
1847 (eq (org-element-property :type
(org-element-context)) 'inactive-range
)))
1849 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
1850 (let ((timestamp (org-element-context)))
1851 (or (org-element-property :hour-end timestamp
)
1852 (org-element-property :minute-end timestamp
)))))
1853 ;; With repeater, warning delay and both.
1856 (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
1857 (org-element-property :repeater-type
(org-element-context)))))
1860 (org-test-with-temp-text "<2012-03-29 Thu --1y>"
1861 (org-element-property :warning-type
(org-element-context)))))
1863 (equal '(cumulate all
)
1864 (org-test-with-temp-text "<2012-03-29 Thu +1y -1y>"
1865 (let ((ts (org-element-context)))
1866 (list (org-element-property :repeater-type ts
)
1867 (org-element-property :warning-type ts
))))))
1868 ;; Timestamps are not planning elements.
1870 (org-test-with-temp-text "SCHEDULED: <2012-03-29 Thu 16:40>"
1871 (org-element-map (org-element-parse-buffer) 'timestamp
'identity
))))
1876 (ert-deftest test-org-element
/underline-parser
()
1877 "Test `underline' parser."
1880 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1881 (org-test-with-temp-text "_underline_"
1882 (org-element-map (org-element-parse-buffer) 'underline
'identity
))))
1883 ;; Multi-line markup.
1886 (org-element-contents
1887 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1888 (org-test-with-temp-text "_first line\nsecond line_"
1890 (org-element-parse-buffer) 'underline
'identity nil t
))))
1891 '("first line\nsecond line"))))
1896 (ert-deftest test-org-element
/verbatim-parser
()
1897 "Test `verbatim' parser."
1900 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1901 (org-test-with-temp-text "=verbatim="
1902 (org-element-map (org-element-parse-buffer) 'verbatim
'identity
))))
1903 ;; Multi-line markup.
1906 (org-element-property
1908 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1909 (org-test-with-temp-text "=first line\nsecond line="
1911 (org-element-parse-buffer) 'verbatim
'identity nil t
))))
1912 "first line\nsecond line")))
1917 (ert-deftest test-org-element
/verse-block-parser
()
1918 "Test `verse-block' parser."
1921 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
1922 (org-element-map (org-element-parse-buffer) 'verse-block
'identity
)))
1925 (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
1926 (org-element-map (org-element-parse-buffer) 'verse-block
'identity
)))
1927 ;; Parse objects in verse blocks.
1929 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
1930 (org-element-map (org-element-parse-buffer) 'entity
'identity
)))
1931 ;; Ignore incomplete verse block.
1933 (org-test-with-temp-text "#+BEGIN_VERSE"
1935 (org-element-parse-buffer) 'verse-block
'identity nil t
))))
1939 ;;; Test Interpreters.
1941 (ert-deftest test-org-element
/affiliated-keywords-interpreter
()
1942 "Test if affiliated keywords are correctly interpreted."
1943 ;; Interpret simple keywords.
1946 (org-element-interpret-data
1947 '(org-data nil
(paragraph (:name
"para") "Paragraph")))
1948 "#+NAME: para\nParagraph\n"))
1949 ;; Interpret multiple keywords.
1952 (org-element-interpret-data
1953 '(org-data nil
(paragraph (:attr_ascii
("line2" "line1")) "Paragraph")))
1954 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
1955 ;; Interpret parsed keywords.
1958 (org-element-interpret-data
1959 '(org-data nil
(paragraph (:caption
(("caption"))) "Paragraph")))
1960 "#+CAPTION: caption\nParagraph\n"))
1961 ;; Interpret dual keywords.
1964 (org-element-interpret-data
1965 '(org-data nil
(paragraph (:caption
((("long") "short"))) "Paragraph")))
1966 "#+CAPTION[short]: long\nParagraph\n"))
1967 ;; Interpret multiple parsed dual keywords.
1970 (org-element-interpret-data
1971 '(org-data nil
(paragraph
1972 (:caption
((("l2") "s2") (("l1") "s1"))) "Paragraph")))
1973 "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph\n")))
1975 (ert-deftest test-org-element
/center-block-interpreter
()
1976 "Test center block interpreter."
1978 (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
1979 "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
1981 (ert-deftest test-org-element
/drawer-interpreter
()
1982 "Test drawer interpreter."
1984 (equal (let ((org-drawers '("TEST")))
1985 (org-test-parse-and-interpret ":TEST:\nTest\n:END:"))
1986 ":TEST:\nTest\n:END:\n")))
1988 (ert-deftest test-org-element
/dynamic-block-interpreter
()
1989 "Test dynamic block interpreter."
1991 (equal (org-test-parse-and-interpret
1992 "#+BEGIN: myblock :parameter value1\nTest\n#+END:")
1993 "#+BEGIN: myblock :parameter value1\nTest\n#+END:\n")))
1995 (ert-deftest test-org-element
/footnote-definition-interpreter
()
1996 "Test footnote definition interpreter."
1997 (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")))
1999 (ert-deftest test-org-element
/headline-interpreter
()
2000 "Test headline and section interpreters."
2001 ;; 1. Standard test.
2002 (should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
2003 ;; 2. With TODO keywords.
2005 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2006 (org-test-parse-and-interpret "* TODO Headline"))
2007 "* TODO Headline\n"))
2010 ;; 3.1. ... and a positive `org-tags-column' value.
2012 (equal (let ((org-tags-column 20))
2013 (org-test-parse-and-interpret "* Headline :tag:"))
2014 "* Headline :tag:\n"))
2015 ;; 3.2. ... and a negative `org-tags-column' value.
2017 (equal (let ((org-tags-column -
20))
2018 (org-test-parse-and-interpret "* Headline :tag:"))
2019 "* Headline :tag:\n"))
2020 ;; 3.3. ... and a null `org-tags-column' value.
2022 (equal (let ((org-tags-column 0))
2023 (org-test-parse-and-interpret "* Headline :tag:"))
2024 "* Headline :tag:\n"))
2025 ;; 4. With priority cookie.
2027 (equal (org-test-parse-and-interpret "* [#B] Headline")
2028 "* [#B] Headline\n"))
2029 ;; 5. With comment keyword.
2031 (equal (let ((org-comment-string "COMMENT"))
2032 (org-test-parse-and-interpret "* COMMENT Headline"))
2033 "* COMMENT Headline\n"))
2034 ;; 6. With quote section.
2036 (equal (let ((org-quote-string "QUOTE"))
2037 (org-test-parse-and-interpret "* QUOTE Headline"))
2038 "* QUOTE Headline\n"))
2039 ;; 7. Keep same number of blank lines before body.
2041 (equal (org-test-parse-and-interpret
2042 "* Headline\n\n\nText after two blank lines.")
2043 "* Headline\n\n\nText after two blank lines.\n")))
2045 (ert-deftest test-org-element
/inlinetask-interpreter
()
2046 "Test inlinetask interpretation."
2047 (when (featurep 'org-inlinetask
)
2048 (let ((org-inlinetask-min-level 15))
2049 ;; 1. Regular inlinetask.
2050 (should (equal (org-test-parse-and-interpret
2051 "*************** Task\nTest\n*************** END")
2052 "*************** Task\nTest\n*************** END\n"))
2053 ;; 2. Degenerate inlinetask.
2054 (should (equal (org-test-parse-and-interpret "*************** Task")
2055 "*************** Task\n"))
2056 ;; 3. Prefer degenerate form when there are no contents.
2057 (should (equal (org-test-parse-and-interpret
2058 "*************** Task\n*************** END")
2059 "*************** Task\n"))
2060 ;; 4. With TODO keywords.
2062 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2063 (org-test-parse-and-interpret "*************** TODO Task"))
2064 "*************** TODO Task\n"))
2067 ;; 5.1. ... and a positive `org-tags-column' value.
2069 (equal (let ((org-tags-column 30))
2070 (org-test-parse-and-interpret "*************** Task :tag:"))
2071 "*************** Task :tag:\n"))
2072 ;; 5.2. ... and a negative `org-tags-column' value.
2074 (equal (let ((org-tags-column -
30))
2075 (org-test-parse-and-interpret "*************** Task :tag:"))
2076 "*************** Task :tag:\n"))
2077 ;; 5.3. ... and a null `org-tags-column' value.
2079 (equal (let ((org-tags-column 0))
2080 (org-test-parse-and-interpret "*************** Task :tag:"))
2081 "*************** Task :tag:\n"))
2082 ;; 6. With priority cookie.
2084 (equal (org-test-parse-and-interpret "*************** [#B] Task")
2085 "*************** [#B] Task\n")))))
2087 (ert-deftest test-org-element
/plain-list-interpreter
()
2088 "Test plain-list and item interpreters."
2089 (let ((org-list-two-spaces-after-bullet-regexp nil
))
2091 (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
2092 ;; Description list.
2094 (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
2097 (equal (let ((org-plain-list-ordered-item-terminator t
))
2098 (org-test-parse-and-interpret "1. Item"))
2101 (equal (let ((org-plain-list-ordered-item-terminator ?\
)))
2102 (org-test-parse-and-interpret "1) Item"))
2104 ;; Ordered list with counter.
2106 (equal (let ((org-plain-list-ordered-item-terminator t
))
2107 (org-test-parse-and-interpret "1. [@5] Item"))
2109 ;; List with check-boxes.
2111 (equal (org-test-parse-and-interpret
2112 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
2113 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
2114 ;; Item not starting with a paragraph.
2116 (equal (org-test-parse-and-interpret "-\n | a | b |")
2117 "- \n | a | b |\n"))
2118 ;; Special case: correctly handle "*" bullets.
2119 (should (org-test-parse-and-interpret " * item"))
2120 ;; Special case: correctly handle empty items.
2121 (should (org-test-parse-and-interpret "-"))))
2123 (ert-deftest test-org-element
/quote-block-interpreter
()
2124 "Test quote block interpreter."
2125 (should (equal (org-test-parse-and-interpret
2126 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
2127 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
2129 (ert-deftest test-org-element
/special-block-interpreter
()
2130 "Test special block interpreter."
2131 (should (equal (org-test-parse-and-interpret
2132 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
2133 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
2135 (ert-deftest test-org-element
/babel-call-interpreter
()
2136 "Test babel call interpreter."
2137 ;; 1. Without argument.
2138 (should (equal (org-test-parse-and-interpret "#+CALL: test()")
2139 "#+CALL: test()\n"))
2140 ;; 2. With argument.
2141 (should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
2142 "#+CALL: test(x=2)\n"))
2143 ;; 3. With header arguments.
2144 (should (equal (org-test-parse-and-interpret
2145 "#+CALL: test[:results output]()[:results html]")
2146 "#+CALL: test[:results output]()[:results html]\n")))
2148 (ert-deftest test-org-element
/clock-interpreter
()
2149 "Test clock interpreter."
2152 (equal (let ((org-clock-string "CLOCK:"))
2153 (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]"))
2154 "CLOCK: [2012-01-01 sun. 00:01]\n"))
2158 (let ((org-clock-string "CLOCK:"))
2159 (org-test-parse-and-interpret "
2160 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))
2161 "CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01\n")))
2163 (ert-deftest test-org-element
/comment-interpreter
()
2164 "Test comment interpreter."
2166 (should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
2168 (should (equal (org-test-parse-and-interpret " # Comment")
2170 ;; Preserve indentation.
2171 (should (equal (org-test-parse-and-interpret " # No blank\n# One blank")
2172 "# No blank\n# One blank\n")))
2174 (ert-deftest test-org-element
/comment-block-interpreter
()
2175 "Test comment block interpreter."
2176 (should (equal (org-test-parse-and-interpret
2177 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
2178 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n")))
2180 (ert-deftest test-org-element
/diary-sexp
()
2181 "Test diary-sexp interpreter."
2184 (org-test-parse-and-interpret
2185 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old")
2186 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old\n")))
2188 (ert-deftest test-org-element
/example-block-interpreter
()
2189 "Test example block interpreter."
2190 ;; Without switches.
2191 (should (equal (org-test-parse-and-interpret
2192 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE")
2193 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"))
2196 (equal (org-test-parse-and-interpret
2197 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
2198 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n"))
2199 ;; Preserve code escaping.
2201 (equal (org-test-parse-and-interpret
2202 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE")
2203 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE\n")))
2205 (ert-deftest test-org-element
/export-block-interpreter
()
2206 "Test export block interpreter."
2207 (should (equal (org-test-parse-and-interpret
2208 "#+BEGIN_HTML\nTest\n#+END_HTML")
2209 "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
2211 (ert-deftest test-org-element
/fixed-width-interpreter
()
2212 "Test fixed width interpreter."
2214 (should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
2215 ;; Preserve indentation.
2216 (should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
2217 ": 2 blanks\n: 1 blank\n"))
2218 ;; Remove last newline character
2220 (equal (org-element-fixed-width-interpreter
2221 '(fixed-width (:value
"Test\n")) nil
)
2224 (equal (org-element-fixed-width-interpreter
2225 '(fixed-width (:value
"Test")) nil
)
2227 ;; Handle empty string.
2229 (equal (org-element-fixed-width-interpreter
2230 '(fixed-width (:value
"")) nil
)
2232 ;; Handle nil value.
2234 (org-element-fixed-width-interpreter
2235 '(fixed-width (:value nil
)) nil
)))
2237 (ert-deftest test-org-element
/horizontal-rule-interpreter
()
2238 "Test horizontal rule interpreter."
2239 (should (equal (org-test-parse-and-interpret "-------") "-----\n")))
2241 (ert-deftest test-org-element
/keyword-interpreter
()
2242 "Test keyword interpreter."
2243 (should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
2244 "#+KEYWORD: value\n")))
2246 (ert-deftest test-org-element
/latex-environment-interpreter
()
2247 "Test latex environment interpreter."
2248 (should (equal (org-test-parse-and-interpret
2249 "\\begin{equation}\n1+1=2\n\\end{equation}")
2250 "\\begin{equation}\n1+1=2\n\\end{equation}\n"))
2251 (should (equal (org-test-parse-and-interpret
2252 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}")
2253 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}\n")))
2255 (ert-deftest test-org-element
/planning-interpreter
()
2256 "Test planning interpreter."
2257 (let ((org-closed-string "CLOSED:")
2258 (org-deadline-string "DEADLINE:")
2259 (org-scheduled-string "SCHEDULED:"))
2262 (org-test-parse-and-interpret
2264 DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]")
2266 DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]\n"))))
2268 (ert-deftest test-org-element
/property-drawer-interpreter
()
2269 "Test property drawer interpreter."
2270 (should (equal (let ((org-property-format "%-10s %s"))
2271 (org-test-parse-and-interpret
2272 ":PROPERTIES:\n:prop: value\n:END:"))
2273 ":PROPERTIES:\n:prop: value\n:END:\n")))
2275 (ert-deftest test-org-element
/src-block-interpreter
()
2276 "Test src block interpreter."
2279 (equal (let ((org-edit-src-content-indentation 2))
2280 (org-test-parse-and-interpret
2281 "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC"))
2282 "#+BEGIN_SRC emacs-lisp :results silent\n (+ 1 1)\n#+END_SRC\n"))
2285 (equal (let ((org-edit-src-content-indentation 2))
2286 (org-test-parse-and-interpret
2287 "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC"))
2288 "#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
2289 ;; Preserve code escaping.
2291 (equal (let ((org-edit-src-content-indentation 2))
2292 (org-test-parse-and-interpret
2293 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC"))
2294 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n"))
2295 ;; Do not apply `org-edit-src-content-indentation' when preserving
2298 (equal (let ((org-edit-src-content-indentation 2)
2299 (org-src-preserve-indentation t
))
2300 (org-test-parse-and-interpret
2301 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"))
2302 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n"))
2304 (equal (let ((org-edit-src-content-indentation 2)
2305 (org-src-preserve-indentation nil
))
2306 (org-test-parse-and-interpret
2307 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"))
2308 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC\n")))
2310 (ert-deftest test-org-element
/table-interpreter
()
2311 "Test table, table-row and table-cell interpreters."
2313 (should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
2314 "| a | b |\n| c | d |\n"))
2315 ;; 2. With horizontal rules.
2316 (should (equal (org-test-parse-and-interpret
2317 "| a | b |\n|---+---|\n| c | d |")
2318 "| a | b |\n|---+---|\n| c | d |\n"))
2319 ;; 3. With meta-data.
2320 (should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
2321 "| / | < | > |\n| * | 1 | 2 |\n"))
2322 ;; 4. With a formula.
2324 (equal (org-test-parse-and-interpret
2325 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)")
2326 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)\n"))
2327 ;; 5. With multiple formulas.
2329 (equal (org-test-parse-and-interpret
2330 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2")
2331 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n")))
2333 (ert-deftest test-org-element
/timestamp-interpreter
()
2334 "Test timestamp interpreter."
2336 (should (equal (org-test-parse-and-interpret "<2012-03-29 thu. 16:40>")
2337 "<2012-03-29 thu. 16:40>\n"))
2339 (string-match "<2012-03-29 .* 16:40>"
2340 (org-element-timestamp-interpreter
2342 (:type active
:year-start
2012 :month-start
3 :day-start
29
2343 :hour-start
16 :minute-start
40)) nil
)))
2345 (should (equal (org-test-parse-and-interpret "[2012-03-29 thu. 16:40]")
2346 "[2012-03-29 thu. 16:40]\n"))
2349 "\\[2012-03-29 .* 16:40\\]"
2350 (org-element-timestamp-interpreter
2352 (:type inactive
:year-start
2012 :month-start
3 :day-start
29
2353 :hour-start
16 :minute-start
40)) nil
)))
2355 (should (equal (org-test-parse-and-interpret
2356 "<2012-03-29 thu. 16:40>--<2012-03-29 thu. 16:41>")
2357 "<2012-03-29 thu. 16:40>--<2012-03-29 thu. 16:41>\n"))
2360 "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2361 (org-element-timestamp-interpreter
2363 (:type active-range
:year-start
2012 :month-start
3 :day-start
29
2364 :hour-start
16 :minute-start
40 :year-end
2012 :month-end
3
2365 :day-end
29 :hour-end
16 :minute-end
41)) nil
)))
2367 (should (equal (org-test-parse-and-interpret
2368 "[2012-03-29 thu. 16:40]--[2012-03-29 thu. 16:41]")
2369 "[2012-03-29 thu. 16:40]--[2012-03-29 thu. 16:41]\n"))
2372 "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2373 (org-element-timestamp-interpreter
2375 (:type inactive-range
:year-start
2012 :month-start
3 :day-start
29
2376 :hour-start
16 :minute-start
40 :year-end
2012 :month-end
3
2377 :day-end
29 :hour-end
16 :minute-end
41)) nil
)))
2379 (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
2380 "<%%diary-float t 4 2>\n"))
2381 ;; Timestamp with repeater interval, with delay, with both.
2382 (should (equal (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")
2383 "<2012-03-29 thu. +1y>\n"))
2386 "<2012-03-29 .* \\+1y>"
2387 (org-element-timestamp-interpreter
2389 (:type active
:year-start
2012 :month-start
3 :day-start
29
2390 :repeater-type cumulate
:repeater-value
1 :repeater-unit year
))
2394 "<2012-03-29 .* -1y>"
2395 (org-element-timestamp-interpreter
2397 (:type active
:year-start
2012 :month-start
3 :day-start
29
2398 :warning-type all
:warning-value
1 :warning-unit year
))
2402 "<2012-03-29 .* \\+1y -1y>"
2403 (org-element-timestamp-interpreter
2405 (:type active
:year-start
2012 :month-start
3 :day-start
29
2406 :warning-type all
:warning-value
1 :warning-unit year
2407 :repeater-type cumulate
:repeater-value
1 :repeater-unit year
))
2409 ;; Timestamp range with repeater interval
2410 (should (equal (org-test-parse-and-interpret
2411 "<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>")
2412 "<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>\n"))
2415 "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2416 (org-element-timestamp-interpreter
2418 (:type active-range
:year-start
2012 :month-start
3 :day-start
29
2419 :year-end
2012 :month-end
3 :day-end
30 :repeater-type cumulate
2420 :repeater-value
1 :repeater-unit year
))
2423 (ert-deftest test-org-element
/verse-block-interpreter
()
2424 "Test verse block interpretation."
2426 (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
2427 "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
2429 (ert-deftest test-org-element
/bold-interpreter
()
2430 "Test bold interpreter."
2431 (should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
2433 (ert-deftest test-org-element
/code-interpreter
()
2434 "Test code interpreter."
2435 (should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
2437 (ert-deftest test-org-element
/entity-interpreter
()
2438 "Test entity interpreter."
2439 ;; 1. Without brackets.
2441 (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
2442 ;; 2. With brackets.
2444 (equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
2446 (ert-deftest test-org-element
/export-snippet-interpreter
()
2447 "Test export snippet interpreter."
2448 (should (equal (org-test-parse-and-interpret "@@back-end:contents@@")
2449 "@@back-end:contents@@\n")))
2451 (ert-deftest test-org-element
/footnote-reference-interpreter
()
2452 "Test footnote reference interpreter."
2453 ;; 1. Regular reference.
2454 (should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
2455 ;; 2. Normalized reference.
2456 (should (equal (org-test-parse-and-interpret "Text[1]") "Text[1]\n"))
2457 ;; 3. Named reference.
2458 (should (equal (org-test-parse-and-interpret "Text[fn:label]")
2459 "Text[fn:label]\n"))
2460 ;; 4. Inline reference.
2461 (should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
2462 "Text[fn:label:def]\n"))
2463 ;; 5. Anonymous reference.
2464 (should (equal (org-test-parse-and-interpret "Text[fn::def]")
2465 "Text[fn::def]\n")))
2467 (ert-deftest test-org-element
/inline-babel-call-interpreter
()
2468 "Test inline babel call interpreter."
2469 ;; 1. Without arguments.
2470 (should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
2471 ;; 2. With arguments.
2472 (should (equal (org-test-parse-and-interpret "call_test(x=2)")
2473 "call_test(x=2)\n"))
2474 ;; 3. With header arguments.
2475 (should (equal (org-test-parse-and-interpret
2476 "call_test[:results output]()[:results html]")
2477 "call_test[:results output]()[:results html]\n")))
2479 (ert-deftest test-org-element
/inline-src-block-interpreter
()
2480 "Test inline src block interpreter."
2481 ;; 1. Without header argument.
2482 (should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
2483 "src_emacs-lisp{(+ 1 1)}\n"))
2484 ;; 2. With header arguments.
2485 (should (equal (org-test-parse-and-interpret
2486 "src_emacs-lisp[:results silent]{(+ 1 1)}")
2487 "src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
2489 (ert-deftest test-org-element
/italic-interpreter
()
2490 "Test italic interpreter."
2491 (should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
2493 (ert-deftest test-org-element
/latex-fragment-interpreter
()
2494 "Test latex fragment interpreter."
2495 (let ((org-latex-regexps
2496 '(("begin" "^[ ]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^