1 ;;; test-ox.el --- Tests for ox.el
3 ;; Copyright (C) 2012-2015 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.
46 DATA is a string containing the data to be parsed. BODY is the
47 body to execute. Parse tree is available under the `tree'
48 variable, and communication channel under `info'."
49 (declare (debug (form body
)) (indent 1))
50 `(org-test-with-temp-text ,data
51 (org-export--delete-comments)
52 (let* ((tree (org-element-parse-buffer))
53 (info (org-export-get-environment)))
54 (org-export--prune-tree tree info
)
55 (org-export--remove-uninterpreted-data tree info
)
56 (let ((info (org-combine-plists
57 info
(org-export-collect-tree-properties tree info
))))
64 (ert-deftest test-org-export
/bind-keyword
()
65 "Test reading #+BIND: keywords."
66 ;; Test with `org-export-allow-bind-keywords' set to t.
68 (org-test-with-temp-text "#+BIND: test-ox-var value"
69 (let ((org-export-allow-bind-keywords t
))
70 (org-export-get-environment)
71 (eq test-ox-var
'value
))))
72 ;; Test with `org-export-allow-bind-keywords' set to nil.
74 (org-test-with-temp-text "#+BIND: test-ox-var value"
75 (let ((org-export-allow-bind-keywords nil
))
76 (org-export-get-environment)
77 (boundp 'test-ox-var
))))
78 ;; BIND keywords are case-insensitive.
80 (org-test-with-temp-text "#+bind: test-ox-var value"
81 (let ((org-export-allow-bind-keywords t
))
82 (org-export-get-environment)
83 (eq test-ox-var
'value
))))
84 ;; Preserve order of BIND keywords.
86 (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
87 (let ((org-export-allow-bind-keywords t
))
88 (org-export-get-environment)
90 ;; Read BIND keywords in setup files.
92 (org-test-with-temp-text
93 (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir
)
94 (let ((org-export-allow-bind-keywords t
))
95 (org-export-get-environment)
96 (eq variable
'value
))))
97 ;; Verify that bound variables are seen during export.
100 (org-test-with-temp-text "#+BIND: test-ox-var value"
101 (let ((org-export-allow-bind-keywords t
))
103 (org-export-create-backend
105 '((section .
(lambda (s c i
)
106 (if (eq test-ox-var
'value
) "Yes" "No")))))))))))
108 (ert-deftest test-org-export
/parse-option-keyword
()
109 "Test reading all standard #+OPTIONS: items."
112 (org-export--parse-option-keyword
113 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
114 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
117 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
118 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
119 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
120 :with-footnotes t
:with-inlinetasks nil
:with-priority t
121 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
122 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
123 :with-title t
:with-todo-keywords t
)))
124 ;; Test some special values.
127 (org-export--parse-option-keyword
128 "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
131 :with-archived-trees headline
:with-drawers
("TEST")
132 :with-sub-superscript
{} :with-toc
1 :with-tags not-in-toc
133 :with-tasks todo
:with-timestamps active
))))
135 (ert-deftest test-org-export
/get-inbuffer-options
()
136 "Test reading all standard export keywords."
137 ;; Properties should follow buffer order.
140 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
141 (org-export--get-inbuffer-options))
142 '(:language
"fr" :creator
"Me" :email
"email")))
143 ;; Test `space' behaviour.
146 (let ((back-end (org-export-create-backend
147 :options
'((:keyword
"KEYWORD" nil nil space
)))))
148 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: spaces"
149 (org-export--get-inbuffer-options back-end
)))
150 '(:keyword
"With spaces")))
151 ;; Test `newline' behaviour.
154 (let ((back-end (org-export-create-backend
155 :options
'((:keyword
"KEYWORD" nil nil newline
)))))
156 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: two lines"
157 (org-export--get-inbuffer-options back-end
)))
158 '(:keyword
"With\ntwo lines")))
159 ;; Test `split' behaviour.
162 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
163 (org-export--get-inbuffer-options))
164 '(:select-tags
("a" "b"))))
165 ;; Test `parse' behaviour. `parse' implies `space' but preserve
166 ;; line breaks. Multi-line objects are allowed.
169 (org-test-with-temp-text "#+TITLE: *bold*"
170 (plist-get (org-export--get-inbuffer-options) :title
))
171 'bold
#'identity nil t
))
174 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
175 (plist-get (org-export--get-inbuffer-options) :title
))
176 '("Some title with spaces")))
179 (org-test-with-temp-text "#+TITLE: Some title\\\\\n#+TITLE: with spaces"
180 (plist-get (org-export--get-inbuffer-options) :title
))
181 'line-break
#'identity nil t
))
184 (org-test-with-temp-text "#+TITLE: *bold\n#+TITLE: sentence*"
185 (plist-get (org-export--get-inbuffer-options) :title
))
186 'bold
#'identity nil t
))
187 ;; Options set through SETUPFILE.
190 (org-test-with-temp-text
191 (format "#+DESCRIPTION: l1
195 #+SETUPFILE: \"%s/examples/setupfile.org\"
200 (org-export--get-inbuffer-options))
201 '(:language
"fr" :select-tags
("a" "b" "c") :title
("a b c"))))
202 ;; More than one property can refer to the same buffer keyword.
204 (equal '(:k2
"value" :k1
"value")
205 (let ((backend (org-export-create-backend
206 :options
'((:k1
"KEYWORD")
208 (org-test-with-temp-text "#+KEYWORD: value"
209 (org-export--get-inbuffer-options backend
)))))
210 ;; Keywords in commented subtrees are ignored.
213 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
214 (plist-get info
:author
))))
217 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
218 (plist-get info
:email
)))))
220 (ert-deftest test-org-export
/get-subtree-options
()
221 "Test setting options from headline's properties."
223 (org-test-with-temp-text "#+TITLE: Title
226 :EXPORT_TITLE: Subtree Title
230 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
231 '("Subtree Title"))))
235 (org-test-with-temp-text "#+OPTIONS: H:1
243 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
245 (org-test-with-temp-text "#+DATE: today
248 :EXPORT_DATE: 29-03-2012
252 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
254 ;; Properties with `split' behaviour are stored as a list of
258 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
261 :EXPORT_EXCLUDE_TAGS: a b
266 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
267 ;; Handle :PROPERTY+: syntax.
270 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
273 :EXPORT_EXCLUDE_TAGS: a
274 :EXPORT_EXCLUDE_TAGS+: b
279 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
280 ;; Export properties are case-insensitive.
281 (org-test-with-temp-text "* Headline
283 :EXPORT_Date: 29-03-2012
286 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
288 ;; Still grab correct options when section above is empty.
291 (org-test-with-temp-text "* H1\n** H11\n** H12"
292 (progn (forward-line 2)
293 (plist-get (org-export-get-environment nil t
) :title
))))))
295 (ert-deftest test-org-export
/set-title
()
296 "Test title setting."
297 ;; Without TITLE keyword.
301 (let (org-export-filter-body-functions
302 org-export-filter-final-output-functions
)
303 (org-test-with-temp-text "Test"
305 (org-export-create-backend
307 '((template .
(lambda (text info
)
308 (org-element-interpret-data
309 (plist-get info
:title
)))))))))))
310 ;; With a blank TITLE keyword.
314 (let (org-export-filter-body-functions
315 org-export-filter-final-output-functions
)
316 (org-test-with-temp-text "#+TITLE:\nTest"
318 (org-export-create-backend
320 '((template .
(lambda (text info
)
321 (org-element-interpret-data
322 (plist-get info
:title
)))))))))))
323 ;; With a non-empty TITLE keyword.
327 (org-test-with-temp-text "#+TITLE: Title\nTest"
329 (org-export-create-backend
331 '((template .
(lambda (text info
)
332 (org-element-interpret-data
333 (plist-get info
:title
))))))))))
334 ;; When exporting a subtree, its heading becomes the headline of the
339 (org-test-with-temp-text "* Headline\nBody"
341 (org-export-create-backend
343 '((template .
(lambda (text info
)
344 (org-element-interpret-data
345 (plist-get info
:title
))))))
347 ;; ... unless there is an EXPORT_TITLE property at the root of the
352 (org-test-with-temp-text
353 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
355 (org-export-create-backend
357 '((template .
(lambda (text info
)
358 (org-element-interpret-data
359 (plist-get info
:title
))))))
362 (ert-deftest test-org-export
/handle-options
()
363 "Test if export options have an impact on output."
364 ;; Test exclude tags for headlines and inlinetasks.
367 (let (org-export-filter-body-functions
368 org-export-filter-final-output-functions
)
369 (org-test-with-temp-text "* Head1 :noexp:"
370 (org-export-as (org-test-default-backend)
371 nil nil nil
'(:exclude-tags
("noexp")))))))
372 ;; Test include tags for headlines and inlinetasks.
374 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
375 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
376 (let ((org-tags-column 0))
377 (org-export-as (org-test-default-backend)
378 nil nil nil
'(:select-tags
("exp")))))))
379 ;; If there is an include tag, ignore the section before the first
382 (equal "* H1 :exp:\nBody\n"
383 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
384 (let ((org-tags-column 0))
385 (org-export-as (org-test-default-backend)
386 nil nil nil
'(:select-tags
("exp")))))))
388 (equal "* H1 :exp:\n"
389 (org-test-with-temp-text "* H1 :exp:\nBody"
390 (let ((org-tags-column 0))
391 (org-export-as (org-test-default-backend)
392 nil nil nil
'(:select-tags
("exp")))))))
393 ;; Test mixing include tags and exclude tags.
396 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
397 (org-test-with-temp-text "
399 ** Sub-Head1 :noexport:
402 ** Sub-Head1 :export:"
403 (org-export-as (org-test-default-backend) nil nil nil
404 '(:select-tags
("export") :exclude-tags
("noexport"))))))
408 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
409 org-export-filter-body-functions
410 org-export-filter-final-output-functions
)
411 (org-test-with-temp-text "* TODO Head1"
412 (org-export-as (org-test-default-backend)
413 nil nil nil
'(:with-tasks nil
))))))
415 (equal "* TODO Head1\n"
416 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
417 (org-test-with-temp-text "* TODO Head1"
418 (org-export-as (org-test-default-backend)
419 nil nil nil
'(:with-tasks t
))))))
423 (let (org-export-filter-body-functions
424 org-export-filter-final-output-functions
)
425 (org-test-with-temp-text "* Head1 :archive:"
426 (let ((org-archive-tag "archive"))
427 (org-export-as (org-test-default-backend)
428 nil nil nil
'(:with-archived-trees nil
)))))))
431 "\\* Head1[ \t]+:archive:"
432 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
433 (let ((org-archive-tag "archive"))
434 (org-export-as (org-test-default-backend) nil nil nil
435 '(:with-archived-trees headline
))))))
438 "\\`\\* Head1[ \t]+:archive:\n\\'"
439 (org-test-with-temp-text "* Head1 :archive:"
440 (let ((org-archive-tag "archive"))
441 (org-export-as (org-test-default-backend)
442 nil nil nil
'(:with-archived-trees t
))))))
445 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
446 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
447 (org-export-as (org-test-default-backend)
448 nil nil nil
'(:with-clocks t
)))))
451 (let (org-export-filter-body-functions
452 org-export-filter-final-output-functions
)
453 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
454 (org-export-as (org-test-default-backend)
455 nil nil nil
'(:with-clocks nil
))))))
459 (let (org-export-filter-body-functions
460 org-export-filter-final-output-functions
)
461 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
462 (org-export-as (org-test-default-backend)
463 nil nil nil
'(:with-drawers nil
))))))
465 (equal ":TEST:\ncontents\n:END:\n"
466 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
467 (org-export-as (org-test-default-backend)
468 nil nil nil
'(:with-drawers t
)))))
470 (equal ":FOO:\nkeep\n:END:\n"
471 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-drawers
("FOO"))))))
475 (equal ":FOO:\nkeep\n:END:\n"
476 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
477 (org-export-as (org-test-default-backend)
478 nil nil nil
'(:with-drawers
(not "BAR"))))))
482 (org-test-with-temp-text ": A"
483 (org-export-as (org-test-default-backend) nil nil nil
484 '(:with-fixed-width t
)))))
487 (let (org-export-filter-body-functions
488 org-export-filter-final-output-functions
)
489 (org-test-with-temp-text ": A"
490 (org-export-as (org-test-default-backend) nil nil nil
491 '(:with-fixed-width nil
))))))
495 (let ((org-footnote-section nil
))
496 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
497 (org-trim (org-export-as (org-test-default-backend)
498 nil nil nil
'(:with-footnotes nil
)))))))
500 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
501 (let ((org-footnote-section nil
))
502 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
503 (org-trim (org-export-as (org-test-default-backend)
504 nil nil nil
'(:with-footnotes t
)))))))
506 (when (featurep 'org-inlinetask
)
510 (let ((org-inlinetask-min-level 15)
511 org-export-filter-body-functions
512 org-export-filter-final-output-functions
)
513 (org-test-with-temp-text "*************** Task"
514 (org-export-as (org-test-default-backend)
515 nil nil nil
'(:with-inlinetasks nil
))))))
519 (let ((org-inlinetask-min-level 15)
520 org-export-filter-body-functions
521 org-export-filter-final-output-functions
)
522 (org-test-with-temp-text
523 "*************** Task\nContents\n*************** END"
524 (org-export-as (org-test-default-backend)
525 nil nil nil
'(:with-inlinetasks nil
)))))))
529 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
530 (let ((org-closed-string "CLOSED:"))
531 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
532 (org-export-as (org-test-default-backend)
533 nil nil nil
'(:with-planning t
))))))
536 (let ((org-closed-string "CLOSED:"))
537 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
538 (org-export-as (org-test-default-backend)
539 nil nil nil
'(:with-planning nil
))))))
543 (org-test-with-temp-text
544 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
545 (org-export-as (org-test-default-backend)
546 nil nil nil
'(:with-properties nil
)))))
548 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
549 (org-test-with-temp-text
550 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
551 (org-export-as (org-test-default-backend)
552 nil nil nil
'(:with-properties t
)))))
554 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
555 (org-test-with-temp-text
556 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
557 (org-export-as (org-test-default-backend)
558 nil nil nil
'(:with-properties
("B"))))))
559 ;; Statistics cookies.
562 (let (org-export-filter-body-functions
563 org-export-filter-final-output-functions
)
565 (org-test-with-temp-text "[0/0]"
566 (org-export-as (org-test-default-backend)
567 nil nil nil
'(:with-statistics-cookies nil
)))))))
571 (org-test-with-temp-text "| A |"
572 (org-export-as (org-test-default-backend) nil nil nil
573 '(:with-tables t
)))))
576 (let (org-export-filter-body-functions
577 org-export-filter-final-output-functions
)
578 (org-test-with-temp-text "| A |"
579 (org-export-as (org-test-default-backend) nil nil nil
580 '(:with-tables nil
)))))))
582 (ert-deftest test-org-export
/with-timestamps
()
583 "Test `org-export-with-timestamps' specifications."
587 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
588 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
589 (org-export-as (org-test-default-backend)
590 nil nil nil
'(:with-timestamps t
)))))
595 (let (org-export-filter-body-functions
596 org-export-filter-final-output-functions
)
598 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
599 (org-export-as (org-test-default-backend)
600 nil nil nil
'(:with-timestamps nil
)))))))
604 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
605 (org-test-with-temp-text
606 "<2012-03-29 Thu>[2012-03-29 Thu]
608 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
609 (org-export-as (org-test-default-backend)
610 nil nil nil
'(:with-timestamps active
)))))
614 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
615 (org-test-with-temp-text
616 "<2012-03-29 Thu>[2012-03-29 Thu]
618 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
619 (org-export-as (org-test-default-backend)
620 nil nil nil
'(:with-timestamps inactive
))))))
622 (ert-deftest test-org-export
/comment-tree
()
623 "Test if export process ignores commented trees."
626 (let (org-export-filter-body-functions
627 org-export-filter-final-output-functions
)
628 (org-test-with-temp-text "* COMMENT Head1"
629 (org-export-as (org-test-default-backend)))))))
631 (ert-deftest test-org-export
/uninterpreted
()
632 "Test handling of uninterpreted elements."
636 (org-test-with-temp-text "\\alpha"
638 (org-export-create-backend
639 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
640 (paragraph .
(lambda (p c i
) c
))
641 (section .
(lambda (s c i
) c
))))
642 nil nil nil
'(:with-entities t
)))))
645 (org-test-with-temp-text "\\alpha"
647 (org-export-create-backend
648 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
649 (paragraph .
(lambda (p c i
) c
))
650 (section .
(lambda (s c i
) c
))))
651 nil nil nil
'(:with-entities nil
)))))
655 (org-test-with-temp-text "*bold*"
657 (org-export-create-backend
658 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
659 (paragraph .
(lambda (p c i
) c
))
660 (section .
(lambda (s c i
) c
))))
661 nil nil nil
'(:with-emphasize t
)))))
664 (org-test-with-temp-text "*bold*"
666 (org-export-create-backend
667 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
668 (paragraph .
(lambda (p c i
) c
))
669 (section .
(lambda (s c i
) c
))))
670 nil nil nil
'(:with-emphasize nil
)))))
671 ;; LaTeX environment.
674 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
676 (org-export-create-backend
677 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
678 (section .
(lambda (s c i
) c
))))
679 nil nil nil
'(:with-latex t
)))))
681 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
682 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
684 (org-export-create-backend
685 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
686 (section .
(lambda (s c i
) c
))))
687 nil nil nil
'(:with-latex verbatim
)))))
691 (org-test-with-temp-text "$1$"
693 (org-export-create-backend
694 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
695 (paragraph .
(lambda (p c i
) c
))
696 (section .
(lambda (s c i
) c
))))
697 nil nil nil
'(:with-latex t
)))))
700 (org-test-with-temp-text "$1$"
702 (org-export-create-backend
703 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
704 (paragraph .
(lambda (p c i
) c
))
705 (section .
(lambda (s c i
) c
))))
706 nil nil nil
'(:with-latex verbatim
)))))
710 (org-test-with-temp-text "a_b"
712 (org-export-create-backend
713 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
714 (paragraph .
(lambda (p c i
) c
))
715 (section .
(lambda (s c i
) c
))))
716 nil nil nil
'(:with-sub-superscript t
)))))
719 (org-test-with-temp-text "a_b"
721 (org-export-create-backend
722 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
723 (paragraph .
(lambda (p c i
) c
))
724 (section .
(lambda (s c i
) c
))))
725 nil nil nil
'(:with-sub-superscript nil
)))))
728 (org-test-with-temp-text "a_b"
730 (org-export-create-backend
731 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
732 (paragraph .
(lambda (p c i
) c
))
733 (section .
(lambda (s c i
) c
))))
734 nil nil nil
'(:with-sub-superscript
{})))))
737 (org-test-with-temp-text "a_{b}"
739 (org-export-create-backend
740 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
741 (paragraph .
(lambda (p c i
) c
))
742 (section .
(lambda (s c i
) c
))))
743 nil nil nil
'(:with-sub-superscript
{})))))
744 ;; Also handle uninterpreted objects in title.
747 (org-test-with-temp-text "#+TITLE: a_b"
749 (org-export-create-backend
751 '((subscript .
(lambda (s c i
) "dummy"))
752 (template .
(lambda (c i
) (org-export-data
753 (plist-get i
:title
) i
)))
754 (section .
(lambda (s c i
) c
))))
755 nil nil nil
'(:with-sub-superscript nil
)))))
756 ;; Special case: multiples uninterpreted objects in a row.
759 (org-test-with-temp-text "a_b_c_d"
761 (org-export-create-backend
762 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
763 (paragraph .
(lambda (p c i
) c
))
764 (section .
(lambda (s c i
) c
))))
765 nil nil nil
'(:with-sub-superscript
{}))))))
767 (ert-deftest test-org-export
/export-scope
()
768 "Test all export scopes."
769 (org-test-with-temp-text "
776 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
777 "text\n*** Head3\n"))
779 (goto-char (point-min))
782 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
785 (goto-char (point-min))
787 (transient-mark-mode 1)
788 (push-mark (point) t t
)
789 (goto-char (point-at-eol))
790 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
791 ;; Subtree with a code block calling another block outside.
792 (let ((org-export-babel-evaluate t
))
795 (org-test-with-temp-text "
797 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
802 #+BEGIN_SRC emacs-lisp
806 (org-export-as (org-test-default-backend) 'subtree
)))))
808 (let ((backend (org-test-default-backend)))
809 (setf (org-export-backend-transcoders backend
)
810 (cons '(template .
(lambda (body i
)
811 (format "BEGIN\n%sEND" body
)))
812 (org-export-backend-transcoders backend
)))
813 (org-test-with-temp-text "Text"
814 (should (equal (org-export-as backend nil nil
'body-only
)
816 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
818 (ert-deftest test-org-export
/output-file-name
()
819 "Test `org-export-output-file-name' specifications."
820 ;; Export from a file: name is built from original file name.
822 (org-test-with-temp-text-in-file "Test"
823 (equal (concat (file-name-as-directory ".")
824 (file-name-nondirectory
825 (file-name-sans-extension (buffer-file-name))))
826 (file-name-sans-extension (org-export-output-file-name ".ext")))))
827 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
829 (org-test-with-temp-text-in-file
830 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
831 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
832 ;; From a buffer not associated to a file, too.
834 (org-test-with-temp-text
835 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
836 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
837 ;; When provided name is absolute, preserve it.
839 (org-test-with-temp-text
840 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
841 (expand-file-name "test"))
842 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
843 ;; When PUB-DIR argument is provided, use it.
845 (org-test-with-temp-text-in-file "Test"
846 (equal (file-name-directory
847 (org-export-output-file-name ".ext" nil
"dir/"))
849 ;; When returned name would overwrite original file, add EXTENSION
852 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
853 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
855 (ert-deftest test-org-export
/expand-include
()
856 "Test file inclusion in an Org buffer."
857 ;; Error when file isn't specified.
859 (org-test-with-temp-text "#+INCLUDE: dummy.org"
860 (org-export-expand-include-keyword)))
861 ;; Full insertion with recursive inclusion.
866 (expand-file-name "examples/include.org" org-test-dir
))
867 (replace-regexp-in-string
868 (regexp-quote "#+INCLUDE: \"include2.org\"")
869 "Success!" (buffer-string)))
870 (org-test-with-temp-text
871 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
872 (org-export-expand-include-keyword)
874 ;; Localized insertion.
875 (org-test-with-temp-text
876 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
878 (org-export-expand-include-keyword)
879 (should (equal (buffer-string)
880 "Small Org file with an include keyword.\n")))
881 ;; Insertion with constraints on headlines level.
884 "* Top heading\n** Heading\nbody\n"
885 (org-test-with-temp-text
887 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
889 (org-export-expand-include-keyword)
893 "* Top heading\n* Heading\nbody\n"
894 (org-test-with-temp-text
896 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
898 (org-export-expand-include-keyword)
900 ;; Inclusion within an example block.
903 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
904 (org-test-with-temp-text
905 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
907 (org-export-expand-include-keyword)
909 ;; Inclusion within a src-block.
912 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
913 (org-test-with-temp-text
915 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
917 (org-export-expand-include-keyword)
919 ;; Inclusion within an html export-block.
922 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
923 (org-test-with-temp-text
925 "#+INCLUDE: \"%s/examples/include.html\" HTML"
927 (org-export-expand-include-keyword)
929 ;; Inclusion within an center paragraph
932 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
933 (org-test-with-temp-text
935 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
937 (org-export-expand-include-keyword)
939 ;; Footnotes labels are local to each included file.
945 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
947 \[fn:test] Footnote \"test\""))
948 (org-test-with-temp-text-in-file contents
949 (let ((file1 (buffer-file-name)))
950 (org-test-with-temp-text-in-file contents
951 (let ((file2 (buffer-file-name)))
952 (org-test-with-temp-text
953 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
955 (org-export-expand-include-keyword)
956 (org-element-map (org-element-parse-buffer)
959 (org-element-property :label ref
)))))))))))))
960 ;; Footnotes labels are not local to each include keyword.
966 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
969 \[fn:test] Footnote \"test\""))
970 (org-test-with-temp-text-in-file contents
971 (let ((file (buffer-file-name)))
972 (org-test-with-temp-text
973 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
974 (org-export-expand-include-keyword)
975 (org-element-map (org-element-parse-buffer)
977 (lambda (ref) (org-element-property :label ref
)))))))))))
978 ;; Footnotes are supported by :lines-like elements and unnecessary
979 ;; footnotes are dropped.
988 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
993 \[fn:test] Footnote \"test\"
996 (org-test-with-temp-text-in-file contents
997 (let ((file (buffer-file-name)))
998 (org-test-with-temp-text
999 (format "#+INCLUDE: \"%s::*bar\"
1001 (org-export-expand-include-keyword)
1002 (org-element-map (org-element-parse-buffer)
1003 'footnote-definition
1004 (lambda (ref) (org-element-property :label ref
)))))))))))
1005 ;; If only-contents is non-nil only include contents of element.
1009 (org-test-with-temp-text
1011 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
1013 (org-export-expand-include-keyword)
1015 ;; Headings can be included via CUSTOM_ID.
1017 (org-test-with-temp-text
1018 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1019 (org-export-expand-include-keyword)
1020 (goto-char (point-min))
1021 (looking-at "* Another heading")))
1022 ;; Named objects can be included.
1026 (org-test-with-temp-text
1027 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
1028 (org-export-expand-include-keyword)
1030 ;; Including non-existing elements should result in an error.
1032 (org-test-with-temp-text
1033 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
1034 (org-export-expand-include-keyword)))
1035 ;; Lines work relatively to an included element.
1039 (org-test-with-temp-text
1040 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
1041 (org-export-expand-include-keyword)
1043 ;; Properties should be dropped from headlines.
1046 (org-test-with-temp-text
1047 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
1048 (org-export-expand-include-keyword)
1050 (org-test-with-temp-text
1051 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1052 (org-export-expand-include-keyword)
1054 ;; Properties should be dropped, drawers should not be.
1057 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1058 (org-test-with-temp-text
1059 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
1060 (org-export-expand-include-keyword)
1062 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1064 (org-every (lambda (level) (zerop (1- level
)))
1065 (org-test-with-temp-text
1067 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir
)
1068 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir
))
1069 (org-export-expand-include-keyword)
1070 (org-element-map (org-element-parse-buffer) 'headline
1071 (lambda (head) (org-element-property :level head
))))))
1072 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1075 (org-test-with-temp-text
1076 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir
)
1077 (org-export-expand-include-keyword)
1079 (org-test-with-temp-text
1080 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir
)
1081 (org-export-expand-include-keyword)
1083 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1085 (org-test-with-temp-text-in-file
1086 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1087 (narrow-to-region (point) (point-max))
1088 (org-export-expand-include-keyword)
1089 (eq 1 (org-current-level))))
1090 ;; If :minlevel is present do not alter it.
1092 (org-test-with-temp-text
1093 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir
)
1094 (narrow-to-region (point) (point-max))
1095 (org-export-expand-include-keyword)
1096 (eq 3 (org-current-level)))))
1098 (ert-deftest test-org-export
/expand-macro
()
1099 "Test macro expansion in an Org buffer."
1100 ;; Standard macro expansion.
1102 (equal "#+MACRO: macro1 value\nvalue\n"
1103 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1104 (org-export-as (org-test-default-backend)))))
1105 ;; Allow macro in parsed keywords and associated properties.
1106 ;; Standard macro expansion.
1110 (let ((backend (org-export-create-backend
1112 :options
'((:k
"K" nil nil parse
)))))
1113 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1114 (org-export-as backend
)))))
1118 (let ((backend (org-export-create-backend
1120 :options
'((:k
"K" nil nil parse
)))))
1121 (org-test-with-temp-text
1122 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1123 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1124 ;; Expand specific macros.
1126 (equal "me 2012-03-29 me@here Title\n"
1127 (org-test-with-temp-text
1133 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1134 (let ((output (org-export-as (org-test-default-backend))))
1135 (substring output
(string-match ".*\n\\'" output
))))))
1136 ;; Expand specific macros when property contained a regular macro
1140 (org-test-with-temp-text "
1141 #+MACRO: macro1 value
1142 #+TITLE: {{{macro1}}}
1144 (let ((output (org-export-as (org-test-default-backend))))
1145 (substring output
(string-match ".*\n\\'" output
))))))
1146 ;; Expand macros with templates in included files.
1149 (org-test-with-temp-text
1150 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1151 {{{included-macro}}}" org-test-dir
)
1152 (let ((output (org-export-as (org-test-default-backend))))
1153 (substring output
(string-match ".*\n\\'" output
))))))
1154 ;; Date macro takes a optional formatting argument
1157 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1158 (org-export-as (org-test-default-backend)))))
1159 ;; Only single timestamps are formatted
1161 (equal "<2015-02x-09>\n"
1162 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1163 (org-export-as (org-test-default-backend)))))
1164 ;; Throw an error when a macro definition is missing.
1166 (org-test-with-temp-text "{{{missing}}}"
1167 (org-export-as (org-test-default-backend))))
1168 ;; Macros defined in commented subtrees are ignored.
1170 (org-test-with-temp-text
1171 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1172 (org-export-as (org-test-default-backend))))
1174 (org-test-with-temp-text
1175 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1176 (org-export-as (org-test-default-backend)))))
1178 (ert-deftest test-org-export
/before-processing-hook
()
1179 "Test `org-export-before-processing-hook'."
1182 "#+MACRO: mac val\nTest\n"
1183 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1184 (let ((org-export-before-processing-hook
1186 (while (re-search-forward "{{{" nil t
)
1187 (let ((object (org-element-context)))
1188 (when (eq (org-element-type object
) 'macro
)
1190 (org-element-property :begin object
)
1191 (org-element-property :end object
)))))))))
1192 (org-export-as (org-test-default-backend)))))))
1194 (ert-deftest test-org-export
/before-parsing-hook
()
1195 "Test `org-export-before-parsing-hook'."
1197 (equal "Body 1\nBody 2\n"
1198 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1199 (let ((org-export-before-parsing-hook
1201 (goto-char (point-min))
1202 (while (re-search-forward org-outline-regexp-bol nil t
)
1204 (point-at-bol) (progn (forward-line) (point))))))))
1205 (org-export-as (org-test-default-backend)))))))
1209 ;;; Affiliated Keywords
1211 (ert-deftest test-org-export
/read-attribute
()
1212 "Test `org-export-read-attribute' specifications."
1216 (org-export-read-attribute
1218 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1219 (org-element-at-point)))
1221 ;; Return nil on empty attribute.
1223 (org-export-read-attribute
1225 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1226 ;; Return nil on "nil" string.
1228 (equal '(:a nil
:b nil
)
1229 (org-export-read-attribute
1231 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1232 (org-element-at-point)))))
1233 ;; Return nil on empty string.
1235 (equal '(:a nil
:b nil
)
1236 (org-export-read-attribute
1238 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1239 (org-element-at-point)))))
1240 ;; Return empty string when value is "".
1243 (org-export-read-attribute
1245 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1246 (org-element-at-point)))))
1247 ;; Return \"\" when value is """".
1250 (org-export-read-attribute
1252 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1253 (org-element-at-point)))))
1254 ;; Ignore text before first property.
1257 (org-export-read-attribute
1259 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1260 (org-element-at-point))))))
1262 (ert-deftest test-org-export
/get-caption
()
1263 "Test `org-export-get-caption' specifications."
1264 ;; Without optional argument, return long caption
1268 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1269 (org-export-get-caption (org-element-at-point)))))
1270 ;; With optional argument, return short caption.
1274 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1275 (org-export-get-caption (org-element-at-point) t
))))
1276 ;; Multiple lines are separated by white spaces.
1280 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1281 (org-export-get-caption (org-element-at-point))))))
1287 (ert-deftest test-org-export
/define-backend
()
1288 "Test back-end definition and accessors."
1291 (equal '((headline . my-headline-test
))
1292 (let (org-export--registered-backends)
1293 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1294 (org-export-get-all-transcoders 'test
))))
1297 (equal '((:filter-headline . my-filter
))
1298 (let (org-export--registered-backends)
1299 (org-export-define-backend 'test
1300 '((headline . my-headline-test
))
1301 :filters-alist
'((:filter-headline . my-filter
)))
1302 (org-export-backend-filters (org-export-get-backend 'test
)))))
1305 (equal '((:prop value
))
1306 (let (org-export--registered-backends)
1307 (org-export-define-backend 'test
1308 '((headline . my-headline-test
))
1309 :options-alist
'((:prop value
)))
1310 (org-export-backend-options (org-export-get-backend 'test
)))))
1313 (equal '(?k
"Test Export" test
)
1314 (let (org-export--registered-backends)
1315 (org-export-define-backend 'test
1316 '((headline . my-headline-test
))
1317 :menu-entry
'(?k
"Test Export" test
))
1318 (org-export-backend-menu (org-export-get-backend 'test
)))))
1321 (equal '(("TEST" . org-element-export-block-parser
))
1322 (let (org-export--registered-backends org-element-block-name-alist
)
1323 (org-export-define-backend 'test
1324 '((headline . my-headline-test
))
1325 :export-block
'("test"))
1326 org-element-block-name-alist
))))
1328 (ert-deftest test-org-export
/define-derived-backend
()
1329 "Test `org-export-define-derived-backend' specifications."
1330 ;; Error when parent back-end is not defined.
1332 (let (org-export--registered-backends)
1333 (org-export-define-derived-backend 'test
'parent
)))
1334 ;; Append translation table to parent's.
1336 (equal '((:headline . test
) (:headline . parent
))
1337 (let (org-export--registered-backends)
1338 (org-export-define-backend 'parent
'((:headline . parent
)))
1339 (org-export-define-derived-backend 'test
'parent
1340 :translate-alist
'((:headline . test
)))
1341 (org-export-get-all-transcoders 'test
))))
1342 ;; Options defined in the new back have priority over those defined
1346 (let (org-export--registered-backends)
1347 (org-export-define-backend 'parent
1348 '((:headline . parent
))
1349 :options-alist
'((:a nil nil
'parent
)))
1350 (org-export-define-derived-backend 'test
'parent
1351 :options-alist
'((:a nil nil
'test
)))
1352 (plist-get (org-export--get-global-options
1353 (org-export-get-backend 'test
))
1356 (ert-deftest test-org-export
/derived-backend-p
()
1357 "Test `org-export-derived-backend-p' specifications."
1358 ;; Non-nil with direct match.
1360 (let (org-export--registered-backends)
1361 (org-export-define-backend 'test
'((headline . test
)))
1362 (org-export-derived-backend-p 'test
'test
)))
1364 (let (org-export--registered-backends)
1365 (org-export-define-backend 'test
'((headline . test
)))
1366 (org-export-define-derived-backend 'test2
'test
)
1367 (org-export-derived-backend-p 'test2
'test2
)))
1368 ;; Non-nil with a direct parent.
1370 (let (org-export--registered-backends)
1371 (org-export-define-backend 'test
'((headline . test
)))
1372 (org-export-define-derived-backend 'test2
'test
)
1373 (org-export-derived-backend-p 'test2
'test
)))
1374 ;; Non-nil with an indirect parent.
1376 (let (org-export--registered-backends)
1377 (org-export-define-backend 'test
'((headline . test
)))
1378 (org-export-define-derived-backend 'test2
'test
)
1379 (org-export-define-derived-backend 'test3
'test2
)
1380 (org-export-derived-backend-p 'test3
'test
)))
1383 (let (org-export--registered-backends)
1384 (org-export-define-backend 'test
'((headline . test
)))
1385 (org-export-define-backend 'test2
'((headline . test2
)))
1386 (org-export-derived-backend-p 'test2
'test
)))
1388 (let (org-export--registered-backends)
1389 (org-export-define-backend 'test
'((headline . test
)))
1390 (org-export-define-backend 'test2
'((headline . test2
)))
1391 (org-export-define-derived-backend 'test3
'test2
)
1392 (org-export-derived-backend-p 'test3
'test
))))
1394 (ert-deftest test-org-export
/get-all-transcoders
()
1395 "Test `org-export-get-all-transcoders' specifications."
1396 ;; Return nil when back-end cannot be found.
1397 (should-not (org-export-get-all-transcoders nil
))
1398 ;; Same as `org-export-transcoders' if no parent.
1400 (equal '((headline . ignore
))
1401 (org-export-get-all-transcoders
1402 (org-export-create-backend
1403 :transcoders
'((headline . ignore
))))))
1404 ;; But inherit from all ancestors whenever possible.
1406 (equal '((section . ignore
) (headline . ignore
))
1407 (let (org-export--registered-backends)
1408 (org-export-define-backend 'b1
'((headline . ignore
)))
1409 (org-export-get-all-transcoders
1410 (org-export-create-backend
1411 :parent
'b1
:transcoders
'((section . ignore
)))))))
1413 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1414 (let (org-export--registered-backends)
1415 (org-export-define-backend 'b1
'((headline . ignore
)))
1416 (org-export-define-derived-backend 'b2
'b1
1417 :translate-alist
'((section . ignore
)))
1418 (org-export-get-all-transcoders
1419 (org-export-create-backend
1420 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1421 ;; Back-end transcoders overrule inherited ones.
1424 (let (org-export--registered-backends)
1425 (org-export-define-backend 'b1
'((headline . a
)))
1426 (cdr (assq 'headline
1427 (org-export-get-all-transcoders
1428 (org-export-create-backend
1429 :parent
'b1
:transcoders
'((headline . b
))))))))))
1431 (ert-deftest test-org-export
/get-all-options
()
1432 "Test `org-export-get-all-options' specifications."
1433 ;; Return nil when back-end cannot be found.
1434 (should-not (org-export-get-all-options nil
))
1435 ;; Same as `org-export-options' if no parent.
1437 (equal '((headline . ignore
))
1438 (org-export-get-all-options
1439 (org-export-create-backend
1440 :options
'((headline . ignore
))))))
1441 ;; But inherit from all ancestors whenever possible.
1443 (equal '((:key2 value2
) (:key1 value1
))
1444 (let (org-export--registered-backends)
1445 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1446 (org-export-get-all-options
1447 (org-export-create-backend
1448 :parent
'b1
:options
'((:key2 value2
)))))))
1450 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1451 (let (org-export--registered-backends)
1452 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1453 (org-export-define-derived-backend 'b2
'b1
1454 :options-alist
'((:key2 value2
)))
1455 (org-export-get-all-options
1456 (org-export-create-backend
1457 :parent
'b2
:options
'((:key3 value3
)))))))
1458 ;; Back-end options overrule inherited ones.
1461 (let (org-export--registered-backends)
1462 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1464 (org-export-get-all-options
1465 (org-export-create-backend
1466 :parent
'b1
:options
'((:key1 . b
))))))))))
1468 (ert-deftest test-org-export
/get-all-filters
()
1469 "Test `org-export-get-all-filters' specifications."
1470 ;; Return nil when back-end cannot be found.
1471 (should-not (org-export-get-all-filters nil
))
1472 ;; Same as `org-export-filters' if no parent.
1474 (equal '((:filter-headline . ignore
))
1475 (org-export-get-all-filters
1476 (org-export-create-backend
1477 :filters
'((:filter-headline . ignore
))))))
1478 ;; But inherit from all ancestors whenever possible.
1480 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1481 (let (org-export--registered-backends)
1482 (org-export-define-backend 'b1
1483 nil
:filters-alist
'((:filter-headline . ignore
)))
1484 (org-export-get-all-filters
1485 (org-export-create-backend
1486 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1488 (equal '((:filter-paragraph . ignore
)
1489 (:filter-section . ignore
)
1490 (:filter-headline . ignore
))
1491 (let (org-export--registered-backends)
1492 (org-export-define-backend 'b1
1493 nil
:filters-alist
'((:filter-headline . ignore
)))
1494 (org-export-define-derived-backend 'b2
'b1
1495 :filters-alist
'((:filter-section . ignore
)))
1496 (org-export-get-all-filters
1497 (org-export-create-backend
1498 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1499 ;; Back-end filters overrule inherited ones.
1502 (let (org-export--registered-backends)
1503 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1504 (cdr (assq :filter-headline
1505 (org-export-get-all-filters
1506 (org-export-create-backend
1507 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1509 (ert-deftest test-org-export
/with-backend
()
1510 "Test `org-export-with-backend' definition."
1511 ;; Error when calling an undefined back-end
1512 (should-error (org-export-with-backend nil
"Test"))
1513 ;; Error when called back-end doesn't have an appropriate
1516 (org-export-with-backend
1517 (org-export-create-backend :transcoders
'((headline . ignore
)))
1519 ;; Otherwise, export using correct transcoder
1522 (let (org-export--registered-backends)
1523 (org-export-define-backend 'test
1524 '((plain-text .
(lambda (text contents info
) "Failure"))))
1525 (org-export-define-backend 'test2
1526 '((plain-text .
(lambda (text contents info
) "Success"))))
1527 (org-export-with-backend 'test2
"Test"))))
1528 ;; Provide correct back-end if transcoder needs to use recursive
1532 (let ((test-back-end
1533 (org-export-create-backend
1535 '((headline .
(lambda (headline contents info
)
1537 (org-element-property :title headline
)
1539 (plain-text .
(lambda (text info
) "Success"))))))
1540 (org-export-string-as
1542 (org-export-create-backend
1544 '((headline .
(lambda (headline contents info
)
1545 (org-export-with-backend
1546 test-back-end headline contents info
))))))))))
1548 (ert-deftest test-org-export
/data-with-backend
()
1549 "Test `org-export-data-with-backend' specifications."
1550 ;; Error when calling an undefined back-end.
1551 (should-error (org-export-data-with-backend nil
"nil" nil
))
1552 ;; Otherwise, export data recursively, using correct back-end.
1556 (org-export-data-with-backend
1558 (org-export-create-backend
1560 '((plain-text .
(lambda (text info
) "Success"))
1561 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1562 '(:with-emphasize t
)))))
1568 (ert-deftest test-org-export
/export-snippet
()
1569 "Test export snippets transcoding."
1571 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1572 (let ((backend (org-test-default-backend)))
1573 (setf (org-export-backend-name backend
) 'test
)
1574 (setf (org-export-backend-transcoders backend
)
1575 (cons (cons 'export-snippet
1576 (lambda (snippet contents info
)
1577 (when (eq (org-export-snippet-backend snippet
) 'test
)
1578 (org-element-property :value snippet
))))
1579 (org-export-backend-transcoders backend
)))
1580 (let ((org-export-snippet-translation-alist nil
))
1581 (should (equal (org-export-as backend
) "A\n")))
1582 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1583 (should (equal (org-export-as backend
) "AB\n")))))
1584 ;; Ignored export snippets do not remove any blank.
1586 (equal "begin end\n"
1587 (org-test-with-parsed-data "begin @@test:A@@ end"
1588 (org-export-data-with-backend
1590 (org-export-create-backend
1592 '((paragraph .
(lambda (paragraph contents info
) contents
))
1593 (section .
(lambda (section contents info
) contents
))))
1600 (ert-deftest test-org-export
/footnote-first-reference-p
()
1601 "Test `org-export-footnote-first-reference-p' specifications."
1605 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1608 (org-export-create-backend
1610 `(,(cons 'footnote-reference
1612 (push (org-export-footnote-first-reference-p f info
)
1615 (section .
(lambda (s c i
) c
))
1616 (paragraph .
(lambda (p c i
) c
))))
1617 nil nil nil
'(:with-footnotes t
))
1618 (nreverse result
)))))
1619 ;; Limit check to DATA, when non-nil.
1623 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1625 (org-element-map tree
'footnote-reference
1628 (org-export-footnote-first-reference-p
1629 ref info
(org-element-map tree
'headline
#'identity info t
))
1632 (nreverse result
)))))
1636 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1638 (org-element-map tree
'footnote-reference
1640 (push (org-export-footnote-first-reference-p ref info
) result
))
1642 (nreverse result
)))))
1643 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1644 ;; in the main body of the document. Otherwise, enter footnote
1645 ;; definitions when they are encountered.
1649 (org-test-with-temp-text
1650 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1653 (org-export-create-backend
1655 `(,(cons 'footnote-reference
1657 (when (org-element-lineage f
'(drawer))
1658 (push (org-export-footnote-first-reference-p f info nil
)
1661 (drawer .
(lambda (d c i
) c
))
1662 (footnote-definition .
(lambda (d c i
) c
))
1663 (section .
(lambda (s c i
) c
))
1664 (paragraph .
(lambda (p c i
) c
))))
1665 nil nil nil
'(:with-footnotes t
))
1666 (nreverse result
)))))
1670 (org-test-with-temp-text
1671 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1674 (org-export-create-backend
1676 `(,(cons 'footnote-reference
1678 (when (org-element-lineage f
'(drawer))
1679 (push (org-export-footnote-first-reference-p f info nil t
)
1682 (drawer .
(lambda (d c i
) c
))
1683 (footnote-definition .
(lambda (d c i
) c
))
1684 (section .
(lambda (s c i
) c
))
1685 (paragraph .
(lambda (p c i
) c
))))
1686 nil nil nil
'(:with-footnotes t
))
1687 (nreverse result
))))))
1689 (ert-deftest test-org-export
/get-footnote-number
()
1690 "Test `org-export-get-footnote-number' specifications."
1693 (org-test-with-parsed-data
1694 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1695 (org-element-map tree
'footnote-reference
1696 (lambda (ref) (org-export-get-footnote-number ref info
))
1698 ;; Anonymous footnotes all get a new number.
1701 (org-test-with-parsed-data
1702 "Text[fn::anon1][fn::anon2]"
1703 (org-element-map tree
'footnote-reference
1704 (lambda (ref) (org-export-get-footnote-number ref info
))
1706 ;; Test nested footnotes order.
1709 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (3 .
"fn:3") (4))
1710 (org-test-with-parsed-data
1711 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1712 (org-element-map tree
'footnote-reference
1714 (cons (org-export-get-footnote-number ref info
)
1715 (org-element-property :label ref
)))
1717 ;; Limit number to provided DATA, when non-nil.
1721 (org-test-with-parsed-data
1722 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1723 (org-element-map tree
'footnote-reference
1725 (org-export-get-footnote-number
1726 ref info
(org-element-map tree
'headline
#'identity info t
)))
1731 (org-test-with-parsed-data
1732 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1733 (org-element-map tree
'footnote-reference
1734 (lambda (ref) (org-export-get-footnote-number ref info
))
1736 ;; With a non-nil BODY-FIRST optional argument, first check body,
1737 ;; then footnote definitions.
1740 '(("fn:1" .
1) ("fn:2" .
2) ("fn:3" .
3) ("fn:3" .
3))
1741 (org-test-with-parsed-data
1742 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1743 (org-element-map tree
'footnote-reference
1745 (cons (org-element-property :label ref
)
1746 (org-export-get-footnote-number ref info nil t
)))
1750 '(("fn:1" .
1) ("fn:2" .
3) ("fn:3" .
2) ("fn:3" .
2))
1751 (org-test-with-parsed-data
1752 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1753 (org-element-map tree
'footnote-reference
1755 (cons (org-element-property :label ref
)
1756 (org-export-get-footnote-number ref info nil
)))
1759 (ert-deftest test-org-export
/collect-footnote-definitions
()
1760 "Test `org-export-collect-footnote-definitions' specifications."
1763 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1765 \[fn:2] B [fn:3] [fn::D].
1768 (length (org-export-collect-footnote-definitions info
)))))
1769 ;; Limit number to provided DATA, when non-nil.
1773 (org-test-with-parsed-data
1774 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1776 (org-export-collect-footnote-definitions
1777 info
(org-element-map tree
'headline
#'identity info t
))))))
1780 '((1 "fn:1") (2 "fn:2"))
1781 (org-test-with-parsed-data
1782 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1783 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
1784 ;; With optional argument BODY-FIRST, first check body, then
1785 ;; footnote definitions.
1787 (equal '("fn:1" "fn:3" "fn:2" nil
)
1788 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1790 \[fn:2] B [fn:3] [fn::D].
1793 (mapcar (lambda (e) (nth 1 e
))
1794 (org-export-collect-footnote-definitions info nil t
)))))
1796 (equal '("fn:1" "fn:3" "fn:2" nil
)
1797 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1799 \[fn:2] B [fn:3] [fn::D].
1802 (mapcar (lambda (e) (nth 1 e
))
1803 (org-export-collect-footnote-definitions info
))))))
1805 (ert-deftest test-org-export
/footnotes
()
1806 "Miscellaneous tests on footnotes."
1807 (let ((org-footnote-section nil
)
1808 (org-export-with-footnotes t
))
1809 ;; Read every type of footnote.
1812 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1813 (org-test-with-parsed-data
1814 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1815 (org-element-map tree
'footnote-reference
1817 (let ((def (org-export-get-footnote-definition ref info
)))
1818 (cons (org-export-get-footnote-number ref info
)
1819 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1820 (car (org-element-contents
1821 (car (org-element-contents def
))))))))
1823 ;; Test nested footnote in invisible definitions.
1824 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1825 ;; Hide definitions.
1826 (narrow-to-region (point) (point-at-eol))
1827 (let* ((tree (org-element-parse-buffer))
1828 (info (org-combine-plists
1829 `(:parse-tree
,tree
)
1830 (org-export-collect-tree-properties
1831 tree
(org-export-get-environment)))))
1832 ;; Both footnotes should be seen.
1834 (= (length (org-export-collect-footnote-definitions info
)) 2))))
1835 ;; Test export of footnotes defined outside parsing scope.
1838 "ParagraphOut of scope\n"
1839 (org-test-with-temp-text "[fn:1] Out of scope
1842 (let ((backend (org-test-default-backend)))
1843 (setf (org-export-backend-transcoders backend
)
1844 (cons (cons 'footnote-reference
1845 (lambda (fn contents info
)
1846 (org-element-interpret-data
1847 (org-export-get-footnote-definition fn info
))))
1848 (org-export-backend-transcoders backend
)))
1850 (org-export-as backend
'subtree
)))))
1851 ;; Footnotes without a definition should throw an error.
1853 (org-test-with-parsed-data "Text[fn:1]"
1854 (org-export-get-footnote-definition
1855 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1856 ;; Footnote section should be ignored in TOC and in headlines
1859 (= 1 (let ((org-footnote-section "Footnotes"))
1860 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1861 (org-export-collect-headlines info
))))))
1864 (let ((org-footnote-section "Footnotes"))
1865 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1866 (org-element-map tree
'headline
1868 (when (equal (org-element-property :raw-value hl
) "H2")
1869 (org-export-get-headline-number hl info
)))
1874 ;;; Headlines and Inlinetasks
1876 (ert-deftest test-org-export
/get-relative-level
()
1877 "Test `org-export-get-relative-level' specifications."
1881 (let ((org-odd-levels-only nil
))
1882 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1883 (org-element-map tree
'headline
1884 (lambda (h) (org-export-get-relative-level h info
))
1889 (let ((org-odd-levels-only nil
))
1890 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1891 (org-element-map tree
'headline
1892 (lambda (h) (org-export-get-relative-level h info
))
1895 (ert-deftest test-org-export
/low-level-p
()
1896 "Test `org-export-low-level-p' specifications."
1900 (let ((org-odd-levels-only nil
))
1901 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1902 (org-element-map tree
'headline
1903 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1904 (plist-put info
:headline-levels
1)))))))
1906 (ert-deftest test-org-export
/get-headline-number
()
1907 "Test `org-export-get-headline-number' specifications."
1912 (let ((org-odd-levels-only nil
))
1913 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1914 (org-element-map tree
'headline
1915 (lambda (h) (org-export-get-headline-number h info
))
1917 ;; Missing levels are replaced with 0.
1921 (let ((org-odd-levels-only nil
))
1922 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1923 (org-element-map tree
'headline
1924 (lambda (h) (org-export-get-headline-number h info
))
1927 (ert-deftest test-org-export
/numbered-headline-p
()
1928 "Test `org-export-numbered-headline-p' specifications."
1929 ;; If `:section-numbers' is nil, never number headlines.
1931 (org-test-with-parsed-data "* Headline"
1932 (org-element-map tree
'headline
1933 (lambda (h) (org-export-numbered-headline-p h info
))
1934 (plist-put info
:section-numbers nil
))))
1935 ;; If `:section-numbers' is a number, only number headlines with
1936 ;; a level greater that it.
1940 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1941 (org-element-map tree
'headline
1942 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1943 (plist-put info
:section-numbers
1)))))
1944 ;; Otherwise, headlines are always numbered.
1946 (org-test-with-parsed-data "* Headline"
1947 (org-element-map tree
'headline
1948 (lambda (h) (org-export-numbered-headline-p h info
))
1949 (plist-put info
:section-numbers t
))))
1950 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
1952 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1953 (org-export-numbered-headline-p
1954 (org-element-map tree
'headline
'identity info t
)
1956 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
1958 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1959 (org-export-numbered-headline-p
1960 (org-element-map tree
'headline
#'identity info t
)
1962 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1963 ;; ancestors disables numbering.
1965 (org-test-with-parsed-data
1976 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1977 (org-element-map tree
'headline
#'identity info
)))))
1979 (ert-deftest test-org-export
/number-to-roman
()
1980 "Test `org-export-number-to-roman' specifications."
1981 ;; If number is negative, return it as a string.
1982 (should (equal (org-export-number-to-roman -
1) "-1"))
1983 ;; Otherwise, return it as a roman number.
1984 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1986 (ert-deftest test-org-export
/get-optional-title
()
1987 "Test `org-export-get-alt-title' specifications."
1988 ;; If ALT_TITLE property is defined, use it.
1991 (org-test-with-parsed-data
1992 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1993 (org-export-get-alt-title
1994 (org-element-map tree
'headline
'identity info t
)
1996 ;; Otherwise, fall-back to regular title.
1998 (equal '("Headline")
1999 (org-test-with-parsed-data "* Headline"
2000 (org-export-get-alt-title
2001 (org-element-map tree
'headline
'identity info t
)
2004 (ert-deftest test-org-export
/get-tags
()
2005 "Test `org-export-get-tags' specifications."
2006 (let ((org-export-exclude-tags '("noexport"))
2007 (org-export-select-tags '("export")))
2008 ;; Standard test: tags which are not a select tag, an exclude tag,
2009 ;; or specified as optional argument shouldn't be ignored.
2011 (org-test-with-parsed-data "* Headline :tag:"
2012 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2014 ;; Exclude tags are removed.
2016 (org-test-with-parsed-data "* Headline :noexport:"
2017 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2019 ;; Select tags are removed.
2021 (org-test-with-parsed-data "* Headline :export:"
2022 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2027 (org-test-with-parsed-data "* Headline :tag:export:"
2028 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2030 ;; Tags provided in the optional argument are also ignored.
2032 (org-test-with-parsed-data "* Headline :ignore:"
2033 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2035 ;; Allow tag inheritance.
2039 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2040 (org-element-map tree
'headline
2041 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2042 ;; Tag inheritance checks FILETAGS keywords.
2046 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2047 (org-element-map tree
'headline
2048 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
2050 (ert-deftest test-org-export
/get-node-property
()
2051 "Test`org-export-get-node-property' specifications."
2055 (org-test-with-parsed-data "* Headline
2059 (org-export-get-node-property
2060 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2061 ;; Test inheritance.
2064 (org-test-with-parsed-data "* Parent
2070 (org-export-get-node-property
2071 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2072 ;; Cannot return a value before the first headline.
2074 (org-test-with-parsed-data "Paragraph
2079 (org-export-get-node-property
2080 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2082 (ert-deftest test-org-export
/get-category
()
2083 "Test `org-export-get-category' specifications."
2087 (org-test-with-parsed-data "* Headline
2091 (org-export-get-category
2092 (org-element-map tree
'headline
'identity nil t
) info
))))
2093 ;; Test inheritance from a parent headline.
2095 (equal '("value" "value")
2096 (org-test-with-parsed-data "* Headline1
2101 (org-element-map tree
'headline
2102 (lambda (hl) (org-export-get-category hl info
)) info
))))
2103 ;; Test inheritance from #+CATEGORY keyword
2106 (org-test-with-parsed-data "#+CATEGORY: value
2108 (org-export-get-category
2109 (org-element-map tree
'headline
'identity nil t
) info
))))
2110 ;; Test inheritance from file name.
2113 (org-test-with-parsed-data "* Headline"
2114 (let ((info (plist-put info
:input-file
"~/test.org")))
2115 (org-export-get-category
2116 (org-element-map tree
'headline
'identity nil t
) info
)))))
2120 (org-test-with-parsed-data "* Headline"
2121 (org-export-get-category
2122 (org-element-map tree
'headline
'identity nil t
) info
)))))
2124 (ert-deftest test-org-export
/first-sibling-p
()
2125 "Test `org-export-first-sibling-p' specifications."
2130 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2131 (org-element-map tree
'headline
2132 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2136 (org-test-with-parsed-data "- item\n\n para"
2137 (org-element-map tree
'paragraph
2138 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2140 ;; Ignore sections for headlines.
2143 (org-test-with-parsed-data "* H\nSection\n** H 2"
2144 (org-element-map tree
'headline
2145 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2147 ;; Ignore headlines not exported.
2151 (let ((org-export-exclude-tags '("ignore")))
2152 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2153 (org-element-map tree
'headline
2154 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2157 (ert-deftest test-org-export
/last-sibling-p
()
2158 "Test `org-export-last-sibling-p' specifications."
2163 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2164 (org-element-map tree
'headline
2165 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2169 (org-test-with-parsed-data "- item\n\n para"
2170 (org-element-map tree
'paragraph
2171 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2173 ;; Ignore headlines not exported.
2177 (let ((org-export-exclude-tags '("ignore")))
2178 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2179 (org-element-map tree
'headline
2180 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2183 (ert-deftest test-org-export
/handle-inlinetasks
()
2184 "Test inlinetask export."
2185 ;; Inlinetask with an exclude tag.
2186 (when (featurep 'org-inlinetask
)
2190 (let ((org-inlinetask-min-level 3)
2191 org-export-filter-body-functions
2192 org-export-filter-final-output-functions
)
2193 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2194 (org-export-as (org-test-default-backend)
2195 nil nil nil
'(:exclude-tags
("noexp")))))))
2196 ;; Inlinetask with an include tag.
2199 "* H2\n*** Inline :exp:\n"
2200 (let ((org-inlinetask-min-level 3)
2201 (org-tags-column 0))
2202 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2203 (org-export-as (org-test-default-backend)
2204 nil nil nil
'(:select-tags
("exp")))))))
2205 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2208 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2209 (org-inlinetask-min-level 3)
2210 org-export-filter-body-functions
2211 org-export-filter-final-output-functions
)
2212 (org-test-with-temp-text "*** TODO Inline"
2213 (org-export-as (org-test-default-backend)
2214 nil nil nil
'(:with-tasks nil
))))))))
2220 (ert-deftest test-org-export
/get-date
()
2221 "Test `org-export-get-date' specifications."
2222 ;; Return a properly formatted string when
2223 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2224 ;; consists in a single timestamp.
2227 (let ((org-export-date-timestamp-format "%d %m %Y"))
2228 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2229 (org-export-get-date info
)))))
2230 ;; Return a secondary string otherwise.
2233 (let ((org-export-date-timestamp-format nil
))
2234 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2235 (org-export-get-date info
)))))
2238 (org-test-with-parsed-data "#+DATE: Date"
2239 (org-export-get-date info
))))
2240 ;; Optional argument has precedence over
2241 ;; `org-export-date-timestamp-format'.
2244 (let ((org-export-date-timestamp-format "%d %m %Y"))
2245 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2246 (org-export-get-date info
"%d %m"))))))
2252 (ert-deftest test-org-export
/custom-protocol-maybe
()
2253 "Test `org-export-custom-protocol-maybe' specifications."
2257 (let ((org-link-types (copy-sequence org-link-types
)))
2258 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2259 (org-export-string-as
2261 (org-export-create-backend
2264 '((section .
(lambda (s c i
) c
))
2265 (paragraph .
(lambda (p c i
) c
))
2266 (link .
(lambda (l c i
)
2267 (or (org-export-custom-protocol-maybe l c
'test
)
2272 (let ((org-link-types (copy-sequence org-link-types
)))
2274 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2275 (org-export-string-as
2277 (org-export-create-backend
2280 '((section .
(lambda (s c i
) c
))
2281 (paragraph .
(lambda (p c i
) c
))
2282 (link .
(lambda (l c i
)
2283 (or (org-export-custom-protocol-maybe l c
'no-test
)
2285 ;; Ignore anonymous back-ends.
2289 (let ((org-link-types (copy-sequence org-link-types
)))
2291 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2292 (org-export-string-as
2294 (org-export-create-backend
2296 '((section .
(lambda (s c i
) c
))
2297 (paragraph .
(lambda (p c i
) c
))
2298 (link .
(lambda (l c i
)
2299 (or (org-export-custom-protocol-maybe l c nil
)
2302 (ert-deftest test-org-export
/get-coderef-format
()
2303 "Test `org-export-get-coderef-format' specifications."
2304 ;; A link without description returns "%s"
2305 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2307 ;; Return "%s" when path is matched within description.
2308 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2310 ;; Otherwise return description.
2311 (should (equal (org-export-get-coderef-format "path" "desc")
2314 (ert-deftest test-org-export
/inline-image-p
()
2315 "Test `org-export-inline-image-p' specifications."
2317 (org-export-inline-image-p
2318 (org-test-with-temp-text "[[#id]]"
2319 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2320 '(("custom-id" .
"id")))))
2322 (ert-deftest test-org-export
/fuzzy-link
()
2323 "Test fuzzy links specifications."
2324 ;; Link to an headline should return headline's number.
2325 (org-test-with-parsed-data
2326 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2328 ;; Note: Headline's number is in fact a list of numbers.
2330 (org-element-map tree
'link
2332 (org-export-get-ordinal
2333 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2334 ;; Link to a target in an item should return item's number.
2335 (org-test-with-parsed-data
2336 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2338 ;; Note: Item's number is in fact a list of numbers.
2340 (org-element-map tree
'link
2342 (org-export-get-ordinal
2343 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2344 ;; Link to a target in a footnote should return footnote's number.
2345 (org-test-with-parsed-data "
2346 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2349 (org-element-map tree
'link
2351 (org-export-get-ordinal
2352 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2353 ;; Link to a named element should return sequence number of that
2355 (org-test-with-parsed-data
2356 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2359 (org-element-map tree
'link
2361 (org-export-get-ordinal
2362 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2363 ;; Link to a target not within an item, a table, a footnote
2364 ;; reference or definition should return section number.
2365 (org-test-with-parsed-data
2366 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2369 (org-element-map tree
'link
2371 (org-export-get-ordinal
2372 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2373 ;; Space are not significant when matching a fuzzy link.
2375 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2376 (org-element-map tree
'link
2377 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2379 ;; Statistics cookies are ignored for headline match.
2381 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2382 (org-element-map tree
'link
2383 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2386 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2387 (org-element-map tree
'link
2388 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2390 ;; Headline match is position dependent.
2394 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2395 (org-element-map tree
'link
2396 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
2398 (ert-deftest test-org-export
/resolve-coderef
()
2399 "Test `org-export-resolve-coderef' specifications."
2400 (let ((org-coderef-label-format "(ref:%s)"))
2401 ;; A link to a "-n -k -r" block returns line number.
2404 (org-test-with-parsed-data
2405 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2406 (org-export-resolve-coderef "coderef" info
))))
2409 (org-test-with-parsed-data
2410 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2411 (org-export-resolve-coderef "coderef" info
))))
2412 ;; A link to a "-n -r" block returns line number.
2415 (org-test-with-parsed-data
2416 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2417 (org-export-resolve-coderef "coderef" info
))))
2420 (org-test-with-parsed-data
2421 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2422 (org-export-resolve-coderef "coderef" info
))))
2423 ;; A link to a "-n" block returns coderef.
2426 (org-test-with-parsed-data
2427 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2428 (org-export-resolve-coderef "coderef" info
))))
2431 (org-test-with-parsed-data
2432 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2433 (org-export-resolve-coderef "coderef" info
))))
2434 ;; A link to a "-r" block returns line number.
2437 (org-test-with-parsed-data
2438 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2439 (org-export-resolve-coderef "coderef" info
))))
2442 (org-test-with-parsed-data
2443 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2444 (org-export-resolve-coderef "coderef" info
))))
2445 ;; A link to a block without a switch returns coderef.
2448 (org-test-with-parsed-data
2449 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2450 (org-export-resolve-coderef "coderef" info
))))
2451 (org-test-with-parsed-data
2452 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2453 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2454 ;; Correctly handle continued line numbers. A "+n" switch should
2455 ;; resume numbering from previous block with numbered lines,
2456 ;; ignoring blocks not numbering lines in the process. A "-n"
2457 ;; switch resets count.
2460 (org-test-with-parsed-data "
2465 #+BEGIN_SRC emacs-lisp
2469 #+BEGIN_SRC emacs-lisp +n -r
2470 \(+ 1 1) (ref:addition)
2473 #+BEGIN_EXAMPLE -n -r
2474 Another text. (ref:text)
2476 (list (org-export-resolve-coderef "addition" info
)
2477 (org-export-resolve-coderef "text" info
)))))
2478 ;; Recognize coderef with user-specified syntax.
2481 (org-test-with-parsed-data
2482 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2483 (org-export-resolve-coderef "text" info
))))
2484 ;; Unresolved coderefs throw an error.
2486 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2487 (org-export-resolve-coderef "unknown" info
)))))
2489 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2490 "Test `org-export-resolve-fuzzy-link' specifications."
2491 ;; Match target objects.
2493 (org-test-with-parsed-data "<<target>> [[target]]"
2494 (org-export-resolve-fuzzy-link
2495 (org-element-map tree
'link
'identity info t
) info
)))
2496 ;; Match named elements.
2498 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2499 (org-export-resolve-fuzzy-link
2500 (org-element-map tree
'link
'identity info t
) info
)))
2501 ;; Match exact headline's name.
2503 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2504 (org-export-resolve-fuzzy-link
2505 (org-element-map tree
'link
'identity info t
) info
)))
2506 ;; Targets objects have priority over named elements and headline
2510 (org-test-with-parsed-data
2511 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2513 (org-export-resolve-fuzzy-link
2514 (org-element-map tree
'link
'identity info t
) info
)))))
2515 ;; Named elements have priority over headline titles.
2518 (org-test-with-parsed-data
2519 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2521 (org-export-resolve-fuzzy-link
2522 (org-element-map tree
'link
'identity info t
) info
)))))
2523 ;; If link's path starts with a "*", only match headline titles,
2527 (org-test-with-parsed-data
2528 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2530 (org-export-resolve-fuzzy-link
2531 (org-element-map tree
'link
'identity info t
) info
)))))
2532 ;; Error if no match.
2534 (org-test-with-parsed-data "[[target]]"
2535 (org-export-resolve-fuzzy-link
2536 (org-element-map tree
'link
'identity info t
) info
)))
2537 ;; Match fuzzy link even when before first headline.
2540 (org-test-with-parsed-data "[[hl]]\n* hl"
2542 (org-export-resolve-fuzzy-link
2543 (org-element-map tree
'link
'identity info t
) info
))))))
2545 (ert-deftest test-org-export
/resolve-id-link
()
2546 "Test `org-export-resolve-id-link' specifications."
2547 ;; Regular test for custom-id link.
2549 (equal '("Headline1")
2550 (org-test-with-parsed-data "* Headline1
2556 (org-element-property
2558 (org-export-resolve-id-link
2559 (org-element-map tree
'link
'identity info t
) info
)))))
2560 ;; Throw an error on failing searches.
2562 (org-test-with-parsed-data "* Headline1
2568 (org-export-resolve-id-link
2569 (org-element-map tree
'link
'identity info t
) info
)))
2570 ;; Test for internal id target.
2572 (equal '("Headline1")
2573 (org-test-with-parsed-data "* Headline1
2579 (org-element-property
2581 (org-export-resolve-id-link
2582 (org-element-map tree
'link
'identity info t
) info
)))))
2583 ;; Test for external id target.
2587 (org-test-with-parsed-data "[[id:aaaa]]"
2588 (org-export-resolve-id-link
2589 (org-element-map tree
'link
'identity info t
)
2590 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2592 (ert-deftest test-org-export
/resolve-radio-link
()
2593 "Test `org-export-resolve-radio-link' specifications."
2596 (org-test-with-temp-text "<<<radio>>> radio"
2597 (org-update-radio-target-regexp)
2598 (let* ((tree (org-element-parse-buffer))
2599 (info `(:parse-tree
,tree
)))
2600 (org-export-resolve-radio-link
2601 (org-element-map tree
'link
'identity info t
)
2603 ;; Radio targets are case-insensitive.
2605 (org-test-with-temp-text "<<<RADIO>>> radio"
2606 (org-update-radio-target-regexp)
2607 (let* ((tree (org-element-parse-buffer))
2608 (info `(:parse-tree
,tree
)))
2609 (org-export-resolve-radio-link
2610 (org-element-map tree
'link
'identity info t
)
2612 ;; Radio target with objects.
2614 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2615 (org-update-radio-target-regexp)
2616 (let* ((tree (org-element-parse-buffer))
2617 (info `(:parse-tree
,tree
)))
2618 (org-export-resolve-radio-link
2619 (org-element-map tree
'link
'identity info t
)
2621 ;; Radio target with objects at its beginning.
2623 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2624 (org-update-radio-target-regexp)
2625 (let* ((tree (org-element-parse-buffer))
2626 (info `(:parse-tree
,tree
)))
2627 (org-export-resolve-radio-link
2628 (org-element-map tree
'link
'identity info t
)
2630 ;; Radio link next to an apostrophe.
2632 (org-test-with-temp-text "<<<radio>>> radio's"
2633 (org-update-radio-target-regexp)
2634 (let* ((tree (org-element-parse-buffer))
2635 (info `(:parse-tree
,tree
)))
2636 (org-export-resolve-radio-link
2637 (org-element-map tree
'link
'identity info t
)
2639 ;; Multiple radio targets.
2641 (equal '("radio1" "radio2")
2642 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2643 (org-update-radio-target-regexp)
2644 (let* ((tree (org-element-parse-buffer))
2645 (info `(:parse-tree
,tree
)))
2646 (org-element-map tree
'link
2648 (org-element-property
2649 :value
(org-export-resolve-radio-link link info
)))
2651 ;; Radio target is whitespace insensitive.
2653 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2654 (org-update-radio-target-regexp)
2655 (let* ((tree (org-element-parse-buffer))
2656 (info `(:parse-tree
,tree
)))
2657 (org-element-map tree
'link
2658 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2660 (ert-deftest test-org-export
/file-uri
()
2661 "Test `org-export-file-uri' specifications."
2662 ;; Preserve relative filenames.
2663 (should (equal "relative.org" (org-export-file-uri "relative.org")))
2664 ;; Local files start with "file:///"
2665 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
2666 ;; Remote files start with "file://"
2667 (should (equal "file://myself@some.where:papers/last.pdf"
2668 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
2669 ;; Expand filename starting with "~".
2670 (should (equal (org-export-file-uri "~/file.org")
2671 (concat "file://" (expand-file-name "~/file.org")))))
2675 ;;; Src-block and example-block
2677 (ert-deftest test-org-export
/unravel-code
()
2678 "Test `org-export-unravel-code' function."
2679 ;; Code without reference.
2681 (equal '("(+ 1 1)\n")
2682 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2683 (org-export-unravel-code (org-element-at-point)))))
2684 ;; Code with reference.
2686 (equal '("(+ 1 1)\n" (1 .
"test"))
2687 (org-test-with-temp-text
2688 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2689 (let ((org-coderef-label-format "(ref:%s)"))
2690 (org-export-unravel-code (org-element-at-point))))))
2691 ;; Code with user-defined reference.
2694 '("(+ 1 1)\n" (1 .
"test"))
2695 (org-test-with-temp-text
2696 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2697 (let ((org-coderef-label-format "(ref:%s)"))
2698 (org-export-unravel-code (org-element-at-point))))))
2699 ;; Code references keys are relative to the current block.
2701 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2702 (org-test-with-temp-text "
2711 (let ((org-coderef-label-format "(ref:%s)"))
2712 (org-export-unravel-code (org-element-at-point)))))))
2714 (ert-deftest test-org-export
/format-code-default
()
2715 "Test `org-export-format-code-default' specifications."
2716 ;; Return the empty string when code is empty.
2719 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2720 (org-export-format-code-default
2721 (org-element-map tree
'src-block
'identity info t
) info
))))
2722 ;; Number lines, two whitespace characters before the actual loc.
2725 (org-test-with-parsed-data
2726 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2727 (org-export-format-code-default
2728 (org-element-map tree
'src-block
'identity info t
) info
))))
2729 ;; Put references 6 whitespace characters after the widest line,
2730 ;; wrapped within parenthesis.
2732 (equal "123 (a)\n1 (b)\n"
2733 (let ((org-coderef-label-format "(ref:%s)"))
2734 (org-test-with-parsed-data
2735 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2736 (org-export-format-code-default
2737 (org-element-map tree
'src-block
'identity info t
) info
))))))
2743 (ert-deftest test-org-export
/activate-smart-quotes
()
2744 "Test `org-export-activate-smart-quotes' specifications."
2745 ;; Double quotes: standard test.
2748 '("some “quoted” text")
2749 (let ((org-export-default-language "en"))
2750 (org-test-with-parsed-data "some \"quoted\" text"
2751 (org-element-map tree
'plain-text
2752 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2754 ;; Opening quotes: at the beginning of a paragraph.
2758 (let ((org-export-default-language "en"))
2759 (org-test-with-parsed-data "\"begin"
2760 (org-element-map tree
'plain-text
2761 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2763 ;; Opening quotes: after an object.
2766 '("“quoted” text")
2767 (let ((org-export-default-language "en"))
2768 (org-test-with-parsed-data "=verb= \"quoted\" text"
2769 (org-element-map tree
'plain-text
2770 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2772 ;; Closing quotes: at the end of a paragraph.
2775 '("Quoted “text”")
2776 (let ((org-export-default-language "en"))
2777 (org-test-with-parsed-data "Quoted \"text\""
2778 (org-element-map tree
'plain-text
2779 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2781 ;; Inner quotes: standard test.
2783 (equal '("« outer « inner » outer »")
2784 (let ((org-export-default-language "fr"))
2785 (org-test-with-parsed-data "\"outer 'inner' outer\""
2786 (org-element-map tree
'plain-text
2787 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2789 ;; Apostrophe: standard test.
2791 (equal '("It « shouldn’t » fail")
2792 (let ((org-export-default-language "fr"))
2793 (org-test-with-parsed-data "It \"shouldn't\" fail"
2794 (org-element-map tree
'plain-text
2795 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2798 (equal '("It shouldn’t fail")
2799 (let ((org-export-default-language "fr"))
2800 (org-test-with-parsed-data "It shouldn't fail"
2801 (org-element-map tree
'plain-text
2802 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2804 ;; Apostrophe: before an object.
2807 '("« a’" " »")
2808 (let ((org-export-default-language "fr"))
2809 (org-test-with-parsed-data "\"a'=b=\""
2810 (org-element-map tree
'plain-text
2811 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2813 ;; Apostrophe: after an object.
2815 (equal '("« " "’s »")
2816 (let ((org-export-default-language "fr"))
2817 (org-test-with-parsed-data "\"=code='s\""
2818 (org-element-map tree
'plain-text
2819 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2821 ;; Special case: isolated quotes.
2823 (equal '("“" "”")
2824 (let ((org-export-default-language "en"))
2825 (org-test-with-parsed-data "\"$x$\""
2826 (org-element-map tree
'plain-text
2827 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2829 ;; Smart quotes in secondary strings.
2831 (equal '("“" "”")
2832 (let ((org-export-default-language "en"))
2833 (org-test-with-parsed-data "* \"$x$\""
2834 (org-element-map tree
'plain-text
2835 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2837 ;; Smart quotes in document keywords.
2839 (equal '("“" "”")
2840 (let ((org-export-default-language "en"))
2841 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2842 (org-element-map (plist-get info
:title
) 'plain-text
2843 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2845 ;; Smart quotes in parsed affiliated keywords.
2847 (equal '("“" "”" "Paragraph")
2848 (let ((org-export-default-language "en"))
2849 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2850 (org-element-map tree
'plain-text
2851 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2852 info nil nil t
))))))
2858 (ert-deftest test-org-export
/special-column
()
2859 "Test if the table's special column is properly recognized."
2860 ;; 1. First column is special if it contains only a special marking
2861 ;; characters or empty cells.
2862 (org-test-with-temp-text "
2866 (org-export-table-has-special-column-p
2868 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2869 ;; 2. If the column contains anything else, it isn't special.
2870 (org-test-with-temp-text "
2874 (org-export-table-has-special-column-p
2876 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2877 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2879 (org-test-with-temp-text "
2888 (org-export-table-has-special-column-p
2890 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2891 ;; 4. A first column with only empty cells isn't considered as
2893 (org-test-with-temp-text "
2897 (org-export-table-has-special-column-p
2899 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2901 (ert-deftest test-org-export
/table-row-is-special-p
()
2902 "Test `org-export-table-row-is-special-p' specifications."
2903 ;; 1. A row is special if it has a special marking character in the
2905 (org-test-with-parsed-data "| ! | 1 |"
2907 (org-export-table-row-is-special-p
2908 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2909 ;; 2. A row is special when its first field is "/"
2910 (org-test-with-parsed-data "
2914 (org-export-table-row-is-special-p
2915 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2916 ;; 3. A row only containing alignment cookies is also considered as
2918 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2920 (org-export-table-row-is-special-p
2921 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2922 ;; 4. Everything else isn't considered as special.
2923 (org-test-with-parsed-data "| \alpha | | c |"
2925 (org-export-table-row-is-special-p
2926 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2927 ;; 5. Table's rules are never considered as special rows.
2928 (org-test-with-parsed-data "|---+---|"
2930 (org-export-table-row-is-special-p
2931 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2933 (ert-deftest test-org-export
/has-header-p
()
2934 "Test `org-export-table-has-header-p' specifications."
2935 ;; 1. With an header.
2936 (org-test-with-parsed-data "
2941 (org-export-table-has-header-p
2942 (org-element-map tree
'table
'identity info
'first-match
)
2944 ;; 2. Without an header.
2945 (org-test-with-parsed-data "
2949 (org-export-table-has-header-p
2950 (org-element-map tree
'table
'identity info
'first-match
)
2952 ;; 3. Don't get fooled with starting and ending rules.
2953 (org-test-with-parsed-data "
2959 (org-export-table-has-header-p
2960 (org-element-map tree
'table
'identity info
'first-match
)
2963 (ert-deftest test-org-export
/table-row-group
()
2964 "Test `org-export-table-row-group' specifications."
2965 ;; 1. A rule creates a new group.
2968 (org-test-with-parsed-data "
2972 (org-element-map tree
'table-row
2974 (if (eq (org-element-property :type row
) 'rule
) 'rule
2975 (org-export-table-row-group row info
)))))))
2976 ;; 2. Special rows are ignored in count.
2980 (org-test-with-parsed-data "
2984 (org-element-map tree
'table-row
2986 (if (eq (org-element-property :type row
) 'rule
) 'rule
2987 (org-export-table-row-group row info
)))
2989 ;; 3. Double rules also are ignored in count.
2991 (equal '(1 rule rule
2)
2992 (org-test-with-parsed-data "
2997 (org-element-map tree
'table-row
2999 (if (eq (org-element-property :type row
) 'rule
) 'rule
3000 (org-export-table-row-group row info
))))))))
3002 (ert-deftest test-org-export
/table-row-number
()
3003 "Test `org-export-table-row-number' specifications."
3004 ;; Standard test. Number is 0-indexed.
3007 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3008 (org-element-map tree
'table-row
3009 (lambda (row) (org-export-table-row-number row info
)) info
))))
3010 ;; Number ignores separators.
3013 (org-test-with-parsed-data "
3017 (org-element-map tree
'table-row
3018 (lambda (row) (org-export-table-row-number row info
)) info
))))
3019 ;; Number ignores special rows.
3022 (org-test-with-parsed-data "
3028 (org-element-map tree
'table-row
3029 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3031 (ert-deftest test-org-export
/table-cell-width
()
3032 "Test `org-export-table-cell-width' specifications."
3033 ;; 1. Width is primarily determined by width cookies. If no cookie
3034 ;; is found, cell's width is nil.
3035 (org-test-with-parsed-data "
3036 | / | <l> | <6> | <l7> |
3041 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3042 (org-element-map tree
'table-cell
'identity info
)))))
3043 ;; 2. The last width cookie has precedence.
3044 (org-test-with-parsed-data "
3051 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3052 (org-element-map tree
'table-cell
'identity info
)))))
3053 ;; 3. Valid width cookies must have a specific row.
3054 (org-test-with-parsed-data "| <6> | cell |"
3058 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3059 (org-element-map tree
'table-cell
'identity
))))))
3061 (ert-deftest test-org-export
/table-cell-alignment
()
3062 "Test `org-export-table-cell-alignment' specifications."
3063 ;; 1. Alignment is primarily determined by alignment cookies.
3065 (equal '(left center right
)
3066 (let ((org-table-number-fraction 0.5)
3067 (org-table-number-regexp "^[0-9]+$"))
3068 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3069 (mapcar (lambda (cell)
3070 (org-export-table-cell-alignment cell info
))
3071 (org-element-map tree
'table-cell
'identity
))))))
3072 ;; 2. The last alignment cookie has precedence.
3074 (equal '(right right right
)
3075 (org-test-with-parsed-data "
3079 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3080 (org-element-map tree
'table-cell
'identity
)))))
3081 ;; 3. If there's no cookie, cell's contents determine alignment.
3082 ;; A column mostly made of cells containing numbers will align
3083 ;; its cells to the right.
3085 (equal '(right right right
)
3086 (let ((org-table-number-fraction 0.5)
3087 (org-table-number-regexp "^[0-9]+$"))
3088 (org-test-with-parsed-data "
3092 (mapcar (lambda (cell)
3093 (org-export-table-cell-alignment cell info
))
3094 (org-element-map tree
'table-cell
'identity
))))))
3095 ;; 4. Otherwise, they will be aligned to the left.
3097 (equal '(left left left
)
3098 (org-test-with-parsed-data "
3102 (mapcar (lambda (cell)
3103 (org-export-table-cell-alignment cell info
))
3104 (org-element-map tree
'table-cell
'identity info
))))))
3106 (ert-deftest test-org-export
/table-cell-borders
()
3107 "Test `org-export-table-cell-borders' specifications."
3108 ;; 1. Recognize various column groups indicators.
3109 (org-test-with-parsed-data "| / | < | > | <> |"
3112 '((right bottom top
) (left bottom top
) (right bottom top
)
3113 (right left bottom top
))
3114 (mapcar (lambda (cell)
3115 (org-export-table-cell-borders cell info
))
3116 (org-element-map tree
'table-cell
'identity
)))))
3117 ;; 2. Accept shortcuts to define column groups.
3118 (org-test-with-parsed-data "| / | < | < |"
3121 '((right bottom top
) (right left bottom top
) (left bottom top
))
3122 (mapcar (lambda (cell)
3123 (org-export-table-cell-borders cell info
))
3124 (org-element-map tree
'table-cell
'identity
)))))
3125 ;; 3. A valid column groups row must start with a "/".
3126 (org-test-with-parsed-data "
3130 (equal '((top) (top) (bottom) (bottom))
3131 (mapcar (lambda (cell)
3132 (org-export-table-cell-borders cell info
))
3133 (org-element-map tree
'table-cell
'identity
)))))
3134 ;; 4. Take table rules into consideration.
3135 (org-test-with-parsed-data "
3140 (equal '((below top
) (bottom above
))
3141 (mapcar (lambda (cell)
3142 (org-export-table-cell-borders cell info
))
3143 (org-element-map tree
'table-cell
'identity
)))))
3144 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3145 ;; (resp. `bottom' and `below') borders. Any special row is
3147 (org-test-with-parsed-data "
3153 (equal '((bottom below top above
))
3155 (mapcar (lambda (cell)
3156 (org-export-table-cell-borders cell info
))
3157 (org-element-map tree
'table-cell
'identity
)))))))
3159 (ert-deftest test-org-export
/table-dimensions
()
3160 "Test `org-export-table-dimensions' specifications."
3161 ;; 1. Standard test.
3162 (org-test-with-parsed-data "
3167 (org-export-table-dimensions
3168 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3169 ;; 2. Ignore horizontal rules and special columns.
3170 (org-test-with-parsed-data "
3177 (org-export-table-dimensions
3178 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3180 (ert-deftest test-org-export
/table-cell-address
()
3181 "Test `org-export-table-cell-address' specifications."
3182 ;; 1. Standard test: index is 0-based.
3183 (org-test-with-parsed-data "| a | b |"
3185 (equal '((0 .
0) (0 .
1))
3186 (org-element-map tree
'table-cell
3187 (lambda (cell) (org-export-table-cell-address cell info
))
3189 ;; 2. Special column isn't counted, nor are special rows.
3190 (org-test-with-parsed-data "
3195 (org-export-table-cell-address
3196 (car (last (org-element-map tree
'table-cell
'identity info
)))
3198 ;; 3. Tables rules do not count either.
3199 (org-test-with-parsed-data "
3207 (org-export-table-cell-address
3208 (car (last (org-element-map tree
'table-cell
'identity info
)))
3210 ;; 4. Return nil for special cells.
3211 (org-test-with-parsed-data "| / | a |"
3213 (org-export-table-cell-address
3214 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3217 (ert-deftest test-org-export
/get-table-cell-at
()
3218 "Test `org-export-get-table-cell-at' specifications."
3219 ;; 1. Address ignores special columns, special rows and rules.
3220 (org-test-with-parsed-data "
3227 (org-element-contents
3228 (org-export-get-table-cell-at
3230 (org-element-map tree
'table
'identity info
'first-match
)
3232 ;; 2. Return value for a non-existent address is nil.
3233 (org-test-with-parsed-data "| a |"
3235 (org-export-get-table-cell-at
3237 (org-element-map tree
'table
'identity info
'first-match
)
3239 (org-test-with-parsed-data "| / |"
3241 (org-export-get-table-cell-at
3243 (org-element-map tree
'table
'identity info
'first-match
)
3246 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3247 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3248 ;; 1. A cell at a beginning of a row always starts a column group.
3249 (org-test-with-parsed-data "| a |"
3251 (org-export-table-cell-starts-colgroup-p
3252 (org-element-map tree
'table-cell
'identity info
'first-match
)
3254 ;; 2. Special column should be ignored when determining the
3255 ;; beginning of the row.
3256 (org-test-with-parsed-data "
3260 (org-export-table-cell-starts-colgroup-p
3261 (org-element-map tree
'table-cell
'identity info
'first-match
)
3263 ;; 2. Explicit column groups.
3264 (org-test-with-parsed-data "
3270 (org-element-map tree
'table-cell
3272 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3275 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3276 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3277 ;; 1. A cell at the end of a row always ends a column group.
3278 (org-test-with-parsed-data "| a |"
3280 (org-export-table-cell-ends-colgroup-p
3281 (org-element-map tree
'table-cell
'identity info
'first-match
)
3283 ;; 2. Special column should be ignored when determining the
3284 ;; beginning of the row.
3285 (org-test-with-parsed-data "
3289 (org-export-table-cell-ends-colgroup-p
3290 (org-element-map tree
'table-cell
'identity info
'first-match
)
3292 ;; 3. Explicit column groups.
3293 (org-test-with-parsed-data "
3299 (org-element-map tree
'table-cell
3301 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3304 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3305 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3306 ;; 1. A row at the beginning of a table always starts a row group.
3307 ;; So does a row following a table rule.
3308 (org-test-with-parsed-data "
3315 (org-element-map tree
'table-row
3317 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3319 ;; 2. Special rows should be ignored when determining the beginning
3321 (org-test-with-parsed-data "
3330 (org-element-map tree
'table-row
3332 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3335 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3336 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3337 ;; 1. A row at the end of a table always ends a row group. So does
3338 ;; a row preceding a table rule.
3339 (org-test-with-parsed-data "
3346 (org-element-map tree
'table-row
3348 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3350 ;; 2. Special rows should be ignored when determining the beginning
3352 (org-test-with-parsed-data "
3361 (org-element-map tree
'table-row
3363 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3366 (ert-deftest test-org-export
/table-row-in-header-p
()
3367 "Test `org-export-table-row-in-header-p' specifications."
3368 ;; Standard test. Separators are always nil.
3372 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3373 (org-element-map tree
'table-row
3375 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3376 ;; Nil when there is no header.
3380 (org-test-with-parsed-data "| a |\n| b |"
3381 (org-element-map tree
'table-row
3383 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3385 (ert-deftest test-org-export
/table-row-starts-header-p
()
3386 "Test `org-export-table-row-starts-header-p' specifications."
3387 ;; 1. Only the row starting the first row group starts the table
3389 (org-test-with-parsed-data "
3397 (org-element-map tree
'table-row
3399 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3401 ;; 2. A row cannot start an header if there's no header in the
3403 (org-test-with-parsed-data "
3407 (org-export-table-row-starts-header-p
3408 (org-element-map tree
'table-row
'identity info
'first-match
)
3411 (ert-deftest test-org-export
/table-row-ends-header-p
()
3412 "Test `org-export-table-row-ends-header-p' specifications."
3413 ;; 1. Only the row starting the first row group starts the table
3415 (org-test-with-parsed-data "
3423 (org-element-map tree
'table-row
3425 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3427 ;; 2. A row cannot start an header if there's no header in the
3429 (org-test-with-parsed-data "
3433 (org-export-table-row-ends-header-p
3434 (org-element-map tree
'table-row
'identity info
'first-match
)
3439 ;;; Tables of Contents
3441 (ert-deftest test-org-export
/collect-headlines
()
3442 "Test `org-export-collect-headlines' specifications."
3447 (org-test-with-parsed-data "* H1\n** H2"
3448 (org-export-collect-headlines info
)))))
3449 ;; Do not collect headlines below optional argument.
3453 (org-test-with-parsed-data "* H1\n** H2"
3454 (org-export-collect-headlines info
1)))))
3455 ;; Never collect headlines below maximum headline level.
3459 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3460 (org-export-collect-headlines info
)))))
3464 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3465 (org-export-collect-headlines info
2)))))
3466 ;; Collect headlines locally.
3469 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3470 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3471 (length (org-export-collect-headlines info nil scope
))))))
3472 ;; When collecting locally, optional level is relative.
3475 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3476 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3477 (length (org-export-collect-headlines info
1 scope
)))))))
3483 (ert-deftest test-org-export
/inner-template
()
3484 "Test `inner-template' translator specifications."
3487 (org-test-with-temp-text "* Headline"
3489 (org-export-create-backend
3491 '((inner-template .
(lambda (contents info
) "Success!"))
3492 (headline .
(lambda (h c i
) "Headline"))))))))
3493 ;; Inner template is applied even in a "body-only" export.
3496 (org-test-with-temp-text "* Headline"
3498 (org-export-create-backend
3499 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3500 (headline .
(lambda (h c i
) "Headline"))))
3501 nil nil
'body-only
)))))
3503 (ert-deftest test-org-export
/template
()
3504 "Test `template' translator specifications."
3507 (org-test-with-temp-text "* Headline"
3509 (org-export-create-backend
3510 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3511 (headline .
(lambda (h c i
) "Headline"))))))))
3512 ;; Template is not applied in a "body-only" export.
3515 (org-test-with-temp-text "* Headline"
3517 (org-export-create-backend
3518 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3519 (headline .
(lambda (h c i
) "Headline"))))
3520 nil nil
'body-only
)))))
3526 (ert-deftest test-org-export
/get-next-element
()
3527 "Test `org-export-get-next-element' specifications."
3531 (org-test-with-parsed-data "* Headline\n*a* b"
3532 (org-export-get-next-element
3533 (org-element-map tree
'bold
'identity info t
) info
))))
3534 ;; Return nil when no previous element.
3536 (org-test-with-parsed-data "* Headline\na *b*"
3537 (org-export-get-next-element
3538 (org-element-map tree
'bold
'identity info t
) info
)))
3539 ;; Non-exportable elements are ignored.
3541 (let ((org-export-with-timestamps nil
))
3542 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3543 (org-export-get-next-element
3544 (org-element-map tree
'entity
'identity info t
) info
))))
3545 ;; Find next element in secondary strings.
3548 (org-test-with-parsed-data "* a =verb="
3550 (org-export-get-next-element
3551 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3554 (org-test-with-parsed-data "* /italic/ =verb="
3556 (org-export-get-next-element
3557 (org-element-map tree
'italic
'identity info t
) info
)))))
3558 ;; Find next element in document keywords.
3561 (org-test-with-parsed-data "#+TITLE: a =verb="
3563 (org-export-get-next-element
3565 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3566 ;; Find next element in parsed affiliated keywords.
3569 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3571 (org-export-get-next-element
3572 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3573 ;; With optional argument N, return a list containing all the
3574 ;; following elements.
3577 '(bold code underline
)
3578 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3580 (org-export-get-next-element
3581 (org-element-map tree
'italic
'identity info t
) info t
)))))
3582 ;; When N is a positive integer, return a list containing up to
3583 ;; N following elements.
3587 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3589 (org-export-get-next-element
3590 (org-element-map tree
'italic
'identity info t
) info
2))))))
3592 (ert-deftest test-org-export
/get-previous-element
()
3593 "Test `org-export-get-previous-element' specifications."
3597 (org-test-with-parsed-data "* Headline\na *b*"
3598 (org-export-get-previous-element
3599 (org-element-map tree
'bold
'identity info t
) info
))))
3600 ;; Return nil when no previous element.
3602 (org-test-with-parsed-data "* Headline\n*a* b"
3603 (org-export-get-previous-element
3604 (org-element-map tree
'bold
'identity info t
) info
)))
3605 ;; Non-exportable elements are ignored.
3607 (let ((org-export-with-timestamps nil
))
3608 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3609 (org-export-get-previous-element
3610 (org-element-map tree
'entity
'identity info t
) info
))))
3611 ;; Find previous element in secondary strings.
3614 (org-test-with-parsed-data "* =verb= a"
3616 (org-export-get-previous-element
3617 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3620 (org-test-with-parsed-data "* =verb= /italic/"
3622 (org-export-get-previous-element
3623 (org-element-map tree
'italic
'identity info t
) info
)))))
3624 ;; Find previous element in document keywords.
3627 (org-test-with-parsed-data "#+TITLE: =verb= a"
3629 (org-export-get-previous-element
3631 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3632 ;; Find previous element in parsed affiliated keywords.
3635 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3637 (org-export-get-previous-element
3638 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3639 ;; With optional argument N, return a list containing up to
3640 ;; N previous elements.
3642 (equal '(underline italic bold
)
3643 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3645 (org-export-get-previous-element
3646 (org-element-map tree
'code
'identity info t
) info t
)))))
3647 ;; When N is a positive integer, return a list containing up to
3648 ;; N previous elements.
3650 (equal '(italic bold
)
3651 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3653 (org-export-get-previous-element
3654 (org-element-map tree
'code
'identity info t
) info
2))))))
3658 ;;; test-org-export.el end here