1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012, 2013 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'ox
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defun org-test-default-backend ()
28 "Return a default export back-end.
29 This back-end simply returns parsed data as Org syntax."
30 (org-export-create-backend
31 :transcoders
(let (transcode-table)
32 (dolist (type (append org-element-all-elements
33 org-element-all-objects
)
37 (lambda (obj contents info
)
39 (intern (format "org-element-%s-interpreter"
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-allow-bind-keywords' set to t.
70 (org-test-with-temp-text "#+BIND: test-ox-var value"
71 (let ((org-export-allow-bind-keywords t
))
72 (org-export-get-environment)
73 (eq test-ox-var
'value
))))
74 ;; Test with `org-export-allow-bind-keywords' set to nil.
76 (org-test-with-temp-text "#+BIND: test-ox-var value"
77 (let ((org-export-allow-bind-keywords nil
))
78 (org-export-get-environment)
79 (boundp 'test-ox-var
))))
80 ;; BIND keywords are case-insensitive.
82 (org-test-with-temp-text "#+bind: test-ox-var value"
83 (let ((org-export-allow-bind-keywords t
))
84 (org-export-get-environment)
85 (eq test-ox-var
'value
))))
86 ;; Preserve order of BIND keywords.
88 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
89 (let ((org-export-allow-bind-keywords t
))
90 (org-export-get-environment)
92 ;; Read BIND keywords in setup files.
94 (org-test-with-temp-text
95 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
96 (let ((org-export-allow-bind-keywords t
))
97 (org-export-get-environment)
98 (eq variable
'value
))))
99 ;; Verify that bound variables are seen during export.
102 (org-test-with-temp-text "#+BIND: test-ox-var value"
103 (let ((org-export-allow-bind-keywords t
))
105 (org-export-create-backend
107 '((section .
(lambda (s c i
)
108 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
110 (ert-deftest test-org-export
/parse-option-keyword
()
111 "Test reading all standard #+OPTIONS: items."
114 (org-export--parse-option-keyword
115 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
116 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
119 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
120 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
121 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
122 :with-footnotes t
:with-inlinetasks nil
:with-priority t
123 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
124 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
125 :with-todo-keywords t
)))
126 ;; Test some special values.
129 (org-export--parse-option-keyword
130 "arch:headline creator:comment d:(\"TEST\")
131 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
134 :with-archived-trees headline
:with-creator comment
135 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
136 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
138 (ert-deftest test-org-export
/get-inbuffer-options
()
139 "Test reading all standard export keywords."
140 ;; Properties should follow buffer order.
143 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
144 (org-export--get-inbuffer-options))
145 '(:language
"fr" :creator
"Me" :email
"email")))
146 ;; Parse document keywords.
149 (org-test-with-temp-text "#+AUTHOR: Me"
150 (org-export--get-inbuffer-options))
152 ;; Test `space' behaviour.
155 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
156 (org-export--get-inbuffer-options))
157 '(:title
("Some title with spaces"))))
158 ;; Test `newline' behaviour.
161 (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
162 (org-export--get-inbuffer-options))
163 '(:description
"With\ntwo lines")))
164 ;; Test `split' behaviour.
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags
("a" "b"))))
170 ;; Options set through SETUPFILE.
173 (org-test-with-temp-text
174 (format "#+DESCRIPTION: l1
178 #+SETUPFILE: \"%s/examples/setupfile.org\"
184 (org-export--get-inbuffer-options))
185 '(:description
"l1\nl2\nl3":language
"fr" :select-tags
("a" "b" "c")
187 ;; More than one property can refer to the same buffer keyword.
189 (equal '(:k2
"value" :k1
"value")
190 (let ((backend (org-export-create-backend
191 :options
'((:k1
"KEYWORD")
193 (org-test-with-temp-text "#+KEYWORD: value"
194 (org-export--get-inbuffer-options backend
))))))
196 (ert-deftest test-org-export
/get-subtree-options
()
197 "Test setting options from headline's properties."
199 (org-test-with-temp-text "#+TITLE: Title
202 :EXPORT_TITLE: Subtree Title
206 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
207 '("Subtree Title"))))
211 (org-test-with-temp-text "#+OPTIONS: H:1
219 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
221 (org-test-with-temp-text "#+DATE: today
224 :EXPORT_DATE: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Properties with `split' behaviour are stored as a list of
234 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
237 :EXPORT_EXCLUDE_TAGS: a b
242 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
243 ;; Handle :PROPERTY+: syntax.
246 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
249 :EXPORT_EXCLUDE_TAGS: a
250 :EXPORT_EXCLUDE_TAGS+: b
255 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
256 ;; Export properties are case-insensitive.
257 (org-test-with-temp-text "* Headline
259 :EXPORT_Date: 29-03-2012
262 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
264 ;; Still grab correct options when section above is empty.
267 (org-test-with-temp-text "* H1\n** H11\n** H12"
268 (progn (forward-line 2)
269 (plist-get (org-export-get-environment nil t
) :title
))))))
271 (ert-deftest test-org-export
/set-title
()
272 "Test title setting."
273 ;; If no title if specified, use file name.
277 (org-test-with-temp-text-in-file "Test"
280 (org-export-create-backend
282 '((template .
(lambda (text info
)
283 (org-element-interpret-data
284 (plist-get info
:title
)))))))
285 (file-name-nondirectory
286 (file-name-sans-extension (buffer-file-name)))))))
287 ;; If no title is specified, and no file is associated to the
288 ;; buffer, use buffer's name.
292 (org-test-with-temp-text "Test"
295 (org-export-create-backend
297 '((template .
(lambda (text info
)
298 (org-element-interpret-data
299 (plist-get info
:title
)))))))
301 ;; If a title is specified, use it.
305 (org-test-with-temp-text-in-file "#+TITLE: Title\nTest"
308 (org-export-create-backend
310 '((template .
(lambda (text info
)
311 (org-element-interpret-data
312 (plist-get info
:title
))))))))))
313 ;; If an empty title is specified, do not set it.
317 (org-test-with-temp-text-in-file "#+TITLE:\nTest"
320 (org-export-create-backend
322 '((template .
(lambda (text info
)
323 (org-element-interpret-data
324 (plist-get info
:title
)))))))))))
326 (ert-deftest test-org-export
/handle-options
()
327 "Test if export options have an impact on output."
328 ;; Test exclude tags for headlines and inlinetasks.
331 (org-test-with-temp-text "* Head1 :noexp:"
332 (org-export-as (org-test-default-backend)
333 nil nil nil
'(:exclude-tags
("noexp"))))))
334 ;; Test include tags for headlines and inlinetasks.
336 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
337 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
338 (let ((org-tags-column 0))
339 (org-export-as (org-test-default-backend)
340 nil nil nil
'(:select-tags
("exp")))))))
341 ;; If there is an include tag, ignore the section before the first
344 (equal "* H1 :exp:\nBody\n"
345 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
346 (let ((org-tags-column 0))
347 (org-export-as (org-test-default-backend)
348 nil nil nil
'(:select-tags
("exp")))))))
350 (equal "* H1 :exp:\n"
351 (org-test-with-temp-text "* H1 :exp:\nBody"
352 (let ((org-tags-column 0))
353 (org-export-as (org-test-default-backend)
354 nil nil nil
'(:select-tags
("exp")))))))
355 ;; Test mixing include tags and exclude tags.
358 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
359 (org-test-with-temp-text "
361 ** Sub-Head1 :noexport:
364 ** Sub-Head1 :export:"
365 (org-export-as (org-test-default-backend) nil nil nil
366 '(:select-tags
("export") :exclude-tags
("noexport"))))))
370 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
371 (org-test-with-temp-text "* TODO Head1"
372 (org-export-as (org-test-default-backend)
373 nil nil nil
'(:with-tasks nil
))))))
375 (equal "* TODO Head1\n"
376 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
377 (org-test-with-temp-text "* TODO Head1"
378 (org-export-as (org-test-default-backend)
379 nil nil nil
'(:with-tasks t
))))))
383 (org-test-with-temp-text "* Head1 :archive:"
384 (let ((org-archive-tag "archive"))
385 (org-export-as (org-test-default-backend)
386 nil nil nil
'(:with-archived-trees nil
))))))
389 "\\* Head1[ \t]+:archive:"
390 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
391 (let ((org-archive-tag "archive"))
392 (org-export-as (org-test-default-backend) nil nil nil
393 '(:with-archived-trees headline
))))))
396 "\\`\\* Head1[ \t]+:archive:\n\\'"
397 (org-test-with-temp-text "* Head1 :archive:"
398 (let ((org-archive-tag "archive"))
399 (org-export-as (org-test-default-backend)
400 nil nil nil
'(:with-archived-trees t
))))))
403 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
404 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
405 (org-export-as (org-test-default-backend)
406 nil nil nil
'(:with-clocks t
)))))
409 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
410 (org-export-as (org-test-default-backend)
411 nil nil nil
'(:with-clocks nil
)))))
415 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
416 (org-export-as (org-test-default-backend)
417 nil nil nil
'(:with-drawers nil
)))))
419 (equal ":TEST:\ncontents\n:END:\n"
420 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
421 (org-export-as (org-test-default-backend)
422 nil nil nil
'(:with-drawers t
)))))
424 (equal ":FOO:\nkeep\n:END:\n"
425 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
426 (org-export-as (org-test-default-backend)
427 nil nil nil
'(:with-drawers
("FOO"))))))
429 (equal ":FOO:\nkeep\n:END:\n"
430 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
431 (org-export-as (org-test-default-backend)
432 nil nil nil
'(:with-drawers
(not "BAR"))))))
436 (org-test-with-temp-text ": A"
437 (org-export-as (org-test-default-backend) nil nil nil
438 '(:with-fixed-width t
)))))
441 (org-test-with-temp-text ": A"
442 (org-export-as (org-test-default-backend) nil nil nil
443 '(:with-fixed-width nil
)))))
447 (let ((org-footnote-section nil
))
448 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
449 (org-trim (org-export-as (org-test-default-backend)
450 nil nil nil
'(:with-footnotes nil
)))))))
452 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
453 (let ((org-footnote-section nil
))
454 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
455 (org-trim (org-export-as (org-test-default-backend)
456 nil nil nil
'(:with-footnotes t
)))))))
458 (when (featurep 'org-inlinetask
)
462 (let ((org-inlinetask-min-level 15))
463 (org-test-with-temp-text "*************** Task"
464 (org-export-as (org-test-default-backend)
465 nil nil nil
'(:with-inlinetasks nil
))))))
469 (let ((org-inlinetask-min-level 15))
470 (org-test-with-temp-text
471 "*************** Task\nContents\n*************** END"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-inlinetasks nil
)))))))
477 "CLOSED: \\[2012-04-29 .* 10:45\\]"
478 (let ((org-closed-string "CLOSED:"))
479 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
480 (org-export-as (org-test-default-backend)
481 nil nil nil
'(:with-planning t
))))))
484 (let ((org-closed-string "CLOSED:"))
485 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
486 (org-export-as (org-test-default-backend)
487 nil nil nil
'(:with-planning nil
))))))
491 (org-test-with-temp-text
492 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
493 (org-export-as (org-test-default-backend)
494 nil nil nil
'(:with-properties nil
)))))
496 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
497 (org-test-with-temp-text
498 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
499 (org-export-as (org-test-default-backend)
500 nil nil nil
'(:with-properties t
)))))
502 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
503 (org-test-with-temp-text
504 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
505 (org-export-as (org-test-default-backend)
506 nil nil nil
'(:with-properties
("B"))))))
507 ;; Statistics cookies.
510 (org-test-with-temp-text "[0/0]"
511 (org-export-as (org-test-default-backend)
512 nil nil nil
'(:with-statistics-cookies nil
)))))
516 (org-test-with-temp-text "| A |"
517 (org-export-as (org-test-default-backend) nil nil nil
518 '(:with-tables t
)))))
521 (org-test-with-temp-text "| A |"
522 (org-export-as (org-test-default-backend) nil nil nil
523 '(:with-tables nil
))))))
525 (ert-deftest test-org-export
/with-timestamps
()
526 "Test `org-export-with-timestamps' specifications."
530 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
531 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
532 (org-export-as (org-test-default-backend)
533 nil nil nil
'(:with-timestamps t
)))))
538 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
539 (org-export-as (org-test-default-backend)
540 nil nil nil
'(:with-timestamps nil
)))))
544 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
545 (org-test-with-temp-text
546 "<2012-03-29 Thu>[2012-03-29 Thu]
548 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
549 (org-export-as (org-test-default-backend)
550 nil nil nil
'(:with-timestamps active
)))))
554 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
555 (org-test-with-temp-text
556 "<2012-03-29 Thu>[2012-03-29 Thu]
558 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
559 (org-export-as (org-test-default-backend)
560 nil nil nil
'(:with-timestamps inactive
))))))
562 (ert-deftest test-org-export
/comment-tree
()
563 "Test if export process ignores commented trees."
566 (org-test-with-temp-text "* COMMENT Head1"
567 (org-export-as (org-test-default-backend))))))
569 (ert-deftest test-org-export
/uninterpreted
()
570 "Test handling of uninterpreted elements."
574 (org-test-with-temp-text "\\alpha"
576 (org-export-create-backend
577 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
578 (paragraph .
(lambda (p c i
) c
))
579 (section .
(lambda (s c i
) c
))))
580 nil nil nil
'(:with-entities t
)))))
583 (org-test-with-temp-text "\\alpha"
585 (org-export-create-backend
586 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
587 (paragraph .
(lambda (p c i
) c
))
588 (section .
(lambda (s c i
) c
))))
589 nil nil nil
'(:with-entities nil
)))))
593 (org-test-with-temp-text "*bold*"
595 (org-export-create-backend
596 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
597 (paragraph .
(lambda (p c i
) c
))
598 (section .
(lambda (s c i
) c
))))
599 nil nil nil
'(:with-emphasize t
)))))
602 (org-test-with-temp-text "*bold*"
604 (org-export-create-backend
605 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
606 (paragraph .
(lambda (p c i
) c
))
607 (section .
(lambda (s c i
) c
))))
608 nil nil nil
'(:with-emphasize nil
)))))
609 ;; LaTeX environment.
612 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
614 (org-export-create-backend
615 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
616 (section .
(lambda (s c i
) c
))))
617 nil nil nil
'(:with-latex t
)))))
619 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
620 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
622 (org-export-create-backend
623 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
624 (section .
(lambda (s c i
) c
))))
625 nil nil nil
'(:with-latex verbatim
)))))
629 (org-test-with-temp-text "$1$"
631 (org-export-create-backend
632 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
633 (paragraph .
(lambda (p c i
) c
))
634 (section .
(lambda (s c i
) c
))))
635 nil nil nil
'(:with-latex t
)))))
638 (org-test-with-temp-text "$1$"
640 (org-export-create-backend
641 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
642 (paragraph .
(lambda (p c i
) c
))
643 (section .
(lambda (s c i
) c
))))
644 nil nil nil
'(:with-latex verbatim
)))))
648 (org-test-with-temp-text "a_b"
650 (org-export-create-backend
651 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
652 (paragraph .
(lambda (p c i
) c
))
653 (section .
(lambda (s c i
) c
))))
654 nil nil nil
'(:with-sub-superscript t
)))))
657 (org-test-with-temp-text "a_b"
659 (org-export-create-backend
660 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
661 (paragraph .
(lambda (p c i
) c
))
662 (section .
(lambda (s c i
) c
))))
663 nil nil nil
'(:with-sub-superscript nil
)))))
666 (org-test-with-temp-text "a_b"
668 (org-export-create-backend
669 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
670 (paragraph .
(lambda (p c i
) c
))
671 (section .
(lambda (s c i
) c
))))
672 nil nil nil
'(:with-sub-superscript
{})))))
675 (org-test-with-temp-text "a_{b}"
677 (org-export-create-backend
678 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
679 (paragraph .
(lambda (p c i
) c
))
680 (section .
(lambda (s c i
) c
))))
681 nil nil nil
'(:with-sub-superscript
{})))))
682 ;; Also handle uninterpreted objects in title.
685 (org-test-with-temp-text "#+TITLE: a_b"
687 (org-export-create-backend
689 '((subscript .
(lambda (s c i
) "dummy"))
690 (template .
(lambda (c i
) (org-export-data
691 (plist-get i
:title
) i
)))
692 (section .
(lambda (s c i
) c
))))
693 nil nil nil
'(:with-sub-superscript nil
))))))
695 (ert-deftest test-org-export
/export-scope
()
696 "Test all export scopes."
697 (org-test-with-temp-text "
704 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
705 "text\n*** Head3\n"))
707 (goto-char (point-min))
710 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
713 (goto-char (point-min))
715 (transient-mark-mode 1)
716 (push-mark (point) t t
)
717 (goto-char (point-at-eol))
718 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
719 ;; Subtree with a code block calling another block outside.
722 (org-test-with-temp-text "
724 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
729 #+BEGIN_SRC emacs-lisp
733 (org-export-as (org-test-default-backend) 'subtree
))))
735 (let ((backend (org-test-default-backend)))
736 (setf (org-export-backend-transcoders backend
)
737 (cons '(template .
(lambda (body i
)
738 (format "BEGIN\n%sEND" body
)))
739 (org-export-backend-transcoders backend
)))
740 (org-test-with-temp-text "Text"
741 (should (equal (org-export-as backend nil nil
'body-only
)
743 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
745 (ert-deftest test-org-export
/output-file-name
()
746 "Test `org-export-output-file-name' specifications."
747 ;; Export from a file: name is built from original file name.
749 (org-test-with-temp-text-in-file "Test"
750 (equal (concat (file-name-as-directory ".")
751 (file-name-nondirectory
752 (file-name-sans-extension (buffer-file-name))))
753 (file-name-sans-extension (org-export-output-file-name ".ext")))))
754 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
756 (org-test-with-temp-text-in-file
757 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
758 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
759 ;; From a buffer not associated to a file, too.
761 (org-test-with-temp-text
762 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
763 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
764 ;; When provided name is absolute, preserve it.
766 (org-test-with-temp-text
767 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
768 (expand-file-name "test"))
769 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
770 ;; When PUB-DIR argument is provided, use it.
772 (org-test-with-temp-text-in-file "Test"
773 (equal (file-name-directory
774 (org-export-output-file-name ".ext" nil
"dir/"))
776 ;; When returned name would overwrite original file, add EXTENSION
779 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
780 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
782 (ert-deftest test-org-export
/expand-include
()
783 "Test file inclusion in an Org buffer."
784 ;; Error when file isn't specified.
786 (org-test-with-temp-text "#+INCLUDE: dummy.org"
787 (org-export-expand-include-keyword)))
788 ;; Full insertion with recursive inclusion.
789 (org-test-with-temp-text
790 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
791 (org-export-expand-include-keyword)
792 (should (equal (buffer-string)
793 "Small Org file with an include keyword.
795 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
801 ;; Localized insertion.
802 (org-test-with-temp-text
803 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
805 (org-export-expand-include-keyword)
806 (should (equal (buffer-string)
807 "Small Org file with an include keyword.\n")))
808 ;; Insertion with constraints on headlines level.
811 "* Top heading\n** Heading\nbody\n"
812 (org-test-with-temp-text
814 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
816 (org-export-expand-include-keyword)
820 "* Top heading\n* Heading\nbody\n"
821 (org-test-with-temp-text
823 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\" :minlevel 1"
825 (org-export-expand-include-keyword)
827 ;; Inclusion within an example block.
828 (org-test-with-temp-text
829 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
831 (org-export-expand-include-keyword)
835 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
836 ;; Inclusion within a src-block.
837 (org-test-with-temp-text
839 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
841 (org-export-expand-include-keyword)
842 (should (equal (buffer-string)
843 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
845 (ert-deftest test-org-export
/expand-macro
()
846 "Test macro expansion in an Org buffer."
847 ;; Standard macro expansion.
849 (equal "#+MACRO: macro1 value\nvalue\n"
850 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
851 (org-export-as (org-test-default-backend)))))
852 ;; Expand specific macros.
854 (equal "me 2012-03-29 me@here Title\n"
855 (org-test-with-temp-text
861 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
862 (let ((output (org-export-as (org-test-default-backend))))
863 (substring output
(string-match ".*\n\\'" output
))))))
864 ;; Expand specific macros when property contained a regular macro
868 (org-test-with-temp-text "
869 #+MACRO: macro1 value
870 #+TITLE: {{{macro1}}}
872 (let ((output (org-export-as (org-test-default-backend))))
873 (substring output
(string-match ".*\n\\'" output
))))))
874 ;; Expand macros with templates in included files.
877 (org-test-with-temp-text
878 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
879 {{{included-macro}}}" org-test-dir
)
880 (let ((output (org-export-as (org-test-default-backend))))
881 (substring output
(string-match ".*\n\\'" output
)))))))
883 (ert-deftest test-org-export
/user-ignore-list
()
884 "Test if `:ignore-list' accepts user input."
885 (let ((backend (org-test-default-backend)))
886 (setf (org-export-backend-transcoders backend
)
887 (cons '(template .
(lambda (body i
)
888 (format "BEGIN\n%sEND" body
)))
889 (org-export-backend-transcoders backend
)))
890 (org-test-with-temp-text "Text"
891 (should (equal (org-export-as backend nil nil
'body-only
)
893 (should (equal (org-export-as backend
) "BEGIN\nText\nEND"))))
897 (let ((org-export-filter-parse-tree-functions
898 '((lambda (data backend info
)
899 ;; Ignore headlines with the word "note" in their title.
900 (org-element-map data
'headline
902 (when (string-match "\\<note\\>"
903 (org-element-property :raw-value
905 (org-export-ignore-element headline info
)))
908 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
909 (org-export-as (org-test-default-backend)))))))
911 (ert-deftest test-org-export
/before-processing-hook
()
912 "Test `org-export-before-processing-hook'."
915 "#+MACRO: mac val\nTest\n"
916 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
917 (let ((org-export-before-processing-hook
919 (while (re-search-forward "{{{" nil t
)
920 (let ((object (org-element-context)))
921 (when (eq (org-element-type object
) 'macro
)
923 (org-element-property :begin object
)
924 (org-element-property :end object
)))))))))
925 (org-export-as (org-test-default-backend)))))))
927 (ert-deftest test-org-export
/before-parsing-hook
()
928 "Test `org-export-before-parsing-hook'."
930 (equal "Body 1\nBody 2\n"
931 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
932 (let ((org-export-before-parsing-hook
934 (goto-char (point-min))
935 (while (re-search-forward org-outline-regexp-bol nil t
)
937 (point-at-bol) (progn (forward-line) (point))))))))
938 (org-export-as (org-test-default-backend)))))))
942 ;;; Affiliated Keywords
944 (ert-deftest test-org-export
/read-attribute
()
945 "Test `org-export-read-attribute' specifications."
949 (org-export-read-attribute
951 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
952 (org-element-at-point)))
954 ;; Return nil on empty attribute.
956 (org-export-read-attribute
958 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
959 ;; Return nil on "nil" string.
961 (equal '(:a nil
:b nil
)
962 (org-export-read-attribute
964 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
965 (org-element-at-point)))))
966 ;; Return nil on empty string.
968 (equal '(:a nil
:b nil
)
969 (org-export-read-attribute
971 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
972 (org-element-at-point)))))
973 ;; Return empty string when value is "".
976 (org-export-read-attribute
978 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
979 (org-element-at-point)))))
980 ;; Return \"\" when value is """".
983 (org-export-read-attribute
985 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
986 (org-element-at-point)))))
987 ;; Ignore text before first property.
990 (org-export-read-attribute
992 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
993 (org-element-at-point))))))
995 (ert-deftest test-org-export
/get-caption
()
996 "Test `org-export-get-caption' specifications."
997 ;; Without optional argument, return long caption
1001 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1002 (org-export-get-caption (org-element-at-point)))))
1003 ;; With optional argument, return short caption.
1007 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1008 (org-export-get-caption (org-element-at-point) t
))))
1009 ;; Multiple lines are separated by white spaces.
1013 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1014 (org-export-get-caption (org-element-at-point))))))
1020 (ert-deftest test-org-export
/define-backend
()
1021 "Test back-end definition and accessors."
1024 (equal '((headline . my-headline-test
))
1025 (let (org-export--registered-backends)
1026 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1027 (org-export-get-all-transcoders 'test
))))
1030 (equal '((:filter-headline . my-filter
))
1031 (let (org-export--registered-backends)
1032 (org-export-define-backend 'test
1033 '((headline . my-headline-test
))
1034 :filters-alist
'((:filter-headline . my-filter
)))
1035 (org-export-backend-filters (org-export-get-backend 'test
)))))
1038 (equal '((:prop value
))
1039 (let (org-export--registered-backends)
1040 (org-export-define-backend 'test
1041 '((headline . my-headline-test
))
1042 :options-alist
'((:prop value
)))
1043 (org-export-backend-options (org-export-get-backend 'test
)))))
1046 (equal '(?k
"Test Export" test
)
1047 (let (org-export--registered-backends)
1048 (org-export-define-backend 'test
1049 '((headline . my-headline-test
))
1050 :menu-entry
'(?k
"Test Export" test
))
1051 (org-export-backend-menu (org-export-get-backend 'test
)))))
1054 (equal '(("TEST" . org-element-export-block-parser
))
1055 (let (org-export--registered-backends org-element-block-name-alist
)
1056 (org-export-define-backend 'test
1057 '((headline . my-headline-test
))
1058 :export-block
'("test"))
1059 org-element-block-name-alist
))))
1061 (ert-deftest test-org-export
/define-derived-backend
()
1062 "Test `org-export-define-derived-backend' specifications."
1063 ;; Error when parent back-end is not defined.
1065 (let (org-export--registered-backends)
1066 (org-export-define-derived-backend 'test
'parent
)))
1067 ;; Append translation table to parent's.
1069 (equal '((:headline . test
) (:headline . parent
))
1070 (let (org-export--registered-backends)
1071 (org-export-define-backend 'parent
'((:headline . parent
)))
1072 (org-export-define-derived-backend 'test
'parent
1073 :translate-alist
'((:headline . test
)))
1074 (org-export-get-all-transcoders 'test
))))
1075 ;; Options defined in the new back have priority over those defined
1079 (let (org-export--registered-backends)
1080 (org-export-define-backend 'parent
1081 '((:headline . parent
))
1082 :options-alist
'((:a nil nil
'parent
)))
1083 (org-export-define-derived-backend 'test
'parent
1084 :options-alist
'((:a nil nil
'test
)))
1085 (plist-get (org-export--get-global-options
1086 (org-export-get-backend 'test
))
1089 (ert-deftest test-org-export
/derived-backend-p
()
1090 "Test `org-export-derived-backend-p' specifications."
1091 ;; Non-nil with direct match.
1093 (let (org-export--registered-backends)
1094 (org-export-define-backend 'test
'((headline . test
)))
1095 (org-export-derived-backend-p 'test
'test
)))
1097 (let (org-export--registered-backends)
1098 (org-export-define-backend 'test
'((headline . test
)))
1099 (org-export-define-derived-backend 'test2
'test
)
1100 (org-export-derived-backend-p 'test2
'test2
)))
1101 ;; Non-nil with a direct parent.
1103 (let (org-export--registered-backends)
1104 (org-export-define-backend 'test
'((headline . test
)))
1105 (org-export-define-derived-backend 'test2
'test
)
1106 (org-export-derived-backend-p 'test2
'test
)))
1107 ;; Non-nil with an indirect parent.
1109 (let (org-export--registered-backends)
1110 (org-export-define-backend 'test
'((headline . test
)))
1111 (org-export-define-derived-backend 'test2
'test
)
1112 (org-export-define-derived-backend 'test3
'test2
)
1113 (org-export-derived-backend-p 'test3
'test
)))
1116 (let (org-export--registered-backends)
1117 (org-export-define-backend 'test
'((headline . test
)))
1118 (org-export-define-backend 'test2
'((headline . test2
)))
1119 (org-export-derived-backend-p 'test2
'test
)))
1121 (let (org-export--registered-backends)
1122 (org-export-define-backend 'test
'((headline . test
)))
1123 (org-export-define-backend 'test2
'((headline . test2
)))
1124 (org-export-define-derived-backend 'test3
'test2
)
1125 (org-export-derived-backend-p 'test3
'test
))))
1127 (ert-deftest test-org-export
/get-all-transcoders
()
1128 "Test `org-export-get-all-transcoders' specifications."
1129 ;; Return nil when back-end cannot be found.
1130 (should-not (org-export-get-all-transcoders nil
))
1131 ;; Same as `org-export-transcoders' if no parent.
1133 (equal '((headline . ignore
))
1134 (org-export-get-all-transcoders
1135 (org-export-create-backend
1136 :transcoders
'((headline . ignore
))))))
1137 ;; But inherit from all ancestors whenever possible.
1139 (equal '((section . ignore
) (headline . ignore
))
1140 (let (org-export--registered-backends)
1141 (org-export-define-backend 'b1
'((headline . ignore
)))
1142 (org-export-get-all-transcoders
1143 (org-export-create-backend
1144 :parent
'b1
:transcoders
'((section . ignore
)))))))
1146 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1147 (let (org-export--registered-backends)
1148 (org-export-define-backend 'b1
'((headline . ignore
)))
1149 (org-export-define-derived-backend 'b2
'b1
1150 :translate-alist
'((section . ignore
)))
1151 (org-export-get-all-transcoders
1152 (org-export-create-backend
1153 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1154 ;; Back-end transcoders overrule inherited ones.
1157 (let (org-export--registered-backends)
1158 (org-export-define-backend 'b1
'((headline . a
)))
1159 (cdr (assq 'headline
1160 (org-export-get-all-transcoders
1161 (org-export-create-backend
1162 :parent
'b1
:transcoders
'((headline . b
))))))))))
1164 (ert-deftest test-org-export
/get-all-options
()
1165 "Test `org-export-get-all-options' specifications."
1166 ;; Return nil when back-end cannot be found.
1167 (should-not (org-export-get-all-options nil
))
1168 ;; Same as `org-export-options' if no parent.
1170 (equal '((headline . ignore
))
1171 (org-export-get-all-options
1172 (org-export-create-backend
1173 :options
'((headline . ignore
))))))
1174 ;; But inherit from all ancestors whenever possible.
1176 (equal '((:key2 value2
) (:key1 value1
))
1177 (let (org-export--registered-backends)
1178 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1179 (org-export-get-all-options
1180 (org-export-create-backend
1181 :parent
'b1
:options
'((:key2 value2
)))))))
1183 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1184 (let (org-export--registered-backends)
1185 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1186 (org-export-define-derived-backend 'b2
'b1
1187 :options-alist
'((:key2 value2
)))
1188 (org-export-get-all-options
1189 (org-export-create-backend
1190 :parent
'b2
:options
'((:key3 value3
)))))))
1191 ;; Back-end options overrule inherited ones.
1194 (let (org-export--registered-backends)
1195 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1197 (org-export-get-all-options
1198 (org-export-create-backend
1199 :parent
'b1
:options
'((:key1 . b
))))))))))
1201 (ert-deftest test-org-export
/get-all-filters
()
1202 "Test `org-export-get-all-filters' specifications."
1203 ;; Return nil when back-end cannot be found.
1204 (should-not (org-export-get-all-filters nil
))
1205 ;; Same as `org-export-filters' if no parent.
1207 (equal '((:filter-headline . ignore
))
1208 (org-export-get-all-filters
1209 (org-export-create-backend
1210 :filters
'((:filter-headline . ignore
))))))
1211 ;; But inherit from all ancestors whenever possible.
1213 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1214 (let (org-export--registered-backends)
1215 (org-export-define-backend 'b1
1216 nil
:filters-alist
'((:filter-headline . ignore
)))
1217 (org-export-get-all-filters
1218 (org-export-create-backend
1219 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1221 (equal '((:filter-paragraph . ignore
)
1222 (:filter-section . ignore
)
1223 (:filter-headline . ignore
))
1224 (let (org-export--registered-backends)
1225 (org-export-define-backend 'b1
1226 nil
:filters-alist
'((:filter-headline . ignore
)))
1227 (org-export-define-derived-backend 'b2
'b1
1228 :filters-alist
'((:filter-section . ignore
)))
1229 (org-export-get-all-filters
1230 (org-export-create-backend
1231 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1232 ;; Back-end filters overrule inherited ones.
1235 (let (org-export--registered-backends)
1236 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1237 (cdr (assq :filter-headline
1238 (org-export-get-all-filters
1239 (org-export-create-backend
1240 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1242 (ert-deftest test-org-export
/with-backend
()
1243 "Test `org-export-with-backend' definition."
1244 ;; Error when calling an undefined back-end
1245 (should-error (org-export-with-backend nil
"Test"))
1246 ;; Error when called back-end doesn't have an appropriate
1249 (org-export-with-backend
1250 (org-export-create-backend :transcoders
'((headline . ignore
)))
1252 ;; Otherwise, export using correct transcoder
1255 (let (org-export--registered-backends)
1256 (org-export-define-backend 'test
1257 '((plain-text .
(lambda (text contents info
) "Failure"))))
1258 (org-export-define-backend 'test2
1259 '((plain-text .
(lambda (text contents info
) "Success"))))
1260 (org-export-with-backend 'test2
"Test"))))
1261 ;; Provide correct back-end if transcoder needs to use recursive
1265 (let ((test-back-end
1266 (org-export-create-backend
1268 '((headline .
(lambda (headline contents info
)
1270 (org-element-property :title headline
)
1272 (plain-text .
(lambda (text info
) "Success"))))))
1273 (org-export-string-as
1275 (org-export-create-backend
1277 '((headline .
(lambda (headline contents info
)
1278 (org-export-with-backend
1279 test-back-end headline contents info
))))))))))
1281 (ert-deftest test-org-export
/data-with-backend
()
1282 "Test `org-export-data-with-backend' specifications."
1283 ;; Error when calling an undefined back-end.
1284 (should-error (org-export-data-with-backend nil
"nil" nil
))
1285 ;; Otherwise, export data recursively, using correct back-end.
1289 (org-export-data-with-backend
1291 (org-export-create-backend
1293 '((plain-text .
(lambda (text info
) "Success"))
1294 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1295 '(:with-emphasize t
)))))
1301 (ert-deftest test-org-export
/export-snippet
()
1302 "Test export snippets transcoding."
1304 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1305 (let ((backend (org-test-default-backend)))
1306 (setf (org-export-backend-name backend
) 'test
)
1307 (setf (org-export-backend-transcoders backend
)
1308 (cons (cons 'export-snippet
1309 (lambda (snippet contents info
)
1310 (when (eq (org-export-snippet-backend snippet
) 'test
)
1311 (org-element-property :value snippet
))))
1312 (org-export-backend-transcoders backend
)))
1313 (let ((org-export-snippet-translation-alist nil
))
1314 (should (equal (org-export-as backend
) "A\n")))
1315 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1316 (should (equal (org-export-as backend
) "AB\n")))))
1317 ;; Ignored export snippets do not remove any blank.
1319 (equal "begin end\n"
1320 (org-test-with-parsed-data "begin @@test:A@@ end"
1321 (org-export-data-with-backend
1323 (org-export-create-backend
1325 '((paragraph .
(lambda (paragraph contents info
) contents
))
1326 (section .
(lambda (section contents info
) contents
))))
1333 (ert-deftest test-org-export
/footnotes
()
1334 "Test footnotes specifications."
1335 (let ((org-footnote-section nil
)
1336 (org-export-with-footnotes t
))
1337 ;; 1. Read every type of footnote.
1340 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1341 (org-test-with-parsed-data
1342 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1343 (org-element-map tree
'footnote-reference
1345 (let ((def (org-export-get-footnote-definition ref info
)))
1346 (cons (org-export-get-footnote-number ref info
)
1347 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1348 (car (org-element-contents
1349 (car (org-element-contents def
))))))))
1351 ;; 2. Test nested footnotes order.
1354 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
1355 (org-test-with-parsed-data
1356 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1357 (org-element-map tree
'footnote-reference
1359 (when (org-export-footnote-first-reference-p ref info
)
1360 (cons (org-export-get-footnote-number ref info
)
1361 (org-element-property :label ref
))))
1363 ;; 3. Test nested footnote in invisible definitions.
1364 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1365 ;; Hide definitions.
1366 (narrow-to-region (point) (point-at-eol))
1367 (let* ((tree (org-element-parse-buffer))
1368 (info (org-combine-plists
1369 `(:parse-tree
,tree
)
1370 (org-export-collect-tree-properties
1371 tree
(org-export-get-environment)))))
1372 ;; Both footnotes should be seen.
1374 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
1375 ;; 4. Test footnotes definitions collection.
1378 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1380 \[fn:2] B [fn:3] [fn::D].
1383 (length (org-export-collect-footnote-definitions tree info
)))))
1384 ;; 5. Test export of footnotes defined outside parsing scope.
1387 "ParagraphOut of scope\n"
1388 (org-test-with-temp-text "[fn:1] Out of scope
1391 (let ((backend (org-test-default-backend)))
1392 (setf (org-export-backend-transcoders backend
)
1393 (cons (cons 'footnote-reference
1394 (lambda (fn contents info
)
1395 (org-element-interpret-data
1396 (org-export-get-footnote-definition fn info
))))
1397 (org-export-backend-transcoders backend
)))
1399 (org-export-as backend
'subtree
)))))
1400 ;; 6. Footnotes without a definition should be provided a fallback
1403 (org-test-with-parsed-data "[fn:1]"
1404 (org-export-get-footnote-definition
1405 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1406 ;; 7. Footnote section should be ignored in TOC and in headlines
1409 (= 1 (let ((org-footnote-section "Footnotes"))
1410 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1411 (org-export-collect-headlines info
))))))
1414 (let ((org-footnote-section "Footnotes"))
1415 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1416 (org-element-map tree
'headline
1418 (when (equal (org-element-property :raw-value hl
) "H2")
1419 (org-export-get-headline-number hl info
)))
1424 ;;; Headlines and Inlinetasks
1426 (ert-deftest test-org-export
/get-relative-level
()
1427 "Test `org-export-get-relative-level' specifications."
1431 (let ((org-odd-levels-only nil
))
1432 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1433 (org-element-map tree
'headline
1434 (lambda (h) (org-export-get-relative-level h info
))
1439 (let ((org-odd-levels-only nil
))
1440 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1441 (org-element-map tree
'headline
1442 (lambda (h) (org-export-get-relative-level h info
))
1445 (ert-deftest test-org-export
/low-level-p
()
1446 "Test `org-export-low-level-p' specifications."
1450 (let ((org-odd-levels-only nil
))
1451 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1452 (org-element-map tree
'headline
1453 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1454 (plist-put info
:headline-levels
1)))))))
1456 (ert-deftest test-org-export
/get-headline-number
()
1457 "Test `org-export-get-headline-number' specifications."
1462 (let ((org-odd-levels-only nil
))
1463 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1464 (org-element-map tree
'headline
1465 (lambda (h) (org-export-get-headline-number h info
))
1467 ;; Missing levels are replaced with 0.
1471 (let ((org-odd-levels-only nil
))
1472 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1473 (org-element-map tree
'headline
1474 (lambda (h) (org-export-get-headline-number h info
))
1477 (ert-deftest test-org-export
/numbered-headline-p
()
1478 "Test `org-export-numbered-headline-p' specifications."
1479 ;; If `:section-numbers' is nil, never number headlines.
1481 (org-test-with-parsed-data "* Headline"
1482 (org-element-map tree
'headline
1483 (lambda (h) (org-export-numbered-headline-p h info
))
1484 (plist-put info
:section-numbers nil
))))
1485 ;; If `:section-numbers' is a number, only number headlines with
1486 ;; a level greater that it.
1490 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1491 (org-element-map tree
'headline
1492 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1493 (plist-put info
:section-numbers
1)))))
1494 ;; Otherwise, headlines are always numbered.
1496 (org-test-with-parsed-data "* Headline"
1497 (org-element-map tree
'headline
1498 (lambda (h) (org-export-numbered-headline-p h info
))
1499 (plist-put info
:section-numbers t
)))))
1501 (ert-deftest test-org-export
/number-to-roman
()
1502 "Test `org-export-number-to-roman' specifications."
1503 ;; If number is negative, return it as a string.
1504 (should (equal (org-export-number-to-roman -
1) "-1"))
1505 ;; Otherwise, return it as a roman number.
1506 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1508 (ert-deftest test-org-export
/get-optional-title
()
1509 "Test `org-export-get-alt-title' specifications."
1510 ;; If ALT_TITLE property is defined, use it.
1513 (org-test-with-parsed-data
1514 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1515 (org-export-get-alt-title
1516 (org-element-map tree
'headline
'identity info t
)
1518 ;; Otherwise, fall-back to regular title.
1520 (equal '("Headline")
1521 (org-test-with-parsed-data "* Headline"
1522 (org-export-get-alt-title
1523 (org-element-map tree
'headline
'identity info t
)
1526 (ert-deftest test-org-export
/get-tags
()
1527 "Test `org-export-get-tags' specifications."
1528 (let ((org-export-exclude-tags '("noexport"))
1529 (org-export-select-tags '("export")))
1530 ;; Standard test: tags which are not a select tag, an exclude tag,
1531 ;; or specified as optional argument shouldn't be ignored.
1533 (org-test-with-parsed-data "* Headline :tag:"
1534 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1536 ;; Exclude tags are removed.
1538 (org-test-with-parsed-data "* Headline :noexport:"
1539 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1541 ;; Select tags are removed.
1543 (org-test-with-parsed-data "* Headline :export:"
1544 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1549 (org-test-with-parsed-data "* Headline :tag:export:"
1550 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1552 ;; Tags provided in the optional argument are also ignored.
1554 (org-test-with-parsed-data "* Headline :ignore:"
1555 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
1557 ;; Allow tag inheritance.
1561 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
1562 (org-element-map tree
'headline
1563 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
1564 ;; Tag inheritance checks FILETAGS keywords.
1568 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
1569 (org-element-map tree
'headline
1570 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
1572 (ert-deftest test-org-export
/get-node-property
()
1573 "Test`org-export-get-node-property' specifications."
1577 (org-test-with-parsed-data "* Headline
1581 (org-export-get-node-property
1582 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
1583 ;; Test inheritance.
1586 (org-test-with-parsed-data "* Parent
1592 (org-export-get-node-property
1593 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1594 ;; Cannot return a value before the first headline.
1596 (org-test-with-parsed-data "Paragraph
1601 (org-export-get-node-property
1602 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
1604 (ert-deftest test-org-export
/get-category
()
1605 "Test `org-export-get-category' specifications."
1609 (org-test-with-parsed-data "* Headline
1613 (org-export-get-category
1614 (org-element-map tree
'headline
'identity nil t
) info
))))
1615 ;; Test inheritance from a parent headline.
1617 (equal '("value" "value")
1618 (org-test-with-parsed-data "* Headline1
1623 (org-element-map tree
'headline
1624 (lambda (hl) (org-export-get-category hl info
)) info
))))
1625 ;; Test inheritance from #+CATEGORY keyword
1628 (org-test-with-parsed-data "#+CATEGORY: value
1630 (org-export-get-category
1631 (org-element-map tree
'headline
'identity nil t
) info
))))
1632 ;; Test inheritance from file name.
1635 (org-test-with-parsed-data "* Headline"
1636 (let ((info (plist-put info
:input-file
"~/test.org")))
1637 (org-export-get-category
1638 (org-element-map tree
'headline
'identity nil t
) info
)))))
1642 (org-test-with-parsed-data "* Headline"
1643 (org-export-get-category
1644 (org-element-map tree
'headline
'identity nil t
) info
)))))
1646 (ert-deftest test-org-export
/first-sibling-p
()
1647 "Test `org-export-first-sibling-p' specifications."
1652 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1653 (org-element-map tree
'headline
1654 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1656 ;; Ignore headlines not exported.
1660 (let ((org-export-exclude-tags '("ignore")))
1661 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1662 (org-element-map tree
'headline
1663 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1666 (ert-deftest test-org-export
/last-sibling-p
()
1667 "Test `org-export-last-sibling-p' specifications."
1672 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1673 (org-element-map tree
'headline
1674 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1676 ;; Ignore headlines not exported.
1680 (let ((org-export-exclude-tags '("ignore")))
1681 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1682 (org-element-map tree
'headline
1683 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1686 (ert-deftest test-org-export
/handle-inlinetasks
()
1687 "Test inlinetask export."
1688 ;; Inlinetask with an exclude tag.
1689 (when (featurep 'org-inlinetask
)
1693 (let ((org-inlinetask-min-level 3))
1694 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
1695 (org-export-as (org-test-default-backend)
1696 nil nil nil
'(:exclude-tags
("noexp")))))))
1697 ;; Inlinetask with an include tag.
1700 "* H2\n*** Inline :exp:\n"
1701 (let ((org-inlinetask-min-level 3)
1702 (org-tags-column 0))
1703 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
1704 (org-export-as (org-test-default-backend)
1705 nil nil nil
'(:select-tags
("exp")))))))
1706 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
1709 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
1710 (org-inlinetask-min-level 3))
1711 (org-test-with-temp-text "*** TODO Inline"
1712 (org-export-as (org-test-default-backend)
1713 nil nil nil
'(:with-tasks nil
))))))))
1719 (ert-deftest test-org-export
/get-date
()
1720 "Test `org-export-get-date' specifications."
1721 ;; Return a properly formatted string when
1722 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
1723 ;; consists in a single timestamp.
1726 (let ((org-export-date-timestamp-format "%d %m %Y"))
1727 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1728 (org-export-get-date info
)))))
1729 ;; Return a secondary string otherwise.
1732 (let ((org-export-date-timestamp-format nil
))
1733 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1734 (org-export-get-date info
)))))
1737 (org-test-with-parsed-data "#+DATE: Date"
1738 (org-export-get-date info
))))
1739 ;; Optional argument has precedence over
1740 ;; `org-export-date-timestamp-format'.
1743 (let ((org-export-date-timestamp-format "%d %m %Y"))
1744 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
1745 (org-export-get-date info
"%d %m"))))))
1751 (ert-deftest test-org-export
/get-coderef-format
()
1752 "Test `org-export-get-coderef-format' specifications."
1753 ;; A link without description returns "%s"
1754 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1756 ;; Return "%s" when path is matched within description.
1757 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1759 ;; Otherwise return description.
1760 (should (equal (org-export-get-coderef-format "path" "desc")
1763 (ert-deftest test-org-export
/inline-image-p
()
1764 "Test `org-export-inline-image-p' specifications."
1766 (org-export-inline-image-p
1767 (org-test-with-temp-text "[[#id]]"
1768 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
1769 '(("custom-id" .
"id")))))
1771 (ert-deftest test-org-export
/fuzzy-link
()
1772 "Test fuzzy links specifications."
1773 ;; Link to an headline should return headline's number.
1774 (org-test-with-parsed-data
1775 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1777 ;; Note: Headline's number is in fact a list of numbers.
1779 (org-element-map tree
'link
1781 (org-export-get-ordinal
1782 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1783 ;; Link to a target in an item should return item's number.
1784 (org-test-with-parsed-data
1785 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1787 ;; Note: Item's number is in fact a list of numbers.
1789 (org-element-map tree
'link
1791 (org-export-get-ordinal
1792 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1793 ;; Link to a target in a footnote should return footnote's number.
1794 (org-test-with-parsed-data "
1795 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1798 (org-element-map tree
'link
1800 (org-export-get-ordinal
1801 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1802 ;; Link to a named element should return sequence number of that
1804 (org-test-with-parsed-data
1805 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1808 (org-element-map tree
'link
1810 (org-export-get-ordinal
1811 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1812 ;; Link to a target not within an item, a table, a footnote
1813 ;; reference or definition should return section number.
1814 (org-test-with-parsed-data
1815 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1818 (org-element-map tree
'link
1820 (org-export-get-ordinal
1821 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1822 ;; Space are not significant when matching a fuzzy link.
1824 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
1825 (org-element-map tree
'link
1826 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1828 ;; Statistics cookies are ignored for headline match.
1830 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
1831 (org-element-map tree
'link
1832 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1835 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
1836 (org-element-map tree
'link
1837 (lambda (link) (org-export-resolve-fuzzy-link link info
))
1839 ;; Headline match is position dependent.
1843 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
1844 (org-element-map tree
'link
1845 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
1847 (ert-deftest test-org-export
/resolve-coderef
()
1848 "Test `org-export-resolve-coderef' specifications."
1849 (let ((org-coderef-label-format "(ref:%s)"))
1850 ;; 1. A link to a "-n -k -r" block returns line number.
1851 (org-test-with-parsed-data
1852 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1853 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1854 (org-test-with-parsed-data
1855 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1856 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1857 ;; 2. A link to a "-n -r" block returns line number.
1858 (org-test-with-parsed-data
1859 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1860 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1861 (org-test-with-parsed-data
1862 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1863 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1864 ;; 3. A link to a "-n" block returns coderef.
1865 (org-test-with-parsed-data
1866 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1867 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1868 (org-test-with-parsed-data
1869 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1870 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1871 ;; 4. A link to a "-r" block returns line number.
1872 (org-test-with-parsed-data
1873 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1874 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1875 (org-test-with-parsed-data
1876 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1877 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1878 ;; 5. A link to a block without a switch returns coderef.
1879 (org-test-with-parsed-data
1880 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1881 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1882 (org-test-with-parsed-data
1883 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1884 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1885 ;; 6. Correctly handle continued line numbers. A "+n" switch
1886 ;; should resume numbering from previous block with numbered
1887 ;; lines, ignoring blocks not numbering lines in the process.
1888 ;; A "-n" switch resets count.
1889 (org-test-with-parsed-data "
1894 #+BEGIN_SRC emacs-lisp
1898 #+BEGIN_SRC emacs-lisp +n -r
1899 \(+ 1 1) (ref:addition)
1902 #+BEGIN_EXAMPLE -n -r
1903 Another text. (ref:text)
1905 (should (= (org-export-resolve-coderef "addition" info
) 2))
1906 (should (= (org-export-resolve-coderef "text" info
) 1)))
1907 ;; 7. Recognize coderef with user-specified syntax.
1908 (org-test-with-parsed-data
1909 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1910 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1912 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1913 "Test `org-export-resolve-fuzzy-link' specifications."
1914 ;; Match target objects.
1916 (org-test-with-parsed-data "<<target>> [[target]]"
1917 (org-export-resolve-fuzzy-link
1918 (org-element-map tree
'link
'identity info t
) info
)))
1919 ;; Match named elements.
1921 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1922 (org-export-resolve-fuzzy-link
1923 (org-element-map tree
'link
'identity info t
) info
)))
1924 ;; Match exact headline's name.
1926 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1927 (org-export-resolve-fuzzy-link
1928 (org-element-map tree
'link
'identity info t
) info
)))
1929 ;; Targets objects have priority over named elements and headline
1933 (org-test-with-parsed-data
1934 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1936 (org-export-resolve-fuzzy-link
1937 (org-element-map tree
'link
'identity info t
) info
)))))
1938 ;; Named elements have priority over headline titles.
1941 (org-test-with-parsed-data
1942 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1944 (org-export-resolve-fuzzy-link
1945 (org-element-map tree
'link
'identity info t
) info
)))))
1946 ;; If link's path starts with a "*", only match headline titles,
1950 (org-test-with-parsed-data
1951 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1953 (org-export-resolve-fuzzy-link
1954 (org-element-map tree
'link
'identity info t
) info
)))))
1955 ;; Return nil if no match.
1957 (org-test-with-parsed-data "[[target]]"
1958 (org-export-resolve-fuzzy-link
1959 (org-element-map tree
'link
'identity info t
) info
)))
1960 ;; Match fuzzy link even when before first headline.
1963 (org-test-with-parsed-data "[[hl]]\n* hl"
1965 (org-export-resolve-fuzzy-link
1966 (org-element-map tree
'link
'identity info t
) info
))))))
1968 (ert-deftest test-org-export
/resolve-id-link
()
1969 "Test `org-export-resolve-id-link' specifications."
1970 ;; 1. Regular test for custom-id link.
1971 (org-test-with-parsed-data "* Headline1
1978 (org-export-resolve-id-link
1979 (org-element-map tree
'link
'identity info t
) info
)))
1980 ;; 2. Failing test for custom-id link.
1981 (org-test-with-parsed-data "* Headline1
1988 (org-export-resolve-id-link
1989 (org-element-map tree
'link
'identity info t
) info
)))
1990 ;; 3. Test for internal id target.
1991 (org-test-with-parsed-data "* Headline1
1998 (org-export-resolve-id-link
1999 (org-element-map tree
'link
'identity info t
) info
)))
2000 ;; 4. Test for external id target.
2001 (org-test-with-parsed-data "[[id:aaaa]]"
2003 (org-export-resolve-id-link
2004 (org-element-map tree
'link
'identity info t
)
2005 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
2007 (ert-deftest test-org-export
/resolve-radio-link
()
2008 "Test `org-export-resolve-radio-link' specifications."
2011 (org-test-with-temp-text "<<<radio>>> radio"
2012 (org-update-radio-target-regexp)
2013 (let* ((tree (org-element-parse-buffer))
2014 (info `(:parse-tree
,tree
)))
2015 (org-export-resolve-radio-link
2016 (org-element-map tree
'link
'identity info t
)
2018 ;; Radio targets are case-insensitive.
2020 (org-test-with-temp-text "<<<RADIO>>> radio"
2021 (org-update-radio-target-regexp)
2022 (let* ((tree (org-element-parse-buffer))
2023 (info `(:parse-tree
,tree
)))
2024 (org-export-resolve-radio-link
2025 (org-element-map tree
'link
'identity info t
)
2027 ;; Radio target with objects.
2029 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2030 (org-update-radio-target-regexp)
2031 (let* ((tree (org-element-parse-buffer))
2032 (info `(:parse-tree
,tree
)))
2033 (org-export-resolve-radio-link
2034 (org-element-map tree
'link
'identity info t
)
2036 ;; Multiple radio targets.
2038 (equal '("radio1" "radio2")
2039 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2040 (org-update-radio-target-regexp)
2041 (let* ((tree (org-element-parse-buffer))
2042 (info `(:parse-tree
,tree
)))
2043 (org-element-map tree
'link
2045 (org-element-property
2046 :value
(org-export-resolve-radio-link link info
)))
2048 ;; Radio target is whitespace insensitive.
2050 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2051 (org-update-radio-target-regexp)
2052 (let* ((tree (org-element-parse-buffer))
2053 (info `(:parse-tree
,tree
)))
2054 (org-element-map tree
'link
2055 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2059 ;;; Src-block and example-block
2061 (ert-deftest test-org-export
/unravel-code
()
2062 "Test `org-export-unravel-code' function."
2063 ;; Code without reference.
2065 (equal '("(+ 1 1)\n")
2066 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2067 (org-export-unravel-code (org-element-at-point)))))
2068 ;; Code with reference.
2070 (equal '("(+ 1 1)\n" (1 .
"test"))
2071 (org-test-with-temp-text
2072 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2073 (let ((org-coderef-label-format "(ref:%s)"))
2074 (org-export-unravel-code (org-element-at-point))))))
2075 ;; Code with user-defined reference.
2078 '("(+ 1 1)\n" (1 .
"test"))
2079 (org-test-with-temp-text
2080 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2081 (let ((org-coderef-label-format "(ref:%s)"))
2082 (org-export-unravel-code (org-element-at-point))))))
2083 ;; Code references keys are relative to the current block.
2085 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2086 (org-test-with-temp-text "
2095 (let ((org-coderef-label-format "(ref:%s)"))
2096 (org-export-unravel-code (org-element-at-point)))))))
2098 (ert-deftest test-org-export
/format-code-default
()
2099 "Test `org-export-format-code-default' specifications."
2100 ;; Return the empty string when code is empty.
2103 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2104 (org-export-format-code-default
2105 (org-element-map tree
'src-block
'identity info t
) info
))))
2106 ;; Number lines, two whitespace characters before the actual loc.
2109 (org-test-with-parsed-data
2110 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2111 (org-export-format-code-default
2112 (org-element-map tree
'src-block
'identity info t
) info
))))
2113 ;; Put references 6 whitespace characters after the widest line,
2114 ;; wrapped within parenthesis.
2116 (equal "123 (a)\n1 (b)\n"
2117 (let ((org-coderef-label-format "(ref:%s)"))
2118 (org-test-with-parsed-data
2119 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2120 (org-export-format-code-default
2121 (org-element-map tree
'src-block
'identity info t
) info
))))))
2127 (ert-deftest test-org-export
/activate-smart-quotes
()
2128 "Test `org-export-activate-smart-quotes' specifications."
2129 ;; Opening double quotes: standard test.
2132 '("some “paragraph")
2133 (let ((org-export-default-language "en"))
2134 (org-test-with-parsed-data "some \"paragraph"
2135 (org-element-map tree
'plain-text
2136 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2138 ;; Opening quotes: at the beginning of a paragraph.
2142 (let ((org-export-default-language "en"))
2143 (org-test-with-parsed-data "\"begin"
2144 (org-element-map tree
'plain-text
2145 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2147 ;; Opening quotes: after an object.
2151 (let ((org-export-default-language "en"))
2152 (org-test-with-parsed-data "=verb= \"begin"
2153 (org-element-map tree
'plain-text
2154 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2156 ;; Closing quotes: standard test.
2159 '("some” paragraph")
2160 (let ((org-export-default-language "en"))
2161 (org-test-with-parsed-data "some\" paragraph"
2162 (org-element-map tree
'plain-text
2163 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2165 ;; Closing quotes: at the end of a paragraph.
2169 (let ((org-export-default-language "en"))
2170 (org-test-with-parsed-data "end\""
2171 (org-element-map tree
'plain-text
2172 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2174 ;; Apostrophe: standard test.
2177 '("It shouldn’t fail")
2178 (let ((org-export-default-language "en"))
2179 (org-test-with-parsed-data "It shouldn't fail"
2180 (org-element-map tree
'plain-text
2181 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2183 ;; Apostrophe: before an object.
2187 (let ((org-export-default-language "en"))
2188 (org-test-with-parsed-data "a'=b="
2189 (org-element-map tree
'plain-text
2190 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2192 ;; Apostrophe: after an object.
2196 (let ((org-export-default-language "en"))
2197 (org-test-with-parsed-data "=code='s"
2198 (org-element-map tree
'plain-text
2199 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2201 ;; Special case: isolated quotes.
2203 (equal '("“" "”")
2204 (let ((org-export-default-language "en"))
2205 (org-test-with-parsed-data "\"$x$\""
2206 (org-element-map tree
'plain-text
2207 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2209 ;; Smart quotes in secondary strings.
2211 (equal '("“" "”")
2212 (let ((org-export-default-language "en"))
2213 (org-test-with-parsed-data "* \"$x$\""
2214 (org-element-map tree
'plain-text
2215 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2217 ;; Smart quotes in document keywords.
2219 (equal '("“" "”")
2220 (let ((org-export-default-language "en"))
2221 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2222 (org-element-map (plist-get info
:title
) 'plain-text
2223 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2225 ;; Smart quotes in parsed affiliated keywords.
2227 (equal '("“" "”" "Paragraph")
2228 (let ((org-export-default-language "en"))
2229 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2230 (org-element-map tree
'plain-text
2231 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2232 info nil nil t
))))))
2238 (ert-deftest test-org-export
/special-column
()
2239 "Test if the table's special column is properly recognized."
2240 ;; 1. First column is special if it contains only a special marking
2241 ;; characters or empty cells.
2242 (org-test-with-temp-text "
2246 (org-export-table-has-special-column-p
2248 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2249 ;; 2. If the column contains anything else, it isn't special.
2250 (org-test-with-temp-text "
2254 (org-export-table-has-special-column-p
2256 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2257 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2259 (org-test-with-temp-text "
2268 (org-export-table-has-special-column-p
2270 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2271 ;; 4. A first column with only empty cells isn't considered as
2273 (org-test-with-temp-text "
2277 (org-export-table-has-special-column-p
2279 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2281 (ert-deftest test-org-export
/table-row-is-special-p
()
2282 "Test `org-export-table-row-is-special-p' specifications."
2283 ;; 1. A row is special if it has a special marking character in the
2285 (org-test-with-parsed-data "| ! | 1 |"
2287 (org-export-table-row-is-special-p
2288 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2289 ;; 2. A row is special when its first field is "/"
2290 (org-test-with-parsed-data "
2294 (org-export-table-row-is-special-p
2295 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2296 ;; 3. A row only containing alignment cookies is also considered as
2298 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2300 (org-export-table-row-is-special-p
2301 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2302 ;; 4. Everything else isn't considered as special.
2303 (org-test-with-parsed-data "| \alpha | | c |"
2305 (org-export-table-row-is-special-p
2306 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2307 ;; 5. Table's rules are never considered as special rows.
2308 (org-test-with-parsed-data "|---+---|"
2310 (org-export-table-row-is-special-p
2311 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2313 (ert-deftest test-org-export
/has-header-p
()
2314 "Test `org-export-table-has-header-p' specifications."
2315 ;; 1. With an header.
2316 (org-test-with-parsed-data "
2321 (org-export-table-has-header-p
2322 (org-element-map tree
'table
'identity info
'first-match
)
2324 ;; 2. Without an header.
2325 (org-test-with-parsed-data "
2329 (org-export-table-has-header-p
2330 (org-element-map tree
'table
'identity info
'first-match
)
2332 ;; 3. Don't get fooled with starting and ending rules.
2333 (org-test-with-parsed-data "
2339 (org-export-table-has-header-p
2340 (org-element-map tree
'table
'identity info
'first-match
)
2343 (ert-deftest test-org-export
/table-row-group
()
2344 "Test `org-export-table-row-group' specifications."
2345 ;; 1. A rule creates a new group.
2348 (org-test-with-parsed-data "
2352 (org-element-map tree
'table-row
2354 (if (eq (org-element-property :type row
) 'rule
) 'rule
2355 (org-export-table-row-group row info
)))))))
2356 ;; 2. Special rows are ignored in count.
2360 (org-test-with-parsed-data "
2364 (org-element-map tree
'table-row
2366 (if (eq (org-element-property :type row
) 'rule
) 'rule
2367 (org-export-table-row-group row info
)))
2369 ;; 3. Double rules also are ignored in count.
2371 (equal '(1 rule rule
2)
2372 (org-test-with-parsed-data "
2377 (org-element-map tree
'table-row
2379 (if (eq (org-element-property :type row
) 'rule
) 'rule
2380 (org-export-table-row-group row info
))))))))
2382 (ert-deftest test-org-export
/table-row-number
()
2383 "Test `org-export-table-row-number' specifications."
2384 ;; Standard test. Number is 0-indexed.
2387 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
2388 (org-element-map tree
'table-row
2389 (lambda (row) (org-export-table-row-number row info
)) info
))))
2390 ;; Number ignores separators.
2393 (org-test-with-parsed-data "
2397 (org-element-map tree
'table-row
2398 (lambda (row) (org-export-table-row-number row info
)) info
))))
2399 ;; Number ignores special rows.
2402 (org-test-with-parsed-data "
2408 (org-element-map tree
'table-row
2409 (lambda (row) (org-export-table-row-number row info
)) info
)))))
2411 (ert-deftest test-org-export
/table-cell-width
()
2412 "Test `org-export-table-cell-width' specifications."
2413 ;; 1. Width is primarily determined by width cookies. If no cookie
2414 ;; is found, cell's width is nil.
2415 (org-test-with-parsed-data "
2416 | / | <l> | <6> | <l7> |
2421 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2422 (org-element-map tree
'table-cell
'identity info
)))))
2423 ;; 2. The last width cookie has precedence.
2424 (org-test-with-parsed-data "
2431 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2432 (org-element-map tree
'table-cell
'identity info
)))))
2433 ;; 3. Valid width cookies must have a specific row.
2434 (org-test-with-parsed-data "| <6> | cell |"
2438 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
2439 (org-element-map tree
'table-cell
'identity
))))))
2441 (ert-deftest test-org-export
/table-cell-alignment
()
2442 "Test `org-export-table-cell-alignment' specifications."
2443 ;; 1. Alignment is primarily determined by alignment cookies.
2445 (equal '(left center right
)
2446 (let ((org-table-number-fraction 0.5)
2447 (org-table-number-regexp "^[0-9]+$"))
2448 (org-test-with-parsed-data "| <l> | <c> | <r> |"
2449 (mapcar (lambda (cell)
2450 (org-export-table-cell-alignment cell info
))
2451 (org-element-map tree
'table-cell
'identity
))))))
2452 ;; 2. The last alignment cookie has precedence.
2454 (equal '(right right right
)
2455 (org-test-with-parsed-data "
2459 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
2460 (org-element-map tree
'table-cell
'identity
)))))
2461 ;; 3. If there's no cookie, cell's contents determine alignment.
2462 ;; A column mostly made of cells containing numbers will align
2463 ;; its cells to the right.
2465 (equal '(right right right
)
2466 (let ((org-table-number-fraction 0.5)
2467 (org-table-number-regexp "^[0-9]+$"))
2468 (org-test-with-parsed-data "
2472 (mapcar (lambda (cell)
2473 (org-export-table-cell-alignment cell info
))
2474 (org-element-map tree
'table-cell
'identity
))))))
2475 ;; 4. Otherwise, they will be aligned to the left.
2477 (equal '(left left left
)
2478 (org-test-with-parsed-data "
2482 (mapcar (lambda (cell)
2483 (org-export-table-cell-alignment cell info
))
2484 (org-element-map tree
'table-cell
'identity info
))))))
2486 (ert-deftest test-org-export
/table-cell-borders
()
2487 "Test `org-export-table-cell-borders' specifications."
2488 ;; 1. Recognize various column groups indicators.
2489 (org-test-with-parsed-data "| / | < | > | <> |"
2492 '((right bottom top
) (left bottom top
) (right bottom top
)
2493 (right left bottom top
))
2494 (mapcar (lambda (cell)
2495 (org-export-table-cell-borders cell info
))
2496 (org-element-map tree
'table-cell
'identity
)))))
2497 ;; 2. Accept shortcuts to define column groups.
2498 (org-test-with-parsed-data "| / | < | < |"
2501 '((right bottom top
) (right left bottom top
) (left bottom top
))
2502 (mapcar (lambda (cell)
2503 (org-export-table-cell-borders cell info
))
2504 (org-element-map tree
'table-cell
'identity
)))))
2505 ;; 3. A valid column groups row must start with a "/".
2506 (org-test-with-parsed-data "
2510 (equal '((top) (top) (bottom) (bottom))
2511 (mapcar (lambda (cell)
2512 (org-export-table-cell-borders cell info
))
2513 (org-element-map tree
'table-cell
'identity
)))))
2514 ;; 4. Take table rules into consideration.
2515 (org-test-with-parsed-data "
2520 (equal '((below top
) (bottom above
))
2521 (mapcar (lambda (cell)
2522 (org-export-table-cell-borders cell info
))
2523 (org-element-map tree
'table-cell
'identity
)))))
2524 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
2525 ;; (resp. `bottom' and `below') borders. Any special row is
2527 (org-test-with-parsed-data "
2533 (equal '((bottom below top above
))
2535 (mapcar (lambda (cell)
2536 (org-export-table-cell-borders cell info
))
2537 (org-element-map tree
'table-cell
'identity
)))))))
2539 (ert-deftest test-org-export
/table-dimensions
()
2540 "Test `org-export-table-dimensions' specifications."
2541 ;; 1. Standard test.
2542 (org-test-with-parsed-data "
2547 (org-export-table-dimensions
2548 (org-element-map tree
'table
'identity info
'first-match
) info
))))
2549 ;; 2. Ignore horizontal rules and special columns.
2550 (org-test-with-parsed-data "
2557 (org-export-table-dimensions
2558 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
2560 (ert-deftest test-org-export
/table-cell-address
()
2561 "Test `org-export-table-cell-address' specifications."
2562 ;; 1. Standard test: index is 0-based.
2563 (org-test-with-parsed-data "| a | b |"
2565 (equal '((0 .
0) (0 .
1))
2566 (org-element-map tree
'table-cell
2567 (lambda (cell) (org-export-table-cell-address cell info
))
2569 ;; 2. Special column isn't counted, nor are special rows.
2570 (org-test-with-parsed-data "
2575 (org-export-table-cell-address
2576 (car (last (org-element-map tree
'table-cell
'identity info
)))
2578 ;; 3. Tables rules do not count either.
2579 (org-test-with-parsed-data "
2587 (org-export-table-cell-address
2588 (car (last (org-element-map tree
'table-cell
'identity info
)))
2590 ;; 4. Return nil for special cells.
2591 (org-test-with-parsed-data "| / | a |"
2593 (org-export-table-cell-address
2594 (org-element-map tree
'table-cell
'identity nil
'first-match
)
2597 (ert-deftest test-org-export
/get-table-cell-at
()
2598 "Test `org-export-get-table-cell-at' specifications."
2599 ;; 1. Address ignores special columns, special rows and rules.
2600 (org-test-with-parsed-data "
2607 (org-element-contents
2608 (org-export-get-table-cell-at
2610 (org-element-map tree
'table
'identity info
'first-match
)
2612 ;; 2. Return value for a non-existent address is nil.
2613 (org-test-with-parsed-data "| a |"
2615 (org-export-get-table-cell-at
2617 (org-element-map tree
'table
'identity info
'first-match
)
2619 (org-test-with-parsed-data "| / |"
2621 (org-export-get-table-cell-at
2623 (org-element-map tree
'table
'identity info
'first-match
)
2626 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
2627 "Test `org-export-table-cell-starts-colgroup-p' specifications."
2628 ;; 1. A cell at a beginning of a row always starts a column group.
2629 (org-test-with-parsed-data "| a |"
2631 (org-export-table-cell-starts-colgroup-p
2632 (org-element-map tree
'table-cell
'identity info
'first-match
)
2634 ;; 2. Special column should be ignored when determining the
2635 ;; beginning of the row.
2636 (org-test-with-parsed-data "
2640 (org-export-table-cell-starts-colgroup-p
2641 (org-element-map tree
'table-cell
'identity info
'first-match
)
2643 ;; 2. Explicit column groups.
2644 (org-test-with-parsed-data "
2650 (org-element-map tree
'table-cell
2652 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
2655 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
2656 "Test `org-export-table-cell-ends-colgroup-p' specifications."
2657 ;; 1. A cell at the end of a row always ends a column group.
2658 (org-test-with-parsed-data "| a |"
2660 (org-export-table-cell-ends-colgroup-p
2661 (org-element-map tree
'table-cell
'identity info
'first-match
)
2663 ;; 2. Special column should be ignored when determining the
2664 ;; beginning of the row.
2665 (org-test-with-parsed-data "
2669 (org-export-table-cell-ends-colgroup-p
2670 (org-element-map tree
'table-cell
'identity info
'first-match
)
2672 ;; 3. Explicit column groups.
2673 (org-test-with-parsed-data "
2679 (org-element-map tree
'table-cell
2681 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
2684 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
2685 "Test `org-export-table-row-starts-rowgroup-p' specifications."
2686 ;; 1. A row at the beginning of a table always starts a row group.
2687 ;; So does a row following a table rule.
2688 (org-test-with-parsed-data "
2695 (org-element-map tree
'table-row
2697 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2699 ;; 2. Special rows should be ignored when determining the beginning
2701 (org-test-with-parsed-data "
2710 (org-element-map tree
'table-row
2712 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
2715 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2716 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2717 ;; 1. A row at the end of a table always ends a row group. So does
2718 ;; a row preceding a table rule.
2719 (org-test-with-parsed-data "
2726 (org-element-map tree
'table-row
2728 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2730 ;; 2. Special rows should be ignored when determining the beginning
2732 (org-test-with-parsed-data "
2741 (org-element-map tree
'table-row
2743 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2746 (ert-deftest test-org-export
/table-row-starts-header-p
()
2747 "Test `org-export-table-row-starts-header-p' specifications."
2748 ;; 1. Only the row starting the first row group starts the table
2750 (org-test-with-parsed-data "
2758 (org-element-map tree
'table-row
2760 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2762 ;; 2. A row cannot start an header if there's no header in the
2764 (org-test-with-parsed-data "
2768 (org-export-table-row-starts-header-p
2769 (org-element-map tree
'table-row
'identity info
'first-match
)
2772 (ert-deftest test-org-export
/table-row-ends-header-p
()
2773 "Test `org-export-table-row-ends-header-p' specifications."
2774 ;; 1. Only the row starting the first row group starts the table
2776 (org-test-with-parsed-data "
2784 (org-element-map tree
'table-row
2786 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2788 ;; 2. A row cannot start an header if there's no header in the
2790 (org-test-with-parsed-data "
2794 (org-export-table-row-ends-header-p
2795 (org-element-map tree
'table-row
'identity info
'first-match
)
2800 ;;; Tables of Contents
2802 (ert-deftest test-org-export
/collect-headlines
()
2803 "Test `org-export-collect-headlines' specifications."
2808 (org-test-with-parsed-data "* H1\n** H2"
2809 (org-export-collect-headlines info
)))))
2810 ;; Do not collect headlines below optional argument.
2814 (org-test-with-parsed-data "* H1\n** H2"
2815 (org-export-collect-headlines info
1)))))
2816 ;; Never collect headlines below maximum headline level.
2820 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2821 (org-export-collect-headlines info
)))))
2825 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
2826 (org-export-collect-headlines info
2))))))
2832 (ert-deftest test-org-export
/inner-template
()
2833 "Test `inner-template' translator specifications."
2836 (org-test-with-temp-text "* Headline"
2838 (org-export-create-backend
2840 '((inner-template .
(lambda (contents info
) "Success!"))
2841 (headline .
(lambda (h c i
) "Headline"))))))))
2842 ;; Inner template is applied even in a "body-only" export.
2845 (org-test-with-temp-text "* Headline"
2847 (org-export-create-backend
2848 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
2849 (headline .
(lambda (h c i
) "Headline"))))
2850 nil nil
'body-only
)))))
2852 (ert-deftest test-org-export
/template
()
2853 "Test `template' translator specifications."
2856 (org-test-with-temp-text "* Headline"
2858 (org-export-create-backend
2859 :transcoders
'((template .
(lambda (contents info
) "Success!"))
2860 (headline .
(lambda (h c i
) "Headline"))))))))
2861 ;; Template is not applied in a "body-only" export.
2864 (org-test-with-temp-text "* Headline"
2866 (org-export-create-backend
2867 :transcoders
'((template .
(lambda (contents info
) "Success!"))
2868 (headline .
(lambda (h c i
) "Headline"))))
2869 nil nil
'body-only
)))))
2875 (ert-deftest test-org-export
/get-next-element
()
2876 "Test `org-export-get-next-element' specifications."
2880 (org-test-with-parsed-data "* Headline\n*a* b"
2881 (org-export-get-next-element
2882 (org-element-map tree
'bold
'identity info t
) info
))))
2883 ;; Return nil when no previous element.
2885 (org-test-with-parsed-data "* Headline\na *b*"
2886 (org-export-get-next-element
2887 (org-element-map tree
'bold
'identity info t
) info
)))
2888 ;; Non-exportable elements are ignored.
2890 (let ((org-export-with-timestamps nil
))
2891 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2892 (org-export-get-next-element
2893 (org-element-map tree
'entity
'identity info t
) info
))))
2894 ;; Find next element in secondary strings.
2897 (org-test-with-parsed-data "* a =verb="
2899 (org-export-get-next-element
2900 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2903 (org-test-with-parsed-data "* /italic/ =verb="
2905 (org-export-get-next-element
2906 (org-element-map tree
'italic
'identity info t
) info
)))))
2907 ;; Find next element in document keywords.
2910 (org-test-with-parsed-data "#+TITLE: a =verb="
2912 (org-export-get-next-element
2914 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2915 ;; Find next element in parsed affiliated keywords.
2918 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2920 (org-export-get-next-element
2921 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2922 ;; With optional argument N, return a list containing all the
2923 ;; following elements.
2926 '(bold code underline
)
2927 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2929 (org-export-get-next-element
2930 (org-element-map tree
'italic
'identity info t
) info t
)))))
2931 ;; When N is a positive integer, return a list containing up to
2932 ;; N following elements.
2936 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2938 (org-export-get-next-element
2939 (org-element-map tree
'italic
'identity info t
) info
2))))))
2941 (ert-deftest test-org-export
/get-previous-element
()
2942 "Test `org-export-get-previous-element' specifications."
2946 (org-test-with-parsed-data "* Headline\na *b*"
2947 (org-export-get-previous-element
2948 (org-element-map tree
'bold
'identity info t
) info
))))
2949 ;; Return nil when no previous element.
2951 (org-test-with-parsed-data "* Headline\n*a* b"
2952 (org-export-get-previous-element
2953 (org-element-map tree
'bold
'identity info t
) info
)))
2954 ;; Non-exportable elements are ignored.
2956 (let ((org-export-with-timestamps nil
))
2957 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2958 (org-export-get-previous-element
2959 (org-element-map tree
'entity
'identity info t
) info
))))
2960 ;; Find previous element in secondary strings.
2963 (org-test-with-parsed-data "* =verb= a"
2965 (org-export-get-previous-element
2966 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2969 (org-test-with-parsed-data "* =verb= /italic/"
2971 (org-export-get-previous-element
2972 (org-element-map tree
'italic
'identity info t
) info
)))))
2973 ;; Find previous element in document keywords.
2976 (org-test-with-parsed-data "#+TITLE: =verb= a"
2978 (org-export-get-previous-element
2980 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2981 ;; Find previous element in parsed affiliated keywords.
2984 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2986 (org-export-get-previous-element
2987 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2988 ;; With optional argument N, return a list containing up to
2989 ;; N previous elements.
2991 (equal '(underline italic bold
)
2992 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2994 (org-export-get-previous-element
2995 (org-element-map tree
'code
'identity info t
) info t
)))))
2996 ;; When N is a positive integer, return a list containing up to
2997 ;; N previous elements.
2999 (equal '(italic bold
)
3000 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3002 (org-export-get-previous-element
3003 (org-element-map tree
'code
'identity info t
) info
2))))))
3007 ;;; test-org-export.el end here