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 (unless (featurep 'org-element
)
21 (signal 'missing-test-dependency
"org-element"))
23 (defun org-test-parse-and-interpret (text)
24 "Parse TEXT as Org syntax and interpret it.
25 Return interpreted string."
29 (org-element-interpret-data (org-element-parse-buffer))))
33 ;;; Test `org-element-map'
35 (ert-deftest test-org-element
/map
()
36 "Test `org-element-map'."
37 ;; Can map to `plain-text' objects.
40 (org-test-with-temp-text "Some text \alpha
46 (org-element-parse-buffer) 'plain-text
47 (lambda (s) (when (string-match "text" s
) (incf count
))))
49 ;; Applies to secondary strings
51 (org-element-map '("some " (bold nil
"bold") "text") 'bold
'identity
))
52 ;; Enter secondary strings before entering contents.
58 (org-test-with-temp-text "* Some \\alpha headline\n\\beta entity."
59 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
)))))
60 ;; Apply NO-RECURSION argument.
62 (org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
64 (org-element-parse-buffer) 'entity
'identity nil nil
'center-block
))))
70 (ert-deftest test-org-element
/put-property
()
71 "Test `org-element-put-property' specifications."
72 (org-test-with-temp-text "* Headline\n *a*"
73 (let ((tree (org-element-parse-buffer)))
74 (org-element-put-property
75 (org-element-map tree
'bold
'identity nil t
) :test
1)
76 (should (org-element-property
77 :test
(org-element-map tree
'bold
'identity nil t
))))))
79 (ert-deftest test-org-element
/set-contents
()
80 "Test `org-element-set-contents' specifications."
81 ;; Accept multiple entries.
83 (equal '("b" (italic nil
"a"))
84 (org-test-with-temp-text "* Headline\n *a*"
85 (let ((tree (org-element-parse-buffer)))
86 (org-element-set-contents
87 (org-element-map tree
'bold
'identity nil t
) "b" '(italic nil
"a"))
89 (org-element-map tree
'bold
'identity nil t
))))))
90 ;; Accept atoms and elements.
93 (org-test-with-temp-text "* Headline\n *a*"
94 (let ((tree (org-element-parse-buffer)))
95 (org-element-set-contents
96 (org-element-map tree
'bold
'identity nil t
) "b")
98 (org-element-map tree
'bold
'identity nil t
))))))
100 (equal '((italic nil
"b"))
101 (org-test-with-temp-text "* Headline\n *a*"
102 (let ((tree (org-element-parse-buffer)))
103 (org-element-set-contents
104 (org-element-map tree
'bold
'identity nil t
) '(italic nil
"b"))
105 (org-element-contents
106 (org-element-map tree
'bold
'identity nil t
))))))
107 ;; Allow nil contents.
109 (org-test-with-temp-text "* Headline\n *a*"
110 (let ((tree (org-element-parse-buffer)))
111 (org-element-set-contents (org-element-map tree
'bold
'identity nil t
))
112 (org-element-contents (org-element-map tree
'bold
'identity nil t
))))))
114 (ert-deftest test-org-element
/set-element
()
115 "Test `org-element-set-element' specifications."
116 (org-test-with-temp-text "* Headline\n*a*"
117 (let ((tree (org-element-parse-buffer)))
118 (org-element-set-element
119 (org-element-map tree
'bold
'identity nil t
)
121 ;; Check if object is correctly replaced.
122 (should (org-element-map tree
'italic
'identity
))
123 (should-not (org-element-map tree
'bold
'identity
))
124 ;; Check if new object's parent is correctly set.
127 (org-element-property :parent
128 (org-element-map tree
'italic
'identity nil t
))
129 (org-element-map tree
'paragraph
'identity nil t
))))))
131 (ert-deftest test-org-element
/adopt-elements
()
132 "Test `org-element-adopt-elements' specifications."
135 (equal '(plain-text italic
)
136 (org-test-with-temp-text "* Headline\n *a*"
137 (let ((tree (org-element-parse-buffer)))
138 (org-element-adopt-elements
139 (org-element-map tree
'bold
'identity nil t
) '(italic nil
"a"))
140 (mapcar (lambda (blob) (org-element-type blob
))
141 (org-element-contents
142 (org-element-map tree
'bold
'identity nil t
)))))))
146 (org-test-with-temp-text "* Headline\n *a*"
147 (let ((tree (org-element-parse-buffer)))
148 (org-element-adopt-elements
149 (org-element-map tree
'bold
'identity nil t
) "b")
150 (org-element-contents
151 (org-element-map tree
'bold
'identity nil t
)))))))
159 (ert-deftest test-org-element
/babel-call-parser
()
160 "Test `babel-call' parsing."
163 (org-test-with-temp-text "#+CALL: test()"
164 (org-element-map (org-element-parse-buffer) 'babel-call
'identity
)))
167 (org-test-with-temp-text "#+call: test()"
168 (org-element-map (org-element-parse-buffer) 'babel-call
'identity
))))
173 (ert-deftest test-org-element
/bold-parser
()
174 "Test `bold' parser."
177 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
178 (org-test-with-temp-text "*bold*"
179 (org-element-map (org-element-parse-buffer) 'bold
'identity nil t
))))
180 ;; Multi-line markup.
183 (org-element-contents
184 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
185 (org-test-with-temp-text "*first line\nsecond line*"
186 (org-element-map (org-element-parse-buffer) 'bold
'identity nil t
))))
187 '("first line\nsecond line"))))
192 (ert-deftest test-org-element
/center-block-parser
()
193 "Test `center-block' parser."
196 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
197 (org-element-map (org-element-parse-buffer) 'center-block
'identity
)))
200 (org-test-with-temp-text "#+begin_center\nText\n#+end_center"
201 (org-element-map (org-element-parse-buffer) 'center-block
'identity
)))
202 ;; Test folded block.
203 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
206 (org-element-property
209 (org-element-parse-buffer) 'center-block
'identity nil t
))))
210 ;; Ignore incomplete block.
212 (org-test-with-temp-text "#+BEGIN_CENTER"
214 (org-element-parse-buffer) 'center-block
'identity nil t
))))
219 (ert-deftest test-org-element
/clock-parser
()
220 "Test `clock' parser."
222 (let* ((org-clock-string "CLOCK:")
223 (clock (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
225 (org-element-parse-buffer) 'clock
'identity nil t
))))
226 (should (eq (org-element-property :status clock
) 'running
))
227 (should (equal (org-element-property :value clock
)
228 "[2012-01-01 sun. 00:01]"))
229 (should-not (org-element-property :time clock
)))
231 (let* ((org-clock-string "CLOCK:")
232 (clock (org-test-with-temp-text "
233 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
235 (org-element-parse-buffer) 'clock
'identity nil t
))))
236 (should (eq (org-element-property :status clock
) 'closed
))
237 (should (equal (org-element-property :value clock
)
238 "[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"))
239 (should (equal (org-element-property :time clock
) "0:01"))))
244 (ert-deftest test-org-element
/code-parser
()
245 "Test `code' parser."
248 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
249 (org-test-with-temp-text "~code~"
250 (org-element-map (org-element-parse-buffer) 'code
'identity
))))
251 ;; Multi-line markup.
254 (org-element-property
256 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
257 (org-test-with-temp-text "~first line\nsecond line~"
259 (org-element-parse-buffer) 'code
'identity nil t
))))
260 "first line\nsecond line")))
265 (ert-deftest test-org-element
/comment-parser
()
266 "Test `comment' parser."
269 (org-test-with-temp-text "# Comment"
270 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
273 (org-test-with-temp-text " # Comment"
274 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
275 ;; Preserve indentation.
278 (org-element-property
280 (org-test-with-temp-text "# No blank\n# One blank"
281 (org-element-map (org-element-parse-buffer) 'comment
'identity nil t
)))
282 "No blank\n One blank"))
283 ;; Comment with blank lines.
286 (org-element-property
288 (org-test-with-temp-text "# First part\n# \n#\n# Second part"
289 (org-element-map (org-element-parse-buffer) 'comment
'identity nil t
)))
290 "First part\n\n\nSecond part"))
291 ;; Do not mix comments and keywords.
294 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
295 (length (org-element-map
296 (org-element-parse-buffer) 'comment
'identity
)))))
299 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
300 (org-element-property
303 (org-element-parse-buffer) 'comment
'identity nil t
))))))
308 (ert-deftest test-org-element
/comment-block-parser
()
309 "Test `comment-block' parser."
312 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
314 (org-element-parse-buffer) 'comment-block
'identity
)))
317 (org-test-with-temp-text "#+begin_comment\nText\n#+end_comment"
319 (org-element-parse-buffer) 'comment-block
'identity
)))
320 ;; Test folded block.
321 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
324 (org-element-property
327 (org-element-parse-buffer) 'comment-block
'identity nil t
))))
328 ;; Ignore incomplete block.
330 (org-test-with-temp-text "#+BEGIN_COMMENT"
332 (org-element-parse-buffer) 'comment-block
'identity nil t
))))
337 (ert-deftest test-org-element
/drawer-parser
()
338 "Test `drawer' parser."
341 (let ((org-drawers '("TEST")))
342 (org-test-with-temp-text ":TEST:\nText\n:END:"
343 (org-element-map (org-element-parse-buffer) 'drawer
'identity
))))
344 ;; Do not mix regular drawers and property drawers.
346 (let ((org-drawers '("PROPERTIES")))
347 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
349 (org-element-parse-buffer) 'drawer
'identity nil t
))))
350 ;; Ignore incomplete drawer.
352 (let ((org-drawers '("TEST")))
353 (org-test-with-temp-text ":TEST:"
355 (org-element-parse-buffer) 'drawer
'identity nil t
)))))
360 (ert-deftest test-org-element
/dynamic-block-parser
()
361 "Test `dynamic-block' parser."
364 (org-test-with-temp-text
365 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
366 (org-element-map (org-element-parse-buffer) 'dynamic-block
'identity
)))
368 (org-test-with-temp-text
369 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
372 (org-element-property
375 (org-element-parse-buffer) 'dynamic-block
'identity nil t
))))
378 (org-test-with-temp-text
379 "#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
380 (org-element-map (org-element-parse-buffer) 'dynamic-block
'identity
)))
381 ;; Ignore incomplete block.
383 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
385 (org-element-parse-buffer) 'dynamic-block
'identity nil t
))))
390 (ert-deftest test-org-element
/entity-parser
()
391 "Test `entity' parser."
394 (org-test-with-temp-text "\\sin"
395 (org-element-map (org-element-parse-buffer) 'entity
'identity
)))
398 (org-element-property
400 (org-test-with-temp-text "\\alpha{}text"
401 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
))))
402 ;; User-defined entity.
405 (org-element-property
407 (let ((org-entities-user
408 '(("test" "test" nil
"test" "test" "test" "test"))))
409 (org-test-with-temp-text "\\test"
410 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
))))
416 (ert-deftest test-org-element
/example-block-parser
()
417 "Test `example-block' parser."
420 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
421 (org-element-map (org-element-parse-buffer) 'example-block
'identity
)))
422 ;; Test folded block.
423 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
426 (org-element-property
429 (org-element-parse-buffer) 'example-block
'identity nil t
))))
430 ;; Ignore incomplete block.
432 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
434 (org-element-parse-buffer) 'example-block
'identity nil t
))))
436 (ert-deftest test-org-element
/block-switches
()
437 "Test `example-block' and `src-block' switches parsing."
438 (let ((org-coderef-label-format "(ref:%s)"))
439 ;; 1. Test "-i" switch.
440 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
442 (org-element-property :preserve-indent
(org-element-at-point))))
443 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
444 (should (org-element-property :preserve-indent
(org-element-at-point))))
445 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
447 (org-element-property :preserve-indent
(org-element-at-point))))
448 (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
449 (should (org-element-property :preserve-indent
(org-element-at-point))))
450 ;; 2. "-n -r -k" combination should number lines, retain labels but
451 ;; not use them in coderefs.
452 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
453 (let ((element (org-element-at-point)))
454 (should (and (org-element-property :number-lines element
)
455 (org-element-property :retain-labels element
)
456 (not (org-element-property :use-labels element
))))))
457 (org-test-with-temp-text
458 "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
459 (let ((element (org-element-at-point)))
460 (should (and (org-element-property :number-lines element
)
461 (org-element-property :retain-labels element
)
462 (not (org-element-property :use-labels element
))))))
463 ;; 3. "-n -r" combination should number-lines remove labels and not
464 ;; use them in coderefs.
465 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
466 (let ((element (org-element-at-point)))
467 (should (and (org-element-property :number-lines element
)
468 (not (org-element-property :retain-labels element
))
469 (not (org-element-property :use-labels element
))))))
470 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
471 (let ((element (org-element-at-point)))
472 (should (and (org-element-property :number-lines element
)
473 (not (org-element-property :retain-labels element
))
474 (not (org-element-property :use-labels element
))))))
475 ;; 4. "-n" or "+n" should number lines, retain labels and use them
477 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
478 (let ((element (org-element-at-point)))
479 (should (and (org-element-property :number-lines element
)
480 (org-element-property :retain-labels element
)
481 (org-element-property :use-labels element
)))))
482 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
483 (let ((element (org-element-at-point)))
484 (should (and (org-element-property :number-lines element
)
485 (org-element-property :retain-labels element
)
486 (org-element-property :use-labels element
)))))
487 (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
488 (let ((element (org-element-at-point)))
489 (should (and (org-element-property :number-lines element
)
490 (org-element-property :retain-labels element
)
491 (org-element-property :use-labels element
)))))
492 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
493 (let ((element (org-element-at-point)))
494 (should (and (org-element-property :number-lines element
)
495 (org-element-property :retain-labels element
)
496 (org-element-property :use-labels element
)))))
497 ;; 5. No switch should not number lines, but retain labels and use
499 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
500 (let ((element (org-element-at-point)))
501 (should (and (not (org-element-property :number-lines element
))
502 (org-element-property :retain-labels element
)
503 (org-element-property :use-labels element
)))))
504 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
505 (let ((element (org-element-at-point)))
506 (should (and (not (org-element-property :number-lines element
))
507 (org-element-property :retain-labels element
)
508 (org-element-property :use-labels element
)))))
509 ;; 6. "-r" switch only: do not number lines, remove labels, and
510 ;; don't use labels in coderefs.
511 (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
512 (let ((element (org-element-at-point)))
513 (should (and (not (org-element-property :number-lines element
))
514 (not (org-element-property :retain-labels element
))
515 (not (org-element-property :use-labels element
))))))
516 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
517 (let ((element (org-element-at-point)))
518 (should (and (not (org-element-property :number-lines element
))
519 (not (org-element-property :retain-labels element
))
520 (not (org-element-property :use-labels element
))))))
521 ;; 7. Recognize coderefs with user-defined syntax.
522 (org-test-with-temp-text
523 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
524 (let ((element (org-element-at-point)))
526 (equal (org-element-property :label-fmt element
) "[ref:%s]"))))
527 (org-test-with-temp-text
528 "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
529 (let ((element (org-element-at-point)))
531 (equal (org-element-property :label-fmt element
) "[ref:%s]"))))))
536 (ert-deftest test-org-element
/export-block-parser
()
537 "Test `export-block' parser."
540 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
542 (let ((org-element-block-name-alist
543 '(("LATEX" . org-element-export-block-parser
))))
544 (org-element-parse-buffer))
545 'export-block
'identity
)))
546 ;; Test folded block.
547 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
550 (org-element-property
553 (let ((org-element-block-name-alist
554 '(("LATEX" . org-element-export-block-parser
))))
555 (org-element-parse-buffer))
556 'export-block
'identity nil t
))))
559 (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
561 (let ((org-element-block-name-alist
562 '(("LATEX" . org-element-export-block-parser
))))
563 (org-element-parse-buffer))
564 'export-block
'identity
)))
565 ;; Ignore incomplete block.
567 (org-test-with-temp-text "#+BEGIN_LATEX"
569 (let ((org-element-block-name-alist
570 '(("LATEX" . org-element-export-block-parser
))))
571 (org-element-parse-buffer))
572 'export-block
'identity nil t
))))
577 (ert-deftest test-org-element
/export-snippet-parser
()
578 "Test `export-snippet' parser."
581 '("back-end" .
"contents")
582 (org-test-with-temp-text "@@back-end:contents@@"
584 (org-element-parse-buffer) 'export-snippet
585 (lambda (snippet) (cons (org-element-property :back-end snippet
)
586 (org-element-property :value snippet
)))
592 (ert-deftest test-org-element
/fixed-width
()
593 "Test fixed-width area parsing."
594 ;; Preserve indentation.
596 (org-test-with-temp-text ": no blank\n: one blank"
597 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
598 ;; Fixed-width with empty lines.
600 (org-test-with-temp-text ": first part\n:\n: \n: second part"
601 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
602 ;; Parse indented fixed-width markers.
604 (org-test-with-temp-text "Text\n : no blank\n : one blank"
605 (org-element-map (org-element-parse-buffer) 'fixed-width
'identity
)))
606 ;; Distinguish fixed-width areas within a list and outside of it.
610 (org-test-with-temp-text "
613 : fixed-width outside"
615 (org-element-parse-buffer) 'fixed-width
'identity
))))))
618 ;;;; Footnote Definition
620 (ert-deftest test-org-element
/footnote-definition-parser
()
621 "Test `footnote-definition' parser."
623 (org-test-with-temp-text "[fn:1] Definition"
625 (org-element-parse-buffer) 'footnote-definition
'identity nil t
)))
626 ;; Footnote with more contents
629 (org-element-property
631 (org-test-with-temp-text "[fn:1] Definition\n| a | b |"
633 (org-element-parse-buffer)
634 'footnote-definition
'identity nil t
))))))
637 ;;;; Footnotes Reference.
639 (ert-deftest test-org-element
/footnote-reference-parser
()
640 "Test `footnote-reference' parser."
641 ;; 1. Parse a standard reference.
642 (org-test-with-temp-text "Text[fn:label]"
645 (org-element-parse-buffer) 'footnote-reference
'identity
)))
646 ;; 2. Parse a normalized reference.
647 (org-test-with-temp-text "Text[1]"
650 (org-element-parse-buffer) 'footnote-reference
'identity
)))
651 ;; 3. Parse an inline reference.
652 (org-test-with-temp-text "Text[fn:test:def]"
655 (org-element-parse-buffer) 'footnote-reference
'identity
)))
656 ;; 4. Parse an anonymous reference.
657 (org-test-with-temp-text "Text[fn::def]"
660 (org-element-parse-buffer) 'footnote-reference
'identity
)))
661 ;; 5. Parse nested footnotes.
662 (org-test-with-temp-text "Text[fn::def [fn:label]]"
667 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
668 ;; 6. Parse adjacent footnotes.
669 (org-test-with-temp-text "Text[fn:label1][fn:label2]"
674 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
675 ;; 7. Only properly closed footnotes are recognized as such.
676 (org-test-with-temp-text "Text[fn:label"
679 (org-element-parse-buffer) 'footnote-reference
'identity
))))
684 (ert-deftest test-org-element
/headline-quote-keyword
()
685 "Test QUOTE keyword recognition."
687 (org-test-with-temp-text "* Headline"
688 (let ((org-quote-string "QUOTE"))
689 (should-not (org-element-property :quotedp
(org-element-at-point)))))
690 ;; Standard position.
691 (org-test-with-temp-text "* QUOTE Headline"
692 (let ((org-quote-string "QUOTE"))
693 (let ((headline (org-element-at-point)))
694 (should (org-element-property :quotedp headline
))
695 ;; Test removal from raw value.
696 (should (equal (org-element-property :raw-value headline
) "Headline"))))
698 (let ((org-quote-string "Quote"))
699 (should-not (org-element-property :quotedp
(org-element-at-point)))))
700 ;; With another keyword.
701 (org-test-with-temp-text "* TODO QUOTE Headline"
702 (let ((org-quote-string "QUOTE")
703 (org-todo-keywords '((sequence "TODO" "DONE"))))
704 (should (org-element-property :quotedp
(org-element-at-point))))))
706 (ert-deftest test-org-element
/headline-comment-keyword
()
707 "Test COMMENT keyword recognition."
709 (org-test-with-temp-text "* Headline"
710 (let ((org-comment-string "COMMENT"))
711 (should-not (org-element-property :commentedp
(org-element-at-point)))))
712 ;; Standard position.
713 (org-test-with-temp-text "* COMMENT Headline"
714 (let ((org-comment-string "COMMENT"))
715 (let ((headline (org-element-at-point)))
716 (should (org-element-property :commentedp headline
))
717 ;; Test removal from raw value.
718 (should (equal (org-element-property :raw-value headline
) "Headline"))))
720 (let ((org-comment-string "Comment"))
721 (should-not (org-element-property :commentedp
(org-element-at-point)))))
722 ;; With another keyword.
723 (org-test-with-temp-text "* TODO COMMENT Headline"
724 (let ((org-comment-string "COMMENT")
725 (org-todo-keywords '((sequence "TODO" "DONE"))))
726 (should (org-element-property :commentedp
(org-element-at-point))))))
728 (ert-deftest test-org-element
/headline-archive-tag
()
729 "Test ARCHIVE tag recognition."
731 (org-test-with-temp-text "* Headline"
732 (let ((org-archive-tag "ARCHIVE"))
733 (should-not (org-element-property :archivedp
(org-element-at-point)))))
735 (org-test-with-temp-text "* Headline :ARCHIVE:"
736 (let ((org-archive-tag "ARCHIVE"))
737 (let ((headline (org-element-at-point)))
738 (should (org-element-property :archivedp headline
))
740 (should-not (org-element-property :tags headline
))))
741 (let ((org-archive-tag "Archive"))
742 (should-not (org-element-property :archivedp
(org-element-at-point)))))
744 (org-test-with-temp-text "* Headline :test:ARCHIVE:"
745 (let ((org-archive-tag "ARCHIVE"))
746 (let ((headline (org-element-at-point)))
747 (should (org-element-property :archivedp headline
))
749 (should (equal (org-element-property :tags headline
) '("test")))))))
754 (ert-deftest test-org-element
/horizontal-rule-parser
()
755 "Test `horizontal-rule' parser."
758 (org-test-with-temp-text "-----"
759 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
762 (org-test-with-temp-text " -----"
763 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
764 ;; Hyphen must be alone on the line.
766 (org-test-with-temp-text "-----wrong"
767 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
768 ;; 4 hyphens is too small.
770 (org-test-with-temp-text "----"
771 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
))))
774 ;;;; Inline Babel Call
776 (ert-deftest test-org-element
/inline-babel-call-parser
()
777 "Test `inline-babel-call' parser."
779 (org-test-with-temp-text "call_test()"
781 (org-element-parse-buffer) 'inline-babel-call
'identity
))))
784 ;;;; Inline Src Block
786 (ert-deftest test-org-element
/inline-src-block-parser
()
787 "Test `inline-src-block' parser."
789 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
790 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
))))
795 (ert-deftest test-org-element
/inlinetask-parser
()
796 "Test `inlinetask' parser."
797 (when (featurep 'org-inlinetask
)
798 (let ((org-inlinetask-min-level 15))
799 ;; 1. Regular inlinetask.
801 (org-test-with-temp-text
802 "*************** Task\nTest\n*************** END"
803 (org-element-map (org-element-parse-buffer) 'inlinetask
'identity
)))
804 ;; 2. Degenerate inlinetask.
806 (org-test-with-temp-text "*************** Task"
807 (org-element-map (org-element-parse-buffer) 'inlinetask
'identity
)))
812 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
813 (org-test-with-temp-text "*************** TODO Task"
814 (org-element-property
817 (org-element-parse-buffer) 'inlinetask
'identity nil t
))))))
822 (org-test-with-temp-text "
824 DEADLINE: <2012-03-29 thu.>"
825 (org-element-property
828 (org-element-parse-buffer) 'inlinetask
'identity nil t
)))))
833 (org-test-with-temp-text "
834 *************** [#A] Task"
835 (org-element-property
838 (org-element-parse-buffer) 'inlinetask
'identity nil t
)))))
843 (org-test-with-temp-text "
844 *************** Task :test:"
845 (org-element-property
848 (org-element-parse-buffer) 'inlinetask
'identity nil t
))))))))
853 (ert-deftest test-org-element
/italic-parser
()
854 "Test `italic' parser."
857 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
858 (org-test-with-temp-text "/italic/"
859 (org-element-map (org-element-parse-buffer) 'italic
'identity nil t
))))
860 ;; Multi-line markup.
863 (org-element-contents
864 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
865 (org-test-with-temp-text "/first line\nsecond line/"
866 (org-element-map (org-element-parse-buffer) 'italic
'identity nil t
))))
867 '("first line\nsecond line"))))
872 (ert-deftest test-org-element
/item-parser
()
873 "Test `item' parser."
876 (org-test-with-temp-text "- item"
877 (org-element-map (org-element-parse-buffer) 'item
'identity
)))
881 (org-element-property
883 (org-test-with-temp-text "6. [@6] item"
884 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
889 (org-element-property
891 (org-test-with-temp-text "- tag :: description"
892 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
893 ;; No tags in ordered lists.
895 (org-element-property
897 (org-test-with-temp-text "1. tag :: description"
898 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
))))
903 (org-test-with-temp-text "
908 (org-element-parse-buffer) 'item
909 (lambda (item) (org-element-property :checkbox item
))))))
911 (org-test-with-temp-text "* Headline
916 (let ((org-cycle-include-plain-lists t
)) (org-cycle))
918 (org-element-property
920 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
925 (ert-deftest test-org-element
/keyword-parser
()
926 "Test `keyword' parser."
929 (org-test-with-temp-text "#+KEYWORD: value"
930 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
931 ;; Keywords are case-insensitive.
933 (org-test-with-temp-text "#+keyword: value"
934 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
935 ;; Affiliated keywords are not keywords.
937 (org-test-with-temp-text "#+NAME: value
939 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
940 ;; Do not mix keywords with Babel calls and dynamic blocks.
942 (org-test-with-temp-text "#+CALL: fun()"
943 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
945 (org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
946 (org-element-map (org-element-parse-buffer) 'keyword
'identity
))))
949 ;;;; Latex Environment
951 (ert-deftest test-org-element
/latex-environment-parser
()
952 "Test `latex-environment' parser."
954 (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
956 (org-element-parse-buffer) 'latex-environment
'identity
)))
957 ;; Allow nested environments.
965 (org-test-with-temp-text "
971 (org-element-property
974 (org-element-parse-buffer) 'latex-environment
'identity nil t
))))))
979 (ert-deftest test-org-element
/latex-fragment-parser
()
980 "Test `latex-fragment' parser."
981 (let ((org-latex-regexps
982 '(("begin" "^[ ]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^