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 :section-numbers t
:preserve-breaks 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-priority t
:with-special-strings t
121 :with-sub-superscript t
:with-toc t
:with-tables t
:with-tags t
122 :with-tasks t
:with-timestamps t
:with-todo-keywords t
123 :with-inlinetasks nil
:with-statistics-cookies t
:with-title 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")
129 '(:with-archived-trees
130 headline
:with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
131 :with-tags not-in-toc
:with-tasks todo
:section-numbers
2
132 :with-timestamps active
)))
133 ;; Test back-end specific values.
136 (org-export--parse-option-keyword
137 "opt:t" (org-export-create-backend :options
'((:option nil
"opt"))))
140 (ert-deftest test-org-export
/get-inbuffer-options
()
141 "Test reading all standard export keywords."
142 ;; Properties should follow buffer order.
145 (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
146 (org-export--get-inbuffer-options))
147 '(:language
"fr" :creator
"Me" :email
"email")))
148 ;; Test `space' behaviour.
151 (let ((back-end (org-export-create-backend
152 :options
'((:keyword
"KEYWORD" nil nil space
)))))
153 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: spaces"
154 (org-export--get-inbuffer-options back-end
)))
155 '(:keyword
"With spaces")))
156 ;; Test `newline' behaviour.
159 (let ((back-end (org-export-create-backend
160 :options
'((:keyword
"KEYWORD" nil nil newline
)))))
161 (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: two lines"
162 (org-export--get-inbuffer-options back-end
)))
163 '(:keyword
"With\ntwo lines")))
164 ;; Test `split' behaviour.
167 (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
168 (org-export--get-inbuffer-options))
169 '(:select-tags
("a" "b"))))
170 ;; Test `parse' behaviour. `parse' implies `space' but preserve
171 ;; line breaks. Multi-line objects are allowed.
174 (org-test-with-temp-text "#+TITLE: *bold*"
175 (plist-get (org-export--get-inbuffer-options) :title
))
176 'bold
#'identity nil t
))
179 (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
180 (plist-get (org-export--get-inbuffer-options) :title
))
181 '("Some title with spaces")))
184 (org-test-with-temp-text "#+TITLE: Some title\\\\\n#+TITLE: with spaces"
185 (plist-get (org-export--get-inbuffer-options) :title
))
186 'line-break
#'identity nil t
))
189 (org-test-with-temp-text "#+TITLE: *bold\n#+TITLE: sentence*"
190 (plist-get (org-export--get-inbuffer-options) :title
))
191 'bold
#'identity nil t
))
192 ;; Options set through SETUPFILE.
195 (org-test-with-temp-text
196 (format "#+DESCRIPTION: l1
200 #+SETUPFILE: \"%s/examples/setupfile.org\"
205 (org-export--get-inbuffer-options))
206 '(:language
"fr" :select-tags
("a" "b" "c") :title
("a b c"))))
207 ;; More than one property can refer to the same buffer keyword.
209 (equal '(:k2
"value" :k1
"value")
210 (let ((backend (org-export-create-backend
211 :options
'((:k1
"KEYWORD")
213 (org-test-with-temp-text "#+KEYWORD: value"
214 (org-export--get-inbuffer-options backend
)))))
215 ;; Keywords in commented subtrees are ignored.
218 (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
219 (plist-get info
:author
))))
222 (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
223 (plist-get info
:email
)))))
225 (ert-deftest test-org-export
/get-subtree-options
()
226 "Test setting options from headline's properties."
228 (org-test-with-temp-text "#+TITLE: Title
231 :EXPORT_TITLE: Subtree Title
235 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
236 '("Subtree Title"))))
240 (org-test-with-temp-text "#+OPTIONS: H:1
248 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
250 (org-test-with-temp-text "#+DATE: today
253 :EXPORT_DATE: 29-03-2012
257 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
259 ;; Properties with `split' behaviour are stored as a list of
263 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
266 :EXPORT_EXCLUDE_TAGS: a b
271 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
272 ;; Handle :PROPERTY+: syntax.
275 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
278 :EXPORT_EXCLUDE_TAGS: a
279 :EXPORT_EXCLUDE_TAGS+: b
284 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
285 ;; Export properties are case-insensitive.
286 (org-test-with-temp-text "* Headline
288 :EXPORT_Date: 29-03-2012
291 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
293 ;; Still grab correct options when section above is empty.
296 (org-test-with-temp-text "* H1\n** H11\n** H12"
297 (progn (forward-line 2)
298 (plist-get (org-export-get-environment nil t
) :title
))))))
300 (ert-deftest test-org-export
/set-title
()
301 "Test title setting."
302 ;; Without TITLE keyword.
306 (let (org-export-filter-body-functions
307 org-export-filter-final-output-functions
)
308 (org-test-with-temp-text "Test"
310 (org-export-create-backend
312 '((template .
(lambda (text info
)
313 (org-element-interpret-data
314 (plist-get info
:title
)))))))))))
315 ;; With a blank TITLE keyword.
319 (let (org-export-filter-body-functions
320 org-export-filter-final-output-functions
)
321 (org-test-with-temp-text "#+TITLE:\nTest"
323 (org-export-create-backend
325 '((template .
(lambda (text info
)
326 (org-element-interpret-data
327 (plist-get info
:title
)))))))))))
328 ;; With a non-empty TITLE keyword.
332 (org-test-with-temp-text "#+TITLE: Title\nTest"
334 (org-export-create-backend
336 '((template .
(lambda (text info
)
337 (org-element-interpret-data
338 (plist-get info
:title
))))))))))
339 ;; When exporting a subtree, its heading becomes the headline of the
344 (org-test-with-temp-text "* Headline\nBody"
346 (org-export-create-backend
348 '((template .
(lambda (text info
)
349 (org-element-interpret-data
350 (plist-get info
:title
))))))
352 ;; ... unless there is an EXPORT_TITLE property at the root of the
357 (org-test-with-temp-text
358 "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
360 (org-export-create-backend
362 '((template .
(lambda (text info
)
363 (org-element-interpret-data
364 (plist-get info
:title
))))))
367 (ert-deftest test-org-export
/handle-options
()
368 "Test if export options have an impact on output."
369 ;; Test exclude tags for headlines and inlinetasks.
372 (let (org-export-filter-body-functions
373 org-export-filter-final-output-functions
)
374 (org-test-with-temp-text "* Head1 :noexp:"
375 (org-export-as (org-test-default-backend)
376 nil nil nil
'(:exclude-tags
("noexp")))))))
377 ;; Test include tags for headlines and inlinetasks.
379 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
380 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
381 (let ((org-tags-column 0))
382 (org-export-as (org-test-default-backend)
383 nil nil nil
'(:select-tags
("exp")))))))
384 ;; If there is an include tag, ignore the section before the first
387 (equal "* H1 :exp:\nBody\n"
388 (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
389 (let ((org-tags-column 0))
390 (org-export-as (org-test-default-backend)
391 nil nil nil
'(:select-tags
("exp")))))))
393 (equal "* H1 :exp:\n"
394 (org-test-with-temp-text "* H1 :exp:\nBody"
395 (let ((org-tags-column 0))
396 (org-export-as (org-test-default-backend)
397 nil nil nil
'(:select-tags
("exp")))))))
398 ;; Test mixing include tags and exclude tags.
401 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
402 (org-test-with-temp-text "
404 ** Sub-Head1 :noexport:
407 ** Sub-Head1 :export:"
408 (org-export-as (org-test-default-backend) nil nil nil
409 '(:select-tags
("export") :exclude-tags
("noexport"))))))
413 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
414 org-export-filter-body-functions
415 org-export-filter-final-output-functions
)
416 (org-test-with-temp-text "* TODO Head1"
417 (org-export-as (org-test-default-backend)
418 nil nil nil
'(:with-tasks nil
))))))
420 (equal "* TODO Head1\n"
421 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
422 (org-test-with-temp-text "* TODO Head1"
423 (org-export-as (org-test-default-backend)
424 nil nil nil
'(:with-tasks t
))))))
428 (let (org-export-filter-body-functions
429 org-export-filter-final-output-functions
)
430 (org-test-with-temp-text "* Head1 :archive:"
431 (let ((org-archive-tag "archive"))
432 (org-export-as (org-test-default-backend)
433 nil nil nil
'(:with-archived-trees nil
)))))))
436 "\\* Head1[ \t]+:archive:"
437 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
438 (let ((org-archive-tag "archive"))
439 (org-export-as (org-test-default-backend) nil nil nil
440 '(:with-archived-trees headline
))))))
443 "\\`\\* Head1[ \t]+:archive:\n\\'"
444 (org-test-with-temp-text "* Head1 :archive:"
445 (let ((org-archive-tag "archive"))
446 (org-export-as (org-test-default-backend)
447 nil nil nil
'(:with-archived-trees t
))))))
450 (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
451 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
452 (org-export-as (org-test-default-backend)
453 nil nil nil
'(:with-clocks t
)))))
456 (let (org-export-filter-body-functions
457 org-export-filter-final-output-functions
)
458 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
459 (org-export-as (org-test-default-backend)
460 nil nil nil
'(:with-clocks nil
))))))
464 (let (org-export-filter-body-functions
465 org-export-filter-final-output-functions
)
466 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
467 (org-export-as (org-test-default-backend)
468 nil nil nil
'(:with-drawers nil
))))))
470 (equal ":TEST:\ncontents\n:END:\n"
471 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
472 (org-export-as (org-test-default-backend)
473 nil nil nil
'(:with-drawers t
)))))
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
("FOO"))))))
480 (equal ":FOO:\nkeep\n:END:\n"
481 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
482 (org-export-as (org-test-default-backend)
483 nil nil nil
'(:with-drawers
(not "BAR"))))))
487 (org-test-with-temp-text ": A"
488 (org-export-as (org-test-default-backend) nil nil nil
489 '(:with-fixed-width t
)))))
492 (let (org-export-filter-body-functions
493 org-export-filter-final-output-functions
)
494 (org-test-with-temp-text ": A"
495 (org-export-as (org-test-default-backend) nil nil nil
496 '(:with-fixed-width nil
))))))
500 (let ((org-footnote-section nil
))
501 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
502 (org-trim (org-export-as (org-test-default-backend)
503 nil nil nil
'(:with-footnotes nil
)))))))
505 (equal "Footnote?[fn:1]\n\n[fn:1] Def"
506 (let ((org-footnote-section nil
))
507 (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
508 (org-trim (org-export-as (org-test-default-backend)
509 nil nil nil
'(:with-footnotes t
)))))))
511 (when (featurep 'org-inlinetask
)
515 (let ((org-inlinetask-min-level 15)
516 org-export-filter-body-functions
517 org-export-filter-final-output-functions
)
518 (org-test-with-temp-text "*************** Task"
519 (org-export-as (org-test-default-backend)
520 nil nil nil
'(:with-inlinetasks nil
))))))
524 (let ((org-inlinetask-min-level 15)
525 org-export-filter-body-functions
526 org-export-filter-final-output-functions
)
527 (org-test-with-temp-text
528 "*************** Task\nContents\n*************** END"
529 (org-export-as (org-test-default-backend)
530 nil nil nil
'(:with-inlinetasks nil
)))))))
534 "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
535 (let ((org-closed-string "CLOSED:"))
536 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
537 (org-export-as (org-test-default-backend)
538 nil nil nil
'(:with-planning t
))))))
541 (let ((org-closed-string "CLOSED:"))
542 (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
543 (org-export-as (org-test-default-backend)
544 nil nil nil
'(:with-planning nil
))))))
548 (org-test-with-temp-text
549 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
550 (org-export-as (org-test-default-backend)
551 nil nil nil
'(:with-properties nil
)))))
553 (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
554 (org-test-with-temp-text
555 "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
556 (org-export-as (org-test-default-backend)
557 nil nil nil
'(:with-properties t
)))))
559 (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
560 (org-test-with-temp-text
561 "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
562 (org-export-as (org-test-default-backend)
563 nil nil nil
'(:with-properties
("B"))))))
564 ;; Statistics cookies.
567 (let (org-export-filter-body-functions
568 org-export-filter-final-output-functions
)
570 (org-test-with-temp-text "[0/0]"
571 (org-export-as (org-test-default-backend)
572 nil nil nil
'(:with-statistics-cookies nil
)))))))
576 (org-test-with-temp-text "| A |"
577 (org-export-as (org-test-default-backend) nil nil nil
578 '(:with-tables t
)))))
581 (let (org-export-filter-body-functions
582 org-export-filter-final-output-functions
)
583 (org-test-with-temp-text "| A |"
584 (org-export-as (org-test-default-backend) nil nil nil
585 '(:with-tables nil
)))))))
587 (ert-deftest test-org-export
/with-timestamps
()
588 "Test `org-export-with-timestamps' specifications."
592 "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
593 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
594 (org-export-as (org-test-default-backend)
595 nil nil nil
'(:with-timestamps t
)))))
600 (let (org-export-filter-body-functions
601 org-export-filter-final-output-functions
)
603 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
604 (org-export-as (org-test-default-backend)
605 nil nil nil
'(:with-timestamps nil
)))))))
609 "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
610 (org-test-with-temp-text
611 "<2012-03-29 Thu>[2012-03-29 Thu]
613 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
614 (org-export-as (org-test-default-backend)
615 nil nil nil
'(:with-timestamps active
)))))
619 "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
620 (org-test-with-temp-text
621 "<2012-03-29 Thu>[2012-03-29 Thu]
623 Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
624 (org-export-as (org-test-default-backend)
625 nil nil nil
'(:with-timestamps inactive
))))))
627 (ert-deftest test-org-export
/comment-tree
()
628 "Test if export process ignores commented trees."
631 (let (org-export-filter-body-functions
632 org-export-filter-final-output-functions
)
633 (org-test-with-temp-text "* COMMENT Head1"
634 (org-export-as (org-test-default-backend)))))))
636 (ert-deftest test-org-export
/uninterpreted
()
637 "Test handling of uninterpreted elements."
641 (org-test-with-temp-text "\\alpha"
643 (org-export-create-backend
644 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
645 (paragraph .
(lambda (p c i
) c
))
646 (section .
(lambda (s c i
) c
))))
647 nil nil nil
'(:with-entities t
)))))
650 (org-test-with-temp-text "\\alpha"
652 (org-export-create-backend
653 :transcoders
'((entity .
(lambda (e c i
) "dummy"))
654 (paragraph .
(lambda (p c i
) c
))
655 (section .
(lambda (s c i
) c
))))
656 nil nil nil
'(:with-entities nil
)))))
660 (org-test-with-temp-text "*bold*"
662 (org-export-create-backend
663 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
664 (paragraph .
(lambda (p c i
) c
))
665 (section .
(lambda (s c i
) c
))))
666 nil nil nil
'(:with-emphasize t
)))))
669 (org-test-with-temp-text "*bold*"
671 (org-export-create-backend
672 :transcoders
'((bold .
(lambda (b c i
) "dummy"))
673 (paragraph .
(lambda (p c i
) c
))
674 (section .
(lambda (s c i
) c
))))
675 nil nil nil
'(:with-emphasize nil
)))))
676 ;; LaTeX environment.
679 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
681 (org-export-create-backend
682 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
683 (section .
(lambda (s c i
) c
))))
684 nil nil nil
'(:with-latex t
)))))
686 (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
687 (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
689 (org-export-create-backend
690 :transcoders
'((latex-environment .
(lambda (l c i
) "dummy"))
691 (section .
(lambda (s c i
) c
))))
692 nil nil nil
'(:with-latex verbatim
)))))
696 (org-test-with-temp-text "$1$"
698 (org-export-create-backend
699 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
700 (paragraph .
(lambda (p c i
) c
))
701 (section .
(lambda (s c i
) c
))))
702 nil nil nil
'(:with-latex t
)))))
705 (org-test-with-temp-text "$1$"
707 (org-export-create-backend
708 :transcoders
'((latex-fragment .
(lambda (l c i
) "dummy"))
709 (paragraph .
(lambda (p c i
) c
))
710 (section .
(lambda (s c i
) c
))))
711 nil nil nil
'(:with-latex verbatim
)))))
715 (org-test-with-temp-text "a_b"
717 (org-export-create-backend
718 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
719 (paragraph .
(lambda (p c i
) c
))
720 (section .
(lambda (s c i
) c
))))
721 nil nil nil
'(:with-sub-superscript t
)))))
724 (org-test-with-temp-text "a_b"
726 (org-export-create-backend
727 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
728 (paragraph .
(lambda (p c i
) c
))
729 (section .
(lambda (s c i
) c
))))
730 nil nil nil
'(:with-sub-superscript nil
)))))
733 (org-test-with-temp-text "a_b"
735 (org-export-create-backend
736 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
737 (paragraph .
(lambda (p c i
) c
))
738 (section .
(lambda (s c i
) c
))))
739 nil nil nil
'(:with-sub-superscript
{})))))
742 (org-test-with-temp-text "a_{b}"
744 (org-export-create-backend
745 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
746 (paragraph .
(lambda (p c i
) c
))
747 (section .
(lambda (s c i
) c
))))
748 nil nil nil
'(:with-sub-superscript
{})))))
749 ;; Also handle uninterpreted objects in title.
752 (org-test-with-temp-text "#+TITLE: a_b"
754 (org-export-create-backend
756 '((subscript .
(lambda (s c i
) "dummy"))
757 (template .
(lambda (c i
) (org-export-data
758 (plist-get i
:title
) i
)))
759 (section .
(lambda (s c i
) c
))))
760 nil nil nil
'(:with-sub-superscript nil
)))))
761 ;; Special case: multiples uninterpreted objects in a row.
764 (org-test-with-temp-text "a_b_c_d"
766 (org-export-create-backend
767 :transcoders
'((subscript .
(lambda (s c i
) "dummy"))
768 (paragraph .
(lambda (p c i
) c
))
769 (section .
(lambda (s c i
) c
))))
770 nil nil nil
'(:with-sub-superscript
{}))))))
772 (ert-deftest test-org-export
/export-scope
()
773 "Test all export scopes."
774 (org-test-with-temp-text "
781 (should (equal (org-export-as (org-test-default-backend) 'subtree
)
782 "text\n*** Head3\n"))
784 (goto-char (point-min))
787 (should (equal (org-export-as (org-test-default-backend) nil
'visible
)
790 (goto-char (point-min))
792 (transient-mark-mode 1)
793 (push-mark (point) t t
)
794 (goto-char (point-at-eol))
795 (should (equal (org-export-as (org-test-default-backend)) "text\n")))
796 ;; Subtree with a code block calling another block outside.
797 (let ((org-export-babel-evaluate t
))
800 (org-test-with-temp-text "
802 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
807 #+BEGIN_SRC emacs-lisp
811 (org-export-as (org-test-default-backend) 'subtree
)))))
813 (let ((backend (org-test-default-backend)))
814 (setf (org-export-backend-transcoders backend
)
815 (cons '(template .
(lambda (body i
)
816 (format "BEGIN\n%sEND" body
)))
817 (org-export-backend-transcoders backend
)))
818 (org-test-with-temp-text "Text"
819 (should (equal (org-export-as backend nil nil
'body-only
)
821 (should (equal (org-export-as backend
) "BEGIN\nText\nEND")))))
823 (ert-deftest test-org-export
/output-file-name
()
824 "Test `org-export-output-file-name' specifications."
825 ;; Export from a file: name is built from original file name.
827 (org-test-with-temp-text-in-file "Test"
828 (equal (concat (file-name-as-directory ".")
829 (file-name-nondirectory
830 (file-name-sans-extension (buffer-file-name))))
831 (file-name-sans-extension (org-export-output-file-name ".ext")))))
832 ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
834 (org-test-with-temp-text-in-file
835 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
836 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
837 ;; From a buffer not associated to a file, too.
839 (org-test-with-temp-text
840 "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
841 (equal (org-export-output-file-name ".ext" t
) "./test.ext")))
842 ;; When provided name is absolute, preserve it.
844 (org-test-with-temp-text
845 (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
846 (expand-file-name "test"))
847 (file-name-absolute-p (org-export-output-file-name ".ext" t
))))
848 ;; When PUB-DIR argument is provided, use it.
850 (org-test-with-temp-text-in-file "Test"
851 (equal (file-name-directory
852 (org-export-output-file-name ".ext" nil
"dir/"))
854 ;; When returned name would overwrite original file, add EXTENSION
857 (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
858 (equal (org-export-output-file-name ".org") "./normal.org.org"))))
860 (ert-deftest test-org-export
/expand-include
()
861 "Test file inclusion in an Org buffer."
862 ;; Error when file isn't specified.
864 (org-test-with-temp-text "#+INCLUDE: dummy.org"
865 (org-export-expand-include-keyword)))
866 ;; Full insertion with recursive inclusion.
871 (expand-file-name "examples/include.org" org-test-dir
))
872 (replace-regexp-in-string
873 (regexp-quote "#+INCLUDE: \"include2.org\"")
874 "Success!" (buffer-string)))
875 (org-test-with-temp-text
876 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
877 (org-export-expand-include-keyword)
879 ;; Localized insertion.
880 (org-test-with-temp-text
881 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
883 (org-export-expand-include-keyword)
884 (should (equal (buffer-string)
885 "Small Org file with an include keyword.\n")))
886 ;; Insertion with constraints on headlines level.
889 "* Top heading\n** Heading\nbody\n"
890 (org-test-with-temp-text
892 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
894 (org-export-expand-include-keyword)
898 "* Top heading\n* Heading\nbody\n"
899 (org-test-with-temp-text
901 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
903 (org-export-expand-include-keyword)
905 ;; Inclusion within an example block.
908 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
909 (org-test-with-temp-text
910 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
912 (org-export-expand-include-keyword)
914 ;; Inclusion within a src-block.
917 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
918 (org-test-with-temp-text
920 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
922 (org-export-expand-include-keyword)
924 ;; Inclusion within an html export-block.
927 "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
928 (org-test-with-temp-text
930 "#+INCLUDE: \"%s/examples/include.html\" HTML"
932 (org-export-expand-include-keyword)
934 ;; Inclusion within an center paragraph
937 "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
938 (org-test-with-temp-text
940 "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
942 (org-export-expand-include-keyword)
944 ;; Footnotes labels are local to each included file.
950 Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
952 \[fn:test] Footnote \"test\""))
953 (org-test-with-temp-text-in-file contents
954 (let ((file1 (buffer-file-name)))
955 (org-test-with-temp-text-in-file contents
956 (let ((file2 (buffer-file-name)))
957 (org-test-with-temp-text
958 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
960 (org-export-expand-include-keyword)
961 (org-element-map (org-element-parse-buffer)
964 (org-element-property :label ref
)))))))))))))
965 ;; Footnotes labels are not local to each include keyword.
971 Footnotes[fn:1], [fn:test], [2] and [fn:inline:anonymous footnote].
974 \[fn:test] Footnote \"test\""))
975 (org-test-with-temp-text-in-file contents
976 (let ((file (buffer-file-name)))
977 (org-test-with-temp-text
978 (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file
)
979 (org-export-expand-include-keyword)
980 (org-element-map (org-element-parse-buffer)
982 (lambda (ref) (org-element-property :label ref
)))))))))))
983 ;; Footnotes are supported by :lines-like elements and unnecessary
984 ;; footnotes are dropped.
993 Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote]
998 \[fn:test] Footnote \"test\"
1001 (org-test-with-temp-text-in-file contents
1002 (let ((file (buffer-file-name)))
1003 (org-test-with-temp-text
1004 (format "#+INCLUDE: \"%s::*bar\"
1006 (org-export-expand-include-keyword)
1007 (org-element-map (org-element-parse-buffer)
1008 'footnote-definition
1009 (lambda (ref) (org-element-property :label ref
)))))))))))
1010 ;; If only-contents is non-nil only include contents of element.
1014 (org-test-with-temp-text
1016 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir
)
1018 (org-export-expand-include-keyword)
1020 ;; Headings can be included via CUSTOM_ID.
1022 (org-test-with-temp-text
1023 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1024 (org-export-expand-include-keyword)
1025 (goto-char (point-min))
1026 (looking-at "* Another heading")))
1027 ;; Named objects can be included.
1031 (org-test-with-temp-text
1032 (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir
)
1033 (org-export-expand-include-keyword)
1035 ;; Including non-existing elements should result in an error.
1037 (org-test-with-temp-text
1038 (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir
)
1039 (org-export-expand-include-keyword)))
1040 ;; Lines work relatively to an included element.
1044 (org-test-with-temp-text
1045 (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir
)
1046 (org-export-expand-include-keyword)
1048 ;; Properties should be dropped from headlines.
1051 (org-test-with-temp-text
1052 (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir
)
1053 (org-export-expand-include-keyword)
1055 (org-test-with-temp-text
1056 (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir
)
1057 (org-export-expand-include-keyword)
1059 ;; Properties should be dropped, drawers should not be.
1062 ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
1063 (org-test-with-temp-text
1064 (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir
)
1065 (org-export-expand-include-keyword)
1067 ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
1069 (org-every (lambda (level) (zerop (1- level
)))
1070 (org-test-with-temp-text
1072 (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir
)
1073 (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir
))
1074 (org-export-expand-include-keyword)
1075 (org-element-map (org-element-parse-buffer) 'headline
1076 (lambda (head) (org-element-property :level head
))))))
1077 ;; INCLUDE does not insert induced :minlevel for src-blocks.
1080 (org-test-with-temp-text
1081 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir
)
1082 (org-export-expand-include-keyword)
1084 (org-test-with-temp-text
1085 (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir
)
1086 (org-export-expand-include-keyword)
1088 ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
1090 (org-test-with-temp-text-in-file
1091 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir
)
1092 (narrow-to-region (point) (point-max))
1093 (org-export-expand-include-keyword)
1094 (eq 1 (org-current-level))))
1095 ;; If :minlevel is present do not alter it.
1097 (org-test-with-temp-text
1098 (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir
)
1099 (narrow-to-region (point) (point-max))
1100 (org-export-expand-include-keyword)
1101 (eq 3 (org-current-level)))))
1103 (ert-deftest test-org-export
/expand-macro
()
1104 "Test macro expansion in an Org buffer."
1105 ;; Standard macro expansion.
1107 (equal "#+MACRO: macro1 value\nvalue\n"
1108 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
1109 (org-export-as (org-test-default-backend)))))
1110 ;; Allow macro in parsed keywords and associated properties.
1111 ;; Standard macro expansion.
1115 (let ((backend (org-export-create-backend
1117 :options
'((:k
"K" nil nil parse
)))))
1118 (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
1119 (org-export-as backend
)))))
1123 (let ((backend (org-export-create-backend
1125 :options
'((:k
"K" nil nil parse
)))))
1126 (org-test-with-temp-text
1127 "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
1128 (org-export-as backend nil nil nil
'(:with-properties t
))))))
1129 ;; Expand specific macros.
1131 (equal "me 2012-03-29 me@here Title\n"
1132 (org-test-with-temp-text
1138 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
1139 (let ((output (org-export-as (org-test-default-backend))))
1140 (substring output
(string-match ".*\n\\'" output
))))))
1141 ;; Expand specific macros when property contained a regular macro
1145 (org-test-with-temp-text "
1146 #+MACRO: macro1 value
1147 #+TITLE: {{{macro1}}}
1149 (let ((output (org-export-as (org-test-default-backend))))
1150 (substring output
(string-match ".*\n\\'" output
))))))
1151 ;; Expand macros with templates in included files.
1154 (org-test-with-temp-text
1155 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
1156 {{{included-macro}}}" org-test-dir
)
1157 (let ((output (org-export-as (org-test-default-backend))))
1158 (substring output
(string-match ".*\n\\'" output
))))))
1159 ;; Date macro takes a optional formatting argument
1162 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
1163 (org-export-as (org-test-default-backend)))))
1164 ;; Only single timestamps are formatted
1166 (equal "<2015-02x-09>\n"
1167 (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
1168 (org-export-as (org-test-default-backend)))))
1169 ;; Throw an error when a macro definition is missing.
1171 (org-test-with-temp-text "{{{missing}}}"
1172 (org-export-as (org-test-default-backend))))
1173 ;; Macros defined in commented subtrees are ignored.
1175 (org-test-with-temp-text
1176 "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
1177 (org-export-as (org-test-default-backend))))
1179 (org-test-with-temp-text
1180 "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
1181 (org-export-as (org-test-default-backend)))))
1183 (ert-deftest test-org-export
/before-processing-hook
()
1184 "Test `org-export-before-processing-hook'."
1187 "#+MACRO: mac val\nTest\n"
1188 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
1189 (let ((org-export-before-processing-hook
1191 (while (re-search-forward "{{{" nil t
)
1192 (let ((object (org-element-context)))
1193 (when (eq (org-element-type object
) 'macro
)
1195 (org-element-property :begin object
)
1196 (org-element-property :end object
)))))))))
1197 (org-export-as (org-test-default-backend)))))))
1199 (ert-deftest test-org-export
/before-parsing-hook
()
1200 "Test `org-export-before-parsing-hook'."
1202 (equal "Body 1\nBody 2\n"
1203 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
1204 (let ((org-export-before-parsing-hook
1206 (goto-char (point-min))
1207 (while (re-search-forward org-outline-regexp-bol nil t
)
1209 (point-at-bol) (progn (forward-line) (point))))))))
1210 (org-export-as (org-test-default-backend)))))))
1214 ;;; Affiliated Keywords
1216 (ert-deftest test-org-export
/read-attribute
()
1217 "Test `org-export-read-attribute' specifications."
1221 (org-export-read-attribute
1223 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
1224 (org-element-at-point)))
1226 ;; Return nil on empty attribute.
1228 (org-export-read-attribute
1230 (org-test-with-temp-text "Paragraph" (org-element-at-point))))
1231 ;; Return nil on "nil" string.
1233 (equal '(:a nil
:b nil
)
1234 (org-export-read-attribute
1236 (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
1237 (org-element-at-point)))))
1238 ;; Return nil on empty string.
1240 (equal '(:a nil
:b nil
)
1241 (org-export-read-attribute
1243 (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
1244 (org-element-at-point)))))
1245 ;; Return empty string when value is "".
1248 (org-export-read-attribute
1250 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
1251 (org-element-at-point)))))
1252 ;; Return \"\" when value is """".
1255 (org-export-read-attribute
1257 (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
1258 (org-element-at-point)))))
1259 ;; Ignore text before first property.
1262 (org-export-read-attribute
1264 (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
1265 (org-element-at-point))))))
1267 (ert-deftest test-org-export
/get-caption
()
1268 "Test `org-export-get-caption' specifications."
1269 ;; Without optional argument, return long caption
1273 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1274 (org-export-get-caption (org-element-at-point)))))
1275 ;; With optional argument, return short caption.
1279 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
1280 (org-export-get-caption (org-element-at-point) t
))))
1281 ;; Multiple lines are separated by white spaces.
1285 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
1286 (org-export-get-caption (org-element-at-point))))))
1292 (ert-deftest test-org-export
/define-backend
()
1293 "Test back-end definition and accessors."
1296 (equal '((headline . my-headline-test
))
1297 (let (org-export-registered-backends)
1298 (org-export-define-backend 'test
'((headline . my-headline-test
)))
1299 (org-export-get-all-transcoders 'test
))))
1302 (equal '((:filter-headline . my-filter
))
1303 (let (org-export-registered-backends)
1304 (org-export-define-backend 'test
1305 '((headline . my-headline-test
))
1306 :filters-alist
'((:filter-headline . my-filter
)))
1307 (org-export-backend-filters (org-export-get-backend 'test
)))))
1310 (equal '((:prop value
))
1311 (let (org-export-registered-backends)
1312 (org-export-define-backend 'test
1313 '((headline . my-headline-test
))
1314 :options-alist
'((:prop value
)))
1315 (org-export-backend-options (org-export-get-backend 'test
)))))
1318 (equal '(?k
"Test Export" test
)
1319 (let (org-export-registered-backends)
1320 (org-export-define-backend 'test
1321 '((headline . my-headline-test
))
1322 :menu-entry
'(?k
"Test Export" test
))
1323 (org-export-backend-menu (org-export-get-backend 'test
)))))
1326 (equal '(("TEST" . org-element-export-block-parser
))
1327 (let (org-export-registered-backends org-element-block-name-alist
)
1328 (org-export-define-backend 'test
1329 '((headline . my-headline-test
))
1330 :export-block
'("test"))
1331 org-element-block-name-alist
))))
1333 (ert-deftest test-org-export
/define-derived-backend
()
1334 "Test `org-export-define-derived-backend' specifications."
1335 ;; Error when parent back-end is not defined.
1337 (let (org-export-registered-backends)
1338 (org-export-define-derived-backend 'test
'parent
)))
1339 ;; Append translation table to parent's.
1341 (equal '((:headline . test
) (:headline . parent
))
1342 (let (org-export-registered-backends)
1343 (org-export-define-backend 'parent
'((:headline . parent
)))
1344 (org-export-define-derived-backend 'test
'parent
1345 :translate-alist
'((:headline . test
)))
1346 (org-export-get-all-transcoders 'test
))))
1347 ;; Options defined in the new back have priority over those defined
1351 (let (org-export-registered-backends)
1352 (org-export-define-backend 'parent
1353 '((:headline . parent
))
1354 :options-alist
'((:a nil nil
'parent
)))
1355 (org-export-define-derived-backend 'test
'parent
1356 :options-alist
'((:a nil nil
'test
)))
1357 (plist-get (org-export--get-global-options
1358 (org-export-get-backend 'test
))
1361 (ert-deftest test-org-export
/derived-backend-p
()
1362 "Test `org-export-derived-backend-p' specifications."
1363 ;; Non-nil with direct match.
1365 (let (org-export-registered-backends)
1366 (org-export-define-backend 'test
'((headline . test
)))
1367 (org-export-derived-backend-p 'test
'test
)))
1369 (let (org-export-registered-backends)
1370 (org-export-define-backend 'test
'((headline . test
)))
1371 (org-export-define-derived-backend 'test2
'test
)
1372 (org-export-derived-backend-p 'test2
'test2
)))
1373 ;; Non-nil with a direct parent.
1375 (let (org-export-registered-backends)
1376 (org-export-define-backend 'test
'((headline . test
)))
1377 (org-export-define-derived-backend 'test2
'test
)
1378 (org-export-derived-backend-p 'test2
'test
)))
1379 ;; Non-nil with an indirect parent.
1381 (let (org-export-registered-backends)
1382 (org-export-define-backend 'test
'((headline . test
)))
1383 (org-export-define-derived-backend 'test2
'test
)
1384 (org-export-define-derived-backend 'test3
'test2
)
1385 (org-export-derived-backend-p 'test3
'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-derived-backend-p 'test2
'test
)))
1393 (let (org-export-registered-backends)
1394 (org-export-define-backend 'test
'((headline . test
)))
1395 (org-export-define-backend 'test2
'((headline . test2
)))
1396 (org-export-define-derived-backend 'test3
'test2
)
1397 (org-export-derived-backend-p 'test3
'test
))))
1399 (ert-deftest test-org-export
/get-all-transcoders
()
1400 "Test `org-export-get-all-transcoders' specifications."
1401 ;; Return nil when back-end cannot be found.
1402 (should-not (org-export-get-all-transcoders nil
))
1403 ;; Same as `org-export-transcoders' if no parent.
1405 (equal '((headline . ignore
))
1406 (org-export-get-all-transcoders
1407 (org-export-create-backend
1408 :transcoders
'((headline . ignore
))))))
1409 ;; But inherit from all ancestors whenever possible.
1411 (equal '((section . ignore
) (headline . ignore
))
1412 (let (org-export-registered-backends)
1413 (org-export-define-backend 'b1
'((headline . ignore
)))
1414 (org-export-get-all-transcoders
1415 (org-export-create-backend
1416 :parent
'b1
:transcoders
'((section . ignore
)))))))
1418 (equal '((paragraph . ignore
) (section . ignore
) (headline . ignore
))
1419 (let (org-export-registered-backends)
1420 (org-export-define-backend 'b1
'((headline . ignore
)))
1421 (org-export-define-derived-backend 'b2
'b1
1422 :translate-alist
'((section . ignore
)))
1423 (org-export-get-all-transcoders
1424 (org-export-create-backend
1425 :parent
'b2
:transcoders
'((paragraph . ignore
)))))))
1426 ;; Back-end transcoders overrule inherited ones.
1429 (let (org-export-registered-backends)
1430 (org-export-define-backend 'b1
'((headline . a
)))
1431 (cdr (assq 'headline
1432 (org-export-get-all-transcoders
1433 (org-export-create-backend
1434 :parent
'b1
:transcoders
'((headline . b
))))))))))
1436 (ert-deftest test-org-export
/get-all-options
()
1437 "Test `org-export-get-all-options' specifications."
1438 ;; Return nil when back-end cannot be found.
1439 (should-not (org-export-get-all-options nil
))
1440 ;; Same as `org-export-options' if no parent.
1442 (equal '((headline . ignore
))
1443 (org-export-get-all-options
1444 (org-export-create-backend
1445 :options
'((headline . ignore
))))))
1446 ;; But inherit from all ancestors whenever possible.
1448 (equal '((:key2 value2
) (:key1 value1
))
1449 (let (org-export-registered-backends)
1450 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1451 (org-export-get-all-options
1452 (org-export-create-backend
1453 :parent
'b1
:options
'((:key2 value2
)))))))
1455 (equal '((:key3 value3
) (:key2 value2
) (:key1 value1
))
1456 (let (org-export-registered-backends)
1457 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 value1
)))
1458 (org-export-define-derived-backend 'b2
'b1
1459 :options-alist
'((:key2 value2
)))
1460 (org-export-get-all-options
1461 (org-export-create-backend
1462 :parent
'b2
:options
'((:key3 value3
)))))))
1463 ;; Back-end options overrule inherited ones.
1466 (let (org-export-registered-backends)
1467 (org-export-define-backend 'b1 nil
:options-alist
'((:key1 . a
)))
1469 (org-export-get-all-options
1470 (org-export-create-backend
1471 :parent
'b1
:options
'((:key1 . b
))))))))))
1473 (ert-deftest test-org-export
/get-all-filters
()
1474 "Test `org-export-get-all-filters' specifications."
1475 ;; Return nil when back-end cannot be found.
1476 (should-not (org-export-get-all-filters nil
))
1477 ;; Same as `org-export-filters' if no parent.
1479 (equal '((:filter-headline . ignore
))
1480 (org-export-get-all-filters
1481 (org-export-create-backend
1482 :filters
'((:filter-headline . ignore
))))))
1483 ;; But inherit from all ancestors whenever possible.
1485 (equal '((:filter-section . ignore
) (:filter-headline . ignore
))
1486 (let (org-export-registered-backends)
1487 (org-export-define-backend 'b1
1488 nil
:filters-alist
'((:filter-headline . ignore
)))
1489 (org-export-get-all-filters
1490 (org-export-create-backend
1491 :parent
'b1
:filters
'((:filter-section . ignore
)))))))
1493 (equal '((:filter-paragraph . ignore
)
1494 (:filter-section . ignore
)
1495 (:filter-headline . ignore
))
1496 (let (org-export-registered-backends)
1497 (org-export-define-backend 'b1
1498 nil
:filters-alist
'((:filter-headline . ignore
)))
1499 (org-export-define-derived-backend 'b2
'b1
1500 :filters-alist
'((:filter-section . ignore
)))
1501 (org-export-get-all-filters
1502 (org-export-create-backend
1503 :parent
'b2
:filters
'((:filter-paragraph . ignore
)))))))
1504 ;; Back-end filters overrule inherited ones.
1507 (let (org-export-registered-backends)
1508 (org-export-define-backend 'b1
'((:filter-headline . a
)))
1509 (cdr (assq :filter-headline
1510 (org-export-get-all-filters
1511 (org-export-create-backend
1512 :parent
'b1
:filters
'((:filter-headline . b
))))))))))
1514 (ert-deftest test-org-export
/with-backend
()
1515 "Test `org-export-with-backend' definition."
1516 ;; Error when calling an undefined back-end
1517 (should-error (org-export-with-backend nil
"Test"))
1518 ;; Error when called back-end doesn't have an appropriate
1521 (org-export-with-backend
1522 (org-export-create-backend :transcoders
'((headline . ignore
)))
1524 ;; Otherwise, export using correct transcoder
1527 (let (org-export-registered-backends)
1528 (org-export-define-backend 'test
1529 '((plain-text .
(lambda (text contents info
) "Failure"))))
1530 (org-export-define-backend 'test2
1531 '((plain-text .
(lambda (text contents info
) "Success"))))
1532 (org-export-with-backend 'test2
"Test"))))
1533 ;; Provide correct back-end if transcoder needs to use recursive
1537 (let ((test-back-end
1538 (org-export-create-backend
1540 '((headline .
(lambda (headline contents info
)
1542 (org-element-property :title headline
)
1544 (plain-text .
(lambda (text info
) "Success"))))))
1545 (org-export-string-as
1547 (org-export-create-backend
1549 '((headline .
(lambda (headline contents info
)
1550 (org-export-with-backend
1551 test-back-end headline contents info
))))))))))
1553 (ert-deftest test-org-export
/data-with-backend
()
1554 "Test `org-export-data-with-backend' specifications."
1555 ;; Error when calling an undefined back-end.
1556 (should-error (org-export-data-with-backend nil
"nil" nil
))
1557 ;; Otherwise, export data recursively, using correct back-end.
1561 (org-export-data-with-backend
1563 (org-export-create-backend
1565 '((plain-text .
(lambda (text info
) "Success"))
1566 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
1567 '(:with-emphasize t
)))))
1573 (ert-deftest test-org-export
/export-snippet
()
1574 "Test export snippets transcoding."
1576 (org-test-with-temp-text "@@test:A@@@@t:B@@"
1577 (let ((backend (org-test-default-backend)))
1578 (setf (org-export-backend-name backend
) 'test
)
1579 (setf (org-export-backend-transcoders backend
)
1580 (cons (cons 'export-snippet
1581 (lambda (snippet contents info
)
1582 (when (eq (org-export-snippet-backend snippet
) 'test
)
1583 (org-element-property :value snippet
))))
1584 (org-export-backend-transcoders backend
)))
1585 (let ((org-export-snippet-translation-alist nil
))
1586 (should (equal (org-export-as backend
) "A\n")))
1587 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
1588 (should (equal (org-export-as backend
) "AB\n")))))
1589 ;; Ignored export snippets do not remove any blank.
1591 (equal "begin end\n"
1592 (org-test-with-parsed-data "begin @@test:A@@ end"
1593 (org-export-data-with-backend
1595 (org-export-create-backend
1597 '((paragraph .
(lambda (paragraph contents info
) contents
))
1598 (section .
(lambda (section contents info
) contents
))))
1605 (ert-deftest test-org-export
/footnote-first-reference-p
()
1606 "Test `org-export-footnote-first-reference-p' specifications."
1610 (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
1613 (org-export-create-backend
1615 `(,(cons 'footnote-reference
1617 (push (org-export-footnote-first-reference-p f info
)
1620 (section .
(lambda (s c i
) c
))
1621 (paragraph .
(lambda (p c i
) c
))))
1622 nil nil nil
'(:with-footnotes t
))
1623 (nreverse result
)))))
1624 ;; Limit check to DATA, when non-nil.
1628 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1630 (org-element-map tree
'footnote-reference
1633 (org-export-footnote-first-reference-p
1634 ref info
(org-element-map tree
'headline
#'identity info t
))
1637 (nreverse result
)))))
1641 (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
1643 (org-element-map tree
'footnote-reference
1645 (push (org-export-footnote-first-reference-p ref info
) result
))
1647 (nreverse result
)))))
1648 ;; If optional argument BODY-FIRST is non-nil, first find footnote
1649 ;; in the main body of the document. Otherwise, enter footnote
1650 ;; definitions when they are encountered.
1654 (org-test-with-temp-text
1655 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1658 (org-export-create-backend
1660 `(,(cons 'footnote-reference
1662 (when (org-element-lineage f
'(drawer))
1663 (push (org-export-footnote-first-reference-p f info nil
)
1666 (drawer .
(lambda (d c i
) c
))
1667 (footnote-definition .
(lambda (d c i
) c
))
1668 (section .
(lambda (s c i
) c
))
1669 (paragraph .
(lambda (p c i
) c
))))
1670 nil nil nil
'(:with-footnotes t
))
1671 (nreverse result
)))))
1675 (org-test-with-temp-text
1676 ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
1679 (org-export-create-backend
1681 `(,(cons 'footnote-reference
1683 (when (org-element-lineage f
'(drawer))
1684 (push (org-export-footnote-first-reference-p f info nil t
)
1687 (drawer .
(lambda (d c i
) c
))
1688 (footnote-definition .
(lambda (d c i
) c
))
1689 (section .
(lambda (s c i
) c
))
1690 (paragraph .
(lambda (p c i
) c
))))
1691 nil nil nil
'(:with-footnotes t
))
1692 (nreverse result
))))))
1694 (ert-deftest test-org-export
/get-footnote-number
()
1695 "Test `org-export-get-footnote-number' specifications."
1698 (org-test-with-parsed-data
1699 "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
1700 (org-element-map tree
'footnote-reference
1701 (lambda (ref) (org-export-get-footnote-number ref info
))
1703 ;; Anonymous footnotes all get a new number.
1706 (org-test-with-parsed-data
1707 "Text[fn::anon1][fn::anon2]"
1708 (org-element-map tree
'footnote-reference
1709 (lambda (ref) (org-export-get-footnote-number ref info
))
1711 ;; Test nested footnotes order.
1714 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (3 .
"fn:3") (4))
1715 (org-test-with-parsed-data
1716 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
1717 (org-element-map tree
'footnote-reference
1719 (cons (org-export-get-footnote-number ref info
)
1720 (org-element-property :label ref
)))
1722 ;; Limit number to provided DATA, when non-nil.
1726 (org-test-with-parsed-data
1727 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1728 (org-element-map tree
'footnote-reference
1730 (org-export-get-footnote-number
1731 ref info
(org-element-map tree
'headline
#'identity info t
)))
1736 (org-test-with-parsed-data
1737 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
1738 (org-element-map tree
'footnote-reference
1739 (lambda (ref) (org-export-get-footnote-number ref info
))
1741 ;; With a non-nil BODY-FIRST optional argument, first check body,
1742 ;; then footnote definitions.
1745 '(("fn:1" .
1) ("fn:2" .
2) ("fn:3" .
3) ("fn:3" .
3))
1746 (org-test-with-parsed-data
1747 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1748 (org-element-map tree
'footnote-reference
1750 (cons (org-element-property :label ref
)
1751 (org-export-get-footnote-number ref info nil t
)))
1755 '(("fn:1" .
1) ("fn:2" .
3) ("fn:3" .
2) ("fn:3" .
2))
1756 (org-test-with-parsed-data
1757 "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
1758 (org-element-map tree
'footnote-reference
1760 (cons (org-element-property :label ref
)
1761 (org-export-get-footnote-number ref info nil
)))
1764 (ert-deftest test-org-export
/collect-footnote-definitions
()
1765 "Test `org-export-collect-footnote-definitions' specifications."
1768 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1770 \[fn:2] B [fn:3] [fn::D].
1773 (length (org-export-collect-footnote-definitions info
)))))
1774 ;; Limit number to provided DATA, when non-nil.
1778 (org-test-with-parsed-data
1779 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1781 (org-export-collect-footnote-definitions
1782 info
(org-element-map tree
'headline
#'identity info t
))))))
1785 '((1 "fn:1") (2 "fn:2"))
1786 (org-test-with-parsed-data
1787 "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
1788 (mapcar #'butlast
(org-export-collect-footnote-definitions info
)))))
1789 ;; With optional argument BODY-FIRST, first check body, then
1790 ;; footnote definitions.
1792 (equal '("fn:1" "fn:3" "fn:2" nil
)
1793 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1795 \[fn:2] B [fn:3] [fn::D].
1798 (mapcar (lambda (e) (nth 1 e
))
1799 (org-export-collect-footnote-definitions info nil t
)))))
1801 (equal '("fn:1" "fn:3" "fn:2" nil
)
1802 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
1804 \[fn:2] B [fn:3] [fn::D].
1807 (mapcar (lambda (e) (nth 1 e
))
1808 (org-export-collect-footnote-definitions info
))))))
1810 (ert-deftest test-org-export
/footnotes
()
1811 "Miscellaneous tests on footnotes."
1812 (let ((org-footnote-section nil
)
1813 (org-export-with-footnotes t
))
1814 ;; Read every type of footnote.
1817 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
1818 (org-test-with-parsed-data
1819 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
1820 (org-element-map tree
'footnote-reference
1822 (let ((def (org-export-get-footnote-definition ref info
)))
1823 (cons (org-export-get-footnote-number ref info
)
1824 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
1825 (car (org-element-contents
1826 (car (org-element-contents def
))))))))
1828 ;; Test nested footnote in invisible definitions.
1829 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
1830 ;; Hide definitions.
1831 (narrow-to-region (point) (point-at-eol))
1832 (let* ((tree (org-element-parse-buffer))
1833 (info (org-combine-plists
1834 `(:parse-tree
,tree
)
1835 (org-export-collect-tree-properties
1836 tree
(org-export-get-environment)))))
1837 ;; Both footnotes should be seen.
1839 (= (length (org-export-collect-footnote-definitions info
)) 2))))
1840 ;; Test export of footnotes defined outside parsing scope.
1843 "ParagraphOut of scope\n"
1844 (org-test-with-temp-text "[fn:1] Out of scope
1847 (let ((backend (org-test-default-backend)))
1848 (setf (org-export-backend-transcoders backend
)
1849 (cons (cons 'footnote-reference
1850 (lambda (fn contents info
)
1851 (org-element-interpret-data
1852 (org-export-get-footnote-definition fn info
))))
1853 (org-export-backend-transcoders backend
)))
1855 (org-export-as backend
'subtree
)))))
1856 ;; Footnotes without a definition should throw an error.
1858 (org-test-with-parsed-data "Text[fn:1]"
1859 (org-export-get-footnote-definition
1860 (org-element-map tree
'footnote-reference
'identity info t
) info
)))
1861 ;; Footnote section should be ignored in TOC and in headlines
1864 (= 1 (let ((org-footnote-section "Footnotes"))
1865 (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
1866 (org-export-collect-headlines info
))))))
1869 (let ((org-footnote-section "Footnotes"))
1870 (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
1871 (org-element-map tree
'headline
1873 (when (equal (org-element-property :raw-value hl
) "H2")
1874 (org-export-get-headline-number hl info
)))
1879 ;;; Headlines and Inlinetasks
1881 (ert-deftest test-org-export
/get-relative-level
()
1882 "Test `org-export-get-relative-level' specifications."
1886 (let ((org-odd-levels-only nil
))
1887 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1888 (org-element-map tree
'headline
1889 (lambda (h) (org-export-get-relative-level h info
))
1894 (let ((org-odd-levels-only nil
))
1895 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
1896 (org-element-map tree
'headline
1897 (lambda (h) (org-export-get-relative-level h info
))
1900 (ert-deftest test-org-export
/low-level-p
()
1901 "Test `org-export-low-level-p' specifications."
1905 (let ((org-odd-levels-only nil
))
1906 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1907 (org-element-map tree
'headline
1908 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
1909 (plist-put info
:headline-levels
1)))))))
1911 (ert-deftest test-org-export
/get-headline-number
()
1912 "Test `org-export-get-headline-number' specifications."
1917 (let ((org-odd-levels-only nil
))
1918 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1919 (org-element-map tree
'headline
1920 (lambda (h) (org-export-get-headline-number h info
))
1922 ;; Missing levels are replaced with 0.
1926 (let ((org-odd-levels-only nil
))
1927 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
1928 (org-element-map tree
'headline
1929 (lambda (h) (org-export-get-headline-number h info
))
1932 (ert-deftest test-org-export
/numbered-headline-p
()
1933 "Test `org-export-numbered-headline-p' specifications."
1934 ;; If `:section-numbers' is nil, never number headlines.
1936 (org-test-with-parsed-data "* Headline"
1937 (org-element-map tree
'headline
1938 (lambda (h) (org-export-numbered-headline-p h info
))
1939 (plist-put info
:section-numbers nil
))))
1940 ;; If `:section-numbers' is a number, only number headlines with
1941 ;; a level greater that it.
1945 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
1946 (org-element-map tree
'headline
1947 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
1948 (plist-put info
:section-numbers
1)))))
1949 ;; Otherwise, headlines are always numbered.
1951 (org-test-with-parsed-data "* Headline"
1952 (org-element-map tree
'headline
1953 (lambda (h) (org-export-numbered-headline-p h info
))
1954 (plist-put info
:section-numbers t
))))
1955 ;; With #+OPTIONS: num:nil all headlines are unnumbered.
1957 (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
1958 (org-export-numbered-headline-p
1959 (org-element-map tree
'headline
'identity info t
)
1961 ;; Headlines with a non-nil UNNUMBERED property are not numbered.
1963 (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
1964 (org-export-numbered-headline-p
1965 (org-element-map tree
'headline
#'identity info t
)
1967 ;; UNNUMBERED ignores inheritance. Any non-nil value among
1968 ;; ancestors disables numbering.
1970 (org-test-with-parsed-data
1981 (lambda (h) (not (org-export-numbered-headline-p h info
)))
1982 (org-element-map tree
'headline
#'identity info
)))))
1984 (ert-deftest test-org-export
/number-to-roman
()
1985 "Test `org-export-number-to-roman' specifications."
1986 ;; If number is negative, return it as a string.
1987 (should (equal (org-export-number-to-roman -
1) "-1"))
1988 ;; Otherwise, return it as a roman number.
1989 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
1991 (ert-deftest test-org-export
/get-optional-title
()
1992 "Test `org-export-get-alt-title' specifications."
1993 ;; If ALT_TITLE property is defined, use it.
1996 (org-test-with-parsed-data
1997 "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
1998 (org-export-get-alt-title
1999 (org-element-map tree
'headline
'identity info t
)
2001 ;; Otherwise, fall-back to regular title.
2003 (equal '("Headline")
2004 (org-test-with-parsed-data "* Headline"
2005 (org-export-get-alt-title
2006 (org-element-map tree
'headline
'identity info t
)
2009 (ert-deftest test-org-export
/get-tags
()
2010 "Test `org-export-get-tags' specifications."
2011 (let ((org-export-exclude-tags '("noexport"))
2012 (org-export-select-tags '("export")))
2013 ;; Standard test: tags which are not a select tag, an exclude tag,
2014 ;; or specified as optional argument shouldn't be ignored.
2016 (org-test-with-parsed-data "* Headline :tag:"
2017 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2019 ;; Exclude tags are removed.
2021 (org-test-with-parsed-data "* Headline :noexport:"
2022 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2024 ;; Select tags are removed.
2026 (org-test-with-parsed-data "* Headline :export:"
2027 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2032 (org-test-with-parsed-data "* Headline :tag:export:"
2033 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2035 ;; Tags provided in the optional argument are also ignored.
2037 (org-test-with-parsed-data "* Headline :ignore:"
2038 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
2040 ;; Allow tag inheritance.
2044 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
2045 (org-element-map tree
'headline
2046 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
2047 ;; Tag inheritance checks FILETAGS keywords.
2051 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
2052 (org-element-map tree
'headline
2053 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
2055 (ert-deftest test-org-export
/get-node-property
()
2056 "Test`org-export-get-node-property' specifications."
2060 (org-test-with-parsed-data "* Headline
2064 (org-export-get-node-property
2065 :PROP
(org-element-map tree
'headline
'identity nil t
)))))
2066 ;; Test inheritance.
2069 (org-test-with-parsed-data "* Parent
2075 (org-export-get-node-property
2076 :PROP
(org-element-map tree
'paragraph
'identity nil t
) t
))))
2077 ;; Cannot return a value before the first headline.
2079 (org-test-with-parsed-data "Paragraph
2084 (org-export-get-node-property
2085 :PROP
(org-element-map tree
'paragraph
'identity nil t
)))))
2087 (ert-deftest test-org-export
/get-category
()
2088 "Test `org-export-get-category' specifications."
2092 (org-test-with-parsed-data "* Headline
2096 (org-export-get-category
2097 (org-element-map tree
'headline
'identity nil t
) info
))))
2098 ;; Test inheritance from a parent headline.
2100 (equal '("value" "value")
2101 (org-test-with-parsed-data "* Headline1
2106 (org-element-map tree
'headline
2107 (lambda (hl) (org-export-get-category hl info
)) info
))))
2108 ;; Test inheritance from #+CATEGORY keyword
2111 (org-test-with-parsed-data "#+CATEGORY: value
2113 (org-export-get-category
2114 (org-element-map tree
'headline
'identity nil t
) info
))))
2115 ;; Test inheritance from file name.
2118 (org-test-with-parsed-data "* Headline"
2119 (let ((info (plist-put info
:input-file
"~/test.org")))
2120 (org-export-get-category
2121 (org-element-map tree
'headline
'identity nil t
) info
)))))
2125 (org-test-with-parsed-data "* Headline"
2126 (org-export-get-category
2127 (org-element-map tree
'headline
'identity nil t
) info
)))))
2129 (ert-deftest test-org-export
/first-sibling-p
()
2130 "Test `org-export-first-sibling-p' specifications."
2135 (org-test-with-parsed-data "* H\n** H 2\n** H 3"
2136 (org-element-map tree
'headline
2137 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2141 (org-test-with-parsed-data "- item\n\n para"
2142 (org-element-map tree
'paragraph
2143 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2145 ;; Ignore sections for headlines.
2148 (org-test-with-parsed-data "* H\nSection\n** H 2"
2149 (org-element-map tree
'headline
2150 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2152 ;; Ignore headlines not exported.
2156 (let ((org-export-exclude-tags '("ignore")))
2157 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
2158 (org-element-map tree
'headline
2159 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
2162 (ert-deftest test-org-export
/last-sibling-p
()
2163 "Test `org-export-last-sibling-p' specifications."
2168 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
2169 (org-element-map tree
'headline
2170 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2174 (org-test-with-parsed-data "- item\n\n para"
2175 (org-element-map tree
'paragraph
2176 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2178 ;; Ignore headlines not exported.
2182 (let ((org-export-exclude-tags '("ignore")))
2183 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
2184 (org-element-map tree
'headline
2185 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
2188 (ert-deftest test-org-export
/handle-inlinetasks
()
2189 "Test inlinetask export."
2190 ;; Inlinetask with an exclude tag.
2191 (when (featurep 'org-inlinetask
)
2195 (let ((org-inlinetask-min-level 3)
2196 org-export-filter-body-functions
2197 org-export-filter-final-output-functions
)
2198 (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
2199 (org-export-as (org-test-default-backend)
2200 nil nil nil
'(:exclude-tags
("noexp")))))))
2201 ;; Inlinetask with an include tag.
2204 "* H2\n*** Inline :exp:\n"
2205 (let ((org-inlinetask-min-level 3)
2206 (org-tags-column 0))
2207 (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
2208 (org-export-as (org-test-default-backend)
2209 nil nil nil
'(:select-tags
("exp")))))))
2210 ;; Ignore inlinetask with a TODO keyword and tasks excluded.
2213 (let ((org-todo-keywords '((sequence "TODO" "DONE")))
2214 (org-inlinetask-min-level 3)
2215 org-export-filter-body-functions
2216 org-export-filter-final-output-functions
)
2217 (org-test-with-temp-text "*** TODO Inline"
2218 (org-export-as (org-test-default-backend)
2219 nil nil nil
'(:with-tasks nil
))))))))
2225 (ert-deftest test-org-export
/get-date
()
2226 "Test `org-export-get-date' specifications."
2227 ;; Return a properly formatted string when
2228 ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
2229 ;; consists in a single timestamp.
2232 (let ((org-export-date-timestamp-format "%d %m %Y"))
2233 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2234 (org-export-get-date info
)))))
2235 ;; Return a secondary string otherwise.
2238 (let ((org-export-date-timestamp-format nil
))
2239 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2240 (org-export-get-date info
)))))
2243 (org-test-with-parsed-data "#+DATE: Date"
2244 (org-export-get-date info
))))
2245 ;; Optional argument has precedence over
2246 ;; `org-export-date-timestamp-format'.
2249 (let ((org-export-date-timestamp-format "%d %m %Y"))
2250 (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
2251 (org-export-get-date info
"%d %m"))))))
2257 (ert-deftest test-org-export
/custom-protocol-maybe
()
2258 "Test `org-export-custom-protocol-maybe' specifications."
2262 (let ((org-link-types (copy-sequence org-link-types
)))
2263 (org-add-link-type "foo" nil
(lambda (p d f
) "success"))
2264 (org-export-string-as
2266 (org-export-create-backend
2269 '((section .
(lambda (s c i
) c
))
2270 (paragraph .
(lambda (p c i
) c
))
2271 (link .
(lambda (l c i
)
2272 (or (org-export-custom-protocol-maybe l c
'test
)
2277 (let ((org-link-types (copy-sequence org-link-types
)))
2279 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2280 (org-export-string-as
2282 (org-export-create-backend
2285 '((section .
(lambda (s c i
) c
))
2286 (paragraph .
(lambda (p c i
) c
))
2287 (link .
(lambda (l c i
)
2288 (or (org-export-custom-protocol-maybe l c
'no-test
)
2290 ;; Ignore anonymous back-ends.
2294 (let ((org-link-types (copy-sequence org-link-types
)))
2296 "foo" nil
(lambda (p d f
) (and (eq f
'test
) "success")))
2297 (org-export-string-as
2299 (org-export-create-backend
2301 '((section .
(lambda (s c i
) c
))
2302 (paragraph .
(lambda (p c i
) c
))
2303 (link .
(lambda (l c i
)
2304 (or (org-export-custom-protocol-maybe l c nil
)
2307 (ert-deftest test-org-export
/get-coderef-format
()
2308 "Test `org-export-get-coderef-format' specifications."
2309 ;; A link without description returns "%s"
2310 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
2312 ;; Return "%s" when path is matched within description.
2313 (should (equal (org-export-get-coderef-format "path" "desc (path)")
2315 ;; Otherwise return description.
2316 (should (equal (org-export-get-coderef-format "path" "desc")
2319 (ert-deftest test-org-export
/inline-image-p
()
2320 "Test `org-export-inline-image-p' specifications."
2322 (org-export-inline-image-p
2323 (org-test-with-temp-text "[[#id]]"
2324 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))
2325 '(("custom-id" .
"id")))))
2327 (ert-deftest test-org-export
/fuzzy-link
()
2328 "Test fuzzy links specifications."
2329 ;; Link to an headline should return headline's number.
2330 (org-test-with-parsed-data
2331 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
2333 ;; Note: Headline's number is in fact a list of numbers.
2335 (org-element-map tree
'link
2337 (org-export-get-ordinal
2338 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2339 ;; Link to a target in an item should return item's number.
2340 (org-test-with-parsed-data
2341 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
2343 ;; Note: Item's number is in fact a list of numbers.
2345 (org-element-map tree
'link
2347 (org-export-get-ordinal
2348 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2349 ;; Link to a target in a footnote should return footnote's number.
2350 (org-test-with-parsed-data "
2351 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
2354 (org-element-map tree
'link
2356 (org-export-get-ordinal
2357 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
2358 ;; Link to a named element should return sequence number of that
2360 (org-test-with-parsed-data
2361 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
2364 (org-element-map tree
'link
2366 (org-export-get-ordinal
2367 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2368 ;; Link to a target not within an item, a table, a footnote
2369 ;; reference or definition should return section number.
2370 (org-test-with-parsed-data
2371 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
2374 (org-element-map tree
'link
2376 (org-export-get-ordinal
2377 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
2378 ;; Space are not significant when matching a fuzzy link.
2380 (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
2381 (org-element-map tree
'link
2382 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2384 ;; Statistics cookies are ignored for headline match.
2386 (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
2387 (org-element-map tree
'link
2388 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2391 (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
2392 (org-element-map tree
'link
2393 (lambda (link) (org-export-resolve-fuzzy-link link info
))
2395 ;; Headline match is position dependent.
2399 (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
2400 (org-element-map tree
'link
2401 (lambda (link) (org-export-resolve-fuzzy-link link info
)) info
)))))
2403 (ert-deftest test-org-export
/resolve-coderef
()
2404 "Test `org-export-resolve-coderef' specifications."
2405 (let ((org-coderef-label-format "(ref:%s)"))
2406 ;; A link to a "-n -k -r" block returns line number.
2409 (org-test-with-parsed-data
2410 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2411 (org-export-resolve-coderef "coderef" info
))))
2414 (org-test-with-parsed-data
2415 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2416 (org-export-resolve-coderef "coderef" info
))))
2417 ;; A link to a "-n -r" block returns line number.
2420 (org-test-with-parsed-data
2421 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2422 (org-export-resolve-coderef "coderef" info
))))
2425 (org-test-with-parsed-data
2426 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2427 (org-export-resolve-coderef "coderef" info
))))
2428 ;; A link to a "-n" block returns coderef.
2431 (org-test-with-parsed-data
2432 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2433 (org-export-resolve-coderef "coderef" info
))))
2436 (org-test-with-parsed-data
2437 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2438 (org-export-resolve-coderef "coderef" info
))))
2439 ;; A link to a "-r" block returns line number.
2442 (org-test-with-parsed-data
2443 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2444 (org-export-resolve-coderef "coderef" info
))))
2447 (org-test-with-parsed-data
2448 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2449 (org-export-resolve-coderef "coderef" info
))))
2450 ;; A link to a block without a switch returns coderef.
2453 (org-test-with-parsed-data
2454 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2455 (org-export-resolve-coderef "coderef" info
))))
2456 (org-test-with-parsed-data
2457 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2458 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2459 ;; Correctly handle continued line numbers. A "+n" switch should
2460 ;; resume numbering from previous block with numbered lines,
2461 ;; ignoring blocks not numbering lines in the process. A "-n"
2462 ;; switch resets count.
2465 (org-test-with-parsed-data "
2470 #+BEGIN_SRC emacs-lisp
2474 #+BEGIN_SRC emacs-lisp +n -r
2475 \(+ 1 1) (ref:addition)
2478 #+BEGIN_EXAMPLE -n -r
2479 Another text. (ref:text)
2481 (list (org-export-resolve-coderef "addition" info
)
2482 (org-export-resolve-coderef "text" info
)))))
2483 ;; Recognize coderef with user-specified syntax.
2486 (org-test-with-parsed-data
2487 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2488 (org-export-resolve-coderef "text" info
))))
2489 ;; Unresolved coderefs throw an error.
2491 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2492 (org-export-resolve-coderef "unknown" info
)))))
2494 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2495 "Test `org-export-resolve-fuzzy-link' specifications."
2496 ;; Match target objects.
2498 (org-test-with-parsed-data "<<target>> [[target]]"
2499 (org-export-resolve-fuzzy-link
2500 (org-element-map tree
'link
'identity info t
) info
)))
2501 ;; Match named elements.
2503 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2504 (org-export-resolve-fuzzy-link
2505 (org-element-map tree
'link
'identity info t
) info
)))
2506 ;; Match exact headline's name.
2508 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2509 (org-export-resolve-fuzzy-link
2510 (org-element-map tree
'link
'identity info t
) info
)))
2511 ;; Targets objects have priority over named elements and headline
2515 (org-test-with-parsed-data
2516 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2518 (org-export-resolve-fuzzy-link
2519 (org-element-map tree
'link
'identity info t
) info
)))))
2520 ;; Named elements have priority over headline titles.
2523 (org-test-with-parsed-data
2524 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2526 (org-export-resolve-fuzzy-link
2527 (org-element-map tree
'link
'identity info t
) info
)))))
2528 ;; If link's path starts with a "*", only match headline titles,
2532 (org-test-with-parsed-data
2533 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2535 (org-export-resolve-fuzzy-link
2536 (org-element-map tree
'link
'identity info t
) info
)))))
2537 ;; Error if no match.
2539 (org-test-with-parsed-data "[[target]]"
2540 (org-export-resolve-fuzzy-link
2541 (org-element-map tree
'link
'identity info t
) info
)))
2542 ;; Match fuzzy link even when before first headline.
2545 (org-test-with-parsed-data "[[hl]]\n* hl"
2547 (org-export-resolve-fuzzy-link
2548 (org-element-map tree
'link
'identity info t
) info
))))))
2550 (ert-deftest test-org-export
/resolve-id-link
()
2551 "Test `org-export-resolve-id-link' specifications."
2552 ;; Regular test for custom-id link.
2554 (equal '("Headline1")
2555 (org-test-with-parsed-data "* Headline1
2561 (org-element-property
2563 (org-export-resolve-id-link
2564 (org-element-map tree
'link
'identity info t
) info
)))))
2565 ;; Throw an error on failing searches.
2567 (org-test-with-parsed-data "* Headline1
2573 (org-export-resolve-id-link
2574 (org-element-map tree
'link
'identity info t
) info
)))
2575 ;; Test for internal id target.
2577 (equal '("Headline1")
2578 (org-test-with-parsed-data "* Headline1
2584 (org-element-property
2586 (org-export-resolve-id-link
2587 (org-element-map tree
'link
'identity info t
) info
)))))
2588 ;; Test for external id target.
2592 (org-test-with-parsed-data "[[id:aaaa]]"
2593 (org-export-resolve-id-link
2594 (org-element-map tree
'link
'identity info t
)
2595 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2597 (ert-deftest test-org-export
/resolve-radio-link
()
2598 "Test `org-export-resolve-radio-link' specifications."
2601 (org-test-with-temp-text "<<<radio>>> radio"
2602 (org-update-radio-target-regexp)
2603 (let* ((tree (org-element-parse-buffer))
2604 (info `(:parse-tree
,tree
)))
2605 (org-export-resolve-radio-link
2606 (org-element-map tree
'link
'identity info t
)
2608 ;; Radio targets are case-insensitive.
2610 (org-test-with-temp-text "<<<RADIO>>> radio"
2611 (org-update-radio-target-regexp)
2612 (let* ((tree (org-element-parse-buffer))
2613 (info `(:parse-tree
,tree
)))
2614 (org-export-resolve-radio-link
2615 (org-element-map tree
'link
'identity info t
)
2617 ;; Radio target with objects.
2619 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2620 (org-update-radio-target-regexp)
2621 (let* ((tree (org-element-parse-buffer))
2622 (info `(:parse-tree
,tree
)))
2623 (org-export-resolve-radio-link
2624 (org-element-map tree
'link
'identity info t
)
2626 ;; Radio target with objects at its beginning.
2628 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2629 (org-update-radio-target-regexp)
2630 (let* ((tree (org-element-parse-buffer))
2631 (info `(:parse-tree
,tree
)))
2632 (org-export-resolve-radio-link
2633 (org-element-map tree
'link
'identity info t
)
2635 ;; Radio link next to an apostrophe.
2637 (org-test-with-temp-text "<<<radio>>> radio's"
2638 (org-update-radio-target-regexp)
2639 (let* ((tree (org-element-parse-buffer))
2640 (info `(:parse-tree
,tree
)))
2641 (org-export-resolve-radio-link
2642 (org-element-map tree
'link
'identity info t
)
2644 ;; Multiple radio targets.
2646 (equal '("radio1" "radio2")
2647 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2648 (org-update-radio-target-regexp)
2649 (let* ((tree (org-element-parse-buffer))
2650 (info `(:parse-tree
,tree
)))
2651 (org-element-map tree
'link
2653 (org-element-property
2654 :value
(org-export-resolve-radio-link link info
)))
2656 ;; Radio target is whitespace insensitive.
2658 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2659 (org-update-radio-target-regexp)
2660 (let* ((tree (org-element-parse-buffer))
2661 (info `(:parse-tree
,tree
)))
2662 (org-element-map tree
'link
2663 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2665 (ert-deftest test-org-export
/file-uri
()
2666 "Test `org-export-file-uri' specifications."
2667 ;; Preserve relative filenames.
2668 (should (equal "relative.org" (org-export-file-uri "relative.org")))
2669 ;; Local files start with "file:///"
2670 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
2671 ;; Remote files start with "file://"
2672 (should (equal "file://myself@some.where:papers/last.pdf"
2673 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
2674 ;; Expand filename starting with "~".
2675 (should (equal (org-export-file-uri "~/file.org")
2676 (concat "file://" (expand-file-name "~/file.org")))))
2680 ;;; Src-block and example-block
2682 (ert-deftest test-org-export
/unravel-code
()
2683 "Test `org-export-unravel-code' function."
2684 ;; Code without reference.
2686 (equal '("(+ 1 1)\n")
2687 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2688 (org-export-unravel-code (org-element-at-point)))))
2689 ;; Code with reference.
2691 (equal '("(+ 1 1)\n" (1 .
"test"))
2692 (org-test-with-temp-text
2693 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2694 (let ((org-coderef-label-format "(ref:%s)"))
2695 (org-export-unravel-code (org-element-at-point))))))
2696 ;; Code with user-defined reference.
2699 '("(+ 1 1)\n" (1 .
"test"))
2700 (org-test-with-temp-text
2701 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2702 (let ((org-coderef-label-format "(ref:%s)"))
2703 (org-export-unravel-code (org-element-at-point))))))
2704 ;; Code references keys are relative to the current block.
2706 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2707 (org-test-with-temp-text "
2716 (let ((org-coderef-label-format "(ref:%s)"))
2717 (org-export-unravel-code (org-element-at-point)))))))
2719 (ert-deftest test-org-export
/format-code-default
()
2720 "Test `org-export-format-code-default' specifications."
2721 ;; Return the empty string when code is empty.
2724 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2725 (org-export-format-code-default
2726 (org-element-map tree
'src-block
'identity info t
) info
))))
2727 ;; Number lines, two whitespace characters before the actual loc.
2730 (org-test-with-parsed-data
2731 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2732 (org-export-format-code-default
2733 (org-element-map tree
'src-block
'identity info t
) info
))))
2734 ;; Put references 6 whitespace characters after the widest line,
2735 ;; wrapped within parenthesis.
2737 (equal "123 (a)\n1 (b)\n"
2738 (let ((org-coderef-label-format "(ref:%s)"))
2739 (org-test-with-parsed-data
2740 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2741 (org-export-format-code-default
2742 (org-element-map tree
'src-block
'identity info t
) info
))))))
2748 (ert-deftest test-org-export
/activate-smart-quotes
()
2749 "Test `org-export-activate-smart-quotes' specifications."
2750 ;; Double quotes: standard test.
2753 '("some “quoted” text")
2754 (let ((org-export-default-language "en"))
2755 (org-test-with-parsed-data "some \"quoted\" text"
2756 (org-element-map tree
'plain-text
2757 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2759 ;; Opening quotes: at the beginning of a paragraph.
2763 (let ((org-export-default-language "en"))
2764 (org-test-with-parsed-data "\"begin"
2765 (org-element-map tree
'plain-text
2766 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2768 ;; Opening quotes: after an object.
2771 '("“quoted” text")
2772 (let ((org-export-default-language "en"))
2773 (org-test-with-parsed-data "=verb= \"quoted\" text"
2774 (org-element-map tree
'plain-text
2775 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2777 ;; Closing quotes: at the end of a paragraph.
2780 '("Quoted “text”")
2781 (let ((org-export-default-language "en"))
2782 (org-test-with-parsed-data "Quoted \"text\""
2783 (org-element-map tree
'plain-text
2784 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2786 ;; Inner quotes: standard test.
2788 (equal '("« outer « inner » outer »")
2789 (let ((org-export-default-language "fr"))
2790 (org-test-with-parsed-data "\"outer 'inner' outer\""
2791 (org-element-map tree
'plain-text
2792 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2794 ;; Apostrophe: standard test.
2796 (equal '("It « shouldn’t » fail")
2797 (let ((org-export-default-language "fr"))
2798 (org-test-with-parsed-data "It \"shouldn't\" fail"
2799 (org-element-map tree
'plain-text
2800 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2803 (equal '("It shouldn’t fail")
2804 (let ((org-export-default-language "fr"))
2805 (org-test-with-parsed-data "It shouldn't fail"
2806 (org-element-map tree
'plain-text
2807 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2809 ;; Apostrophe: before an object.
2812 '("« a’" " »")
2813 (let ((org-export-default-language "fr"))
2814 (org-test-with-parsed-data "\"a'=b=\""
2815 (org-element-map tree
'plain-text
2816 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2818 ;; Apostrophe: after an object.
2820 (equal '("« " "’s »")
2821 (let ((org-export-default-language "fr"))
2822 (org-test-with-parsed-data "\"=code='s\""
2823 (org-element-map tree
'plain-text
2824 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2826 ;; Special case: isolated quotes.
2828 (equal '("“" "”")
2829 (let ((org-export-default-language "en"))
2830 (org-test-with-parsed-data "\"$x$\""
2831 (org-element-map tree
'plain-text
2832 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2834 ;; Smart quotes in secondary strings.
2836 (equal '("“" "”")
2837 (let ((org-export-default-language "en"))
2838 (org-test-with-parsed-data "* \"$x$\""
2839 (org-element-map tree
'plain-text
2840 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2842 ;; Smart quotes in document keywords.
2844 (equal '("“" "”")
2845 (let ((org-export-default-language "en"))
2846 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2847 (org-element-map (plist-get info
:title
) 'plain-text
2848 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2850 ;; Smart quotes in parsed affiliated keywords.
2852 (equal '("“" "”" "Paragraph")
2853 (let ((org-export-default-language "en"))
2854 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2855 (org-element-map tree
'plain-text
2856 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2857 info nil nil t
))))))
2863 (ert-deftest test-org-export
/special-column
()
2864 "Test if the table's special column is properly recognized."
2865 ;; 1. First column is special if it contains only a special marking
2866 ;; characters or empty cells.
2867 (org-test-with-temp-text "
2871 (org-export-table-has-special-column-p
2873 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2874 ;; 2. If the column contains anything else, it isn't special.
2875 (org-test-with-temp-text "
2879 (org-export-table-has-special-column-p
2881 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2882 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2884 (org-test-with-temp-text "
2893 (org-export-table-has-special-column-p
2895 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2896 ;; 4. A first column with only empty cells isn't considered as
2898 (org-test-with-temp-text "
2902 (org-export-table-has-special-column-p
2904 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2906 (ert-deftest test-org-export
/table-row-is-special-p
()
2907 "Test `org-export-table-row-is-special-p' specifications."
2908 ;; 1. A row is special if it has a special marking character in the
2910 (org-test-with-parsed-data "| ! | 1 |"
2912 (org-export-table-row-is-special-p
2913 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2914 ;; 2. A row is special when its first field is "/"
2915 (org-test-with-parsed-data "
2919 (org-export-table-row-is-special-p
2920 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2921 ;; 3. A row only containing alignment cookies is also considered as
2923 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2925 (org-export-table-row-is-special-p
2926 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2927 ;; 4. Everything else isn't considered as special.
2928 (org-test-with-parsed-data "| \alpha | | c |"
2930 (org-export-table-row-is-special-p
2931 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2932 ;; 5. Table's rules are never considered as special rows.
2933 (org-test-with-parsed-data "|---+---|"
2935 (org-export-table-row-is-special-p
2936 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2938 (ert-deftest test-org-export
/has-header-p
()
2939 "Test `org-export-table-has-header-p' specifications."
2940 ;; 1. With an header.
2941 (org-test-with-parsed-data "
2946 (org-export-table-has-header-p
2947 (org-element-map tree
'table
'identity info
'first-match
)
2949 ;; 2. Without an header.
2950 (org-test-with-parsed-data "
2954 (org-export-table-has-header-p
2955 (org-element-map tree
'table
'identity info
'first-match
)
2957 ;; 3. Don't get fooled with starting and ending rules.
2958 (org-test-with-parsed-data "
2964 (org-export-table-has-header-p
2965 (org-element-map tree
'table
'identity info
'first-match
)
2968 (ert-deftest test-org-export
/table-row-group
()
2969 "Test `org-export-table-row-group' specifications."
2970 ;; 1. A rule creates a new group.
2973 (org-test-with-parsed-data "
2977 (org-element-map tree
'table-row
2979 (if (eq (org-element-property :type row
) 'rule
) 'rule
2980 (org-export-table-row-group row info
)))))))
2981 ;; 2. Special rows are ignored in count.
2985 (org-test-with-parsed-data "
2989 (org-element-map tree
'table-row
2991 (if (eq (org-element-property :type row
) 'rule
) 'rule
2992 (org-export-table-row-group row info
)))
2994 ;; 3. Double rules also are ignored in count.
2996 (equal '(1 rule rule
2)
2997 (org-test-with-parsed-data "
3002 (org-element-map tree
'table-row
3004 (if (eq (org-element-property :type row
) 'rule
) 'rule
3005 (org-export-table-row-group row info
))))))))
3007 (ert-deftest test-org-export
/table-row-number
()
3008 "Test `org-export-table-row-number' specifications."
3009 ;; Standard test. Number is 0-indexed.
3012 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3013 (org-element-map tree
'table-row
3014 (lambda (row) (org-export-table-row-number row info
)) info
))))
3015 ;; Number ignores separators.
3018 (org-test-with-parsed-data "
3022 (org-element-map tree
'table-row
3023 (lambda (row) (org-export-table-row-number row info
)) info
))))
3024 ;; Number ignores special rows.
3027 (org-test-with-parsed-data "
3033 (org-element-map tree
'table-row
3034 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3036 (ert-deftest test-org-export
/table-cell-width
()
3037 "Test `org-export-table-cell-width' specifications."
3038 ;; 1. Width is primarily determined by width cookies. If no cookie
3039 ;; is found, cell's width is nil.
3040 (org-test-with-parsed-data "
3041 | / | <l> | <6> | <l7> |
3046 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3047 (org-element-map tree
'table-cell
'identity info
)))))
3048 ;; 2. The last width cookie has precedence.
3049 (org-test-with-parsed-data "
3056 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3057 (org-element-map tree
'table-cell
'identity info
)))))
3058 ;; 3. Valid width cookies must have a specific row.
3059 (org-test-with-parsed-data "| <6> | cell |"
3063 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3064 (org-element-map tree
'table-cell
'identity
))))))
3066 (ert-deftest test-org-export
/table-cell-alignment
()
3067 "Test `org-export-table-cell-alignment' specifications."
3068 ;; 1. Alignment is primarily determined by alignment cookies.
3070 (equal '(left center right
)
3071 (let ((org-table-number-fraction 0.5)
3072 (org-table-number-regexp "^[0-9]+$"))
3073 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3074 (mapcar (lambda (cell)
3075 (org-export-table-cell-alignment cell info
))
3076 (org-element-map tree
'table-cell
'identity
))))))
3077 ;; 2. The last alignment cookie has precedence.
3079 (equal '(right right right
)
3080 (org-test-with-parsed-data "
3084 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3085 (org-element-map tree
'table-cell
'identity
)))))
3086 ;; 3. If there's no cookie, cell's contents determine alignment.
3087 ;; A column mostly made of cells containing numbers will align
3088 ;; its cells to the right.
3090 (equal '(right right right
)
3091 (let ((org-table-number-fraction 0.5)
3092 (org-table-number-regexp "^[0-9]+$"))
3093 (org-test-with-parsed-data "
3097 (mapcar (lambda (cell)
3098 (org-export-table-cell-alignment cell info
))
3099 (org-element-map tree
'table-cell
'identity
))))))
3100 ;; 4. Otherwise, they will be aligned to the left.
3102 (equal '(left left left
)
3103 (org-test-with-parsed-data "
3107 (mapcar (lambda (cell)
3108 (org-export-table-cell-alignment cell info
))
3109 (org-element-map tree
'table-cell
'identity info
))))))
3111 (ert-deftest test-org-export
/table-cell-borders
()
3112 "Test `org-export-table-cell-borders' specifications."
3113 ;; 1. Recognize various column groups indicators.
3114 (org-test-with-parsed-data "| / | < | > | <> |"
3117 '((right bottom top
) (left bottom top
) (right bottom top
)
3118 (right left bottom top
))
3119 (mapcar (lambda (cell)
3120 (org-export-table-cell-borders cell info
))
3121 (org-element-map tree
'table-cell
'identity
)))))
3122 ;; 2. Accept shortcuts to define column groups.
3123 (org-test-with-parsed-data "| / | < | < |"
3126 '((right bottom top
) (right left bottom top
) (left bottom top
))
3127 (mapcar (lambda (cell)
3128 (org-export-table-cell-borders cell info
))
3129 (org-element-map tree
'table-cell
'identity
)))))
3130 ;; 3. A valid column groups row must start with a "/".
3131 (org-test-with-parsed-data "
3135 (equal '((top) (top) (bottom) (bottom))
3136 (mapcar (lambda (cell)
3137 (org-export-table-cell-borders cell info
))
3138 (org-element-map tree
'table-cell
'identity
)))))
3139 ;; 4. Take table rules into consideration.
3140 (org-test-with-parsed-data "
3145 (equal '((below top
) (bottom above
))
3146 (mapcar (lambda (cell)
3147 (org-export-table-cell-borders cell info
))
3148 (org-element-map tree
'table-cell
'identity
)))))
3149 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3150 ;; (resp. `bottom' and `below') borders. Any special row is
3152 (org-test-with-parsed-data "
3158 (equal '((bottom below top above
))
3160 (mapcar (lambda (cell)
3161 (org-export-table-cell-borders cell info
))
3162 (org-element-map tree
'table-cell
'identity
)))))))
3164 (ert-deftest test-org-export
/table-dimensions
()
3165 "Test `org-export-table-dimensions' specifications."
3166 ;; 1. Standard test.
3167 (org-test-with-parsed-data "
3172 (org-export-table-dimensions
3173 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3174 ;; 2. Ignore horizontal rules and special columns.
3175 (org-test-with-parsed-data "
3182 (org-export-table-dimensions
3183 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3185 (ert-deftest test-org-export
/table-cell-address
()
3186 "Test `org-export-table-cell-address' specifications."
3187 ;; 1. Standard test: index is 0-based.
3188 (org-test-with-parsed-data "| a | b |"
3190 (equal '((0 .
0) (0 .
1))
3191 (org-element-map tree
'table-cell
3192 (lambda (cell) (org-export-table-cell-address cell info
))
3194 ;; 2. Special column isn't counted, nor are special rows.
3195 (org-test-with-parsed-data "
3200 (org-export-table-cell-address
3201 (car (last (org-element-map tree
'table-cell
'identity info
)))
3203 ;; 3. Tables rules do not count either.
3204 (org-test-with-parsed-data "
3212 (org-export-table-cell-address
3213 (car (last (org-element-map tree
'table-cell
'identity info
)))
3215 ;; 4. Return nil for special cells.
3216 (org-test-with-parsed-data "| / | a |"
3218 (org-export-table-cell-address
3219 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3222 (ert-deftest test-org-export
/get-table-cell-at
()
3223 "Test `org-export-get-table-cell-at' specifications."
3224 ;; 1. Address ignores special columns, special rows and rules.
3225 (org-test-with-parsed-data "
3232 (org-element-contents
3233 (org-export-get-table-cell-at
3235 (org-element-map tree
'table
'identity info
'first-match
)
3237 ;; 2. Return value for a non-existent address is nil.
3238 (org-test-with-parsed-data "| a |"
3240 (org-export-get-table-cell-at
3242 (org-element-map tree
'table
'identity info
'first-match
)
3244 (org-test-with-parsed-data "| / |"
3246 (org-export-get-table-cell-at
3248 (org-element-map tree
'table
'identity info
'first-match
)
3251 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3252 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3253 ;; 1. A cell at a beginning of a row always starts a column group.
3254 (org-test-with-parsed-data "| a |"
3256 (org-export-table-cell-starts-colgroup-p
3257 (org-element-map tree
'table-cell
'identity info
'first-match
)
3259 ;; 2. Special column should be ignored when determining the
3260 ;; beginning of the row.
3261 (org-test-with-parsed-data "
3265 (org-export-table-cell-starts-colgroup-p
3266 (org-element-map tree
'table-cell
'identity info
'first-match
)
3268 ;; 2. Explicit column groups.
3269 (org-test-with-parsed-data "
3275 (org-element-map tree
'table-cell
3277 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3280 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3281 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3282 ;; 1. A cell at the end of a row always ends a column group.
3283 (org-test-with-parsed-data "| a |"
3285 (org-export-table-cell-ends-colgroup-p
3286 (org-element-map tree
'table-cell
'identity info
'first-match
)
3288 ;; 2. Special column should be ignored when determining the
3289 ;; beginning of the row.
3290 (org-test-with-parsed-data "
3294 (org-export-table-cell-ends-colgroup-p
3295 (org-element-map tree
'table-cell
'identity info
'first-match
)
3297 ;; 3. Explicit column groups.
3298 (org-test-with-parsed-data "
3304 (org-element-map tree
'table-cell
3306 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3309 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3310 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3311 ;; 1. A row at the beginning of a table always starts a row group.
3312 ;; So does a row following a table rule.
3313 (org-test-with-parsed-data "
3320 (org-element-map tree
'table-row
3322 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3324 ;; 2. Special rows should be ignored when determining the beginning
3326 (org-test-with-parsed-data "
3335 (org-element-map tree
'table-row
3337 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3340 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3341 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3342 ;; 1. A row at the end of a table always ends a row group. So does
3343 ;; a row preceding a table rule.
3344 (org-test-with-parsed-data "
3351 (org-element-map tree
'table-row
3353 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3355 ;; 2. Special rows should be ignored when determining the beginning
3357 (org-test-with-parsed-data "
3366 (org-element-map tree
'table-row
3368 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3371 (ert-deftest test-org-export
/table-row-in-header-p
()
3372 "Test `org-export-table-row-in-header-p' specifications."
3373 ;; Standard test. Separators are always nil.
3377 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3378 (org-element-map tree
'table-row
3380 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3381 ;; Nil when there is no header.
3385 (org-test-with-parsed-data "| a |\n| b |"
3386 (org-element-map tree
'table-row
3388 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3390 (ert-deftest test-org-export
/table-row-starts-header-p
()
3391 "Test `org-export-table-row-starts-header-p' specifications."
3392 ;; 1. Only the row starting the first row group starts the table
3394 (org-test-with-parsed-data "
3402 (org-element-map tree
'table-row
3404 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3406 ;; 2. A row cannot start an header if there's no header in the
3408 (org-test-with-parsed-data "
3412 (org-export-table-row-starts-header-p
3413 (org-element-map tree
'table-row
'identity info
'first-match
)
3416 (ert-deftest test-org-export
/table-row-ends-header-p
()
3417 "Test `org-export-table-row-ends-header-p' specifications."
3418 ;; 1. Only the row starting the first row group starts the table
3420 (org-test-with-parsed-data "
3428 (org-element-map tree
'table-row
3430 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3432 ;; 2. A row cannot start an header if there's no header in the
3434 (org-test-with-parsed-data "
3438 (org-export-table-row-ends-header-p
3439 (org-element-map tree
'table-row
'identity info
'first-match
)
3444 ;;; Tables of Contents
3446 (ert-deftest test-org-export
/collect-headlines
()
3447 "Test `org-export-collect-headlines' specifications."
3452 (org-test-with-parsed-data "* H1\n** H2"
3453 (org-export-collect-headlines info
)))))
3454 ;; Do not collect headlines below optional argument.
3458 (org-test-with-parsed-data "* H1\n** H2"
3459 (org-export-collect-headlines info
1)))))
3460 ;; Never collect headlines below maximum headline level.
3464 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3465 (org-export-collect-headlines info
)))))
3469 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3470 (org-export-collect-headlines info
2)))))
3471 ;; Collect headlines locally.
3474 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3475 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3476 (length (org-export-collect-headlines info nil scope
))))))
3477 ;; When collecting locally, optional level is relative.
3480 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3481 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3482 (length (org-export-collect-headlines info
1 scope
)))))))
3488 (ert-deftest test-org-export
/inner-template
()
3489 "Test `inner-template' translator specifications."
3492 (org-test-with-temp-text "* Headline"
3494 (org-export-create-backend
3496 '((inner-template .
(lambda (contents info
) "Success!"))
3497 (headline .
(lambda (h c i
) "Headline"))))))))
3498 ;; Inner template is applied even in a "body-only" export.
3501 (org-test-with-temp-text "* Headline"
3503 (org-export-create-backend
3504 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3505 (headline .
(lambda (h c i
) "Headline"))))
3506 nil nil
'body-only
)))))
3508 (ert-deftest test-org-export
/template
()
3509 "Test `template' translator specifications."
3512 (org-test-with-temp-text "* Headline"
3514 (org-export-create-backend
3515 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3516 (headline .
(lambda (h c i
) "Headline"))))))))
3517 ;; Template is not applied in a "body-only" export.
3520 (org-test-with-temp-text "* Headline"
3522 (org-export-create-backend
3523 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3524 (headline .
(lambda (h c i
) "Headline"))))
3525 nil nil
'body-only
)))))
3531 (ert-deftest test-org-export
/get-next-element
()
3532 "Test `org-export-get-next-element' specifications."
3536 (org-test-with-parsed-data "* Headline\n*a* b"
3537 (org-export-get-next-element
3538 (org-element-map tree
'bold
'identity info t
) info
))))
3539 ;; Return nil when no previous element.
3541 (org-test-with-parsed-data "* Headline\na *b*"
3542 (org-export-get-next-element
3543 (org-element-map tree
'bold
'identity info t
) info
)))
3544 ;; Non-exportable elements are ignored.
3546 (let ((org-export-with-timestamps nil
))
3547 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3548 (org-export-get-next-element
3549 (org-element-map tree
'entity
'identity info t
) info
))))
3550 ;; Find next element in secondary strings.
3553 (org-test-with-parsed-data "* a =verb="
3555 (org-export-get-next-element
3556 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3559 (org-test-with-parsed-data "* /italic/ =verb="
3561 (org-export-get-next-element
3562 (org-element-map tree
'italic
'identity info t
) info
)))))
3563 ;; Find next element in document keywords.
3566 (org-test-with-parsed-data "#+TITLE: a =verb="
3568 (org-export-get-next-element
3570 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3571 ;; Find next element in parsed affiliated keywords.
3574 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3576 (org-export-get-next-element
3577 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3578 ;; With optional argument N, return a list containing all the
3579 ;; following elements.
3582 '(bold code underline
)
3583 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3585 (org-export-get-next-element
3586 (org-element-map tree
'italic
'identity info t
) info t
)))))
3587 ;; When N is a positive integer, return a list containing up to
3588 ;; N following elements.
3592 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3594 (org-export-get-next-element
3595 (org-element-map tree
'italic
'identity info t
) info
2))))))
3597 (ert-deftest test-org-export
/get-previous-element
()
3598 "Test `org-export-get-previous-element' specifications."
3602 (org-test-with-parsed-data "* Headline\na *b*"
3603 (org-export-get-previous-element
3604 (org-element-map tree
'bold
'identity info t
) info
))))
3605 ;; Return nil when no previous element.
3607 (org-test-with-parsed-data "* Headline\n*a* b"
3608 (org-export-get-previous-element
3609 (org-element-map tree
'bold
'identity info t
) info
)))
3610 ;; Non-exportable elements are ignored.
3612 (let ((org-export-with-timestamps nil
))
3613 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3614 (org-export-get-previous-element
3615 (org-element-map tree
'entity
'identity info t
) info
))))
3616 ;; Find previous element in secondary strings.
3619 (org-test-with-parsed-data "* =verb= a"
3621 (org-export-get-previous-element
3622 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3625 (org-test-with-parsed-data "* =verb= /italic/"
3627 (org-export-get-previous-element
3628 (org-element-map tree
'italic
'identity info t
) info
)))))
3629 ;; Find previous element in document keywords.
3632 (org-test-with-parsed-data "#+TITLE: =verb= a"
3634 (org-export-get-previous-element
3636 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3637 ;; Find previous element in parsed affiliated keywords.
3640 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3642 (org-export-get-previous-element
3643 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3644 ;; With optional argument N, return a list containing up to
3645 ;; N previous elements.
3647 (equal '(underline italic bold
)
3648 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3650 (org-export-get-previous-element
3651 (org-element-map tree
'code
'identity info t
) info t
)))))
3652 ;; When N is a positive integer, return a list containing up to
3653 ;; N previous elements.
3655 (equal '(italic bold
)
3656 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3658 (org-export-get-previous-element
3659 (org-element-map tree
'code
'identity info t
) info
2))))))
3663 ;;; test-org-export.el end here