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
))
2396 (ert-deftest test-org-export
/resolve-coderef
()
2397 "Test `org-export-resolve-coderef' specifications."
2398 (let ((org-coderef-label-format "(ref:%s)"))
2399 ;; A link to a "-n -k -r" block returns line number.
2402 (org-test-with-parsed-data
2403 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
2404 (org-export-resolve-coderef "coderef" info
))))
2407 (org-test-with-parsed-data
2408 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2409 (org-export-resolve-coderef "coderef" info
))))
2410 ;; A link to a "-n -r" block returns line number.
2413 (org-test-with-parsed-data
2414 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
2415 (org-export-resolve-coderef "coderef" info
))))
2418 (org-test-with-parsed-data
2419 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2420 (org-export-resolve-coderef "coderef" info
))))
2421 ;; A link to a "-n" block returns coderef.
2424 (org-test-with-parsed-data
2425 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2426 (org-export-resolve-coderef "coderef" info
))))
2429 (org-test-with-parsed-data
2430 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
2431 (org-export-resolve-coderef "coderef" info
))))
2432 ;; A link to a "-r" block returns line number.
2435 (org-test-with-parsed-data
2436 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2437 (org-export-resolve-coderef "coderef" info
))))
2440 (org-test-with-parsed-data
2441 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
2442 (org-export-resolve-coderef "coderef" info
))))
2443 ;; A link to a block without a switch returns coderef.
2446 (org-test-with-parsed-data
2447 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
2448 (org-export-resolve-coderef "coderef" info
))))
2449 (org-test-with-parsed-data
2450 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
2451 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
2452 ;; Correctly handle continued line numbers. A "+n" switch should
2453 ;; resume numbering from previous block with numbered lines,
2454 ;; ignoring blocks not numbering lines in the process. A "-n"
2455 ;; switch resets count.
2458 (org-test-with-parsed-data "
2463 #+BEGIN_SRC emacs-lisp
2467 #+BEGIN_SRC emacs-lisp +n -r
2468 \(+ 1 1) (ref:addition)
2471 #+BEGIN_EXAMPLE -n -r
2472 Another text. (ref:text)
2474 (list (org-export-resolve-coderef "addition" info
)
2475 (org-export-resolve-coderef "text" info
)))))
2476 ;; Recognize coderef with user-specified syntax.
2479 (org-test-with-parsed-data
2480 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
2481 (org-export-resolve-coderef "text" info
))))
2482 ;; Unresolved coderefs throw an error.
2484 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
2485 (org-export-resolve-coderef "unknown" info
)))))
2487 (ert-deftest test-org-export
/resolve-fuzzy-link
()
2488 "Test `org-export-resolve-fuzzy-link' specifications."
2489 ;; Match target objects.
2491 (org-test-with-parsed-data "<<target>> [[target]]"
2492 (org-export-resolve-fuzzy-link
2493 (org-element-map tree
'link
'identity info t
) info
)))
2494 ;; Match named elements.
2496 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
2497 (org-export-resolve-fuzzy-link
2498 (org-element-map tree
'link
'identity info t
) info
)))
2499 ;; Match exact headline's name.
2501 (org-test-with-parsed-data "* My headline\n[[My headline]]"
2502 (org-export-resolve-fuzzy-link
2503 (org-element-map tree
'link
'identity info t
) info
)))
2504 ;; Targets objects have priority over named elements and headline
2508 (org-test-with-parsed-data
2509 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
2511 (org-export-resolve-fuzzy-link
2512 (org-element-map tree
'link
'identity info t
) info
)))))
2513 ;; Named elements have priority over headline titles.
2516 (org-test-with-parsed-data
2517 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
2519 (org-export-resolve-fuzzy-link
2520 (org-element-map tree
'link
'identity info t
) info
)))))
2521 ;; If link's path starts with a "*", only match headline titles,
2525 (org-test-with-parsed-data
2526 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
2528 (org-export-resolve-fuzzy-link
2529 (org-element-map tree
'link
'identity info t
) info
)))))
2530 ;; Error if no match.
2532 (org-test-with-parsed-data "[[target]]"
2533 (org-export-resolve-fuzzy-link
2534 (org-element-map tree
'link
'identity info t
) info
)))
2535 ;; Match fuzzy link even when before first headline.
2538 (org-test-with-parsed-data "[[hl]]\n* hl"
2540 (org-export-resolve-fuzzy-link
2541 (org-element-map tree
'link
'identity info t
) info
)))))
2542 ;; Handle url-encoded fuzzy links.
2544 (org-test-with-parsed-data "* A B\n[[A%20B]]"
2545 (org-export-resolve-fuzzy-link
2546 (org-element-map tree
'link
#'identity info t
) info
))))
2548 (ert-deftest test-org-export
/resolve-id-link
()
2549 "Test `org-export-resolve-id-link' specifications."
2550 ;; Regular test for custom-id link.
2552 (equal '("Headline1")
2553 (org-test-with-parsed-data "* Headline1
2559 (org-element-property
2561 (org-export-resolve-id-link
2562 (org-element-map tree
'link
'identity info t
) info
)))))
2563 ;; Throw an error on failing searches.
2565 (org-test-with-parsed-data "* Headline1
2571 (org-export-resolve-id-link
2572 (org-element-map tree
'link
'identity info t
) info
)))
2573 ;; Test for internal id target.
2575 (equal '("Headline1")
2576 (org-test-with-parsed-data "* Headline1
2582 (org-element-property
2584 (org-export-resolve-id-link
2585 (org-element-map tree
'link
'identity info t
) info
)))))
2586 ;; Test for external id target.
2590 (org-test-with-parsed-data "[[id:aaaa]]"
2591 (org-export-resolve-id-link
2592 (org-element-map tree
'link
'identity info t
)
2593 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file")))))))))
2595 (ert-deftest test-org-export
/resolve-radio-link
()
2596 "Test `org-export-resolve-radio-link' specifications."
2599 (org-test-with-temp-text "<<<radio>>> radio"
2600 (org-update-radio-target-regexp)
2601 (let* ((tree (org-element-parse-buffer))
2602 (info `(:parse-tree
,tree
)))
2603 (org-export-resolve-radio-link
2604 (org-element-map tree
'link
'identity info t
)
2606 ;; Radio targets are case-insensitive.
2608 (org-test-with-temp-text "<<<RADIO>>> radio"
2609 (org-update-radio-target-regexp)
2610 (let* ((tree (org-element-parse-buffer))
2611 (info `(:parse-tree
,tree
)))
2612 (org-export-resolve-radio-link
2613 (org-element-map tree
'link
'identity info t
)
2615 ;; Radio target with objects.
2617 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
2618 (org-update-radio-target-regexp)
2619 (let* ((tree (org-element-parse-buffer))
2620 (info `(:parse-tree
,tree
)))
2621 (org-export-resolve-radio-link
2622 (org-element-map tree
'link
'identity info t
)
2624 ;; Radio target with objects at its beginning.
2626 (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
2627 (org-update-radio-target-regexp)
2628 (let* ((tree (org-element-parse-buffer))
2629 (info `(:parse-tree
,tree
)))
2630 (org-export-resolve-radio-link
2631 (org-element-map tree
'link
'identity info t
)
2633 ;; Radio link next to an apostrophe.
2635 (org-test-with-temp-text "<<<radio>>> radio's"
2636 (org-update-radio-target-regexp)
2637 (let* ((tree (org-element-parse-buffer))
2638 (info `(:parse-tree
,tree
)))
2639 (org-export-resolve-radio-link
2640 (org-element-map tree
'link
'identity info t
)
2642 ;; Multiple radio targets.
2644 (equal '("radio1" "radio2")
2645 (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
2646 (org-update-radio-target-regexp)
2647 (let* ((tree (org-element-parse-buffer))
2648 (info `(:parse-tree
,tree
)))
2649 (org-element-map tree
'link
2651 (org-element-property
2652 :value
(org-export-resolve-radio-link link info
)))
2654 ;; Radio target is whitespace insensitive.
2656 (org-test-with-temp-text "<<<a radio>>> a\n radio"
2657 (org-update-radio-target-regexp)
2658 (let* ((tree (org-element-parse-buffer))
2659 (info `(:parse-tree
,tree
)))
2660 (org-element-map tree
'link
2661 (lambda (link) (org-export-resolve-radio-link link info
)) info t
)))))
2663 (ert-deftest test-org-export
/file-uri
()
2664 "Test `org-export-file-uri' specifications."
2665 ;; Preserve relative filenames.
2666 (should (equal "relative.org" (org-export-file-uri "relative.org")))
2667 ;; Local files start with "file:///"
2668 (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
2669 ;; Remote files start with "file://"
2670 (should (equal "file://myself@some.where:papers/last.pdf"
2671 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
2672 ;; Expand filename starting with "~".
2673 (should (equal (org-export-file-uri "~/file.org")
2674 (concat "file://" (expand-file-name "~/file.org")))))
2678 ;;; Src-block and example-block
2680 (ert-deftest test-org-export
/unravel-code
()
2681 "Test `org-export-unravel-code' function."
2682 ;; Code without reference.
2684 (equal '("(+ 1 1)\n")
2685 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
2686 (org-export-unravel-code (org-element-at-point)))))
2687 ;; Code with reference.
2689 (equal '("(+ 1 1)\n" (1 .
"test"))
2690 (org-test-with-temp-text
2691 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
2692 (let ((org-coderef-label-format "(ref:%s)"))
2693 (org-export-unravel-code (org-element-at-point))))))
2694 ;; Code with user-defined reference.
2697 '("(+ 1 1)\n" (1 .
"test"))
2698 (org-test-with-temp-text
2699 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
2700 (let ((org-coderef-label-format "(ref:%s)"))
2701 (org-export-unravel-code (org-element-at-point))))))
2702 ;; Code references keys are relative to the current block.
2704 (equal '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one"))
2705 (org-test-with-temp-text "
2714 (let ((org-coderef-label-format "(ref:%s)"))
2715 (org-export-unravel-code (org-element-at-point)))))))
2717 (ert-deftest test-org-export
/format-code-default
()
2718 "Test `org-export-format-code-default' specifications."
2719 ;; Return the empty string when code is empty.
2722 (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
2723 (org-export-format-code-default
2724 (org-element-map tree
'src-block
'identity info t
) info
))))
2725 ;; Number lines, two whitespace characters before the actual loc.
2728 (org-test-with-parsed-data
2729 "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
2730 (org-export-format-code-default
2731 (org-element-map tree
'src-block
'identity info t
) info
))))
2732 ;; Put references 6 whitespace characters after the widest line,
2733 ;; wrapped within parenthesis.
2735 (equal "123 (a)\n1 (b)\n"
2736 (let ((org-coderef-label-format "(ref:%s)"))
2737 (org-test-with-parsed-data
2738 "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
2739 (org-export-format-code-default
2740 (org-element-map tree
'src-block
'identity info t
) info
))))))
2746 (ert-deftest test-org-export
/activate-smart-quotes
()
2747 "Test `org-export-activate-smart-quotes' specifications."
2748 ;; Double quotes: standard test.
2751 '("some “quoted” text")
2752 (let ((org-export-default-language "en"))
2753 (org-test-with-parsed-data "some \"quoted\" text"
2754 (org-element-map tree
'plain-text
2755 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2757 ;; Opening quotes: at the beginning of a paragraph.
2761 (let ((org-export-default-language "en"))
2762 (org-test-with-parsed-data "\"begin"
2763 (org-element-map tree
'plain-text
2764 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2766 ;; Opening quotes: after an object.
2769 '("“quoted” text")
2770 (let ((org-export-default-language "en"))
2771 (org-test-with-parsed-data "=verb= \"quoted\" text"
2772 (org-element-map tree
'plain-text
2773 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2775 ;; Closing quotes: at the end of a paragraph.
2778 '("Quoted “text”")
2779 (let ((org-export-default-language "en"))
2780 (org-test-with-parsed-data "Quoted \"text\""
2781 (org-element-map tree
'plain-text
2782 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2784 ;; Inner quotes: standard test.
2786 (equal '("« outer « inner » outer »")
2787 (let ((org-export-default-language "fr"))
2788 (org-test-with-parsed-data "\"outer 'inner' outer\""
2789 (org-element-map tree
'plain-text
2790 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2792 ;; Apostrophe: standard test.
2794 (equal '("It « shouldn’t » fail")
2795 (let ((org-export-default-language "fr"))
2796 (org-test-with-parsed-data "It \"shouldn't\" fail"
2797 (org-element-map tree
'plain-text
2798 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2801 (equal '("It shouldn’t fail")
2802 (let ((org-export-default-language "fr"))
2803 (org-test-with-parsed-data "It shouldn't fail"
2804 (org-element-map tree
'plain-text
2805 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2807 ;; Apostrophe: before an object.
2810 '("« a’" " »")
2811 (let ((org-export-default-language "fr"))
2812 (org-test-with-parsed-data "\"a'=b=\""
2813 (org-element-map tree
'plain-text
2814 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2816 ;; Apostrophe: after an object.
2818 (equal '("« " "’s »")
2819 (let ((org-export-default-language "fr"))
2820 (org-test-with-parsed-data "\"=code='s\""
2821 (org-element-map tree
'plain-text
2822 (lambda (s) (org-export-activate-smart-quotes s
:utf-8 info
))
2824 ;; Special case: isolated quotes.
2826 (equal '("“" "”")
2827 (let ((org-export-default-language "en"))
2828 (org-test-with-parsed-data "\"$x$\""
2829 (org-element-map tree
'plain-text
2830 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2832 ;; Smart quotes in secondary strings.
2834 (equal '("“" "”")
2835 (let ((org-export-default-language "en"))
2836 (org-test-with-parsed-data "* \"$x$\""
2837 (org-element-map tree
'plain-text
2838 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2840 ;; Smart quotes in document keywords.
2842 (equal '("“" "”")
2843 (let ((org-export-default-language "en"))
2844 (org-test-with-parsed-data "#+TITLE: \"$x$\""
2845 (org-element-map (plist-get info
:title
) 'plain-text
2846 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2848 ;; Smart quotes in parsed affiliated keywords.
2850 (equal '("“" "”" "Paragraph")
2851 (let ((org-export-default-language "en"))
2852 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
2853 (org-element-map tree
'plain-text
2854 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
2855 info nil nil t
))))))
2861 (ert-deftest test-org-export
/special-column
()
2862 "Test if the table's special column is properly recognized."
2863 ;; 1. First column is special if it contains only a special marking
2864 ;; characters or empty cells.
2865 (org-test-with-temp-text "
2869 (org-export-table-has-special-column-p
2871 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2872 ;; 2. If the column contains anything else, it isn't special.
2873 (org-test-with-temp-text "
2877 (org-export-table-has-special-column-p
2879 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2880 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
2882 (org-test-with-temp-text "
2891 (org-export-table-has-special-column-p
2893 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
2894 ;; 4. A first column with only empty cells isn't considered as
2896 (org-test-with-temp-text "
2900 (org-export-table-has-special-column-p
2902 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
2904 (ert-deftest test-org-export
/table-row-is-special-p
()
2905 "Test `org-export-table-row-is-special-p' specifications."
2906 ;; 1. A row is special if it has a special marking character in the
2908 (org-test-with-parsed-data "| ! | 1 |"
2910 (org-export-table-row-is-special-p
2911 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2912 ;; 2. A row is special when its first field is "/"
2913 (org-test-with-parsed-data "
2917 (org-export-table-row-is-special-p
2918 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2919 ;; 3. A row only containing alignment cookies is also considered as
2921 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
2923 (org-export-table-row-is-special-p
2924 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2925 ;; 4. Everything else isn't considered as special.
2926 (org-test-with-parsed-data "| \alpha | | c |"
2928 (org-export-table-row-is-special-p
2929 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
2930 ;; 5. Table's rules are never considered as special rows.
2931 (org-test-with-parsed-data "|---+---|"
2933 (org-export-table-row-is-special-p
2934 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
2936 (ert-deftest test-org-export
/has-header-p
()
2937 "Test `org-export-table-has-header-p' specifications."
2938 ;; 1. With an header.
2939 (org-test-with-parsed-data "
2944 (org-export-table-has-header-p
2945 (org-element-map tree
'table
'identity info
'first-match
)
2947 ;; 2. Without an header.
2948 (org-test-with-parsed-data "
2952 (org-export-table-has-header-p
2953 (org-element-map tree
'table
'identity info
'first-match
)
2955 ;; 3. Don't get fooled with starting and ending rules.
2956 (org-test-with-parsed-data "
2962 (org-export-table-has-header-p
2963 (org-element-map tree
'table
'identity info
'first-match
)
2966 (ert-deftest test-org-export
/table-row-group
()
2967 "Test `org-export-table-row-group' specifications."
2968 ;; 1. A rule creates a new group.
2971 (org-test-with-parsed-data "
2975 (org-element-map tree
'table-row
2977 (if (eq (org-element-property :type row
) 'rule
) 'rule
2978 (org-export-table-row-group row info
)))))))
2979 ;; 2. Special rows are ignored in count.
2983 (org-test-with-parsed-data "
2987 (org-element-map tree
'table-row
2989 (if (eq (org-element-property :type row
) 'rule
) 'rule
2990 (org-export-table-row-group row info
)))
2992 ;; 3. Double rules also are ignored in count.
2994 (equal '(1 rule rule
2)
2995 (org-test-with-parsed-data "
3000 (org-element-map tree
'table-row
3002 (if (eq (org-element-property :type row
) 'rule
) 'rule
3003 (org-export-table-row-group row info
))))))))
3005 (ert-deftest test-org-export
/table-row-number
()
3006 "Test `org-export-table-row-number' specifications."
3007 ;; Standard test. Number is 0-indexed.
3010 (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
3011 (org-element-map tree
'table-row
3012 (lambda (row) (org-export-table-row-number row info
)) info
))))
3013 ;; Number ignores separators.
3016 (org-test-with-parsed-data "
3020 (org-element-map tree
'table-row
3021 (lambda (row) (org-export-table-row-number row info
)) info
))))
3022 ;; Number ignores special rows.
3025 (org-test-with-parsed-data "
3031 (org-element-map tree
'table-row
3032 (lambda (row) (org-export-table-row-number row info
)) info
)))))
3034 (ert-deftest test-org-export
/table-cell-width
()
3035 "Test `org-export-table-cell-width' specifications."
3036 ;; 1. Width is primarily determined by width cookies. If no cookie
3037 ;; is found, cell's width is nil.
3038 (org-test-with-parsed-data "
3039 | / | <l> | <6> | <l7> |
3044 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3045 (org-element-map tree
'table-cell
'identity info
)))))
3046 ;; 2. The last width cookie has precedence.
3047 (org-test-with-parsed-data "
3054 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3055 (org-element-map tree
'table-cell
'identity info
)))))
3056 ;; 3. Valid width cookies must have a specific row.
3057 (org-test-with-parsed-data "| <6> | cell |"
3061 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
3062 (org-element-map tree
'table-cell
'identity
))))))
3064 (ert-deftest test-org-export
/table-cell-alignment
()
3065 "Test `org-export-table-cell-alignment' specifications."
3066 ;; 1. Alignment is primarily determined by alignment cookies.
3068 (equal '(left center right
)
3069 (let ((org-table-number-fraction 0.5)
3070 (org-table-number-regexp "^[0-9]+$"))
3071 (org-test-with-parsed-data "| <l> | <c> | <r> |"
3072 (mapcar (lambda (cell)
3073 (org-export-table-cell-alignment cell info
))
3074 (org-element-map tree
'table-cell
'identity
))))))
3075 ;; 2. The last alignment cookie has precedence.
3077 (equal '(right right right
)
3078 (org-test-with-parsed-data "
3082 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
3083 (org-element-map tree
'table-cell
'identity
)))))
3084 ;; 3. If there's no cookie, cell's contents determine alignment.
3085 ;; A column mostly made of cells containing numbers will align
3086 ;; its cells to the right.
3088 (equal '(right right right
)
3089 (let ((org-table-number-fraction 0.5)
3090 (org-table-number-regexp "^[0-9]+$"))
3091 (org-test-with-parsed-data "
3095 (mapcar (lambda (cell)
3096 (org-export-table-cell-alignment cell info
))
3097 (org-element-map tree
'table-cell
'identity
))))))
3098 ;; 4. Otherwise, they will be aligned to the left.
3100 (equal '(left left left
)
3101 (org-test-with-parsed-data "
3105 (mapcar (lambda (cell)
3106 (org-export-table-cell-alignment cell info
))
3107 (org-element-map tree
'table-cell
'identity info
))))))
3109 (ert-deftest test-org-export
/table-cell-borders
()
3110 "Test `org-export-table-cell-borders' specifications."
3111 ;; 1. Recognize various column groups indicators.
3112 (org-test-with-parsed-data "| / | < | > | <> |"
3115 '((right bottom top
) (left bottom top
) (right bottom top
)
3116 (right left bottom top
))
3117 (mapcar (lambda (cell)
3118 (org-export-table-cell-borders cell info
))
3119 (org-element-map tree
'table-cell
'identity
)))))
3120 ;; 2. Accept shortcuts to define column groups.
3121 (org-test-with-parsed-data "| / | < | < |"
3124 '((right bottom top
) (right left bottom top
) (left bottom top
))
3125 (mapcar (lambda (cell)
3126 (org-export-table-cell-borders cell info
))
3127 (org-element-map tree
'table-cell
'identity
)))))
3128 ;; 3. A valid column groups row must start with a "/".
3129 (org-test-with-parsed-data "
3133 (equal '((top) (top) (bottom) (bottom))
3134 (mapcar (lambda (cell)
3135 (org-export-table-cell-borders cell info
))
3136 (org-element-map tree
'table-cell
'identity
)))))
3137 ;; 4. Take table rules into consideration.
3138 (org-test-with-parsed-data "
3143 (equal '((below top
) (bottom above
))
3144 (mapcar (lambda (cell)
3145 (org-export-table-cell-borders cell info
))
3146 (org-element-map tree
'table-cell
'identity
)))))
3147 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
3148 ;; (resp. `bottom' and `below') borders. Any special row is
3150 (org-test-with-parsed-data "
3156 (equal '((bottom below top above
))
3158 (mapcar (lambda (cell)
3159 (org-export-table-cell-borders cell info
))
3160 (org-element-map tree
'table-cell
'identity
)))))))
3162 (ert-deftest test-org-export
/table-dimensions
()
3163 "Test `org-export-table-dimensions' specifications."
3164 ;; 1. Standard test.
3165 (org-test-with-parsed-data "
3170 (org-export-table-dimensions
3171 (org-element-map tree
'table
'identity info
'first-match
) info
))))
3172 ;; 2. Ignore horizontal rules and special columns.
3173 (org-test-with-parsed-data "
3180 (org-export-table-dimensions
3181 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
3183 (ert-deftest test-org-export
/table-cell-address
()
3184 "Test `org-export-table-cell-address' specifications."
3185 ;; 1. Standard test: index is 0-based.
3186 (org-test-with-parsed-data "| a | b |"
3188 (equal '((0 .
0) (0 .
1))
3189 (org-element-map tree
'table-cell
3190 (lambda (cell) (org-export-table-cell-address cell info
))
3192 ;; 2. Special column isn't counted, nor are special rows.
3193 (org-test-with-parsed-data "
3198 (org-export-table-cell-address
3199 (car (last (org-element-map tree
'table-cell
'identity info
)))
3201 ;; 3. Tables rules do not count either.
3202 (org-test-with-parsed-data "
3210 (org-export-table-cell-address
3211 (car (last (org-element-map tree
'table-cell
'identity info
)))
3213 ;; 4. Return nil for special cells.
3214 (org-test-with-parsed-data "| / | a |"
3216 (org-export-table-cell-address
3217 (org-element-map tree
'table-cell
'identity nil
'first-match
)
3220 (ert-deftest test-org-export
/get-table-cell-at
()
3221 "Test `org-export-get-table-cell-at' specifications."
3222 ;; 1. Address ignores special columns, special rows and rules.
3223 (org-test-with-parsed-data "
3230 (org-element-contents
3231 (org-export-get-table-cell-at
3233 (org-element-map tree
'table
'identity info
'first-match
)
3235 ;; 2. Return value for a non-existent address is nil.
3236 (org-test-with-parsed-data "| a |"
3238 (org-export-get-table-cell-at
3240 (org-element-map tree
'table
'identity info
'first-match
)
3242 (org-test-with-parsed-data "| / |"
3244 (org-export-get-table-cell-at
3246 (org-element-map tree
'table
'identity info
'first-match
)
3249 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
3250 "Test `org-export-table-cell-starts-colgroup-p' specifications."
3251 ;; 1. A cell at a beginning of a row always starts a column group.
3252 (org-test-with-parsed-data "| a |"
3254 (org-export-table-cell-starts-colgroup-p
3255 (org-element-map tree
'table-cell
'identity info
'first-match
)
3257 ;; 2. Special column should be ignored when determining the
3258 ;; beginning of the row.
3259 (org-test-with-parsed-data "
3263 (org-export-table-cell-starts-colgroup-p
3264 (org-element-map tree
'table-cell
'identity info
'first-match
)
3266 ;; 2. Explicit column groups.
3267 (org-test-with-parsed-data "
3273 (org-element-map tree
'table-cell
3275 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
3278 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
3279 "Test `org-export-table-cell-ends-colgroup-p' specifications."
3280 ;; 1. A cell at the end of a row always ends a column group.
3281 (org-test-with-parsed-data "| a |"
3283 (org-export-table-cell-ends-colgroup-p
3284 (org-element-map tree
'table-cell
'identity info
'first-match
)
3286 ;; 2. Special column should be ignored when determining the
3287 ;; beginning of the row.
3288 (org-test-with-parsed-data "
3292 (org-export-table-cell-ends-colgroup-p
3293 (org-element-map tree
'table-cell
'identity info
'first-match
)
3295 ;; 3. Explicit column groups.
3296 (org-test-with-parsed-data "
3302 (org-element-map tree
'table-cell
3304 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
3307 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
3308 "Test `org-export-table-row-starts-rowgroup-p' specifications."
3309 ;; 1. A row at the beginning of a table always starts a row group.
3310 ;; So does a row following a table rule.
3311 (org-test-with-parsed-data "
3318 (org-element-map tree
'table-row
3320 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3322 ;; 2. Special rows should be ignored when determining the beginning
3324 (org-test-with-parsed-data "
3333 (org-element-map tree
'table-row
3335 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
3338 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
3339 "Test `org-export-table-row-ends-rowgroup-p' specifications."
3340 ;; 1. A row at the end of a table always ends a row group. So does
3341 ;; a row preceding a table rule.
3342 (org-test-with-parsed-data "
3349 (org-element-map tree
'table-row
3351 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3353 ;; 2. Special rows should be ignored when determining the beginning
3355 (org-test-with-parsed-data "
3364 (org-element-map tree
'table-row
3366 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
3369 (ert-deftest test-org-export
/table-row-in-header-p
()
3370 "Test `org-export-table-row-in-header-p' specifications."
3371 ;; Standard test. Separators are always nil.
3375 (org-test-with-parsed-data "| a |\n|---|\n| b |"
3376 (org-element-map tree
'table-row
3378 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
))))
3379 ;; Nil when there is no header.
3383 (org-test-with-parsed-data "| a |\n| b |"
3384 (org-element-map tree
'table-row
3386 (if (org-export-table-row-in-header-p row info
) 'yes
'no
)) info
)))))
3388 (ert-deftest test-org-export
/table-row-starts-header-p
()
3389 "Test `org-export-table-row-starts-header-p' specifications."
3390 ;; 1. Only the row starting the first row group starts the table
3392 (org-test-with-parsed-data "
3400 (org-element-map tree
'table-row
3402 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
3404 ;; 2. A row cannot start an header if there's no header in the
3406 (org-test-with-parsed-data "
3410 (org-export-table-row-starts-header-p
3411 (org-element-map tree
'table-row
'identity info
'first-match
)
3414 (ert-deftest test-org-export
/table-row-ends-header-p
()
3415 "Test `org-export-table-row-ends-header-p' specifications."
3416 ;; 1. Only the row starting the first row group starts the table
3418 (org-test-with-parsed-data "
3426 (org-element-map tree
'table-row
3428 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
3430 ;; 2. A row cannot start an header if there's no header in the
3432 (org-test-with-parsed-data "
3436 (org-export-table-row-ends-header-p
3437 (org-element-map tree
'table-row
'identity info
'first-match
)
3442 ;;; Tables of Contents
3444 (ert-deftest test-org-export
/collect-headlines
()
3445 "Test `org-export-collect-headlines' specifications."
3450 (org-test-with-parsed-data "* H1\n** H2"
3451 (org-export-collect-headlines info
)))))
3452 ;; Do not collect headlines below optional argument.
3456 (org-test-with-parsed-data "* H1\n** H2"
3457 (org-export-collect-headlines info
1)))))
3458 ;; Never collect headlines below maximum headline level.
3462 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3463 (org-export-collect-headlines info
)))))
3467 (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
3468 (org-export-collect-headlines info
2)))))
3469 ;; Collect headlines locally.
3472 (org-test-with-parsed-data "* H1\n** H2\n** H3"
3473 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3474 (length (org-export-collect-headlines info nil scope
))))))
3475 ;; When collecting locally, optional level is relative.
3478 (org-test-with-parsed-data "* H1\n** H2\n*** H3"
3479 (let ((scope (org-element-map tree
'headline
#'identity info t
)))
3480 (length (org-export-collect-headlines info
1 scope
)))))))
3486 (ert-deftest test-org-export
/inner-template
()
3487 "Test `inner-template' translator specifications."
3490 (org-test-with-temp-text "* Headline"
3492 (org-export-create-backend
3494 '((inner-template .
(lambda (contents info
) "Success!"))
3495 (headline .
(lambda (h c i
) "Headline"))))))))
3496 ;; Inner template is applied even in a "body-only" export.
3499 (org-test-with-temp-text "* Headline"
3501 (org-export-create-backend
3502 :transcoders
'((inner-template .
(lambda (c i
) "Success!"))
3503 (headline .
(lambda (h c i
) "Headline"))))
3504 nil nil
'body-only
)))))
3506 (ert-deftest test-org-export
/template
()
3507 "Test `template' translator specifications."
3510 (org-test-with-temp-text "* Headline"
3512 (org-export-create-backend
3513 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3514 (headline .
(lambda (h c i
) "Headline"))))))))
3515 ;; Template is not applied in a "body-only" export.
3518 (org-test-with-temp-text "* Headline"
3520 (org-export-create-backend
3521 :transcoders
'((template .
(lambda (contents info
) "Success!"))
3522 (headline .
(lambda (h c i
) "Headline"))))
3523 nil nil
'body-only
)))))
3529 (ert-deftest test-org-export
/get-next-element
()
3530 "Test `org-export-get-next-element' specifications."
3534 (org-test-with-parsed-data "* Headline\n*a* b"
3535 (org-export-get-next-element
3536 (org-element-map tree
'bold
'identity info t
) info
))))
3537 ;; Return nil when no previous element.
3539 (org-test-with-parsed-data "* Headline\na *b*"
3540 (org-export-get-next-element
3541 (org-element-map tree
'bold
'identity info t
) info
)))
3542 ;; Non-exportable elements are ignored.
3544 (let ((org-export-with-timestamps nil
))
3545 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
3546 (org-export-get-next-element
3547 (org-element-map tree
'entity
'identity info t
) info
))))
3548 ;; Find next element in secondary strings.
3551 (org-test-with-parsed-data "* a =verb="
3553 (org-export-get-next-element
3554 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3557 (org-test-with-parsed-data "* /italic/ =verb="
3559 (org-export-get-next-element
3560 (org-element-map tree
'italic
'identity info t
) info
)))))
3561 ;; Find next element in document keywords.
3564 (org-test-with-parsed-data "#+TITLE: a =verb="
3566 (org-export-get-next-element
3568 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3569 ;; Find next element in parsed affiliated keywords.
3572 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
3574 (org-export-get-next-element
3575 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3576 ;; With optional argument N, return a list containing all the
3577 ;; following elements.
3580 '(bold code underline
)
3581 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3583 (org-export-get-next-element
3584 (org-element-map tree
'italic
'identity info t
) info t
)))))
3585 ;; When N is a positive integer, return a list containing up to
3586 ;; N following elements.
3590 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
3592 (org-export-get-next-element
3593 (org-element-map tree
'italic
'identity info t
) info
2))))))
3595 (ert-deftest test-org-export
/get-previous-element
()
3596 "Test `org-export-get-previous-element' specifications."
3600 (org-test-with-parsed-data "* Headline\na *b*"
3601 (org-export-get-previous-element
3602 (org-element-map tree
'bold
'identity info t
) info
))))
3603 ;; Return nil when no previous element.
3605 (org-test-with-parsed-data "* Headline\n*a* b"
3606 (org-export-get-previous-element
3607 (org-element-map tree
'bold
'identity info t
) info
)))
3608 ;; Non-exportable elements are ignored.
3610 (let ((org-export-with-timestamps nil
))
3611 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
3612 (org-export-get-previous-element
3613 (org-element-map tree
'entity
'identity info t
) info
))))
3614 ;; Find previous element in secondary strings.
3617 (org-test-with-parsed-data "* =verb= a"
3619 (org-export-get-previous-element
3620 (org-element-map tree
'plain-text
'identity info t
) info
)))))
3623 (org-test-with-parsed-data "* =verb= /italic/"
3625 (org-export-get-previous-element
3626 (org-element-map tree
'italic
'identity info t
) info
)))))
3627 ;; Find previous element in document keywords.
3630 (org-test-with-parsed-data "#+TITLE: =verb= a"
3632 (org-export-get-previous-element
3634 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
3635 ;; Find previous element in parsed affiliated keywords.
3638 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
3640 (org-export-get-previous-element
3641 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
3642 ;; With optional argument N, return a list containing up to
3643 ;; N previous elements.
3645 (equal '(underline italic bold
)
3646 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3648 (org-export-get-previous-element
3649 (org-element-map tree
'code
'identity info t
) info t
)))))
3650 ;; When N is a positive integer, return a list containing up to
3651 ;; N previous elements.
3653 (equal '(italic bold
)
3654 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
3656 (org-export-get-previous-element
3657 (org-element-map tree
'code
'identity info t
) info
2))))))
3661 ;;; test-org-export.el end here